Title: [130987] trunk
Revision
130987
Author
morr...@google.com
Date
2012-10-10 18:00:37 -0700 (Wed, 10 Oct 2012)

Log Message

https://bugs.webkit.org/show_bug.cgi?id=95664
[Shadow DOM] should be able to be available without <style scoped>

Reviewed by Dimitri Glazkov.

Source/WebCore:

This change relaxes ENABLE(STYLE_SCOPED) compilation guard
and styleScopedEnabled() runtime guard. The flags now masks
user visible bits of the code, rather than all of it.
This change also eliminates some redundant guards for simplicity.

Test: fast/dom/shadow/style-scoped-not-enabled.html

* css/StyleResolver.cpp:
(WebCore::StyleResolver::matchScopedAuthorRules):
(WebCore::StyleResolver::locateCousinList):
(WebCore::StyleResolver::canShareStyleWithElement):
(WebCore::StyleResolver::locateSharedStyle):
* css/StyleScopeResolver.cpp:
(WebCore::StyleScopeResolver::scopeFor):
* css/StyleScopeResolver.h:
(WebCore):
* html/HTMLStyleElement.cpp:
(WebCore::HTMLStyleElement::HTMLStyleElement):
(WebCore::HTMLStyleElement::parseAttribute):
(WebCore::HTMLStyleElement::scopedAttributeChanged):
(WebCore::HTMLStyleElement::isRegisteredAsScoped):
(WebCore::HTMLStyleElement::registerWithScopingNode):
(WebCore::HTMLStyleElement::unregisterWithScopingNode):
(WebCore::HTMLStyleElement::insertedInto):
(WebCore::HTMLStyleElement::removedFrom):
(WebCore::HTMLStyleElement::scoped):
(WebCore::HTMLStyleElement::scopingElement):
* html/HTMLStyleElement.h:
(HTMLStyleElement):
* testing/InternalSettings.cpp: Exporsing a flag for testing.
(WebCore::InternalSettings::Backup::Backup):
(WebCore::InternalSettings::Backup::restoreTo):
(WebCore::InternalSettings::setStyleScopedEnabled):
(WebCore):
* testing/InternalSettings.h: Exporsing a flag for testing.
(Backup):
(InternalSettings):
* testing/InternalSettings.idl: Exporsing a flag for testing.

LayoutTests:

* fast/dom/shadow/style-scoped-not-enabled-expected.txt: Added.
* fast/dom/shadow/style-scoped-not-enabled.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (130986 => 130987)


--- trunk/LayoutTests/ChangeLog	2012-10-11 01:00:26 UTC (rev 130986)
+++ trunk/LayoutTests/ChangeLog	2012-10-11 01:00:37 UTC (rev 130987)
@@ -1,3 +1,13 @@
+2012-10-10  MORITA Hajime  <morr...@google.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=95664
+        [Shadow DOM] should be able to be available without <style scoped>
+
+        Reviewed by Dimitri Glazkov.
+
+        * fast/dom/shadow/style-scoped-not-enabled-expected.txt: Added.
+        * fast/dom/shadow/style-scoped-not-enabled.html: Added.
+
 2012-10-10  Ojan Vafai  <o...@chromium.org>
 
         check-layout.js should always dumpAsText

Added: trunk/LayoutTests/fast/dom/shadow/style-scoped-not-enabled-expected.txt (0 => 130987)


--- trunk/LayoutTests/fast/dom/shadow/style-scoped-not-enabled-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/style-scoped-not-enabled-expected.txt	2012-10-11 01:00:37 UTC (rev 130987)
@@ -0,0 +1,16 @@
+This test ensures content element feature can be disabled
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS window.getComputedStyle(shouldBeApplied).color is 'rgb(0, 0, 255)'
+PASS window.getComputedStyle(shouldNotBeApplied).color is 'rgb(0, 0, 0)'
+PASS window.getComputedStyle(insideScope).color is 'rgb(255, 0, 0)'
+PASS window.getComputedStyle(shouldNotBeScoped).color is 'rgb(255, 0, 0)'
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Should not be blue
+Should be red
+
+Should be red

Added: trunk/LayoutTests/fast/dom/shadow/style-scoped-not-enabled.html (0 => 130987)


--- trunk/LayoutTests/fast/dom/shadow/style-scoped-not-enabled.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/style-scoped-not-enabled.html	2012-10-11 01:00:37 UTC (rev 130987)
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+if (window.internals)
+    window.internals.settings.setStyleScopedEnabled(false);
+</script>
+</head>
+<body>
+<div id="host"></div>
+<span id='shouldNotBeApplied'>Should not be blue</span>
+<div>
+  <style scoped> p { color: red; } </style>
+  <p id='insideScope'>Should be red</p>
+</div>
+<p id='shouldNotBeScoped'>Should be red</p>
+<script>
+description("This test ensures content element feature can be disabled");
+var host = document.getElementById("host");
+var shadow = new WebKitShadowRoot(host);
+shadow.innerHTML = "<style> span { color: blue; } </style><span id='shouldBeApplied'>Should be blue</span>";
+var shouldBeApplied = shadow.getElementById("shouldBeApplied");
+var shouldNotBeApplied = document.getElementById("shouldNotBeApplied");
+var shouldNotBeScoped = document.getElementById("shouldNotBeScoped");
+var insideScope = document.getElementById("insideScope");
+shouldBe("window.getComputedStyle(shouldBeApplied).color", "'rgb(0, 0, 255)'");
+shouldBe("window.getComputedStyle(shouldNotBeApplied).color", "'rgb(0, 0, 0)'");
+shouldBe("window.getComputedStyle(insideScope).color", "'rgb(255, 0, 0)'");
+shouldBe("window.getComputedStyle(shouldNotBeScoped).color", "'rgb(255, 0, 0)'");
+finishJSTest();
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (130986 => 130987)


--- trunk/Source/WebCore/ChangeLog	2012-10-11 01:00:26 UTC (rev 130986)
+++ trunk/Source/WebCore/ChangeLog	2012-10-11 01:00:37 UTC (rev 130987)
@@ -1,3 +1,49 @@
+2012-10-10  MORITA Hajime  <morr...@google.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=95664
+        [Shadow DOM] should be able to be available without <style scoped>
+
+        Reviewed by Dimitri Glazkov.
+
+        This change relaxes ENABLE(STYLE_SCOPED) compilation guard
+        and styleScopedEnabled() runtime guard. The flags now masks
+        user visible bits of the code, rather than all of it.
+        This change also eliminates some redundant guards for simplicity.
+
+        Test: fast/dom/shadow/style-scoped-not-enabled.html
+
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::matchScopedAuthorRules):
+        (WebCore::StyleResolver::locateCousinList):
+        (WebCore::StyleResolver::canShareStyleWithElement):
+        (WebCore::StyleResolver::locateSharedStyle):
+        * css/StyleScopeResolver.cpp:
+        (WebCore::StyleScopeResolver::scopeFor):
+        * css/StyleScopeResolver.h:
+        (WebCore):
+        * html/HTMLStyleElement.cpp:
+        (WebCore::HTMLStyleElement::HTMLStyleElement):
+        (WebCore::HTMLStyleElement::parseAttribute):
+        (WebCore::HTMLStyleElement::scopedAttributeChanged):
+        (WebCore::HTMLStyleElement::isRegisteredAsScoped):
+        (WebCore::HTMLStyleElement::registerWithScopingNode):
+        (WebCore::HTMLStyleElement::unregisterWithScopingNode):
+        (WebCore::HTMLStyleElement::insertedInto):
+        (WebCore::HTMLStyleElement::removedFrom):
+        (WebCore::HTMLStyleElement::scoped):
+        (WebCore::HTMLStyleElement::scopingElement):
+        * html/HTMLStyleElement.h:
+        (HTMLStyleElement):
+        * testing/InternalSettings.cpp: Exporsing a flag for testing.
+        (WebCore::InternalSettings::Backup::Backup):
+        (WebCore::InternalSettings::Backup::restoreTo):
+        (WebCore::InternalSettings::setStyleScopedEnabled):
+        (WebCore):
+        * testing/InternalSettings.h: Exporsing a flag for testing.
+        (Backup):
+        (InternalSettings):
+        * testing/InternalSettings.idl: Exporsing a flag for testing.
+
 2012-10-10  Roger Fong  <roger_f...@apple.com>
 
         [WebGL] [On Mac] queried attributes and uniforms need to return the original variable name, not the mapped name.

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (130986 => 130987)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2012-10-11 01:00:26 UTC (rev 130986)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2012-10-11 01:00:37 UTC (rev 130987)
@@ -712,7 +712,7 @@
 
 void StyleResolver::matchScopedAuthorRules(MatchResult& result, bool includeEmptyRules)
 {
-#if ENABLE(STYLE_SCOPED)
+#if ENABLE(STYLE_SCOPED) || ENABLE(SHADOW_DOM)
     if (!m_scopeResolver || !m_scopeResolver->hasScopedStyles())
         return;
 
@@ -996,10 +996,8 @@
         return 0;
     if (!parent || !parent->isStyledElement())
         return 0;
-#if ENABLE(STYLE_SCOPED)
     if (parent->hasScopedHTMLStyleChild())
         return 0;
-#endif
     StyledElement* p = static_cast<StyledElement*>(parent);
     if (p->inlineStyle())
         return 0;
@@ -1179,14 +1177,10 @@
         return false;
     if (element->fastGetAttribute(cellpaddingAttr) != m_element->fastGetAttribute(cellpaddingAttr))
         return false;
-
     if (element->hasID() && m_features.idsInRules.contains(element->idForStyleResolution().impl()))
         return false;
-
-#if ENABLE(STYLE_SCOPED)
     if (element->hasScopedHTMLStyleChild())
         return false;
-#endif
 
 #if ENABLE(PROGRESS_ELEMENT)
     if (element->hasTagName(progressTag)) {
@@ -1293,10 +1287,8 @@
         return 0;
     if (parentStylePreventsSharing(m_parentStyle))
         return 0;
-#if ENABLE(STYLE_SCOPED)
     if (m_styledElement->hasScopedHTMLStyleChild())
         return 0;
-#endif
 
     // Check previous siblings and their cousins.
     unsigned count = 0;

Modified: trunk/Source/WebCore/css/StyleScopeResolver.cpp (130986 => 130987)


--- trunk/Source/WebCore/css/StyleScopeResolver.cpp	2012-10-11 01:00:26 UTC (rev 130986)
+++ trunk/Source/WebCore/css/StyleScopeResolver.cpp	2012-10-11 01:00:37 UTC (rev 130987)
@@ -27,7 +27,7 @@
 #include "config.h"
 #include "StyleScopeResolver.h"
 
-#if ENABLE(STYLE_SCOPED)
+#if ENABLE(STYLE_SCOPED) || ENABLE(SHADOW_DOM)
 
 #include "CSSStyleSheet.h"
 #include "ContextFeatures.h"
@@ -60,16 +60,13 @@
     Document* document = sheet->ownerDocument();
     if (!document)
         return 0;
-    if (!ContextFeatures::styleScopedEnabled(document))
-        return 0;
-
     Node* ownerNode = sheet->ownerNode();
     if (!ownerNode || !ownerNode->isHTMLElement() || !ownerNode->hasTagName(HTMLNames::styleTag))
         return 0;
 
     HTMLStyleElement* styleElement = static_cast<HTMLStyleElement*>(ownerNode);
     if (!styleElement->scoped())
-        return styleElement->isInShadowTree()? styleElement->shadowRoot() : 0;
+        return styleElement->isInShadowTree() ? styleElement->shadowRoot() : 0;
 
     ContainerNode* parent = styleElement->parentNode();
     if (!parent)

Modified: trunk/Source/WebCore/css/StyleScopeResolver.h (130986 => 130987)


--- trunk/Source/WebCore/css/StyleScopeResolver.h	2012-10-11 01:00:26 UTC (rev 130986)
+++ trunk/Source/WebCore/css/StyleScopeResolver.h	2012-10-11 01:00:37 UTC (rev 130987)
@@ -40,7 +40,7 @@
 class RuleSet;
 class RuleFeatureSet;
 
-#if ENABLE(STYLE_SCOPED)
+#if ENABLE(STYLE_SCOPED) || ENABLE(SHADOW_DOM)
 
 class StyleScopeResolver {
 public:

Modified: trunk/Source/WebCore/html/HTMLStyleElement.cpp (130986 => 130987)


--- trunk/Source/WebCore/html/HTMLStyleElement.cpp	2012-10-11 01:00:26 UTC (rev 130986)
+++ trunk/Source/WebCore/html/HTMLStyleElement.cpp	2012-10-11 01:00:37 UTC (rev 130987)
@@ -51,9 +51,7 @@
     , StyleElement(document, createdByParser)
     , m_firedLoad(false)
     , m_loadedSheet(false)
-#if ENABLE(STYLE_SCOPED)
     , m_scopedStyleRegistrationState(NotRegistered)
-#endif
 {
     ASSERT(hasTagName(styleTag));
 }
@@ -80,10 +78,8 @@
         setAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(this, attribute));
     else if (attribute.name() == onerrorAttr)
         setAttributeEventListener(eventNames().errorEvent, createAttributeEventListener(this, attribute));
-#if ENABLE(STYLE_SCOPED)
-    else if (attribute.name() == scopedAttr)
+    else if (attribute.name() == scopedAttr && ContextFeatures::styleScopedEnabled(document()))
         scopedAttributeChanged(!attribute.isNull());
-#endif
     else if (attribute.name() == mediaAttr && inDocument() && document()->renderer() && m_sheet) {
         m_sheet->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(attribute.value()));
         document()->styleResolverChanged(RecalcStyleImmediately);
@@ -91,9 +87,10 @@
         HTMLElement::parseAttribute(attribute);
 }
 
-#if ENABLE(STYLE_SCOPED)
 void HTMLStyleElement::scopedAttributeChanged(bool scoped)
 {
+    ASSERT(ContextFeatures::styleScopedEnabled(document()));
+
     if (!inDocument())
         return;
 
@@ -118,7 +115,6 @@
     if (isInShadowTree() && m_scopedStyleRegistrationState != RegisteredInShadowRoot)
         registerWithScopingNode(false);
 }
-#endif
 
 void HTMLStyleElement::finishParsingChildren()
 {
@@ -126,15 +122,12 @@
     HTMLElement::finishParsingChildren();
 }
 
-#if ENABLE(STYLE_SCOPED)
 inline bool HTMLStyleElement::isRegisteredAsScoped() const
 {
     // Note: We cannot rely on the 'scoped' attribute still being present when this method is invoked.
     // Therefore we cannot rely on scoped()!
     if (m_scopedStyleRegistrationState == NotRegistered)
         return false;
-    if (!ContextFeatures::styleScopedEnabled(document()))
-        return false;
     return true;
 }
 
@@ -171,8 +164,6 @@
     ASSERT(inDocument());
     if (m_scopedStyleRegistrationState != NotRegistered)
         return;
-    if (!ContextFeatures::styleScopedEnabled(document()))
-        return;
 
     ContainerNode* scope = scoped ? parentNode() : shadowRoot();
     if (!scope)
@@ -209,22 +200,14 @@
 
     m_scopedStyleRegistrationState = NotRegistered;
 }
-#else
-size_t Node::numberOfScopedHTMLStyleChildren() const
-{
-    return 0;
-}
-#endif
 
 Node::InsertionNotificationRequest HTMLStyleElement::insertedInto(ContainerNode* insertionPoint)
 {
     HTMLElement::insertedInto(insertionPoint);
     if (insertionPoint->inDocument()) {
         StyleElement::insertedIntoDocument(document(), this);
-#if ENABLE(STYLE_SCOPED)
         if (m_scopedStyleRegistrationState == NotRegistered && (scoped() || isInShadowTree()))
             registerWithScopingNode(scoped());
-#endif
     }
 
     return InsertionDone;
@@ -234,7 +217,6 @@
 {
     HTMLElement::removedFrom(insertionPoint);
 
-#if ENABLE(STYLE_SCOPED)
     // In the current implementation, <style scoped> is only registered if the node is in the document.
     // That is, because willRemove() is also called if an ancestor is removed from the document.
     // Now, if we want to register <style scoped> even if it's not inDocument,
@@ -249,7 +231,6 @@
             scope = parentNode() ? parentNode() : insertionPoint;
         unregisterWithScopingNode(scope);
     }
-#endif
 
     if (insertionPoint->inDocument())
         StyleElement::removedFromDocument(document(), this);
@@ -271,10 +252,9 @@
     return getAttribute(typeAttr);
 }
 
-#if ENABLE(STYLE_SCOPED)
 bool HTMLStyleElement::scoped() const
 {
-    return fastHasAttribute(scopedAttr);
+    return fastHasAttribute(scopedAttr) && ContextFeatures::styleScopedEnabled(document());
 }
 
 void HTMLStyleElement::setScoped(bool scopedValue)
@@ -296,7 +276,6 @@
 
     return toElement(parentOrHost);
 }
-#endif // ENABLE(STYLE_SCOPED)
 
 void HTMLStyleElement::dispatchPendingLoadEvents()
 {

Modified: trunk/Source/WebCore/html/HTMLStyleElement.h (130986 => 130987)


--- trunk/Source/WebCore/html/HTMLStyleElement.h	2012-10-11 01:00:26 UTC (rev 130986)
+++ trunk/Source/WebCore/html/HTMLStyleElement.h	2012-10-11 01:00:37 UTC (rev 130987)
@@ -41,12 +41,10 @@
 
     void setType(const AtomicString&);
 
-#if ENABLE(STYLE_SCOPED)
     bool scoped() const;
     void setScoped(bool);
     Element* scopingElement() const;
     bool isRegisteredAsScoped() const;
-#endif
 
     using StyleElement::sheet;
 
@@ -77,23 +75,19 @@
     virtual const AtomicString& media() const;
     virtual const AtomicString& type() const;
 
-#if ENABLE(STYLE_SCOPED)
     void scopedAttributeChanged(bool);
     void registerWithScopingNode(bool);
     void unregisterWithScopingNode(ContainerNode*);
-#endif
 
     bool m_firedLoad;
     bool m_loadedSheet;
 
-#if ENABLE(STYLE_SCOPED)
     enum ScopedStyleRegistrationState {
         NotRegistered,
         RegisteredAsScoped,
         RegisteredInShadowRoot
     };
     ScopedStyleRegistrationState m_scopedStyleRegistrationState;
-#endif
 };
 
 } //namespace

Modified: trunk/Source/WebCore/testing/InternalSettings.cpp (130986 => 130987)


--- trunk/Source/WebCore/testing/InternalSettings.cpp	2012-10-11 01:00:26 UTC (rev 130986)
+++ trunk/Source/WebCore/testing/InternalSettings.cpp	2012-10-11 01:00:37 UTC (rev 130987)
@@ -79,6 +79,9 @@
     , m_originalShadowDOMEnabled(RuntimeEnabledFeatures::shadowDOMEnabled())
     , m_originalAuthorShadowDOMForAnyElementEnabled(RuntimeEnabledFeatures::authorShadowDOMForAnyElementEnabled())
 #endif
+#if ENABLE(STYLE_SCOPED)
+    , m_originalStyleScoped(RuntimeEnabledFeatures::styleScopedEnabled())
+#endif
     , m_originalEditingBehavior(settings->editingBehaviorType())
     , m_originalUnifiedSpellCheckerEnabled(settings->unifiedTextCheckerEnabled())
     , m_originalFixedPositionCreatesStackingContext(settings->fixedPositionCreatesStackingContext())
@@ -114,6 +117,9 @@
     RuntimeEnabledFeatures::setShadowDOMEnabled(m_originalShadowDOMEnabled);
     RuntimeEnabledFeatures::setAuthorShadowDOMForAnyElementEnabled(m_originalAuthorShadowDOMForAnyElementEnabled);
 #endif
+#if ENABLE(STYLE_SCOPED)
+    RuntimeEnabledFeatures::setStyleScopedEnabled(m_originalStyleScoped);
+#endif
     settings->setEditingBehaviorType(m_originalEditingBehavior);
     settings->setUnifiedTextCheckerEnabled(m_originalUnifiedSpellCheckerEnabled);
     settings->setFixedPositionCreatesStackingContext(m_originalFixedPositionCreatesStackingContext);
@@ -302,6 +308,15 @@
 #endif
 }
 
+void InternalSettings::setStyleScopedEnabled(bool enabled)
+{
+#if ENABLE(STYLE_SCOPED)
+    RuntimeEnabledFeatures::setStyleScopedEnabled(enabled);
+#else
+    UNUSED_PARAM(enabled);
+#endif
+}
+
 void InternalSettings::setTouchEventEmulationEnabled(bool enabled, ExceptionCode& ec)
 {
 #if ENABLE(TOUCH_EVENTS)

Modified: trunk/Source/WebCore/testing/InternalSettings.h (130986 => 130987)


--- trunk/Source/WebCore/testing/InternalSettings.h	2012-10-11 01:00:26 UTC (rev 130986)
+++ trunk/Source/WebCore/testing/InternalSettings.h	2012-10-11 01:00:37 UTC (rev 130987)
@@ -61,6 +61,9 @@
         bool m_originalShadowDOMEnabled;
         bool m_originalAuthorShadowDOMForAnyElementEnabled;
 #endif
+#if ENABLE(STYLE_SCOPED)
+        bool m_originalStyleScoped;
+#endif
         EditingBehaviorType m_originalEditingBehavior;
         bool m_originalUnifiedSpellCheckerEnabled;
         bool m_originalFixedPositionCreatesStackingContext;
@@ -113,6 +116,7 @@
     void setDeviceSupportsMouse(bool enabled, ExceptionCode&);
     void setShadowDOMEnabled(bool enabled, ExceptionCode&);
     void setAuthorShadowDOMForAnyElementEnabled(bool);
+    void setStyleScopedEnabled(bool);
     void setStandardFontFamily(const String& family, const String& script, ExceptionCode&);
     void setSerifFontFamily(const String& family, const String& script, ExceptionCode&);
     void setSansSerifFontFamily(const String& family, const String& script, ExceptionCode&);

Modified: trunk/Source/WebCore/testing/InternalSettings.idl (130986 => 130987)


--- trunk/Source/WebCore/testing/InternalSettings.idl	2012-10-11 01:00:26 UTC (rev 130986)
+++ trunk/Source/WebCore/testing/InternalSettings.idl	2012-10-11 01:00:37 UTC (rev 130987)
@@ -46,6 +46,7 @@
         void setDeviceSupportsMouse(in boolean enabled) raises(DOMException);
         void setShadowDOMEnabled(in boolean enabled) raises(DOMException);
         void setAuthorShadowDOMForAnyElementEnabled(in boolean isEnabled);
+        void setStyleScopedEnabled(in boolean isEnabled);
         void setStandardFontFamily(in DOMString family, in DOMString script) raises(DOMException);
         void setSerifFontFamily(in DOMString family, in DOMString script) raises(DOMException);
         void setSansSerifFontFamily(in DOMString family, in DOMString script) raises(DOMException);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to