| 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 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "core/layout/LayoutThemeFontProvider.h" | 26 #include "core/layout/LayoutThemeFontProvider.h" |
| 27 | 27 |
| 28 #include "core/CSSValueKeywords.h" | 28 #include "core/CSSValueKeywords.h" |
| 29 #include "platform/fonts/FontCache.h" | 29 #include "platform/fonts/FontCache.h" |
| 30 #include "platform/fonts/FontDescription.h" | 30 #include "platform/fonts/FontDescription.h" |
| 31 #include "platform/win/HWndDC.h" | 31 #include "platform/win/HWndDC.h" |
| 32 #include "platform/win/SystemInfo.h" | |
| 33 #include "wtf/text/WTFString.h" | 32 #include "wtf/text/WTFString.h" |
| 34 #include <windows.h> | 33 #include <windows.h> |
| 35 | 34 |
| 36 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(structName, member) \ | |
| 37 offsetof(structName, member) + \ | |
| 38 (sizeof static_cast<structName*>(nullptr)->member) | |
| 39 #define NONCLIENTMETRICS_SIZE_PRE_VISTA \ | |
| 40 SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont) | |
| 41 | |
| 42 namespace blink { | 35 namespace blink { |
| 43 | 36 |
| 44 // Converts |points| to pixels. One point is 1/72 of an inch. | 37 // Converts |points| to pixels. One point is 1/72 of an inch. |
| 45 static float pointsToPixels(float points) | 38 static float pointsToPixels(float points) |
| 46 { | 39 { |
| 47 static float pixelsPerInch = 0.0f; | 40 static float pixelsPerInch = 0.0f; |
| 48 if (!pixelsPerInch) { | 41 if (!pixelsPerInch) { |
| 49 HWndDC hdc(0); // What about printing? Is this the right DC? | 42 HWndDC hdc(0); // What about printing? Is this the right DC? |
| 50 if (hdc) // Can this ever actually be 0? | 43 if (hdc) // Can this ever actually be 0? |
| 51 pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY); | 44 pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY); |
| 52 else | 45 else |
| 53 pixelsPerInch = 96.0f; | 46 pixelsPerInch = 96.0f; |
| 54 } | 47 } |
| 55 | 48 |
| 56 static const float pointsPerInch = 72.0f; | 49 static const float pointsPerInch = 72.0f; |
| 57 return points / pointsPerInch * pixelsPerInch; | 50 return points / pointsPerInch * pixelsPerInch; |
| 58 } | 51 } |
| 59 | 52 |
| 60 static bool getNonClientMetrics(NONCLIENTMETRICS* metrics) | 53 static bool getNonClientMetrics(NONCLIENTMETRICS* metrics) |
| 61 { | 54 { |
| 62 static UINT size = isWindowsVistaOrGreater() ? | 55 metrics->cbSize = sizeof(NONCLIENTMETRICS); |
| 63 sizeof(NONCLIENTMETRICS) : NONCLIENTMETRICS_SIZE_PRE_VISTA; | 56 bool success = !!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLI
ENTMETRICS), metrics, 0); |
| 64 metrics->cbSize = size; | |
| 65 bool success = !!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, size, metrics
, 0); | |
| 66 ASSERT_UNUSED(success, success); | 57 ASSERT_UNUSED(success, success); |
| 67 return success; | 58 return success; |
| 68 } | 59 } |
| 69 | 60 |
| 70 // Return the height of system font |font| in pixels. We use this size by | 61 // Return the height of system font |font| in pixels. We use this size by |
| 71 // default for some non-form-control elements. | 62 // default for some non-form-control elements. |
| 72 static float systemFontSize(const LOGFONT& font) | 63 static float systemFontSize(const LOGFONT& font) |
| 73 { | 64 { |
| 74 float size = -font.lfHeight; | 65 float size = -font.lfHeight; |
| 75 if (size < 0) { | 66 if (size < 0) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 153 } |
| 163 } | 154 } |
| 164 | 155 |
| 165 // static | 156 // static |
| 166 void LayoutThemeFontProvider::setDefaultFontSize(int fontSize) | 157 void LayoutThemeFontProvider::setDefaultFontSize(int fontSize) |
| 167 { | 158 { |
| 168 s_defaultFontSize = static_cast<float>(fontSize); | 159 s_defaultFontSize = static_cast<float>(fontSize); |
| 169 } | 160 } |
| 170 | 161 |
| 171 } // namespace blink | 162 } // namespace blink |
| OLD | NEW |