Commit 5df504c9 authored by aazzam's avatar aazzam Committed by Commit bot

Implements CSSPropertyAPI for the font-variation-settings property.

A part of Project Ribbon, separating the parsing logic for CSS
properties from the parser into an API. This patch removes
CSSPropertyFontVariationSettings from the switch statement in
parseSingleValue, and calls the API instead.

A function pointer to the parseSingleValue function from the API for the
page property is stored in a CSSPropertyDescriptor, and is called from
CSSPropertyParser.

This patch:
- Adds CSSPropertyAPIFontVariationSettings.cpp to the BUILD.gn file.
- Adds api_class flag to CSSProperties.in, which indicates that
  CSSPropertyAPIFontVariationSettings.h is generated.
- Moves the parsing logic for page from CSSPropertyParser.cpp to
  CSSPropertyAPIFontVariationSettings.cpp, which implements
  CSSPropertyAPI.h.

BUG=668012

Review-Url: https://codereview.chromium.org/2613723003
Cr-Commit-Position: refs/heads/master@{#442838}
parent f7bdce18
......@@ -349,6 +349,7 @@ blink_core_sources("css") {
"properties/CSSPropertyAPIColumnGap.cpp",
"properties/CSSPropertyAPIFlexBasis.cpp",
"properties/CSSPropertyAPIFontSizeAdjust.cpp",
"properties/CSSPropertyAPIFontVariationSettings.cpp",
"properties/CSSPropertyAPISize.cpp",
"properties/CSSPropertyAPITextDecorationColor.cpp",
"properties/CSSPropertyAPITextDecorationSkip.cpp",
......
......@@ -174,7 +174,7 @@ font-variant-caps inherited, font, name_for_methods=VariantCaps, converter=conve
font-variant-numeric inherited, font, name_for_methods=VariantNumeric, converter=convertFontVariantNumeric
font-weight interpolable, inherited, font, type_name=FontWeight, name_for_methods=Weight, converter=convertFontWeight
font-feature-settings inherited, font, name_for_methods=FeatureSettings, converter=convertFontFeatureSettings
font-variation-settings runtime_flag=CSSVariableFonts, inherited, font, name_for_methods=VariationSettings, converter=convertFontVariationSettings
font-variation-settings runtime_flag=CSSVariableFonts, inherited, font, name_for_methods=VariationSettings, converter=convertFontVariationSettings, api_class
-webkit-font-smoothing inherited, font, type_name=FontSmoothingMode
-webkit-locale inherited, font, custom_value
text-orientation inherited, custom_value, type_name=TextOrientation
......
......@@ -329,45 +329,6 @@ static CSSValue* consumeFontFeatureSettings(CSSParserTokenRange& range) {
return settings;
}
static CSSFontVariationValue* consumeFontVariationTag(
CSSParserTokenRange& range) {
// Feature tag name consists of 4-letter characters.
static const unsigned tagNameLength = 4;
const CSSParserToken& token = range.consumeIncludingWhitespace();
// Feature tag name comes first
if (token.type() != StringToken)
return nullptr;
if (token.value().length() != tagNameLength)
return nullptr;
AtomicString tag = token.value().toAtomicString();
for (unsigned i = 0; i < tagNameLength; ++i) {
// Limits the range of characters to 0x20-0x7E, following the tag name rules
// defined in the OpenType specification.
UChar character = tag[i];
if (character < 0x20 || character > 0x7E)
return nullptr;
}
double tagValue = 0;
if (!consumeNumberRaw(range, tagValue))
return nullptr;
return CSSFontVariationValue::create(tag, clampTo<float>(tagValue));
}
static CSSValue* consumeFontVariationSettings(CSSParserTokenRange& range) {
if (range.peek().id() == CSSValueNormal)
return consumeIdent(range);
CSSValueList* variationSettings = CSSValueList::createCommaSeparated();
do {
CSSFontVariationValue* fontVariationValue = consumeFontVariationTag(range);
if (!fontVariationValue)
return nullptr;
variationSettings->append(*fontVariationValue);
} while (consumeCommaIncludingWhitespace(range));
return variationSettings;
}
static CSSValue* consumePage(CSSParserTokenRange& range) {
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
......@@ -3298,9 +3259,6 @@ const CSSValue* CSSPropertyParser::parseSingleValue(
return consumeFontFeatureSettings(m_range);
case CSSPropertyFontFamily:
return consumeFontFamily(m_range);
case CSSPropertyFontVariationSettings:
DCHECK(RuntimeEnabledFeatures::cssVariableFontsEnabled());
return consumeFontVariationSettings(m_range);
case CSSPropertyFontWeight:
return consumeFontWeight(m_range);
case CSSPropertyLetterSpacing:
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/css/properties/CSSPropertyAPIFontVariationSettings.h"
#include "core/css/CSSFontVariationValue.h"
#include "core/css/CSSValueList.h"
#include "core/css/parser/CSSParserContext.h"
#include "core/css/parser/CSSPropertyParserHelpers.h"
#include "platform/RuntimeEnabledFeatures.h"
namespace blink {
namespace {
CSSFontVariationValue* consumeFontVariationTag(CSSParserTokenRange& range) {
// Feature tag name consists of 4-letter characters.
static const unsigned tagNameLength = 4;
const CSSParserToken& token = range.consumeIncludingWhitespace();
// Feature tag name comes first
if (token.type() != StringToken)
return nullptr;
if (token.value().length() != tagNameLength)
return nullptr;
AtomicString tag = token.value().toAtomicString();
for (unsigned i = 0; i < tagNameLength; ++i) {
// Limits the range of characters to 0x20-0x7E, following the tag name rules
// defined in the OpenType specification.
UChar character = tag[i];
if (character < 0x20 || character > 0x7E)
return nullptr;
}
double tagValue = 0;
if (!CSSPropertyParserHelpers::consumeNumberRaw(range, tagValue))
return nullptr;
return CSSFontVariationValue::create(tag, clampTo<float>(tagValue));
}
} // namespace
const CSSValue* CSSPropertyAPIFontVariationSettings::parseSingleValue(
CSSParserTokenRange& range,
const CSSParserContext& context) {
DCHECK(RuntimeEnabledFeatures::cssVariableFontsEnabled());
if (range.peek().id() == CSSValueNormal)
return CSSPropertyParserHelpers::consumeIdent(range);
CSSValueList* variationSettings = CSSValueList::createCommaSeparated();
do {
CSSFontVariationValue* fontVariationValue = consumeFontVariationTag(range);
if (!fontVariationValue)
return nullptr;
variationSettings->append(*fontVariationValue);
} while (CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(range));
return variationSettings;
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment