OLD | NEW |
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 24 matching lines...) Loading... |
35 #include "wtf/text/WTFString.h" | 35 #include "wtf/text/WTFString.h" |
36 | 36 |
37 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(structName, member) \ | 37 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(structName, member) \ |
38 offsetof(structName, member) + \ | 38 offsetof(structName, member) + \ |
39 (sizeof static_cast<structName*>(0)->member) | 39 (sizeof static_cast<structName*>(0)->member) |
40 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ | 40 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ |
41 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) | 41 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) |
42 | 42 |
43 namespace WebCore { | 43 namespace WebCore { |
44 | 44 |
45 static FontDescription& smallSystemFont() | |
46 { | |
47 DEFINE_STATIC_LOCAL(FontDescription, font, ()); | |
48 return font; | |
49 } | |
50 | |
51 static FontDescription& menuFont() | |
52 { | |
53 DEFINE_STATIC_LOCAL(FontDescription, font, ()); | |
54 return font; | |
55 } | |
56 | |
57 static FontDescription& labelFont() | |
58 { | |
59 DEFINE_STATIC_LOCAL(FontDescription, font, ()); | |
60 return font; | |
61 } | |
62 | |
63 // Converts |points| to pixels. One point is 1/72 of an inch. | 45 // Converts |points| to pixels. One point is 1/72 of an inch. |
64 static float pointsToPixels(float points) | 46 static float pointsToPixels(float points) |
65 { | 47 { |
66 static float pixelsPerInch = 0.0f; | 48 static float pixelsPerInch = 0.0f; |
67 if (!pixelsPerInch) { | 49 if (!pixelsPerInch) { |
68 HWndDC hdc(0); // What about printing? Is this the right DC? | 50 HWndDC hdc(0); // What about printing? Is this the right DC? |
69 if (hdc) // Can this ever actually be 0? | 51 if (hdc) // Can this ever actually be 0? |
70 pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY); | 52 pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY); |
71 else | 53 else |
72 pixelsPerInch = 96.0f; | 54 pixelsPerInch = 96.0f; |
(...skipping 39 matching lines...) Loading... |
112 // FIXME: http://b/1119883 Since this is only used for "small caption", | 94 // FIXME: http://b/1119883 Since this is only used for "small caption", |
113 // "menu", and "status bar" objects, I'm not sure how much this even | 95 // "menu", and "status bar" objects, I'm not sure how much this even |
114 // matters. Plus the Gecko patch went in back in 2002, and maybe this | 96 // matters. Plus the Gecko patch went in back in 2002, and maybe this |
115 // isn't even relevant anymore. We should investigate whether this should | 97 // isn't even relevant anymore. We should investigate whether this should |
116 // be removed, or perhaps broadened to be "any CJK locale". | 98 // be removed, or perhaps broadened to be "any CJK locale". |
117 // | 99 // |
118 return ((size < 12.0f) && (GetACP() == 936)) ? 12.0f : size; | 100 return ((size < 12.0f) && (GetACP() == 936)) ? 12.0f : size; |
119 } | 101 } |
120 | 102 |
121 // static | 103 // static |
122 void RenderThemeChromiumFontProvider::systemFont(CSSValueID valueID, FontDescrip
tion& fontDescription) | 104 void RenderThemeChromiumFontProvider::systemFont(CSSValueID systemFontID, FontSt
yle& fontStyle, FontWeight& fontWeight, float& fontSize, AtomicString& fontFamil
y) |
123 { | 105 { |
124 // This logic owes much to RenderThemeSafari.cpp. | 106 fontStyle = FontStyleNormal; |
125 FontDescription* cachedDesc = 0; | 107 fontWeight = FontWeightNormal; |
126 AtomicString faceName; | 108 |
127 float fontSize = 0; | 109 switch (systemFontID) { |
128 switch (valueID) { | 110 case CSSValueSmallCaption: { |
129 case CSSValueSmallCaption: | 111 NONCLIENTMETRICS metrics; |
130 cachedDesc = &smallSystemFont(); | 112 getNonClientMetrics(&metrics); |
131 if (!smallSystemFont().isAbsoluteSize()) { | 113 fontSize = systemFontSize(metrics.lfSmCaptionFont); |
132 NONCLIENTMETRICS metrics; | 114 fontFamily = AtomicString(metrics.lfSmCaptionFont.lfFaceName, wcslen(met
rics.lfSmCaptionFont.lfFaceName)); |
133 getNonClientMetrics(&metrics); | |
134 faceName = AtomicString(metrics.lfSmCaptionFont.lfFaceName, wcslen(m
etrics.lfSmCaptionFont.lfFaceName)); | |
135 fontSize = systemFontSize(metrics.lfSmCaptionFont); | |
136 } | |
137 break; | 115 break; |
138 case CSSValueMenu: | 116 } |
139 cachedDesc = &menuFont(); | 117 case CSSValueMenu: { |
140 if (!menuFont().isAbsoluteSize()) { | 118 NONCLIENTMETRICS metrics; |
141 NONCLIENTMETRICS metrics; | 119 getNonClientMetrics(&metrics); |
142 getNonClientMetrics(&metrics); | 120 fontSize = systemFontSize(metrics.lfMenuFont); |
143 faceName = AtomicString(metrics.lfMenuFont.lfFaceName, wcslen(metric
s.lfMenuFont.lfFaceName)); | 121 fontFamily = AtomicString(metrics.lfMenuFont.lfFaceName, wcslen(metrics.
lfMenuFont.lfFaceName)); |
144 fontSize = systemFontSize(metrics.lfMenuFont); | |
145 } | |
146 break; | 122 break; |
147 case CSSValueStatusBar: | 123 } |
148 cachedDesc = &labelFont(); | 124 case CSSValueStatusBar: { |
149 if (!labelFont().isAbsoluteSize()) { | 125 NONCLIENTMETRICS metrics; |
150 NONCLIENTMETRICS metrics; | 126 getNonClientMetrics(&metrics); |
151 getNonClientMetrics(&metrics); | 127 fontSize = systemFontSize(metrics.lfStatusFont); |
152 faceName = metrics.lfStatusFont.lfFaceName; | 128 fontFamily = metrics.lfStatusFont.lfFaceName; |
153 fontSize = systemFontSize(metrics.lfStatusFont); | |
154 } | |
155 break; | 129 break; |
| 130 } |
156 case CSSValueWebkitMiniControl: | 131 case CSSValueWebkitMiniControl: |
157 case CSSValueWebkitSmallControl: | 132 case CSSValueWebkitSmallControl: |
158 case CSSValueWebkitControl: | 133 case CSSValueWebkitControl: |
159 faceName = defaultGUIFont(); | |
160 // Why 2 points smaller? Because that's what Gecko does. | 134 // Why 2 points smaller? Because that's what Gecko does. |
161 fontSize = s_defaultFontSize - pointsToPixels(2); | 135 fontSize = s_defaultFontSize - pointsToPixels(2); |
| 136 fontFamily = defaultGUIFont(); |
162 break; | 137 break; |
163 default: | 138 default: |
164 faceName = defaultGUIFont(); | |
165 fontSize = s_defaultFontSize; | 139 fontSize = s_defaultFontSize; |
| 140 fontFamily = defaultGUIFont(); |
166 break; | 141 break; |
167 } | 142 } |
168 | |
169 if (!cachedDesc) | |
170 cachedDesc = &fontDescription; | |
171 | |
172 if (fontSize) { | |
173 cachedDesc->firstFamily().setFamily(faceName); | |
174 cachedDesc->setIsAbsoluteSize(true); | |
175 cachedDesc->setGenericFamily(FontDescription::NoFamily); | |
176 cachedDesc->setSpecifiedSize(fontSize); | |
177 cachedDesc->setWeight(FontWeightNormal); | |
178 cachedDesc->setStyle(false); | |
179 } | |
180 fontDescription = *cachedDesc; | |
181 } | 143 } |
182 | 144 |
183 // static | 145 // static |
184 void RenderThemeChromiumFontProvider::setDefaultFontSize(int fontSize) | 146 void RenderThemeChromiumFontProvider::setDefaultFontSize(int fontSize) |
185 { | 147 { |
186 s_defaultFontSize = static_cast<float>(fontSize); | 148 s_defaultFontSize = static_cast<float>(fontSize); |
187 | |
188 // Reset cached fonts. | |
189 smallSystemFont() = menuFont() = labelFont() = FontDescription(); | |
190 } | 149 } |
191 | 150 |
192 } // namespace WebCore | 151 } // namespace WebCore |
OLD | NEW |