Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/WebKit/Source/core/dom/Document.cpp

Issue 2775563002: getComputedStyle should not always force a layout inside shadow trees. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSComputedStyleDeclaration.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All
7 * rights reserved. 7 * rights reserved.
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/) 9 * (http://www.torchmobile.com/)
10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
(...skipping 2138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 2149
2150 m_lifecycle.advanceTo(DocumentLifecycle::InLayoutSubtreeChange); 2150 m_lifecycle.advanceTo(DocumentLifecycle::InLayoutSubtreeChange);
2151 2151
2152 layoutViewItem().handleSubtreeModifications(); 2152 layoutViewItem().handleSubtreeModifications();
2153 DCHECK(!layoutViewItem().wasNotifiedOfSubtreeChange()); 2153 DCHECK(!layoutViewItem().wasNotifiedOfSubtreeChange());
2154 2154
2155 m_lifecycle.advanceTo(DocumentLifecycle::LayoutSubtreeChangeClean); 2155 m_lifecycle.advanceTo(DocumentLifecycle::LayoutSubtreeChangeClean);
2156 } 2156 }
2157 2157
2158 bool Document::needsLayoutTreeUpdateForNode(const Node& node) const { 2158 bool Document::needsLayoutTreeUpdateForNode(const Node& node) const {
2159 if (!node.canParticipateInFlatTree())
2160 return false;
2161 if (!needsLayoutTreeUpdate()) 2159 if (!needsLayoutTreeUpdate())
2162 return false; 2160 return false;
2163 if (!node.isConnected()) 2161 if (!node.isConnected())
2164 return false; 2162 return false;
2165 2163
2164 // Elements that are not distributed can still have a style, for example a
2165 // <slot> can still be styled, but LayoutTreeBuilder::parent DCHECKs on
2166 // things outside the flat tree, so we instead disable this optimization.
2167 if (!node.canParticipateInFlatTree())
2168 return true;
2169
2166 if (needsFullLayoutTreeUpdate() || node.needsStyleRecalc() || 2170 if (needsFullLayoutTreeUpdate() || node.needsStyleRecalc() ||
2167 node.needsStyleInvalidation()) 2171 node.needsStyleInvalidation())
2168 return true; 2172 return true;
2169 for (const ContainerNode* ancestor = LayoutTreeBuilderTraversal::parent(node); 2173
2170 ancestor; ancestor = LayoutTreeBuilderTraversal::parent(*ancestor)) { 2174 const ContainerNode* deepestParent = LayoutTreeBuilderTraversal::parent(node);
2175
2176 // If we're not distributed anywhere we need our style recomputed always.
2177 if (!deepestParent)
2178 return true;
2179
2180 for (const ContainerNode* ancestor = deepestParent; ancestor;
2181 ancestor = LayoutTreeBuilderTraversal::parent(*ancestor)) {
2171 if (ancestor->needsStyleRecalc() || ancestor->needsStyleInvalidation() || 2182 if (ancestor->needsStyleRecalc() || ancestor->needsStyleInvalidation() ||
2172 ancestor->needsAdjacentStyleRecalc()) 2183 ancestor->needsAdjacentStyleRecalc())
2173 return true; 2184 return true;
2174 } 2185 }
2186
2187 ShadowRoot* scope = node.containingShadowRoot();
2188 if (!scope)
2189 return false;
2190
2191 // Traverse up the scopes from the node to the root checking for bits, we
2192 // need to do this since the LayoutTreeBuilder::parent walk above skips all
2193 // shadow roots.
2194 for (const ShadowRoot* root = scope; root;
2195 root = root->host().containingShadowRoot()) {
2196 if (root->needsStyleRecalc() || root->needsStyleInvalidation() ||
2197 root->needsAdjacentStyleRecalc())
2198 return true;
2199 }
2200
2201 // Traverse from the location where we were distributed up until we hit the
2202 // scope that owns the node itself which we checked above.
2203 for (const ShadowRoot* root = deepestParent->containingShadowRoot();
2204 root && root != scope; root = root->host().containingShadowRoot()) {
2205 if (root->needsStyleRecalc() || root->needsStyleInvalidation() ||
2206 root->needsAdjacentStyleRecalc())
2207 return true;
2208 }
2209
2175 return false; 2210 return false;
2176 } 2211 }
2177 2212
2178 void Document::updateStyleAndLayoutTreeForNode(const Node* node) { 2213 void Document::updateStyleAndLayoutTreeForNode(const Node* node) {
2179 DCHECK(node); 2214 DCHECK(node);
2180 if (!needsLayoutTreeUpdateForNode(*node)) 2215 if (!needsLayoutTreeUpdateForNode(*node))
2181 return; 2216 return;
2182 updateStyleAndLayoutTree(); 2217 updateStyleAndLayoutTree();
2183 } 2218 }
2184 2219
(...skipping 4465 matching lines...) Expand 10 before | Expand all | Expand 10 after
6650 } 6685 }
6651 6686
6652 void showLiveDocumentInstances() { 6687 void showLiveDocumentInstances() {
6653 WeakDocumentSet& set = liveDocumentSet(); 6688 WeakDocumentSet& set = liveDocumentSet();
6654 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 6689 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
6655 for (blink::Document* document : set) 6690 for (blink::Document* document : set)
6656 fprintf(stderr, "- Document %p URL: %s\n", document, 6691 fprintf(stderr, "- Document %p URL: %s\n", document,
6657 document->url().getString().utf8().data()); 6692 document->url().getString().utf8().data());
6658 } 6693 }
6659 #endif 6694 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSComputedStyleDeclaration.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698