Title: [94784] trunk
Revision
94784
Author
rolandstei...@chromium.org
Date
2011-09-08 12:56:38 -0700 (Thu, 08 Sep 2011)

Log Message

<style scoped>: Add 'scoped' attribute
https://bugs.webkit.org/show_bug.cgi?id=67718

Source/WebCore:

Add 'scoped' attribute to IDL and attribute list,
implement and test setting/resetting of the attribute.

Reviewed by Dimitri Glazkov.

Test: fast/css/style-scoped/basic-attribute.html

* html/HTMLAttributeNames.in:
* html/HTMLStyleElement.cpp:
(WebCore::HTMLStyleElement::scoped):
(WebCore::HTMLStyleElement::setScoped):
(WebCore::HTMLStyleElement::scopingElement):
* html/HTMLStyleElement.h:
* html/HTMLStyleElement.idl:

LayoutTests:

Test setting/resetting of the 'scoped' attribute in various circumstances.

Reviewed by Dimitri Glazkov.

* fast/css/style-scoped/basic-attribute-expected.txt: Added.
* fast/css/style-scoped/basic-attribute.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (94783 => 94784)


--- trunk/LayoutTests/ChangeLog	2011-09-08 19:55:20 UTC (rev 94783)
+++ trunk/LayoutTests/ChangeLog	2011-09-08 19:56:38 UTC (rev 94784)
@@ -1,3 +1,15 @@
+2011-09-08  Roland Steiner  <rolandstei...@chromium.org>
+
+        <style scoped>: Add 'scoped' attribute
+        https://bugs.webkit.org/show_bug.cgi?id=67718
+
+        Test setting/resetting of the 'scoped' attribute in various circumstances.
+
+        Reviewed by Dimitri Glazkov.
+
+        * fast/css/style-scoped/basic-attribute-expected.txt: Added.
+        * fast/css/style-scoped/basic-attribute.html: Added.
+
 2011-09-08  Ben Wells  <benwe...@chromium.org>
 
         Rebaseline for bug 65583 (path based border radius drawing on skia) part 2

Added: trunk/LayoutTests/fast/css/style-scoped/basic-attribute-expected.txt (0 => 94784)


--- trunk/LayoutTests/fast/css/style-scoped/basic-attribute-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/style-scoped/basic-attribute-expected.txt	2011-09-08 19:56:38 UTC (rev 94784)
@@ -0,0 +1,62 @@
+Basic test for the <style scoped> attribute.
+
+--- Initial ---
+PASS global1.getAttribute('scoped') is null
+PASS global1.scoped is false
+PASS global2.getAttribute('scoped') is null
+PASS global2.scoped is false
+PASS testBooleanAttribute(scoped1, 'scoped') is true
+PASS scoped1.scoped is true
+PASS testBooleanAttribute(scoped2, 'scoped') is true
+PASS scoped2.scoped is true
+PASS testBooleanAttribute(scoped3, 'scoped') is true
+PASS scoped3.scoped is true
+--- After insertion into tree ---
+PASS global1.getAttribute('scoped') is null
+PASS global1.scoped is false
+PASS global2.getAttribute('scoped') is null
+PASS global2.scoped is false
+PASS testBooleanAttribute(scoped1, 'scoped') is true
+PASS scoped1.scoped is true
+PASS testBooleanAttribute(scoped2, 'scoped') is true
+PASS scoped2.scoped is true
+PASS testBooleanAttribute(scoped3, 'scoped') is true
+PASS scoped3.scoped is true
+--- Inverting 'scoped' attribute while in tree ---
+PASS testBooleanAttribute(global1, 'scoped') is true
+PASS global1.scoped is true
+PASS testBooleanAttribute(global2, 'scoped') is true
+PASS global2.scoped is true
+PASS scoped1.getAttribute('scoped') is null
+PASS scoped1.scoped is false
+PASS scoped2.getAttribute('scoped') is null
+PASS scoped2.scoped is false
+PASS scoped3.getAttribute('scoped') is null
+PASS scoped3.scoped is false
+--- After removal from tree (attribute is still inverted) ---
+PASS testBooleanAttribute(global1, 'scoped') is true
+PASS global1.scoped is true
+PASS testBooleanAttribute(global2, 'scoped') is true
+PASS global2.scoped is true
+PASS scoped1.getAttribute('scoped') is null
+PASS scoped1.scoped is false
+PASS scoped2.getAttribute('scoped') is null
+PASS scoped2.scoped is false
+PASS scoped3.getAttribute('scoped') is null
+PASS scoped3.scoped is false
+--- Inverting 'scoped' attribute again, while outside tree ---
+PASS global1.getAttribute('scoped') is null
+PASS global1.scoped is false
+PASS global2.getAttribute('scoped') is null
+PASS global2.scoped is false
+PASS testBooleanAttribute(scoped1, 'scoped') is true
+PASS scoped1.scoped is true
+PASS testBooleanAttribute(scoped2, 'scoped') is true
+PASS scoped2.scoped is true
+PASS testBooleanAttribute(scoped3, 'scoped') is true
+PASS scoped3.scoped is true
+--- DONE ---
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/style-scoped/basic-attribute.html (0 => 94784)


--- trunk/LayoutTests/fast/css/style-scoped/basic-attribute.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/style-scoped/basic-attribute.html	2011-09-08 19:56:38 UTC (rev 94784)
@@ -0,0 +1,124 @@
+<html>
+<head>
+    <link rel="stylesheet" href=""
+    <script src=""
+</head>
+<body>
+    <p>Basic test for the &lt;style scoped&gt; attribute.</p>
+    <div id="scope">
+        <style id="global1"></style>
+        <style scoped='scoped' id="scoped1"></style>
+    </div>
+
+    <div id="console"></div>
+
+    <script>
+        function testBooleanAttribute(elem, attr)
+        {
+            var val = elem.getAttribute(attr);
+            if (val === null)
+                return false
+            if (val === '' || val === attr)
+                return true;
+            throw "Illegal value for boolean attribute!";
+        }
+    
+        var scope = document.getElementById('scope');
+
+        var global1 = document.getElementById('global1');
+        var scoped1 = document.getElementById('scoped1');
+
+        var global2 = document.createElement('style');
+        var scoped2 = document.createElement('style');
+        scoped2.setAttribute('scoped', 'scoped');
+        var scoped3 = document.createElement('style');
+        scoped3.scoped = true;
+
+        debug("--- Initial ---");
+        shouldBeNull("global1.getAttribute('scoped')");
+        shouldBeFalse("global1.scoped");
+        shouldBeNull("global2.getAttribute('scoped')");
+        shouldBeFalse("global2.scoped");
+        shouldBeTrue("testBooleanAttribute(scoped1, 'scoped')");
+        shouldBeTrue("scoped1.scoped");
+        shouldBeTrue("testBooleanAttribute(scoped2, 'scoped')");
+        shouldBeTrue("scoped2.scoped");
+        shouldBeTrue("testBooleanAttribute(scoped3, 'scoped')");
+        shouldBeTrue("scoped3.scoped");
+
+        debug("--- After insertion into tree ---")
+        scope.appendChild(global2);
+        scope.appendChild(scoped2);
+        scope.appendChild(scoped3);
+
+        shouldBeNull("global1.getAttribute('scoped')");
+        shouldBeFalse("global1.scoped");
+        shouldBeNull("global2.getAttribute('scoped')");
+        shouldBeFalse("global2.scoped");
+        shouldBeTrue("testBooleanAttribute(scoped1, 'scoped')");
+        shouldBeTrue("scoped1.scoped");
+        shouldBeTrue("testBooleanAttribute(scoped2, 'scoped')");
+        shouldBeTrue("scoped2.scoped");
+        shouldBeTrue("testBooleanAttribute(scoped3, 'scoped')");
+        shouldBeTrue("scoped3.scoped");
+
+        debug("--- Inverting 'scoped' attribute while in tree ---");
+        scoped1.scoped = null;
+        scoped2.scoped = false;
+        scoped3.removeAttribute('scoped');
+        global1.scoped = true;
+        global2.setAttribute('scoped', 'scoped');
+
+        shouldBeTrue("testBooleanAttribute(global1, 'scoped')");
+        shouldBeTrue("global1.scoped");
+        shouldBeTrue("testBooleanAttribute(global2, 'scoped')");
+        shouldBeTrue("global2.scoped");
+        shouldBeNull("scoped1.getAttribute('scoped')");
+        shouldBeFalse("scoped1.scoped");
+        shouldBeNull("scoped2.getAttribute('scoped')");
+        shouldBeFalse("scoped2.scoped");
+        shouldBeNull("scoped3.getAttribute('scoped')");
+        shouldBeFalse("scoped3.scoped");
+
+        debug("--- After removal from tree (attribute is still inverted) ---");
+        scope.removeChild(global1);
+        scope.removeChild(global2);
+        scope.removeChild(scoped1);
+        scope.removeChild(scoped2);
+        scope.removeChild(scoped3);
+
+        shouldBeTrue("testBooleanAttribute(global1, 'scoped')");
+        shouldBeTrue("global1.scoped");
+        shouldBeTrue("testBooleanAttribute(global2, 'scoped')");
+        shouldBeTrue("global2.scoped");
+        shouldBeNull("scoped1.getAttribute('scoped')");
+        shouldBeFalse("scoped1.scoped");
+        shouldBeNull("scoped2.getAttribute('scoped')");
+        shouldBeFalse("scoped2.scoped");
+        shouldBeNull("scoped3.getAttribute('scoped')");
+        shouldBeFalse("scoped3.scoped");
+
+        debug("--- Inverting 'scoped' attribute again, while outside tree ---");
+        scoped1.scoped = true;
+        scoped2.scoped = true;
+        scoped3.setAttribute('scoped', 'scoped');
+        global1.scoped = false;
+        global2.removeAttribute('scoped');
+
+        shouldBeNull("global1.getAttribute('scoped')");
+        shouldBeFalse("global1.scoped");
+        shouldBeNull("global2.getAttribute('scoped')");
+        shouldBeFalse("global2.scoped");
+        shouldBeTrue("testBooleanAttribute(scoped1, 'scoped')");
+        shouldBeTrue("scoped1.scoped");
+        shouldBeTrue("testBooleanAttribute(scoped2, 'scoped')");
+        shouldBeTrue("scoped2.scoped");
+        shouldBeTrue("testBooleanAttribute(scoped3, 'scoped')");
+        shouldBeTrue("scoped3.scoped");
+
+        debug("--- DONE ---");
+        var successfullyParsed = true;
+    </script>
+    <script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (94783 => 94784)


--- trunk/Source/WebCore/ChangeLog	2011-09-08 19:55:20 UTC (rev 94783)
+++ trunk/Source/WebCore/ChangeLog	2011-09-08 19:56:38 UTC (rev 94784)
@@ -1,3 +1,23 @@
+2011-09-08  Roland Steiner  <rolandstei...@chromium.org>
+
+        <style scoped>: Add 'scoped' attribute
+        https://bugs.webkit.org/show_bug.cgi?id=67718
+
+        Add 'scoped' attribute to IDL and attribute list,
+        implement and test setting/resetting of the attribute.
+
+        Reviewed by Dimitri Glazkov.
+
+        Test: fast/css/style-scoped/basic-attribute.html
+
+        * html/HTMLAttributeNames.in:
+        * html/HTMLStyleElement.cpp:
+        (WebCore::HTMLStyleElement::scoped):
+        (WebCore::HTMLStyleElement::setScoped):
+        (WebCore::HTMLStyleElement::scopingElement):
+        * html/HTMLStyleElement.h:
+        * html/HTMLStyleElement.idl:
+
 2011-09-08  Erik Arvidsson  <a...@chromium.org>
 
         Move Element.contains to Node

Modified: trunk/Source/WebCore/html/HTMLAttributeNames.in (94783 => 94784)


--- trunk/Source/WebCore/html/HTMLAttributeNames.in	2011-09-08 19:55:20 UTC (rev 94783)
+++ trunk/Source/WebCore/html/HTMLAttributeNames.in	2011-09-08 19:56:38 UTC (rev 94784)
@@ -266,6 +266,7 @@
 sandbox
 scheme
 scope
+scoped
 scrollamount
 scrolldelay
 scrolling

Modified: trunk/Source/WebCore/html/HTMLStyleElement.cpp (94783 => 94784)


--- trunk/Source/WebCore/html/HTMLStyleElement.cpp	2011-09-08 19:55:20 UTC (rev 94783)
+++ trunk/Source/WebCore/html/HTMLStyleElement.cpp	2011-09-08 19:56:38 UTC (rev 94784)
@@ -94,6 +94,31 @@
     return getAttribute(typeAttr);
 }
 
+bool HTMLStyleElement::scoped() const
+{
+    return fastHasAttribute(scopedAttr);
+}
+
+void HTMLStyleElement::setScoped(bool scopedValue)
+{
+    setBooleanAttribute(scopedAttr, scopedValue);
+}
+
+Element* HTMLStyleElement::scopingElement() const
+{
+    if (!scoped())
+        return 0;
+
+    // FIXME: This probably needs to be refined for scoped stylesheets within shadow DOM.
+    // As written, such a stylesheet could style the host element, as well as children of the host.
+    // OTOH, this paves the way for a :bound-element implementation.
+    ContainerNode* parentOrHost = parentOrHostNode();
+    if (!parentOrHost || !parentOrHost->isElementNode())
+        return 0;
+
+    return toElement(parentOrHost);
+}
+
 void HTMLStyleElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
 {    
     HTMLElement::addSubresourceAttributeURLs(urls);

Modified: trunk/Source/WebCore/html/HTMLStyleElement.h (94783 => 94784)


--- trunk/Source/WebCore/html/HTMLStyleElement.h	2011-09-08 19:55:20 UTC (rev 94783)
+++ trunk/Source/WebCore/html/HTMLStyleElement.h	2011-09-08 19:56:38 UTC (rev 94784)
@@ -37,6 +37,10 @@
 
     void setType(const AtomicString&);
 
+    bool scoped() const;
+    void setScoped(bool);
+    Element* scopingElement() const;
+
     using StyleElement::sheet;
 
     bool disabled() const;

Modified: trunk/Source/WebCore/html/HTMLStyleElement.idl (94783 => 94784)


--- trunk/Source/WebCore/html/HTMLStyleElement.idl	2011-09-08 19:55:20 UTC (rev 94783)
+++ trunk/Source/WebCore/html/HTMLStyleElement.idl	2011-09-08 19:56:38 UTC (rev 94784)
@@ -22,6 +22,7 @@
 
     interface HTMLStyleElement : HTMLElement {
         attribute boolean disabled;
+        attribute boolean scoped;
         attribute [Reflect] DOMString media;
         attribute [Reflect] DOMString type;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to