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 #ifndef CSSPropertyPositionUtils_h |
| 5 #define CSSPropertyPositionUtils_h |
| 6 |
| 7 #include "core/CSSValueKeywords.h" |
| 8 #include "core/css/parser/CSSParserMode.h" |
| 9 |
| 10 #include "wtf/Allocator.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 class CSSParserTokenRange; |
| 15 class CSSValue; |
| 16 |
| 17 class CSSPropertyPositionUtils { |
| 18 STATIC_ONLY(CSSPropertyPositionUtils); |
| 19 |
| 20 template <CSSValueID start, CSSValueID end> |
| 21 static CSSValue* consumePositionLonghand(CSSParserTokenRange& range, |
| 22 CSSParserMode cssParserMode) { |
| 23 if (range.peek().type() == IdentToken) { |
| 24 CSSValueID id = range.peek().id(); |
| 25 int percent; |
| 26 if (id == start) |
| 27 percent = 0; |
| 28 else if (id == CSSValueCenter) |
| 29 percent = 50; |
| 30 else if (id == end) |
| 31 percent = 100; |
| 32 else |
| 33 return nullptr; |
| 34 range.consumeIncludingWhitespace(); |
| 35 return CSSPrimitiveValue::create(percent, |
| 36 CSSPrimitiveValue::UnitType::Percentage); |
| 37 } |
| 38 return CSSPropertyParserHelpers::consumeLengthOrPercent( |
| 39 range, cssParserMode, ValueRangeAll); |
| 40 } |
| 41 }; |
| 42 |
| 43 } // namespace blink |
| 44 |
| 45 #endif // CSSPropertyPositionUtils_h |
OLD | NEW |