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

Unified Diff: third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp

Issue 1375753002: Move font shorthand handling into CSSPropertyParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch for landing Created 5 years, 2 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 | « third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp
diff --git a/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp b/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp
index d23f9a0d730630f9196c543fd6d5371a524537da..35b4e0e744576319b32198c8292875c36860682e 100644
--- a/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp
+++ b/third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp
@@ -54,7 +54,6 @@
#include "core/css/parser/CSSParserFastPaths.h"
#include "core/css/parser/CSSParserValues.h"
#include "core/frame/UseCounter.h"
-#include "core/layout/LayoutTheme.h"
#include "core/style/GridCoordinate.h"
#include "core/svg/SVGPathUtilities.h"
#include "platform/RuntimeEnabledFeatures.h"
@@ -1283,12 +1282,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
return parse4Values(propId, paddingShorthand().properties(), important);
case CSSPropertyFlexFlow:
return parseShorthand(propId, flexFlowShorthand(), important);
- case CSSPropertyFont:
- // [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]?
- // 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit
- if (id >= CSSValueCaption && id <= CSSValueStatusBar)
- return parseSystemFont(important);
- return parseFont(important);
case CSSPropertyListStyle:
return parseShorthand(propId, listStyleShorthand(), important);
case CSSPropertyWebkitColumns:
@@ -1386,6 +1379,7 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
case CSSPropertyFontSize:
case CSSPropertyLineHeight:
case CSSPropertyRotate:
+ case CSSPropertyFont:
validPrimitive = false;
break;
@@ -4362,277 +4356,6 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseBasicShape()
return shape.release();
}
-// [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height' ]? 'font-family'
-bool CSSPropertyParser::parseFont(bool important)
-{
- // Let's check if there is an inherit or initial somewhere in the shorthand.
- for (unsigned i = 0; i < m_valueList->size(); ++i) {
- if (m_valueList->valueAt(i)->id == CSSValueInherit || m_valueList->valueAt(i)->id == CSSValueInitial)
- return false;
- }
-
- ShorthandScope scope(this, CSSPropertyFont);
- // Optional font-style, font-variant and font-weight.
- bool fontStyleParsed = false;
- bool fontVariantParsed = false;
- bool fontWeightParsed = false;
- bool fontStretchParsed = false;
- CSSParserValue* value = m_valueList->current();
- for (; value; value = m_valueList->next()) {
- if (!fontStyleParsed && CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyFontStyle, value->id)) {
- addProperty(CSSPropertyFontStyle, cssValuePool().createIdentifierValue(value->id), important);
- fontStyleParsed = true;
- } else if (!fontVariantParsed && (value->id == CSSValueNormal || value->id == CSSValueSmallCaps)) {
- // Font variant in the shorthand is particular, it only accepts normal or small-caps.
- addProperty(CSSPropertyFontVariant, cssValuePool().createIdentifierValue(value->id), important);
- fontVariantParsed = true;
- } else if (!fontWeightParsed && parseFontWeight(important)) {
- fontWeightParsed = true;
- } else if (!fontStretchParsed && CSSParserFastPaths::isValidKeywordPropertyAndValue(CSSPropertyFontStretch, value->id)) {
- addProperty(CSSPropertyFontStretch, cssValuePool().createIdentifierValue(value->id), important);
- fontStretchParsed = true;
- } else {
- break;
- }
- }
-
- if (!value)
- return false;
-
- if (!fontStyleParsed)
- addProperty(CSSPropertyFontStyle, cssValuePool().createIdentifierValue(CSSValueNormal), important, true);
- if (!fontVariantParsed)
- addProperty(CSSPropertyFontVariant, cssValuePool().createIdentifierValue(CSSValueNormal), important, true);
- if (!fontWeightParsed)
- addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue(CSSValueNormal), important, true);
- if (!fontStretchParsed)
- addProperty(CSSPropertyFontStretch, cssValuePool().createIdentifierValue(CSSValueNormal), important, true);
-
- // Now a font size _must_ come.
- // <absolute-size> | <relative-size> | <length> | <percentage> | inherit
- if (!parseFontSize(important))
- return false;
-
- value = m_valueList->current();
- if (!value)
- return false;
-
- if (isForwardSlashOperator(value)) {
- // The line-height property.
- value = m_valueList->next();
- if (!value)
- return false;
- RefPtrWillBeRawPtr<CSSPrimitiveValue> lineHeight = parseLineHeight();
- if (!lineHeight)
- return false;
- addProperty(CSSPropertyLineHeight, lineHeight.release(), important);
- } else {
- addProperty(CSSPropertyLineHeight, cssValuePool().createIdentifierValue(CSSValueNormal), important, true);
- }
-
- // Font family must come now.
- RefPtrWillBeRawPtr<CSSValue> parsedFamilyValue = parseFontFamily();
- if (!parsedFamilyValue)
- return false;
-
- addProperty(CSSPropertyFontFamily, parsedFamilyValue.release(), important);
-
- // FIXME: http://www.w3.org/TR/2011/WD-css3-fonts-20110324/#font-prop requires that
- // "font-stretch", "font-size-adjust", and "font-kerning" be reset to their initial values
- // but we don't seem to support them at the moment. They should also be added here once implemented.
- if (m_valueList->current())
- return false;
-
- return true;
-}
-
-bool CSSPropertyParser::parseSystemFont(bool important)
-{
- CSSValueID systemFontID = m_valueList->valueAt(0)->id;
- ASSERT(systemFontID >= CSSValueCaption && systemFontID <= CSSValueStatusBar);
- if (m_valueList->next())
- return false;
-
- FontStyle fontStyle = FontStyleNormal;
- FontWeight fontWeight = FontWeightNormal;
- float fontSize = 0;
- AtomicString fontFamily;
- LayoutTheme::theme().systemFont(systemFontID, fontStyle, fontWeight, fontSize, fontFamily);
-
- ShorthandScope scope(this, CSSPropertyFont);
- addProperty(CSSPropertyFontStyle, cssValuePool().createIdentifierValue(fontStyle == FontStyleItalic ? CSSValueItalic : CSSValueNormal), important);
- addProperty(CSSPropertyFontWeight, cssValuePool().createValue(fontWeight), important);
- addProperty(CSSPropertyFontSize, cssValuePool().createValue(fontSize, CSSPrimitiveValue::UnitType::Pixels), important);
- RefPtrWillBeRawPtr<CSSValueList> fontFamilyList = CSSValueList::createCommaSeparated();
- fontFamilyList->append(cssValuePool().createFontFamilyValue(fontFamily));
- addProperty(CSSPropertyFontFamily, fontFamilyList.release(), important);
-
- addProperty(CSSPropertyFontStretch, cssValuePool().createIdentifierValue(CSSValueNormal), important);
- addProperty(CSSPropertyFontVariant, cssValuePool().createIdentifierValue(CSSValueNormal), important);
- addProperty(CSSPropertyLineHeight, cssValuePool().createIdentifierValue(CSSValueNormal), important);
- return true;
-}
-
-class FontFamilyValueBuilder {
- STACK_ALLOCATED();
-public:
- FontFamilyValueBuilder(CSSValueList* list)
- : m_list(list)
- {
- }
-
- void add(const CSSParserString& string)
- {
- if (!m_builder.isEmpty())
- m_builder.append(' ');
-
- if (string.is8Bit()) {
- m_builder.append(string.characters8(), string.length());
- return;
- }
-
- m_builder.append(string.characters16(), string.length());
- }
-
- void commit()
- {
- if (m_builder.isEmpty())
- return;
- m_list->append(cssValuePool().createFontFamilyValue(m_builder.toString()));
- m_builder.clear();
- }
-
-private:
- StringBuilder m_builder;
- RawPtrWillBeMember<CSSValueList> m_list;
-};
-
-PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseFontFamily()
-{
- RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
- CSSParserValue* value = m_valueList->current();
-
- FontFamilyValueBuilder familyBuilder(list.get());
- bool inFamily = false;
-
- while (value) {
- CSSParserValue* nextValue = m_valueList->next();
- bool nextValBreaksFont = !nextValue || isComma(nextValue);
- bool nextValIsFontName = nextValue &&
- ((nextValue->id >= CSSValueSerif && nextValue->id <= CSSValueWebkitBody) ||
- (nextValue->unit() == CSSPrimitiveValue::UnitType::String || nextValue->m_unit == CSSParserValue::Identifier));
-
- if (isCSSWideKeyword(*value) && !inFamily) {
- if (nextValBreaksFont)
- return nullptr;
- else if (nextValIsFontName)
- value = nextValue;
- continue;
- }
-
- if (value->id >= CSSValueSerif && value->id <= CSSValueWebkitBody) {
- if (inFamily)
- familyBuilder.add(value->string);
- else if (nextValBreaksFont || !nextValIsFontName)
- list->append(cssValuePool().createIdentifierValue(value->id));
- else {
- familyBuilder.commit();
- familyBuilder.add(value->string);
- inFamily = true;
- }
- } else if (value->unit() == CSSPrimitiveValue::UnitType::String) {
- // Strings never share in a family name.
- inFamily = false;
- familyBuilder.commit();
- list->append(cssValuePool().createFontFamilyValue(value->string));
- } else if (value->m_unit == CSSParserValue::Identifier) {
- if (inFamily)
- familyBuilder.add(value->string);
- else if (nextValBreaksFont || !nextValIsFontName)
- list->append(cssValuePool().createFontFamilyValue(value->string));
- else {
- familyBuilder.commit();
- familyBuilder.add(value->string);
- inFamily = true;
- }
- } else {
- break;
- }
-
- if (!nextValue)
- break;
-
- if (nextValBreaksFont) {
- value = m_valueList->next();
- familyBuilder.commit();
- inFamily = false;
- }
- else if (nextValIsFontName)
- value = nextValue;
- else
- break;
- }
- familyBuilder.commit();
- if (!list->length() || (m_ruleType == StyleRule::FontFace && list->length() > 1))
- list = nullptr;
- return list.release();
-}
-
-PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseLineHeight()
-{
- CSSParserValue* value = m_valueList->current();
- CSSValueID id = value->id;
-
- // normal | <number> | <length> | <percentage> | inherit
- if (id == CSSValueNormal) {
- m_valueList->next();
- return cssValuePool().createIdentifierValue(id);
- }
-
- if (!validUnit(value, FNumber | FLength | FPercent | FNonNeg))
- return nullptr;
- // The line-height property can accept both percents and numbers but additive opertaions are
- // not permitted on them in calc() expressions.
- if (m_parsedCalculation && m_parsedCalculation->category() == CalcPercentNumber) {
- m_parsedCalculation.release();
- return nullptr;
- }
- m_valueList->next();
- return createPrimitiveNumericValue(value);
-}
-
-bool CSSPropertyParser::parseFontSize(bool important)
-{
- CSSParserValue* value = m_valueList->current();
- CSSValueID id = value->id;
- bool validPrimitive = false;
- // <absolute-size> | <relative-size> | <length> | <percentage> | inherit
- if (id >= CSSValueXxSmall && id <= CSSValueLarger)
- validPrimitive = true;
- else
- validPrimitive = validUnit(value, FLength | FPercent | FNonNeg | (inShorthand() ? FUnknown : FUnitlessQuirk));
- if (validPrimitive && (!m_valueList->next() || inShorthand()))
- addProperty(CSSPropertyFontSize, parseValidPrimitive(id, value), important);
- return validPrimitive;
-}
-
-bool CSSPropertyParser::parseFontWeight(bool important)
-{
- CSSParserValue* value = m_valueList->current();
- if (value->id >= CSSValueNormal && value->id <= CSSValueLighter) {
- addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue(value->id), important);
- return true;
- }
- if (value->unit() == CSSPrimitiveValue::UnitType::Number) {
- int weight = static_cast<int>(value->fValue);
- if (!(weight % 100) && weight >= 100 && weight <= 900) {
- addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1)), important);
- return true;
- }
- }
- return false;
-}
-
inline int CSSPropertyParser::colorIntFromValue(CSSParserValue* v)
{
bool isPercent;
« no previous file with comments | « third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698