Commit 778279c9 authored by Rob Buis's avatar Rob Buis Committed by Commit Bot

Support unset in CSSParserFastPaths

Support unset as a CSS wide keyword [1] and add some unit tests for it.

[1] https://www.w3.org/TR/css3-values/#common-keywords

Bug: 660273
Change-Id: Ic739055b83988017e11ff3968c1a0aad48073613
Reviewed-on: https://chromium-review.googlesource.com/663820
Commit-Queue: Rob Buis <rob.buis@samsung.com>
Reviewed-by: default avatarBugs Nash <bugsnash@chromium.org>
Reviewed-by: default avatarmeade_UTC10 <meade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501642}
parent 2573ac31
......@@ -12,6 +12,7 @@
#include "core/css/CSSInheritedValue.h"
#include "core/css/CSSInitialValue.h"
#include "core/css/CSSPrimitiveValue.h"
#include "core/css/CSSUnsetValue.h"
#include "core/css/StyleColor.h"
#include "core/css/parser/CSSParserIdioms.h"
#include "core/css/parser/CSSPropertyParser.h"
......@@ -985,12 +986,13 @@ static CSSValue* ParseKeywordValue(CSSPropertyID property_id,
DCHECK(!string.IsEmpty());
if (!CSSParserFastPaths::IsKeywordPropertyID(property_id)) {
// All properties accept the values of "initial" and "inherit".
// All properties accept the values of "initial," "inherit" and "unset".
if (!EqualIgnoringASCIICase(string, "initial") &&
!EqualIgnoringASCIICase(string, "inherit"))
!EqualIgnoringASCIICase(string, "inherit") &&
!EqualIgnoringASCIICase(string, "unset"))
return nullptr;
// Parse initial/inherit shorthands using the CSSPropertyParser.
// Parse initial/inherit/unset shorthands using the CSSPropertyParser.
if (shorthandForProperty(property_id).length())
return nullptr;
......@@ -1008,6 +1010,8 @@ static CSSValue* ParseKeywordValue(CSSPropertyID property_id,
return CSSInheritedValue::Create();
if (value_id == CSSValueInitial)
return CSSInitialValue::Create();
if (value_id == CSSValueUnset)
return CSSUnsetValue::Create();
if (CSSParserFastPaths::IsValidKeywordPropertyAndValue(property_id, value_id,
parser_mode))
return CSSIdentifierValue::Create(value_id);
......
......@@ -24,7 +24,8 @@ TEST(CSSParserFastPathsTest, ParseKeyword) {
kHTMLStandardMode);
ASSERT_EQ(nullptr, value);
}
TEST(CSSParserFastPathsTest, ParseInitialAndInheritKeyword) {
TEST(CSSParserFastPathsTest, ParseCSSWideKeywords) {
CSSValue* value = CSSParserFastPaths::MaybeParseValue(
CSSPropertyMarginTop, "inherit", kHTMLStandardMode);
ASSERT_NE(nullptr, value);
......@@ -41,6 +42,14 @@ TEST(CSSParserFastPathsTest, ParseInitialAndInheritKeyword) {
kHTMLStandardMode);
ASSERT_NE(nullptr, value);
EXPECT_TRUE(value->IsInitialValue());
value = CSSParserFastPaths::MaybeParseValue(CSSPropertyMarginTop, "unset",
kHTMLStandardMode);
ASSERT_NE(nullptr, value);
EXPECT_TRUE(value->IsUnsetValue());
value = CSSParserFastPaths::MaybeParseValue(CSSPropertyMarginLeft, "unsEt",
kHTMLStandardMode);
ASSERT_NE(nullptr, value);
EXPECT_TRUE(value->IsUnsetValue());
// Fast path doesn't handle short hands.
value = CSSParserFastPaths::MaybeParseValue(CSSPropertyMargin, "initial",
kHTMLStandardMode);
......
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