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

Side by Side Diff: Source/core/rendering/RenderThemeChromiumFontProviderWin.cpp

Issue 677103002: Expand system font values during property parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove isExpandedShorthandForAll. Created 6 years, 1 month 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 23 matching lines...) Expand all
34 #include <windows.h> 34 #include <windows.h>
35 35
36 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(structName, member) \ 36 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(structName, member) \
37 offsetof(structName, member) + \ 37 offsetof(structName, member) + \
38 (sizeof static_cast<structName*>(0)->member) 38 (sizeof static_cast<structName*>(0)->member)
39 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ 39 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \
40 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) 40 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont)
41 41
42 namespace blink { 42 namespace blink {
43 43
44 static FontDescription& smallSystemFont()
45 {
46 DEFINE_STATIC_LOCAL(FontDescription, font, ());
47 return font;
48 }
49
50 static FontDescription& menuFont()
51 {
52 DEFINE_STATIC_LOCAL(FontDescription, font, ());
53 return font;
54 }
55
56 static FontDescription& labelFont()
57 {
58 DEFINE_STATIC_LOCAL(FontDescription, font, ());
59 return font;
60 }
61
62 // Converts |points| to pixels. One point is 1/72 of an inch. 44 // Converts |points| to pixels. One point is 1/72 of an inch.
63 static float pointsToPixels(float points) 45 static float pointsToPixels(float points)
64 { 46 {
65 static float pixelsPerInch = 0.0f; 47 static float pixelsPerInch = 0.0f;
66 if (!pixelsPerInch) { 48 if (!pixelsPerInch) {
67 HWndDC hdc(0); // What about printing? Is this the right DC? 49 HWndDC hdc(0); // What about printing? Is this the right DC?
68 if (hdc) // Can this ever actually be 0? 50 if (hdc) // Can this ever actually be 0?
69 pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY); 51 pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
70 else 52 else
71 pixelsPerInch = 96.0f; 53 pixelsPerInch = 96.0f;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // FIXME: http://b/1119883 Since this is only used for "small caption", 93 // FIXME: http://b/1119883 Since this is only used for "small caption",
112 // "menu", and "status bar" objects, I'm not sure how much this even 94 // "menu", and "status bar" objects, I'm not sure how much this even
113 // matters. Plus the Gecko patch went in back in 2002, and maybe this 95 // matters. Plus the Gecko patch went in back in 2002, and maybe this
114 // isn't even relevant anymore. We should investigate whether this should 96 // isn't even relevant anymore. We should investigate whether this should
115 // be removed, or perhaps broadened to be "any CJK locale". 97 // be removed, or perhaps broadened to be "any CJK locale".
116 // 98 //
117 return ((size < 12.0f) && (GetACP() == 936)) ? 12.0f : size; 99 return ((size < 12.0f) && (GetACP() == 936)) ? 12.0f : size;
118 } 100 }
119 101
120 // static 102 // static
121 void RenderThemeChromiumFontProvider::systemFont(CSSValueID valueID, FontDescrip tion& fontDescription) 103 void RenderThemeChromiumFontProvider::systemFont(CSSValueID systemFontID, FontSt yle& fontStyle, FontWeight& fontWeight, float& fontSize, AtomicString& fontFamil y)
122 { 104 {
123 // This logic owes much to RenderThemeSafari.cpp. 105 fontStyle = FontStyleNormal;
124 FontDescription* cachedDesc = 0; 106 fontWeight = FontWeightNormal;
125 AtomicString faceName; 107
126 float fontSize = 0; 108 switch (systemFontID) {
127 switch (valueID) { 109 case CSSValueSmallCaption: {
128 case CSSValueSmallCaption: 110 NONCLIENTMETRICS metrics;
129 cachedDesc = &smallSystemFont(); 111 getNonClientMetrics(&metrics);
130 if (!smallSystemFont().isAbsoluteSize()) { 112 fontSize = systemFontSize(metrics.lfSmCaptionFont);
131 NONCLIENTMETRICS metrics; 113 fontFamily = AtomicString(metrics.lfSmCaptionFont.lfFaceName, wcslen(met rics.lfSmCaptionFont.lfFaceName));
132 getNonClientMetrics(&metrics);
133 faceName = AtomicString(metrics.lfSmCaptionFont.lfFaceName, wcslen(m etrics.lfSmCaptionFont.lfFaceName));
134 fontSize = systemFontSize(metrics.lfSmCaptionFont);
135 }
136 break; 114 break;
137 case CSSValueMenu: 115 }
138 cachedDesc = &menuFont(); 116 case CSSValueMenu: {
139 if (!menuFont().isAbsoluteSize()) { 117 NONCLIENTMETRICS metrics;
140 NONCLIENTMETRICS metrics; 118 getNonClientMetrics(&metrics);
141 getNonClientMetrics(&metrics); 119 fontSize = systemFontSize(metrics.lfMenuFont);
142 faceName = AtomicString(metrics.lfMenuFont.lfFaceName, wcslen(metric s.lfMenuFont.lfFaceName)); 120 fontFamily = AtomicString(metrics.lfMenuFont.lfFaceName, wcslen(metrics. lfMenuFont.lfFaceName));
143 fontSize = systemFontSize(metrics.lfMenuFont);
144 }
145 break; 121 break;
146 case CSSValueStatusBar: 122 }
147 cachedDesc = &labelFont(); 123 case CSSValueStatusBar: {
148 if (!labelFont().isAbsoluteSize()) { 124 NONCLIENTMETRICS metrics;
149 NONCLIENTMETRICS metrics; 125 getNonClientMetrics(&metrics);
150 getNonClientMetrics(&metrics); 126 fontSize = systemFontSize(metrics.lfStatusFont);
151 faceName = metrics.lfStatusFont.lfFaceName; 127 fontFamily = metrics.lfStatusFont.lfFaceName;
152 fontSize = systemFontSize(metrics.lfStatusFont);
153 }
154 break; 128 break;
129 }
155 case CSSValueWebkitMiniControl: 130 case CSSValueWebkitMiniControl:
156 case CSSValueWebkitSmallControl: 131 case CSSValueWebkitSmallControl:
157 case CSSValueWebkitControl: 132 case CSSValueWebkitControl:
158 faceName = defaultGUIFont();
159 // Why 2 points smaller? Because that's what Gecko does. 133 // Why 2 points smaller? Because that's what Gecko does.
160 fontSize = s_defaultFontSize - pointsToPixels(2); 134 fontSize = s_defaultFontSize - pointsToPixels(2);
135 fontFamily = defaultGUIFont();
161 break; 136 break;
162 default: 137 default:
163 faceName = defaultGUIFont();
164 fontSize = s_defaultFontSize; 138 fontSize = s_defaultFontSize;
139 fontFamily = defaultGUIFont();
165 break; 140 break;
166 } 141 }
167
168 if (!cachedDesc)
169 cachedDesc = &fontDescription;
170
171 if (fontSize) {
172 cachedDesc->firstFamily().setFamily(faceName);
173 cachedDesc->setIsAbsoluteSize(true);
174 cachedDesc->setGenericFamily(FontDescription::NoFamily);
175 cachedDesc->setSpecifiedSize(fontSize);
176 cachedDesc->setWeight(FontWeightNormal);
177 cachedDesc->setStyle(FontStyleNormal);
178 }
179 fontDescription = *cachedDesc;
180 } 142 }
181 143
182 // static 144 // static
183 void RenderThemeChromiumFontProvider::setDefaultFontSize(int fontSize) 145 void RenderThemeChromiumFontProvider::setDefaultFontSize(int fontSize)
184 { 146 {
185 s_defaultFontSize = static_cast<float>(fontSize); 147 s_defaultFontSize = static_cast<float>(fontSize);
186
187 // Reset cached fonts.
188 smallSystemFont() = menuFont() = labelFont() = FontDescription();
189 } 148 }
190 149
191 } // namespace blink 150 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderThemeChromiumFontProviderLinux.cpp ('k') | Source/core/rendering/RenderThemeChromiumMac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698