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

Side by Side Diff: third_party/WebKit/Source/core/layout/svg/LayoutSVGText.cpp

Issue 1861013003: Separate metrics update and layout attribute resolving (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplify-layoutattr-invalidation
Patch Set: Rebase Created 4 years, 8 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) 2006 Apple Computer, Inc. 2 * Copyright (C) 2006 Apple Computer, Inc.
3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org> 3 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
4 * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz> 4 * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>
5 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 5 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
6 * Copyright (C) 2008 Rob Buis <buis@kde.org> 6 * Copyright (C) 2008 Rob Buis <buis@kde.org>
7 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 7 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
8 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved. 8 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved.
9 * Copyright (C) 2012 Google Inc. 9 * Copyright (C) 2012 Google Inc.
10 * 10 *
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 { 138 {
139 if (beingDestroyed() || !everHadLayout()) { 139 if (beingDestroyed() || !everHadLayout()) {
140 ASSERT(m_layoutAttributes.isEmpty()); 140 ASSERT(m_layoutAttributes.isEmpty());
141 ASSERT(!m_layoutAttributesBuilder.numberOfTextPositioningElements()); 141 ASSERT(!m_layoutAttributesBuilder.numberOfTextPositioningElements());
142 return; 142 return;
143 } 143 }
144 144
145 // The positioning elements cache depends on the size of each text layoutObj ect in the 145 // The positioning elements cache depends on the size of each text layoutObj ect in the
146 // subtree. If this changes, clear the cache. It will be rebuilt on the next layout. 146 // subtree. If this changes, clear the cache. It will be rebuilt on the next layout.
147 invalidatePositioningValues(LayoutInvalidationReason::ChildChanged); 147 invalidatePositioningValues(LayoutInvalidationReason::ChildChanged);
148 setNeedsTextMetricsUpdate();
148 } 149 }
149 150
150 void LayoutSVGText::subtreeTextDidChange() 151 void LayoutSVGText::subtreeTextDidChange()
151 { 152 {
152 ASSERT(!beingDestroyed()); 153 ASSERT(!beingDestroyed());
153 if (!everHadLayout()) { 154 if (!everHadLayout()) {
154 ASSERT(m_layoutAttributes.isEmpty()); 155 ASSERT(m_layoutAttributes.isEmpty());
155 ASSERT(!m_layoutAttributesBuilder.numberOfTextPositioningElements()); 156 ASSERT(!m_layoutAttributesBuilder.numberOfTextPositioningElements());
156 return; 157 return;
157 } 158 }
158 159
159 // The positioning elements cache depends on the size of each text object in 160 // The positioning elements cache depends on the size of each text object in
160 // the subtree. If this changes, clear the cache and mark it for rebuilding 161 // the subtree. If this changes, clear the cache and mark it for rebuilding
161 // in the next layout. 162 // in the next layout.
162 invalidatePositioningValues(LayoutInvalidationReason::TextChanged); 163 invalidatePositioningValues(LayoutInvalidationReason::TextChanged);
163 setNeedsTextMetricsUpdate(); 164 setNeedsTextMetricsUpdate();
164 } 165 }
165 166
166 static inline void updateFontInAllDescendants(LayoutSVGText& textRoot, SVGTextLa youtAttributesBuilder* builder = nullptr) 167 static inline void updateFontAndMetrics(LayoutSVGText& textRoot)
167 { 168 {
168 for (LayoutObject* descendant = &textRoot; descendant; descendant = descenda nt->nextInPreOrder(&textRoot)) { 169 bool lastCharacterWasWhiteSpace = true;
170 for (LayoutObject* descendant = textRoot.firstChild(); descendant; descendan t = descendant->nextInPreOrder(&textRoot)) {
169 if (!descendant->isSVGInlineText()) 171 if (!descendant->isSVGInlineText())
170 continue; 172 continue;
171 LayoutSVGInlineText* text = toLayoutSVGInlineText(descendant); 173 LayoutSVGInlineText& text = toLayoutSVGInlineText(*descendant);
172 text->updateScaledFont(); 174 text.updateScaledFont();
173 if (builder) 175 text.updateMetricsList(lastCharacterWasWhiteSpace);
174 builder->rebuildMetricsForTextLayoutObject(textRoot, *text);
175 } 176 }
176 } 177 }
177 178
178 static inline void checkLayoutAttributesConsistency(LayoutSVGText* text, Vector< SVGTextLayoutAttributes*>& expectedLayoutAttributes) 179 static inline void checkLayoutAttributesConsistency(LayoutSVGText* text, Vector< SVGTextLayoutAttributes*>& expectedLayoutAttributes)
179 { 180 {
180 #if ENABLE(ASSERT) 181 #if ENABLE(ASSERT)
181 Vector<SVGTextLayoutAttributes*> newLayoutAttributes; 182 Vector<SVGTextLayoutAttributes*> newLayoutAttributes;
182 collectLayoutAttributes(text, newLayoutAttributes); 183 collectLayoutAttributes(text, newLayoutAttributes);
183 ASSERT(newLayoutAttributes == expectedLayoutAttributes); 184 ASSERT(newLayoutAttributes == expectedLayoutAttributes);
184 #endif 185 #endif
185 } 186 }
186 187
187 void LayoutSVGText::layout() 188 void LayoutSVGText::layout()
188 { 189 {
189 ASSERT(needsLayout()); 190 ASSERT(needsLayout());
190 LayoutAnalyzer::Scope analyzer(*this); 191 LayoutAnalyzer::Scope analyzer(*this);
191 192
192 bool updateCachedBoundariesInParents = false; 193 bool updateCachedBoundariesInParents = false;
193 if (m_needsTransformUpdate) { 194 if (m_needsTransformUpdate) {
194 m_localTransform = toSVGTextElement(node())->calculateAnimatedLocalTrans form(); 195 m_localTransform = toSVGTextElement(node())->calculateAnimatedLocalTrans form();
195 m_needsTransformUpdate = false; 196 m_needsTransformUpdate = false;
196 updateCachedBoundariesInParents = true; 197 updateCachedBoundariesInParents = true;
197 } 198 }
198 199
199 if (!everHadLayout()) { 200 if (!everHadLayout()) {
200 // When laying out initially, collect all layout attributes, build the c haracter data map, 201 // When laying out initially, collect all layout attributes, build the c haracter data map,
201 // and propogate resulting SVGLayoutAttributes to all LayoutSVGInlineTex t children in the subtree. 202 // and propogate resulting SVGLayoutAttributes to all LayoutSVGInlineTex t children in the subtree.
202 ASSERT(m_layoutAttributes.isEmpty()); 203 ASSERT(m_layoutAttributes.isEmpty());
203 collectLayoutAttributes(this, m_layoutAttributes); 204 collectLayoutAttributes(this, m_layoutAttributes);
204 updateFontInAllDescendants(*this); 205 updateFontAndMetrics(*this);
205 m_layoutAttributesBuilder.buildLayoutAttributesForForSubtree(*this); 206 m_layoutAttributesBuilder.buildLayoutAttributesForTextRoot(*this);
206 207
207 m_needsReordering = true; 208 m_needsReordering = true;
208 m_needsTextMetricsUpdate = false; 209 m_needsTextMetricsUpdate = false;
209 m_needsPositioningValuesUpdate = false; 210 m_needsPositioningValuesUpdate = false;
210 updateCachedBoundariesInParents = true; 211 updateCachedBoundariesInParents = true;
211 } else if (m_needsPositioningValuesUpdate) { 212 } else if (m_needsPositioningValuesUpdate) {
212 // When the x/y/dx/dy/rotate lists change, recompute the layout attribut es, and eventually 213 // When the x/y/dx/dy/rotate lists change, recompute the layout attribut es, and eventually
213 // update the on-screen font objects as well in all descendants. 214 // update the on-screen font objects as well in all descendants.
214 if (m_needsTextMetricsUpdate) { 215 if (m_needsTextMetricsUpdate) {
215 updateFontInAllDescendants(*this); 216 updateFontAndMetrics(*this);
216 m_needsTextMetricsUpdate = false; 217 m_needsTextMetricsUpdate = false;
217 } 218 }
218 219
219 m_layoutAttributes.clear(); 220 m_layoutAttributes.clear();
220 collectLayoutAttributes(this, m_layoutAttributes); 221 collectLayoutAttributes(this, m_layoutAttributes);
221 m_layoutAttributesBuilder.buildLayoutAttributesForForSubtree(*this); 222 m_layoutAttributesBuilder.buildLayoutAttributesForTextRoot(*this);
222 m_needsReordering = true; 223 m_needsReordering = true;
223 m_needsPositioningValuesUpdate = false; 224 m_needsPositioningValuesUpdate = false;
224 updateCachedBoundariesInParents = true; 225 updateCachedBoundariesInParents = true;
225 } else if (m_needsTextMetricsUpdate || SVGLayoutSupport::findTreeRootObject( this)->isLayoutSizeChanged()) { 226 } else if (m_needsTextMetricsUpdate || SVGLayoutSupport::findTreeRootObject( this)->isLayoutSizeChanged()) {
226 // If the root layout size changed (eg. window size changes) or the tran sform to the root 227 // If the root layout size changed (eg. window size changes) or the tran sform to the root
227 // context has changed then recompute the on-screen font size. 228 // context has changed then recompute the on-screen font size.
228 updateFontInAllDescendants(*this, &m_layoutAttributesBuilder); 229 updateFontAndMetrics(*this);
229 230
230 ASSERT(!m_needsReordering); 231 ASSERT(!m_needsReordering);
231 ASSERT(!m_needsPositioningValuesUpdate); 232 ASSERT(!m_needsPositioningValuesUpdate);
232 m_needsTextMetricsUpdate = false; 233 m_needsTextMetricsUpdate = false;
233 updateCachedBoundariesInParents = true; 234 updateCachedBoundariesInParents = true;
234 } 235 }
235 236
236 checkLayoutAttributesConsistency(this, m_layoutAttributes); 237 checkLayoutAttributesConsistency(this, m_layoutAttributes);
237 238
238 // Reduced version of LayoutBlock::layoutBlock(), which only takes care of S VG text. 239 // Reduced version of LayoutBlock::layoutBlock(), which only takes care of S VG text.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 paintInvalidationState.pushDelayedPaintInvalidationTarget(*this); 408 paintInvalidationState.pushDelayedPaintInvalidationTarget(*this);
408 409
409 if (reason == PaintInvalidationSVGResourceChange) 410 if (reason == PaintInvalidationSVGResourceChange)
410 newPaintInvalidationState.setForceSubtreeInvalidationWithinContainer(); 411 newPaintInvalidationState.setForceSubtreeInvalidationWithinContainer();
411 412
412 newPaintInvalidationState.updateForChildren(); 413 newPaintInvalidationState.updateForChildren();
413 invalidatePaintOfSubtreesIfNeeded(newPaintInvalidationState); 414 invalidatePaintOfSubtreesIfNeeded(newPaintInvalidationState);
414 } 415 }
415 416
416 } // namespace blink 417 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698