Title: [134662] trunk/Source/WebCore
Revision
134662
Author
[email protected]
Date
2012-11-14 13:56:02 -0800 (Wed, 14 Nov 2012)

Log Message

[Chromium] Refactor theme font lookup into a factory
https://bugs.webkit.org/show_bug.cgi?id=101949

Patch by Scott Violet <[email protected]> on 2012-11-14
Reviewed by Tony Chang.

This will ultimately allow us to use what is currently in RenderThemeChromiumLinux on windows.

No new tests. Refactoring only.

* WebCore.gyp/WebCore.gyp:
* WebCore.gypi:
* rendering/RenderThemeChromiumFontProvider.cpp: Added.
(WebCore):
(WebCore::RenderThemeChromiumFontProvider::defaultGUIFont): Moved into RenderThemeFontProvider.
* rendering/RenderThemeChromiumFontProvider.h: Added.
(WTF):
(WebCore):
(RenderThemeChromiumFontProvider): This is the font related methods.
* rendering/RenderThemeChromiumFontProviderLinux.cpp: Added.
(WebCore):
(WebCore::RenderThemeChromiumFontProvider::setDefaultFontSize): What was in RenderThemeChromiumSkia::setDefaultFontSize.
(WebCore::RenderThemeChromiumFontProvider::systemFont): What was in RenderThemeChromiumSkia::systemFont.
* rendering/RenderThemeChromiumFontProviderWin.cpp: Added.
(WebCore):
(WebCore::pointsToPixels): Moved from RenderThemeChromiumWin.
(WebCore::getNonClientMetrics): Moved from RenderThemeChromiumWin.
(WebCore::systemFontSize): Moved from RenderThemeChromiumWin.
(WebCore::RenderThemeChromiumFontProvider::systemFont): Moved from RenderThemeChromiumWin.
(WebCore::RenderThemeChromiumFontProvider::setDefaultFontSize): Moved from RenderThemeChromiumWin.
* rendering/RenderThemeChromiumSkia.cpp:
(WebCore::RenderThemeChromiumSkia::RenderThemeChromiumSkia): Moved into RenderThemeFontProvider.
(WebCore::RenderThemeChromiumSkia::systemFont): Calls to RenderThemeChromiumFontProvider.
(WebCore::RenderThemeChromiumSkia::setDefaultFontSize): Calls to RenderThemeChromiumFontProvider.
* rendering/RenderThemeChromiumSkia.h:
(RenderThemeChromiumSkia): Moves defaultFontSize into RenderThemeChromiumFontProvider.
* rendering/RenderThemeChromiumWin.cpp: Moves font code into RenderThemeFontProviderWin.
(WebCore):
* rendering/RenderThemeChromiumWin.h: Removed overriden methods now handled by RenderThemeChromiumSkia.
(RenderThemeChromiumWin):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (134661 => 134662)


--- trunk/Source/WebCore/ChangeLog	2012-11-14 21:52:49 UTC (rev 134661)
+++ trunk/Source/WebCore/ChangeLog	2012-11-14 21:56:02 UTC (rev 134662)
@@ -1,3 +1,45 @@
+2012-11-14  Scott Violet  <[email protected]>
+
+        [Chromium] Refactor theme font lookup into a factory
+        https://bugs.webkit.org/show_bug.cgi?id=101949
+
+        Reviewed by Tony Chang.
+
+        This will ultimately allow us to use what is currently in RenderThemeChromiumLinux on windows.
+
+        No new tests. Refactoring only.
+
+        * WebCore.gyp/WebCore.gyp:
+        * WebCore.gypi:
+        * rendering/RenderThemeChromiumFontProvider.cpp: Added.
+        (WebCore):
+        (WebCore::RenderThemeChromiumFontProvider::defaultGUIFont): Moved into RenderThemeFontProvider.
+        * rendering/RenderThemeChromiumFontProvider.h: Added.
+        (WTF):
+        (WebCore):
+        (RenderThemeChromiumFontProvider): This is the font related methods.
+        * rendering/RenderThemeChromiumFontProviderLinux.cpp: Added.
+        (WebCore):
+        (WebCore::RenderThemeChromiumFontProvider::setDefaultFontSize): What was in RenderThemeChromiumSkia::setDefaultFontSize.
+        (WebCore::RenderThemeChromiumFontProvider::systemFont): What was in RenderThemeChromiumSkia::systemFont.
+        * rendering/RenderThemeChromiumFontProviderWin.cpp: Added.
+        (WebCore):
+        (WebCore::pointsToPixels): Moved from RenderThemeChromiumWin.
+        (WebCore::getNonClientMetrics): Moved from RenderThemeChromiumWin.
+        (WebCore::systemFontSize): Moved from RenderThemeChromiumWin.
+        (WebCore::RenderThemeChromiumFontProvider::systemFont): Moved from RenderThemeChromiumWin.
+        (WebCore::RenderThemeChromiumFontProvider::setDefaultFontSize): Moved from RenderThemeChromiumWin.
+        * rendering/RenderThemeChromiumSkia.cpp:
+        (WebCore::RenderThemeChromiumSkia::RenderThemeChromiumSkia): Moved into RenderThemeFontProvider.
+        (WebCore::RenderThemeChromiumSkia::systemFont): Calls to RenderThemeChromiumFontProvider.
+        (WebCore::RenderThemeChromiumSkia::setDefaultFontSize): Calls to RenderThemeChromiumFontProvider.
+        * rendering/RenderThemeChromiumSkia.h:
+        (RenderThemeChromiumSkia): Moves defaultFontSize into RenderThemeChromiumFontProvider.
+        * rendering/RenderThemeChromiumWin.cpp: Moves font code into RenderThemeFontProviderWin.
+        (WebCore):
+        * rendering/RenderThemeChromiumWin.h: Removed overriden methods now handled by RenderThemeChromiumSkia.
+        (RenderThemeChromiumWin):
+
 2012-11-14  Erik Arvidsson  <[email protected]>
 
         Update DOMException name: InUseAttributeError

Modified: trunk/Source/WebCore/WebCore.gyp/WebCore.gyp (134661 => 134662)


--- trunk/Source/WebCore/WebCore.gyp/WebCore.gyp	2012-11-14 21:52:49 UTC (rev 134661)
+++ trunk/Source/WebCore/WebCore.gyp/WebCore.gyp	2012-11-14 21:56:02 UTC (rev 134662)
@@ -1965,7 +1965,8 @@
         # FIXME: Figure out how to store these patterns in a variable.
         ['exclude', '(cairo|ca|cf|cg|curl|efl|freetype|gstreamer|gtk|linux|mac|opengl|openvg|opentype|pango|posix|qt|soup|svg|symbian|texmap|iphone|win|wince|wx)/'],
         ['exclude', '(?<!Chromium)(Cairo|CF|CG|Curl|Gtk|JSC|Linux|Mac|OpenType|POSIX|Posix|Qt|Safari|Soup|Symbian|Win|WinCE|Wx)\\.(cpp|mm?)$'],
-
+        # Previous rule excludes things like ChromiumFooWin, include those.
+        ['include', 'rendering/.*Chromium.*\\.(cpp|mm?)$'],
         ['exclude', 'AllInOne\\.cpp$'],
       ],
       'conditions': [
@@ -1983,6 +1984,9 @@
             # RenderThemeChromiumSkia is not used on mac since RenderThemeChromiumMac
             # does not reference the Skia code that is used by Windows, Linux and Android.
             ['exclude', 'rendering/RenderThemeChromiumSkia\\.cpp$'],
+            # RenderThemeChromiumFontProvider is used by RenderThemeChromiumSkia.
+            ['exclude', 'rendering/RenderThemeChromiumFontProvider\\.cpp'],
+            ['exclude', 'rendering/RenderThemeChromiumFontProvider\\.h'],
           ],
         },{ # OS!="mac"
           'sources/': [['exclude', 'Mac\\.(cpp|mm?)$']]
@@ -2008,6 +2012,7 @@
         }],
         ['OS=="android"', {
           'sources/': [
+            ['include', 'rendering/RenderThemeChromiumFontProviderLinux\\.cpp$'],
             ['include', 'rendering/RenderThemeChromiumLinux\\.cpp$'],
           ],
         },{ # OS!="android"

Modified: trunk/Source/WebCore/WebCore.gypi (134661 => 134662)


--- trunk/Source/WebCore/WebCore.gypi	2012-11-14 21:52:49 UTC (rev 134661)
+++ trunk/Source/WebCore/WebCore.gypi	2012-11-14 21:56:02 UTC (rev 134662)
@@ -3454,6 +3454,10 @@
             'rendering/RenderThemeChromiumAndroid.h',
             'rendering/RenderThemeChromiumCommon.cpp',
             'rendering/RenderThemeChromiumCommon.h',
+            'rendering/RenderThemeChromiumFontProvider.cpp',
+            'rendering/RenderThemeChromiumFontProvider.h',
+            'rendering/RenderThemeChromiumFontProviderLinux.cpp',
+            'rendering/RenderThemeChromiumFontProviderWin.cpp',
             'rendering/RenderThemeChromiumLinux.cpp',
             'rendering/RenderThemeChromiumLinux.h',
             'rendering/RenderThemeChromiumMac.h',

Added: trunk/Source/WebCore/rendering/RenderThemeChromiumFontProvider.cpp (0 => 134662)


--- trunk/Source/WebCore/rendering/RenderThemeChromiumFontProvider.cpp	                        (rev 0)
+++ trunk/Source/WebCore/rendering/RenderThemeChromiumFontProvider.cpp	2012-11-14 21:56:02 UTC (rev 134662)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2012 Google Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RenderThemeChromiumFontProvider.h"
+
+#include <wtf/StdLibExtras.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+// The default variable-width font size. We use this as the default font
+// size for the "system font", and as a base size (which we then shrink) for
+// form control fonts.
+// static
+float RenderThemeChromiumFontProvider::s_defaultFontSize = 16.0;
+
+// We aim to match IE here.
+// -IE uses a font based on the encoding as the default font for form controls.
+// -Gecko uses MS Shell Dlg (actually calls GetStockObject(DEFAULT_GUI_FONT),
+// which returns MS Shell Dlg)
+// -Safari uses Lucida Grande.
+//
+// FIXME: The only case where we know we don't match IE is for ANSI encodings.
+// IE uses MS Shell Dlg there, which we render incorrectly at certain pixel
+// sizes (e.g. 15px). So, for now we just use Arial.
+const String& RenderThemeChromiumFontProvider::defaultGUIFont()
+{
+    DEFINE_STATIC_LOCAL(String, fontFace, (ASCIILiteral("Arial")));
+    return fontFace;
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/rendering/RenderThemeChromiumFontProvider.h (0 => 134662)


--- trunk/Source/WebCore/rendering/RenderThemeChromiumFontProvider.h	                        (rev 0)
+++ trunk/Source/WebCore/rendering/RenderThemeChromiumFontProvider.h	2012-11-14 21:56:02 UTC (rev 134662)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2012 Google Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef RenderThemeChromiumFontProvider_h
+#define RenderThemeChromiumFontProvider_h
+
+namespace WTF {
+class String;
+}
+
+namespace WebCore {
+
+class FontDescription;
+
+class RenderThemeChromiumFontProvider {
+public:
+    static void systemFont(int propId, FontDescription&);
+    static void setDefaultFontSize(int);
+
+protected:
+    static const WTF::String& defaultGUIFont();
+
+    static float s_defaultFontSize;
+};
+
+} // namespace WebCore
+
+#endif // RenderThemeChromiumFontProvider_h

Added: trunk/Source/WebCore/rendering/RenderThemeChromiumFontProviderLinux.cpp (0 => 134662)


--- trunk/Source/WebCore/rendering/RenderThemeChromiumFontProviderLinux.cpp	                        (rev 0)
+++ trunk/Source/WebCore/rendering/RenderThemeChromiumFontProviderLinux.cpp	2012-11-14 21:56:02 UTC (rev 134662)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2012 Google Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RenderThemeChromiumFontProvider.h"
+
+#include "CSSValueKeywords.h"
+#include "FontDescription.h"
+
+#include <wtf/StdLibExtras.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+// static
+void RenderThemeChromiumFontProvider::setDefaultFontSize(int fontSize)
+{
+    s_defaultFontSize = static_cast<float>(fontSize);
+}
+
+// static
+void RenderThemeChromiumFontProvider::systemFont(int propId, FontDescription& fontDescription)
+{
+    float fontSize = s_defaultFontSize;
+
+    switch (propId) {
+    case CSSValueWebkitMiniControl:
+    case CSSValueWebkitSmallControl:
+    case CSSValueWebkitControl:
+        // Why 2 points smaller? Because that's what Gecko does. Note that we
+        // are assuming a 96dpi screen, which is the default that we use on
+        // Windows.
+        static const float pointsPerInch = 72.0f;
+        static const float pixelsPerInch = 96.0f;
+        fontSize -= (2.0f / pointsPerInch) * pixelsPerInch;
+        break;
+    }
+
+    fontDescription.firstFamily().setFamily(defaultGUIFont());
+    fontDescription.setSpecifiedSize(fontSize);
+    fontDescription.setIsAbsoluteSize(true);
+    fontDescription.setGenericFamily(FontDescription::NoFamily);
+    fontDescription.setWeight(FontWeightNormal);
+    fontDescription.setItalic(false);
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/rendering/RenderThemeChromiumFontProviderWin.cpp (0 => 134662)


--- trunk/Source/WebCore/rendering/RenderThemeChromiumFontProviderWin.cpp	                        (rev 0)
+++ trunk/Source/WebCore/rendering/RenderThemeChromiumFontProviderWin.cpp	2012-11-14 21:56:02 UTC (rev 134662)
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2012 Google Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RenderThemeChromiumFontProvider.h"
+
+#include "CSSValueKeywords.h"
+#include "FontDescription.h"
+#include "HWndDC.h"
+#include "SystemInfo.h"
+
+#include <windows.h>
+#include <wtf/text/WTFString.h>
+
+#define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(structName, member) \
+    offsetof(structName, member) + \
+    (sizeof static_cast<structName*>(0)->member)
+#define NONCLIENTMETRICS_SIZE_PRE_VISTA \
+    SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont)
+
+namespace WebCore {
+
+static FontDescription& smallSystemFont()
+{
+    DEFINE_STATIC_LOCAL(FontDescription, font, ());
+    return font;
+}
+
+static FontDescription& menuFont()
+{
+    DEFINE_STATIC_LOCAL(FontDescription, font, ());
+    return font;
+}
+
+static FontDescription& labelFont()
+{
+    DEFINE_STATIC_LOCAL(FontDescription, font, ());
+    return font;
+}
+
+// Converts |points| to pixels. One point is 1/72 of an inch.
+static float pointsToPixels(float points)
+{
+    static float pixelsPerInch = 0.0f;
+    if (!pixelsPerInch) {
+        HWndDC hdc(0); // What about printing? Is this the right DC?
+        if (hdc) // Can this ever actually be 0?
+            pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
+        else
+            pixelsPerInch = 96.0f;
+    }
+
+    static const float pointsPerInch = 72.0f;
+    return points / pointsPerInch * pixelsPerInch;
+}
+
+static void getNonClientMetrics(NONCLIENTMETRICS* metrics)
+{
+    static UINT size = (windowsVersion() >= WindowsVista) ?
+        sizeof(NONCLIENTMETRICS) : NONCLIENTMETRICS_SIZE_PRE_VISTA;
+    metrics->cbSize = size;
+    bool success = !!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, size, metrics, 0);
+    ASSERT(success);
+}
+
+// Return the height of system font |font| in pixels. We use this size by
+// default for some non-form-control elements.
+static float systemFontSize(const LOGFONT& font)
+{
+    float size = -font.lfHeight;
+    if (size < 0) {
+        HFONT hFont = CreateFontIndirect(&font);
+        if (hFont) {
+            HWndDC hdc(0); // What about printing? Is this the right DC?
+            if (hdc) {
+                HGDIOBJ hObject = SelectObject(hdc, hFont);
+                TEXTMETRIC tm;
+                GetTextMetrics(hdc, &tm);
+                SelectObject(hdc, hObject);
+                size = tm.tmAscent;
+            }
+            DeleteObject(hFont);
+        }
+    }
+
+    // The "codepage 936" bit here is from Gecko; apparently this helps make
+    // fonts more legible in Simplified Chinese where the default font size is
+    // too small.
+    //
+    // FIXME: http://b/1119883 Since this is only used for "small caption",
+    // "menu", and "status bar" objects, I'm not sure how much this even
+    // matters. Plus the Gecko patch went in back in 2002, and maybe this
+    // isn't even relevant anymore. We should investigate whether this should
+    // be removed, or perhaps broadened to be "any CJK locale".
+    //
+    return ((size < 12.0f) && (GetACP() == 936)) ? 12.0f : size;
+}
+
+// static
+void RenderThemeChromiumFontProvider::systemFont(int propId, FontDescription& fontDescription)
+{
+    // This logic owes much to RenderThemeSafari.cpp.
+    FontDescription* cachedDesc = 0;
+    AtomicString faceName;
+    float fontSize = 0;
+    switch (propId) {
+    case CSSValueSmallCaption:
+        cachedDesc = &smallSystemFont();
+        if (!smallSystemFont().isAbsoluteSize()) {
+            NONCLIENTMETRICS metrics;
+            getNonClientMetrics(&metrics);
+            faceName = AtomicString(metrics.lfSmCaptionFont.lfFaceName, wcslen(metrics.lfSmCaptionFont.lfFaceName));
+            fontSize = systemFontSize(metrics.lfSmCaptionFont);
+        }
+        break;
+    case CSSValueMenu:
+        cachedDesc = &menuFont();
+        if (!menuFont().isAbsoluteSize()) {
+            NONCLIENTMETRICS metrics;
+            getNonClientMetrics(&metrics);
+            faceName = AtomicString(metrics.lfMenuFont.lfFaceName, wcslen(metrics.lfMenuFont.lfFaceName));
+            fontSize = systemFontSize(metrics.lfMenuFont);
+        }
+        break;
+    case CSSValueStatusBar:
+        cachedDesc = &labelFont();
+        if (!labelFont().isAbsoluteSize()) {
+            NONCLIENTMETRICS metrics;
+            getNonClientMetrics(&metrics);
+            faceName = metrics.lfStatusFont.lfFaceName;
+            fontSize = systemFontSize(metrics.lfStatusFont);
+        }
+        break;
+    case CSSValueWebkitMiniControl:
+    case CSSValueWebkitSmallControl:
+    case CSSValueWebkitControl:
+        faceName = defaultGUIFont();
+        // Why 2 points smaller? Because that's what Gecko does.
+        fontSize = s_defaultFontSize - pointsToPixels(2);
+        break;
+    default:
+        faceName = defaultGUIFont();
+        fontSize = s_defaultFontSize;
+        break;
+    }
+
+    if (!cachedDesc)
+        cachedDesc = &fontDescription;
+
+    if (fontSize) {
+        cachedDesc->firstFamily().setFamily(faceName);
+        cachedDesc->setIsAbsoluteSize(true);
+        cachedDesc->setGenericFamily(FontDescription::NoFamily);
+        cachedDesc->setSpecifiedSize(fontSize);
+        cachedDesc->setWeight(FontWeightNormal);
+        cachedDesc->setItalic(false);
+    }
+    fontDescription = *cachedDesc;
+}
+
+// static
+void RenderThemeChromiumFontProvider::setDefaultFontSize(int fontSize)
+{
+    s_defaultFontSize = static_cast<float>(fontSize);
+
+    // Reset cached fonts.
+    smallSystemFont() = menuFont() = labelFont() = FontDescription();
+}
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/rendering/RenderThemeChromiumSkia.cpp (134661 => 134662)


--- trunk/Source/WebCore/rendering/RenderThemeChromiumSkia.cpp	2012-11-14 21:52:49 UTC (rev 134661)
+++ trunk/Source/WebCore/rendering/RenderThemeChromiumSkia.cpp	2012-11-14 21:56:02 UTC (rev 134662)
@@ -39,6 +39,7 @@
 #include "RenderObject.h"
 #include "RenderProgress.h"
 #include "RenderSlider.h"
+#include "RenderThemeChromiumFontProvider.h"
 #include "ScrollbarTheme.h"
 #include "TimeRanges.h"
 #include "TransformationMatrix.h"
@@ -70,23 +71,6 @@
 static const float maxSearchFieldResultsDecorationSize = 30;
 static const float defaultSearchFieldResultsButtonWidth = 18;
 
-// We aim to match IE here.
-// -IE uses a font based on the encoding as the default font for form controls.
-// -Gecko uses MS Shell Dlg (actually calls GetStockObject(DEFAULT_GUI_FONT),
-// which returns MS Shell Dlg)
-// -Safari uses Lucida Grande.
-//
-// FIXME: The only case where we know we don't match IE is for ANSI encodings.
-// IE uses MS Shell Dlg there, which we render incorrectly at certain pixel
-// sizes (e.g. 15px). So, for now we just use Arial.
-const String& RenderThemeChromiumSkia::defaultGUIFont()
-{
-    DEFINE_STATIC_LOCAL(String, fontFace, (ASCIILiteral("Arial")));
-    return fontFace;
-}
-
-float RenderThemeChromiumSkia::defaultFontSize = 16.0;
-
 RenderThemeChromiumSkia::RenderThemeChromiumSkia()
 {
 }
@@ -183,27 +167,7 @@
 
 void RenderThemeChromiumSkia::systemFont(int propId, FontDescription& fontDescription) const
 {
-    float fontSize = defaultFontSize;
-
-    switch (propId) {
-    case CSSValueWebkitMiniControl:
-    case CSSValueWebkitSmallControl:
-    case CSSValueWebkitControl:
-        // Why 2 points smaller? Because that's what Gecko does. Note that we
-        // are assuming a 96dpi screen, which is the default that we use on
-        // Windows.
-        static const float pointsPerInch = 72.0f;
-        static const float pixelsPerInch = 96.0f;
-        fontSize -= (2.0f / pointsPerInch) * pixelsPerInch;
-        break;
-    }
-
-    fontDescription.firstFamily().setFamily(defaultGUIFont());
-    fontDescription.setSpecifiedSize(fontSize);
-    fontDescription.setIsAbsoluteSize(true);
-    fontDescription.setGenericFamily(FontDescription::NoFamily);
-    fontDescription.setWeight(FontWeightNormal);
-    fontDescription.setItalic(false);
+    RenderThemeChromiumFontProvider::systemFont(propId, fontDescription);
 }
 
 int RenderThemeChromiumSkia::minimumMenuListSize(RenderStyle* style) const
@@ -573,7 +537,7 @@
 // static
 void RenderThemeChromiumSkia::setDefaultFontSize(int fontSize)
 {
-    defaultFontSize = static_cast<float>(fontSize);
+    RenderThemeChromiumFontProvider::setDefaultFontSize(fontSize);
 }
 
 double RenderThemeChromiumSkia::caretBlinkIntervalInternal() const

Modified: trunk/Source/WebCore/rendering/RenderThemeChromiumSkia.h (134661 => 134662)


--- trunk/Source/WebCore/rendering/RenderThemeChromiumSkia.h	2012-11-14 21:52:49 UTC (rev 134661)
+++ trunk/Source/WebCore/rendering/RenderThemeChromiumSkia.h	2012-11-14 21:56:02 UTC (rev 134662)
@@ -145,13 +145,6 @@
         static void setDefaultFontSize(int);
 
     protected:
-        static const String& defaultGUIFont();
-
-        // The default variable-width font size.  We use this as the default font
-        // size for the "system font", and as a base size (which we then shrink) for
-        // form control fonts.
-        static float defaultFontSize;
-
         virtual double caretBlinkIntervalInternal() const;
 
         virtual int menuListArrowPadding() const;

Modified: trunk/Source/WebCore/rendering/RenderThemeChromiumWin.cpp (134661 => 134662)


--- trunk/Source/WebCore/rendering/RenderThemeChromiumWin.cpp	2012-11-14 21:52:49 UTC (rev 134661)
+++ trunk/Source/WebCore/rendering/RenderThemeChromiumWin.cpp	2012-11-14 21:56:02 UTC (rev 134662)
@@ -35,7 +35,6 @@
 #include "GraphicsContext.h"
 #include "HTMLMediaElement.h"
 #include "HTMLNames.h"
-#include "HWndDC.h"
 #include "LayoutTestSupport.h"
 #include "MediaControlElements.h"
 #include "PaintInfo.h"
@@ -43,6 +42,7 @@
 #include "RenderBox.h"
 #include "RenderProgress.h"
 #include "RenderSlider.h"
+#include "RenderThemeChromiumCommon.h"
 #include "ScrollbarTheme.h"
 #include "SystemInfo.h"
 #include "TransparencyWin.h"
@@ -52,12 +52,6 @@
 // FIXME: This dependency should eventually be removed.
 #include <skia/ext/skia_utils_win.h>
 
-#define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(structName, member) \
-    offsetof(structName, member) + \
-    (sizeof static_cast<structName*>(0)->member)
-#define NONCLIENTMETRICS_SIZE_PRE_VISTA \
-    SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont)
-
 namespace WebCore {
 
 // The standard width for the menu list drop-down button when run under
@@ -135,19 +129,6 @@
 
 } // namespace
 
-static void getNonClientMetrics(NONCLIENTMETRICS* metrics)
-{
-    static UINT size = (windowsVersion() >= WindowsVista) ?
-        sizeof(NONCLIENTMETRICS) : NONCLIENTMETRICS_SIZE_PRE_VISTA;
-    metrics->cbSize = size;
-    bool success = !!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, size, metrics, 0);
-    ASSERT(success);
-}
-
-static FontDescription smallSystemFont;
-static FontDescription menuFont;
-static FontDescription labelFont;
-
 // Internal static helper functions.  We don't put them in an anonymous
 // namespace so they have easier access to the WebCore namespace.
 
@@ -166,55 +147,6 @@
     return false;
 }
 
-// Return the height of system font |font| in pixels.  We use this size by
-// default for some non-form-control elements.
-static float systemFontSize(const LOGFONT& font)
-{
-    float size = -font.lfHeight;
-    if (size < 0) {
-        HFONT hFont = CreateFontIndirect(&font);
-        if (hFont) {
-            HWndDC hdc(0); // What about printing? Is this the right DC?
-            if (hdc) {
-                HGDIOBJ hObject = SelectObject(hdc, hFont);
-                TEXTMETRIC tm;
-                GetTextMetrics(hdc, &tm);
-                SelectObject(hdc, hObject);
-                size = tm.tmAscent;
-            }
-            DeleteObject(hFont);
-        }
-    }
-
-    // The "codepage 936" bit here is from Gecko; apparently this helps make
-    // fonts more legible in Simplified Chinese where the default font size is
-    // too small.
-    //
-    // FIXME: http://b/1119883 Since this is only used for "small caption",
-    // "menu", and "status bar" objects, I'm not sure how much this even
-    // matters.  Plus the Gecko patch went in back in 2002, and maybe this
-    // isn't even relevant anymore.  We should investigate whether this should
-    // be removed, or perhaps broadened to be "any CJK locale".
-    //
-    return ((size < 12.0f) && (GetACP() == 936)) ? 12.0f : size;
-}
-
-// Converts |points| to pixels.  One point is 1/72 of an inch.
-static float pointsToPixels(float points)
-{
-    static float pixelsPerInch = 0.0f;
-    if (!pixelsPerInch) {
-        HWndDC hdc(0); // What about printing? Is this the right DC?
-        if (hdc) // Can this ever actually be NULL?
-            pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
-        else
-            pixelsPerInch = 96.0f;
-    }
-
-    static const float pointsPerInch = 72.0f;
-    return points / pointsPerInch * pixelsPerInch;
-}
-
 static double querySystemBlinkInterval(double defaultInterval)
 {
     UINT blinkTime = GetCaretBlinkTime();
@@ -285,67 +217,6 @@
     return Color(0xff, 0xff, 0x96); // Yellow.
 }
 
-void RenderThemeChromiumWin::systemFont(int propId, FontDescription& fontDescription) const
-{
-    // This logic owes much to RenderThemeSafari.cpp.
-    FontDescription* cachedDesc = 0;
-    AtomicString faceName;
-    float fontSize = 0;
-    switch (propId) {
-    case CSSValueSmallCaption:
-        cachedDesc = &smallSystemFont;
-        if (!smallSystemFont.isAbsoluteSize()) {
-            NONCLIENTMETRICS metrics;
-            getNonClientMetrics(&metrics);
-            faceName = AtomicString(metrics.lfSmCaptionFont.lfFaceName, wcslen(metrics.lfSmCaptionFont.lfFaceName));
-            fontSize = systemFontSize(metrics.lfSmCaptionFont);
-        }
-        break;
-    case CSSValueMenu:
-        cachedDesc = &menuFont;
-        if (!menuFont.isAbsoluteSize()) {
-            NONCLIENTMETRICS metrics;
-            getNonClientMetrics(&metrics);
-            faceName = AtomicString(metrics.lfMenuFont.lfFaceName, wcslen(metrics.lfMenuFont.lfFaceName));
-            fontSize = systemFontSize(metrics.lfMenuFont);
-        }
-        break;
-    case CSSValueStatusBar:
-        cachedDesc = &labelFont;
-        if (!labelFont.isAbsoluteSize()) {
-            NONCLIENTMETRICS metrics;
-            getNonClientMetrics(&metrics);
-            faceName = metrics.lfStatusFont.lfFaceName;
-            fontSize = systemFontSize(metrics.lfStatusFont);
-        }
-        break;
-    case CSSValueWebkitMiniControl:
-    case CSSValueWebkitSmallControl:
-    case CSSValueWebkitControl:
-        faceName = defaultGUIFont();
-        // Why 2 points smaller?  Because that's what Gecko does.
-        fontSize = defaultFontSize - pointsToPixels(2);
-        break;
-    default:
-        faceName = defaultGUIFont();
-        fontSize = defaultFontSize;
-        break;
-    }
-
-    if (!cachedDesc)
-        cachedDesc = &fontDescription;
-
-    if (fontSize) {
-        cachedDesc->firstFamily().setFamily(faceName);
-        cachedDesc->setIsAbsoluteSize(true);
-        cachedDesc->setGenericFamily(FontDescription::NoFamily);
-        cachedDesc->setSpecifiedSize(fontSize);
-        cachedDesc->setWeight(FontWeightNormal);
-        cachedDesc->setItalic(false);
-    }
-    fontDescription = *cachedDesc;
-}
-
 // Map a CSSValue* system color to an index understood by GetSysColor().
 static int cssValueIdToSysColorIndex(int cssValueId)
 {
@@ -536,15 +407,6 @@
     return false;
 }
 
-// static
-void RenderThemeChromiumWin::setDefaultFontSize(int fontSize)
-{
-    RenderThemeChromiumSkia::setDefaultFontSize(fontSize);
-
-    // Reset cached fonts.
-    smallSystemFont = menuFont = labelFont = FontDescription();
-}
-
 double RenderThemeChromiumWin::caretBlinkIntervalInternal() const
 {
     // This involves a system call, so we cache the result.

Modified: trunk/Source/WebCore/rendering/RenderThemeChromiumWin.h (134661 => 134662)


--- trunk/Source/WebCore/rendering/RenderThemeChromiumWin.h	2012-11-14 21:52:49 UTC (rev 134661)
+++ trunk/Source/WebCore/rendering/RenderThemeChromiumWin.h	2012-11-14 21:56:02 UTC (rev 134662)
@@ -57,8 +57,6 @@
         virtual Color platformActiveTextSearchHighlightColor() const;
         virtual Color platformInactiveTextSearchHighlightColor() const;
 
-        // System fonts.
-        virtual void systemFont(int propId, FontDescription&) const;
         virtual Color systemColor(int cssValueId) const;
 
 #if ENABLE(DATALIST_ELEMENT)
@@ -86,10 +84,6 @@
         // entire menulist.
         virtual bool paintMenuList(RenderObject*, const PaintInfo&, const IntRect&);
 
-        // Override RenderThemeChromiumSkia's setDefaultFontSize method to also reset the local font property caches.
-        // See comment in RenderThemeChromiumSkia::setDefaultFontSize() regarding ugliness of this hack.
-        static void setDefaultFontSize(int);
-
         virtual void adjustInnerSpinButtonStyle(StyleResolver*, RenderStyle*, Element*) const;
         virtual bool paintInnerSpinButton(RenderObject*, const PaintInfo&, const IntRect&);
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to