Commit 51446e5d authored by Jia's avatar Jia Committed by Commit Bot

Implement ConsumeShorthandVia4LonghandsAPI in CSSPropertyParserHelpers.

The new function ConsumeShorthandVia4LonghandsAPI is a modified version
of Consume4Values of CSSPropertyParser. They both parse shorthands 
consisting of 4 longhands (top, right, bottom, left). The difference
between this new version and the old/existing Consume4Values 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.

This cl contains one change only, i.e. the impl of 
ConsumeShorthandVia4LonghandsAPI. This cl is also a use case of
ParseLonghandViaAPI. The next cl will have a shorthand API impl
that will use ConsumeShorthandVia4LonghandsAPI.

Bug: 668012
Change-Id: I9a638d9c654a1bb734b60dccadaf2c52ddd761f0
Reviewed-on: https://chromium-review.googlesource.com/560920
Commit-Queue: Jia Meng <jiameng@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarDarren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485175}
parent 11353980
......@@ -1581,6 +1581,58 @@ const CSSValue* ParseLonghandViaAPI(CSSPropertyID unresolved_property,
return nullptr;
}
bool ConsumeShorthandVia4LonghandsAPI(
const StylePropertyShorthand& shorthand,
bool important,
const CSSParserContext& context,
CSSParserTokenRange& range,
HeapVector<CSSProperty, 256>& properties) {
DCHECK_EQ(shorthand.length(), 4u);
const CSSPropertyID* longhands = shorthand.properties();
bool needs_legacy_parsing = false;
const CSSValue* top = ParseLonghandViaAPI(
longhands[0], shorthand.id(), context, range, needs_legacy_parsing);
DCHECK(!needs_legacy_parsing);
if (!top)
return false;
const CSSValue* right = ParseLonghandViaAPI(
longhands[1], shorthand.id(), context, range, needs_legacy_parsing);
DCHECK(!needs_legacy_parsing);
const CSSValue* bottom = nullptr;
const CSSValue* left = nullptr;
if (right) {
bottom = ParseLonghandViaAPI(longhands[2], shorthand.id(), context, range,
needs_legacy_parsing);
DCHECK(!needs_legacy_parsing);
if (bottom) {
left = ParseLonghandViaAPI(longhands[3], shorthand.id(), context, range,
needs_legacy_parsing);
DCHECK(!needs_legacy_parsing);
}
}
if (!right)
right = top;
if (!bottom)
bottom = top;
if (!left)
left = right;
AddProperty(longhands[0], shorthand.id(), *top, important,
IsImplicitProperty::kNotImplicit, properties);
AddProperty(longhands[1], shorthand.id(), *right, important,
IsImplicitProperty::kNotImplicit, properties);
AddProperty(longhands[2], shorthand.id(), *bottom, important,
IsImplicitProperty::kNotImplicit, properties);
AddProperty(longhands[3], shorthand.id(), *left, important,
IsImplicitProperty::kNotImplicit, properties);
return range.AtEnd();
}
} // namespace CSSPropertyParserHelpers
} // namespace blink
......@@ -23,6 +23,7 @@ class CSSProperty;
class CSSStringValue;
class CSSURIValue;
class CSSValuePair;
class StylePropertyShorthand;
// When these functions are successful, they will consume all the relevant
// tokens from the range and also consume any whitespace which follows. When
......@@ -130,6 +131,12 @@ const CSSValue* ParseLonghandViaAPI(CSSPropertyID unresolved_property,
CSSParserTokenRange&,
bool& needs_legacy_parsing);
bool ConsumeShorthandVia4LonghandsAPI(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>
......
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