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

Side by Side Diff: Source/core/css/resolver/FontBuilder.cpp

Issue 714163002: Remove RenderStyle member from FontBuilder. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Ensure font is created before taking animation snapshot. Created 6 years, 1 month 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 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
4 * Copyright (C) 2013 Google Inc. All rights reserved. 4 * Copyright (C) 2013 Google Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 24 matching lines...) Expand all
35 35
36 namespace blink { 36 namespace blink {
37 37
38 // FIXME: This scoping class is a short-term fix to minimize the changes in 38 // FIXME: This scoping class is a short-term fix to minimize the changes in
39 // Font-constructing logic. 39 // Font-constructing logic.
40 class FontDescriptionChangeScope { 40 class FontDescriptionChangeScope {
41 STACK_ALLOCATED(); 41 STACK_ALLOCATED();
42 public: 42 public:
43 FontDescriptionChangeScope(FontBuilder* fontBuilder) 43 FontDescriptionChangeScope(FontBuilder* fontBuilder)
44 : m_fontBuilder(fontBuilder) 44 : m_fontBuilder(fontBuilder)
45 , m_fontDescription(fontBuilder->m_style->fontDescription()) 45 , m_fontDescription(fontBuilder->fontDescription())
46 { 46 {
47 } 47 }
48 48
49 void reset() { m_fontDescription = FontDescription(); }
50 void set(const FontDescription& fontDescription) { m_fontDescription = fontD escription; }
51 FontDescription& fontDescription() { return m_fontDescription; }
52
53 ~FontDescriptionChangeScope() 49 ~FontDescriptionChangeScope()
54 { 50 {
55 m_fontBuilder->didChangeFontParameters(m_fontBuilder->m_style->setFontDe scription(m_fontDescription)); 51 if (m_fontBuilder->fontDirty())
52 return;
53 m_fontBuilder->didChangeFontParameters(m_fontBuilder->fontDescription() != m_fontDescription);
56 } 54 }
57 55
58 private: 56 private:
59 RawPtrWillBeMember<FontBuilder> m_fontBuilder; 57 RawPtrWillBeMember<FontBuilder> m_fontBuilder;
60 FontDescription m_fontDescription; 58 FontDescription m_fontDescription;
61 }; 59 };
62 60
63 FontBuilder::FontBuilder(const Document& document) 61 FontBuilder::FontBuilder(const Document& document)
64 : m_document(document) 62 : m_document(document)
65 , m_style(nullptr)
66 , m_fontDirty(false) 63 , m_fontDirty(false)
67 { 64 {
68 ASSERT(document.frame()); 65 ASSERT(document.frame());
69 } 66 }
70 67
71 void FontBuilder::setInitial(float effectiveZoom) 68 void FontBuilder::setInitial(float effectiveZoom)
72 { 69 {
73 ASSERT(m_document.settings()); 70 ASSERT(m_document.settings());
74 if (!m_document.settings()) 71 if (!m_document.settings())
75 return; 72 return;
76 73
77 FontDescriptionChangeScope scope(this); 74 FontDescriptionChangeScope scope(this);
78 75
79 scope.reset(); 76 m_fontDescription = FontDescription();
80 setFamilyDescription(scope.fontDescription(), FontBuilder::initialFamilyDesc ription()); 77 setFamilyDescription(m_fontDescription, FontBuilder::initialFamilyDescriptio n());
81 setSize(scope.fontDescription(), FontBuilder::initialSize()); 78 setSize(m_fontDescription, FontBuilder::initialSize());
82 } 79 }
83 80
84 void FontBuilder::inheritFrom(const FontDescription& fontDescription) 81 void FontBuilder::inheritFrom(const FontDescription& fontDescription)
85 { 82 {
86 FontDescriptionChangeScope scope(this); 83 FontDescriptionChangeScope scope(this);
87 84
88 scope.set(fontDescription); 85 m_fontDescription = fontDescription;
89 } 86 }
90 87
91 void FontBuilder::didChangeFontParameters(bool changed) 88 void FontBuilder::didChangeFontParameters(bool changed)
92 { 89 {
93 m_fontDirty |= changed; 90 m_fontDirty |= changed;
94 } 91 }
95 92
96 FontFamily FontBuilder::standardFontFamily() const 93 FontFamily FontBuilder::standardFontFamily() const
97 { 94 {
98 FontFamily family; 95 FontFamily family;
(...skipping 30 matching lines...) Expand all
129 return FontFamilyNames::webkit_fantasy; 126 return FontFamilyNames::webkit_fantasy;
130 case FontDescription::PictographFamily: 127 case FontDescription::PictographFamily:
131 return FontFamilyNames::webkit_pictograph; 128 return FontFamilyNames::webkit_pictograph;
132 } 129 }
133 } 130 }
134 131
135 void FontBuilder::setFamilyDescription(const FontDescription::FamilyDescription& familyDescription) 132 void FontBuilder::setFamilyDescription(const FontDescription::FamilyDescription& familyDescription)
136 { 133 {
137 FontDescriptionChangeScope scope(this); 134 FontDescriptionChangeScope scope(this);
138 135
139 setFamilyDescription(scope.fontDescription(), familyDescription); 136 setFamilyDescription(m_fontDescription, familyDescription);
140 } 137 }
141 138
142 void FontBuilder::setWeight(FontWeight fontWeight) 139 void FontBuilder::setWeight(FontWeight fontWeight)
143 { 140 {
144 FontDescriptionChangeScope scope(this); 141 FontDescriptionChangeScope scope(this);
145 142
146 scope.fontDescription().setWeight(fontWeight); 143 m_fontDescription.setWeight(fontWeight);
147 } 144 }
148 145
149 void FontBuilder::setSize(const FontDescription::Size& size) 146 void FontBuilder::setSize(const FontDescription::Size& size)
150 { 147 {
151 FontDescriptionChangeScope scope(this); 148 FontDescriptionChangeScope scope(this);
152 149
153 setSize(scope.fontDescription(), size); 150 setSize(m_fontDescription, size);
154 } 151 }
155 152
156 void FontBuilder::setStretch(FontStretch fontStretch) 153 void FontBuilder::setStretch(FontStretch fontStretch)
157 { 154 {
158 FontDescriptionChangeScope scope(this); 155 FontDescriptionChangeScope scope(this);
159 156
160 scope.fontDescription().setStretch(fontStretch); 157 m_fontDescription.setStretch(fontStretch);
161 } 158 }
162 159
163 void FontBuilder::setScript(const String& locale) 160 void FontBuilder::setScript(const String& locale)
164 { 161 {
165 FontDescriptionChangeScope scope(this); 162 FontDescriptionChangeScope scope(this);
166 163
167 scope.fontDescription().setLocale(locale); 164 m_fontDescription.setLocale(locale);
168 scope.fontDescription().setScript(localeToScriptCodeForFontSelection(locale) ); 165 m_fontDescription.setScript(localeToScriptCodeForFontSelection(locale));
169 } 166 }
170 167
171 void FontBuilder::setStyle(FontStyle italic) 168 void FontBuilder::setStyle(FontStyle italic)
172 { 169 {
173 FontDescriptionChangeScope scope(this); 170 FontDescriptionChangeScope scope(this);
174 171
175 scope.fontDescription().setStyle(italic); 172 m_fontDescription.setStyle(italic);
176 } 173 }
177 174
178 void FontBuilder::setVariant(FontVariant smallCaps) 175 void FontBuilder::setVariant(FontVariant smallCaps)
179 { 176 {
180 FontDescriptionChangeScope scope(this); 177 FontDescriptionChangeScope scope(this);
181 178
182 scope.fontDescription().setVariant(smallCaps); 179 m_fontDescription.setVariant(smallCaps);
183 } 180 }
184 181
185 void FontBuilder::setVariantLigatures(const FontDescription::VariantLigatures& l igatures) 182 void FontBuilder::setVariantLigatures(const FontDescription::VariantLigatures& l igatures)
186 { 183 {
187 FontDescriptionChangeScope scope(this); 184 FontDescriptionChangeScope scope(this);
188 185
189 scope.fontDescription().setVariantLigatures(ligatures); 186 m_fontDescription.setVariantLigatures(ligatures);
190 } 187 }
191 188
192 void FontBuilder::setTextRendering(TextRenderingMode textRenderingMode) 189 void FontBuilder::setTextRendering(TextRenderingMode textRenderingMode)
193 { 190 {
194 FontDescriptionChangeScope scope(this); 191 FontDescriptionChangeScope scope(this);
195 192
196 scope.fontDescription().setTextRendering(textRenderingMode); 193 m_fontDescription.setTextRendering(textRenderingMode);
197 } 194 }
198 195
199 void FontBuilder::setKerning(FontDescription::Kerning kerning) 196 void FontBuilder::setKerning(FontDescription::Kerning kerning)
200 { 197 {
201 FontDescriptionChangeScope scope(this); 198 FontDescriptionChangeScope scope(this);
202 199
203 scope.fontDescription().setKerning(kerning); 200 m_fontDescription.setKerning(kerning);
204 } 201 }
205 202
206 void FontBuilder::setFontSmoothing(FontSmoothingMode foontSmoothingMode) 203 void FontBuilder::setFontSmoothing(FontSmoothingMode foontSmoothingMode)
207 { 204 {
208 FontDescriptionChangeScope scope(this); 205 FontDescriptionChangeScope scope(this);
209 206
210 scope.fontDescription().setFontSmoothing(foontSmoothingMode); 207 m_fontDescription.setFontSmoothing(foontSmoothingMode);
211 } 208 }
212 209
213 void FontBuilder::setFeatureSettings(PassRefPtr<FontFeatureSettings> settings) 210 void FontBuilder::setFeatureSettings(PassRefPtr<FontFeatureSettings> settings)
214 { 211 {
215 FontDescriptionChangeScope scope(this); 212 FontDescriptionChangeScope scope(this);
216 213
217 scope.fontDescription().setFeatureSettings(settings); 214 m_fontDescription.setFeatureSettings(settings);
218 } 215 }
219 216
220 void FontBuilder::setFamilyDescription(FontDescription& fontDescription, const F ontDescription::FamilyDescription& familyDescription) 217 void FontBuilder::setFamilyDescription(FontDescription& fontDescription, const F ontDescription::FamilyDescription& familyDescription)
221 { 218 {
222 FixedPitchFontType oldFixedPitchFontType = fontDescription.fixedPitchFontTyp e(); 219 FixedPitchFontType oldFixedPitchFontType = fontDescription.fixedPitchFontTyp e();
223 220
224 bool isInitial = familyDescription.genericFamily == FontDescription::Standar dFamily && familyDescription.family.familyIsEmpty(); 221 bool isInitial = familyDescription.genericFamily == FontDescription::Standar dFamily && familyDescription.family.familyIsEmpty();
225 222
226 fontDescription.setGenericFamily(familyDescription.genericFamily); 223 fontDescription.setGenericFamily(familyDescription.genericFamily);
227 fontDescription.setFamily(isInitial ? standardFontFamily() : familyDescripti on.family); 224 fontDescription.setFamily(isInitial ? standardFontFamily() : familyDescripti on.family);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 296 }
300 297
301 void FontBuilder::checkForOrientationChange(RenderStyle* style) 298 void FontBuilder::checkForOrientationChange(RenderStyle* style)
302 { 299 {
303 FontOrientation fontOrientation; 300 FontOrientation fontOrientation;
304 NonCJKGlyphOrientation glyphOrientation; 301 NonCJKGlyphOrientation glyphOrientation;
305 getFontAndGlyphOrientation(style, fontOrientation, glyphOrientation); 302 getFontAndGlyphOrientation(style, fontOrientation, glyphOrientation);
306 303
307 FontDescriptionChangeScope scope(this); 304 FontDescriptionChangeScope scope(this);
308 305
309 if (scope.fontDescription().orientation() == fontOrientation && scope.fontDe scription().nonCJKGlyphOrientation() == glyphOrientation) 306 if (m_fontDescription.orientation() == fontOrientation && m_fontDescription. nonCJKGlyphOrientation() == glyphOrientation)
310 return; 307 return;
311 308
312 scope.fontDescription().setNonCJKGlyphOrientation(glyphOrientation); 309 m_fontDescription.setNonCJKGlyphOrientation(glyphOrientation);
313 scope.fontDescription().setOrientation(fontOrientation); 310 m_fontDescription.setOrientation(fontOrientation);
314 } 311 }
315 312
316 void FontBuilder::checkForGenericFamilyChange(RenderStyle* style, const RenderSt yle* parentStyle) 313 void FontBuilder::checkForGenericFamilyChange(RenderStyle* style, const RenderSt yle* parentStyle)
317 { 314 {
318 FontDescriptionChangeScope scope(this); 315 FontDescriptionChangeScope scope(this);
319 316
320 if (scope.fontDescription().isAbsoluteSize() || !parentStyle) 317 if (m_fontDescription.isAbsoluteSize() || !parentStyle)
321 return; 318 return;
322 319
323 const FontDescription& parentFontDescription = parentStyle->fontDescription( ); 320 const FontDescription& parentFontDescription = parentStyle->fontDescription( );
324 if (scope.fontDescription().fixedPitchFontType() == parentFontDescription.fi xedPitchFontType()) 321 if (m_fontDescription.fixedPitchFontType() == parentFontDescription.fixedPit chFontType())
325 return; 322 return;
326 323
327 // For now, lump all families but monospace together. 324 // For now, lump all families but monospace together.
328 if (scope.fontDescription().genericFamily() != FontDescription::MonospaceFam ily 325 if (m_fontDescription.genericFamily() != FontDescription::MonospaceFamily
329 && parentFontDescription.genericFamily() != FontDescription::MonospaceFa mily) 326 && parentFontDescription.genericFamily() != FontDescription::MonospaceFa mily)
330 return; 327 return;
331 328
332 // We know the parent is monospace or the child is monospace, and that font 329 // We know the parent is monospace or the child is monospace, and that font
333 // size was unspecified. We want to scale our font size as appropriate. 330 // size was unspecified. We want to scale our font size as appropriate.
334 // If the font uses a keyword size, then we refetch from the table rather th an 331 // If the font uses a keyword size, then we refetch from the table rather th an
335 // multiplying by our scale factor. 332 // multiplying by our scale factor.
336 float size; 333 float size;
337 if (scope.fontDescription().keywordSize()) { 334 if (m_fontDescription.keywordSize()) {
338 size = FontSize::fontSizeForKeyword(&m_document, scope.fontDescription() .keywordSize(), scope.fontDescription().fixedPitchFontType()); 335 size = FontSize::fontSizeForKeyword(&m_document, m_fontDescription.keywo rdSize(), m_fontDescription.fixedPitchFontType());
339 } else { 336 } else {
340 Settings* settings = m_document.settings(); 337 Settings* settings = m_document.settings();
341 float fixedScaleFactor = (settings && settings->defaultFixedFontSize() & & settings->defaultFontSize()) 338 float fixedScaleFactor = (settings && settings->defaultFixedFontSize() & & settings->defaultFontSize())
342 ? static_cast<float>(settings->defaultFixedFontSize()) / settings->d efaultFontSize() 339 ? static_cast<float>(settings->defaultFixedFontSize()) / settings->d efaultFontSize()
343 : 1; 340 : 1;
344 size = parentFontDescription.fixedPitchFontType() == FixedPitchFont ? 341 size = parentFontDescription.fixedPitchFontType() == FixedPitchFont ?
345 scope.fontDescription().specifiedSize() / fixedScaleFactor : 342 m_fontDescription.specifiedSize() / fixedScaleFactor :
346 scope.fontDescription().specifiedSize() * fixedScaleFactor; 343 m_fontDescription.specifiedSize() * fixedScaleFactor;
347 } 344 }
348 345
349 scope.fontDescription().setSpecifiedSize(size); 346 m_fontDescription.setSpecifiedSize(size);
350 updateComputedSize(scope.fontDescription(), style); 347 updateComputedSize(m_fontDescription, style);
351 } 348 }
352 349
353 void FontBuilder::updateComputedSize(RenderStyle* style, const RenderStyle* pare ntStyle) 350 void FontBuilder::updateComputedSize(RenderStyle* style, const RenderStyle* pare ntStyle)
354 { 351 {
355 FontDescriptionChangeScope scope(this); 352 FontDescriptionChangeScope scope(this);
356 updateComputedSize(scope.fontDescription(), style); 353 updateComputedSize(m_fontDescription, style);
357 } 354 }
358 355
359 void FontBuilder::updateComputedSize(FontDescription& fontDescription, RenderSty le* style) 356 void FontBuilder::updateComputedSize(FontDescription& fontDescription, RenderSty le* style)
360 { 357 {
361 float computedSize = getComputedSizeFromSpecifiedSize(fontDescription, style ->effectiveZoom(), fontDescription.specifiedSize()); 358 float computedSize = getComputedSizeFromSpecifiedSize(fontDescription, style ->effectiveZoom(), fontDescription.specifiedSize());
362 float multiplier = style->textAutosizingMultiplier(); 359 float multiplier = style->textAutosizingMultiplier();
363 if (multiplier > 1) 360 if (multiplier > 1)
364 computedSize = TextAutosizer::computeAutosizedFontSize(computedSize, mul tiplier); 361 computedSize = TextAutosizer::computeAutosizedFontSize(computedSize, mul tiplier);
365 fontDescription.setComputedSize(computedSize); 362 fontDescription.setComputedSize(computedSize);
366 } 363 }
367 364
368 // FIXME: style param should come first 365 void FontBuilder::createFont(PassRefPtrWillBeRawPtr<FontSelector> fontSelector, RenderStyle* style, const RenderStyle* parentStyle)
369 void FontBuilder::createFont(PassRefPtrWillBeRawPtr<FontSelector> fontSelector, const RenderStyle* parentStyle, RenderStyle* style)
370 { 366 {
371 if (!m_fontDirty) 367 if (!m_fontDirty)
372 return; 368 return;
373 369
374 updateComputedSize(style, parentStyle); 370 updateComputedSize(style, parentStyle);
375 checkForGenericFamilyChange(style, parentStyle); 371 checkForGenericFamilyChange(style, parentStyle);
376 checkForOrientationChange(style); 372 checkForOrientationChange(style);
373 style->setFontDescription(m_fontDescription);
377 style->font().update(fontSelector); 374 style->font().update(fontSelector);
378 m_fontDirty = false; 375 m_fontDirty = false;
379 } 376 }
380 377
381 void FontBuilder::createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector> fon tSelector, RenderStyle* documentStyle) 378 void FontBuilder::createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector> fon tSelector, RenderStyle* documentStyle)
382 { 379 {
383 FontDescription fontDescription = FontDescription(); 380 FontDescription fontDescription = FontDescription();
384 fontDescription.setLocale(documentStyle->locale()); 381 fontDescription.setLocale(documentStyle->locale());
385 fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle-> locale())); 382 fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle-> locale()));
386 383
387 setFamilyDescription(fontDescription, FontBuilder::initialFamilyDescription( )); 384 setFamilyDescription(fontDescription, FontBuilder::initialFamilyDescription( ));
388 setSize(fontDescription, FontDescription::Size(FontSize::initialKeywordSize( ), 0.0f, false)); 385 setSize(fontDescription, FontDescription::Size(FontSize::initialKeywordSize( ), 0.0f, false));
389 updateComputedSize(fontDescription, documentStyle); 386 updateComputedSize(fontDescription, documentStyle);
390 387
391 FontOrientation fontOrientation; 388 FontOrientation fontOrientation;
392 NonCJKGlyphOrientation glyphOrientation; 389 NonCJKGlyphOrientation glyphOrientation;
393 getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation) ; 390 getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation) ;
394 fontDescription.setOrientation(fontOrientation); 391 fontDescription.setOrientation(fontOrientation);
395 fontDescription.setNonCJKGlyphOrientation(glyphOrientation); 392 fontDescription.setNonCJKGlyphOrientation(glyphOrientation);
396 documentStyle->setFontDescription(fontDescription); 393 documentStyle->setFontDescription(fontDescription);
397 documentStyle->font().update(fontSelector); 394 documentStyle->font().update(fontSelector);
398 } 395 }
399 396
400 } 397 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698