ShadowRoot needs resetStyleInheritance
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Jun 2012 05:29:01 +0000 (05:29 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Jun 2012 05:29:01 +0000 (05:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=84048

Source/WebCore:

Added resetStyleInheritance API to ShadowRoot. The spec URL is
http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#shadow-root-attributes
To implement the API, modified StyleResolver to use empty style
instead of parent style if resetStyleInheritance is true,
and a node and its parent node are placed in different shadow trees.

Patch by Takashi Sakamoto <tasak@google.com> on 2012-06-07
Reviewed by Hajime Morita.

Test: fast/dom/shadow/shadow-root-resetStyleInheritance.html
      fast/dom/shadow/shadow-root-resetStyleInheritance-expected.html

* css/StyleResolver.cpp:
(WebCore::StyleResolver::initForStyleResolve):
Set m_parentStyle to NULL when resetStyleInheritance.
(WebCore::StyleResolver::documentSettings):
Added a new method to obtain current document's settings.
(WebCore::StyleResolver::initializeFontStyle):
Initialize m_style by using document settings. Its code was move
from the code initializing font style in applyProperty.
(WebCore::StyleResolver::styleForElement):
Initialize font style if m_parentStyle is NULL. The old code just
used style() and don't touch font style. The new code uses the above
initializeFontStyle.
(WebCore::StyleResolver::applyProperty):
Moved a code for initializing font style as "initial" to
a new method: initializeFontStyle and modified to use the method.
Modified to use documentSettings().
(WebCore::StyleResolver::checkForGenericFamilyChange):
Modified to use documentSettings().
* css/StyleResolver.h:
(WebCore::StyleResolver::documentSettings):
(WebCore::StyleResolver::initializeFontStyle):
Added two new methods to class StyleResolver.
* dom/NodeRenderingContext.cpp:
(WebCore::NodeRenderingContext::NodeRenderingContext):
Modified to calculate m_resetStyleInheritance in its constructor.
* dom/NodeRenderingContext.h:
(WebCore::NodeRenderingContext::resetStyleInheritance):
Implemented a new method, just returning m_resetStyleInheritance.
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::setResetStyleInheritance):
Modified to force to recalculate children's styles if
resetStyleInheritance is changed.
* dom/ShadowRoot.h:
(ShadowRoot):
Added resetStyleInheritance getter and setter.
* dom/ShadowRoot.idl:
Added an attribute, resetStyleInheritance.
* dom/TreeScope.cpp:
(WebCore::TreeScope::resetStyleInheritance):
* dom/TreeScope.h:
(TreeScope):
Added resetStyleInheritance's default getter.
The getter will be overrided by class ShadowRoot's getter.

LayoutTests:

Added layout tests for checking whether resetStyleInheritance works correctly or not.

Patch by Takashi Sakamoto <tasak@google.com> on 2012-06-07
Reviewed by Hajime Morita.

* fast/dom/shadow/shadow-root-resetStyleInheritance.html: Added.
* fast/dom/shadow/shadow-root-resetStyleInheritance-expected.html: Added.

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

13 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/shadow/shadow-root-resetStyleInheritance-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/shadow-root-resetStyleInheritance.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/StyleResolver.cpp
Source/WebCore/css/StyleResolver.h
Source/WebCore/dom/NodeRenderingContext.cpp
Source/WebCore/dom/NodeRenderingContext.h
Source/WebCore/dom/ShadowRoot.cpp
Source/WebCore/dom/ShadowRoot.h
Source/WebCore/dom/ShadowRoot.idl
Source/WebCore/dom/TreeScope.cpp
Source/WebCore/dom/TreeScope.h

index 5dc9415..ed2b036 100644 (file)
@@ -1,3 +1,15 @@
+2012-06-07  Takashi Sakamoto  <tasak@google.com>
+
+        ShadowRoot needs resetStyleInheritance
+        https://bugs.webkit.org/show_bug.cgi?id=84048
+
+        Added layout tests for checking whether resetStyleInheritance works correctly or not.
+
+        Reviewed by Hajime Morita.
+
+        * fast/dom/shadow/shadow-root-resetStyleInheritance.html: Added.
+        * fast/dom/shadow/shadow-root-resetStyleInheritance-expected.html: Added.
+
 2012-06-07  Kinuko Yasuda  <kinuko@chromium.org>
 
         Fix unmatched parenthesis in fast/dom/HTMLAnchorElement/anchor-download-unset.html
diff --git a/LayoutTests/fast/dom/shadow/shadow-root-resetStyleInheritance-expected.html b/LayoutTests/fast/dom/shadow/shadow-root-resetStyleInheritance-expected.html
new file mode 100644 (file)
index 0000000..afdeb65
--- /dev/null
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+div.resetTest {
+  background-color: #eef;
+  border: solid;
+  margin: 4px;
+  padding: 16px;
+  color: #fee;
+  font-family: Serif;
+  font-size: 24px;
+  font-style: italic;
+  font-variant: small-caps;
+  font-weight: bold;
+  letter-spacing: 2px;
+  line-height: 200%;
+  text-align: start;
+  text-indent: 50px;
+  text-transform: uppercase;
+  white-space: nowrap;
+  word-spacing: 30px;
+}
+div.initialValues {
+  color: initial;
+  font-family: initial;
+  font-size: initial;
+  font-style: initial;
+  font-variant: initial;
+  font-weight: initial;
+  letter-spacing: initial;
+  line-height: initial;
+  text-align: initial;
+  text-indent: initial;
+  text-transform: initial;
+  white-space: initial;
+  word-spacing: initial;
+}
+</style>
+</head>
+<body>
+<div><div class="resetTest"><div class="initialValues">text</div></div></div>
+<div><div class="resetTest"><div>text</div></div></div>
+<div><div class="resetTest"><div>text</div></div></div>
+<div><div class="resetTest"><div class="initialValues">text</div></div></div>
+<div><div class="resetTest"><div class="initialValues">text</div></div></div>
+<div><div class="resetTest"><div>text</div></div></div>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/shadow/shadow-root-resetStyleInheritance.html b/LayoutTests/fast/dom/shadow/shadow-root-resetStyleInheritance.html
new file mode 100644 (file)
index 0000000..c1b8d26
--- /dev/null
@@ -0,0 +1,169 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+div.resetTest {
+  background-color: #eef;
+  border: solid;
+  margin: 4px;
+  padding: 16px;
+  color: #fee;
+  font-family: Serif;
+  font-size: 24px;
+  font-style: italic;
+  font-variant: small-caps;
+  font-weight: bold;
+  letter-spacing: 2px;
+  line-height: 200%;
+  text-align: start;
+  text-indent: 50px;
+  text-transform: uppercase;
+  white-space: nowrap;
+  word-spacing: 30px;
+}
+</style>
+<script>
+function assertTrue(id, actual) {
+    if (!actual)
+        throw "failure:" + id + ": assertTrue failed";
+}
+
+function assertFalse(id, actual) {
+    if (actual)
+        throw "failure:" + id +  ": assertFalse failed";
+}
+
+function shouldBe(a, b)
+{
+    if (a != b)
+        throw "failure:" + a + ": should be " + b;
+}
+
+function shouldNotBe(a, b)
+{
+    if (a == b)
+        throw "failure:" + a + ": should not be " + b;
+}
+</script>
+<script src="resources/polyfill.js"></script>
+</head>
+<body>
+<div id="reset-style-inheritance"></div>
+<div id="no-reset-style-inheritance"></div>
+<div id="reset-style-inheritance-true-to-false"></div>
+<div id="reset-style-inheritance-false-to-true"></div>
+<div id="reset-style-inheritance-for-content"></div>
+<div id="no-reset-style-inheritance-for-content"></div>
+
+<script>
+function renderWithNoResetStyleInheritance() {
+    var div = document.createElement('div');
+    div.className = 'resetTest';
+
+    var shadowRoot = new WebKitShadowRoot(div);
+    assertFalse('default resetStyleInheritance should be false', shadowRoot.resetStyleInheritance);
+    shadowRoot.innerHTML = '<div>text</div>';
+    
+    document.getElementById('no-reset-style-inheritance').appendChild(div);
+}
+
+function renderWithResetStyleInheritance() {
+    var div = document.createElement('div');
+    div.className = 'resetTest';
+
+    var shadowRoot = new WebKitShadowRoot(div);
+    assertFalse('default resetStyleInheritance should be false', shadowRoot.resetStyleInheritance);
+    shadowRoot.resetStyleInheritance = true;
+    shadowRoot.innerHTML = '<div>text</div>';
+    assertTrue('resetStyleInheritance should be true as explicitly set', shadowRoot.resetStyleInheritance);
+    
+    document.getElementById('reset-style-inheritance').appendChild(div);
+}
+
+function renderWithChangingResetStyleInheritanceFromTrueToFalse() {
+    var div = document.createElement('div');
+    div.className = 'resetTest';
+
+    var shadowRoot = new WebKitShadowRoot(div);
+    assertFalse('default resetStyleInheritance should be false', shadowRoot.resetStyleInheritance);
+    shadowRoot.resetStyleInheritance = true;
+    shadowRoot.innerHTML = '<div id="test1">text</div>';
+    assertTrue('resetStyleInheritance should be true', shadowRoot.resetStyleInheritance);
+    
+    document.getElementById('reset-style-inheritance-true-to-false').appendChild(div);
+    div.offsetLeft;
+    var target = shadowRoot.getElementById('test1');
+    shouldNotBe(window.getComputedStyle(target).getPropertyValue('font-family'), 'serif');
+    shouldNotBe(window.getComputedStyle(target).getPropertyValue('line-height'), '48px');
+
+    shadowRoot.resetStyleInheritance = false;
+    assertFalse('resetStyleInheritance should be false', shadowRoot.resetStyleInheritance);
+    div.offsetLeft;
+    shouldBe(window.getComputedStyle(target).getPropertyValue('font-family'), 'serif');
+    shouldBe(window.getComputedStyle(target).getPropertyValue('line-height'), '48px');
+}
+
+function renderWithChangingResetStyleInheritanceFromFalseToTrue() {
+    var div = document.createElement('div');
+    div.className = 'resetTest';
+
+    var shadowRoot = new WebKitShadowRoot(div);
+    assertFalse('default resetStyleInheritance should be false', shadowRoot.resetStyleInheritance);
+    shadowRoot.resetStyleInheritance = false;
+    shadowRoot.innerHTML = '<div id="test2">text</div>';
+    assertFalse('default resetStyleInheritance should be false', shadowRoot.resetStyleInheritance);
+    
+    document.getElementById('reset-style-inheritance-false-to-true').appendChild(div);
+    div.offsetLeft;
+    var target = shadowRoot.getElementById('test2');
+    shouldBe(window.getComputedStyle(target).getPropertyValue('font-family'), 'serif');
+    shouldBe(window.getComputedStyle(target).getPropertyValue('line-height'), '48px');
+
+    shadowRoot.resetStyleInheritance = true;
+    assertTrue('resetStyleInheritance should be true', shadowRoot.resetStyleInheritance);
+    div.offsetLeft;
+    shouldNotBe(window.getComputedStyle(target).getPropertyValue('font-family'), 'serif');
+    shouldNotBe(window.getComputedStyle(target).getPropertyValue('line-height'), '48px');
+}
+
+function createDivWithText(text) {
+    var div = document.createElement('div');
+    div.appendChild(document.createTextNode(text));
+    return div;
+}
+
+function renderResetStyleInheritanceForContent() {
+    var div = document.createElement('div');
+    div.className = 'resetTest';
+    div.appendChild(createDivWithText('text'));
+
+    var shadowRoot = new WebKitShadowRoot(div);
+    shadowRoot.innerHTML = '<content select="div"></content>';
+    shadowRoot.resetStyleInheritance = true;
+    assertTrue('resetStyleInheritance should be true', shadowRoot.resetStyleInheritance);
+    document.getElementById('reset-style-inheritance-for-content').appendChild(div);
+    div.offsetLeft;
+}
+
+function renderNoResetStyleInheritanceForContent() {
+    var div = document.createElement('div');
+    div.className = 'resetTest';
+    div.appendChild(createDivWithText('text'));
+
+    var shadowRoot = new WebKitShadowRoot(div);
+    shadowRoot.innerHTML = '<content select="div"></content>';
+    shadowRoot.resetStyleInheritance = false;
+    assertFalse('resetStyleInheritance should be false', shadowRoot.resetStyleInheritance);
+    document.getElementById('no-reset-style-inheritance-for-content').appendChild(div);
+    div.offsetLeft;
+}
+
+renderWithNoResetStyleInheritance();
+renderWithResetStyleInheritance();
+renderWithChangingResetStyleInheritanceFromTrueToFalse();
+renderWithChangingResetStyleInheritanceFromFalseToTrue();
+renderResetStyleInheritanceForContent();
+renderNoResetStyleInheritanceForContent();
+</script>
+</body>
+</html>
index d72ca5d..dd63efe 100644 (file)
@@ -1,3 +1,63 @@
+2012-06-07  Takashi Sakamoto  <tasak@google.com>
+
+        ShadowRoot needs resetStyleInheritance
+        https://bugs.webkit.org/show_bug.cgi?id=84048
+
+        Added resetStyleInheritance API to ShadowRoot. The spec URL is
+        http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#shadow-root-attributes
+        To implement the API, modified StyleResolver to use empty style
+        instead of parent style if resetStyleInheritance is true,
+        and a node and its parent node are placed in different shadow trees.
+
+        Reviewed by Hajime Morita.
+
+        Test: fast/dom/shadow/shadow-root-resetStyleInheritance.html
+              fast/dom/shadow/shadow-root-resetStyleInheritance-expected.html
+
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::initForStyleResolve):
+        Set m_parentStyle to NULL when resetStyleInheritance.
+        (WebCore::StyleResolver::documentSettings):
+        Added a new method to obtain current document's settings.
+        (WebCore::StyleResolver::initializeFontStyle):
+        Initialize m_style by using document settings. Its code was move
+        from the code initializing font style in applyProperty.
+        (WebCore::StyleResolver::styleForElement):
+        Initialize font style if m_parentStyle is NULL. The old code just
+        used style() and don't touch font style. The new code uses the above
+        initializeFontStyle.
+        (WebCore::StyleResolver::applyProperty):
+        Moved a code for initializing font style as "initial" to
+        a new method: initializeFontStyle and modified to use the method.
+        Modified to use documentSettings().
+        (WebCore::StyleResolver::checkForGenericFamilyChange):
+        Modified to use documentSettings().
+        * css/StyleResolver.h:
+        (WebCore::StyleResolver::documentSettings):
+        (WebCore::StyleResolver::initializeFontStyle):
+        Added two new methods to class StyleResolver.
+        * dom/NodeRenderingContext.cpp:
+        (WebCore::NodeRenderingContext::NodeRenderingContext):
+        Modified to calculate m_resetStyleInheritance in its constructor.
+        * dom/NodeRenderingContext.h:
+        (WebCore::NodeRenderingContext::resetStyleInheritance):
+        Implemented a new method, just returning m_resetStyleInheritance.
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::setResetStyleInheritance):
+        Modified to force to recalculate children's styles if
+        resetStyleInheritance is changed.
+        * dom/ShadowRoot.h:
+        (ShadowRoot):
+        Added resetStyleInheritance getter and setter.
+        * dom/ShadowRoot.idl:
+        Added an attribute, resetStyleInheritance.
+        * dom/TreeScope.cpp:
+        (WebCore::TreeScope::resetStyleInheritance):
+        * dom/TreeScope.h:
+        (TreeScope):
+        Added resetStyleInheritance's default getter.
+        The getter will be overrided by class ShadowRoot's getter.
+
 2012-06-07  Victor Carbune  <victor@rosedu.org>
 
         addTextTrack should set track mode to HIDDEN
index 648f61b..de3001c 100644 (file)
@@ -78,6 +78,7 @@
 #include "MediaList.h"
 #include "MediaQueryEvaluator.h"
 #include "NodeRenderStyle.h"
+#include "NodeRenderingContext.h"
 #include "Page.h"
 #include "PageGroup.h"
 #include "Pair.h"
@@ -1163,12 +1164,16 @@ inline void StyleResolver::initForStyleResolve(Element* e, RenderStyle* parentSt
 {
     m_checker.setPseudoStyle(pseudoID);
 
-    m_parentNode = e ? e->parentNodeForRenderingAndStyle() : 0;
-
-    if (parentStyle)
+    if (e) {
+        NodeRenderingContext context(e);
+        m_parentNode = context.parentNodeForRenderingAndStyle();
+        m_parentStyle = context.resetStyleInheritance()? 0 :
+            parentStyle ? parentStyle :
+            m_parentNode ? m_parentNode->renderStyle() : 0;
+    } else {
+        m_parentNode = 0;
         m_parentStyle = parentStyle;
-    else
-        m_parentStyle = m_parentNode ? m_parentNode->renderStyle() : 0;
+    }
 
     Node* docElement = e ? e->document()->documentElement() : 0;
     RenderStyle* docStyle = m_checker.document()->renderStyle();
@@ -1653,7 +1658,11 @@ PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS
     else {
         m_parentStyle = style();
         // Make sure our fonts are initialized if we don't inherit them from our parent style.
-        m_style->font().update(0);
+        if (Settings* settings = documentSettings()) {
+            initializeFontStyle(settings);
+            m_style->font().update(fontSelector());
+        } else
+            m_style->font().update(0);
     }
 
     // Even if surrounding content is user-editable, shadow DOM should act as a single unit, and not necessarily be editable
@@ -3347,7 +3356,7 @@ void StyleResolver::applyProperty(CSSPropertyID id, CSSValue *value)
                 continue;
             CSSPrimitiveValue* contentValue = static_cast<CSSPrimitiveValue*>(item);
             AtomicString face;
-            Settings* settings = m_checker.document()->settings();
+            Settings* settings = documentSettings();
             if (contentValue->isString())
                 face = contentValue->getStringValue();
             else if (settings) {
@@ -3431,24 +3440,11 @@ void StyleResolver::applyProperty(CSSPropertyID id, CSSValue *value)
             m_lineHeightValue = 0;
             setFontDescription(fontDescription);
         } else if (isInitial) {
-            Settings* settings = m_checker.document()->settings();
+            Settings* settings = documentSettings();
             ASSERT(settings); // If we're doing style resolution, this document should always be in a frame and thus have settings
             if (!settings)
                 return;
-            FontDescription fontDescription;
-            fontDescription.setGenericFamily(FontDescription::StandardFamily);
-            fontDescription.setRenderingMode(settings->fontRenderingMode());
-            fontDescription.setUsePrinterFont(m_checker.document()->printing());
-            const AtomicString& standardFontFamily = m_checker.document()->settings()->standardFontFamily();
-            if (!standardFontFamily.isEmpty()) {
-                fontDescription.firstFamily().setFamily(standardFontFamily);
-                fontDescription.firstFamily().appendFamily(0);
-            }
-            fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
-            setFontSize(fontDescription, fontSizeForKeyword(m_checker.document(), CSSValueMedium, false));
-            m_style->setLineHeight(RenderStyle::initialLineHeight());
-            m_lineHeightValue = 0;
-            setFontDescription(fontDescription);
+            initializeFontStyle(settings);
         } else if (primitiveValue) {
             m_style->setLineHeight(RenderStyle::initialLineHeight());
             m_lineHeightValue = 0;
@@ -3459,7 +3455,7 @@ void StyleResolver::applyProperty(CSSPropertyID id, CSSValue *value)
             // Double-check and see if the theme did anything. If not, don't bother updating the font.
             if (fontDescription.isAbsoluteSize()) {
                 // Make sure the rendering mode and printer font settings are updated.
-                Settings* settings = m_checker.document()->settings();
+                Settings* settings = documentSettings();
                 ASSERT(settings); // If we're doing style resolution, this document should always be in a frame and thus have settings
                 if (!settings)
                     return;
@@ -4912,7 +4908,7 @@ void StyleResolver::checkForGenericFamilyChange(RenderStyle* style, RenderStyle*
     if (childFont.keywordSize())
         size = fontSizeForKeyword(m_checker.document(), CSSValueXxSmall + childFont.keywordSize() - 1, childFont.useFixedDefaultSize());
     else {
-        Settings* settings = m_checker.document()->settings();
+        Settings* settings = documentSettings();
         float fixedScaleFactor = settings
             ? static_cast<float>(settings->defaultFixedFontSize()) / settings->defaultFontSize()
             : 1;
@@ -4926,6 +4922,24 @@ void StyleResolver::checkForGenericFamilyChange(RenderStyle* style, RenderStyle*
     style->setFontDescription(newFontDescription);
 }
 
+void StyleResolver::initializeFontStyle(Settings* settings)
+{
+    FontDescription fontDescription;
+    fontDescription.setGenericFamily(FontDescription::StandardFamily);
+    fontDescription.setRenderingMode(settings->fontRenderingMode());
+    fontDescription.setUsePrinterFont(m_checker.document()->printing());
+    const AtomicString& standardFontFamily = documentSettings()->standardFontFamily();
+    if (!standardFontFamily.isEmpty()) {
+        fontDescription.firstFamily().setFamily(standardFontFamily);
+        fontDescription.firstFamily().appendFamily(0);
+    }
+    fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
+    setFontSize(fontDescription, fontSizeForKeyword(m_checker.document(), CSSValueMedium, false));
+    m_style->setLineHeight(RenderStyle::initialLineHeight());
+    m_lineHeightValue = 0;
+    setFontDescription(fontDescription);
+}
+
 void StyleResolver::setFontSize(FontDescription& fontDescription, float size)
 {
     fontDescription.setSpecifiedSize(size);
index 539dd63..7e8f3a1 100644 (file)
@@ -208,6 +208,7 @@ public:
     void applyPropertyToCurrentStyle(CSSPropertyID, CSSValue*);
 
     void updateFont();
+    void initializeFontStyle(Settings*);
 
     static float getComputedSizeFromSpecifiedSize(Document*, float zoomFactor, bool isAbsoluteSize, float specifiedSize, ESmartMinimumForFontSize = UseSmartMinimumForFontFize);
 
@@ -366,6 +367,8 @@ private:
 
     void matchPageRules(MatchResult&, RuleSet*, bool isLeftPage, bool isFirstPage, const String& pageName);
     void matchPageRulesForList(Vector<StyleRulePage*>& matchedRules, const Vector<StyleRulePage*>&, bool isLeftPage, bool isFirstPage, const String& pageName);
+    Settings* documentSettings() { return m_checker.document()->settings(); }
+
     bool isLeftPage(int pageIndex) const;
     bool isRightPage(int pageIndex) const { return !isLeftPage(pageIndex); }
     bool isFirstPage(int pageIndex) const;
index 7f70e7c..b4d6d46 100644 (file)
@@ -55,6 +55,7 @@ NodeRenderingContext::NodeRenderingContext(Node* node)
     : m_phase(AttachingNotInTree)
     , m_node(node)
     , m_parentNodeForRenderingAndStyle(0)
+    , m_resetStyleInheritance(false)
     , m_visualParentShadow(0)
     , m_insertionPoint(0)
     , m_style(0)
@@ -67,6 +68,7 @@ NodeRenderingContext::NodeRenderingContext(Node* node)
     if (parent->isShadowRoot() && toShadowRoot(parent)->isYoungest()) {
         m_phase = AttachingShadowChild;
         m_parentNodeForRenderingAndStyle = toShadowRoot(parent)->host();
+        m_resetStyleInheritance = toShadowRoot(parent)->resetStyleInheritance();
         return;
     }
 
@@ -82,7 +84,9 @@ NodeRenderingContext::NodeRenderingContext(Node* node)
             if ((m_insertionPoint = m_visualParentShadow->insertionPointFor(m_node))) {
                 if (m_insertionPoint->shadowRoot()->isUsedForRendering()) {
                     m_phase = AttachingDistributed;
-                    m_parentNodeForRenderingAndStyle = NodeRenderingContext(m_insertionPoint).parentNodeForRenderingAndStyle();
+                    NodeRenderingContext insertionPointContext(m_insertionPoint);
+                    m_parentNodeForRenderingAndStyle = insertionPointContext.parentNodeForRenderingAndStyle();
+                    m_resetStyleInheritance = insertionPointContext.resetStyleInheritance();
                     return;
                 }
             }
@@ -107,9 +111,11 @@ NodeRenderingContext::NodeRenderingContext(Node* node)
             else
                 m_phase = AttachingFallbacked;
 
-            if (toInsertionPoint(parent)->isActive())
-                m_parentNodeForRenderingAndStyle = NodeRenderingContext(parent).parentNodeForRenderingAndStyle();
-            else
+            if (toInsertionPoint(parent)->isActive()) {
+                NodeRenderingContext parentContext(parent);
+                m_parentNodeForRenderingAndStyle = parentContext.parentNodeForRenderingAndStyle();
+                m_resetStyleInheritance = parentContext.resetStyleInheritance();
+            } else
                 m_parentNodeForRenderingAndStyle = parent;
             return;
         }
@@ -123,6 +129,7 @@ NodeRenderingContext::NodeRenderingContext(Node* node, RenderStyle* style)
     : m_phase(Calculating)
     , m_node(node)
     , m_parentNodeForRenderingAndStyle(0)
+    , m_resetStyleInheritance(false)
     , m_visualParentShadow(0)
     , m_insertionPoint(0)
     , m_style(style)
index 7b14e03..60792cb 100644 (file)
@@ -49,6 +49,7 @@ public:
 
     Node* node() const;
     ContainerNode* parentNodeForRenderingAndStyle() const;
+    bool resetStyleInheritance() const;
     RenderObject* parentRenderer() const;
     RenderObject* nextRenderer() const;
     RenderObject* previousRenderer() const;
@@ -81,6 +82,7 @@ private:
     AttachingPhase m_phase;
     Node* m_node;
     ContainerNode* m_parentNodeForRenderingAndStyle;
+    bool m_resetStyleInheritance;
     ElementShadow* m_visualParentShadow;
     InsertionPoint* m_insertionPoint;
     RefPtr<RenderStyle> m_style;
@@ -99,6 +101,12 @@ inline ContainerNode* NodeRenderingContext::parentNodeForRenderingAndStyle() con
     return m_parentNodeForRenderingAndStyle;
 }
 
+inline bool NodeRenderingContext::resetStyleInheritance() const
+{
+    ASSERT(m_phase != Calculating);
+    return m_resetStyleInheritance;
+}
+
 inline RenderStyle* NodeRenderingContext::style() const
 {
     return m_style.get();
index 6723a0f..2c57560 100644 (file)
@@ -50,6 +50,7 @@ ShadowRoot::ShadowRoot(Document* document)
     , m_prev(0)
     , m_next(0)
     , m_applyAuthorStyles(false)
+    , m_resetStyleInheritance(false)
     , m_insertionPointAssignedTo(0)
 {
     ASSERT(document);
@@ -193,6 +194,20 @@ void ShadowRoot::setApplyAuthorStyles(bool value)
     }
 }
 
+bool ShadowRoot::resetStyleInheritance() const
+{
+    return m_resetStyleInheritance;
+}
+
+void ShadowRoot::setResetStyleInheritance(bool value)
+{
+    if (value != m_resetStyleInheritance) {
+        m_resetStyleInheritance = value;
+        if (attached() && owner())
+            owner()->recalcStyle(Force);
+    }
+}
+
 void ShadowRoot::attach()
 {
     StyleResolver* styleResolver = document()->styleResolver();
index 0b7ffa5..6a76e4f 100644 (file)
@@ -63,6 +63,8 @@ public:
 
     virtual bool applyAuthorStyles() const OVERRIDE;
     void setApplyAuthorStyles(bool);
+    virtual bool resetStyleInheritance() const OVERRIDE;
+    void setResetStyleInheritance(bool);
 
     Element* host() const;
     void setHost(Element*);
@@ -98,6 +100,7 @@ private:
     ShadowRoot* m_prev;
     ShadowRoot* m_next;
     bool m_applyAuthorStyles : 1;
+    bool m_resetStyleInheritance : 1;
     InsertionPoint* m_insertionPointAssignedTo;
 };
 
index 8110c1e..00f7cd8 100644 (file)
@@ -34,6 +34,7 @@ module core {
         readonly attribute Element host;
         readonly attribute Element activeElement;
         attribute boolean applyAuthorStyles;
+        attribute boolean resetStyleInheritance;
 
         attribute [TreatNullAs=NullString] DOMString innerHTML
             setter raises(DOMException);
index d70b900..8322fcb 100644 (file)
@@ -191,6 +191,11 @@ bool TreeScope::applyAuthorStyles() const
     return true;
 }
 
+bool TreeScope::resetStyleInheritance() const
+{
+    return false;
+}
+
 void TreeScope::adoptIfNeeded(Node* node)
 {
     ASSERT(this);
index 0d1dceb..5ecc039 100644 (file)
@@ -75,6 +75,7 @@ public:
     Element* findAnchor(const String& name);
 
     virtual bool applyAuthorStyles() const;
+    virtual bool resetStyleInheritance() const;
 
     // Used by the basic DOM mutation methods (e.g., appendChild()).
     void adoptIfNeeded(Node*);