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

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

Issue 671613003: Eliminate FontBuilder::initForStyleResolve. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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 | « Source/core/css/resolver/FontBuilder.h ('k') | Source/core/css/resolver/FontBuilderTest.cpp » ('j') | 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 * 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 ~FontDescriptionChangeScope() 53 ~FontDescriptionChangeScope()
54 { 54 {
55 m_fontBuilder->didChangeFontParameters(m_fontBuilder->m_style->setFontDe scription(m_fontDescription)); 55 m_fontBuilder->didChangeFontParameters(m_fontBuilder->m_style->setFontDe scription(m_fontDescription));
56 } 56 }
57 57
58 private: 58 private:
59 RawPtrWillBeMember<FontBuilder> m_fontBuilder; 59 RawPtrWillBeMember<FontBuilder> m_fontBuilder;
60 FontDescription m_fontDescription; 60 FontDescription m_fontDescription;
61 }; 61 };
62 62
63 FontBuilder::FontBuilder() 63 FontBuilder::FontBuilder(const Document& document)
64 : m_document(nullptr) 64 : m_document(document)
65 , m_style(0) 65 , m_style(nullptr)
66 , m_fontDirty(false) 66 , m_fontDirty(false)
67 { 67 {
68 }
69
70 void FontBuilder::initForStyleResolve(const Document& document, RenderStyle* sty le)
71 {
72 ASSERT(document.frame()); 68 ASSERT(document.frame());
73 m_document = &document;
74 m_style = style;
75 m_fontDirty = false;
76 } 69 }
77 70
78 void FontBuilder::setInitial(float effectiveZoom) 71 void FontBuilder::setInitial(float effectiveZoom)
79 { 72 {
80 ASSERT(m_document && m_document->settings()); 73 ASSERT(m_document.settings());
81 if (!m_document || !m_document->settings()) 74 if (!m_document.settings())
82 return; 75 return;
83 76
84 FontDescriptionChangeScope scope(this); 77 FontDescriptionChangeScope scope(this);
85 78
86 scope.reset(); 79 scope.reset();
87 setFamilyDescription(scope.fontDescription(), FontBuilder::initialFamilyDesc ription()); 80 setFamilyDescription(scope.fontDescription(), FontBuilder::initialFamilyDesc ription());
88 setSize(scope.fontDescription(), FontBuilder::initialSize()); 81 setSize(scope.fontDescription(), FontBuilder::initialSize());
89 } 82 }
90 83
91 void FontBuilder::inheritFrom(const FontDescription& fontDescription) 84 void FontBuilder::inheritFrom(const FontDescription& fontDescription)
(...skipping 13 matching lines...) Expand all
105 FontDescriptionChangeScope scope(this); 98 FontDescriptionChangeScope scope(this);
106 99
107 FontDescription fontDescription; 100 FontDescription fontDescription;
108 RenderTheme::theme().systemFont(valueId, fontDescription); 101 RenderTheme::theme().systemFont(valueId, fontDescription);
109 102
110 // Double-check and see if the theme did anything. If not, don't bother upda ting the font. 103 // Double-check and see if the theme did anything. If not, don't bother upda ting the font.
111 if (!fontDescription.isAbsoluteSize()) 104 if (!fontDescription.isAbsoluteSize())
112 return; 105 return;
113 106
114 // Make sure the rendering mode and printer font settings are updated. 107 // Make sure the rendering mode and printer font settings are updated.
115 const Settings* settings = m_document->settings(); 108 const Settings* settings = m_document.settings();
116 ASSERT(settings); // If we're doing style resolution, this document should a lways be in a frame and thus have settings 109 ASSERT(settings); // If we're doing style resolution, this document should a lways be in a frame and thus have settings
117 if (!settings) 110 if (!settings)
118 return; 111 return;
119 112
120 // Handle the zoom factor. 113 // Handle the zoom factor.
121 fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescrip tion, effectiveZoom, fontDescription.specifiedSize())); 114 fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescrip tion, effectiveZoom, fontDescription.specifiedSize()));
122 scope.set(fontDescription); 115 scope.set(fontDescription);
123 } 116 }
124 117
125 FontFamily FontBuilder::standardFontFamily() const 118 FontFamily FontBuilder::standardFontFamily() const
126 { 119 {
127 FontFamily family; 120 FontFamily family;
128 family.setFamily(standardFontFamilyName()); 121 family.setFamily(standardFontFamilyName());
129 return family; 122 return family;
130 } 123 }
131 124
132 AtomicString FontBuilder::standardFontFamilyName() const 125 AtomicString FontBuilder::standardFontFamilyName() const
133 { 126 {
134 ASSERT(m_document); 127 Settings* settings = m_document.settings();
135 Settings* settings = m_document->settings();
136 if (settings) 128 if (settings)
137 return settings->genericFontFamilySettings().standard(); 129 return settings->genericFontFamilySettings().standard();
138 return AtomicString(); 130 return AtomicString();
139 } 131 }
140 132
141 AtomicString FontBuilder::genericFontFamilyName(FontDescription::GenericFamilyTy pe genericFamily) const 133 AtomicString FontBuilder::genericFontFamilyName(FontDescription::GenericFamilyTy pe genericFamily) const
142 { 134 {
143 switch (genericFamily) { 135 switch (genericFamily) {
144 default: 136 default:
145 ASSERT_NOT_REACHED(); 137 ASSERT_NOT_REACHED();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 250
259 if (fontDescription.keywordSize() && fontDescription.fixedPitchFontType() != oldFixedPitchFontType) 251 if (fontDescription.keywordSize() && fontDescription.fixedPitchFontType() != oldFixedPitchFontType)
260 setSize(fontDescription, FontDescription::Size(fontDescription.keywordSi ze(), 0.0f, false)); 252 setSize(fontDescription, FontDescription::Size(fontDescription.keywordSi ze(), 0.0f, false));
261 } 253 }
262 254
263 void FontBuilder::setSize(FontDescription& fontDescription, const FontDescriptio n::Size& size) 255 void FontBuilder::setSize(FontDescription& fontDescription, const FontDescriptio n::Size& size)
264 { 256 {
265 float specifiedSize = size.value; 257 float specifiedSize = size.value;
266 258
267 if (!specifiedSize && size.keyword) 259 if (!specifiedSize && size.keyword)
268 specifiedSize = FontSize::fontSizeForKeyword(m_document, size.keyword, f ontDescription.fixedPitchFontType()); 260 specifiedSize = FontSize::fontSizeForKeyword(&m_document, size.keyword, fontDescription.fixedPitchFontType());
269 261
270 if (specifiedSize < 0) 262 if (specifiedSize < 0)
271 return; 263 return;
272 264
273 // Overly large font sizes will cause crashes on some platforms (such as Win dows). 265 // Overly large font sizes will cause crashes on some platforms (such as Win dows).
274 // Cap font size here to make sure that doesn't happen. 266 // Cap font size here to make sure that doesn't happen.
275 specifiedSize = std::min(maximumAllowedFontSize, specifiedSize); 267 specifiedSize = std::min(maximumAllowedFontSize, specifiedSize);
276 268
277 fontDescription.setKeywordSize(size.keyword); 269 fontDescription.setKeywordSize(size.keyword);
278 fontDescription.setSpecifiedSize(specifiedSize); 270 fontDescription.setSpecifiedSize(specifiedSize);
279 fontDescription.setIsAbsoluteSize(size.isAbsolute); 271 fontDescription.setIsAbsoluteSize(size.isAbsolute);
280 } 272 }
281 273
282 float FontBuilder::getComputedSizeFromSpecifiedSize(FontDescription& fontDescrip tion, float effectiveZoom, float specifiedSize) 274 float FontBuilder::getComputedSizeFromSpecifiedSize(FontDescription& fontDescrip tion, float effectiveZoom, float specifiedSize)
283 { 275 {
284 float zoomFactor = effectiveZoom; 276 float zoomFactor = effectiveZoom;
285 // FIXME: Why is this here!!!!?! 277 // FIXME: Why is this here!!!!?!
286 if (LocalFrame* frame = m_document->frame()) 278 if (LocalFrame* frame = m_document.frame())
287 zoomFactor *= frame->textZoomFactor(); 279 zoomFactor *= frame->textZoomFactor();
288 280
289 return FontSize::getComputedSizeFromSpecifiedSize(m_document, zoomFactor, fo ntDescription.isAbsoluteSize(), specifiedSize); 281 return FontSize::getComputedSizeFromSpecifiedSize(&m_document, zoomFactor, f ontDescription.isAbsoluteSize(), specifiedSize);
290 } 282 }
291 283
292 static void getFontAndGlyphOrientation(const RenderStyle* style, FontOrientation & fontOrientation, NonCJKGlyphOrientation& glyphOrientation) 284 static void getFontAndGlyphOrientation(const RenderStyle* style, FontOrientation & fontOrientation, NonCJKGlyphOrientation& glyphOrientation)
293 { 285 {
294 if (style->isHorizontalWritingMode()) { 286 if (style->isHorizontalWritingMode()) {
295 fontOrientation = Horizontal; 287 fontOrientation = Horizontal;
296 glyphOrientation = NonCJKGlyphOrientationVerticalRight; 288 glyphOrientation = NonCJKGlyphOrientationVerticalRight;
297 return; 289 return;
298 } 290 }
299 291
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (scope.fontDescription().genericFamily() != FontDescription::MonospaceFam ily 350 if (scope.fontDescription().genericFamily() != FontDescription::MonospaceFam ily
359 && parentFontDescription.genericFamily() != FontDescription::MonospaceFa mily) 351 && parentFontDescription.genericFamily() != FontDescription::MonospaceFa mily)
360 return; 352 return;
361 353
362 // We know the parent is monospace or the child is monospace, and that font 354 // We know the parent is monospace or the child is monospace, and that font
363 // size was unspecified. We want to scale our font size as appropriate. 355 // size was unspecified. We want to scale our font size as appropriate.
364 // If the font uses a keyword size, then we refetch from the table rather th an 356 // If the font uses a keyword size, then we refetch from the table rather th an
365 // multiplying by our scale factor. 357 // multiplying by our scale factor.
366 float size; 358 float size;
367 if (scope.fontDescription().keywordSize()) { 359 if (scope.fontDescription().keywordSize()) {
368 size = FontSize::fontSizeForKeyword(m_document, scope.fontDescription(). keywordSize(), scope.fontDescription().fixedPitchFontType()); 360 size = FontSize::fontSizeForKeyword(&m_document, scope.fontDescription() .keywordSize(), scope.fontDescription().fixedPitchFontType());
369 } else { 361 } else {
370 Settings* settings = m_document->settings(); 362 Settings* settings = m_document.settings();
371 float fixedScaleFactor = (settings && settings->defaultFixedFontSize() & & settings->defaultFontSize()) 363 float fixedScaleFactor = (settings && settings->defaultFixedFontSize() & & settings->defaultFontSize())
372 ? static_cast<float>(settings->defaultFixedFontSize()) / settings->d efaultFontSize() 364 ? static_cast<float>(settings->defaultFixedFontSize()) / settings->d efaultFontSize()
373 : 1; 365 : 1;
374 size = parentFontDescription.fixedPitchFontType() == FixedPitchFont ? 366 size = parentFontDescription.fixedPitchFontType() == FixedPitchFont ?
375 scope.fontDescription().specifiedSize() / fixedScaleFactor : 367 scope.fontDescription().specifiedSize() / fixedScaleFactor :
376 scope.fontDescription().specifiedSize() * fixedScaleFactor; 368 scope.fontDescription().specifiedSize() * fixedScaleFactor;
377 } 369 }
378 370
379 scope.fontDescription().setSpecifiedSize(size); 371 scope.fontDescription().setSpecifiedSize(size);
380 updateComputedSize(scope.fontDescription(), style); 372 updateComputedSize(scope.fontDescription(), style);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 FontOrientation fontOrientation; 413 FontOrientation fontOrientation;
422 NonCJKGlyphOrientation glyphOrientation; 414 NonCJKGlyphOrientation glyphOrientation;
423 getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation) ; 415 getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation) ;
424 fontDescription.setOrientation(fontOrientation); 416 fontDescription.setOrientation(fontOrientation);
425 fontDescription.setNonCJKGlyphOrientation(glyphOrientation); 417 fontDescription.setNonCJKGlyphOrientation(glyphOrientation);
426 documentStyle->setFontDescription(fontDescription); 418 documentStyle->setFontDescription(fontDescription);
427 documentStyle->font().update(fontSelector); 419 documentStyle->font().update(fontSelector);
428 } 420 }
429 421
430 } 422 }
OLDNEW
« no previous file with comments | « Source/core/css/resolver/FontBuilder.h ('k') | Source/core/css/resolver/FontBuilderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698