OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/css/properties/CSSPropertyAPIClip.h" |
| 6 |
| 7 #include "core/css/CSSQuadValue.h" |
| 8 #include "core/css/parser/CSSParserContext.h" |
| 9 #include "core/css/parser/CSSPropertyParserHelpers.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 namespace { |
| 14 |
| 15 CSSValue* consumeClipComponent(CSSParserTokenRange& range, |
| 16 CSSParserMode cssParserMode) { |
| 17 if (range.peek().id() == CSSValueAuto) |
| 18 return CSSPropertyParserHelpers::consumeIdent(range); |
| 19 return CSSPropertyParserHelpers::consumeLength( |
| 20 range, cssParserMode, ValueRangeAll, |
| 21 CSSPropertyParserHelpers::UnitlessQuirk::Allow); |
| 22 } |
| 23 } |
| 24 |
| 25 const CSSValue* CSSPropertyAPIClip::parseSingleValue( |
| 26 CSSParserTokenRange& range, |
| 27 const CSSParserContext& context) { |
| 28 if (range.peek().id() == CSSValueAuto) |
| 29 return CSSPropertyParserHelpers::consumeIdent(range); |
| 30 |
| 31 if (range.peek().functionId() != CSSValueRect) |
| 32 return nullptr; |
| 33 |
| 34 CSSParserTokenRange args = CSSPropertyParserHelpers::consumeFunction(range); |
| 35 // rect(t, r, b, l) || rect(t r b l) |
| 36 CSSValue* top = consumeClipComponent(args, context.mode()); |
| 37 if (!top) |
| 38 return nullptr; |
| 39 bool needsComma = |
| 40 CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(args); |
| 41 CSSValue* right = consumeClipComponent(args, context.mode()); |
| 42 if (!right || |
| 43 (needsComma && |
| 44 !CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(args))) |
| 45 return nullptr; |
| 46 CSSValue* bottom = consumeClipComponent(args, context.mode()); |
| 47 if (!bottom || |
| 48 (needsComma && |
| 49 !CSSPropertyParserHelpers::consumeCommaIncludingWhitespace(args))) |
| 50 return nullptr; |
| 51 CSSValue* left = consumeClipComponent(args, context.mode()); |
| 52 if (!left || !args.atEnd()) |
| 53 return nullptr; |
| 54 return CSSQuadValue::create(top, right, bottom, left, |
| 55 CSSQuadValue::SerializeAsRect); |
| 56 } |
| 57 |
| 58 } // namespace blink |
OLD | NEW |