Title: [146014] trunk/Source/WebCore
Revision
146014
Author
e...@chromium.org
Date
2013-03-17 10:14:33 -0700 (Sun, 17 Mar 2013)

Log Message

Move font-family applying code to StyleBuilder
https://bugs.webkit.org/show_bug.cgi?id=112441

Reviewed by Allan Sandfeld Jensen.

Many of the font related properties were moved to StyleBuilder in r87362
two years ago. Move font-family as well so that all font properties are
handled the same way.

No new tests, no change in functionality.

* css/StyleBuilder.cpp:
(ApplyPropertyFontFamily):
(WebCore::ApplyPropertyFontFamily::applyInheritValue):
(WebCore::ApplyPropertyFontFamily::applyInitialValue):
(WebCore::ApplyPropertyFontFamily::applyValue):
(WebCore::ApplyPropertyFontFamily::createHandler):
(WebCore::StyleBuilder::StyleBuilder):
Add ApplyPropertyFontFamily for CSSPropertyFontFamily.

* css/StyleResolver.cpp:
(WebCore::StyleResolver::applyProperty):
Remove CSSPropertyFontFamily from the giant switch statement.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (146013 => 146014)


--- trunk/Source/WebCore/ChangeLog	2013-03-17 17:12:41 UTC (rev 146013)
+++ trunk/Source/WebCore/ChangeLog	2013-03-17 17:14:33 UTC (rev 146014)
@@ -1,3 +1,29 @@
+2013-03-17  Emil A Eklund  <e...@chromium.org>
+
+        Move font-family applying code to StyleBuilder
+        https://bugs.webkit.org/show_bug.cgi?id=112441
+
+        Reviewed by Allan Sandfeld Jensen.
+
+        Many of the font related properties were moved to StyleBuilder in r87362
+        two years ago. Move font-family as well so that all font properties are
+        handled the same way.
+
+        No new tests, no change in functionality.
+
+        * css/StyleBuilder.cpp:
+        (ApplyPropertyFontFamily):
+        (WebCore::ApplyPropertyFontFamily::applyInheritValue):
+        (WebCore::ApplyPropertyFontFamily::applyInitialValue):
+        (WebCore::ApplyPropertyFontFamily::applyValue):
+        (WebCore::ApplyPropertyFontFamily::createHandler):
+        (WebCore::StyleBuilder::StyleBuilder):
+        Add ApplyPropertyFontFamily for CSSPropertyFontFamily.
+
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::applyProperty):
+        Remove CSSPropertyFontFamily from the giant switch statement.
+
 2013-03-17  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [ENCHANT] Invalid charset encoding used for spelling guess context menu items

Modified: trunk/Source/WebCore/css/StyleBuilder.cpp (146013 => 146014)


--- trunk/Source/WebCore/css/StyleBuilder.cpp	2013-03-17 17:12:41 UTC (rev 146013)
+++ trunk/Source/WebCore/css/StyleBuilder.cpp	2013-03-17 17:14:33 UTC (rev 146014)
@@ -657,6 +657,120 @@
     static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
 };
 
+class ApplyPropertyFontFamily {
+public:
+    static void applyInheritValue(CSSPropertyID, StyleResolver* styleResolver)
+    {
+        FontDescription fontDescription = styleResolver->style()->fontDescription();
+        FontDescription parentFontDescription = styleResolver->parentStyle()->fontDescription();
+        
+        fontDescription.setGenericFamily(parentFontDescription.genericFamily());
+        fontDescription.setFamily(parentFontDescription.firstFamily());
+        fontDescription.setIsSpecifiedFont(parentFontDescription.isSpecifiedFont());
+        styleResolver->setFontDescription(fontDescription);
+        return;
+    }
+
+    static void applyInitialValue(CSSPropertyID, StyleResolver* styleResolver)
+    {
+        FontDescription fontDescription = styleResolver->style()->fontDescription();
+        FontDescription initialDesc = FontDescription();
+        
+        // We need to adjust the size to account for the generic family change from monospace to non-monospace.
+        if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize())
+            styleResolver->setFontSize(fontDescription, styleResolver->fontSizeForKeyword(styleResolver->document(), CSSValueXxSmall + fontDescription.keywordSize() - 1, false));
+        fontDescription.setGenericFamily(initialDesc.genericFamily());
+        if (!initialDesc.firstFamily().familyIsEmpty())
+            fontDescription.setFamily(initialDesc.firstFamily());
+
+        styleResolver->setFontDescription(fontDescription);
+        return;
+    }
+
+    static void applyValue(CSSPropertyID, StyleResolver* styleResolver, CSSValue* value)
+    {
+        if (!value->isValueList())
+            return;
+
+        FontDescription fontDescription = styleResolver->style()->fontDescription();
+        FontFamily& firstFamily = fontDescription.firstFamily();
+        FontFamily* currFamily = 0;
+
+        // Before mapping in a new font-family property, we should reset the generic family.
+        bool oldFamilyUsedFixedDefaultSize = fontDescription.useFixedDefaultSize();
+        fontDescription.setGenericFamily(FontDescription::NoFamily);
+
+        for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
+            CSSValue* item = i.value();
+            if (!item->isPrimitiveValue())
+                continue;
+            CSSPrimitiveValue* contentValue = static_cast<CSSPrimitiveValue*>(item);
+            AtomicString face;
+            Settings* settings = styleResolver->document()->settings();
+            if (contentValue->isString())
+                face = contentValue->getStringValue();
+            else if (settings) {
+                switch (contentValue->getIdent()) {
+                case CSSValueWebkitBody:
+                    face = settings->standardFontFamily();
+                    break;
+                case CSSValueSerif:
+                    face = serifFamily;
+                    fontDescription.setGenericFamily(FontDescription::SerifFamily);
+                    break;
+                case CSSValueSansSerif:
+                    face = sansSerifFamily;
+                    fontDescription.setGenericFamily(FontDescription::SansSerifFamily);
+                    break;
+                case CSSValueCursive:
+                    face = cursiveFamily;
+                    fontDescription.setGenericFamily(FontDescription::CursiveFamily);
+                    break;
+                case CSSValueFantasy:
+                    face = fantasyFamily;
+                    fontDescription.setGenericFamily(FontDescription::FantasyFamily);
+                    break;
+                case CSSValueMonospace:
+                    face = monospaceFamily;
+                    fontDescription.setGenericFamily(FontDescription::MonospaceFamily);
+                    break;
+                case CSSValueWebkitPictograph:
+                    face = pictographFamily;
+                    fontDescription.setGenericFamily(FontDescription::PictographFamily);
+                    break;
+                }
+            }
+
+            if (!face.isEmpty()) {
+                if (!currFamily) {
+                    // Filling in the first family.
+                    firstFamily.setFamily(face);
+                    firstFamily.appendFamily(0); // Remove any inherited family-fallback list.
+                    currFamily = &firstFamily;
+                    fontDescription.setIsSpecifiedFont(fontDescription.genericFamily() == FontDescription::NoFamily);
+                } else {
+                    RefPtr<SharedFontFamily> newFamily = SharedFontFamily::create();
+                    newFamily->setFamily(face);
+                    currFamily->appendFamily(newFamily);
+                    currFamily = newFamily.get();
+                }
+            }
+        }
+
+        // We can't call useFixedDefaultSize() until all new font families have been added
+        // If currFamily is non-zero then we set at least one family on this description.
+        if (currFamily) {
+            if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize() != oldFamilyUsedFixedDefaultSize)
+                styleResolver->setFontSize(fontDescription, styleResolver->fontSizeForKeyword(styleResolver->document(), CSSValueXxSmall + fontDescription.keywordSize() - 1, !oldFamilyUsedFixedDefaultSize));
+
+            styleResolver->setFontDescription(fontDescription);
+        }
+        return;
+    }
+
+    static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
+};
+
 class ApplyPropertyFontSize {
 private:
     // When the CSS keyword "larger" is used, this function will attempt to match within the keyword
@@ -1876,6 +1990,7 @@
     setPropertyHandler(CSSPropertyDisplay, ApplyPropertyDisplay::createHandler());
     setPropertyHandler(CSSPropertyEmptyCells, ApplyPropertyDefault<EEmptyCell, &RenderStyle::emptyCells, EEmptyCell, &RenderStyle::setEmptyCells, EEmptyCell, &RenderStyle::initialEmptyCells>::createHandler());
     setPropertyHandler(CSSPropertyFloat, ApplyPropertyDefault<EFloat, &RenderStyle::floating, EFloat, &RenderStyle::setFloating, EFloat, &RenderStyle::initialFloating>::createHandler());
+    setPropertyHandler(CSSPropertyFontFamily, ApplyPropertyFontFamily::createHandler());
     setPropertyHandler(CSSPropertyFontSize, ApplyPropertyFontSize::createHandler());
     setPropertyHandler(CSSPropertyFontStyle, ApplyPropertyFont<FontItalic, &FontDescription::italic, &FontDescription::setItalic, FontItalicOff>::createHandler());
     setPropertyHandler(CSSPropertyFontVariant, ApplyPropertyFont<FontSmallCaps, &FontDescription::smallCaps, &FontDescription::setSmallCaps, FontSmallCapsOff>::createHandler());

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (146013 => 146014)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2013-03-17 17:12:41 UTC (rev 146013)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2013-03-17 17:14:33 UTC (rev 146014)
@@ -2394,109 +2394,6 @@
                 state.style()->setQuotes(QuotesData::create());
         }
         return;
-    case CSSPropertyFontFamily: {
-        // list of strings and ids
-        if (isInherit) {
-            FontDescription parentFontDescription = state.parentStyle()->fontDescription();
-            FontDescription fontDescription = state.style()->fontDescription();
-            fontDescription.setGenericFamily(parentFontDescription.genericFamily());
-            fontDescription.setFamily(parentFontDescription.firstFamily());
-            fontDescription.setIsSpecifiedFont(parentFontDescription.isSpecifiedFont());
-            setFontDescription(fontDescription);
-            return;
-        }
-
-        if (isInitial) {
-            FontDescription initialDesc = FontDescription();
-            FontDescription fontDescription = state.style()->fontDescription();
-            // We need to adjust the size to account for the generic family change from monospace
-            // to non-monospace.
-            if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize())
-                setFontSize(fontDescription, fontSizeForKeyword(document(), CSSValueXxSmall + fontDescription.keywordSize() - 1, false));
-            fontDescription.setGenericFamily(initialDesc.genericFamily());
-            if (!initialDesc.firstFamily().familyIsEmpty())
-                fontDescription.setFamily(initialDesc.firstFamily());
-            setFontDescription(fontDescription);
-            return;
-        }
-
-        if (!value->isValueList())
-            return;
-        FontDescription fontDescription = state.style()->fontDescription();
-        FontFamily& firstFamily = fontDescription.firstFamily();
-        FontFamily* currFamily = 0;
-
-        // Before mapping in a new font-family property, we should reset the generic family.
-        bool oldFamilyUsedFixedDefaultSize = fontDescription.useFixedDefaultSize();
-        fontDescription.setGenericFamily(FontDescription::NoFamily);
-
-        for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
-            CSSValue* item = i.value();
-            if (!item->isPrimitiveValue())
-                continue;
-            CSSPrimitiveValue* contentValue = static_cast<CSSPrimitiveValue*>(item);
-            AtomicString face;
-            Settings* settings = documentSettings();
-            if (contentValue->isString())
-                face = contentValue->getStringValue();
-            else if (settings) {
-                switch (contentValue->getIdent()) {
-                case CSSValueWebkitBody:
-                    face = settings->standardFontFamily();
-                    break;
-                case CSSValueSerif:
-                    face = serifFamily;
-                    fontDescription.setGenericFamily(FontDescription::SerifFamily);
-                    break;
-                case CSSValueSansSerif:
-                    face = sansSerifFamily;
-                    fontDescription.setGenericFamily(FontDescription::SansSerifFamily);
-                    break;
-                case CSSValueCursive:
-                    face = cursiveFamily;
-                    fontDescription.setGenericFamily(FontDescription::CursiveFamily);
-                    break;
-                case CSSValueFantasy:
-                    face = fantasyFamily;
-                    fontDescription.setGenericFamily(FontDescription::FantasyFamily);
-                    break;
-                case CSSValueMonospace:
-                    face = monospaceFamily;
-                    fontDescription.setGenericFamily(FontDescription::MonospaceFamily);
-                    break;
-                case CSSValueWebkitPictograph:
-                    face = pictographFamily;
-                    fontDescription.setGenericFamily(FontDescription::PictographFamily);
-                    break;
-                }
-            }
-
-            if (!face.isEmpty()) {
-                if (!currFamily) {
-                    // Filling in the first family.
-                    firstFamily.setFamily(face);
-                    firstFamily.appendFamily(0); // Remove any inherited family-fallback list.
-                    currFamily = &firstFamily;
-                    fontDescription.setIsSpecifiedFont(fontDescription.genericFamily() == FontDescription::NoFamily);
-                } else {
-                    RefPtr<SharedFontFamily> newFamily = SharedFontFamily::create();
-                    newFamily->setFamily(face);
-                    currFamily->appendFamily(newFamily);
-                    currFamily = newFamily.get();
-                }
-            }
-        }
-
-        // We can't call useFixedDefaultSize() until all new font families have been added
-        // If currFamily is non-zero then we set at least one family on this description.
-        if (currFamily) {
-            if (fontDescription.keywordSize() && fontDescription.useFixedDefaultSize() != oldFamilyUsedFixedDefaultSize)
-                setFontSize(fontDescription, fontSizeForKeyword(document(), CSSValueXxSmall + fontDescription.keywordSize() - 1, !oldFamilyUsedFixedDefaultSize));
-
-            setFontDescription(fontDescription);
-        }
-        return;
-    }
     // Shorthand properties.
     case CSSPropertyFont:
         if (isInherit) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to