Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: third_party/WebKit/Source/core/css/cssom/CSSLengthValue.cpp

Issue 2047923002: [WIP] Add support for CSSValue-> CSSLengthValue and CSSTranslation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@supported-types
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/cssom/CSSLengthValue.h ('k') | third_party/WebKit/Source/core/css/cssom/CSSSimpleLength.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698