Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Unified Diff: Source/core/css/resolver/StyleBuilderConverter.cpp

Issue 602373003: Make style building for 'font-family' less custom. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Init genericFamily in all cases. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/resolver/StyleBuilderConverter.h ('k') | Source/core/css/resolver/StyleBuilderCustom.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/resolver/StyleBuilderConverter.cpp
diff --git a/Source/core/css/resolver/StyleBuilderConverter.cpp b/Source/core/css/resolver/StyleBuilderConverter.cpp
index cd935a52559baae565c428bfc3efad42c49703ca..d5dcf939b6e44886fc440a37bc9f0951b83e61fc 100644
--- a/Source/core/css/resolver/StyleBuilderConverter.cpp
+++ b/Source/core/css/resolver/StyleBuilderConverter.cpp
@@ -102,6 +102,77 @@ LengthBox StyleBuilderConverter::convertClip(StyleResolverState& state, CSSValue
convertLengthOrAuto(state, rect->left()));
}
+static FontDescription::GenericFamilyType convertGenericFamily(CSSValueID valueID)
+{
+ switch (valueID) {
+ case CSSValueWebkitBody:
+ return FontDescription::StandardFamily;
+ case CSSValueSerif:
+ return FontDescription::SerifFamily;
+ case CSSValueSansSerif:
+ return FontDescription::SansSerifFamily;
+ case CSSValueCursive:
+ return FontDescription::CursiveFamily;
+ case CSSValueFantasy:
+ return FontDescription::FantasyFamily;
+ case CSSValueMonospace:
+ return FontDescription::MonospaceFamily;
+ case CSSValueWebkitPictograph:
+ return FontDescription::PictographFamily;
+ default:
+ return FontDescription::NoFamily;
+ }
+}
+
+static bool convertFontFamilyName(StyleResolverState& state, CSSPrimitiveValue* primitiveValue,
+ FontDescription::GenericFamilyType& genericFamily, AtomicString& familyName)
+{
+ if (primitiveValue->isString()) {
+ genericFamily = FontDescription::NoFamily;
+ familyName = AtomicString(primitiveValue->getStringValue());
+ } else if (state.document().settings()) {
+ genericFamily = convertGenericFamily(primitiveValue->getValueID());
+ familyName = state.fontBuilder().genericFontFamilyName(genericFamily);
+ }
+
+ return !familyName.isEmpty();
+}
+
+FontDescription::FamilyDescription StyleBuilderConverter::convertFontFamily(StyleResolverState& state, CSSValue* value)
+{
+ ASSERT(value->isValueList());
+
+ FontDescription::FamilyDescription desc(FontDescription::NoFamily);
+ FontFamily* currFamily = nullptr;
+
+ for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
+ CSSValue* item = i.value();
+ if (!item->isPrimitiveValue())
+ continue;
+
+ FontDescription::GenericFamilyType genericFamily = FontDescription::NoFamily;
+ AtomicString familyName;
+
+ if (!convertFontFamilyName(state, toCSSPrimitiveValue(item), genericFamily, familyName))
+ continue;
+
+ if (!currFamily) {
+ currFamily = &desc.family;
+ } else {
+ RefPtr<SharedFontFamily> newFamily = SharedFontFamily::create();
+ currFamily->appendFamily(newFamily);
+ currFamily = newFamily.get();
+ }
+
+ currFamily->setFamily(familyName);
+
+ if (genericFamily != FontDescription::NoFamily)
+ desc.genericFamily = genericFamily;
+ }
+
+ return desc;
+}
+
PassRefPtr<FontFeatureSettings> StyleBuilderConverter::convertFontFeatureSettings(StyleResolverState& state, CSSValue* value)
{
if (value->isPrimitiveValue() && toCSSPrimitiveValue(value)->getValueID() == CSSValueNormal)
« no previous file with comments | « Source/core/css/resolver/StyleBuilderConverter.h ('k') | Source/core/css/resolver/StyleBuilderCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698