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

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

Issue 602373003: Make style building for 'font-family' less custom. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Init genericFamily in all cases. 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
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 *
11 * This library is distributed in the hope that it will be useful, 11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details. 14 * Library General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Library General Public License 16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to 17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA. 19 * Boston, MA 02110-1301, USA.
20 * 20 *
21 */ 21 */
22 22
23 #include "config.h" 23 #include "config.h"
24 #include "core/css/resolver/FontBuilder.h" 24 #include "core/css/resolver/FontBuilder.h"
25 25
26 #include "core/css/CSSCalculationValue.h" 26 #include "core/CSSValueKeywords.h"
27 #include "core/css/CSSToLengthConversionData.h"
28 #include "core/frame/LocalFrame.h" 27 #include "core/frame/LocalFrame.h"
29 #include "core/frame/Settings.h" 28 #include "core/frame/Settings.h"
30 #include "core/rendering/RenderTheme.h" 29 #include "core/rendering/RenderTheme.h"
31 #include "core/rendering/RenderView.h" 30 #include "core/rendering/RenderView.h"
32 #include "core/rendering/TextAutosizer.h" 31 #include "core/rendering/TextAutosizer.h"
32 #include "platform/FontFamilyNames.h"
33 #include "platform/fonts/FontDescription.h" 33 #include "platform/fonts/FontDescription.h"
34 #include "platform/text/LocaleToScriptMapping.h" 34 #include "platform/text/LocaleToScriptMapping.h"
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:
(...skipping 25 matching lines...) Expand all
68 } 68 }
69 69
70 void FontBuilder::initForStyleResolve(const Document& document, RenderStyle* sty le) 70 void FontBuilder::initForStyleResolve(const Document& document, RenderStyle* sty le)
71 { 71 {
72 ASSERT(document.frame()); 72 ASSERT(document.frame());
73 m_document = &document; 73 m_document = &document;
74 m_style = style; 74 m_style = style;
75 m_fontDirty = false; 75 m_fontDirty = false;
76 } 76 }
77 77
78 inline static void setFontFamilyToStandard(FontDescription& fontDescription, con st Document* document)
79 {
80 if (!document || !document->settings())
81 return;
82
83 fontDescription.setGenericFamily(FontDescription::StandardFamily);
84 const AtomicString& standardFontFamily = document->settings()->genericFontFa milySettings().standard();
85 if (standardFontFamily.isEmpty())
86 return;
87
88 fontDescription.firstFamily().setFamily(standardFontFamily);
89 // FIXME: Why is this needed here?
90 fontDescription.firstFamily().appendFamily(nullptr);
91 }
92
93 void FontBuilder::setInitial(float effectiveZoom) 78 void FontBuilder::setInitial(float effectiveZoom)
94 { 79 {
95 ASSERT(m_document && m_document->settings()); 80 ASSERT(m_document && m_document->settings());
96 if (!m_document || !m_document->settings()) 81 if (!m_document || !m_document->settings())
97 return; 82 return;
98 83
99 FontDescriptionChangeScope scope(this); 84 FontDescriptionChangeScope scope(this);
100 85
101 scope.reset(); 86 scope.reset();
102 setFontFamilyToStandard(scope.fontDescription(), m_document); 87 setFamilyDescription(scope.fontDescription(), FontBuilder::initialFamilyDesc ription());
103 setSize(scope.fontDescription(), FontBuilder::initialSize()); 88 setSize(scope.fontDescription(), FontBuilder::initialSize());
104 } 89 }
105 90
106 void FontBuilder::inheritFrom(const FontDescription& fontDescription) 91 void FontBuilder::inheritFrom(const FontDescription& fontDescription)
107 { 92 {
108 FontDescriptionChangeScope scope(this); 93 FontDescriptionChangeScope scope(this);
109 94
110 scope.set(fontDescription); 95 scope.set(fontDescription);
111 } 96 }
112 97
(...skipping 17 matching lines...) Expand all
130 const Settings* settings = m_document->settings(); 115 const Settings* settings = m_document->settings();
131 ASSERT(settings); // If we're doing style resolution, this document should a lways be in a frame and thus have settings 116 ASSERT(settings); // If we're doing style resolution, this document should a lways be in a frame and thus have settings
132 if (!settings) 117 if (!settings)
133 return; 118 return;
134 119
135 // Handle the zoom factor. 120 // Handle the zoom factor.
136 fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescrip tion, effectiveZoom, fontDescription.specifiedSize())); 121 fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescrip tion, effectiveZoom, fontDescription.specifiedSize()));
137 scope.set(fontDescription); 122 scope.set(fontDescription);
138 } 123 }
139 124
140 void FontBuilder::setFontFamilyInitial() 125 FontFamily FontBuilder::standardFontFamily() const
126 {
127 FontFamily family;
128 family.setFamily(standardFontFamilyName());
129 return family;
130 }
131
132 AtomicString FontBuilder::standardFontFamilyName() const
133 {
134 ASSERT(m_document);
135 Settings* settings = m_document->settings();
136 if (settings)
137 return settings->genericFontFamilySettings().standard();
138 return AtomicString();
139 }
140
141 AtomicString FontBuilder::genericFontFamilyName(FontDescription::GenericFamilyTy pe genericFamily) const
142 {
143 switch (genericFamily) {
144 default:
145 ASSERT_NOT_REACHED();
146 case FontDescription::NoFamily:
147 return AtomicString();
148 case FontDescription::StandardFamily:
149 return standardFontFamilyName();
150 case FontDescription::SerifFamily:
151 return FontFamilyNames::webkit_serif;
152 case FontDescription::SansSerifFamily:
153 return FontFamilyNames::webkit_sans_serif;
154 case FontDescription::MonospaceFamily:
155 return FontFamilyNames::webkit_monospace;
156 case FontDescription::CursiveFamily:
157 return FontFamilyNames::webkit_cursive;
158 case FontDescription::FantasyFamily:
159 return FontFamilyNames::webkit_fantasy;
160 case FontDescription::PictographFamily:
161 return FontFamilyNames::webkit_pictograph;
162 }
163 }
164
165 void FontBuilder::setFamilyDescription(const FontDescription::FamilyDescription& familyDescription)
141 { 166 {
142 FontDescriptionChangeScope scope(this); 167 FontDescriptionChangeScope scope(this);
143 168
144 setFontFamilyToStandard(scope.fontDescription(), m_document); 169 setFamilyDescription(scope.fontDescription(), familyDescription);
145 }
146
147 void FontBuilder::setFontFamilyInherit(const FontDescription& parentFontDescript ion)
148 {
149 FontDescriptionChangeScope scope(this);
150
151 scope.fontDescription().setGenericFamily(parentFontDescription.genericFamily ());
152 scope.fontDescription().setFamily(parentFontDescription.family());
153 }
154
155 // FIXME: I am not convinced FontBuilder needs to know anything about CSSValues.
156 void FontBuilder::setFontFamilyValue(CSSValue* value)
157 {
158 FontDescriptionChangeScope scope(this);
159
160 if (!value->isValueList())
161 return;
162
163 FontFamily& firstFamily = scope.fontDescription().firstFamily();
164 FontFamily* currFamily = 0;
165
166 // Before mapping in a new font-family property, we should reset the generic family.
167 FixedPitchFontType oldFixedPitchFontType = scope.fontDescription().fixedPitc hFontType();
168 scope.fontDescription().setGenericFamily(FontDescription::NoFamily);
169
170 for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
171 CSSValue* item = i.value();
172 if (!item->isPrimitiveValue())
173 continue;
174 CSSPrimitiveValue* contentValue = toCSSPrimitiveValue(item);
175 AtomicString face;
176 Settings* settings = m_document->settings();
177 if (contentValue->isString()) {
178 face = AtomicString(contentValue->getStringValue());
179 } else if (settings) {
180 switch (contentValue->getValueID()) {
181 case CSSValueWebkitBody:
182 face = settings->genericFontFamilySettings().standard();
183 break;
184 case CSSValueSerif:
185 face = FontFamilyNames::webkit_serif;
186 scope.fontDescription().setGenericFamily(FontDescription::SerifF amily);
187 break;
188 case CSSValueSansSerif:
189 face = FontFamilyNames::webkit_sans_serif;
190 scope.fontDescription().setGenericFamily(FontDescription::SansSe rifFamily);
191 break;
192 case CSSValueCursive:
193 face = FontFamilyNames::webkit_cursive;
194 scope.fontDescription().setGenericFamily(FontDescription::Cursiv eFamily);
195 break;
196 case CSSValueFantasy:
197 face = FontFamilyNames::webkit_fantasy;
198 scope.fontDescription().setGenericFamily(FontDescription::Fantas yFamily);
199 break;
200 case CSSValueMonospace:
201 face = FontFamilyNames::webkit_monospace;
202 scope.fontDescription().setGenericFamily(FontDescription::Monosp aceFamily);
203 break;
204 case CSSValueWebkitPictograph:
205 face = FontFamilyNames::webkit_pictograph;
206 scope.fontDescription().setGenericFamily(FontDescription::Pictog raphFamily);
207 break;
208 default:
209 break;
210 }
211 }
212
213 if (!face.isEmpty()) {
214 if (!currFamily) {
215 // Filling in the first family.
216 firstFamily.setFamily(face);
217 firstFamily.appendFamily(nullptr); // Remove any inherited famil y-fallback list.
218 currFamily = &firstFamily;
219 } else {
220 RefPtr<SharedFontFamily> newFamily = SharedFontFamily::create();
221 newFamily->setFamily(face);
222 currFamily->appendFamily(newFamily);
223 currFamily = newFamily.get();
224 }
225 }
226 }
227
228 // We can't call useFixedDefaultSize() until all new font families have been added
229 // If currFamily is non-zero then we set at least one family on this descrip tion.
230 if (!currFamily)
231 return;
232
233 if (scope.fontDescription().keywordSize() && scope.fontDescription().fixedPi tchFontType() != oldFixedPitchFontType)
234 setSize(scope.fontDescription(), FontDescription::Size(scope.fontDescrip tion().keywordSize(), 0.0f, false));
235 } 170 }
236 171
237 void FontBuilder::setWeight(FontWeight fontWeight) 172 void FontBuilder::setWeight(FontWeight fontWeight)
238 { 173 {
239 FontDescriptionChangeScope scope(this); 174 FontDescriptionChangeScope scope(this);
240 175
241 scope.fontDescription().setWeight(fontWeight); 176 scope.fontDescription().setWeight(fontWeight);
242 } 177 }
243 178
244 void FontBuilder::setSize(const FontDescription::Size& size) 179 void FontBuilder::setSize(const FontDescription::Size& size)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 scope.fontDescription().setFontSmoothing(foontSmoothingMode); 240 scope.fontDescription().setFontSmoothing(foontSmoothingMode);
306 } 241 }
307 242
308 void FontBuilder::setFeatureSettings(PassRefPtr<FontFeatureSettings> settings) 243 void FontBuilder::setFeatureSettings(PassRefPtr<FontFeatureSettings> settings)
309 { 244 {
310 FontDescriptionChangeScope scope(this); 245 FontDescriptionChangeScope scope(this);
311 246
312 scope.fontDescription().setFeatureSettings(settings); 247 scope.fontDescription().setFeatureSettings(settings);
313 } 248 }
314 249
250 void FontBuilder::setFamilyDescription(FontDescription& fontDescription, const F ontDescription::FamilyDescription& familyDescription)
251 {
252 FixedPitchFontType oldFixedPitchFontType = fontDescription.fixedPitchFontTyp e();
253
254 bool isInitial = familyDescription.genericFamily == FontDescription::Standar dFamily && familyDescription.family.familyIsEmpty();
255
256 fontDescription.setGenericFamily(familyDescription.genericFamily);
257 fontDescription.setFamily(isInitial ? standardFontFamily() : familyDescripti on.family);
258
259 if (fontDescription.keywordSize() && fontDescription.fixedPitchFontType() != oldFixedPitchFontType)
260 setSize(fontDescription, FontDescription::Size(fontDescription.keywordSi ze(), 0.0f, false));
261 }
262
315 void FontBuilder::setSize(FontDescription& fontDescription, const FontDescriptio n::Size& size) 263 void FontBuilder::setSize(FontDescription& fontDescription, const FontDescriptio n::Size& size)
316 { 264 {
317 float specifiedSize = size.value; 265 float specifiedSize = size.value;
318 266
319 if (!specifiedSize && size.keyword) 267 if (!specifiedSize && size.keyword)
320 specifiedSize = FontSize::fontSizeForKeyword(m_document, size.keyword, f ontDescription.fixedPitchFontType()); 268 specifiedSize = FontSize::fontSizeForKeyword(m_document, size.keyword, f ontDescription.fixedPitchFontType());
321 269
322 if (specifiedSize < 0) 270 if (specifiedSize < 0)
323 return; 271 return;
324 272
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 checkForOrientationChange(style); 406 checkForOrientationChange(style);
459 style->font().update(fontSelector); 407 style->font().update(fontSelector);
460 m_fontDirty = false; 408 m_fontDirty = false;
461 } 409 }
462 410
463 void FontBuilder::createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector> fon tSelector, RenderStyle* documentStyle) 411 void FontBuilder::createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector> fon tSelector, RenderStyle* documentStyle)
464 { 412 {
465 FontDescription fontDescription = FontDescription(); 413 FontDescription fontDescription = FontDescription();
466 fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle-> locale())); 414 fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle-> locale()));
467 415
468 setFontFamilyToStandard(fontDescription, m_document); 416 setFamilyDescription(fontDescription, FontBuilder::initialFamilyDescription( ));
469
470 setSize(fontDescription, FontDescription::Size(FontSize::initialKeywordSize( ), 0.0f, false)); 417 setSize(fontDescription, FontDescription::Size(FontSize::initialKeywordSize( ), 0.0f, false));
471 updateComputedSize(fontDescription, documentStyle); 418 updateComputedSize(fontDescription, documentStyle);
472 419
473 FontOrientation fontOrientation; 420 FontOrientation fontOrientation;
474 NonCJKGlyphOrientation glyphOrientation; 421 NonCJKGlyphOrientation glyphOrientation;
475 getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation) ; 422 getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation) ;
476 fontDescription.setOrientation(fontOrientation); 423 fontDescription.setOrientation(fontOrientation);
477 fontDescription.setNonCJKGlyphOrientation(glyphOrientation); 424 fontDescription.setNonCJKGlyphOrientation(glyphOrientation);
478 documentStyle->setFontDescription(fontDescription); 425 documentStyle->setFontDescription(fontDescription);
479 documentStyle->font().update(fontSelector); 426 documentStyle->font().update(fontSelector);
480 } 427 }
481 428
482 } 429 }
OLDNEW
« no previous file with comments | « Source/core/css/resolver/FontBuilder.h ('k') | Source/core/css/resolver/StyleBuilderConverter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698