| Index: third_party/WebKit/Source/core/css/properties/CSSPropertyBackgroundComponentUtils.cpp
|
| diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyBackgroundComponentUtils.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyBackgroundComponentUtils.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ba5ddfa51695055b46abed4a20dc73d0361b426b
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyBackgroundComponentUtils.cpp
|
| @@ -0,0 +1,162 @@
|
| +// 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/CSSPropertyBackgroundComponentUtils.h"
|
| +
|
| +#include "core/css/CSSValueList.h"
|
| +#include "core/css/CSSValuePair.h"
|
| +#include "core/css/parser/CSSPropertyParserHelpers.h"
|
| +#include "core/css/properties/CSSPropertyPositionUtils.h"
|
| +#include "platform/RuntimeEnabledFeatures.h"
|
| +
|
| +namespace blink {
|
| +
|
| +namespace {
|
| +
|
| +static CSSValue* consumeBackgroundBlendMode(CSSParserTokenRange& range) {
|
| + CSSValueID id = range.peek().id();
|
| + if (id == CSSValueNormal || id == CSSValueOverlay ||
|
| + (id >= CSSValueMultiply && id <= CSSValueLuminosity))
|
| + return CSSPropertyParserHelpers::consumeIdent(range);
|
| + return nullptr;
|
| +}
|
| +
|
| +CSSValue* consumeBackgroundAttachment(CSSParserTokenRange& range) {
|
| + return CSSPropertyParserHelpers::consumeIdent<CSSValueScroll, CSSValueFixed,
|
| + CSSValueLocal>(range);
|
| +}
|
| +
|
| +CSSValue* consumeBackgroundBox(CSSParserTokenRange& range) {
|
| + return CSSPropertyParserHelpers::consumeIdent<
|
| + CSSValueBorderBox, CSSValuePaddingBox, CSSValueContentBox>(range);
|
| +}
|
| +
|
| +CSSValue* consumeBackgroundComposite(CSSParserTokenRange& range) {
|
| + return CSSPropertyParserHelpers::consumeIdentRange(range, CSSValueClear,
|
| + CSSValuePlusLighter);
|
| +}
|
| +
|
| +CSSValue* consumeMaskSourceType(CSSParserTokenRange& range) {
|
| + DCHECK(RuntimeEnabledFeatures::cssMaskSourceTypeEnabled());
|
| + return CSSPropertyParserHelpers::consumeIdent<CSSValueAuto, CSSValueAlpha,
|
| + CSSValueLuminance>(range);
|
| +}
|
| +
|
| +CSSValue* consumePrefixedBackgroundBox(CSSPropertyID property,
|
| + CSSParserTokenRange& range,
|
| + const CSSParserContext* context) {
|
| + // 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 = CSSPropertyParserHelpers::consumeIdentRange(
|
| + range, CSSValueBorder, CSSValuePaddingBox))
|
| + return value;
|
| + if ((property == CSSPropertyWebkitBackgroundClip ||
|
| + property == CSSPropertyWebkitMaskClip) &&
|
| + range.peek().id() == CSSValueText)
|
| + return CSSPropertyParserHelpers::consumeIdent(range);
|
| + return nullptr;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +CSSValue* CSSPropertyBackgroundComponentUtils::consumeBackgroundSize(
|
| + CSSPropertyID unresolvedProperty,
|
| + CSSParserTokenRange& range,
|
| + CSSParserMode cssParserMode) {
|
| + if (CSSPropertyParserHelpers::identMatches<CSSValueContain, CSSValueCover>(
|
| + range.peek().id()))
|
| + return CSSPropertyParserHelpers::consumeIdent(range);
|
| +
|
| + CSSValue* horizontal =
|
| + CSSPropertyParserHelpers::consumeIdent<CSSValueAuto>(range);
|
| + if (!horizontal) {
|
| + horizontal = CSSPropertyParserHelpers::consumeLengthOrPercent(
|
| + range, cssParserMode, ValueRangeAll,
|
| + CSSPropertyParserHelpers::UnitlessQuirk::Forbid);
|
| + }
|
| +
|
| + CSSValue* vertical = nullptr;
|
| + if (!range.atEnd()) {
|
| + if (range.peek().id() == CSSValueAuto) {
|
| + // `auto' is the default
|
| + range.consumeIncludingWhitespace();
|
| + } else {
|
| + vertical = CSSPropertyParserHelpers::consumeLengthOrPercent(
|
| + range, cssParserMode, ValueRangeAll,
|
| + CSSPropertyParserHelpers::UnitlessQuirk::Forbid);
|
| + }
|
| + } else if (unresolvedProperty == CSSPropertyAliasWebkitBackgroundSize) {
|
| + // Legacy syntax: "-webkit-background-size: 10px" is equivalent to
|
| + // "background-size: 10px 10px".
|
| + vertical = horizontal;
|
| + }
|
| + if (!vertical)
|
| + return horizontal;
|
| + return CSSValuePair::create(horizontal, vertical,
|
| + CSSValuePair::KeepIdenticalValues);
|
| +}
|
| +
|
| +void CSSPropertyBackgroundComponentUtils::addBackgroundValue(CSSValue*& list,
|
| + CSSValue* value) {
|
| + if (list) {
|
| + if (!list->isBaseValueList()) {
|
| + CSSValue* firstValue = list;
|
| + list = CSSValueList::createCommaSeparated();
|
| + toCSSValueList(list)->append(*firstValue);
|
| + }
|
| + toCSSValueList(list)->append(*value);
|
| + } else {
|
| + // To conserve memory we don't actually wrap a single value in a list.
|
| + list = value;
|
| + }
|
| +}
|
| +
|
| +CSSValue* CSSPropertyBackgroundComponentUtils::consumeBackgroundComponent(
|
| + CSSPropertyID unresolvedProperty,
|
| + CSSParserTokenRange& range,
|
| + const CSSParserContext* context) {
|
| + switch (unresolvedProperty) {
|
| + case CSSPropertyBackgroundClip:
|
| + return consumeBackgroundBox(range);
|
| + case CSSPropertyBackgroundBlendMode:
|
| + return consumeBackgroundBlendMode(range);
|
| + case CSSPropertyBackgroundAttachment:
|
| + return consumeBackgroundAttachment(range);
|
| + case CSSPropertyBackgroundOrigin:
|
| + return consumeBackgroundBox(range);
|
| + case CSSPropertyWebkitMaskComposite:
|
| + return consumeBackgroundComposite(range);
|
| + case CSSPropertyMaskSourceType:
|
| + return consumeMaskSourceType(range);
|
| + case CSSPropertyWebkitBackgroundClip:
|
| + case CSSPropertyWebkitBackgroundOrigin:
|
| + case CSSPropertyWebkitMaskClip:
|
| + case CSSPropertyWebkitMaskOrigin:
|
| + return consumePrefixedBackgroundBox(unresolvedProperty, range, context);
|
| + case CSSPropertyBackgroundImage:
|
| + case CSSPropertyWebkitMaskImage:
|
| + return CSSPropertyParserHelpers::consumeImageOrNone(range, context);
|
| + case CSSPropertyBackgroundPositionX:
|
| + case CSSPropertyWebkitMaskPositionX:
|
| + return CSSPropertyPositionUtils::consumePositionLonghand<CSSValueLeft,
|
| + CSSValueRight>(
|
| + range, context->mode());
|
| + case CSSPropertyBackgroundPositionY:
|
| + case CSSPropertyWebkitMaskPositionY:
|
| + return CSSPropertyPositionUtils::consumePositionLonghand<CSSValueTop,
|
| + CSSValueBottom>(
|
| + range, context->mode());
|
| + case CSSPropertyBackgroundSize:
|
| + case CSSPropertyAliasWebkitBackgroundSize:
|
| + case CSSPropertyWebkitMaskSize:
|
| + return consumeBackgroundSize(unresolvedProperty, range, context->mode());
|
| + case CSSPropertyBackgroundColor:
|
| + return CSSPropertyParserHelpers::consumeColor(range, context->mode());
|
| + default:
|
| + break;
|
| + };
|
| + return nullptr;
|
| +}
|
| +
|
| +} // namespace blink
|
|
|