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

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

Issue 2867883003: [CSS Typed OM] Delete obsolete number and length classes from Typed OM (Closed)
Patch Set: rebase Created 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/css/cssom/CSSLengthValue.h"
6
7 #include "bindings/core/v8/ExceptionState.h"
8 #include "core/css/CSSPrimitiveValue.h"
9 #include "core/css/cssom/CSSCalcDictionary.h"
10 #include "core/css/cssom/CSSCalcLength.h"
11 #include "core/css/cssom/CSSSimpleLength.h"
12 #include "platform/wtf/HashMap.h"
13
14 namespace blink {
15
16 CSSPrimitiveValue::UnitType CSSLengthValue::UnitFromName(const String& name) {
17 if (EqualIgnoringASCIICase(name, "percent") || name == "%")
18 return CSSPrimitiveValue::UnitType::kPercentage;
19 return CSSPrimitiveValue::StringToUnitType(name);
20 }
21
22 CSSLengthValue* CSSLengthValue::FromCSSValue(const CSSPrimitiveValue& value) {
23 if (value.IsCalculated()) {
24 // TODO(meade): Implement CSSCalcLength::FromCSSValue.
25 return nullptr;
26 }
27 return CSSSimpleLength::FromCSSValue(value);
28 }
29
30 CSSLengthValue* CSSLengthValue::from(const String& css_text,
31 ExceptionState& exception_state) {
32 // TODO: Implement
33 return nullptr;
34 }
35
36 CSSLengthValue* CSSLengthValue::from(double value,
37 const String& type,
38 ExceptionState&) {
39 return CSSSimpleLength::Create(value, UnitFromName(type));
40 }
41
42 CSSLengthValue* CSSLengthValue::from(const CSSCalcDictionary& dictionary,
43 ExceptionState& exception_state) {
44 return CSSCalcLength::Create(dictionary, exception_state);
45 }
46
47 CSSLengthValue* CSSLengthValue::add(const CSSLengthValue* other) {
48 if (GetType() == kCalcLengthType)
49 return AddInternal(other);
50
51 DCHECK_EQ(GetType(), kSimpleLengthType);
52 if (other->GetType() == kSimpleLengthType &&
53 ToCSSSimpleLength(this)->unit() == ToCSSSimpleLength(other)->unit()) {
54 return AddInternal(other);
55 }
56
57 // TODO(meade): This CalcLength is immediately thrown away. We might want
58 // to optimize this at some point.
59 CSSCalcLength* result = CSSCalcLength::Create(this);
60 return result->add(other);
61 }
62
63 CSSLengthValue* CSSLengthValue::subtract(const CSSLengthValue* other) {
64 if (GetType() == kCalcLengthType)
65 return SubtractInternal(other);
66
67 DCHECK_EQ(GetType(), kSimpleLengthType);
68 if (other->GetType() == kSimpleLengthType &&
69 ToCSSSimpleLength(this)->unit() == ToCSSSimpleLength(other)->unit()) {
70 return SubtractInternal(other);
71 }
72
73 CSSCalcLength* result = CSSCalcLength::Create(this);
74 return result->subtract(other);
75 }
76
77 CSSLengthValue* CSSLengthValue::multiply(double x) {
78 return MultiplyInternal(x);
79 }
80
81 CSSLengthValue* CSSLengthValue::divide(double x,
82 ExceptionState& exception_state) {
83 if (x == 0) {
84 exception_state.ThrowRangeError("Cannot divide by zero");
85 return nullptr;
86 }
87 return DivideInternal(x);
88 }
89
90 CSSLengthValue* CSSLengthValue::AddInternal(const CSSLengthValue*) {
91 NOTREACHED();
92 return nullptr;
93 }
94
95 CSSLengthValue* CSSLengthValue::SubtractInternal(const CSSLengthValue*) {
96 NOTREACHED();
97 return nullptr;
98 }
99
100 CSSLengthValue* CSSLengthValue::MultiplyInternal(double) {
101 NOTREACHED();
102 return nullptr;
103 }
104
105 CSSLengthValue* CSSLengthValue::DivideInternal(double) {
106 NOTREACHED();
107 return nullptr;
108 }
109
110 } // 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/CSSLengthValue.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698