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

Side by Side Diff: third_party/WebKit/Source/core/css/FontSize.cpp

Issue 2392343005: Reflow comments in core/css (Closed)
Patch Set: Revert clang-format Created 4 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 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc.
6 * All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
10 * (http://www.torchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 11 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 12 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
11 * Copyright (C) 2012 Google Inc. All rights reserved. 13 * Copyright (C) 2012 Google Inc. All rights reserved.
12 * 14 *
13 * This library is free software; you can redistribute it and/or 15 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Library General Public 16 * modify it under the terms of the GNU Library General Public
15 * License as published by the Free Software Foundation; either 17 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version. 18 * version 2 of the License, or (at your option) any later version.
17 * 19 *
18 * This library is distributed in the hope that it will be useful, 20 * This library is distributed in the hope that it will be useful,
(...skipping 21 matching lines...) Expand all
40 bool isAbsoluteSize, 42 bool isAbsoluteSize,
41 float specifiedSize, 43 float specifiedSize,
42 ESmartMinimumForFontSize useSmartMinimumForFontSize) { 44 ESmartMinimumForFontSize useSmartMinimumForFontSize) {
43 // Text with a 0px font size should not be visible and therefore needs to be 45 // Text with a 0px font size should not be visible and therefore needs to be
44 // exempt from minimum font size rules. Acid3 relies on this for pixel-perfect 46 // exempt from minimum font size rules. Acid3 relies on this for pixel-perfect
45 // rendering. This is also compatible with other browsers that have minimum 47 // rendering. This is also compatible with other browsers that have minimum
46 // font size settings (e.g. Firefox). 48 // font size settings (e.g. Firefox).
47 if (fabsf(specifiedSize) < std::numeric_limits<float>::epsilon()) 49 if (fabsf(specifiedSize) < std::numeric_limits<float>::epsilon())
48 return 0.0f; 50 return 0.0f;
49 51
50 // We support two types of minimum font size. The first is a hard override tha t applies to 52 // We support two types of minimum font size. The first is a hard override
51 // all fonts. This is "minSize." The second type of minimum font size is a "sm art minimum" 53 // that applies to all fonts. This is "minSize." The second type of minimum
52 // that is applied only when the Web page can't know what size it really asked for, e.g., 54 // font size is a "smart minimum" that is applied only when the Web page can't
53 // when it uses logical sizes like "small" or expresses the font-size as a per centage of 55 // know what size it really asked for, e.g., when it uses logical sizes like
54 // the user's default font setting. 56 // "small" or expresses the font-size as a percentage of the user's default
57 // font setting.
55 58
56 // With the smart minimum, we never want to get smaller than the minimum font size to keep fonts readable. 59 // With the smart minimum, we never want to get smaller than the minimum font
57 // However we always allow the page to set an explicit pixel size that is smal ler, 60 // size to keep fonts readable. However we always allow the page to set an
58 // since sites will mis-render otherwise (e.g., http://www.gamespot.com with a 9px minimum). 61 // explicit pixel size that is smaller, since sites will mis-render otherwise
62 // (e.g., http://www.gamespot.com with a 9px minimum).
59 63
60 Settings* settings = document->settings(); 64 Settings* settings = document->settings();
61 if (!settings) 65 if (!settings)
62 return 1.0f; 66 return 1.0f;
63 67
64 int minSize = settings->minimumFontSize(); 68 int minSize = settings->minimumFontSize();
65 int minLogicalSize = settings->minimumLogicalFontSize(); 69 int minLogicalSize = settings->minimumLogicalFontSize();
66 float zoomedSize = specifiedSize * zoomFactor; 70 float zoomedSize = specifiedSize * zoomFactor;
67 71
68 // Apply the hard minimum first. We only apply the hard minimum if after zoomi ng we're still too small. 72 // Apply the hard minimum first. We only apply the hard minimum if after
73 // zooming we're still too small.
69 if (zoomedSize < minSize) 74 if (zoomedSize < minSize)
70 zoomedSize = minSize; 75 zoomedSize = minSize;
71 76
72 // Now apply the "smart minimum." This minimum is also only applied if we're s till too small 77 // Now apply the "smart minimum." This minimum is also only applied if we're
73 // after zooming. The font size must either be relative to the user default or the original size 78 // still too small after zooming. The font size must either be relative to the
74 // must have been acceptable. In other words, we only apply the smart minimum whenever we're positive 79 // user default or the original size must have been acceptable. In other
75 // doing so won't disrupt the layout. 80 // words, we only apply the smart minimum whenever we're positive doing so
81 // won't disrupt the layout.
76 if (useSmartMinimumForFontSize && zoomedSize < minLogicalSize && 82 if (useSmartMinimumForFontSize && zoomedSize < minLogicalSize &&
77 (specifiedSize >= minLogicalSize || !isAbsoluteSize)) 83 (specifiedSize >= minLogicalSize || !isAbsoluteSize))
78 zoomedSize = minLogicalSize; 84 zoomedSize = minLogicalSize;
79 85
80 // Also clamp to a reasonable maximum to prevent insane font sizes from causin g crashes on various 86 // Also clamp to a reasonable maximum to prevent insane font sizes from
81 // platforms (I'm looking at you, Windows.) 87 // causing crashes on various platforms (I'm looking at you, Windows.)
82 return std::min(maximumAllowedFontSize, zoomedSize); 88 return std::min(maximumAllowedFontSize, zoomedSize);
83 } 89 }
84 90
85 const int fontSizeTableMax = 16; 91 const int fontSizeTableMax = 16;
86 const int fontSizeTableMin = 9; 92 const int fontSizeTableMin = 9;
87 const int totalKeywords = 8; 93 const int totalKeywords = 8;
88 94
89 // WinIE/Nav4 table for font sizes. Designed to match the legacy font mapping sy stem of HTML. 95 // WinIE/Nav4 table for font sizes. Designed to match the legacy font mapping
96 // system of HTML.
90 static const int quirksFontSizeTable[fontSizeTableMax - fontSizeTableMin + 97 static const int quirksFontSizeTable[fontSizeTableMax - fontSizeTableMin +
91 1][totalKeywords] = { 98 1][totalKeywords] = {
92 {9, 9, 9, 9, 11, 14, 18, 28}, {9, 9, 9, 10, 12, 15, 20, 31}, 99 {9, 9, 9, 9, 11, 14, 18, 28}, {9, 9, 9, 10, 12, 15, 20, 31},
93 {9, 9, 9, 11, 13, 17, 22, 34}, {9, 9, 10, 12, 14, 18, 24, 37}, 100 {9, 9, 9, 11, 13, 17, 22, 34}, {9, 9, 10, 12, 14, 18, 24, 37},
94 {9, 9, 10, 13, 16, 20, 26, 40}, // fixed font default (13) 101 {9, 9, 10, 13, 16, 20, 26, 40}, // fixed font default (13)
95 {9, 9, 11, 14, 17, 21, 28, 42}, {9, 10, 12, 15, 17, 23, 30, 45}, 102 {9, 9, 11, 14, 17, 21, 28, 42}, {9, 10, 12, 15, 17, 23, 30, 45},
96 {9, 10, 13, 16, 18, 24, 32, 48} // proportional font default (16) 103 {9, 10, 13, 16, 18, 24, 32, 48} // proportional font default (16)
97 }; 104 };
98 // HTML 1 2 3 4 5 6 7 105 // HTML 1 2 3 4 5 6 7
99 // CSS xxs xs s m l xl xxl 106 // CSS xxs xs s m l xl xxl
100 // | 107 // |
101 // user pref 108 // user pref
102 109
103 // Strict mode table matches MacIE and Mozilla's settings exactly. 110 // Strict mode table matches MacIE and Mozilla's settings exactly.
104 static const int strictFontSizeTable[fontSizeTableMax - fontSizeTableMin + 111 static const int strictFontSizeTable[fontSizeTableMax - fontSizeTableMin +
105 1][totalKeywords] = { 112 1][totalKeywords] = {
106 {9, 9, 9, 9, 11, 14, 18, 27}, {9, 9, 9, 10, 12, 15, 20, 30}, 113 {9, 9, 9, 9, 11, 14, 18, 27}, {9, 9, 9, 10, 12, 15, 20, 30},
107 {9, 9, 10, 11, 13, 17, 22, 33}, {9, 9, 10, 12, 14, 18, 24, 36}, 114 {9, 9, 10, 11, 13, 17, 22, 33}, {9, 9, 10, 12, 14, 18, 24, 36},
108 {9, 10, 12, 13, 16, 20, 26, 39}, // fixed font default (13) 115 {9, 10, 12, 13, 16, 20, 26, 39}, // fixed font default (13)
109 {9, 10, 12, 14, 17, 21, 28, 42}, {9, 10, 13, 15, 18, 23, 30, 45}, 116 {9, 10, 12, 14, 17, 21, 28, 42}, {9, 10, 13, 15, 18, 23, 30, 45},
110 {9, 10, 13, 16, 18, 24, 32, 48} // proportional font default (16) 117 {9, 10, 13, 16, 18, 24, 32, 48} // proportional font default (16)
111 }; 118 };
112 // HTML 1 2 3 4 5 6 7 119 // HTML 1 2 3 4 5 6 7
113 // CSS xxs xs s m l xl xxl 120 // CSS xxs xs s m l xl xxl
114 // | 121 // |
115 // user pref 122 // user pref
116 123
117 // For values outside the range of the table, we use Todd Fahrner's suggested sc ale 124 // For values outside the range of the table, we use Todd Fahrner's suggested
118 // factors for each keyword value. 125 // scale factors for each keyword value.
119 static const float fontSizeFactors[totalKeywords] = {0.60f, 0.75f, 0.89f, 1.0f, 126 static const float fontSizeFactors[totalKeywords] = {0.60f, 0.75f, 0.89f, 1.0f,
120 1.2f, 1.5f, 2.0f, 3.0f}; 127 1.2f, 1.5f, 2.0f, 3.0f};
121 128
122 static int inline rowFromMediumFontSizeInRange(const Settings* settings, 129 static int inline rowFromMediumFontSizeInRange(const Settings* settings,
123 bool quirksMode, 130 bool quirksMode,
124 bool isMonospace, 131 bool isMonospace,
125 int& mediumSize) { 132 int& mediumSize) {
126 mediumSize = isMonospace ? settings->defaultFixedFontSize() 133 mediumSize = isMonospace ? settings->defaultFixedFontSize()
127 : settings->defaultFontSize(); 134 : settings->defaultFontSize();
128 if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) 135 if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax)
(...skipping 21 matching lines...) Expand all
150 157
151 // Value is outside the range of the table. Apply the scale factor instead. 158 // Value is outside the range of the table. Apply the scale factor instead.
152 float minLogicalSize = std::max(settings->minimumLogicalFontSize(), 1); 159 float minLogicalSize = std::max(settings->minimumLogicalFontSize(), 1);
153 return std::max(fontSizeFactors[keyword - 1] * mediumSize, minLogicalSize); 160 return std::max(fontSizeFactors[keyword - 1] * mediumSize, minLogicalSize);
154 } 161 }
155 162
156 template <typename T> 163 template <typename T>
157 static int findNearestLegacyFontSize(int pixelFontSize, 164 static int findNearestLegacyFontSize(int pixelFontSize,
158 const T* table, 165 const T* table,
159 int multiplier) { 166 int multiplier) {
160 // Ignore table[0] because xx-small does not correspond to any legacy font siz e. 167 // Ignore table[0] because xx-small does not correspond to any legacy font
168 // size.
161 for (int i = 1; i < totalKeywords - 1; i++) { 169 for (int i = 1; i < totalKeywords - 1; i++) {
162 if (pixelFontSize * 2 < (table[i] + table[i + 1]) * multiplier) 170 if (pixelFontSize * 2 < (table[i] + table[i + 1]) * multiplier)
163 return i; 171 return i;
164 } 172 }
165 return totalKeywords - 1; 173 return totalKeywords - 1;
166 } 174 }
167 175
168 int FontSize::legacyFontSize(const Document* document, 176 int FontSize::legacyFontSize(const Document* document,
169 int pixelFontSize, 177 int pixelFontSize,
170 bool isMonospace) { 178 bool isMonospace) {
171 const Settings* settings = document->settings(); 179 const Settings* settings = document->settings();
172 if (!settings) 180 if (!settings)
173 return 1; 181 return 1;
174 182
175 bool quirksMode = document->inQuirksMode(); 183 bool quirksMode = document->inQuirksMode();
176 int mediumSize = 0; 184 int mediumSize = 0;
177 int row = rowFromMediumFontSizeInRange(settings, quirksMode, isMonospace, 185 int row = rowFromMediumFontSizeInRange(settings, quirksMode, isMonospace,
178 mediumSize); 186 mediumSize);
179 if (row >= 0) 187 if (row >= 0)
180 return findNearestLegacyFontSize<int>( 188 return findNearestLegacyFontSize<int>(
181 pixelFontSize, 189 pixelFontSize,
182 quirksMode ? quirksFontSizeTable[row] : strictFontSizeTable[row], 1); 190 quirksMode ? quirksFontSizeTable[row] : strictFontSizeTable[row], 1);
183 191
184 return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors, 192 return findNearestLegacyFontSize<float>(pixelFontSize, fontSizeFactors,
185 mediumSize); 193 mediumSize);
186 } 194 }
187 195
188 } // namespace blink 196 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/FontSize.h ('k') | third_party/WebKit/Source/core/css/FontStyleMatcher.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698