| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 #include "core/dom/shadow/ShadowRoot.h" | 28 #include "core/dom/shadow/ShadowRoot.h" |
| 29 | 29 |
| 30 #include "bindings/v8/ExceptionState.h" | 30 #include "bindings/v8/ExceptionState.h" |
| 31 #include "core/css/StyleSheetList.h" | 31 #include "core/css/StyleSheetList.h" |
| 32 #include "core/css/resolver/StyleResolver.h" | 32 #include "core/css/resolver/StyleResolver.h" |
| 33 #include "core/css/resolver/StyleResolverParentScope.h" |
| 33 #include "core/dom/ElementTraversal.h" | 34 #include "core/dom/ElementTraversal.h" |
| 34 #include "core/dom/StyleEngine.h" | 35 #include "core/dom/StyleEngine.h" |
| 35 #include "core/dom/Text.h" | 36 #include "core/dom/Text.h" |
| 36 #include "core/dom/shadow/ElementShadow.h" | 37 #include "core/dom/shadow/ElementShadow.h" |
| 37 #include "core/dom/shadow/InsertionPoint.h" | 38 #include "core/dom/shadow/InsertionPoint.h" |
| 38 #include "core/dom/shadow/ShadowRootRareData.h" | 39 #include "core/dom/shadow/ShadowRootRareData.h" |
| 39 #include "core/editing/markup.h" | 40 #include "core/editing/markup.h" |
| 40 #include "core/html/HTMLShadowElement.h" | 41 #include "core/html/HTMLShadowElement.h" |
| 41 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
| 42 | 43 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 134 |
| 134 if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(mark
up, host(), AllowScriptingContent, "innerHTML", exceptionState)) | 135 if (RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(mark
up, host(), AllowScriptingContent, "innerHTML", exceptionState)) |
| 135 replaceChildrenWithFragment(this, fragment.release(), exceptionState); | 136 replaceChildrenWithFragment(this, fragment.release(), exceptionState); |
| 136 } | 137 } |
| 137 | 138 |
| 138 void ShadowRoot::recalcStyle(StyleRecalcChange change) | 139 void ShadowRoot::recalcStyle(StyleRecalcChange change) |
| 139 { | 140 { |
| 140 // ShadowRoot doesn't support custom callbacks. | 141 // ShadowRoot doesn't support custom callbacks. |
| 141 ASSERT(!hasCustomStyleCallbacks()); | 142 ASSERT(!hasCustomStyleCallbacks()); |
| 142 | 143 |
| 143 StyleResolver& styleResolver = document().ensureStyleResolver(); | 144 StyleResolverParentScope parentScope(*this); |
| 144 styleResolver.pushParentShadowRoot(*this); | |
| 145 | 145 |
| 146 if (styleChangeType() >= SubtreeStyleChange) | 146 if (styleChangeType() >= SubtreeStyleChange) |
| 147 change = Force; | 147 change = Force; |
| 148 | 148 |
| 149 if (change < Force && hasRareData() && childNeedsStyleRecalc()) | 149 if (change < Force && hasRareData() && childNeedsStyleRecalc()) |
| 150 checkForChildrenAdjacentRuleChanges(); | 150 checkForChildrenAdjacentRuleChanges(); |
| 151 | 151 |
| 152 // There's no style to update so just calling recalcStyle means we're update
d. | 152 // There's no style to update so just calling recalcStyle means we're update
d. |
| 153 clearNeedsStyleRecalc(); | 153 clearNeedsStyleRecalc(); |
| 154 | 154 |
| 155 // FIXME: This doesn't handle :hover + div properly like Element::recalcStyl
e does. | 155 // FIXME: This doesn't handle :hover + div properly like Element::recalcStyl
e does. |
| 156 Text* lastTextNode = 0; | 156 Text* lastTextNode = 0; |
| 157 for (Node* child = lastChild(); child; child = child->previousSibling()) { | 157 for (Node* child = lastChild(); child; child = child->previousSibling()) { |
| 158 if (child->isTextNode()) { | 158 if (child->isTextNode()) { |
| 159 toText(child)->recalcTextStyle(change, lastTextNode); | 159 toText(child)->recalcTextStyle(change, lastTextNode); |
| 160 lastTextNode = toText(child); | 160 lastTextNode = toText(child); |
| 161 } else if (child->isElementNode()) { | 161 } else if (child->isElementNode()) { |
| 162 if (child->shouldCallRecalcStyle(change)) | 162 if (child->shouldCallRecalcStyle(change)) |
| 163 toElement(child)->recalcStyle(change, lastTextNode); | 163 toElement(child)->recalcStyle(change, lastTextNode); |
| 164 if (child->renderer()) | 164 if (child->renderer()) |
| 165 lastTextNode = 0; | 165 lastTextNode = 0; |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 styleResolver.popParentShadowRoot(*this); | |
| 170 | |
| 171 clearChildNeedsStyleRecalc(); | 169 clearChildNeedsStyleRecalc(); |
| 172 } | 170 } |
| 173 | 171 |
| 174 void ShadowRoot::setApplyAuthorStyles(bool value) | 172 void ShadowRoot::setApplyAuthorStyles(bool value) |
| 175 { | 173 { |
| 176 if (isOrphan()) | 174 if (isOrphan()) |
| 177 return; | 175 return; |
| 178 | 176 |
| 179 if (applyAuthorStyles() == value) | 177 if (applyAuthorStyles() == value) |
| 180 return; | 178 return; |
| 181 | 179 |
| 182 m_applyAuthorStyles = value; | 180 m_applyAuthorStyles = value; |
| 183 | 181 |
| 184 ASSERT(host()); | 182 ASSERT(host()); |
| 185 ASSERT(host()->shadow()); | 183 ASSERT(host()->shadow()); |
| 186 if (host()->shadow()->didAffectApplyAuthorStyles()) | 184 if (host()->shadow()->didAffectApplyAuthorStyles()) |
| 187 host()->setNeedsStyleRecalc(SubtreeStyleChange); | 185 host()->setNeedsStyleRecalc(SubtreeStyleChange); |
| 188 | 186 |
| 189 // Since styles in shadow trees can select shadow hosts, set shadow host's n
eeds-recalc flag true. | 187 // Since styles in shadow trees can select shadow hosts, set shadow host's n
eeds-recalc flag true. |
| 190 // FIXME: host->setNeedsStyleRecalc() should take care of all elements in it
s shadow tree. | 188 // FIXME: host->setNeedsStyleRecalc() should take care of all elements in it
s shadow tree. |
| 191 // However, when host's recalcStyle is skipped (i.e. host's parent has no re
nderer), | 189 // However, when host's recalcStyle is skipped (i.e. host's parent has no re
nderer), |
| 192 // no recalc style is invoked for any elements in its shadow tree. | 190 // no recalc style is invoked for any elements in its shadow tree. |
| 193 // This problem occurs when using getComputedStyle() API. | 191 // This problem occurs when using getComputedStyle() API. |
| 194 // So currently host and shadow root's needsStyleRecalc flags are set to be
true. | 192 // So currently host and shadow root's needsStyleRecalc flags are set to be
true. |
| 195 setNeedsStyleRecalc(SubtreeStyleChange); | 193 setNeedsStyleRecalc(SubtreeStyleChange); |
| 196 } | 194 } |
| 197 | 195 |
| 198 void ShadowRoot::attach(const AttachContext& context) | 196 void ShadowRoot::attach(const AttachContext& context) |
| 199 { | 197 { |
| 200 StyleResolver& styleResolver = document().ensureStyleResolver(); | 198 StyleResolverParentScope parentScope(*this); |
| 201 styleResolver.pushParentShadowRoot(*this); | |
| 202 DocumentFragment::attach(context); | 199 DocumentFragment::attach(context); |
| 203 styleResolver.popParentShadowRoot(*this); | |
| 204 } | 200 } |
| 205 | 201 |
| 206 Node::InsertionNotificationRequest ShadowRoot::insertedInto(ContainerNode* inser
tionPoint) | 202 Node::InsertionNotificationRequest ShadowRoot::insertedInto(ContainerNode* inser
tionPoint) |
| 207 { | 203 { |
| 208 DocumentFragment::insertedInto(insertionPoint); | 204 DocumentFragment::insertedInto(insertionPoint); |
| 209 | 205 |
| 210 if (!insertionPoint->inDocument() || !isOldest()) | 206 if (!insertionPoint->inDocument() || !isOldest()) |
| 211 return InsertionDone; | 207 return InsertionDone; |
| 212 | 208 |
| 213 // FIXME: When parsing <video controls>, insertedInto() is called many times
without invoking removedFrom. | 209 // FIXME: When parsing <video controls>, insertedInto() is called many times
without invoking removedFrom. |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 358 |
| 363 StyleSheetList* ShadowRoot::styleSheets() | 359 StyleSheetList* ShadowRoot::styleSheets() |
| 364 { | 360 { |
| 365 if (!ensureShadowRootRareData()->styleSheets()) | 361 if (!ensureShadowRootRareData()->styleSheets()) |
| 366 m_shadowRootRareData->setStyleSheets(StyleSheetList::create(this)); | 362 m_shadowRootRareData->setStyleSheets(StyleSheetList::create(this)); |
| 367 | 363 |
| 368 return m_shadowRootRareData->styleSheets(); | 364 return m_shadowRootRareData->styleSheets(); |
| 369 } | 365 } |
| 370 | 366 |
| 371 } | 367 } |
| OLD | NEW |