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
......
...@@ -2,92 +2,33 @@ ...@@ -2,92 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "core/css/properties/CSSPropertyAPIBaseHelper.h" #include "core/css/properties/CSSShorthandPropertyAPIBackground.h"
#include "core/StylePropertyShorthand.h" #include "core/StylePropertyShorthand.h"
#include "core/css/CSSFunctionValue.h"
#include "core/css/CSSGridAutoRepeatValue.h"
#include "core/css/CSSGridLineNamesValue.h"
#include "core/css/CSSIdentifierValue.h"
#include "core/css/CSSInheritedValue.h"
#include "core/css/CSSInitialValue.h" #include "core/css/CSSInitialValue.h"
#include "core/css/CSSPrimitiveValueMappings.h"
#include "core/css/CSSValue.h"
#include "core/css/CSSValuePair.h"
#include "core/css/parser/CSSParserContext.h" #include "core/css/parser/CSSParserContext.h"
#include "core/css/parser/CSSParserIdioms.h" #include "core/css/parser/CSSParserLocalContext.h"
#include "core/css/parser/CSSParserMode.h"
#include "core/css/parser/CSSPropertyParserHelpers.h" #include "core/css/parser/CSSPropertyParserHelpers.h"
#include "core/css/properties/CSSPropertyAlignmentUtils.h"
#include "core/css/properties/CSSPropertyBackgroundUtils.h" #include "core/css/properties/CSSPropertyBackgroundUtils.h"
#include "core/css/properties/CSSPropertyGridUtils.h"
#include "core/css/properties/CSSPropertyPositionUtils.h" #include "core/css/properties/CSSPropertyPositionUtils.h"
#include "core/style/GridArea.h"
#include "platform/wtf/text/StringBuilder.h"
namespace blink { namespace blink {
namespace CSSPropertyAPIBaseHelper {
using namespace CSSPropertyParserHelpers;
namespace { namespace {
// This is copied from CSSPropertyParser for now. This should go away once we CSSValue* ConsumeBackgroundComponent(CSSPropertyID resolved_property,
// finish ribbonizing all the shorthands. CSSParserTokenRange& range,
void AddExpandedPropertyForValue(CSSPropertyID property, const CSSParserContext& context) {
const CSSValue& value, switch (resolved_property) {
bool important,
HeapVector<CSSProperty, 256>& properties) {
const StylePropertyShorthand& shorthand = shorthandForProperty(property);
unsigned shorthand_length = shorthand.length();
DCHECK(shorthand_length);
const CSSPropertyID* longhands = shorthand.properties();
for (unsigned i = 0; i < shorthand_length; ++i) {
AddProperty(longhands[i], shorthand.id(), value, important,
IsImplicitProperty::kNotImplicit, properties);
}
}
} // namespace
CSSValue* ConsumePrefixedBackgroundBox(CSSParserTokenRange& range,
bool allow_text_value) {
// The values 'border', 'padding' and 'content' are deprecated and do not
// apply to the version of the property that has the -webkit- prefix removed.
if (CSSValue* value =
ConsumeIdentRange(range, CSSValueBorder, CSSValuePaddingBox))
return value;
if (allow_text_value && range.Peek().Id() == CSSValueText)
return ConsumeIdent(range);
return nullptr;
}
static CSSValue* ConsumeBackgroundComponent(CSSPropertyID unresolved_property,
CSSParserTokenRange& range,
const CSSParserContext& context) {
switch (unresolved_property) {
case CSSPropertyBackgroundClip: case CSSPropertyBackgroundClip:
return CSSPropertyBackgroundUtils::ConsumeBackgroundBox(range); return CSSPropertyBackgroundUtils::ConsumeBackgroundBox(range);
case CSSPropertyBackgroundBlendMode:
return CSSPropertyBackgroundUtils::ConsumeBackgroundBlendMode(range);
case CSSPropertyBackgroundAttachment: case CSSPropertyBackgroundAttachment:
return CSSPropertyBackgroundUtils::ConsumeBackgroundAttachment(range); return CSSPropertyBackgroundUtils::ConsumeBackgroundAttachment(range);
case CSSPropertyBackgroundOrigin: case CSSPropertyBackgroundOrigin:
return CSSPropertyBackgroundUtils::ConsumeBackgroundBox(range); return CSSPropertyBackgroundUtils::ConsumeBackgroundBox(range);
case CSSPropertyWebkitMaskComposite:
return CSSPropertyBackgroundUtils::ConsumeBackgroundComposite(range);
case CSSPropertyMaskSourceType:
return CSSPropertyBackgroundUtils::ConsumeMaskSourceType(range);
case CSSPropertyWebkitBackgroundClip:
case CSSPropertyWebkitMaskClip:
return ConsumePrefixedBackgroundBox(range, true /* allow_text_value */);
case CSSPropertyWebkitBackgroundOrigin:
case CSSPropertyWebkitMaskOrigin:
return ConsumePrefixedBackgroundBox(range, false /* allow_text_value */);
case CSSPropertyBackgroundImage: case CSSPropertyBackgroundImage:
case CSSPropertyWebkitMaskImage: case CSSPropertyWebkitMaskImage:
return ConsumeImageOrNone(range, &context); return CSSPropertyParserHelpers::ConsumeImageOrNone(range, &context);
case CSSPropertyBackgroundPositionX: case CSSPropertyBackgroundPositionX:
case CSSPropertyWebkitMaskPositionX: case CSSPropertyWebkitMaskPositionX:
return CSSPropertyPositionUtils::ConsumePositionLonghand<CSSValueLeft, return CSSPropertyPositionUtils::ConsumePositionLonghand<CSSValueLeft,
...@@ -102,105 +43,44 @@ static CSSValue* ConsumeBackgroundComponent(CSSPropertyID unresolved_property, ...@@ -102,105 +43,44 @@ static CSSValue* ConsumeBackgroundComponent(CSSPropertyID unresolved_property,
case CSSPropertyWebkitMaskSize: case CSSPropertyWebkitMaskSize:
return CSSPropertyBackgroundUtils::ConsumeBackgroundSize( return CSSPropertyBackgroundUtils::ConsumeBackgroundSize(
range, context.Mode(), ParsingStyle::kNotLegacy); range, context.Mode(), ParsingStyle::kNotLegacy);
case CSSPropertyAliasWebkitBackgroundSize:
return CSSPropertyBackgroundUtils::ConsumeBackgroundSize(
range, context.Mode(), ParsingStyle::kLegacy);
case CSSPropertyBackgroundColor: case CSSPropertyBackgroundColor:
return ConsumeColor(range, context.Mode()); return CSSPropertyParserHelpers::ConsumeColor(range, context.Mode());
case CSSPropertyWebkitMaskClip:
return CSSPropertyBackgroundUtils::ConsumePrefixedBackgroundBox(
range, AllowTextValue::kAllowed);
case CSSPropertyWebkitMaskOrigin:
return CSSPropertyBackgroundUtils::ConsumePrefixedBackgroundBox(
range, AllowTextValue::kNotAllowed);
default: default:
break; break;
}; };
return nullptr; return nullptr;
} }
bool ConsumeBorder(bool important, } // namespace
CSSParserTokenRange& range,
const CSSParserContext& context,
HeapVector<CSSProperty, 256>& properties) {
CSSValue* width = nullptr;
const CSSValue* style = nullptr;
CSSValue* color = nullptr;
while (!width || !style || !color) {
if (!width) {
width = ConsumeLineWidth(range, context.Mode(), UnitlessQuirk::kForbid);
if (width)
continue;
}
if (!style) {
style = CSSPropertyParserHelpers::ParseLonghandViaAPI(
CSSPropertyBorderLeftStyle, CSSPropertyBorder, context, range);
if (style)
continue;
}
if (!color) {
color = ConsumeColor(range, context.Mode());
if (color)
continue;
}
break;
}
if (!width && !style && !color)
return false;
if (!width)
width = CSSInitialValue::Create();
if (!style)
style = CSSInitialValue::Create();
if (!color)
color = CSSInitialValue::Create();
AddExpandedPropertyForValue(CSSPropertyBorderWidth, *width, important,
properties);
AddExpandedPropertyForValue(CSSPropertyBorderStyle, *style, important,
properties);
AddExpandedPropertyForValue(CSSPropertyBorderColor, *color, important,
properties);
AddExpandedPropertyForValue(CSSPropertyBorderImage,
*CSSInitialValue::Create(), important,
properties);
return range.AtEnd();
}
bool ConsumeRepeatStyleComponent(CSSParserTokenRange& range,
CSSValue*& value1,
CSSValue*& value2,
bool& implicit) {
if (ConsumeIdent<CSSValueRepeatX>(range)) {
value1 = CSSIdentifierValue::Create(CSSValueRepeat);
value2 = CSSIdentifierValue::Create(CSSValueNoRepeat);
implicit = true;
return true;
}
if (ConsumeIdent<CSSValueRepeatY>(range)) {
value1 = CSSIdentifierValue::Create(CSSValueNoRepeat);
value2 = CSSIdentifierValue::Create(CSSValueRepeat);
implicit = true;
return true;
}
value1 = ConsumeIdent<CSSValueRepeat, CSSValueNoRepeat, CSSValueRound,
CSSValueSpace>(range);
if (!value1)
return false;
value2 = ConsumeIdent<CSSValueRepeat, CSSValueNoRepeat, CSSValueRound, // Note: this assumes y properties (e.g. background-position-y) follow the x
CSSValueSpace>(range); // properties in the shorthand array.
if (!value2) { // TODO(jiameng): this API is used by background and -webkit-mask, hence we need
value2 = value1; // local_context as an input that contains shorthand id. We will consider remove
implicit = true; // local_context as an input after
} // (i). StylePropertyShorthand is refactored and
return true; // (ii). we split parsing logic of background and -webkit-mask into
} // different APIs.
bool CSSShorthandPropertyAPIBackground::ParseShorthand(
CSSPropertyID,
bool important,
CSSParserTokenRange& range,
const CSSParserContext& context,
const CSSParserLocalContext& local_context,
HeapVector<CSSProperty, 256>& properties) const {
CSSPropertyID shorthand_id = local_context.CurrentShorthand();
DCHECK(shorthand_id == CSSPropertyBackground ||
shorthand_id == CSSPropertyWebkitMask);
const StylePropertyShorthand& shorthand =
shorthand_id == CSSPropertyBackground ? backgroundShorthand()
: webkitMaskShorthand();
// Note: consumeBackgroundShorthand assumes y properties (for example
// background-position-y) follow the x properties in the shorthand array.
bool ConsumeBackgroundShorthand(const StylePropertyShorthand& shorthand,
bool important,
CSSParserTokenRange& range,
const CSSParserContext& context,
HeapVector<CSSProperty, 256>& properties) {
const unsigned longhand_count = shorthand.length(); const unsigned longhand_count = shorthand.length();
CSSValue* longhands[10] = {0}; CSSValue* longhands[10] = {0};
DCHECK_LE(longhand_count, 10u); DCHECK_LE(longhand_count, 10u);
...@@ -220,21 +100,25 @@ bool ConsumeBackgroundShorthand(const StylePropertyShorthand& shorthand, ...@@ -220,21 +100,25 @@ bool ConsumeBackgroundShorthand(const StylePropertyShorthand& shorthand,
CSSPropertyID property = shorthand.properties()[i]; CSSPropertyID property = shorthand.properties()[i];
if (property == CSSPropertyBackgroundRepeatX || if (property == CSSPropertyBackgroundRepeatX ||
property == CSSPropertyWebkitMaskRepeatX) { property == CSSPropertyWebkitMaskRepeatX) {
ConsumeRepeatStyleComponent(range, value, value_y, implicit); CSSPropertyBackgroundUtils::ConsumeRepeatStyleComponent(
range, value, value_y, implicit);
} else if (property == CSSPropertyBackgroundPositionX || } else if (property == CSSPropertyBackgroundPositionX ||
property == CSSPropertyWebkitMaskPositionX) { property == CSSPropertyWebkitMaskPositionX) {
if (!ConsumePosition(range, context, UnitlessQuirk::kForbid, if (!CSSPropertyParserHelpers::ConsumePosition(
WebFeature::kThreeValuedPositionBackground, range, context,
value, value_y)) CSSPropertyParserHelpers::UnitlessQuirk::kForbid,
WebFeature::kThreeValuedPositionBackground, value, value_y))
continue; continue;
} else if (property == CSSPropertyBackgroundSize || } else if (property == CSSPropertyBackgroundSize ||
property == CSSPropertyWebkitMaskSize) { property == CSSPropertyWebkitMaskSize) {
if (!ConsumeSlashIncludingWhitespace(range)) if (!CSSPropertyParserHelpers::ConsumeSlashIncludingWhitespace(range))
continue; continue;
value = CSSPropertyBackgroundUtils::ConsumeBackgroundSize( value = CSSPropertyBackgroundUtils::ConsumeBackgroundSize(
range, context.Mode(), ParsingStyle::kNotLegacy); range, context.Mode(), ParsingStyle::kNotLegacy);
if (!value || !parsed_longhand[i - 1]) { if (!value ||
// Position must have been parsed in the current layer. !parsed_longhand[i - 1]) // Position must have been
// parsed in the current layer.
{
return false; return false;
} }
} else if (property == CSSPropertyBackgroundPositionY || } else if (property == CSSPropertyBackgroundPositionY ||
...@@ -247,8 +131,9 @@ bool ConsumeBackgroundShorthand(const StylePropertyShorthand& shorthand, ...@@ -247,8 +131,9 @@ bool ConsumeBackgroundShorthand(const StylePropertyShorthand& shorthand,
} }
if (value) { if (value) {
if (property == CSSPropertyBackgroundOrigin || if (property == CSSPropertyBackgroundOrigin ||
property == CSSPropertyWebkitMaskOrigin) property == CSSPropertyWebkitMaskOrigin) {
origin_value = value; origin_value = value;
}
parsed_longhand[i] = true; parsed_longhand[i] = true;
found_property = true; found_property = true;
CSSPropertyBackgroundUtils::AddBackgroundValue(longhands[i], value); CSSPropertyBackgroundUtils::AddBackgroundValue(longhands[i], value);
...@@ -283,7 +168,7 @@ bool ConsumeBackgroundShorthand(const StylePropertyShorthand& shorthand, ...@@ -283,7 +168,7 @@ bool ConsumeBackgroundShorthand(const StylePropertyShorthand& shorthand,
longhands[i], CSSInitialValue::Create()); longhands[i], CSSInitialValue::Create());
} }
} }
} while (ConsumeCommaIncludingWhitespace(range)); } while (CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(range));
if (!range.AtEnd()) if (!range.AtEnd())
return false; return false;
...@@ -292,34 +177,13 @@ bool ConsumeBackgroundShorthand(const StylePropertyShorthand& shorthand, ...@@ -292,34 +177,13 @@ bool ConsumeBackgroundShorthand(const StylePropertyShorthand& shorthand,
if (property == CSSPropertyBackgroundSize && longhands[i] && if (property == CSSPropertyBackgroundSize && longhands[i] &&
context.UseLegacyBackgroundSizeShorthandBehavior()) context.UseLegacyBackgroundSizeShorthandBehavior())
continue; continue;
AddProperty(property, shorthand.id(), *longhands[i], important, CSSPropertyParserHelpers::AddProperty(
implicit ? IsImplicitProperty::kImplicit property, shorthand.id(), *longhands[i], important,
: IsImplicitProperty::kNotImplicit, implicit ? CSSPropertyParserHelpers::IsImplicitProperty::kImplicit
properties); : CSSPropertyParserHelpers::IsImplicitProperty::kNotImplicit,
properties);
} }
return true; return true;
} }
CSSValueList* ConsumeImplicitAutoFlow(CSSParserTokenRange& range,
const CSSValue& flow_direction) {
// [ auto-flow && dense? ]
CSSValue* dense_algorithm = nullptr;
if ((ConsumeIdent<CSSValueAutoFlow>(range))) {
dense_algorithm = ConsumeIdent<CSSValueDense>(range);
} else {
dense_algorithm = ConsumeIdent<CSSValueDense>(range);
if (!dense_algorithm)
return nullptr;
if (!ConsumeIdent<CSSValueAutoFlow>(range))
return nullptr;
}
CSSValueList* list = CSSValueList::CreateSpaceSeparated();
list->Append(flow_direction);
if (dense_algorithm)
list->Append(*dense_algorithm);
return list;
}
} // namespace CSSPropertyAPIBaseHelper
} // 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