LayoutTests:
authorthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Dec 2005 22:22:21 +0000 (22:22 +0000)
committerthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Dec 2005 22:22:21 +0000 (22:22 +0000)
        Reviewed by Hyatt.

        Test case for our CSS seletorText serialization.

        * fast/dom/css-selectorText-expected.checksum: Added.
        * fast/dom/css-selectorText-expected.png: Added.
        * fast/dom/css-selectorText-expected.txt: Added.
        * fast/dom/css-selectorText.html: Added.

WebCore:

        Reviewed by Dave Hyatt.

        Test: fast/dom/css-selectorText.html

        Fixes selecotrText serialization to only print "*"
        when it is stand alone. Fixes the attribute set selector,
        along with general cleanup. Also print chained selectors.

        * khtml/css/css_base.cpp:
        (CSSSelector::extractPseudoType):
        (CSSSelector::selectorText):
        * khtml/css/css_ruleimpl.cpp:
        (DOM::CSSStyleRuleImpl::selectorText):

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/css-selectorText-expected.checksum [new file with mode: 0644]
LayoutTests/fast/dom/css-selectorText-expected.png [new file with mode: 0644]
LayoutTests/fast/dom/css-selectorText-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/css-selectorText.html [new file with mode: 0644]
WebCore/ChangeLog-2005-12-19
WebCore/khtml/css/css_base.cpp
WebCore/khtml/css/css_ruleimpl.cpp

index 36ebab00eefe176652cbb9547ca415d1c00d0463..b89bb8399d5d1bd47ce93141ed30a0edee541768 100644 (file)
@@ -1,3 +1,14 @@
+2005-12-12  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Hyatt.
+
+        Test case for our CSS seletorText serialization.
+
+        * fast/dom/css-selectorText-expected.checksum: Added.
+        * fast/dom/css-selectorText-expected.png: Added.
+        * fast/dom/css-selectorText-expected.txt: Added.
+        * fast/dom/css-selectorText.html: Added.
+
 2005-12-12  Eric Seidel  <eseidel@apple.com>
 
         Reviewed by ggaren.
diff --git a/LayoutTests/fast/dom/css-selectorText-expected.checksum b/LayoutTests/fast/dom/css-selectorText-expected.checksum
new file mode 100644 (file)
index 0000000..74455f1
--- /dev/null
@@ -0,0 +1 @@
+640609fe21178e25fe100e7b1622f885
\ No newline at end of file
diff --git a/LayoutTests/fast/dom/css-selectorText-expected.png b/LayoutTests/fast/dom/css-selectorText-expected.png
new file mode 100644 (file)
index 0000000..a36de68
Binary files /dev/null and b/LayoutTests/fast/dom/css-selectorText-expected.png differ
diff --git a/LayoutTests/fast/dom/css-selectorText-expected.txt b/LayoutTests/fast/dom/css-selectorText-expected.txt
new file mode 100644 (file)
index 0000000..183b74c
--- /dev/null
@@ -0,0 +1,25 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+layer at (2,2) size 796x596
+  RenderBlock {HTML} at (2,2) size 796x596
+    RenderBody {BODY} at (2,2) size 792x592
+      RenderBlock {PRE} at (2,0) size 788x270
+        RenderText {TEXT} at (0,0) size 208x270
+          text run at (0,0) width 8: "*"
+          text run at (0,15) width 24: "div"
+          text run at (0,30) width 64: "div span"
+          text run at (0,45) width 80: "div ~ span"
+          text run at (0,60) width 80: "div > span"
+          text run at (0,75) width 80: "div + span"
+          text run at (0,90) width 40: "#temp"
+          text run at (0,105) width 64: "div#temp"
+          text run at (0,120) width 176: "div.test[title=\"test\"]"
+          text run at (0,135) width 160: ".test[title~=\"test\"]"
+          text run at (0,150) width 168: "div > [title|=\"test\"]"
+          text run at (0,165) width 184: "div.test[title^=\"test\"]"
+          text run at (0,180) width 192: "span#test[title$=\"test\"]"
+          text run at (0,195) width 208: "span[title*=\"test\"]::after"
+          text run at (0,210) width 80: "div[title]"
+          text run at (0,225) width 56: "[title]"
+          text run at (0,240) width 48: "a:link"
+          text run at (0,255) width 192: "div, span > div:hover, a"
diff --git a/LayoutTests/fast/dom/css-selectorText.html b/LayoutTests/fast/dom/css-selectorText.html
new file mode 100644 (file)
index 0000000..453b6ed
--- /dev/null
@@ -0,0 +1,36 @@
+<html>
+<head>
+<style>
+* { margin: 2px; }
+div { margin: 2px; }
+div span { margin 2px; }
+div ~ span { margin 2px; }
+div > span { margin 2px; }
+div + span { margin 2px; }
+#temp { margin 2px; }
+div#temp { margin 2px; }
+div.test[title="test"] { margin: 2px; }
+.test[title~="test"] { margin: 2px; }
+div > [title|="test"] { margin: 2px; }
+div.test[title^="test"] { margin: 2px; }
+span#test[title$="test"] { margin: 2px; }
+span[title*="test"]::after { margin: 2px; }
+div[title] { margin: 2px; }
+[title] { margin: 2px; }
+a:link { margin: 2px; }
+div, span > div:hover, a { margin: 2px; }
+</style>
+</head>
+<body>
+<pre id="result"></pre>
+<script>
+var styleSheet = document.styleSheets.item(0);
+var s = "";
+for (var i = 0; i < styleSheet.cssRules.length; i++) {
+       var rule = styleSheet.cssRules[i];
+       s += rule.selectorText + "\n";
+}
+document.getElementById("result").innerText = s;
+</script>
+</body>
+</html>
index 6ffa8b109b26885b1c58bf8fa17441dd13735bf7..d66d0929bc99e9d7778ff278bf004f1586f0b303 100644 (file)
@@ -1,3 +1,19 @@
+2005-12-12  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Dave Hyatt.
+
+        Test: fast/dom/css-selectorText.html
+
+        Fixes selecotrText serialization to only print "*"
+        when it is stand alone. Fixes the attribute set selector,
+        along with general cleanup. Also print chained selectors.
+
+        * khtml/css/css_base.cpp:
+        (CSSSelector::extractPseudoType):
+        (CSSSelector::selectorText):
+        * khtml/css/css_ruleimpl.cpp:
+        (DOM::CSSStyleRuleImpl::selectorText):
+
 2005-12-12  Eric Seidel  <eseidel@apple.com>
 
         Reviewed by ggaren.
index cc8338eee23202975cbce8674aa8b455126679da..38799d70f80c011b09ed4580db0f0efcbaabf377 100644 (file)
@@ -236,7 +236,6 @@ void CSSSelector::extractPseudoType() const
            match = PseudoElement;
     else if (match == PseudoElement && !element)
         _pseudoType = PseudoOther;
-    value = nullAtom;
 }
 
 
@@ -265,64 +264,32 @@ DOMString CSSSelector::selectorText() const
     DOMString str;
     const CSSSelector* cs = this;
     const AtomicString& localName = cs->tag.localName();
-    if (localName == starAtom && cs->match == CSSSelector::Id)
-    {
-        str = "#";
+    if (cs->match == CSSSelector::None || localName != starAtom)
+        str = localName;
+    if (cs->match == CSSSelector::Id) {
+        str += "#";
         str += cs->value.qstring();
-    }
-    else if (localName == starAtom && cs->match == CSSSelector::Class)
-    {
-        str = ".";
+    } else if (cs->match == CSSSelector::Class) {
+        str += ".";
         str += cs->value.qstring();
-    }
-    else if (localName == starAtom  && cs->match == CSSSelector::PseudoClass)
-    {
-        str = ":";
+    } else if (cs->match == CSSSelector::PseudoClass) {
+        str += ":";
         str += cs->value.qstring();
-    }
-    else if (localName == starAtom && cs->match == CSSSelector::PseudoElement)
-    {
-        str = "::";
+    } else if (cs->match == CSSSelector::PseudoElement) {
+        str += "::";
         str += cs->value.qstring();
-    }
-    else
-    {
-        if (localName == starAtom)
-            str = "*";
-        else
-            str = localName;
-        if (cs->match == CSSSelector::Id)
-        {
-            str += "#";
-            str += cs->value.qstring();
-        }
-        else if (cs->match == CSSSelector::Class)
-        {
-            str += ".";
-            str += cs->value.qstring();
-        }
-        else if (cs->match == CSSSelector::PseudoClass)
-        {
-            str += ":";
-            str += cs->value.qstring();
-        }
-        else if (cs->match == CSSSelector::PseudoElement)
-        {
-            str += "::";
-            str += cs->value.qstring();
-        }
-        // optional attribute
-        if (cs->hasAttribute()) {
-            // FIXME: Add support for dumping namespaces.
-            DOMString attrName = cs->attr.localName();
-            str += "[";
-            str += attrName;
-            switch (cs->match) {
+    } else if (cs->hasAttribute()) {
+        // FIXME: Add support for dumping namespaces.
+        DOMString attrName = cs->attr.localName();
+        str += "[";
+        str += attrName;
+        switch (cs->match) {
             case CSSSelector::Exact:
                 str += "=";
                 break;
             case CSSSelector::Set:
-                str += " "; /// ## correct?
+                // set has no operator or value, just the attrName
+                str += "]";
                 break;
             case CSSSelector::List:
                 str += "~=";
@@ -341,21 +308,22 @@ DOMString CSSSelector::selectorText() const
                 break;
             default:
                 kdWarning(6080) << "Unhandled case in CSSStyleRuleImpl::selectorText : match=" << cs->match << endl;
-            }
+        }
+        if (cs->match != CSSSelector::Set) {
             str += "\"";
             str += cs->value.qstring();
             str += "\"]";
         }
     }
-    if ( cs->tagHistory ) {
+    if (cs->tagHistory) {
         DOMString tagHistoryText = cs->tagHistory->selectorText();
-               if ( cs->relation == DirectAdjacent )
+        if (cs->relation == CSSSelector::DirectAdjacent)
             str = tagHistoryText + " + " + str;
-        else if ( cs->relation == IndirectAdjacent )
+        else if (cs->relation == CSSSelector::IndirectAdjacent)
             str = tagHistoryText + " ~ " + str;
-        else if ( cs->relation == Child )
+        else if (cs->relation == CSSSelector::Child)
             str = tagHistoryText + " > " + str;
-        else if ( cs->relation == SubSelector )
+        else if (cs->relation == CSSSelector::SubSelector)
             str += tagHistoryText; // the ":" is provided by selectorText()
         else // Descendant
             str = tagHistoryText + " " + str;
index 94be0af8d632b0f7d4ebbc071ea0285ecf48a91d..d61d00d46249178d570b90fd6977d62fb0bd56a6 100644 (file)
@@ -367,9 +367,15 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl()
 
 DOM::DOMString CSSStyleRuleImpl::selectorText() const
 {
-    // FIXME: Handle all the selectors in the chain for comma-separated selectors.
-    if (m_selector)
-        return m_selector->selectorText();
+    if (m_selector) {
+        DOMString str;
+        for (CSSSelector *s = m_selector; s; s = s->next()) {
+            if (s != m_selector)
+                str += ", ";
+            str += s->selectorText();
+        }
+        return str;
+    }
     return DOMString();
 }