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

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

Issue 2382653006: Split CSSPrimitiveValue into CSSPrimitiveValue and CSSIdentifierValue (Closed)
Patch Set: Make check-webkit-style happy Created 4 years, 2 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 /* 1 /*
2 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above 8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following 9 * copyright notice, this list of conditions and the following
10 * disclaimer. 10 * disclaimer.
(...skipping 11 matching lines...) Expand all
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE. 27 * SUCH DAMAGE.
28 */ 28 */
29 29
30 #include "core/css/CSSBasicShapeValues.h" 30 #include "core/css/CSSBasicShapeValues.h"
31 31
32 #include "core/css/CSSIdentifierValue.h"
32 #include "core/css/CSSPrimitiveValue.h" 33 #include "core/css/CSSPrimitiveValue.h"
33 #include "core/css/CSSValuePair.h" 34 #include "core/css/CSSValuePair.h"
34 #include "platform/Length.h" 35 #include "platform/Length.h"
35 #include "wtf/text/StringBuilder.h" 36 #include "wtf/text/StringBuilder.h"
36 37
37 using namespace WTF; 38 using namespace WTF;
38 39
39 namespace blink { 40 namespace blink {
40 41
41 static String buildCircleString(const String& radius, 42 static String buildCircleString(const String& radius,
(...skipping 14 matching lines...) Expand all
56 result.append(centerX); 57 result.append(centerX);
57 result.append(separator); 58 result.append(separator);
58 result.append(centerY); 59 result.append(centerY);
59 } 60 }
60 result.append(')'); 61 result.append(')');
61 return result.toString(); 62 return result.toString();
62 } 63 }
63 64
64 static String serializePositionOffset(const CSSValuePair& offset, 65 static String serializePositionOffset(const CSSValuePair& offset,
65 const CSSValuePair& other) { 66 const CSSValuePair& other) {
66 if ((toCSSPrimitiveValue(offset.first()).getValueID() == CSSValueLeft && 67 if ((toCSSIdentifierValue(offset.first()).getValueID() == CSSValueLeft &&
67 toCSSPrimitiveValue(other.first()).getValueID() == CSSValueTop) || 68 toCSSIdentifierValue(other.first()).getValueID() == CSSValueTop) ||
68 (toCSSPrimitiveValue(offset.first()).getValueID() == CSSValueTop && 69 (toCSSIdentifierValue(offset.first()).getValueID() == CSSValueTop &&
69 toCSSPrimitiveValue(other.first()).getValueID() == CSSValueLeft)) 70 toCSSIdentifierValue(other.first()).getValueID() == CSSValueLeft))
70 return offset.second().cssText(); 71 return offset.second().cssText();
71 return offset.cssText(); 72 return offset.cssText();
72 } 73 }
73 74
74 static CSSValuePair* buildSerializablePositionOffset(CSSValue* offset, 75 static CSSValuePair* buildSerializablePositionOffset(CSSValue* offset,
75 CSSValueID defaultSide) { 76 CSSValueID defaultSide) {
76 CSSValueID side = defaultSide; 77 CSSValueID side = defaultSide;
77 const CSSPrimitiveValue* amount = nullptr; 78 const CSSPrimitiveValue* amount = nullptr;
78 79
79 if (!offset) { 80 if (!offset) {
80 side = CSSValueCenter; 81 side = CSSValueCenter;
81 } else if (offset->isPrimitiveValue() && 82 } else if (offset->isIdentifierValue()) {
82 toCSSPrimitiveValue(offset)->isValueID()) { 83 side = toCSSIdentifierValue(offset)->getValueID();
83 side = toCSSPrimitiveValue(offset)->getValueID();
84 } else if (offset->isValuePair()) { 84 } else if (offset->isValuePair()) {
85 side = toCSSPrimitiveValue(toCSSValuePair(*offset).first()).getValueID(); 85 side = toCSSIdentifierValue(toCSSValuePair(*offset).first()).getValueID();
86 amount = &toCSSPrimitiveValue(toCSSValuePair(*offset).second()); 86 amount = &toCSSPrimitiveValue(toCSSValuePair(*offset).second());
87 if ((side == CSSValueRight || side == CSSValueBottom) && 87 if ((side == CSSValueRight || side == CSSValueBottom) &&
88 amount->isPercentage()) { 88 amount->isPercentage()) {
89 side = defaultSide; 89 side = defaultSide;
90 amount = 90 amount =
91 CSSPrimitiveValue::create(100 - amount->getFloatValue(), 91 CSSPrimitiveValue::create(100 - amount->getFloatValue(),
92 CSSPrimitiveValue::UnitType::Percentage); 92 CSSPrimitiveValue::UnitType::Percentage);
93 } 93 }
94 } else { 94 } else {
95 amount = toCSSPrimitiveValue(offset); 95 amount = toCSSPrimitiveValue(offset);
96 } 96 }
97 97
98 if (side == CSSValueCenter) { 98 if (side == CSSValueCenter) {
99 side = defaultSide; 99 side = defaultSide;
100 amount = 100 amount =
101 CSSPrimitiveValue::create(50, CSSPrimitiveValue::UnitType::Percentage); 101 CSSPrimitiveValue::create(50, CSSPrimitiveValue::UnitType::Percentage);
102 } else if (!amount || (amount->isLength() && !amount->getFloatValue())) { 102 } else if (!amount || (amount->isLength() && !amount->getFloatValue())) {
103 if (side == CSSValueRight || side == CSSValueBottom) 103 if (side == CSSValueRight || side == CSSValueBottom)
104 amount = CSSPrimitiveValue::create( 104 amount = CSSPrimitiveValue::create(
105 100, CSSPrimitiveValue::UnitType::Percentage); 105 100, CSSPrimitiveValue::UnitType::Percentage);
106 else 106 else
107 amount = 107 amount =
108 CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Percentage); 108 CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::Percentage);
109 side = defaultSide; 109 side = defaultSide;
110 } 110 }
111 111
112 return CSSValuePair::create(CSSPrimitiveValue::createIdentifier(side), amount, 112 return CSSValuePair::create(CSSIdentifierValue::create(side), amount,
113 CSSValuePair::KeepIdenticalValues); 113 CSSValuePair::KeepIdenticalValues);
114 } 114 }
115 115
116 String CSSBasicShapeCircleValue::customCSSText() const { 116 String CSSBasicShapeCircleValue::customCSSText() const {
117 CSSValuePair* normalizedCX = 117 CSSValuePair* normalizedCX =
118 buildSerializablePositionOffset(m_centerX, CSSValueLeft); 118 buildSerializablePositionOffset(m_centerX, CSSValueLeft);
119 CSSValuePair* normalizedCY = 119 CSSValuePair* normalizedCY =
120 buildSerializablePositionOffset(m_centerY, CSSValueTop); 120 buildSerializablePositionOffset(m_centerY, CSSValueTop);
121 121
122 String radius; 122 String radius;
123 if (m_radius && m_radius->getValueID() != CSSValueClosestSide) 123 if (m_radius &&
124 !(m_radius->isIdentifierValue() &&
125 toCSSIdentifierValue(*m_radius).getValueID() == CSSValueClosestSide))
124 radius = m_radius->cssText(); 126 radius = m_radius->cssText();
125 127
126 return buildCircleString( 128 return buildCircleString(
127 radius, serializePositionOffset(*normalizedCX, *normalizedCY), 129 radius, serializePositionOffset(*normalizedCX, *normalizedCY),
128 serializePositionOffset(*normalizedCY, *normalizedCX)); 130 serializePositionOffset(*normalizedCY, *normalizedCX));
129 } 131 }
130 132
131 bool CSSBasicShapeCircleValue::equals( 133 bool CSSBasicShapeCircleValue::equals(
132 const CSSBasicShapeCircleValue& other) const { 134 const CSSBasicShapeCircleValue& other) const {
133 return compareCSSValuePtr(m_centerX, other.m_centerX) && 135 return compareCSSValuePtr(m_centerX, other.m_centerX) &&
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 String CSSBasicShapeEllipseValue::customCSSText() const { 180 String CSSBasicShapeEllipseValue::customCSSText() const {
179 CSSValuePair* normalizedCX = 181 CSSValuePair* normalizedCX =
180 buildSerializablePositionOffset(m_centerX, CSSValueLeft); 182 buildSerializablePositionOffset(m_centerX, CSSValueLeft);
181 CSSValuePair* normalizedCY = 183 CSSValuePair* normalizedCY =
182 buildSerializablePositionOffset(m_centerY, CSSValueTop); 184 buildSerializablePositionOffset(m_centerY, CSSValueTop);
183 185
184 String radiusX; 186 String radiusX;
185 String radiusY; 187 String radiusY;
186 if (m_radiusX) { 188 if (m_radiusX) {
187 bool shouldSerializeRadiusXValue = 189 bool shouldSerializeRadiusXValue =
188 m_radiusX->getValueID() != CSSValueClosestSide; 190 !(m_radiusX->isIdentifierValue() &&
191 toCSSIdentifierValue(*m_radiusX).getValueID() == CSSValueClosestSide);
189 bool shouldSerializeRadiusYValue = false; 192 bool shouldSerializeRadiusYValue = false;
190 193
191 if (m_radiusY) { 194 if (m_radiusY) {
192 shouldSerializeRadiusYValue = 195 shouldSerializeRadiusYValue = !(
193 m_radiusY->getValueID() != CSSValueClosestSide; 196 m_radiusY->isIdentifierValue() &&
197 toCSSIdentifierValue(*m_radiusY).getValueID() == CSSValueClosestSide);
194 if (shouldSerializeRadiusYValue) 198 if (shouldSerializeRadiusYValue)
195 radiusY = m_radiusY->cssText(); 199 radiusY = m_radiusY->cssText();
196 } 200 }
197 if (shouldSerializeRadiusXValue || 201 if (shouldSerializeRadiusXValue ||
198 (!shouldSerializeRadiusXValue && shouldSerializeRadiusYValue)) 202 (!shouldSerializeRadiusXValue && shouldSerializeRadiusYValue))
199 radiusX = m_radiusX->cssText(); 203 radiusX = m_radiusX->cssText();
200 } 204 }
201 205
202 return buildEllipseString( 206 return buildEllipseString(
203 radiusX, radiusY, serializePositionOffset(*normalizedCX, *normalizedCY), 207 radiusX, radiusY, serializePositionOffset(*normalizedCX, *normalizedCY),
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 visitor->trace(m_bottom); 429 visitor->trace(m_bottom);
426 visitor->trace(m_left); 430 visitor->trace(m_left);
427 visitor->trace(m_topLeftRadius); 431 visitor->trace(m_topLeftRadius);
428 visitor->trace(m_topRightRadius); 432 visitor->trace(m_topRightRadius);
429 visitor->trace(m_bottomRightRadius); 433 visitor->trace(m_bottomRightRadius);
430 visitor->trace(m_bottomLeftRadius); 434 visitor->trace(m_bottomLeftRadius);
431 CSSValue::traceAfterDispatch(visitor); 435 CSSValue::traceAfterDispatch(visitor);
432 } 436 }
433 437
434 } // namespace blink 438 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698