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

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

Issue 342883004: Using Enum in place of bool for better code readability (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Comment fixes Created 6 years, 5 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/FontSize.cpp ('k') | Source/core/editing/EditingStyle.h » ('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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 { 95 {
96 ASSERT(m_document && m_document->settings()); 96 ASSERT(m_document && m_document->settings());
97 if (!m_document || !m_document->settings()) 97 if (!m_document || !m_document->settings())
98 return; 98 return;
99 99
100 FontDescriptionChangeScope scope(this); 100 FontDescriptionChangeScope scope(this);
101 101
102 scope.reset(); 102 scope.reset();
103 setFontFamilyToStandard(scope.fontDescription(), m_document); 103 setFontFamilyToStandard(scope.fontDescription(), m_document);
104 scope.fontDescription().setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1) ; 104 scope.fontDescription().setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1) ;
105 setSize(scope.fontDescription(), effectiveZoom, FontSize::fontSizeForKeyword (m_document, CSSValueMedium, false)); 105 setSize(scope.fontDescription(), effectiveZoom, FontSize::fontSizeForKeyword (m_document, CSSValueMedium, NonFixedPitchFont));
106 } 106 }
107 107
108 void FontBuilder::inheritFrom(const FontDescription& fontDescription) 108 void FontBuilder::inheritFrom(const FontDescription& fontDescription)
109 { 109 {
110 FontDescriptionChangeScope scope(this); 110 FontDescriptionChangeScope scope(this);
111 111
112 scope.set(fontDescription); 112 scope.set(fontDescription);
113 } 113 }
114 114
115 void FontBuilder::didChangeFontParameters(bool changed) 115 void FontBuilder::didChangeFontParameters(bool changed)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 { 159 {
160 FontDescriptionChangeScope scope(this); 160 FontDescriptionChangeScope scope(this);
161 161
162 if (!value->isValueList()) 162 if (!value->isValueList())
163 return; 163 return;
164 164
165 FontFamily& firstFamily = scope.fontDescription().firstFamily(); 165 FontFamily& firstFamily = scope.fontDescription().firstFamily();
166 FontFamily* currFamily = 0; 166 FontFamily* currFamily = 0;
167 167
168 // Before mapping in a new font-family property, we should reset the generic family. 168 // Before mapping in a new font-family property, we should reset the generic family.
169 bool oldFamilyUsedFixedDefaultSize = scope.fontDescription().useFixedDefault Size(); 169 FixedPitchFontType oldFixedPitchFontType = scope.fontDescription().fixedPitc hFontType();
170 scope.fontDescription().setGenericFamily(FontDescription::NoFamily); 170 scope.fontDescription().setGenericFamily(FontDescription::NoFamily);
171 171
172 for (CSSValueListIterator i = value; i.hasMore(); i.advance()) { 172 for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
173 CSSValue* item = i.value(); 173 CSSValue* item = i.value();
174 if (!item->isPrimitiveValue()) 174 if (!item->isPrimitiveValue())
175 continue; 175 continue;
176 CSSPrimitiveValue* contentValue = toCSSPrimitiveValue(item); 176 CSSPrimitiveValue* contentValue = toCSSPrimitiveValue(item);
177 AtomicString face; 177 AtomicString face;
178 Settings* settings = m_document->settings(); 178 Settings* settings = m_document->settings();
179 if (contentValue->isString()) { 179 if (contentValue->isString()) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 currFamily = newFamily.get(); 225 currFamily = newFamily.get();
226 } 226 }
227 } 227 }
228 } 228 }
229 229
230 // We can't call useFixedDefaultSize() until all new font families have been added 230 // We can't call useFixedDefaultSize() until all new font families have been added
231 // If currFamily is non-zero then we set at least one family on this descrip tion. 231 // If currFamily is non-zero then we set at least one family on this descrip tion.
232 if (!currFamily) 232 if (!currFamily)
233 return; 233 return;
234 234
235 if (scope.fontDescription().keywordSize() && scope.fontDescription().useFixe dDefaultSize() != oldFamilyUsedFixedDefaultSize) 235 if (scope.fontDescription().keywordSize() && scope.fontDescription().fixedPi tchFontType() != oldFixedPitchFontType) {
236 scope.fontDescription().setSpecifiedSize(FontSize::fontSizeForKeyword(m_ document, CSSValueXxSmall + scope.fontDescription().keywordSize() - 1, !oldFamil yUsedFixedDefaultSize)); 236 scope.fontDescription().setSpecifiedSize(FontSize::fontSizeForKeyword(m_ document,
237 static_cast<CSSValueID>(CSSValueXxSmall + scope.fontDescription().keywor dSize() - 1), scope.fontDescription().fixedPitchFontType()));
238 }
237 } 239 }
238 240
239 void FontBuilder::setFontSizeInitial() 241 void FontBuilder::setFontSizeInitial()
240 { 242 {
241 FontDescriptionChangeScope scope(this); 243 FontDescriptionChangeScope scope(this);
242 244
243 float size = FontSize::fontSizeForKeyword(m_document, CSSValueMedium, scope. fontDescription().useFixedDefaultSize()); 245 float size = FontSize::fontSizeForKeyword(m_document, CSSValueMedium, scope. fontDescription().fixedPitchFontType());
244 246
245 if (size < 0) 247 if (size < 0)
246 return; 248 return;
247 249
248 scope.fontDescription().setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1) ; 250 scope.fontDescription().setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1) ;
249 scope.fontDescription().setSpecifiedSize(size); 251 scope.fontDescription().setSpecifiedSize(size);
250 } 252 }
251 253
252 void FontBuilder::setFontSizeInherit(const FontDescription& parentFontDescriptio n) 254 void FontBuilder::setFontSizeInherit(const FontDescription& parentFontDescriptio n)
253 { 255 {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 if (CSSValueID valueID = primitiveValue->getValueID()) { 300 if (CSSValueID valueID = primitiveValue->getValueID()) {
299 switch (valueID) { 301 switch (valueID) {
300 case CSSValueXxSmall: 302 case CSSValueXxSmall:
301 case CSSValueXSmall: 303 case CSSValueXSmall:
302 case CSSValueSmall: 304 case CSSValueSmall:
303 case CSSValueMedium: 305 case CSSValueMedium:
304 case CSSValueLarge: 306 case CSSValueLarge:
305 case CSSValueXLarge: 307 case CSSValueXLarge:
306 case CSSValueXxLarge: 308 case CSSValueXxLarge:
307 case CSSValueWebkitXxxLarge: 309 case CSSValueWebkitXxxLarge:
308 size = FontSize::fontSizeForKeyword(m_document, valueID, scope.fontD escription().useFixedDefaultSize()); 310 size = FontSize::fontSizeForKeyword(m_document, valueID, scope.fontD escription().fixedPitchFontType());
309 scope.fontDescription().setKeywordSize(valueID - CSSValueXxSmall + 1 ); 311 scope.fontDescription().setKeywordSize(valueID - CSSValueXxSmall + 1 );
310 break; 312 break;
311 case CSSValueLarger: 313 case CSSValueLarger:
312 size = largerFontSize(parentSize); 314 size = largerFontSize(parentSize);
313 break; 315 break;
314 case CSSValueSmaller: 316 case CSSValueSmaller:
315 size = smallerFontSize(parentSize); 317 size = smallerFontSize(parentSize);
316 break; 318 break;
317 default: 319 default:
318 return; 320 return;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 } 593 }
592 594
593 void FontBuilder::checkForGenericFamilyChange(RenderStyle* style, const RenderSt yle* parentStyle) 595 void FontBuilder::checkForGenericFamilyChange(RenderStyle* style, const RenderSt yle* parentStyle)
594 { 596 {
595 FontDescriptionChangeScope scope(this); 597 FontDescriptionChangeScope scope(this);
596 598
597 if (scope.fontDescription().isAbsoluteSize() || !parentStyle) 599 if (scope.fontDescription().isAbsoluteSize() || !parentStyle)
598 return; 600 return;
599 601
600 const FontDescription& parentFontDescription = parentStyle->fontDescription( ); 602 const FontDescription& parentFontDescription = parentStyle->fontDescription( );
601 if (scope.fontDescription().useFixedDefaultSize() == parentFontDescription.u seFixedDefaultSize()) 603 if (scope.fontDescription().fixedPitchFontType() == parentFontDescription.fi xedPitchFontType())
602 return; 604 return;
603 605
604 // For now, lump all families but monospace together. 606 // For now, lump all families but monospace together.
605 if (scope.fontDescription().genericFamily() != FontDescription::MonospaceFam ily 607 if (scope.fontDescription().genericFamily() != FontDescription::MonospaceFam ily
606 && parentFontDescription.genericFamily() != FontDescription::MonospaceFa mily) 608 && parentFontDescription.genericFamily() != FontDescription::MonospaceFa mily)
607 return; 609 return;
608 610
609 // We know the parent is monospace or the child is monospace, and that font 611 // We know the parent is monospace or the child is monospace, and that font
610 // size was unspecified. We want to scale our font size as appropriate. 612 // size was unspecified. We want to scale our font size as appropriate.
611 // If the font uses a keyword size, then we refetch from the table rather th an 613 // If the font uses a keyword size, then we refetch from the table rather th an
612 // multiplying by our scale factor. 614 // multiplying by our scale factor.
613 float size; 615 float size;
614 if (scope.fontDescription().keywordSize()) { 616 if (scope.fontDescription().keywordSize()) {
615 size = FontSize::fontSizeForKeyword(m_document, CSSValueXxSmall + scope. fontDescription().keywordSize() - 1, scope.fontDescription().useFixedDefaultSize ()); 617 size = FontSize::fontSizeForKeyword(m_document, static_cast<CSSValueID>( CSSValueXxSmall + scope.fontDescription().keywordSize() - 1), scope.fontDescript ion().fixedPitchFontType());
616 } else { 618 } else {
617 Settings* settings = m_document->settings(); 619 Settings* settings = m_document->settings();
618 float fixedScaleFactor = (settings && settings->defaultFixedFontSize() & & settings->defaultFontSize()) 620 float fixedScaleFactor = (settings && settings->defaultFixedFontSize() & & settings->defaultFontSize())
619 ? static_cast<float>(settings->defaultFixedFontSize()) / settings->d efaultFontSize() 621 ? static_cast<float>(settings->defaultFixedFontSize()) / settings->d efaultFontSize()
620 : 1; 622 : 1;
621 size = parentFontDescription.useFixedDefaultSize() ? 623 size = parentFontDescription.fixedPitchFontType() == FixedPitchFont ?
622 scope.fontDescription().specifiedSize() / fixedScaleFactor : 624 scope.fontDescription().specifiedSize() / fixedScaleFactor :
623 scope.fontDescription().specifiedSize() * fixedScaleFactor; 625 scope.fontDescription().specifiedSize() * fixedScaleFactor;
624 } 626 }
625 627
626 setSize(scope.fontDescription(), style->effectiveZoom(), size); 628 setSize(scope.fontDescription(), style->effectiveZoom(), size);
627 } 629 }
628 630
629 void FontBuilder::updateComputedSize(RenderStyle* style, const RenderStyle* pare ntStyle) 631 void FontBuilder::updateComputedSize(RenderStyle* style, const RenderStyle* pare ntStyle)
630 { 632 {
631 FontDescriptionChangeScope scope(this); 633 FontDescriptionChangeScope scope(this);
(...skipping 14 matching lines...) Expand all
646 m_fontDirty = false; 648 m_fontDirty = false;
647 } 649 }
648 650
649 void FontBuilder::createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector> fon tSelector, RenderStyle* documentStyle) 651 void FontBuilder::createFontForDocument(PassRefPtrWillBeRawPtr<FontSelector> fon tSelector, RenderStyle* documentStyle)
650 { 652 {
651 FontDescription fontDescription = FontDescription(); 653 FontDescription fontDescription = FontDescription();
652 fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle-> locale())); 654 fontDescription.setScript(localeToScriptCodeForFontSelection(documentStyle-> locale()));
653 655
654 setFontFamilyToStandard(fontDescription, m_document); 656 setFontFamilyToStandard(fontDescription, m_document);
655 fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1); 657 fontDescription.setKeywordSize(CSSValueMedium - CSSValueXxSmall + 1);
656 int size = FontSize::fontSizeForKeyword(m_document, CSSValueMedium, false); 658 int size = FontSize::fontSizeForKeyword(m_document, CSSValueMedium, NonFixed PitchFont);
657 fontDescription.setSpecifiedSize(size); 659 fontDescription.setSpecifiedSize(size);
658 fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescrip tion, documentStyle->effectiveZoom(), size)); 660 fontDescription.setComputedSize(getComputedSizeFromSpecifiedSize(fontDescrip tion, documentStyle->effectiveZoom(), size));
659 661
660 FontOrientation fontOrientation; 662 FontOrientation fontOrientation;
661 NonCJKGlyphOrientation glyphOrientation; 663 NonCJKGlyphOrientation glyphOrientation;
662 getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation) ; 664 getFontAndGlyphOrientation(documentStyle, fontOrientation, glyphOrientation) ;
663 fontDescription.setOrientation(fontOrientation); 665 fontDescription.setOrientation(fontOrientation);
664 fontDescription.setNonCJKGlyphOrientation(glyphOrientation); 666 fontDescription.setNonCJKGlyphOrientation(glyphOrientation);
665 documentStyle->setFontDescription(fontDescription); 667 documentStyle->setFontDescription(fontDescription);
666 documentStyle->font().update(fontSelector); 668 documentStyle->font().update(fontSelector);
667 } 669 }
668 670
669 } 671 }
OLDNEW
« no previous file with comments | « Source/core/css/FontSize.cpp ('k') | Source/core/editing/EditingStyle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698