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

Unified Diff: Source/core/css/FontSize.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, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/FontSize.h ('k') | Source/core/css/resolver/FontBuilder.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/FontSize.cpp
diff --git a/Source/core/css/FontSize.cpp b/Source/core/css/FontSize.cpp
index 6c1b53c528205b776fb8ad2348efd357c0cf083e..4eab99cfceb2a32b96af4e0585e76751a9d23288 100644
--- a/Source/core/css/FontSize.cpp
+++ b/Source/core/css/FontSize.cpp
@@ -120,17 +120,25 @@ static const int strictFontSizeTable[fontSizeTableMax - fontSizeTableMin + 1][to
// factors for each keyword value.
static const float fontSizeFactors[totalKeywords] = { 0.60f, 0.75f, 0.89f, 1.0f, 1.2f, 1.5f, 2.0f, 3.0f };
-float FontSize::fontSizeForKeyword(const Document* document, int keyword, bool shouldUseFixedDefaultSize)
+static int inline rowFromMediumFontSizeInRange(const Settings* settings, bool quirksMode, FixedPitchFontType fixedPitchFontType, int& mediumSize)
{
+ mediumSize = fixedPitchFontType == FixedPitchFont ? settings->defaultFixedFontSize() : settings->defaultFontSize();
+ if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax)
+ return mediumSize - fontSizeTableMin;
+ return -1;
+}
+
+float FontSize::fontSizeForKeyword(const Document* document, CSSValueID keyword, FixedPitchFontType fixedPitchFontType)
+{
+ ASSERT(keyword >= CSSValueXxSmall && keyword <= CSSValueWebkitXxxLarge);
const Settings* settings = document->settings();
if (!settings)
return 1.0f;
bool quirksMode = document->inQuirksMode();
- int mediumSize = shouldUseFixedDefaultSize ? settings->defaultFixedFontSize() : settings->defaultFontSize();
- if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) {
- // Look up the entry in the table.
- int row = mediumSize - fontSizeTableMin;
+ int mediumSize = 0;
+ int row = rowFromMediumFontSizeInRange(settings, quirksMode, fixedPitchFontType, mediumSize);
+ if (row >= 0) {
int col = (keyword - CSSValueXxSmall);
return quirksMode ? quirksFontSizeTable[row][col] : strictFontSizeTable[row][col];
}
@@ -153,18 +161,17 @@ static int findNearestLegacyFontSize(int pixelFontSize, const T* table, int mult
return totalKeywords - 1;
}
-int FontSize::legacyFontSize(const Document* document, int pixelFontSize, bool shouldUseFixedDefaultSize)
+int FontSize::legacyFontSize(const Document* document, int pixelFontSize, FixedPitchFontType fixedPitchFontType)
{
const Settings* settings = document->settings();
if (!settings)
return 1;
bool quirksMode = document->inQuirksMode();
- int mediumSize = shouldUseFixedDefaultSize ? settings->defaultFixedFontSize() : settings->defaultFontSize();
- if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) {
- int row = mediumSize - fontSizeTableMin;
+ int mediumSize = 0;
+ int row = rowFromMediumFontSizeInRange(settings, quirksMode, fixedPitchFontType, mediumSize);
+ if (row >= 0)
return findNearestLegacyFontSize<int>(pixelFontSize, quirksMode ? quirksFontSizeTable[row] : strictFontSizeTable[row], 1);
- }
return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors, mediumSize);
}
« no previous file with comments | « Source/core/css/FontSize.h ('k') | Source/core/css/resolver/FontBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698