Title: [98067] branches/chromium/912
Revision
98067
Author
tk...@chromium.org
Date
2011-10-20 22:47:53 -0700 (Thu, 20 Oct 2011)

Log Message

Merge 97745 - REGRESSION(r97248): :visited as descendant selector broken
https://bugs.webkit.org/show_bug.cgi?id=70122

Source/WebCore: 

Reviewed by Nikolas Zimmerman.
        
Make ":visited foo" and similar selectors work correctly again. They can affect 
the visited style of an element inside a visited link.

Test: fast/selectors/visited-descendant.html

* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyDeclarations): 
        
    Apply visited style to children of visited links too.
            
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkSelector): 
        
    Don't disable visited matching until we run into first ancestor link or use combinator other than child/descendant.

(WebCore::SelectorChecker::determineLinkMatchType):
        
    Look into child/descendant component selectors too to determine the link match type.

LayoutTests: 

Reviewed by Nikolas Zimmerman.

* fast/selectors/visited-descendant.html: Added.
* platform/mac/fast/selectors/visited-descendant-expected.txt: Added.



TBR=tk...@chromium.org
BUG=crbug.com/101023
Review URL: http://codereview.chromium.org/8365028

Modified Paths

Added Paths

Diff

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/CSSStyleSelector.cpp (98066 => 98067)


--- branches/chromium/912/Source/WebCore/css/CSSStyleSelector.cpp	2011-10-21 05:43:00 UTC (rev 98066)
+++ branches/chromium/912/Source/WebCore/css/CSSStyleSelector.cpp	2011-10-21 05:47:53 UTC (rev 98067)
@@ -2174,7 +2174,7 @@
     if (startIndex == -1)
         return;
 
-    if (m_element && m_element->isLink()) {
+    if (m_style->insideLink() != NotInsideLink) {
         for (int i = startIndex; i <= endIndex; ++i) {
             CSSMutableStyleDeclaration* styleDeclaration = m_matchedDecls[i].styleDeclaration;
             unsigned linkMatchType = m_matchedDecls[i].linkMatchType;

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;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to