Fix for bug 3303, support CSS2 system fonts. This patch adds a new API
authorhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 Aug 2006 22:37:51 +0000 (22:37 +0000)
committerhyatt <hyatt@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 Aug 2006 22:37:51 +0000 (22:37 +0000)
        to RenderTheme for obtaining a system font. In addition to supporting
        the CSS2 values, extensions have been added for the 3 control sizes on
        Mac.  The UA stylesheet now uses -webkit-small-control and no longer hardcodes
        Lucida Grande 11px.  This means that controls in Safari should now respect
        haxies that modify the default fonts on controls.

        Reviewed by beth

        Added fast/css/css2-system-fonts.html

        * WebCore.xcodeproj/project.pbxproj:
        * css/CSSValueKeywords.in:
        * css/cssparser.cpp:
        (WebCore::CSSParser::parseValue):
        * css/cssstyleselector.cpp:
        (WebCore::CSSStyleSelector::applyProperty):
        * css/html4.css:
        * platform/FontDescription.h:
        (WebCore::FontDescription::setBold):
        * platform/win/TemporaryLinkStubs.cpp:
        (RenderThemeWin::systemFont):
        * rendering/RenderMenuList.cpp:
        (WebCore::RenderMenuList::calcMinMaxWidth):
        * rendering/RenderTheme.h:
        (WebCore::RenderTheme::minimumMenuListSize):
        * rendering/RenderThemeMac.h:
        * rendering/RenderThemeMac.mm:
        (WebCore::RenderThemeMac::systemFont):
        (WebCore::RenderThemeMac::minimumMenuListSize):
        * rendering/RenderThemeWin.h:

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

12 files changed:
WebCore/ChangeLog
WebCore/css/CSSValueKeywords.in
WebCore/css/cssparser.cpp
WebCore/css/cssstyleselector.cpp
WebCore/css/html4.css
WebCore/platform/FontDescription.h
WebCore/platform/win/TemporaryLinkStubs.cpp
WebCore/rendering/RenderMenuList.cpp
WebCore/rendering/RenderTheme.h
WebCore/rendering/RenderThemeMac.h
WebCore/rendering/RenderThemeMac.mm
WebCore/rendering/RenderThemeWin.h

index 041c03a966b5bac341212183852748570b537b9d..bce8b1450fc4af97c9e87fa85f53d43cdbdffe59 100644 (file)
@@ -1,3 +1,37 @@
+2006-08-15  David Hyatt  <hyatt@apple.com>
+
+        Fix for bug 3303, support CSS2 system fonts.  This patch adds a new API
+        to RenderTheme for obtaining a system font. In addition to supporting
+        the CSS2 values, extensions have been added for the 3 control sizes on
+        Mac.  The UA stylesheet now uses -webkit-small-control and no longer hardcodes
+        Lucida Grande 11px.  This means that controls in Safari should now respect
+        haxies that modify the default fonts on controls.
+
+        Reviewed by beth
+
+        Added fast/css/css2-system-fonts.html
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSValueKeywords.in:
+        * css/cssparser.cpp:
+        (WebCore::CSSParser::parseValue):
+        * css/cssstyleselector.cpp:
+        (WebCore::CSSStyleSelector::applyProperty):
+        * css/html4.css:
+        * platform/FontDescription.h:
+        (WebCore::FontDescription::setBold):
+        * platform/win/TemporaryLinkStubs.cpp:
+        (RenderThemeWin::systemFont):
+        * rendering/RenderMenuList.cpp:
+        (WebCore::RenderMenuList::calcMinMaxWidth):
+        * rendering/RenderTheme.h:
+        (WebCore::RenderTheme::minimumMenuListSize):
+        * rendering/RenderThemeMac.h:
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::systemFont):
+        (WebCore::RenderThemeMac::minimumMenuListSize):
+        * rendering/RenderThemeWin.h:
+
 2006-08-15  Adele Peterson  <adele@apple.com>
 
         Reviewed by Maciej.
index 4f4c8c38d272ed2300035ab37c8e7e092ca0e1c6..9ff7de075e6dac5134f249e3a690c814ab5aea9c 100644 (file)
@@ -34,7 +34,11 @@ icon
 menu
 message-box
 small-caption
+-webkit-mini-control
+-webkit-small-control
+-webkit-control
 status-bar
+
 #
 # CSS_PROP_FONT_STYLE:
 #
index cfdb7f9a3739a21dd292b79aac16025e65e31fcd..50bff1f59036adfcbe0274e77b14f7097ec647bd 100644 (file)
@@ -1272,7 +1272,7 @@ bool CSSParser::parseValue(int propId, bool important)
             valid_primitive = true;
         else
             return parseFont(important);
-
+        break;
     case CSS_PROP_LIST_STYLE:
     {
         const int properties[3] = { CSS_PROP_LIST_STYLE_TYPE, CSS_PROP_LIST_STYLE_POSITION,
index ba330078105aa728d75948d5ec44263f94b59381..b2065c75446c58003dfe74da59ca5c81d2d05907 100644 (file)
@@ -3394,6 +3394,12 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
             style->setLineHeight(RenderStyle::initialLineHeight());
             if (style->setFontDescription(fontDescription))
                 fontDirty = true;
+        } else if (primitiveValue) {
+            style->setLineHeight(RenderStyle::initialLineHeight());
+            FontDescription fontDescription;
+            theme()->systemFont(primitiveValue->getIdent(), fontDescription);
+            if (style->setFontDescription(fontDescription))
+                fontDirty = true;
         } else if (value->isFontValue()) {
             FontValue *font = static_cast<FontValue*>(value);
             if (!font->style || !font->variant || !font->weight ||
index 14d4969238d0748d1fe91745c8c465b2f480fa4e..8d93842fc6f2593ebf82b507eeb36b077876d42b 100644 (file)
@@ -294,10 +294,9 @@ button {
     -webkit-appearance: button;
 }
 
-/* If we add support for CSS2 system fonts, then we won't have to hard code Lucida Grande here. */
 input, textarea, select, button {
     margin: 0__qem;
-    font: 11px 'Lucida Grande';
+    font: -webkit-small-control;
     color: initial;
     text-align: -webkit-auto;
     letter-spacing: normal;
index 9dc523cb4cf21526da9d805befd7dd4c9382e029..940ebdca4063823777dd8408628a1ee779d9c433 100644 (file)
@@ -62,6 +62,7 @@ public:
     void setComputedSize(float s) { m_computedSize = s; }
     void setSpecifiedSize(float s) { m_specifiedSize = s; }
     void setItalic(bool i) { m_italic = i; }
+    void setBold(bool b) { m_weight = (b ? cBoldWeight : cNormalWeight); }
     void setSmallCaps(bool c) { m_smallCaps = c; }
     void setIsAbsoluteSize(bool s) { m_isAbsoluteSize = s; }
     void setWeight(unsigned w) { m_weight = w; }
index 0802540856d4c012a9ff001712c0882df3821947..4501c67acc8916bcaa20ec2b25ba051db3924c5d 100644 (file)
@@ -387,3 +387,4 @@ void RenderPopupMenuWin::addOption(HTMLOptionElement*) { notImplemented(); }
 
 bool RenderThemeWin::paintMenuList(RenderObject*, const RenderObject::PaintInfo&, const IntRect&) { notImplemented(); return false; }
 void RenderThemeWin::adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const { notImplemented(); }
+void RenderThemeWin::systemFont(int propId, FontDescription& fontDescription) const {}
index 373829faea56f0204716970a85da6de031b0ff2a..86fafa72354897abe21285f46209e283873ff20a 100644 (file)
@@ -170,7 +170,7 @@ void RenderMenuList::calcMinMaxWidth()
     if (style()->width().isFixed() && style()->width().value() > 0)
         m_minWidth = m_maxWidth = calcContentBoxWidth(style()->width().value());
     else
-        m_maxWidth = max(m_optionsWidth, theme()->minimumTextSize(style()));
+        m_maxWidth = max(m_optionsWidth, theme()->minimumMenuListSize(style()));
 
     if (style()->minWidth().isFixed() && style()->minWidth().value() > 0) {
         m_maxWidth = max(m_maxWidth, calcContentBoxWidth(style()->minWidth().value()));
index 3ab582d78b808d4361adef5545f4b145f69cf55b..3977f38fd5d1fe8ec4797e0059019edded716f46 100644 (file)
@@ -101,7 +101,10 @@ public:
     virtual Color platformActiveSelectionForegroundColor() const;
     virtual Color platformInactiveSelectionForegroundColor() const;
 
-    virtual int minimumTextSize(RenderStyle*) const { return 0; }
+    // System fonts.
+    virtual void systemFont(int propId, FontDescription&) const = 0;
+
+    virtual int minimumMenuListSize(RenderStyle*) const { return 0; }
     virtual RenderPopupMenu* createPopupMenu(RenderArena*, Document*, RenderMenuList*) = 0;
 
 protected:
index ae8fdc3b45af8cb1b94b41c688beb43be61a10e0..e67508a0252645e106170a5af80aff5d42fb878f 100644 (file)
@@ -56,7 +56,10 @@ public:
     virtual Color platformActiveSelectionBackgroundColor() const;
     virtual Color platformInactiveSelectionBackgroundColor() const;
     
-    virtual int minimumTextSize(RenderStyle*) const;
+    // System fonts.
+    virtual void systemFont(int propId, FontDescription&) const;
+
+    virtual int minimumMenuListSize(RenderStyle*) const;
     virtual RenderPopupMenu* createPopupMenu(RenderArena*, Document*, RenderMenuList*);
 
 protected:
index e9b21497e81b79dd907b9180b176c6ce84613fc6..bd85e63a82cf250948c1db99ea7fde892caa907b 100644 (file)
@@ -22,6 +22,7 @@
 #import "config.h"
 #import "RenderThemeMac.h"
 
+#import "CSSValueKeywords.h"
 #import "Document.h"
 #import "FoundationExtras.h"
 #import "FrameView.h"
@@ -76,6 +77,68 @@ Color RenderThemeMac::platformInactiveSelectionBackgroundColor() const
     return Color((int)(255 * [color redComponent]), (int)(255 * [color greenComponent]), (int)(255 * [color blueComponent]));
 }
 
+void RenderThemeMac::systemFont(int propId, 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;
+    NSFont* font = nil;
+    switch (propId) {
+        case CSS_VAL_SMALL_CAPTION:
+            cachedDesc = &smallSystemFont;
+            if (!smallSystemFont.isAbsoluteSize())
+                font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
+            break;
+        case CSS_VAL_MENU:
+            cachedDesc = &menuFont;
+            if (!menuFont.isAbsoluteSize())
+                font = [NSFont menuFontOfSize:[NSFont systemFontSize]];
+            break;
+        case CSS_VAL_STATUS_BAR:
+            cachedDesc = &labelFont;
+            if (!labelFont.isAbsoluteSize())
+                font = [NSFont labelFontOfSize:[NSFont labelFontSize]];
+            break;
+        case CSS_VAL__WEBKIT_MINI_CONTROL:
+            cachedDesc = &miniControlFont;
+            if (!miniControlFont.isAbsoluteSize())
+                font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]];
+            break;
+        case CSS_VAL__WEBKIT_SMALL_CONTROL:
+            cachedDesc = &smallControlFont;
+            if (!smallControlFont.isAbsoluteSize())
+                font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]];
+            break;
+        case CSS_VAL__WEBKIT_CONTROL:
+            cachedDesc = &controlFont;
+            if (!controlFont.isAbsoluteSize())
+                font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]];
+            break;
+        default:
+            cachedDesc = &systemFont;
+            if (!systemFont.isAbsoluteSize())
+                font = [NSFont systemFontOfSize:[NSFont systemFontSize]];
+    }
+    
+    if (font) {
+        cachedDesc->setIsAbsoluteSize(true);
+        cachedDesc->setGenericFamily(FontDescription::SerifFamily);
+        cachedDesc->firstFamily().setFamily([font familyName]);
+        cachedDesc->setComputedSize([font pointSize]);
+        cachedDesc->setSpecifiedSize([font pointSize]);
+        NSFontTraitMask traits = [[NSFontManager sharedFontManager] traitsOfFont:font];
+        cachedDesc->setBold(traits & NSBoldFontMask);
+        cachedDesc->setItalic(traits & NSItalicFontMask);
+    }
+    fontDescription = *cachedDesc;
+}
+
 bool RenderThemeMac::isControlStyled(const RenderStyle* style, const BorderData& border, 
                                      const BackgroundLayer& background, const Color& backgroundColor) const
 {
@@ -698,7 +761,7 @@ RenderPopupMenu* RenderThemeMac::createPopupMenu(RenderArena* arena, Document* d
     return new (arena) RenderPopupMenuMac(doc, menuList);
 }
 
-int RenderThemeMac::minimumTextSize(RenderStyle* style) const
+int RenderThemeMac::minimumMenuListSize(RenderStyle* style) const
 {
     int fontSize = style->fontSize();
     if (fontSize >= 13)
index ec0af9b0f8f6421c7bb91edc6a21f2e633eaf8d6..4b3976975cb0fd57adbd2cf8e48990b417fec0f6 100644 (file)
@@ -53,6 +53,9 @@ public:
     virtual Color platformActiveSelectionForegroundColor() const;
     virtual Color platformInactiveSelectionForegroundColor() const;
 
+    // System fonts.
+    virtual void systemFont(int propId, FontDescription&) const;
+
     virtual bool paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
     { return paintButton(o, i, r); }
     virtual void setCheckboxSize(RenderStyle*) const;