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

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

Issue 1844723003: Move metrics list storage to LayoutSVGInlineText (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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) Research In Motion Limited 2010-2012. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2010-2012. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 219
220 bool lastCharacterWasWhiteSpace; 220 bool lastCharacterWasWhiteSpace;
221 unsigned valueListPosition; 221 unsigned valueListPosition;
222 }; 222 };
223 223
224 // Struct for updating SVGTextLayoutAttributes. If an SVGCharacterDataMap is 224 // Struct for updating SVGTextLayoutAttributes. If an SVGCharacterDataMap is
225 // available, the attribute's character data map will also be updated. 225 // available, the attribute's character data map will also be updated.
226 // TreeWalkTextState should be used to maintain the value list position which 226 // TreeWalkTextState should be used to maintain the value list position which
227 // indexes into the SVGCharacterDataMap of all characters. 227 // indexes into the SVGCharacterDataMap of all characters.
228 struct UpdateAttributes { 228 struct UpdateAttributes {
229 UpdateAttributes(SVGTextLayoutAttributes& textAttributes, const SVGCharacter DataMap* allCharacters) 229 UpdateAttributes(
230 : attributes(textAttributes) 230 SVGTextLayoutAttributes& textAttributes,
231 Vector<SVGTextMetrics>& metricsList,
232 const SVGCharacterDataMap* allCharacters)
233 : metricsList(metricsList)
234 , attributes(textAttributes)
231 , allCharactersMap(allCharacters) { } 235 , allCharactersMap(allCharacters) { }
232 236
233 void clearExistingAttributes() 237 void clearExistingAttributes()
234 { 238 {
239 metricsList.clear();
240
235 if (allCharactersMap) 241 if (allCharactersMap)
236 attributes.clear(); 242 attributes.clear();
237 else
238 attributes.textMetricsValues().clear();
239 } 243 }
240 244
241 void addMetrics(SVGTextMetrics metrics) 245 void addMetrics(SVGTextMetrics metrics)
242 { 246 {
243 attributes.textMetricsValues().append(metrics); 247 metricsList.append(metrics);
244 } 248 }
245 249
246 void updateCharacterDataMap(unsigned valueListPosition, unsigned currentText Position) 250 void updateCharacterDataMap(unsigned valueListPosition, unsigned currentText Position)
247 { 251 {
248 if (!allCharactersMap) 252 if (!allCharactersMap)
249 return; 253 return;
250 const SVGCharacterDataMap::const_iterator it = allCharactersMap->find(va lueListPosition); 254 const SVGCharacterDataMap::const_iterator it = allCharactersMap->find(va lueListPosition);
251 if (it != allCharactersMap->end()) 255 if (it != allCharactersMap->end())
252 attributes.characterDataMap().set(currentTextPosition, it->value); 256 attributes.characterDataMap().set(currentTextPosition, it->value);
253 } 257 }
254 258
259 Vector<SVGTextMetrics>& metricsList;
255 SVGTextLayoutAttributes& attributes; 260 SVGTextLayoutAttributes& attributes;
256 const SVGCharacterDataMap* allCharactersMap; 261 const SVGCharacterDataMap* allCharactersMap;
257 }; 262 };
258 263
259 void walkInlineText(LayoutSVGInlineText* text, TreeWalkTextState& textState, Upd ateAttributes* attributesToUpdate = nullptr) 264 void walkInlineText(LayoutSVGInlineText* text, TreeWalkTextState& textState, Upd ateAttributes* attributesToUpdate = nullptr)
260 { 265 {
261 if (attributesToUpdate) 266 if (attributesToUpdate)
262 attributesToUpdate->clearExistingAttributes(); 267 attributesToUpdate->clearExistingAttributes();
263 268
264 if (!text->textLength()) 269 if (!text->textLength())
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 301
297 void walkTree(LayoutSVGText* start, LayoutSVGInlineText* stopAtText, SVGCharacte rDataMap* allCharactersMap = nullptr) 302 void walkTree(LayoutSVGText* start, LayoutSVGInlineText* stopAtText, SVGCharacte rDataMap* allCharactersMap = nullptr)
298 { 303 {
299 TreeWalkTextState textState; 304 TreeWalkTextState textState;
300 LayoutObject* child = start->firstChild(); 305 LayoutObject* child = start->firstChild();
301 while (child) { 306 while (child) {
302 if (child->isSVGInlineText()) { 307 if (child->isSVGInlineText()) {
303 LayoutSVGInlineText* text = toLayoutSVGInlineText(child); 308 LayoutSVGInlineText* text = toLayoutSVGInlineText(child);
304 OwnPtr<UpdateAttributes> attributesToUpdate = nullptr; 309 OwnPtr<UpdateAttributes> attributesToUpdate = nullptr;
305 if (!stopAtText || stopAtText == text) 310 if (!stopAtText || stopAtText == text)
306 attributesToUpdate = adoptPtr(new UpdateAttributes(*text->layout Attributes(), allCharactersMap)); 311 attributesToUpdate = adoptPtr(new UpdateAttributes(*text->layout Attributes(), text->metricsList(), allCharactersMap));
307 walkInlineText(text, textState, attributesToUpdate.get()); 312 walkInlineText(text, textState, attributesToUpdate.get());
308 if (stopAtText == text) 313 if (stopAtText == text)
309 return; 314 return;
310 } else if (child->isSVGInline()) { 315 } else if (child->isSVGInline()) {
311 // Visit children of text content elements. 316 // Visit children of text content elements.
312 if (LayoutObject* inlineChild = toLayoutSVGInline(child)->firstChild ()) { 317 if (LayoutObject* inlineChild = toLayoutSVGInline(child)->firstChild ()) {
313 child = inlineChild; 318 child = inlineChild;
314 continue; 319 continue;
315 } 320 }
316 } 321 }
(...skipping 10 matching lines...) Expand all
327 walkTree(textRoot, text); 332 walkTree(textRoot, text);
328 } 333 }
329 334
330 void SVGTextMetricsBuilder::buildMetricsAndLayoutAttributes(LayoutSVGText* textR oot, LayoutSVGInlineText* stopAtText, SVGCharacterDataMap& allCharactersMap) 335 void SVGTextMetricsBuilder::buildMetricsAndLayoutAttributes(LayoutSVGText* textR oot, LayoutSVGInlineText* stopAtText, SVGCharacterDataMap& allCharactersMap)
331 { 336 {
332 ASSERT(textRoot); 337 ASSERT(textRoot);
333 walkTree(textRoot, stopAtText, &allCharactersMap); 338 walkTree(textRoot, stopAtText, &allCharactersMap);
334 } 339 }
335 340
336 } // namespace blink 341 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698