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

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

Issue 1689573002: CSS Typed OM: asMatrix for TransformComponent with LengthValue types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@asMatrixMethod
Patch Set: Add in Translation and use exceptionState.hadException Created 4 years, 10 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/LengthValue.h" 5 #include "core/css/cssom/LengthValue.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "core/css/CSSPrimitiveValue.h"
9 #include "core/css/CSSToLengthConversionData.h"
8 #include "core/css/cssom/CalcDictionary.h" 10 #include "core/css/cssom/CalcDictionary.h"
9 #include "core/css/cssom/SimpleLength.h" 11 #include "core/css/cssom/SimpleLength.h"
10 #include "core/css/cssom/StyleCalcLength.h" 12 #include "core/css/cssom/StyleCalcLength.h"
13 #include "core/style/ComputedStyle.h"
11 #include "wtf/HashMap.h" 14 #include "wtf/HashMap.h"
12 15
13 namespace blink { 16 namespace blink {
14 17
15 CSSPrimitiveValue::UnitType LengthValue::unitFromName(const String& name) 18 CSSPrimitiveValue::UnitType LengthValue::unitFromName(const String& name)
16 { 19 {
17 if (equalIgnoringASCIICase(name, "percent") || name == "%") { 20 if (equalIgnoringASCIICase(name, "percent") || name == "%") {
18 return CSSPrimitiveValue::UnitType::Percentage; 21 return CSSPrimitiveValue::UnitType::Percentage;
19 } 22 }
20 return CSSPrimitiveValue::fromName(name); 23 return CSSPrimitiveValue::fromName(name);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 LengthValue* LengthValue::multiply(double x, ExceptionState& exceptionState) 60 LengthValue* LengthValue::multiply(double x, ExceptionState& exceptionState)
58 { 61 {
59 return multiplyInternal(x, exceptionState); 62 return multiplyInternal(x, exceptionState);
60 } 63 }
61 64
62 LengthValue* LengthValue::divide(double x, ExceptionState& exceptionState) 65 LengthValue* LengthValue::divide(double x, ExceptionState& exceptionState)
63 { 66 {
64 return divideInternal(x, exceptionState); 67 return divideInternal(x, exceptionState);
65 } 68 }
66 69
70 double LengthValue::computeLengthPx(ExceptionState& exceptionState) const
71 {
72 if (isRelative()) {
73 // TODO: Resolve relative units to a pixel value.
74 exceptionState.throwTypeError("Cannot resolve a relative unit to a pixel value.");
75 return 0;
76 }
77
78 CSSValue* cssValue = toCSSValue();
79 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(cssValue);
80 ComputedStyle* computedStyle = const_cast<ComputedStyle*>(ComputedStyle::cre ate().get());
81 CSSToLengthConversionData conversionData = CSSToLengthConversionData(compute dStyle,
82 CSSToLengthConversionData::FontSizes(), CSSToLengthConversionData::Viewp ortSize(), 1);
83
84 return primitiveValue->CSSPrimitiveValue::computeLength<double>(conversionDa ta);
85 }
86
67 LengthValue* LengthValue::addInternal(const LengthValue*, ExceptionState&) 87 LengthValue* LengthValue::addInternal(const LengthValue*, ExceptionState&)
68 { 88 {
69 ASSERT_NOT_REACHED(); 89 ASSERT_NOT_REACHED();
70 return nullptr; 90 return nullptr;
71 } 91 }
72 92
73 LengthValue* LengthValue::subtractInternal(const LengthValue*, ExceptionState&) 93 LengthValue* LengthValue::subtractInternal(const LengthValue*, ExceptionState&)
74 { 94 {
75 ASSERT_NOT_REACHED(); 95 ASSERT_NOT_REACHED();
76 return nullptr; 96 return nullptr;
77 } 97 }
78 98
79 LengthValue* LengthValue::multiplyInternal(double, ExceptionState&) 99 LengthValue* LengthValue::multiplyInternal(double, ExceptionState&)
80 { 100 {
81 ASSERT_NOT_REACHED(); 101 ASSERT_NOT_REACHED();
82 return nullptr; 102 return nullptr;
83 } 103 }
84 104
85 LengthValue* LengthValue::divideInternal(double, ExceptionState&) 105 LengthValue* LengthValue::divideInternal(double, ExceptionState&)
86 { 106 {
87 ASSERT_NOT_REACHED(); 107 ASSERT_NOT_REACHED();
88 return nullptr; 108 return nullptr;
89 } 109 }
90 110
91 } // namespace blink 111 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698