WebCore:
authorbfulgham@webkit.org <bfulgham@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Jul 2009 19:51:15 +0000 (19:51 +0000)
committerbfulgham@webkit.org <bfulgham@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Jul 2009 19:51:15 +0000 (19:51 +0000)
2009-07-15  Kai Bruning  <kai@granus.net>

        Reviewed by Dave Hyatt.

        CSS21 attribute selectors not dynamic for xml.
        https://bugs.webkit.org/show_bug.cgi?id=25072

        Moved the relevant test in StyledElement::attributeChanged()
        to a new function Element::recalcStyleIfNeededAfterAttributeChanged()
        so it can be called from both StyledElement::attributeChanged()
        and Element::attributeChanged().
        Refactored Element::attributeChanged() into
        Element::updateAfterAttributeChanged() and
        Element::recalcStyleIfNeededAfterAttributeChanged(), which are called
        separately from StyledElement::attributeChanged().

        Test: fast/css/attribute-selector-dynamic.xml

        * dom/Element.cpp:
        (WebCore::Element::attributeChanged):
        (WebCore::Element::updateAfterAttributeChanged):
        (WebCore::Element::recalcStyleIfNeededAfterAttributeChanged):
        * dom/Element.h:
        * dom/StyledElement.cpp:
        (WebCore::StyledElement::attributeChanged):

LayoutTests:

2009-07-15  Kai Bruning  <kai@granus.net>

        Reviewed by Dave Hyatt.

        CSS21 attribute selectors not dynamic for xml.
        https://bugs.webkit.org/show_bug.cgi?id=25072

        Test that CSS21 attribute selectors take effect when the attribute is
        dynamically changed in an xml dom.

        * fast/css/attribute-selector-dynamic.xml: Added.
        * platform/mac/fast/css/attribute-selector-dynamic-expected.checksum: Added.
        * platform/mac/fast/css/attribute-selector-dynamic-expected.png: Added.
        * platform/mac/fast/css/attribute-selector-dynamic-expected.txt: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/css/attribute-selector-dynamic.xml [new file with mode: 0644]
LayoutTests/platform/mac/fast/css/attribute-selector-dynamic-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/fast/css/attribute-selector-dynamic-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/css/attribute-selector-dynamic-expected.txt [new file with mode: 0644]
WebCore/ChangeLog
WebCore/dom/Element.cpp
WebCore/dom/Element.h
WebCore/dom/StyledElement.cpp

index 547c482..6569243 100644 (file)
@@ -1,3 +1,18 @@
+2009-07-15  Kai Br\9fning  <kai@granus.net>
+
+        Reviewed by Dave Hyatt.
+
+        CSS21 attribute selectors not dynamic for xml.
+        https://bugs.webkit.org/show_bug.cgi?id=25072
+
+        Test that CSS21 attribute selectors take effect when the attribute is
+        dynamically changed in an xml dom.
+
+        * fast/css/attribute-selector-dynamic.xml: Added.
+        * platform/mac/fast/css/attribute-selector-dynamic-expected.checksum: Added.
+        * platform/mac/fast/css/attribute-selector-dynamic-expected.png: Added.
+        * platform/mac/fast/css/attribute-selector-dynamic-expected.txt: Added.
+
 2009-07-14  David Hyatt  <hyatt@apple.com>
 
         Reviewed by Simon Fraser.
diff --git a/LayoutTests/fast/css/attribute-selector-dynamic.xml b/LayoutTests/fast/css/attribute-selector-dynamic.xml
new file mode 100644 (file)
index 0000000..54149d5
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--book xmlns="http://docbook.org/ns/docbook" xmlns:xhtml="http://www.w3.org/1999/xhtml" version="5.0"--> 
+<book xmlns="http://docbook.org/ns/docbook" xmlns:xhtml="http://www.w3.org/1999/xhtml" version="5.0">
+    <xhtml:style>
+        test { color: red; display: block }
+        test:before { content: 'FAILED' }
+        *[test="0"] { color: green; }
+        *[test="0"]:before { content: 'PASSED' }
+    </xhtml:style>
+    
+    <xhtml:div id="description">This test checks whether CSS21 attribute selectors are re-evaluated after attribute changes in xml elements.</xhtml:div>
+
+    <test test="1"></test>
+
+    <xhtml:script>
+      
+        function change() {
+            var element = document.getElementsByTagName('test')[0];
+            element.attributes.test.value = 0;
+            if (window.layoutTestController)
+                layoutTestController.notifyDone();
+        }
+      
+        window.onload = function () {
+            if (window.layoutTestController)
+                layoutTestController.waitUntilDone();
+            // Trigger an attribute change after all load processing is done. Doing the change
+            // here immediately does not exhibit the problem.
+            setTimeout("change();", 0);
+        }
+
+    </xhtml:script>
+</book>
diff --git a/LayoutTests/platform/mac/fast/css/attribute-selector-dynamic-expected.checksum b/LayoutTests/platform/mac/fast/css/attribute-selector-dynamic-expected.checksum
new file mode 100644 (file)
index 0000000..406f7af
--- /dev/null
@@ -0,0 +1 @@
+c00e3035818a0dd64c05ea920d54d5f7
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/css/attribute-selector-dynamic-expected.png b/LayoutTests/platform/mac/fast/css/attribute-selector-dynamic-expected.png
new file mode 100644 (file)
index 0000000..2294964
Binary files /dev/null and b/LayoutTests/platform/mac/fast/css/attribute-selector-dynamic-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/css/attribute-selector-dynamic-expected.txt b/LayoutTests/platform/mac/fast/css/attribute-selector-dynamic-expected.txt
new file mode 100644 (file)
index 0000000..b511551
--- /dev/null
@@ -0,0 +1,11 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x36
+  RenderBlock {book} at (0,0) size 800x36
+    RenderBlock {xhtml:div} at (0,0) size 800x18
+      RenderText {#text} at (0,0) size 670x18
+        text run at (0,0) width 670: "This test checks whether CSS21 attribute selectors are re-evaluated after attribute changes in xml elements."
+    RenderBlock {test} at (0,18) size 800x18 [color=#008000]
+      RenderInline (generated) at (0,0) size 61x18
+        RenderText at (0,0) size 61x18
+          text run at (0,0) width 61: "PASSED"
index a74fe44..1a5d82a 100644 (file)
@@ -1,3 +1,29 @@
+2009-07-15  Kai Br\9fning  <kai@granus.net>
+
+        Reviewed by Dave Hyatt.
+
+        CSS21 attribute selectors not dynamic for xml.
+        https://bugs.webkit.org/show_bug.cgi?id=25072
+
+        Moved the relevant test in StyledElement::attributeChanged()
+        to a new function Element::recalcStyleIfNeededAfterAttributeChanged()
+        so it can be called from both StyledElement::attributeChanged()
+        and Element::attributeChanged().
+        Refactored Element::attributeChanged() into
+        Element::updateAfterAttributeChanged() and
+        Element::recalcStyleIfNeededAfterAttributeChanged(), which are called
+        separately from StyledElement::attributeChanged().
+
+        Test: fast/css/attribute-selector-dynamic.xml
+
+        * dom/Element.cpp:
+        (WebCore::Element::attributeChanged):
+        (WebCore::Element::updateAfterAttributeChanged):
+        (WebCore::Element::recalcStyleIfNeededAfterAttributeChanged):
+        * dom/Element.h:
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::attributeChanged):
+
 2009-07-15  Alpha Lam  <hclam@chromium.org>
 
         Reviewed by David Levin.
index 69ad4d5..91b2598 100644 (file)
@@ -590,6 +590,12 @@ PassRefPtr<Attribute> Element::createAttribute(const QualifiedName& name, const
 
 void Element::attributeChanged(Attribute* attr, bool)
 {
+    recalcStyleIfNeededAfterAttributeChanged(attr);
+    updateAfterAttributeChanged(attr);
+}
+
+void Element::updateAfterAttributeChanged(Attribute* attr)
+{
     if (!document()->axObjectCache()->accessibilityEnabled())
         return;
 
@@ -602,7 +608,13 @@ void Element::attributeChanged(Attribute* attr, bool)
         document()->axObjectCache()->handleAriaRoleChanged(renderer());
     }
 }
-
+    
+void Element::recalcStyleIfNeededAfterAttributeChanged(Attribute* attr)
+{
+    if (document()->attached() && document()->styleSelector()->hasSelectorForAttribute(attr->name().localName()))
+        setNeedsStyleRecalc();
+}
+        
 void Element::setAttributeMap(PassRefPtr<NamedNodeMap> list)
 {
     document()->incDOMTreeVersion();
index b0bbeb3..d1ef3b2 100644 (file)
@@ -136,6 +136,11 @@ public:
     // This method is called whenever an attribute is added, changed or removed.
     virtual void attributeChanged(Attribute*, bool preserveDecls = false);
 
+    // The implementation of Element::attributeChanged() calls the following two functions.
+    // They are separated to allow a different flow of control in StyledElement::attributeChanged().
+    void recalcStyleIfNeededAfterAttributeChanged(Attribute*);
+    void updateAfterAttributeChanged(Attribute*);
+
     // not part of the DOM
     void setAttributeMap(PassRefPtr<NamedNodeMap>);
 
index c22ecf9..456cc52 100644 (file)
@@ -194,8 +194,8 @@ void StyledElement::attributeChanged(Attribute* attr, bool preserveDecls)
     if (needToParse)
         parseMappedAttribute(mappedAttr);
 
-    if (entry == eNone && ownerDocument()->attached() && ownerDocument()->styleSelector()->hasSelectorForAttribute(attr->name().localName()))
-        setNeedsStyleRecalc();
+    if (entry == eNone)
+        recalcStyleIfNeededAfterAttributeChanged(attr);
 
     if (checkDecl && mappedAttr->decl()) {
         // Add the decl to the table in the appropriate spot.
@@ -206,7 +206,7 @@ void StyledElement::attributeChanged(Attribute* attr, bool preserveDecls)
         if (namedAttrMap)
             mappedAttributes()->declAdded();
     }
-    Element::attributeChanged(attr, preserveDecls);
+    updateAfterAttributeChanged(attr);
 }
 
 bool StyledElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const