Commit 632a1f75 authored by Jia's avatar Jia Committed by Commit Bot

Implement ConsumeShorthandGreedilyViaLonghandsAPI and API for shorthand...

Implement ConsumeShorthandGreedilyViaLonghandsAPI and API for shorthand property -webkit-text-emphasis.

ConsumeShorthandGreedilyViaLonghandsAPI is a modified version of
ConsumeShorthandGreedily of CSSPropertyParser. The difference between
the two is that the new version expects component longhands to have API
impl already  as it will forward parsing logic to component longhands API
via ParseLonghandViaAPI.

ConsumeShorthandGreedily will be deprecated soon, when shorthand properties 
are ribbonised (i.e. have their own APIs). Until then, there is a slight 
code duplication between the two versions for the following reasons:

1. An alternative to code duplicate is to have the old ConsumeShorthandGreedily
call the new ConsumeShorthandGreedilyViaLonghandsAPI. However, the new 
ConsumeShorthandGreedilyViaLonghandsAPI expects ALL component longhands 
to have APIs and will parse all longhands via their APIs. In order to parse 
shorthands, where some component longhands do not have APIs, the new 
ConsumeShorthandGreedilyViaLonghandsAPI will need to return to the old 
ConsumeShorthandGreedily which longhands have no APIs and thus are not parsed.
The old ConsumeShorthandGreedily will then have to parse these longhands separately.
Hence there's added code complexity with little code reduction.

2. All shorthand properties will have APIs soon, hence such code duplication is 
temporary only.

This cl also implements API for shorthand property -webkit-text-emphasis
as a use case of ConsumeShorthandGreedilyViaLonghandsAPI.

Design doc for shorthand parsing: https://docs.google.com/document/d/1gF_3wAvO82iVNcyJ7z2YzT8sFa8JepkWmIgJ9NcT1Pc/edit

Diff: https://gist.github.com/f9cff56b20f46225b6b90f033798eccf/revisions
Bug: 668012
Change-Id: I1cf9295893bb113527b44c2935d296e2997164ac
Reviewed-on: https://chromium-review.googlesource.com/564875Reviewed-by: default avatarmeade_UTC10 <meade@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Commit-Queue: Jia Meng <jiameng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485567}
parent 31f47922
......@@ -599,6 +599,7 @@ css_properties("make_core_generated_css_property_apis") {
"$blink_core_output_dir/css/properties/CSSShorthandPropertyAPITextDecoration.h",
"$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitMarginCollapse.h",
"$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitMaskBoxImage.h",
"$blink_core_output_dir/css/properties/CSSShorthandPropertyAPIWebkitTextEmphasis.h",
]
}
......
......@@ -548,6 +548,7 @@ blink_core_sources("css") {
"properties/CSSShorthandPropertyAPITextDecoration.cpp",
"properties/CSSShorthandPropertyAPIWebkitMarginCollapse.cpp",
"properties/CSSShorthandPropertyAPIWebkitMaskBoxImage.cpp",
"properties/CSSShorthandPropertyAPIWebkitTextEmphasis.cpp",
"resolver/AnimatedStyleBuilder.cpp",
"resolver/AnimatedStyleBuilder.h",
"resolver/CSSPropertyPriority.h",
......
......@@ -3924,6 +3924,8 @@
{
name: "-webkit-text-emphasis",
longhands: ["-webkit-text-emphasis-style", "-webkit-text-emphasis-color"],
api_class: true,
api_methods: ["parseShorthand"],
},
{
name: "-webkit-text-stroke",
......
......@@ -2356,8 +2356,6 @@ bool CSSPropertyParser::ParseShorthand(CSSPropertyID unresolved_property,
return ConsumeShorthandGreedily(textDecorationShorthand(), important);
case CSSPropertyPadding:
return Consume4Values(paddingShorthand(), important);
case CSSPropertyWebkitTextEmphasis:
return ConsumeShorthandGreedily(webkitTextEmphasisShorthand(), important);
case CSSPropertyOutline:
return ConsumeShorthandGreedily(outlineShorthand(), important);
case CSSPropertyWebkitBorderStart:
......
......@@ -11,6 +11,7 @@
#include "core/css/CSSGradientValue.h"
#include "core/css/CSSImageSetValue.h"
#include "core/css/CSSImageValue.h"
#include "core/css/CSSInitialValue.h"
#include "core/css/CSSPaintValue.h"
#include "core/css/CSSStringValue.h"
#include "core/css/CSSURIValue.h"
......@@ -1633,6 +1634,49 @@ bool ConsumeShorthandVia4LonghandsAPI(
return range.AtEnd();
}
bool ConsumeShorthandGreedilyViaLonghandAPIs(
const StylePropertyShorthand& shorthand,
bool important,
const CSSParserContext& context,
CSSParserTokenRange& range,
HeapVector<CSSProperty, 256>& properties) {
// Existing shorthands have at most 6 longhands.
DCHECK_LE(shorthand.length(), 6u);
const CSSValue* longhands[6] = {nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr};
bool needs_legacy_parsing = false;
const CSSPropertyID* shorthand_properties = shorthand.properties();
do {
bool found_longhand = false;
for (size_t i = 0; !found_longhand && i < shorthand.length(); ++i) {
if (longhands[i])
continue;
longhands[i] =
ParseLonghandViaAPI(shorthand_properties[i], shorthand.id(), context,
range, needs_legacy_parsing);
DCHECK(!needs_legacy_parsing);
if (longhands[i])
found_longhand = true;
}
if (!found_longhand)
return false;
} while (!range.AtEnd());
for (size_t i = 0; i < shorthand.length(); ++i) {
if (longhands[i]) {
AddProperty(shorthand_properties[i], shorthand.id(), *longhands[i],
important, IsImplicitProperty::kNotImplicit, properties);
} else {
AddProperty(shorthand_properties[i], shorthand.id(),
*CSSInitialValue::Create(), important,
IsImplicitProperty::kNotImplicit, properties);
}
}
return true;
}
} // namespace CSSPropertyParserHelpers
} // namespace blink
......@@ -131,12 +131,39 @@ const CSSValue* ParseLonghandViaAPI(CSSPropertyID unresolved_property,
CSSParserTokenRange&,
bool& needs_legacy_parsing);
// ConsumeShorthandVia4LonghandsAPI and ConsumeShorthandGreedilyViaLonghandAPIs
// are based on CSSPropertyParsers' Consume4Values and ConsumeShorthandGreedily.
// They both delegate parsing of a shorthand property to its respective longhand
// components. The difference is the functions in this Helpers file expect
// component longhands to have API implementations already.
// Consume4Values and ConsumeShorthandGreedily will be deprecated soon, when
// shorthand properties are ribbonised (i.e. have their own APIs). Until then,
// there is a slight code duplication between the two versions for the following
// reasons:
// 1. An alternative to code duplicate is to have the old Consume*
// (e.g. ConsumeShorthandGreedily) call the new Consume*
// (e.g. ConsumeShorthandGreedilyViaLonghandAPIs). However, the
// new Consume* expects ALL component longhands to have APIs and will parse
/// all longhands via their APIs. In order to parse shorthands, where some
// component longhands do not have APIs, the new Consume* will need to return
// to the old Consume* which longhands have no APIs and thus are not parsed.
// The old Consume* will then have to parse these longhands separately.
// Hence there's added code complexity with little code reduction.
// 2. All shorthand properties will have APIs soon, hence such code duplication
// is temporary only.
bool ConsumeShorthandVia4LonghandsAPI(const StylePropertyShorthand&,
bool important,
const CSSParserContext&,
CSSParserTokenRange&,
HeapVector<CSSProperty, 256>& properties);
bool ConsumeShorthandGreedilyViaLonghandAPIs(
const StylePropertyShorthand&,
bool important,
const CSSParserContext&,
CSSParserTokenRange&,
HeapVector<CSSProperty, 256>& properties);
// Template implementations are at the bottom of the file for readability.
template <typename... emptyBaseCase>
......
// 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/CSSShorthandPropertyAPIWebkitTextEmphasis.h"
#include "core/StylePropertyShorthand.h"
#include "core/css/parser/CSSPropertyParserHelpers.h"
namespace blink {
bool CSSShorthandPropertyAPIWebkitTextEmphasis::parseShorthand(
bool important,
CSSParserTokenRange& range,
const CSSParserContext& context,
const CSSParserLocalContext& local_context,
HeapVector<CSSProperty, 256>& properties) {
return CSSPropertyParserHelpers::ConsumeShorthandGreedilyViaLonghandAPIs(
webkitTextEmphasisShorthand(), important, context, range, properties);
}
} // 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