Commit 164dc0f5 authored by Jia's avatar Jia Committed by Commit Bot

Implement parseShorthand API for 4 background related properties.

This cl implements parseShorthand APIs for background, -webkit-mask,
background-repeat and -webkit-mask-repeat.

Properties background and -webkit-mask are handled by the same API. 
This is because their parsing logic is too similar. In order to avoid
duplicating the code and also without having to pass shorthand id to
util functions, we check shorthand id within the API class and 
parses property according to shorthand id.

Bug: 668012
Change-Id: I0751a2b7517fb3fbff53adeb54797fda8f89dd80
Reviewed-on: https://chromium-review.googlesource.com/601770
Commit-Queue: Jia Meng <jiameng@chromium.org>
Reviewed-by: default avatarmeade_UTC10 <meade@chromium.org>
Reviewed-by: default avatarBugs Nash <bugsnash@chromium.org>
Cr-Commit-Position: refs/heads/master@{#496591}
parent 1623c229
...@@ -693,7 +693,6 @@ code_generator("make_core_generated_css_property_apis") { ...@@ -693,7 +693,6 @@ code_generator("make_core_generated_css_property_apis") {
"$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitColumnBreakBefore.h", "$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitColumnBreakBefore.h",
"$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitColumnBreakInside.h", "$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitColumnBreakInside.h",
"$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitMarginCollapse.h", "$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitMarginCollapse.h",
"$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitMask.h",
"$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitMaskBoxImage.h", "$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitMaskBoxImage.h",
"$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitMaskPosition.h", "$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitMaskPosition.h",
"$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitMaskRepeat.h", "$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitMaskRepeat.h",
......
...@@ -394,8 +394,6 @@ blink_core_sources("css") { ...@@ -394,8 +394,6 @@ blink_core_sources("css") {
"properties/CSSPropertyAPIBackgroundOrMaskImage.cpp", "properties/CSSPropertyAPIBackgroundOrMaskImage.cpp",
"properties/CSSPropertyAPIBackgroundOrMaskSize.cpp", "properties/CSSPropertyAPIBackgroundOrMaskSize.cpp",
"properties/CSSPropertyAPIBaseCustom.cpp", "properties/CSSPropertyAPIBaseCustom.cpp",
"properties/CSSPropertyAPIBaseHelper.cpp",
"properties/CSSPropertyAPIBaseHelper.h",
"properties/CSSPropertyAPIBaselineShift.cpp", "properties/CSSPropertyAPIBaselineShift.cpp",
"properties/CSSPropertyAPIBorderColor.cpp", "properties/CSSPropertyAPIBorderColor.cpp",
"properties/CSSPropertyAPIBorderImageOutset.cpp", "properties/CSSPropertyAPIBorderImageOutset.cpp",
...@@ -587,7 +585,9 @@ blink_core_sources("css") { ...@@ -587,7 +585,9 @@ blink_core_sources("css") {
"properties/CSSPropertyWebkitBorderWidthUtils.cpp", "properties/CSSPropertyWebkitBorderWidthUtils.cpp",
"properties/CSSPropertyWebkitBorderWidthUtils.h", "properties/CSSPropertyWebkitBorderWidthUtils.h",
"properties/CSSShorthandPropertyAPIAnimation.cpp", "properties/CSSShorthandPropertyAPIAnimation.cpp",
"properties/CSSShorthandPropertyAPIBackground.cpp",
"properties/CSSShorthandPropertyAPIBackgroundPosition.cpp", "properties/CSSShorthandPropertyAPIBackgroundPosition.cpp",
"properties/CSSShorthandPropertyAPIBackgroundRepeat.cpp",
"properties/CSSShorthandPropertyAPIBorder.cpp", "properties/CSSShorthandPropertyAPIBorder.cpp",
"properties/CSSShorthandPropertyAPIBorderBottom.cpp", "properties/CSSShorthandPropertyAPIBorderBottom.cpp",
"properties/CSSShorthandPropertyAPIBorderColor.cpp", "properties/CSSShorthandPropertyAPIBorderColor.cpp",
...@@ -643,6 +643,7 @@ blink_core_sources("css") { ...@@ -643,6 +643,7 @@ blink_core_sources("css") {
"properties/CSSShorthandPropertyAPIWebkitMarginCollapse.cpp", "properties/CSSShorthandPropertyAPIWebkitMarginCollapse.cpp",
"properties/CSSShorthandPropertyAPIWebkitMaskBoxImage.cpp", "properties/CSSShorthandPropertyAPIWebkitMaskBoxImage.cpp",
"properties/CSSShorthandPropertyAPIWebkitMaskPosition.cpp", "properties/CSSShorthandPropertyAPIWebkitMaskPosition.cpp",
"properties/CSSShorthandPropertyAPIWebkitMaskRepeat.cpp",
"properties/CSSShorthandPropertyAPIWebkitTextEmphasis.cpp", "properties/CSSShorthandPropertyAPIWebkitTextEmphasis.cpp",
"properties/CSSShorthandPropertyAPIWebkitTextStroke.cpp", "properties/CSSShorthandPropertyAPIWebkitTextStroke.cpp",
"resolver/AnimatedStyleBuilder.cpp", "resolver/AnimatedStyleBuilder.cpp",
......
...@@ -3826,7 +3826,8 @@ ...@@ -3826,7 +3826,8 @@
{ {
name: "background", name: "background",
longhands: ["background-image", "background-position-x", "background-position-y", "background-size", "background-repeat-x", "background-repeat-y", "background-attachment", "background-origin", "background-clip", "background-color"], longhands: ["background-image", "background-position-x", "background-position-y", "background-size", "background-repeat-x", "background-repeat-y", "background-attachment", "background-origin", "background-clip", "background-color"],
api_class: true, api_class: "CSSShorthandPropertyAPIBackground",
api_methods: ["ParseShorthand"],
}, },
{ {
name: "background-position", name: "background-position",
...@@ -3838,6 +3839,7 @@ ...@@ -3838,6 +3839,7 @@
name: "background-repeat", name: "background-repeat",
longhands: ["background-repeat-x", "background-repeat-y"], longhands: ["background-repeat-x", "background-repeat-y"],
api_class: true, api_class: true,
api_methods: ["ParseShorthand"],
}, },
{ {
name: "border", name: "border",
...@@ -4180,7 +4182,8 @@ ...@@ -4180,7 +4182,8 @@
{ {
name: "-webkit-mask", name: "-webkit-mask",
longhands: ["-webkit-mask-image", "-webkit-mask-position-x", "-webkit-mask-position-y", "-webkit-mask-size", "-webkit-mask-repeat-x", "-webkit-mask-repeat-y", "-webkit-mask-origin", "-webkit-mask-clip"], longhands: ["-webkit-mask-image", "-webkit-mask-position-x", "-webkit-mask-position-y", "-webkit-mask-size", "-webkit-mask-repeat-x", "-webkit-mask-repeat-y", "-webkit-mask-origin", "-webkit-mask-clip"],
api_class: true, api_class: "CSSShorthandPropertyAPIBackground",
api_methods: ["ParseShorthand"],
}, },
{ {
name: "-webkit-mask-box-image", name: "-webkit-mask-box-image",
...@@ -4198,6 +4201,7 @@ ...@@ -4198,6 +4201,7 @@
name: "-webkit-mask-repeat", name: "-webkit-mask-repeat",
longhands: ["-webkit-mask-repeat-x", "-webkit-mask-repeat-y"], longhands: ["-webkit-mask-repeat-x", "-webkit-mask-repeat-y"],
api_class: true, api_class: true,
api_methods: ["ParseShorthand"],
}, },
{ {
name: "-webkit-text-emphasis", name: "-webkit-text-emphasis",
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "core/css/parser/CSSParserContext.h" #include "core/css/parser/CSSParserContext.h"
#include "core/css/parser/CSSParserLocalContext.h" #include "core/css/parser/CSSParserLocalContext.h"
#include "core/css/parser/CSSPropertyParserHelpers.h" #include "core/css/parser/CSSPropertyParserHelpers.h"
#include "core/css/properties/CSSPropertyAPIBaseHelper.h"
#include "core/css/properties/CSSPropertyAnimationTimingFunctionUtils.h" #include "core/css/properties/CSSPropertyAnimationTimingFunctionUtils.h"
#include "core/css/properties/CSSPropertyBackgroundUtils.h" #include "core/css/properties/CSSPropertyBackgroundUtils.h"
#include "core/css/properties/CSSPropertyBorderImageUtils.h" #include "core/css/properties/CSSPropertyBorderImageUtils.h"
...@@ -24,28 +23,8 @@ ...@@ -24,28 +23,8 @@
namespace blink { namespace blink {
using namespace CSSPropertyAPIBaseHelper;
using namespace CSSPropertyParserHelpers; using namespace CSSPropertyParserHelpers;
namespace {
bool ConsumeRepeatStyle(CSSParserTokenRange& range,
CSSValue*& result_x,
CSSValue*& result_y,
bool& implicit) {
do {
CSSValue* repeat_x = nullptr;
CSSValue* repeat_y = nullptr;
if (!ConsumeRepeatStyleComponent(range, repeat_x, repeat_y, implicit))
return false;
CSSPropertyBackgroundUtils::AddBackgroundValue(result_x, repeat_x);
CSSPropertyBackgroundUtils::AddBackgroundValue(result_y, repeat_y);
} while (ConsumeCommaIncludingWhitespace(range));
return true;
}
} // namespace
const CSSValue* CSSPropertyAPI::ParseSingleValue( const CSSValue* CSSPropertyAPI::ParseSingleValue(
CSSPropertyID property, CSSPropertyID property,
CSSParserTokenRange& range, CSSParserTokenRange& range,
...@@ -70,41 +49,7 @@ bool CSSPropertyAPI::ParseShorthand( ...@@ -70,41 +49,7 @@ bool CSSPropertyAPI::ParseShorthand(
const CSSParserContext& context, const CSSParserContext& context,
const CSSParserLocalContext& local_context, const CSSParserLocalContext& local_context,
HeapVector<CSSProperty, 256>& properties) const { HeapVector<CSSProperty, 256>& properties) const {
// This is the legacy ParseShorthand code. return false;
// TODO(jiameng): Move all of this to individual CSSPropertyAPI subclasses.
switch (property) {
case CSSPropertyBorder:
return ConsumeBorder(important, range, context, properties);
case CSSPropertyBackgroundRepeat:
case CSSPropertyWebkitMaskRepeat: {
CSSValue* result_x = nullptr;
CSSValue* result_y = nullptr;
bool implicit = false;
if (!ConsumeRepeatStyle(range, result_x, result_y, implicit) ||
!range.AtEnd())
return false;
IsImplicitProperty enum_implicit = implicit
? IsImplicitProperty::kImplicit
: IsImplicitProperty::kNotImplicit;
AddProperty(property == CSSPropertyBackgroundRepeat
? CSSPropertyBackgroundRepeatX
: CSSPropertyWebkitMaskRepeatX,
property, *result_x, important, enum_implicit, properties);
AddProperty(property == CSSPropertyBackgroundRepeat
? CSSPropertyBackgroundRepeatY
: CSSPropertyWebkitMaskRepeatY,
property, *result_y, important, enum_implicit, properties);
return true;
}
case CSSPropertyBackground:
return ConsumeBackgroundShorthand(backgroundShorthand(), important, range,
context, properties);
case CSSPropertyWebkitMask:
return ConsumeBackgroundShorthand(webkitMaskShorthand(), important, range,
context, properties);
default:
return false;
}
} }
} // namespace blink } // namespace blink
// 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.
#ifndef CSSPropertyAPIBaseHelper_h
#define CSSPropertyAPIBaseHelper_h
#include "core/CSSPropertyNames.h"
#include "core/css/CSSProperty.h"
#include "core/css/parser/CSSParserMode.h"
#include "platform/wtf/Vector.h"
#include "platform/wtf/text/WTFString.h"
namespace blink {
class CSSParserTokenRange;
class CSSParserContext;
class CSSValue;
class StylePropertyShorthand;
// This file contains a bunch of helper methods that are used in CSSPropertyAPI
namespace CSSPropertyAPIBaseHelper {
bool ConsumeBackgroundShorthand(const StylePropertyShorthand&,
bool important,
CSSParserTokenRange&,
const CSSParserContext&,
HeapVector<CSSProperty, 256>& properties);
bool ConsumeBorder(bool important,
CSSParserTokenRange&,
const CSSParserContext&,
HeapVector<CSSProperty, 256>& properties);
bool ConsumeRepeatStyleComponent(CSSParserTokenRange&,
CSSValue*& value1,
CSSValue*& value2,
bool& implicit);
CSSValue* ConsumeBackgroundSize(CSSParserTokenRange&,
CSSParserMode,
bool use_legacy_parsing);
CSSValue* ConsumePrefixedBackgroundBox(CSSParserTokenRange&,
bool allow_text_value);
} // namespace CSSPropertyAPIBaseHelper
} // namespace blink
#endif // CSSPropertyAPIBaseHelper_h
...@@ -17,7 +17,7 @@ const CSSValue* CSSPropertyAPIWebkitClip::ParseSingleValue( ...@@ -17,7 +17,7 @@ const CSSValue* CSSPropertyAPIWebkitClip::ParseSingleValue(
const CSSParserLocalContext&) const { const CSSParserLocalContext&) const {
return CSSPropertyParserHelpers::ConsumeCommaSeparatedList( return CSSPropertyParserHelpers::ConsumeCommaSeparatedList(
CSSPropertyBackgroundUtils::ConsumePrefixedBackgroundBox, range, CSSPropertyBackgroundUtils::ConsumePrefixedBackgroundBox, range,
true /* allow_text_value */); AllowTextValue::kAllowed);
} }
} // namespace blink } // namespace blink
...@@ -17,7 +17,7 @@ const CSSValue* CSSPropertyAPIWebkitOrigin::ParseSingleValue( ...@@ -17,7 +17,7 @@ const CSSValue* CSSPropertyAPIWebkitOrigin::ParseSingleValue(
const CSSParserLocalContext&) const { const CSSParserLocalContext&) const {
return CSSPropertyParserHelpers::ConsumeCommaSeparatedList( return CSSPropertyParserHelpers::ConsumeCommaSeparatedList(
CSSPropertyBackgroundUtils::ConsumePrefixedBackgroundBox, range, CSSPropertyBackgroundUtils::ConsumePrefixedBackgroundBox, range,
false /* allow_text_value */); AllowTextValue::kNotAllowed);
} }
} // namespace blink } // namespace blink
...@@ -121,15 +121,62 @@ bool CSSPropertyBackgroundUtils::ConsumeBackgroundPosition( ...@@ -121,15 +121,62 @@ bool CSSPropertyBackgroundUtils::ConsumeBackgroundPosition(
CSSValue* CSSPropertyBackgroundUtils::ConsumePrefixedBackgroundBox( CSSValue* CSSPropertyBackgroundUtils::ConsumePrefixedBackgroundBox(
CSSParserTokenRange& range, CSSParserTokenRange& range,
bool allow_text_value) { AllowTextValue allow_text_value) {
// The values 'border', 'padding' and 'content' are deprecated and do not // The values 'border', 'padding' and 'content' are deprecated and do not
// apply to the version of the property that has the -webkit- prefix removed. // apply to the version of the property that has the -webkit- prefix removed.
if (CSSValue* value = CSSPropertyParserHelpers::ConsumeIdentRange( if (CSSValue* value = CSSPropertyParserHelpers::ConsumeIdentRange(
range, CSSValueBorder, CSSValuePaddingBox)) range, CSSValueBorder, CSSValuePaddingBox))
return value; return value;
if (allow_text_value && range.Peek().Id() == CSSValueText) if (allow_text_value == AllowTextValue::kAllowed &&
range.Peek().Id() == CSSValueText)
return CSSPropertyParserHelpers::ConsumeIdent(range); return CSSPropertyParserHelpers::ConsumeIdent(range);
return nullptr; return nullptr;
} }
bool CSSPropertyBackgroundUtils::ConsumeRepeatStyleComponent(
CSSParserTokenRange& range,
CSSValue*& value1,
CSSValue*& value2,
bool& implicit) {
if (CSSPropertyParserHelpers::ConsumeIdent<CSSValueRepeatX>(range)) {
value1 = CSSIdentifierValue::Create(CSSValueRepeat);
value2 = CSSIdentifierValue::Create(CSSValueNoRepeat);
implicit = true;
return true;
}
if (CSSPropertyParserHelpers::ConsumeIdent<CSSValueRepeatY>(range)) {
value1 = CSSIdentifierValue::Create(CSSValueNoRepeat);
value2 = CSSIdentifierValue::Create(CSSValueRepeat);
implicit = true;
return true;
}
value1 = CSSPropertyParserHelpers::ConsumeIdent<
CSSValueRepeat, CSSValueNoRepeat, CSSValueRound, CSSValueSpace>(range);
if (!value1)
return false;
value2 = CSSPropertyParserHelpers::ConsumeIdent<
CSSValueRepeat, CSSValueNoRepeat, CSSValueRound, CSSValueSpace>(range);
if (!value2) {
value2 = value1;
implicit = true;
}
return true;
}
bool CSSPropertyBackgroundUtils::ConsumeRepeatStyle(CSSParserTokenRange& range,
CSSValue*& result_x,
CSSValue*& result_y,
bool& implicit) {
do {
CSSValue* repeat_x = nullptr;
CSSValue* repeat_y = nullptr;
if (!ConsumeRepeatStyleComponent(range, repeat_x, repeat_y, implicit))
return false;
AddBackgroundValue(result_x, repeat_x);
AddBackgroundValue(result_y, repeat_y);
} while (CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(range));
return true;
}
} // namespace blink } // namespace blink
...@@ -15,6 +15,7 @@ class CSSParserTokenRange; ...@@ -15,6 +15,7 @@ class CSSParserTokenRange;
class CSSValue; class CSSValue;
enum class ParsingStyle { kLegacy, kNotLegacy }; enum class ParsingStyle { kLegacy, kNotLegacy };
enum class AllowTextValue { kAllowed, kNotAllowed };
class CSSPropertyBackgroundUtils { class CSSPropertyBackgroundUtils {
STATIC_ONLY(CSSPropertyBackgroundUtils); STATIC_ONLY(CSSPropertyBackgroundUtils);
...@@ -39,7 +40,15 @@ class CSSPropertyBackgroundUtils { ...@@ -39,7 +40,15 @@ class CSSPropertyBackgroundUtils {
CSSValue*& result_x, CSSValue*& result_x,
CSSValue*& result_y); CSSValue*& result_y);
static CSSValue* ConsumePrefixedBackgroundBox(CSSParserTokenRange&, static CSSValue* ConsumePrefixedBackgroundBox(CSSParserTokenRange&,
bool allow_text_value); AllowTextValue);
static bool ConsumeRepeatStyleComponent(CSSParserTokenRange&,
CSSValue*& value1,
CSSValue*& value2,
bool& implicit);
static bool ConsumeRepeatStyle(CSSParserTokenRange&,
CSSValue*& result_x,
CSSValue*& result_y,
bool& implicit);
}; };
} // namespace blink } // namespace blink
......
// 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/CSSShorthandPropertyAPIBackgroundRepeat.h"
#include "core/StylePropertyShorthand.h"
#include "core/css/CSSInitialValue.h"
#include "core/css/parser/CSSParserContext.h"
#include "core/css/parser/CSSPropertyParserHelpers.h"
#include "core/css/properties/CSSPropertyBackgroundUtils.h"
namespace blink {
bool CSSShorthandPropertyAPIBackgroundRepeat::ParseShorthand(
CSSPropertyID,
bool important,
CSSParserTokenRange& range,
const CSSParserContext& context,
const CSSParserLocalContext& local_context,
HeapVector<CSSProperty, 256>& properties) const {
CSSValue* result_x = nullptr;
CSSValue* result_y = nullptr;
bool implicit = false;
if (!CSSPropertyBackgroundUtils::ConsumeRepeatStyle(range, result_x, result_y,
implicit) ||
!range.AtEnd())
return false;
CSSPropertyParserHelpers::AddProperty(
CSSPropertyBackgroundRepeatX, CSSPropertyBackgroundRepeat, *result_x,
important,
implicit ? CSSPropertyParserHelpers::IsImplicitProperty::kImplicit
: CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit,
properties);
CSSPropertyParserHelpers::AddProperty(
CSSPropertyBackgroundRepeatY, CSSPropertyBackgroundRepeat, *result_y,
important,
implicit ? CSSPropertyParserHelpers::IsImplicitProperty::kImplicit
: CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit,
properties);
return true;
}
} // namespace blink
// 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/CSSShorthandPropertyAPIWebkitMaskRepeat.h"
#include "core/StylePropertyShorthand.h"
#include "core/css/CSSInitialValue.h"
#include "core/css/parser/CSSParserContext.h"
#include "core/css/parser/CSSPropertyParserHelpers.h"
#include "core/css/properties/CSSPropertyBackgroundUtils.h"
namespace blink {
bool CSSShorthandPropertyAPIWebkitMaskRepeat::ParseShorthand(
CSSPropertyID,
bool important,
CSSParserTokenRange& range,
const CSSParserContext& context,
const CSSParserLocalContext& local_context,
HeapVector<CSSProperty, 256>& properties) const {
CSSValue* result_x = nullptr;
CSSValue* result_y = nullptr;
bool implicit = false;
if (!CSSPropertyBackgroundUtils::ConsumeRepeatStyle(range, result_x, result_y,
implicit) ||
!range.AtEnd())
return false;
CSSPropertyParserHelpers::AddProperty(
CSSPropertyWebkitMaskRepeatX, CSSPropertyWebkitMaskRepeat, *result_x,
important,
implicit ? CSSPropertyParserHelpers::IsImplicitProperty::kImplicit
: CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit,
properties);
CSSPropertyParserHelpers::AddProperty(
CSSPropertyWebkitMaskRepeatY, CSSPropertyWebkitMaskRepeat, *result_y,
important,
implicit ? CSSPropertyParserHelpers::IsImplicitProperty::kImplicit
: CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit,
properties);
return true;
}
} // 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