Copied: branches/chromium/912/LayoutTests/fast/selectors/visited-descendant.html (from rev 97745, trunk/LayoutTests/fast/selectors/visited-descendant.html) (0 => 98067)
--- branches/chromium/912/LayoutTests/fast/selectors/visited-descendant.html (rev 0)
+++ branches/chromium/912/LayoutTests/fast/selectors/visited-descendant.html 2011-10-21 05:47:53 UTC (rev 98067)
@@ -0,0 +1,55 @@
+<html>
+<head>
+<style>
+:visited { color: red }
+:visited #l1 { color: green }
+:visited > #l2 { color: green }
+:visited span :visited { color: green }
+:link + #span1 { color: green }
+:visited + #span1 { color: red }
+:link ~ #span2 { color: green }
+:visited ~ #span2 { color: red }
+</style>
+</head>
+<body>
+<p>
+Test that visited style matches to the topmost link in a decendant selector.
+The link should be green, with red underlining.
+</p>
+<p>
+<a href="" id="l1">Link</span></a>
+</p>
+<p>
+Test that visited style matches to the topmost link in a child selector.
+The link should be green, with red underlining.
+</p>
+<p>
+<a href="" id="l2">Link</span></a>
+</p>
+<p>
+Test that visited style does not match to non-topmost links.
+The link should be red, with red underlining.
+</p>
+<p>
+<a href="" href="" id="l3">Link</a></span></a>
+</p>
+<p>
+Test that direct adjacent selector doesn't match visited style.
+The link should be red, with red underlining.
+The span should be green.
+</p>
+<p>
+<a href=""
+<span id=span1>Span</span>
+</p>
+<p>
+Test that indirect adjacent selector doesn't match visited style.
+The link should be red, with red underlining.
+The span should be green.
+</p>
+<p>
+<a href=""
+<span id=span2>Span</span>
+</p>
+</body>
+</html>
Copied: branches/chromium/912/LayoutTests/platform/mac/fast/selectors/visited-descendant-expected.txt (from rev 97745, trunk/LayoutTests/platform/mac/fast/selectors/visited-descendant-expected.txt) (0 => 98067)
--- branches/chromium/912/LayoutTests/platform/mac/fast/selectors/visited-descendant-expected.txt (rev 0)
+++ branches/chromium/912/LayoutTests/platform/mac/fast/selectors/visited-descendant-expected.txt 2011-10-21 05:47:53 UTC (rev 98067)
@@ -0,0 +1,61 @@
+layer at (0,0) size 800x600
+ RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+ RenderBlock {HTML} at (0,0) size 800x600
+ RenderBody {BODY} at (8,8) size 784x576
+ RenderBlock {P} at (0,0) size 784x18
+ RenderText {#text} at (0,0) size 760x18
+ text run at (0,0) width 760: "Test that visited style matches to the topmost link in a decendant selector. The link should be green, with red underlining."
+ RenderBlock {P} at (0,34) size 784x18
+ RenderInline {A} at (0,0) size 30x18 [color=#FF0000]
+ RenderInline {SPAN} at (0,0) size 30x18 [color=#008000]
+ RenderText {#text} at (0,0) size 30x18
+ text run at (0,0) width 30: "Link"
+ RenderText {#text} at (0,0) size 0x0
+ RenderBlock {P} at (0,68) size 784x18
+ RenderText {#text} at (0,0) size 727x18
+ text run at (0,0) width 727: "Test that visited style matches to the topmost link in a child selector. The link should be green, with red underlining."
+ RenderBlock {P} at (0,102) size 784x18
+ RenderInline {A} at (0,0) size 30x18 [color=#FF0000]
+ RenderInline {SPAN} at (0,0) size 30x18 [color=#008000]
+ RenderText {#text} at (0,0) size 30x18
+ text run at (0,0) width 30: "Link"
+ RenderText {#text} at (0,0) size 0x0
+ RenderBlock {P} at (0,136) size 784x18
+ RenderText {#text} at (0,0) size 654x18
+ text run at (0,0) width 654: "Test that visited style does not match to non-topmost links. The link should be red, with red underlining."
+ RenderBlock {P} at (0,170) size 784x18
+ RenderInline {A} at (0,0) size 0x0 [color=#FF0000]
+ RenderInline {SPAN} at (0,0) size 0x0
+ RenderInline {A} at (0,0) size 30x18 [color=#FF0000]
+ RenderText {#text} at (0,0) size 30x18
+ text run at (0,0) width 30: "Link"
+ RenderText {#text} at (0,0) size 0x0
+ RenderBlock {P} at (0,204) size 784x36
+ RenderText {#text} at (0,0) size 767x36
+ text run at (0,0) width 767: "Test that direct adjacent selector doesn't match visited style. The link should be red, with red underlining. The span should"
+ text run at (0,18) width 58: "be green."
+ RenderBlock {P} at (0,256) size 784x18
+ RenderInline {A} at (0,0) size 30x18 [color=#FF0000]
+ RenderText {#text} at (0,0) size 30x18
+ text run at (0,0) width 30: "Link"
+ RenderText {#text} at (30,0) size 4x18
+ text run at (30,0) width 4: " "
+ RenderInline {SPAN} at (0,0) size 32x18 [color=#008000]
+ RenderText {#text} at (34,0) size 32x18
+ text run at (34,0) width 32: "Span"
+ RenderText {#text} at (0,0) size 0x0
+ RenderBlock {P} at (0,290) size 784x36
+ RenderText {#text} at (0,0) size 779x36
+ text run at (0,0) width 779: "Test that indirect adjacent selector doesn't match visited style. The link should be red, with red underlining. The span should"
+ text run at (0,18) width 58: "be green."
+ RenderBlock {P} at (0,342) size 784x18
+ RenderInline {A} at (0,0) size 30x18 [color=#FF0000]
+ RenderText {#text} at (0,0) size 30x18
+ text run at (0,0) width 30: "Link"
+ RenderText {#text} at (30,0) size 4x18
+ text run at (30,0) width 4: " "
+ RenderInline {SPAN} at (0,0) size 32x18 [color=#008000]
+ RenderText {#text} at (34,0) size 32x18
+ text run at (34,0) width 32: "Span"
+ RenderText {#text} at (0,0) size 0x0
Modified: branches/chromium/912/Source/WebCore/css/SelectorChecker.cpp (98066 => 98067)
--- branches/chromium/912/Source/WebCore/css/SelectorChecker.cpp 2011-10-21 05:43:00 UTC (rev 98066)
+++ branches/chromium/912/Source/WebCore/css/SelectorChecker.cpp 2011-10-21 05:47:53 UTC (rev 98067)
@@ -450,17 +450,17 @@
sel = sel->tagHistory();
if (!sel)
return SelectorMatches;
-
+
if (relation != CSSSelector::SubSelector) {
// Bail-out if this selector is irrelevant for the pseudoStyle
if (m_pseudoStyle != NOPSEUDO && m_pseudoStyle != dynamicPseudo)
return SelectorFailsCompletely;
- // Disable :visited matching after we move to selector components that would match anything else than the current element.
- if (!isSubSelector)
+ // Disable :visited matching when we see the first link or try to match anything else than an ancestors.
+ if (!isSubSelector && (e->isLink() || (relation != CSSSelector::Descendant && relation != CSSSelector::Child)))
visitedMatchType = VisitedMatchDisabled;
}
-
+
switch (relation) {
case CSSSelector::Descendant:
while (true) {
@@ -1338,7 +1338,7 @@
unsigned linkMatchType = MatchAll;
// Statically determine if this selector will match a link in visited, unvisited or any state, or never.
- // :visited never matches other elements than the current.
+ // :visited never matches other elements than the innermost link element.
for (; selector; selector = selector->tagHistory()) {
switch (selector->pseudoType()) {
case CSSSelector::PseudoNot:
@@ -1361,10 +1361,14 @@
// We don't support :link and :visited inside :-webkit-any.
break;
}
- if (selector->relation() != CSSSelector::SubSelector)
+ CSSSelector::Relation relation = selector->relation();
+ if (relation == CSSSelector::SubSelector)
+ continue;
+ if (relation != CSSSelector::Descendant && relation != CSSSelector::Child)
return linkMatchType;
+ if (linkMatchType != MatchAll)
+ return linkMatchType;
}
- ASSERT_NOT_REACHED();
return linkMatchType;
}