Chromium Code Reviews| Index: third_party/WebKit/Source/core/css/properties/CSSPropertyAPIClip.cpp |
| diff --git a/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIClip.cpp b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIClip.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..882cf110d4ab29b308f89f80609cc37c3166525b |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/css/properties/CSSPropertyAPIClip.cpp |
| @@ -0,0 +1,57 @@ |
| +// Copyright 2016 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/CSSPropertyAPIClip.h" |
| + |
| +#include "core/css/CSSQuadValue.h" |
| +#include "core/css/CSSValueList.h" |
| +#include "core/css/parser/CSSParserTokenRange.h" |
| +#include "core/css/parser/CSSPropertyParser.h" |
| +#include "core/css/parser/CSSPropertyParserHelpers.h" |
| + |
| +namespace blink { |
| + |
| +static CSSValue* consumeClipComponent(CSSParserTokenRange& range, |
|
meade_UTC10
2017/01/05 04:10:22
You could make this helper method more private by
|
| + CSSParserMode cssParserMode) { |
| + if (range.peek().id() == CSSValueAuto) |
| + return CSSPropertyParserHelpers::consumeIdent(range); |
| + return CSSPropertyParserHelpers::consumeLength( |
| + range, cssParserMode, ValueRangeAll, |
| + CSSPropertyParserHelpers::UnitlessQuirk::Allow); |
| +} |
| + |
| +const CSSValue* CSSPropertyAPIClip::parseSingleValue( |
| + CSSParserTokenRange& range, |
| + const CSSParserContext& context) { |
| + if (range.peek().id() == CSSValueAuto) |
| + return CSSPropertyParserHelpers::consumeIdent(range); |
| + |
| + if (range.peek().functionId() != CSSValueRect) |
| + return nullptr; |
| + |
| + CSSParserTokenRange args = CSSPropertyParserHelpers::consumeFunction(range); |
| + // rect(t, r, b, l) || rect(t r b l) |
| + CSSValue* top = consumeClipComponent(args, context.mode()); |
| + if (!top) |
| + return nullptr; |
| + bool needsComma = |
| + CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(args); |
| + CSSValue* right = consumeClipComponent(args, context.mode()); |
| + if (!right || |
| + (needsComma && |
| + !CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(args))) |
| + return nullptr; |
| + CSSValue* bottom = consumeClipComponent(args, context.mode()); |
| + if (!bottom || |
| + (needsComma && |
| + !CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(args))) |
| + return nullptr; |
| + CSSValue* left = consumeClipComponent(args, context.mode()); |
| + if (!left || !args.atEnd()) |
| + return nullptr; |
| + return CSSQuadValue::create(top, right, bottom, left, |
| + CSSQuadValue::SerializeAsRect); |
| +} |
| + |
| +} // namespace blink |