OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/css/cssom/CSSLengthValue.h" | 5 #include "core/css/cssom/CSSLengthValue.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
8 #include "core/css/CSSPrimitiveValueUnitTrie.h" | 8 #include "core/css/CSSPrimitiveValueUnitTrie.h" |
9 #include "core/css/cssom/CSSCalcLength.h" | 9 #include "core/css/cssom/CSSCalcLength.h" |
10 #include "core/css/cssom/CSSSimpleLength.h" | 10 #include "core/css/cssom/CSSSimpleLength.h" |
11 #include "core/css/cssom/CalcDictionary.h" | 11 #include "core/css/cssom/CalcDictionary.h" |
12 #include "wtf/HashMap.h" | 12 #include "wtf/HashMap.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
| 16 CSSLengthValue* CSSLengthValue::fromCSSValue(const CSSValue& value) |
| 17 { |
| 18 if (!value.isPrimitiveValue()) |
| 19 return nullptr; |
| 20 |
| 21 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); |
| 22 if (!primitiveValue.isLength()) |
| 23 return nullptr; |
| 24 |
| 25 if (!primitiveValue.isCalculated()) |
| 26 return CSSSimpleLength::create(primitiveValue.getDoubleValue(), primitiv
eValue.typeWithCalcResolved()); |
| 27 |
| 28 return CSSCalcLength::fromCSSValue(value); |
| 29 } |
| 30 |
16 CSSPrimitiveValue::UnitType CSSLengthValue::unitFromName(const String& name) | 31 CSSPrimitiveValue::UnitType CSSLengthValue::unitFromName(const String& name) |
17 { | 32 { |
18 if (equalIgnoringASCIICase(name, "percent") || name == "%") { | 33 if (equalIgnoringASCIICase(name, "percent") || name == "%") { |
19 return CSSPrimitiveValue::UnitType::Percentage; | 34 return CSSPrimitiveValue::UnitType::Percentage; |
20 } | 35 } |
21 if (name.is8Bit()) | 36 if (name.is8Bit()) |
22 return lookupCSSPrimitiveValueUnit(name.characters8(), name.length()); | 37 return lookupCSSPrimitiveValueUnit(name.characters8(), name.length()); |
23 return lookupCSSPrimitiveValueUnit(name.characters16(), name.length()); | 38 return lookupCSSPrimitiveValueUnit(name.characters16(), name.length()); |
24 } | 39 } |
25 | 40 |
(...skipping 24 matching lines...) Expand all Loading... |
50 | 65 |
51 CSSLengthValue* CSSLengthValue::subtract(const CSSLengthValue* other, ExceptionS
tate& exceptionState) | 66 CSSLengthValue* CSSLengthValue::subtract(const CSSLengthValue* other, ExceptionS
tate& exceptionState) |
52 { | 67 { |
53 if (type() == other->type() || type() == CalcLengthType) | 68 if (type() == other->type() || type() == CalcLengthType) |
54 return subtractInternal(other, exceptionState); | 69 return subtractInternal(other, exceptionState); |
55 | 70 |
56 CSSCalcLength* result = CSSCalcLength::create(this, exceptionState); | 71 CSSCalcLength* result = CSSCalcLength::create(this, exceptionState); |
57 return result->subtract(other, exceptionState); | 72 return result->subtract(other, exceptionState); |
58 } | 73 } |
59 | 74 |
60 CSSLengthValue* CSSLengthValue::multiply(double x, ExceptionState& exceptionStat
e) | 75 CSSLengthValue* CSSLengthValue::multiply(double x, ExceptionState&) |
61 { | 76 { |
62 return multiplyInternal(x, exceptionState); | 77 return multiplyInternal(x); |
63 } | 78 } |
64 | 79 |
65 CSSLengthValue* CSSLengthValue::divide(double x, ExceptionState& exceptionState) | 80 CSSLengthValue* CSSLengthValue::divide(double x, ExceptionState&) |
66 { | 81 { |
67 return divideInternal(x, exceptionState); | 82 return divideInternal(x); |
68 } | 83 } |
69 | 84 |
70 CSSLengthValue* CSSLengthValue::addInternal(const CSSLengthValue*, ExceptionStat
e&) | 85 CSSLengthValue* CSSLengthValue::addInternal(const CSSLengthValue*, ExceptionStat
e&) |
71 { | 86 { |
72 NOTREACHED(); | 87 NOTREACHED(); |
73 return nullptr; | 88 return nullptr; |
74 } | 89 } |
75 | 90 |
76 CSSLengthValue* CSSLengthValue::subtractInternal(const CSSLengthValue*, Exceptio
nState&) | 91 CSSLengthValue* CSSLengthValue::subtractInternal(const CSSLengthValue*, Exceptio
nState&) |
77 { | 92 { |
78 NOTREACHED(); | 93 NOTREACHED(); |
79 return nullptr; | 94 return nullptr; |
80 } | 95 } |
81 | 96 |
82 CSSLengthValue* CSSLengthValue::multiplyInternal(double, ExceptionState&) | 97 CSSLengthValue* CSSLengthValue::multiplyInternal(double) |
83 { | 98 { |
84 NOTREACHED(); | 99 NOTREACHED(); |
85 return nullptr; | 100 return nullptr; |
86 } | 101 } |
87 | 102 |
88 CSSLengthValue* CSSLengthValue::divideInternal(double, ExceptionState&) | 103 CSSLengthValue* CSSLengthValue::divideInternal(double) |
89 { | 104 { |
90 NOTREACHED(); | 105 NOTREACHED(); |
91 return nullptr; | 106 return nullptr; |
92 } | 107 } |
93 | 108 |
94 } // namespace blink | 109 } // namespace blink |
OLD | NEW |