LayoutTests:
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 May 2006 06:46:08 +0000 (06:46 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 May 2006 06:46:08 +0000 (06:46 +0000)
        Reviewed by Maciej.

        Test for http://bugzilla.opendarwin.org/show_bug.cgi?id=7492
        CSS attribute selectors fail when the setAttribute() method is used
        to create an attribute and the attribute name is not Class or ID.

        * fast/css/selector-set-attribute.html: Added.
        * fast/css/selector-set-attribute-expected.txt: Added.
        * fast/css/selector-set-attribute-expected.checksum: Added.
        * fast/css/selector-set-attribute-expected.png: Added.

WebCore:

        Reviewed by Maciej.

        Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=7492
        CSS attribute selectors fail when the setAttribute() method is used
        to create an attribute and the attribute name is not Class or ID.

        Keep track of attributes used in attribute selectors to
        check after setAttribute whether a style recalc is needed.

        Test: fast/css/selector-set-attribute.html

        * css/cssstyleselector.cpp:
        (WebCore::CSSStyleSelector::checkOneSelector):
        (WebCore::CSSStyleSelector::hasSelectorForAttribute):
        * css/cssstyleselector.h:
        * dom/StyledElement.cpp:
        (WebCore::StyledElement::attributeChanged):

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

LayoutTests/ChangeLog
LayoutTests/fast/css/selector-set-attribute-expected.checksum [new file with mode: 0644]
LayoutTests/fast/css/selector-set-attribute-expected.png [new file with mode: 0644]
LayoutTests/fast/css/selector-set-attribute-expected.txt [new file with mode: 0644]
LayoutTests/fast/css/selector-set-attribute.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/css/cssstyleselector.cpp
WebCore/css/cssstyleselector.h
WebCore/dom/StyledElement.cpp

index 2bb9d80937797cd364bd40bcbcc3bb3b3211e680..a12a3887681c4b6c9f0017167f26d188b2dadeec 100644 (file)
@@ -1,4 +1,17 @@
-2006-05-16  Rob Buis  <buis@kde.org>
+2006-05-17  Rob Buis  <buis@kde.org>
+
+        Reviewed by Maciej.
+
+        Test for http://bugzilla.opendarwin.org/show_bug.cgi?id=7492
+        CSS attribute selectors fail when the setAttribute() method is used
+        to create an attribute and the attribute name is not Class or ID.
+
+        * fast/css/selector-set-attribute.html: Added.
+        * fast/css/selector-set-attribute-expected.txt: Added.
+        * fast/css/selector-set-attribute-expected.checksum: Added.
+        * fast/css/selector-set-attribute-expected.png: Added.
+
+2006-05-17  Rob Buis  <buis@kde.org>
 
         Reviewed by Darin.
 
diff --git a/LayoutTests/fast/css/selector-set-attribute-expected.checksum b/LayoutTests/fast/css/selector-set-attribute-expected.checksum
new file mode 100644 (file)
index 0000000..c36dcdb
--- /dev/null
@@ -0,0 +1 @@
+72e7eb6e69af56fe7389b189599ec2ff
\ No newline at end of file
diff --git a/LayoutTests/fast/css/selector-set-attribute-expected.png b/LayoutTests/fast/css/selector-set-attribute-expected.png
new file mode 100644 (file)
index 0000000..bd6439a
Binary files /dev/null and b/LayoutTests/fast/css/selector-set-attribute-expected.png differ
diff --git a/LayoutTests/fast/css/selector-set-attribute-expected.txt b/LayoutTests/fast/css/selector-set-attribute-expected.txt
new file mode 100644 (file)
index 0000000..130990d
--- /dev/null
@@ -0,0 +1,23 @@
+layer at (0,0) size 800x600
+  RenderCanvas 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 {H1} at (0,0) size 784x37
+        RenderText {#text} at (0,0) size 254x37
+          text run at (0,0) width 254: "setAttribute() Test"
+      RenderBlock {P} at (0,58) size 784x18 [color=#008000]
+        RenderText {#text} at (0,0) size 468x18
+          text run at (0,0) width 468: "This element's Class attribute is set using setAttribute(). It should be green."
+      RenderBlock {P} at (0,92) size 784x18 [color=#008000]
+        RenderText {#text} at (0,0) size 451x18
+          text run at (0,0) width 451: "This element's ID attribute is set using setAttribute(). It should be green."
+      RenderBlock {P} at (0,126) size 784x18 [color=#008000]
+        RenderText {#text} at (0,0) size 463x18
+          text run at (0,0) width 463: "This element's Title attribute is set using setAttribute(). It should be green."
+      RenderBlock {P} at (0,160) size 784x18 [color=#008000]
+        RenderText {#text} at (0,0) size 392x18
+          text run at (0,0) width 392: "This element's Title attribute is hard-coded. It should be green."
+      RenderBlock {P} at (0,194) size 784x18 [color=#008000]
+        RenderText {#text} at (0,0) size 467x18
+          text run at (0,0) width 467: "This element's Lang attribute is set using setAttribute(). It should be green."
diff --git a/LayoutTests/fast/css/selector-set-attribute.html b/LayoutTests/fast/css/selector-set-attribute.html
new file mode 100644 (file)
index 0000000..20b3d44
--- /dev/null
@@ -0,0 +1,46 @@
+<html>
+<head>
+<title>setAttribute() Test</title>
+
+<style type="text/css" title="text/css">
+
+    p { display:none; color: red; }
+    p[title] { display:block; color: green; }
+    p[id] { display:block; color: green; }
+    p[class] { display:block; color: green; }
+    p[lang] { display:block; color: green; }
+
+</style>
+
+<script type="text/javascript">
+    window.onload = init;
+    
+    function init() 
+    {
+        document.getElementsByTagName('p')[0].setAttribute('class','test');
+        document.getElementsByTagName('p')[1].setAttribute('id','test');
+        document.getElementsByTagName('p')[2].setAttribute('title','This is a test');
+        document.getElementsByTagName('p')[4].setAttribute('lang','en');
+    }
+</script>
+
+</head>
+<body>
+    <h1>setAttribute() Test</h1>
+    <p>
+        This element's Class attribute is set using setAttribute(). It should be green.     
+    </p>
+    <p>
+        This element's ID attribute is set using setAttribute(). It should be green.        
+    </p>
+    <p>
+        This element's Title attribute is set using setAttribute(). It should be green.     
+    </p>
+    <p title="This is hard-coded">
+        This element's Title attribute is hard-coded. It should be green.       
+    </p>
+    <p>
+        This element's Lang attribute is set using setAttribute(). It should be green.     
+    </p>
+</body>
+</html>
index 2198343085b9cb917fd8f9dc79c822123a105485..443f508e5660808ff44301b999e96cd130ebc402 100644 (file)
@@ -1,4 +1,24 @@
-2006-05-16  Rob Buis  <buis@kde.org>
+2006-05-17  Rob Buis  <buis@kde.org>
+
+        Reviewed by Maciej.
+
+        Fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=7492
+        CSS attribute selectors fail when the setAttribute() method is used
+        to create an attribute and the attribute name is not Class or ID.
+
+        Keep track of attributes used in attribute selectors to
+        check after setAttribute whether a style recalc is needed.
+
+        Test: fast/css/selector-set-attribute.html
+
+        * css/cssstyleselector.cpp:
+        (WebCore::CSSStyleSelector::checkOneSelector):
+        (WebCore::CSSStyleSelector::hasSelectorForAttribute):
+        * css/cssstyleselector.h:
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::attributeChanged):
+
+2006-05-17  Rob Buis  <buis@kde.org>
 
         Reviewed by Darin.
 
@@ -8,6 +28,9 @@
         Do extra checks for document nodes to detect multiple document elements
         and document types.
 
+        Test: fast/dom/createDocumentType2.html
+        Test: fast/dom/createElementNS.html
+
         * dom/Document.cpp:
         (WebCore::Document::childTypeAllowed):
         * dom/Document.h:
index 53f296c77f8c7b879471f2913df126d43009f490..172c5a754d6db27dd949ff7ba6cc18216acde139 100644 (file)
@@ -1226,8 +1226,10 @@ bool CSSStyleSelector::checkOneSelector(CSSSelector* sel, Element* e, bool isSub
         }
         else if (sel->match == CSSSelector::Id)
             return e->hasID() && e->getIDAttribute() == sel->value;
-        else if (style && (e != element || !styledElement || (!styledElement->isMappedAttribute(sel->attr) && sel->attr != typeAttr)))
+        else if (style && (e != element || !styledElement || (!styledElement->isMappedAttribute(sel->attr) && sel->attr != typeAttr))) {
             style->setAffectedByAttributeSelectors(); // Special-case the "type" attribute so input form controls can share style.
+            m_selectorAttrs.add(sel->attr.localName().impl());
+        }
 
         const AtomicString& value = e->getAttribute(sel->attr);
         if (value.isNull())
@@ -4312,4 +4314,9 @@ Color CSSStyleSelector::getColorFromPrimitiveValue(CSSPrimitiveValue* primitiveV
     return col;
 }
 
+bool CSSStyleSelector::hasSelectorForAttribute(const AtomicString &attrname)
+{
+    return m_selectorAttrs.contains(attrname.impl());
+}
+
 } // namespace WebCore
index 245c86b2b114085ca54bb05a735267697431154c..3df939e27d25bb3bc36e93236cebb358c18d9b32 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "DeprecatedString.h"
 #include "render_style.h"
+#include <wtf/HashSet.h>
 
 class KHTMLSettings;
 class KURL;
@@ -127,7 +128,9 @@ class StyledElement;
         float getComputedSizeFromSpecifiedSize(bool isAbsoluteSize, float specifiedSize);
         
         Color getColorFromPrimitiveValue(CSSPrimitiveValue* primitiveValue);
-        
+    
+        bool hasSelectorForAttribute(const AtomicString &attrname);
     protected:
 
         /* checks if a compound selector (which can consist of multiple simple selectors)
@@ -215,6 +218,8 @@ public:
         const KHTMLSettings *settings;
         bool fontDirty;
         bool isXMLDoc;
+
+        HashSet<AtomicStringImpl *> m_selectorAttrs;
         
         void applyProperty(int id, CSSValue *value);
 #if SVG_SUPPORT
index 647e346de4586b1f0abf67677912e82de36dffe1..544e9bccbe58107db8ec2116617d0f694a9b40fb 100644 (file)
@@ -30,6 +30,7 @@
 #include "CSSValueKeywords.h"
 #include "Document.h"
 #include "HTMLNames.h"
+#include "cssstyleselector.h"
 
 using namespace std;
 
@@ -175,7 +176,10 @@ void StyledElement::attributeChanged(Attribute* attr, bool preserveDecls)
 
     if (needToParse)
         parseMappedAttribute(mappedAttr);
-    
+
+    if (entry == eNone && ownerDocument()->styleSelector()->hasSelectorForAttribute(attr->name().localName()))
+        setChanged();
+
     if (checkDecl && mappedAttr->decl()) {
         // Add the decl to the table in the appropriate spot.
         setMappedAttributeDecl(entry, attr, mappedAttr->decl());