Implement system fonts FontDescription caching at RenderTheme level
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Jan 2015 01:41:30 +0000 (01:41 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 24 Jan 2015 01:41:30 +0000 (01:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=140840

Reviewed by Andreas Kling.

Implement system fonts FontDescription caching at RenderTheme level
instead of duplicating the logic in its subclasses for each platform.
This reduces code / logic duplication and reduces the amount of
platform-specific code. This will also make the refactoring at
Bug 140577 a lot easier.

The caching logic remains in RenderThemeIOS class for iOS because:
- It supports different system font values than all other platforms
- It requires cache invalidation in some cases while other platforms
  do not.

This patch is inspired by the following Blink revision:
https://src.chromium.org/viewvc/blink?view=rev&revision=184449

Test: fast/css/css2-system-fonts.html

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179050 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/efl/RenderThemeEfl.cpp
Source/WebCore/platform/efl/RenderThemeEfl.h
Source/WebCore/rendering/RenderTheme.cpp
Source/WebCore/rendering/RenderTheme.h
Source/WebCore/rendering/RenderThemeGtk.cpp
Source/WebCore/rendering/RenderThemeGtk.h
Source/WebCore/rendering/RenderThemeIOS.h
Source/WebCore/rendering/RenderThemeIOS.mm
Source/WebCore/rendering/RenderThemeMac.h
Source/WebCore/rendering/RenderThemeMac.mm
Source/WebCore/rendering/RenderThemeSafari.cpp
Source/WebCore/rendering/RenderThemeSafari.h
Source/WebCore/rendering/RenderThemeWin.cpp
Source/WebCore/rendering/RenderThemeWin.h

index 7d997aa..1c1d158 100644 (file)
@@ -1,3 +1,26 @@
+2015-01-23  Chris Dumez  <cdumez@apple.com>
+
+        Implement system fonts FontDescription caching at RenderTheme level
+        https://bugs.webkit.org/show_bug.cgi?id=140840
+
+        Reviewed by Andreas Kling.
+
+        Implement system fonts FontDescription caching at RenderTheme level
+        instead of duplicating the logic in its subclasses for each platform.
+        This reduces code / logic duplication and reduces the amount of
+        platform-specific code. This will also make the refactoring at
+        Bug 140577 a lot easier.
+
+        The caching logic remains in RenderThemeIOS class for iOS because:
+        - It supports different system font values than all other platforms
+        - It requires cache invalidation in some cases while other platforms
+          do not.
+
+        This patch is inspired by the following Blink revision:
+        https://src.chromium.org/viewvc/blink?view=rev&revision=184449
+
+        Test: fast/css/css2-system-fonts.html
+
 2015-01-23  Zalan Bujtas  <zalan@apple.com>
 
         Simple line layout: Refactor line wrapping logic.
index a35b880..28adcb0 100755 (executable)
@@ -984,7 +984,7 @@ void RenderThemeEfl::setDefaultFontSize(int size)
     defaultFontSize = size;
 }
 
-void RenderThemeEfl::systemFont(CSSValueID, FontDescription& fontDescription) const
+void RenderThemeEfl::updateCachedSystemFontDescription(CSSValueID, FontDescription& fontDescription) const
 {
     // It was called by RenderEmbeddedObject::paintReplaced to render alternative string.
     // To avoid cairo_error while rendering, fontDescription should be passed.
index ffe408b..1d29939 100644 (file)
@@ -104,9 +104,6 @@ public:
 
     void adjustSizeConstraints(RenderStyle&, FormType) const;
 
-    // System fonts.
-    virtual void systemFont(CSSValueID, FontDescription&) const override;
-
     virtual void adjustCheckboxStyle(StyleResolver&, RenderStyle&, Element*) const override;
     virtual bool paintCheckbox(const RenderObject&, const PaintInfo&, const IntRect&) override;
 
@@ -189,6 +186,9 @@ private:
         return m_edje || (!m_themePath.isEmpty() && const_cast<RenderThemeEfl*>(this)->loadTheme());
     }
 
+    // System fonts.
+    virtual void updateCachedSystemFontDescription(CSSValueID, FontDescription&) const override;
+
     ALWAYS_INLINE Ecore_Evas* canvas() const { return m_canvas.get(); }
     ALWAYS_INLINE Evas_Object* edje() const { return m_edje.get(); }
 
index c3cd906..7e1720f 100644 (file)
@@ -1,7 +1,8 @@
-/**
+/*
  * This file is part of the theme implementation for form controls in WebCore.
  *
- * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc.
+ * Copyright (C) 2005-2010, 2012, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2014 Google Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -45,6 +46,7 @@
 #include "SpinButtonElement.h"
 #include "StringTruncator.h"
 #include "TextControlInnerElements.h"
+#include <wtf/NeverDestroyed.h>
 
 #if ENABLE(METER_ELEMENT)
 #include "HTMLMeterElement.h"
@@ -1130,6 +1132,55 @@ void RenderTheme::platformColorsDidChange()
     Page::updateStyleForAllPagesAfterGlobalChangeInEnvironment();
 }
 
+FontDescription& RenderTheme::cachedSystemFontDescription(CSSValueID systemFontID) const
+{
+    static NeverDestroyed<FontDescription> caption;
+    static NeverDestroyed<FontDescription> icon;
+    static NeverDestroyed<FontDescription> menu;
+    static NeverDestroyed<FontDescription> messageBox;
+    static NeverDestroyed<FontDescription> smallCaption;
+    static NeverDestroyed<FontDescription> statusBar;
+    static NeverDestroyed<FontDescription> webkitMiniControl;
+    static NeverDestroyed<FontDescription> webkitSmallControl;
+    static NeverDestroyed<FontDescription> webkitControl;
+    static NeverDestroyed<FontDescription> defaultDescription;
+
+    switch (systemFontID) {
+    case CSSValueCaption:
+        return caption;
+    case CSSValueIcon:
+        return icon;
+    case CSSValueMenu:
+        return menu;
+    case CSSValueMessageBox:
+        return messageBox;
+    case CSSValueSmallCaption:
+        return smallCaption;
+    case CSSValueStatusBar:
+        return statusBar;
+    case CSSValueWebkitMiniControl:
+        return webkitMiniControl;
+    case CSSValueWebkitSmallControl:
+        return webkitSmallControl;
+    case CSSValueWebkitControl:
+        return webkitControl;
+    case CSSValueNone:
+        return defaultDescription;
+    default:
+        ASSERT_NOT_REACHED();
+        return defaultDescription;
+    }
+}
+
+void RenderTheme::systemFont(CSSValueID systemFontID, FontDescription& fontDescription) const
+{
+    fontDescription = cachedSystemFontDescription(systemFontID);
+    if (fontDescription.isAbsoluteSize())
+        return;
+
+    updateCachedSystemFontDescription(systemFontID, fontDescription);
+}
+
 Color RenderTheme::systemColor(CSSValueID cssValueId) const
 {
     switch (cssValueId) {
index c64c73c..fd490fb 100644 (file)
@@ -172,7 +172,7 @@ public:
     virtual double caretBlinkInterval() const { return 0.5; }
 
     // System fonts and colors for CSS.
-    virtual void systemFont(CSSValueID, FontDescription&) const = 0;
+    void systemFont(CSSValueID, FontDescription&) const;
     virtual Color systemColor(CSSValueID) const;
 
     virtual int minimumMenuListSize(RenderStyle&) const { return 0; }
@@ -252,6 +252,9 @@ public:
     virtual bool defaultButtonHasAnimation() const { return false; }
 
 protected:
+    virtual FontDescription& cachedSystemFontDescription(CSSValueID systemFontID) const;
+    virtual void updateCachedSystemFontDescription(CSSValueID systemFontID, FontDescription&) const = 0;
+
     // The platform selection color.
     virtual Color platformActiveSelectionBackgroundColor() const;
     virtual Color platformInactiveSelectionBackgroundColor() const;
index 3c94db6..72d4684 100644 (file)
@@ -84,7 +84,7 @@ static double getScreenDPI()
     return dpi;
 }
 
-void RenderThemeGtk::systemFont(CSSValueID, FontDescription& fontDescription) const
+void RenderThemeGtk::updateCachedSystemFontDescription(CSSValueID, FontDescription& fontDescription) const
 {
     GtkSettings* settings = gtk_settings_get_default();
     if (!settings)
index 37468bb..bb04ff4 100644 (file)
@@ -36,9 +36,6 @@ class RenderThemeGtk final : public RenderTheme {
 public:
     static PassRefPtr<RenderTheme> create();
 
-    // System fonts.
-    virtual void systemFont(CSSValueID, FontDescription&) const override;
-
 #if ENABLE(DATALIST_ELEMENT)
     // Returns size of one slider tick mark for a horizontal track.
     // For vertical tracks we rotate it and use it. i.e. Width is always length along the track.
@@ -47,6 +44,11 @@ public:
     virtual int sliderTickOffsetFromTrackCenter() const override;
 #endif
 
+private:
+    // System fonts.
+    virtual void updateCachedSystemFontDescription(CSSValueID, FontDescription&) const override;
+
+public:
 #ifndef GTK_API_VERSION_2
 
     // A method asking if the theme's controls actually care about redrawing when hovered.
index 1c84357..b863103 100644 (file)
@@ -43,13 +43,13 @@ public:
 
     static void adjustRoundBorderRadius(RenderStyle&, RenderBox&);
 
-    virtual void systemFont(CSSValueID, FontDescription&) const override;
-
     static CFStringRef contentSizeCategory();
 
     WEBCORE_EXPORT static void setContentSizeCategory(const String&);
 
 protected:
+    virtual FontDescription& cachedSystemFontDescription(CSSValueID systemFontID) const override;
+    virtual void updateCachedSystemFontDescription(CSSValueID, FontDescription&) const override;
     virtual int baselinePosition(const RenderObject&) const override;
 
     virtual bool isControlStyled(const RenderStyle&, const BorderData&, const FillLayer& background, const Color& backgroundColor) const override;
index 61b50d9..3097c8c 100644 (file)
@@ -1103,7 +1103,7 @@ static FontWeight fromCTFontWeight(float fontWeight)
     return FontWeightNormal;
 }
 
-void RenderThemeIOS::systemFont(CSSValueID valueID, FontDescription& fontDescription) const
+FontDescription& RenderThemeIOS::cachedSystemFontDescription(CSSValueID valueID) const
 {
     static NeverDestroyed<FontDescription> systemFont;
     static NeverDestroyed<FontDescription> headlineFont;
@@ -1143,123 +1143,130 @@ void RenderThemeIOS::systemFont(CSSValueID valueID, FontDescription& fontDescrip
         tallBodyFont.get().setIsAbsoluteSize(false);
     }
 
-    FontDescription* cachedDesc;
+    switch (valueID) {
+    case CSSValueAppleSystemHeadline:
+        return headlineFont;
+    case CSSValueAppleSystemBody:
+        return bodyFont;
+#if __IPHONE_OS_VERSION_MIN_REQUIRED > 80200
+    case CSSValueAppleSystemTitle1:
+        return title1Font;
+    case CSSValueAppleSystemTitle2:
+        return title2Font;
+    case CSSValueAppleSystemTitle3:
+        return title3Font;
+#endif
+    case CSSValueAppleSystemSubheadline:
+        return subheadlineFont;
+    case CSSValueAppleSystemFootnote:
+        return footnoteFont;
+    case CSSValueAppleSystemCaption1:
+        return caption1Font;
+    case CSSValueAppleSystemCaption2:
+        return caption2Font;
+        // Short version.
+    case CSSValueAppleSystemShortHeadline:
+        return shortHeadlineFont;
+    case CSSValueAppleSystemShortBody:
+        return shortBodyFont;
+    case CSSValueAppleSystemShortSubheadline:
+        return shortSubheadlineFont;
+    case CSSValueAppleSystemShortFootnote:
+        return shortFootnoteFont;
+    case CSSValueAppleSystemShortCaption1:
+        return shortCaption1Font;
+        // Tall version.
+    case CSSValueAppleSystemTallBody:
+        return tallBodyFont;
+    default:
+        return systemFont;
+    }
+}
+
+void RenderThemeIOS::updateCachedSystemFontDescription(CSSValueID valueID, FontDescription& fontDescription) const
+{
     RetainPtr<CTFontDescriptorRef> fontDescriptor;
     CFStringRef textStyle;
     switch (valueID) {
     case CSSValueAppleSystemHeadline:
-        cachedDesc = &headlineFont.get();
         textStyle = kCTUIFontTextStyleHeadline;
-        if (!headlineFont.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
     case CSSValueAppleSystemBody:
-        cachedDesc = &bodyFont.get();
         textStyle = kCTUIFontTextStyleBody;
-        if (!bodyFont.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
 #if __IPHONE_OS_VERSION_MIN_REQUIRED > 80200
     case CSSValueAppleSystemTitle1:
-        cachedDesc = &title1Font.get();
         textStyle = kCTUIFontTextStyleTitle1;
-        if (!title1Font.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
     case CSSValueAppleSystemTitle2:
-        cachedDesc = &title2Font.get();
         textStyle = kCTUIFontTextStyleTitle2;
-        if (!title2Font.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
     case CSSValueAppleSystemTitle3:
-        cachedDesc = &title3Font.get();
         textStyle = kCTUIFontTextStyleTitle3;
-        if (!title3Font.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
 #endif
     case CSSValueAppleSystemSubheadline:
-        cachedDesc = &subheadlineFont.get();
         textStyle = kCTUIFontTextStyleSubhead;
-        if (!subheadlineFont.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
     case CSSValueAppleSystemFootnote:
-        cachedDesc = &footnoteFont.get();
         textStyle = kCTUIFontTextStyleFootnote;
-        if (!footnoteFont.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
     case CSSValueAppleSystemCaption1:
-        cachedDesc = &caption1Font.get();
         textStyle = kCTUIFontTextStyleCaption1;
-        if (!caption1Font.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
     case CSSValueAppleSystemCaption2:
-        cachedDesc = &caption2Font.get();
         textStyle = kCTUIFontTextStyleCaption2;
-        if (!caption2Font.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
 
     // Short version.
     case CSSValueAppleSystemShortHeadline:
-        cachedDesc = &shortHeadlineFont.get();
         textStyle = kCTUIFontTextStyleShortHeadline;
-        if (!shortHeadlineFont.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
     case CSSValueAppleSystemShortBody:
-        cachedDesc = &shortBodyFont.get();
         textStyle = kCTUIFontTextStyleShortBody;
-        if (!shortBodyFont.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
     case CSSValueAppleSystemShortSubheadline:
-        cachedDesc = &shortSubheadlineFont.get();
         textStyle = kCTUIFontTextStyleShortSubhead;
-        if (!shortSubheadlineFont.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
     case CSSValueAppleSystemShortFootnote:
-        cachedDesc = &shortFootnoteFont.get();
         textStyle = kCTUIFontTextStyleShortFootnote;
-        if (!shortFootnoteFont.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
     case CSSValueAppleSystemShortCaption1:
-        cachedDesc = &shortCaption1Font.get();
         textStyle = kCTUIFontTextStyleShortCaption1;
-        if (!shortCaption1Font.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
 
     // Tall version.
     case CSSValueAppleSystemTallBody:
-        cachedDesc = &tallBodyFont.get();
         textStyle = kCTUIFontTextStyleTallBody;
-        if (!tallBodyFont.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, userTextSize, 0));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateWithTextStyle(textStyle, contentSizeCategory(), 0));
         break;
 
     default:
         textStyle = kCTFontDescriptorTextStyleEmphasized;
-        cachedDesc = &systemFont.get();
-        if (!systemFont.get().isAbsoluteSize())
-            fontDescriptor = adoptCF(CTFontDescriptorCreateForUIType(kCTFontSystemFontType, 0, nullptr));
+        fontDescriptor = adoptCF(CTFontDescriptorCreateForUIType(kCTFontSystemFontType, 0, nullptr));
     }
 
-    if (fontDescriptor) {
-        RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), 0, nullptr));
-        cachedDesc->setIsAbsoluteSize(true);
-        cachedDesc->setOneFamily(textStyle);
-        cachedDesc->setSpecifiedSize(CTFontGetSize(font.get()));
-        cachedDesc->setWeight(fromCTFontWeight(FontCache::weightOfCTFont(font.get())));
-        cachedDesc->setItalic(FontItalicOff);
-    }
-    fontDescription = *cachedDesc;
+    ASSERT(fontDescriptor);
+    RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), 0, nullptr));
+    fontDescription.setIsAbsoluteSize(true);
+    fontDescription.setOneFamily(textStyle);
+    fontDescription.setSpecifiedSize(CTFontGetSize(font.get()));
+    fontDescription.setWeight(fromCTFontWeight(FontCache::weightOfCTFont(font.get())));
+    fontDescription.setItalic(FontItalicOff);
 }
 
 #if ENABLE(VIDEO)
index d4cc636..5f54eb5 100644 (file)
@@ -66,9 +66,6 @@ public:
 
     virtual void platformColorsDidChange() override;
 
-    // System fonts.
-    virtual void systemFont(CSSValueID, FontDescription&) const override;
-
     virtual int minimumMenuListSize(RenderStyle&) const override;
 
     virtual void adjustSliderThumbSize(RenderStyle&, Element*) const override;
@@ -112,6 +109,9 @@ protected:
     RenderThemeMac();
     virtual ~RenderThemeMac();
 
+    // System fonts.
+    virtual void updateCachedSystemFontDescription(CSSValueID, FontDescription&) const override;
+
 #if ENABLE(VIDEO)
     // Media controls
     virtual String mediaControlsStyleSheet() override;
index a31f830..b2da6c2 100644 (file)
@@ -338,64 +338,41 @@ static FontWeight toFontWeight(NSInteger appKitFontWeight)
     return fontWeights[appKitFontWeight - 1];
 }
 
-void RenderThemeMac::systemFont(CSSValueID cssValueId, FontDescription& fontDescription) const
-{
-    DEPRECATED_DEFINE_STATIC_LOCAL(FontDescription, systemFont, ());
-    DEPRECATED_DEFINE_STATIC_LOCAL(FontDescription, smallSystemFont, ());
-    DEPRECATED_DEFINE_STATIC_LOCAL(FontDescription, menuFont, ());
-    DEPRECATED_DEFINE_STATIC_LOCAL(FontDescription, labelFont, ());
-    DEPRECATED_DEFINE_STATIC_LOCAL(FontDescription, miniControlFont, ());
-    DEPRECATED_DEFINE_STATIC_LOCAL(FontDescription, smallControlFont, ());
-    DEPRECATED_DEFINE_STATIC_LOCAL(FontDescription, controlFont, ());
-
-    FontDescription* cachedDesc;
-    NSFont* font = nil;
+void RenderThemeMac::updateCachedSystemFontDescription(CSSValueID cssValueId, FontDescription& fontDescription) const
+{
+    NSFont* font;
     switch (cssValueId) {
         case CSSValueSmallCaption:
-            cachedDesc = &smallSystemFont;
-            if (!smallSystemFont.isAbsoluteSize())
-                font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
+            font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
             break;
         case CSSValueMenu:
-            cachedDesc = &menuFont;
-            if (!menuFont.isAbsoluteSize())
-                font = [NSFont menuFontOfSize:[NSFont systemFontSize]];
+            font = [NSFont menuFontOfSize:[NSFont systemFontSize]];
             break;
         case CSSValueStatusBar:
-            cachedDesc = &labelFont;
-            if (!labelFont.isAbsoluteSize())
-                font = [NSFont labelFontOfSize:[NSFont labelFontSize]];
+            font = [NSFont labelFontOfSize:[NSFont labelFontSize]];
             break;
         case CSSValueWebkitMiniControl:
-            cachedDesc = &miniControlFont;
-            if (!miniControlFont.isAbsoluteSize())
-                font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]];
+            font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]];
             break;
         case CSSValueWebkitSmallControl:
-            cachedDesc = &smallControlFont;
-            if (!smallControlFont.isAbsoluteSize())
-                font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]];
+            font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]];
             break;
         case CSSValueWebkitControl:
-            cachedDesc = &controlFont;
-            if (!controlFont.isAbsoluteSize())
-                font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]];
+            font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]];
             break;
         default:
-            cachedDesc = &systemFont;
-            if (!systemFont.isAbsoluteSize())
-                font = [NSFont systemFontOfSize:[NSFont systemFontSize]];
+            font = [NSFont systemFontOfSize:[NSFont systemFontSize]];
     }
 
-    if (font) {
-        NSFontManager *fontManager = [NSFontManager sharedFontManager];
-        cachedDesc->setIsAbsoluteSize(true);
-        cachedDesc->setOneFamily([font webCoreFamilyName]);
-        cachedDesc->setSpecifiedSize([font pointSize]);
-        cachedDesc->setWeight(toFontWeight([fontManager weightOfFont:font]));
-        cachedDesc->setIsItalic([fontManager traitsOfFont:font] & NSItalicFontMask);
-    }
-    fontDescription = *cachedDesc;
+    if (!font)
+        return;
+
+    NSFontManager *fontManager = [NSFontManager sharedFontManager];
+    fontDescription.setIsAbsoluteSize(true);
+    fontDescription.setOneFamily([font webCoreFamilyName]);
+    fontDescription.setSpecifiedSize([font pointSize]);
+    fontDescription.setWeight(toFontWeight([fontManager weightOfFont:font]));
+    fontDescription.setIsItalic([fontManager traitsOfFont:font] & NSItalicFontMask);
 }
 
 static RGBA32 convertNSColorToColor(NSColor *color)
index 10e4347..a56eb43 100644 (file)
@@ -192,63 +192,40 @@ static float systemFontSizeForControlSize(NSControlSize controlSize)
     return sizes[controlSize];
 }
 
-void RenderThemeSafari::systemFont(CSSValueID valueID, FontDescription& fontDescription) const
-{
-    static FontDescription systemFont;
-    static FontDescription smallSystemFont;
-    static FontDescription menuFont;
-    static FontDescription labelFont;
-    static FontDescription miniControlFont;
-    static FontDescription smallControlFont;
-    static FontDescription controlFont;
-
-    FontDescription* cachedDesc;
-    float fontSize = 0;
+void RenderThemeSafari::updateCachedSystemFontDescription(CSSValueID valueID, FontDescription& fontDescription) const
+{
+    float fontSize;
     switch (valueID) {
     case CSSValueSmallCaption:
-        cachedDesc = &smallSystemFont;
-        if (!smallSystemFont.isAbsoluteSize())
-            fontSize = systemFontSizeForControlSize(NSSmallControlSize);
+        fontSize = systemFontSizeForControlSize(NSSmallControlSize);
         break;
     case CSSValueMenu:
-        cachedDesc = &menuFont;
-        if (!menuFont.isAbsoluteSize())
-            fontSize = systemFontSizeForControlSize(NSRegularControlSize);
+        fontSize = systemFontSizeForControlSize(NSRegularControlSize);
         break;
     case CSSValueStatusBar:
-        cachedDesc = &labelFont;
-        if (!labelFont.isAbsoluteSize())
-            fontSize = 10.0f;
+        fontSize = 10.0f;
         break;
     case CSSValueWebkitMiniControl:
-        cachedDesc = &miniControlFont;
-        if (!miniControlFont.isAbsoluteSize())
-            fontSize = systemFontSizeForControlSize(NSMiniControlSize);
+        fontSize = systemFontSizeForControlSize(NSMiniControlSize);
         break;
     case CSSValueWebkitSmallControl:
-        cachedDesc = &smallControlFont;
-        if (!smallControlFont.isAbsoluteSize())
-            fontSize = systemFontSizeForControlSize(NSSmallControlSize);
+        fontSize = systemFontSizeForControlSize(NSSmallControlSize);
         break;
     case CSSValueWebkitControl:
-        cachedDesc = &controlFont;
-        if (!controlFont.isAbsoluteSize())
-            fontSize = systemFontSizeForControlSize(NSRegularControlSize);
+        fontSize = systemFontSizeForControlSize(NSRegularControlSize);
         break;
     default:
-        cachedDesc = &systemFont;
-        if (!systemFont.isAbsoluteSize())
-            fontSize = 13.0f;
+        fontSize = 13.0f;
     }
 
-    if (fontSize) {
-        cachedDesc->setIsAbsoluteSize(true);
-        cachedDesc->setOneFamily("Lucida Grande");
-        cachedDesc->setSpecifiedSize(fontSize);
-        cachedDesc->setWeight(FontWeightNormal);
-        cachedDesc->setItalic(FontItalicOff);
-    }
-    fontDescription = *cachedDesc;
+    if (!fontSize)
+        return;
+
+    fontDescription.setIsAbsoluteSize(true);
+    fontDescription.setOneFamily("Lucida Grande");
+    fontDescription.setSpecifiedSize(fontSize);
+    fontDescription.setWeight(FontWeightNormal);
+    fontDescription.setItalic(FontItalicOff);
 }
 
 bool RenderThemeSafari::isControlStyled(const RenderStyle& style, const BorderData& border,
index cd10623..efd39be 100644 (file)
@@ -71,9 +71,6 @@ public:
 
     virtual Color platformFocusRingColor() const;
 
-    // System fonts.
-    virtual void systemFont(CSSValueID, FontDescription&) const;
-
     virtual int minimumMenuListSize(RenderStyle&) const;
 
     virtual void adjustSliderThumbSize(RenderStyle&, Element*) const;
@@ -85,6 +82,9 @@ public:
     virtual int popupInternalPaddingBottom(RenderStyle&) const;
 
 protected:
+    // System fonts.
+    virtual void updateCachedSystemFontDescription(CSSValueID, FontDescription&) const override;
+
     // Methods for each appearance value.
     virtual bool paintCheckbox(const RenderObject&, const PaintInfo&, const IntRect&);
     virtual void setCheckboxSize(RenderStyle&) const;
index 959ea3e..0e43cfc 100644 (file)
@@ -329,22 +329,8 @@ static void fillFontDescription(FontDescription& fontDescription, LOGFONT& logFo
     fontDescription.setIsItalic(logFont.lfItalic);
 }
 
-static void fillFontDescription(FontDescription& fontDescription, LOGFONT& logFont)
-{   
-    fillFontDescription(fontDescription, logFont, abs(logFont.lfHeight));
-}
-
-void RenderThemeWin::systemFont(CSSValueID valueID, FontDescription& fontDescription) const
+void RenderThemeWin::updateCachedSystemFontDescription(CSSValueID valueID, FontDescription& fontDescription) const
 {
-    static FontDescription captionFont;
-    static FontDescription controlFont;
-    static FontDescription smallCaptionFont;
-    static FontDescription menuFont;
-    static FontDescription iconFont;
-    static FontDescription messageBoxFont;
-    static FontDescription statusBarFont;
-    static FontDescription systemFont;
-    
     static bool initialized;
     static NONCLIENTMETRICS ncm;
 
@@ -354,66 +340,41 @@ void RenderThemeWin::systemFont(CSSValueID valueID, FontDescription& fontDescrip
         ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
     }
  
+    LOGFONT logFont;
+    bool shouldUseDefaultControlFontPixelSize = false;
     switch (valueID) {
-    case CSSValueIcon: {
-        if (!iconFont.isAbsoluteSize()) {
-            LOGFONT logFont;
-            ::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(logFont), &logFont, 0);
-            fillFontDescription(iconFont, logFont);
-        }
-        fontDescription = iconFont;
+    case CSSValueIcon:
+        ::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(logFont), &logFont, 0);
         break;
-    }
     case CSSValueMenu:
-        if (!menuFont.isAbsoluteSize())
-            fillFontDescription(menuFont, ncm.lfMenuFont);
-        fontDescription = menuFont;
+        logFont = ncm.lfMenuFont;
         break;
     case CSSValueMessageBox:
-        if (!messageBoxFont.isAbsoluteSize())
-            fillFontDescription(messageBoxFont, ncm.lfMessageFont);
-        fontDescription = messageBoxFont;
+        logFont = ncm.lfMessageFont;
         break;
     case CSSValueStatusBar:
-        if (!statusBarFont.isAbsoluteSize())
-            fillFontDescription(statusBarFont, ncm.lfStatusFont);
-        fontDescription = statusBarFont;
+        logFont = ncm.lfStatusFont;
         break;
     case CSSValueCaption:
-        if (!captionFont.isAbsoluteSize())
-            fillFontDescription(captionFont, ncm.lfCaptionFont);
-        fontDescription = captionFont;
+        logFont = ncm.lfCaptionFont;
         break;
     case CSSValueSmallCaption:
-        if (!smallCaptionFont.isAbsoluteSize())
-            fillFontDescription(smallCaptionFont, ncm.lfSmCaptionFont);
-        fontDescription = smallCaptionFont;
+        logFont = ncm.lfSmCaptionFont;
         break;
     case CSSValueWebkitSmallControl:
     case CSSValueWebkitMiniControl: // Just map to small.
     case CSSValueWebkitControl: // Just map to small.
-        if (!controlFont.isAbsoluteSize()) {
-            HGDIOBJ hGDI = ::GetStockObject(DEFAULT_GUI_FONT);
-            if (hGDI) {
-                LOGFONT logFont;
-                if (::GetObject(hGDI, sizeof(logFont), &logFont) > 0)
-                    fillFontDescription(controlFont, logFont, defaultControlFontPixelSize);
-            }
-        }
-        fontDescription = controlFont;
-        break;
+        shouldUseDefaultControlFontPixelSize = true;
+        FALLTHROUGH;
     default: { // Everything else uses the stock GUI font.
-        if (!systemFont.isAbsoluteSize()) {
-            HGDIOBJ hGDI = ::GetStockObject(DEFAULT_GUI_FONT);
-            if (hGDI) {
-                LOGFONT logFont;
-                if (::GetObject(hGDI, sizeof(logFont), &logFont) > 0)
-                    fillFontDescription(systemFont, logFont);
-            }
-        }
-        fontDescription = systemFont;
+        HGDIOBJ hGDI = ::GetStockObject(DEFAULT_GUI_FONT);
+        if (!hGDI)
+            return;
+        if (::GetObject(hGDI, sizeof(logFont), &logFont) <= 0)
+            return;
     }
     }
+    fillFontDescription(fontDescription, logFont, shouldUseDefaultControlFontPixelSize ? defaultControlFontPixelSize : abs(logFont.lfHeight));
 }
 
 bool RenderThemeWin::supportsFocus(ControlPart appearance) const
index cc838ef..4e19498 100644 (file)
@@ -62,8 +62,6 @@ public:
     virtual Color platformActiveSelectionForegroundColor() const override;
     virtual Color platformInactiveSelectionForegroundColor() const override;
 
-    // System fonts.
-    virtual void systemFont(CSSValueID, FontDescription&) const override;
     virtual Color systemColor(CSSValueID) const override;
 
     virtual bool paintCheckbox(const RenderObject& o, const PaintInfo& i, const IntRect& r) override
@@ -148,6 +146,9 @@ private:
     RenderThemeWin();
     virtual ~RenderThemeWin();
 
+    // System fonts.
+    virtual void updateCachedSystemFontDescription(CSSValueID, FontDescription&) const override;
+
     void addIntrinsicMargins(RenderStyle&) const;
     void close();