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

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

Issue 2011833002: Typed CSSOM: Rename CalcLength and StyleCalcLength to CSSCalcLength (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/StyleCalcLength.h" 5 #include "core/css/cssom/CSSCalcLength.h"
6 6
7 #include "core/css/CSSCalculationValue.h" 7 #include "core/css/CSSCalculationValue.h"
8 #include "core/css/CSSPrimitiveValue.h" 8 #include "core/css/CSSPrimitiveValue.h"
9 #include "core/css/cssom/CSSSimpleLength.h" 9 #include "core/css/cssom/CSSSimpleLength.h"
10 #include "core/css/cssom/CalcDictionary.h" 10 #include "core/css/cssom/CalcDictionary.h"
11 #include "wtf/Vector.h" 11 #include "wtf/Vector.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 StyleCalcLength::StyleCalcLength() : m_values(CSSLengthValue::kNumSupportedUnits ), m_hasValues(CSSLengthValue::kNumSupportedUnits) {} 15 CSSCalcLength::CSSCalcLength() : m_values(CSSLengthValue::kNumSupportedUnits), m _hasValues(CSSLengthValue::kNumSupportedUnits) {}
16 16
17 StyleCalcLength::StyleCalcLength(const StyleCalcLength& other) : 17 CSSCalcLength::CSSCalcLength(const CSSCalcLength& other) :
18 m_values(other.m_values), 18 m_values(other.m_values),
19 m_hasValues(other.m_hasValues) 19 m_hasValues(other.m_hasValues)
20 {} 20 {}
21 21
22 StyleCalcLength::StyleCalcLength(const CSSSimpleLength& other) : 22 CSSCalcLength::CSSCalcLength(const CSSSimpleLength& other) :
23 m_values(CSSLengthValue::kNumSupportedUnits), m_hasValues(CSSLengthValue::kN umSupportedUnits) 23 m_values(CSSLengthValue::kNumSupportedUnits), m_hasValues(CSSLengthValue::kN umSupportedUnits)
24 { 24 {
25 set(other.value(), other.lengthUnit()); 25 set(other.value(), other.lengthUnit());
26 } 26 }
27 27
28 StyleCalcLength* StyleCalcLength::create(const CSSLengthValue* length) 28 CSSCalcLength* CSSCalcLength::create(const CSSLengthValue* length)
29 { 29 {
30 if (length->type() == SimpleLengthType) { 30 if (length->type() == SimpleLengthType) {
31 const CSSSimpleLength* simpleLength = toCSSSimpleLength(length); 31 const CSSSimpleLength* simpleLength = toCSSSimpleLength(length);
32 return new StyleCalcLength(*simpleLength); 32 return new CSSCalcLength(*simpleLength);
33 } 33 }
34 34
35 return new StyleCalcLength(*toStyleCalcLength(length)); 35 return new CSSCalcLength(*toCSSCalcLength(length));
36 } 36 }
37 37
38 StyleCalcLength* StyleCalcLength::create(const CalcDictionary& dictionary, Excep tionState& exceptionState) 38 CSSCalcLength* CSSCalcLength::create(const CalcDictionary& dictionary, Exception State& exceptionState)
39 { 39 {
40 StyleCalcLength* result = new StyleCalcLength(); 40 CSSCalcLength* result = new CSSCalcLength();
41 int numSet = 0; 41 int numSet = 0;
42 42
43 #define setFromDictValue(name, camelName, primitiveName) \ 43 #define setFromDictValue(name, camelName, primitiveName) \
44 if (dictionary.has##camelName()) { \ 44 if (dictionary.has##camelName()) { \
45 result->set(dictionary.name(), CSSPrimitiveValue::UnitType::primitiveNam e); \ 45 result->set(dictionary.name(), CSSPrimitiveValue::UnitType::primitiveNam e); \
46 numSet++; \ 46 numSet++; \
47 } 47 }
48 48
49 setFromDictValue(px, Px, Pixels) 49 setFromDictValue(px, Px, Pixels)
50 setFromDictValue(percent, Percent, Percentage) 50 setFromDictValue(percent, Percent, Percentage)
51 setFromDictValue(em, Em, Ems) 51 setFromDictValue(em, Em, Ems)
52 setFromDictValue(ex, Ex, Exs) 52 setFromDictValue(ex, Ex, Exs)
53 setFromDictValue(ch, Ch, Chs) 53 setFromDictValue(ch, Ch, Chs)
54 setFromDictValue(rem, Rem, Rems) 54 setFromDictValue(rem, Rem, Rems)
55 setFromDictValue(vw, Vw, ViewportWidth) 55 setFromDictValue(vw, Vw, ViewportWidth)
56 setFromDictValue(vh, Vh, ViewportHeight) 56 setFromDictValue(vh, Vh, ViewportHeight)
57 setFromDictValue(vmin, Vmin, ViewportMin) 57 setFromDictValue(vmin, Vmin, ViewportMin)
58 setFromDictValue(vmax, Vmax, ViewportMax) 58 setFromDictValue(vmax, Vmax, ViewportMax)
59 setFromDictValue(cm, Cm, Centimeters) 59 setFromDictValue(cm, Cm, Centimeters)
60 setFromDictValue(mm, Mm, Millimeters) 60 setFromDictValue(mm, Mm, Millimeters)
61 setFromDictValue(in, In, Inches) 61 setFromDictValue(in, In, Inches)
62 setFromDictValue(pc, Pc, Picas) 62 setFromDictValue(pc, Pc, Picas)
63 setFromDictValue(pt, Pt, Points) 63 setFromDictValue(pt, Pt, Points)
64 64
65 if (numSet == 0) { 65 if (numSet == 0) {
66 exceptionState.throwTypeError("Must specify at least one value in CalcDi ctionary for creating a CalcLength."); 66 exceptionState.throwTypeError("Must specify at least one value in CalcDi ctionary for creating a CSSCalcLength.");
67 } 67 }
68 return result; 68 return result;
69 } 69 }
70 70
71 bool StyleCalcLength::containsPercent() const 71 bool CSSCalcLength::containsPercent() const
72 { 72 {
73 return has(CSSPrimitiveValue::UnitType::Percentage); 73 return has(CSSPrimitiveValue::UnitType::Percentage);
74 } 74 }
75 75
76 CSSLengthValue* StyleCalcLength::addInternal(const CSSLengthValue* other, Except ionState& exceptionState) 76 CSSLengthValue* CSSCalcLength::addInternal(const CSSLengthValue* other, Exceptio nState& exceptionState)
77 { 77 {
78 StyleCalcLength* result = StyleCalcLength::create(other, exceptionState); 78 CSSCalcLength* result = CSSCalcLength::create(other, exceptionState);
79 for (int i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { 79 for (int i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) {
80 if (hasAtIndex(i)) { 80 if (hasAtIndex(i)) {
81 result->setAtIndex(getAtIndex(i) + result->getAtIndex(i), i); 81 result->setAtIndex(getAtIndex(i) + result->getAtIndex(i), i);
82 } 82 }
83 } 83 }
84 return result; 84 return result;
85 } 85 }
86 86
87 CSSLengthValue* StyleCalcLength::subtractInternal(const CSSLengthValue* other, E xceptionState& exceptionState) 87 CSSLengthValue* CSSCalcLength::subtractInternal(const CSSLengthValue* other, Exc eptionState& exceptionState)
88 { 88 {
89 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState); 89 CSSCalcLength* result = CSSCalcLength::create(this, exceptionState);
90 if (other->type() == CalcLengthType) { 90 if (other->type() == CalcLengthType) {
91 const StyleCalcLength* o = toStyleCalcLength(other); 91 const CSSCalcLength* o = toCSSCalcLength(other);
92 for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { 92 for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) {
93 if (o->hasAtIndex(i)) { 93 if (o->hasAtIndex(i)) {
94 result->setAtIndex(getAtIndex(i) - o->getAtIndex(i), i); 94 result->setAtIndex(getAtIndex(i) - o->getAtIndex(i), i);
95 } 95 }
96 } 96 }
97 } else { 97 } else {
98 const CSSSimpleLength* o = toCSSSimpleLength(other); 98 const CSSSimpleLength* o = toCSSSimpleLength(other);
99 result->set(get(o->lengthUnit()) - o->value(), o->lengthUnit()); 99 result->set(get(o->lengthUnit()) - o->value(), o->lengthUnit());
100 } 100 }
101 return result; 101 return result;
102 } 102 }
103 103
104 CSSLengthValue* StyleCalcLength::multiplyInternal(double x, ExceptionState& exce ptionState) 104 CSSLengthValue* CSSCalcLength::multiplyInternal(double x, ExceptionState& except ionState)
105 { 105 {
106 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState); 106 CSSCalcLength* result = CSSCalcLength::create(this, exceptionState);
107 for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { 107 for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) {
108 if (hasAtIndex(i)) { 108 if (hasAtIndex(i)) {
109 result->setAtIndex(getAtIndex(i) * x, i); 109 result->setAtIndex(getAtIndex(i) * x, i);
110 } 110 }
111 } 111 }
112 return result; 112 return result;
113 } 113 }
114 114
115 CSSLengthValue* StyleCalcLength::divideInternal(double x, ExceptionState& except ionState) 115 CSSLengthValue* CSSCalcLength::divideInternal(double x, ExceptionState& exceptio nState)
116 { 116 {
117 StyleCalcLength* result = StyleCalcLength::create(this, exceptionState); 117 CSSCalcLength* result = CSSCalcLength::create(this, exceptionState);
118 for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { 118 for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) {
119 if (hasAtIndex(i)) { 119 if (hasAtIndex(i)) {
120 result->setAtIndex(getAtIndex(i) / x, i); 120 result->setAtIndex(getAtIndex(i) / x, i);
121 } 121 }
122 } 122 }
123 return result; 123 return result;
124 } 124 }
125 125
126 CSSValue* StyleCalcLength::toCSSValue() const 126 CSSValue* CSSCalcLength::toCSSValue() const
127 { 127 {
128 // Create a CSS Calc Value, then put it into a CSSPrimitiveValue 128 // Create a CSS Calc Value, then put it into a CSSPrimitiveValue
129 CSSCalcExpressionNode* node = nullptr; 129 CSSCalcExpressionNode* node = nullptr;
130 for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) { 130 for (unsigned i = 0; i < CSSLengthValue::kNumSupportedUnits; ++i) {
131 if (!hasAtIndex(i)) 131 if (!hasAtIndex(i))
132 continue; 132 continue;
133 double value = getAtIndex(i); 133 double value = getAtIndex(i);
134 if (node) { 134 if (node) {
135 node = CSSCalcValue::createExpressionNode( 135 node = CSSCalcValue::createExpressionNode(
136 node, 136 node,
137 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(std ::abs(value), unitFromIndex(i))), 137 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(std ::abs(value), unitFromIndex(i))),
138 value >= 0 ? CalcAdd : CalcSubtract); 138 value >= 0 ? CalcAdd : CalcSubtract);
139 } else { 139 } else {
140 node = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create( value, unitFromIndex(i))); 140 node = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create( value, unitFromIndex(i)));
141 } 141 }
142 } 142 }
143 return CSSPrimitiveValue::create(CSSCalcValue::create(node)); 143 return CSSPrimitiveValue::create(CSSCalcValue::create(node));
144 } 144 }
145 145
146 int StyleCalcLength::indexForUnit(CSSPrimitiveValue::UnitType unit) 146 int CSSCalcLength::indexForUnit(CSSPrimitiveValue::UnitType unit)
147 { 147 {
148 return (static_cast<int>(unit) - static_cast<int>(CSSPrimitiveValue::UnitTyp e::Percentage)); 148 return (static_cast<int>(unit) - static_cast<int>(CSSPrimitiveValue::UnitTyp e::Percentage));
149 } 149 }
150 150
151 } // namespace blink 151 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/cssom/CSSCalcLength.h ('k') | third_party/WebKit/Source/core/css/cssom/CSSCalcLength.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698