Fix for bugzilla bug 3335, add support for the CSS3 indirect adjacent sibling select...
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Jun 2005 05:31:17 +0000 (05:31 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 11 Jun 2005 05:31:17 +0000 (05:31 +0000)
from KHTML tree by Nick Shanks.

        Reviewed by hyatt

        Test cases added: fast/selectors/046.html

        * khtml/css/css_base.cpp:
        (CSSSelector::selectorText):
        * khtml/css/css_base.h:
        (DOM::CSSSelector::):
        * khtml/css/cssstyleselector.cpp:
        (khtml::CSSStyleSelector::checkSelector):
        * khtml/css/parser.y:
        * layout-tests/fast/selectors/046-expected.txt: Added.
        * layout-tests/fast/selectors/046.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@9358 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/fast/selectors/046-expected.txt [new file with mode: 0644]
LayoutTests/fast/selectors/046.html [new file with mode: 0644]
WebCore/ChangeLog-2005-08-23
WebCore/khtml/css/css_base.cpp
WebCore/khtml/css/css_base.h
WebCore/khtml/css/cssstyleselector.cpp
WebCore/khtml/css/parser.y

diff --git a/LayoutTests/fast/selectors/046-expected.txt b/LayoutTests/fast/selectors/046-expected.txt
new file mode 100644 (file)
index 0000000..4602d01
--- /dev/null
@@ -0,0 +1,21 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (0,0) size 800x186
+  RenderBlock {HTML} at (0,0) size 800x186
+    RenderBody {BODY} at (8,16) size 784x154
+      RenderBlock {DIV} at (0,0) size 784x154
+        RenderBlock {P} at (0,0) size 784x18
+          RenderText {TEXT} at (0,0) size 221x18
+            text run at (0,0) width 221: "This paragraph should be unstyled."
+        RenderBlock {P} at (0,34) size 784x18 [bgcolor=#00FF00]
+          RenderText {TEXT} at (0,0) size 285x18
+            text run at (0,0) width 285: "But this one should have a green background"
+        RenderBlock {P} at (0,68) size 784x18 [bgcolor=#00FF00]
+          RenderText {TEXT} at (0,0) size 319x18
+            text run at (0,0) width 319: "And this one should also have a green background"
+        RenderBlock {ADDRESS} at (0,102) size 784x18
+          RenderText {TEXT} at (0,0) size 431x18
+            text run at (0,0) width 431: "This address is only here to fill some space between two paragraphs"
+        RenderBlock {P} at (0,136) size 784x18 [bgcolor=#00FF00]
+          RenderText {TEXT} at (0,0) size 304x18
+            text run at (0,0) width 304: "This paragraph should have a green background"
diff --git a/LayoutTests/fast/selectors/046.html b/LayoutTests/fast/selectors/046.html
new file mode 100644 (file)
index 0000000..9348d59
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
+<html>
+ <head>
+  <title>Indirect adjacent combinator</title>
+  <style type="text/css">.red { background-color : red }
+div.stub > p ~ p { background-color : lime }</style>
+  <link rel="first" href="css3-modsel-1.html" title="Groups of selectors">
+  <link rel="prev" href="css3-modsel-45c.html" title="Direct adjacent combinator and classes">
+  <link rel="next" href="css3-modsel-46b.html" title="Indirect adjacent combinator">
+  <link rel="last" href="css3-modsel-d5e.html" title="NEGATED :indeterminate with :checked">
+  <link rel="up" href="./index.html">
+  <link rel="top" href="../../index.html">
+ </head>
+ <body>
+ <div class="stub">
+  <p>This paragraph should be unstyled.</p>
+  <p class="red">But this one should have a green background</p>
+  <p class="red">And this one should also have a green background</p>
+  <address>This address is only here to fill some space between two paragraphs</address>
+ <p class="red">This paragraph should have a green background</p>
+ </div>
+</body>
+</html>
\ No newline at end of file
index d0afc8644678fdec8ec6f16c84620220b8291dc1..21b07c35c56614a5c027fdb1d6f250d888834ae5 100644 (file)
@@ -1,3 +1,22 @@
+2005-06-10  David Hyatt  <hyatt@apple.com>
+
+       Fix for bugzilla bug 3335, add support for the CSS3 indirect adjacent sibling selector.  Patch merge
+       from KHTML tree by Nick Shanks.
+       
+        Reviewed by hyatt
+
+        Test cases added: fast/selectors/046.html
+
+        * khtml/css/css_base.cpp:
+        (CSSSelector::selectorText):
+        * khtml/css/css_base.h:
+        (DOM::CSSSelector::):
+        * khtml/css/cssstyleselector.cpp:
+        (khtml::CSSStyleSelector::checkSelector):
+        * khtml/css/parser.y:
+        * layout-tests/fast/selectors/046-expected.txt: Added.
+        * layout-tests/fast/selectors/046.html: Added.
+
 2005-06-10  David Hyatt  <hyatt@apple.com>
 
        Fix for 3237, background image repeats when it shouldn't.  The Radar bug is 4005553.  Patch from
index 8d079eeb0db9a7a19190af81660230138d3cdeae..4d6687af1004c76a959e25fde0f6000b4b51e2a6 100644 (file)
@@ -303,8 +303,10 @@ DOMString CSSSelector::selectorText() const
     }
     if ( cs->tagHistory ) {
         DOMString tagHistoryText = cs->tagHistory->selectorText();
-        if ( cs->relation == Sibling )
+               if ( cs->relation == DirectAdjacent )
             str = tagHistoryText + " + " + str;
+        else if ( cs->relation == IndirectAdjacent )
+            str = tagHistoryText + " ~ " + str;
         else if ( cs->relation == Child )
             str = tagHistoryText + " > " + str;
         else if ( cs->relation == SubSelector )
index 1ba18c524948c186c8e2f54d854df44c891286f0..60f707bd4c05578ba99887889bf228daf1e76759 100644 (file)
@@ -128,8 +128,9 @@ namespace DOM {
        {
            Descendant = 0,
            Child,
-           Sibling,
-           SubSelector
+           DirectAdjacent,
+            IndirectAdjacent,
+            SubSelector
        };
 
        enum PseudoType
@@ -172,7 +173,7 @@ namespace DOM {
        Q_UINT32     attr;
        Q_UINT32     tag;
 
-        Relation relation     : 2;
+        Relation relation     : 3;
        Match    match         : 4;
        unsigned int pseudoId : 3;
        mutable PseudoType _pseudoType : 5;
index 0b3331d95061500fe93ae14bef10004e1c715b5c..cbf870a36321718c30a88964303b7f15fab63dc0 100644 (file)
@@ -1026,17 +1026,32 @@ bool CSSStyleSelector::checkSelector(CSSSelector* sel, ElementImpl *e)
             if (!checkOneSelector(sel, elem)) return false;
             break;
         }
-        case CSSSelector::Sibling:
+        case CSSSelector::DirectAdjacent:
         {
             n = n->previousSibling();
-           while( n && !n->isElementNode() )
-               n = n->previousSibling();
-            if( !n ) return false;
-            ElementImpl *elem = static_cast<ElementImpl *>(n);
-            if (!checkOneSelector(sel, elem)) return false;
+            while (n && !n->isElementNode())
+                n = n->previousSibling();
+            if (!n) return false;
+            ElementImpl *elem = static_cast<ElementImpl*>(n);
+            if (!checkOneSelector(sel, elem))
+                return false;
+            break;
+        }
+        case CSSSelector::IndirectAdjacent:
+        {
+            // FIXME: This match needs to know how to backtrack and be non-deterministic.
+            ElementImpl *elem = 0;
+            do {
+                n = n->previousSibling();
+                while (n && !n->isElementNode())
+                    n = n->previousSibling();
+                if (!n)
+                    return false;
+                elem = static_cast<ElementImpl*>(n);
+            } while (!checkOneSelector(sel, elem));
             break;
         }
-        case CSSSelector::SubSelector:
+       case CSSSelector::SubSelector:
        {
             if (onlyHoverActive)
                 onlyHoverActive = (sel->match == CSSSelector::Pseudo &&
index 2aaa00286b6b825ff162285cb4d8cfbb161cff02..7f96f61e1d1a5c3f65b5e8265e46955570220ea1 100644 (file)
@@ -518,7 +518,8 @@ font_face:
 ;
 
 combinator:
-  '+' maybe_space { $$ = CSSSelector::Sibling; }
+    '+' maybe_space { $$ = CSSSelector::DirectAdjacent; }
+  | '~' maybe_space { $$ = CSSSelector::IndirectAdjacent; }
   | '>' maybe_space { $$ = CSSSelector::Child; }
   | /* empty */ { $$ = CSSSelector::Descendant; }
   ;
@@ -602,7 +603,8 @@ selector:
                 if ( doc )
                     doc->setUsesDescendantRules(true);
             }
-            else if ($2 == CSSSelector::Sibling) {
+            else if ($2 == CSSSelector::DirectAdjacent ||
+                     $2 == CSSSelector::IndirectAdjacent) {
                 CSSParser *p = static_cast<CSSParser *>(parser);
                 DOM::DocumentImpl *doc = p->document();
                 if (doc)