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

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

Issue 2727233005: Remove calls to styleForLayoutObject() in LayoutTreeBuilder::style() (Closed)
Patch Set: Format issue 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
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 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
8 * All rights reserved. 8 * All rights reserved.
9 * (C) 2007 Eric Seidel (eric@webkit.org) 9 * (C) 2007 Eric Seidel (eric@webkit.org)
10 * 10 *
11 * This library is free software; you can redistribute it and/or 11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public 12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either 13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version. 14 * version 2 of the License, or (at your option) any later version.
15 * 15 *
16 * This library is distributed in the hope that it will be useful, 16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details. 19 * Library General Public License for more details.
20 * 20 *
21 * You should have received a copy of the GNU Library General Public License 21 * You should have received a copy of the GNU Library General Public License
22 * along with this library; see the file COPYING.LIB. If not, write to 22 * along with this library; see the file COPYING.LIB. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA. 24 * Boston, MA 02110-1301, USA.
25 */ 25 */
26 26
27 #include "core/dom/Element.h" 27 #include "core/dom/Element.h"
28 28
29 #include <memory>
nainar 2017/03/09 02:53:03 git cl format. Will get rid of this.
29 #include "bindings/core/v8/DOMDataStore.h" 30 #include "bindings/core/v8/DOMDataStore.h"
30 #include "bindings/core/v8/Dictionary.h" 31 #include "bindings/core/v8/Dictionary.h"
31 #include "bindings/core/v8/ExceptionMessages.h" 32 #include "bindings/core/v8/ExceptionMessages.h"
32 #include "bindings/core/v8/ExceptionState.h" 33 #include "bindings/core/v8/ExceptionState.h"
33 #include "bindings/core/v8/V8DOMActivityLogger.h" 34 #include "bindings/core/v8/V8DOMActivityLogger.h"
34 #include "bindings/core/v8/V8DOMWrapper.h" 35 #include "bindings/core/v8/V8DOMWrapper.h"
35 #include "bindings/core/v8/V8PerContextData.h" 36 #include "bindings/core/v8/V8PerContextData.h"
36 #include "core/CSSValueKeywords.h" 37 #include "core/CSSValueKeywords.h"
37 #include "core/SVGNames.h" 38 #include "core/SVGNames.h"
38 #include "core/XMLNames.h" 39 #include "core/XMLNames.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 #include "core/frame/VisualViewport.h" 104 #include "core/frame/VisualViewport.h"
104 #include "core/frame/csp/ContentSecurityPolicy.h" 105 #include "core/frame/csp/ContentSecurityPolicy.h"
105 #include "core/html/ClassList.h" 106 #include "core/html/ClassList.h"
106 #include "core/html/HTMLCanvasElement.h" 107 #include "core/html/HTMLCanvasElement.h"
107 #include "core/html/HTMLCollection.h" 108 #include "core/html/HTMLCollection.h"
108 #include "core/html/HTMLDocument.h" 109 #include "core/html/HTMLDocument.h"
109 #include "core/html/HTMLElement.h" 110 #include "core/html/HTMLElement.h"
110 #include "core/html/HTMLFormControlsCollection.h" 111 #include "core/html/HTMLFormControlsCollection.h"
111 #include "core/html/HTMLFrameElementBase.h" 112 #include "core/html/HTMLFrameElementBase.h"
112 #include "core/html/HTMLFrameOwnerElement.h" 113 #include "core/html/HTMLFrameOwnerElement.h"
114 #include "core/html/HTMLObjectElement.h"
nainar 2017/03/09 02:53:03 Not needed.
113 #include "core/html/HTMLOptionsCollection.h" 115 #include "core/html/HTMLOptionsCollection.h"
114 #include "core/html/HTMLPlugInElement.h" 116 #include "core/html/HTMLPlugInElement.h"
115 #include "core/html/HTMLSlotElement.h" 117 #include "core/html/HTMLSlotElement.h"
116 #include "core/html/HTMLTableRowsCollection.h" 118 #include "core/html/HTMLTableRowsCollection.h"
117 #include "core/html/HTMLTemplateElement.h" 119 #include "core/html/HTMLTemplateElement.h"
118 #include "core/html/parser/HTMLParserIdioms.h" 120 #include "core/html/parser/HTMLParserIdioms.h"
119 #include "core/input/EventHandler.h" 121 #include "core/input/EventHandler.h"
120 #include "core/inspector/InspectorInstrumentation.h" 122 #include "core/inspector/InspectorInstrumentation.h"
121 #include "core/layout/LayoutTextFragment.h" 123 #include "core/layout/LayoutTextFragment.h"
122 #include "core/layout/api/LayoutBoxItem.h" 124 #include "core/layout/api/LayoutBoxItem.h"
(...skipping 16 matching lines...) Expand all
139 #include "platform/EventDispatchForbiddenScope.h" 141 #include "platform/EventDispatchForbiddenScope.h"
140 #include "platform/RuntimeEnabledFeatures.h" 142 #include "platform/RuntimeEnabledFeatures.h"
141 #include "platform/graphics/CompositorMutableProperties.h" 143 #include "platform/graphics/CompositorMutableProperties.h"
142 #include "platform/graphics/CompositorMutation.h" 144 #include "platform/graphics/CompositorMutation.h"
143 #include "platform/scroll/ScrollableArea.h" 145 #include "platform/scroll/ScrollableArea.h"
144 #include "wtf/BitVector.h" 146 #include "wtf/BitVector.h"
145 #include "wtf/HashFunctions.h" 147 #include "wtf/HashFunctions.h"
146 #include "wtf/text/CString.h" 148 #include "wtf/text/CString.h"
147 #include "wtf/text/StringBuilder.h" 149 #include "wtf/text/StringBuilder.h"
148 #include "wtf/text/TextPosition.h" 150 #include "wtf/text/TextPosition.h"
149 #include <memory>
150 151
151 namespace blink { 152 namespace blink {
152 153
153 namespace { 154 namespace {
154 155
155 // We need to retain the scroll customization callbacks until the element 156 // We need to retain the scroll customization callbacks until the element
156 // they're associated with is destroyed. It would be simplest if the callbacks 157 // they're associated with is destroyed. It would be simplest if the callbacks
157 // could be stored in ElementRareData, but we can't afford the space 158 // could be stored in ElementRareData, but we can't afford the space
158 // increase. Instead, keep the scroll customization callbacks here. The other 159 // increase. Instead, keep the scroll customization callbacks here. The other
159 // option would be to store these callbacks on the FrameHost or document, but 160 // option would be to store these callbacks on the FrameHost or document, but
(...skipping 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after
1732 if (ElementAnimations* elementAnimations = 1733 if (ElementAnimations* elementAnimations =
1733 elementRareData()->elementAnimations()) { 1734 elementRareData()->elementAnimations()) {
1734 elementAnimations->cssAnimations().cancel(); 1735 elementAnimations->cssAnimations().cancel();
1735 elementAnimations->setAnimationStyleChange(false); 1736 elementAnimations->setAnimationStyleChange(false);
1736 } 1737 }
1737 } 1738 }
1738 1739
1739 SelectorFilterParentScope filterScope(*this); 1740 SelectorFilterParentScope filterScope(*this);
1740 StyleSharingDepthScope sharingScope(*this); 1741 StyleSharingDepthScope sharingScope(*this);
1741 1742
1743 clearNeedsReattachLayoutTree();
1742 createPseudoElementIfNeeded(PseudoIdBefore); 1744 createPseudoElementIfNeeded(PseudoIdBefore);
1743 1745
1744 // When a shadow root exists, it does the work of attaching the children. 1746 // When a shadow root exists, it does the work of attaching the children.
1745 if (ElementShadow* shadow = this->shadow()) 1747 if (ElementShadow* shadow = this->shadow())
1746 shadow->attach(context); 1748 shadow->attach(context);
1747 1749
1748 ContainerNode::attachLayoutTree(context); 1750 ContainerNode::attachLayoutTree(context);
1749 1751
1750 createPseudoElementIfNeeded(PseudoIdAfter); 1752 createPseudoElementIfNeeded(PseudoIdAfter);
1751 createPseudoElementIfNeeded(PseudoIdBackdrop); 1753 createPseudoElementIfNeeded(PseudoIdBackdrop);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 2016
2015 StyleRecalcChange localChange = 2017 StyleRecalcChange localChange =
2016 ComputedStyle::stylePropagationDiff(oldStyle.get(), newStyle.get()); 2018 ComputedStyle::stylePropagationDiff(oldStyle.get(), newStyle.get());
2017 if (localChange == NoChange) { 2019 if (localChange == NoChange) {
2018 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesUnchanged, 1); 2020 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesUnchanged, 1);
2019 } else { 2021 } else {
2020 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1); 2022 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), stylesChanged, 1);
2021 } 2023 }
2022 2024
2023 if (localChange == Reattach) { 2025 if (localChange == Reattach) {
2026 // This mimicks Element::recalcStyleForReattach except it also stores the
2027 // nextTextSibling information.
2024 StyleReattachData styleReattachData; 2028 StyleReattachData styleReattachData;
2025 styleReattachData.computedStyle = std::move(newStyle); 2029 styleReattachData.computedStyle = std::move(newStyle);
2026 styleReattachData.nextTextSibling = nextTextSibling; 2030 styleReattachData.nextTextSibling = nextTextSibling;
2027 document().addStyleReattachData(*this, styleReattachData); 2031 document().addStyleReattachData(*this, styleReattachData);
2028 setNeedsReattachLayoutTree(); 2032 setNeedsReattachLayoutTree();
2033 recalcContainedStyleForReattach();
2029 return Reattach; 2034 return Reattach;
2030 } 2035 }
2031 2036
2032 DCHECK(oldStyle); 2037 DCHECK(oldStyle);
2033 2038
2034 if (localChange != NoChange) 2039 if (localChange != NoChange)
2035 updateCallbackSelectors(oldStyle.get(), newStyle.get()); 2040 updateCallbackSelectors(oldStyle.get(), newStyle.get());
2036 2041
2037 if (LayoutObject* layoutObject = this->layoutObject()) { 2042 if (LayoutObject* layoutObject = this->layoutObject()) {
2038 if (localChange != NoChange) { 2043 if (localChange != NoChange) {
(...skipping 24 matching lines...) Expand all
2063 return Inherit; 2068 return Inherit;
2064 newStyle->copyChildDependentFlagsFrom(*oldStyle); 2069 newStyle->copyChildDependentFlagsFrom(*oldStyle);
2065 } 2070 }
2066 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle()) 2071 if (oldStyle->hasPseudoElementStyle() || newStyle->hasPseudoElementStyle())
2067 return UpdatePseudoElements; 2072 return UpdatePseudoElements;
2068 } 2073 }
2069 2074
2070 return localChange; 2075 return localChange;
2071 } 2076 }
2072 2077
2078 void Element::recalcStyleForReattach() {
2079 StyleReattachData styleReattachData;
2080 styleReattachData.computedStyle = styleForLayoutObject();
2081 if (layoutObjectIsNeeded(*styleReattachData.computedStyle.get())) {
2082 document().addStyleReattachData(*this, styleReattachData);
2083 setNeedsReattachLayoutTree();
2084 recalcContainedStyleForReattach();
2085 }
2086 }
2087
2088 void Element::recalcContainedStyleForReattach() {
2089 if (!childrenCanHaveStyle())
2090 return;
2091 if (hasCustomStyleCallbacks())
2092 return;
2093
2094 SelectorFilterParentScope filterScope(*this);
2095 StyleSharingDepthScope sharingScope(*this);
2096 recalcPseudoStyleForReattach(PseudoIdBefore);
2097 recalcShadowRootStylesForReattach();
2098 recalcDescendantStylesForReattach();
2099 recalcPseudoStyleForReattach(PseudoIdAfter);
2100 recalcPseudoStyleForReattach(PseudoIdBackdrop);
2101 recalcPseudoStyleForReattach(PseudoIdFirstLetter);
2102 }
2103
2104 void Element::recalcPseudoStyleForReattach(PseudoId pseudoId) {
2105 if (PseudoElement* element = pseudoElement(pseudoId))
2106 element->recalcStyleForReattach();
2107 }
2108
2109 void Element::recalcShadowRootStylesForReattach() {
2110 for (ShadowRoot* root = youngestShadowRoot(); root;
2111 root = root->olderShadowRoot()) {
2112 root->recalcDescendantStylesForReattach();
2113 }
2114 }
2115
2073 void Element::rebuildLayoutTree() { 2116 void Element::rebuildLayoutTree() {
2074 DCHECK(inActiveDocument()); 2117 DCHECK(inActiveDocument());
2075 DCHECK(parentNode()); 2118 DCHECK(parentNode());
2076 2119
2077 if (needsReattachLayoutTree()) { 2120 if (needsReattachLayoutTree()) {
2078 StyleReattachData styleReattachData = 2121 StyleReattachData styleReattachData =
2079 document().getStyleReattachData(*this); 2122 document().getStyleReattachData(*this);
2080 AttachContext reattachContext; 2123 AttachContext reattachContext;
2124 // TODO(nainar): Shouldn't need AttachContext.resolvedStyle anymore
2081 reattachContext.resolvedStyle = styleReattachData.computedStyle.get(); 2125 reattachContext.resolvedStyle = styleReattachData.computedStyle.get();
2082 bool layoutObjectWillChange = needsAttach() || layoutObject(); 2126 bool layoutObjectWillChange = needsAttach() || layoutObject();
2083 reattachLayoutTree(reattachContext); 2127 reattachLayoutTree(reattachContext);
2084 if (layoutObjectWillChange || layoutObject()) { 2128 if (layoutObjectWillChange || layoutObject()) {
2085 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles 2129 // nextTextSibling is passed on to recalcStyle from recalcDescendantStyles
2086 // we can either traverse the current subtree from this node onwards 2130 // we can either traverse the current subtree from this node onwards
2087 // or store it. 2131 // or store it.
2088 // The choice is between increased time and increased memory complexity. 2132 // The choice is between increased time and increased memory complexity.
2089 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling); 2133 reattachWhitespaceSiblingsIfNeeded(styleReattachData.nextTextSibling);
2090 } 2134 }
(...skipping 2136 matching lines...) Expand 10 before | Expand all | Expand 10 after
4227 } 4271 }
4228 4272
4229 DEFINE_TRACE_WRAPPERS(Element) { 4273 DEFINE_TRACE_WRAPPERS(Element) {
4230 if (hasRareData()) { 4274 if (hasRareData()) {
4231 visitor->traceWrappers(elementRareData()); 4275 visitor->traceWrappers(elementRareData());
4232 } 4276 }
4233 ContainerNode::traceWrappers(visitor); 4277 ContainerNode::traceWrappers(visitor);
4234 } 4278 }
4235 4279
4236 } // namespace blink 4280 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Element.h ('k') | third_party/WebKit/Source/core/dom/LayoutTreeBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698