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

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

Issue 2346193002: Split CSSPrimitiveValue into CSSPrimitiveValue and CSSIdentifierValue (Closed)
Patch Set: Rebase please work 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, const String& centerX, con st String& centerY) 42 static String buildCircleString(const String& radius, const String& centerX, con st String& centerY)
(...skipping 13 matching lines...) Expand all
55 result.append(centerX); 56 result.append(centerX);
56 result.append(separator); 57 result.append(separator);
57 result.append(centerY); 58 result.append(centerY);
58 } 59 }
59 result.append(')'); 60 result.append(')');
60 return result.toString(); 61 return result.toString();
61 } 62 }
62 63
63 static String serializePositionOffset(const CSSValuePair& offset, const CSSValue Pair& other) 64 static String serializePositionOffset(const CSSValuePair& offset, const CSSValue Pair& other)
64 { 65 {
65 if ((toCSSPrimitiveValue(offset.first()).getValueID() == CSSValueLeft && toC SSPrimitiveValue(other.first()).getValueID() == CSSValueTop) 66 if ((toCSSIdentifierValue(offset.first()).getValueID() == CSSValueLeft && to CSSIdentifierValue(other.first()).getValueID() == CSSValueTop)
66 || (toCSSPrimitiveValue(offset.first()).getValueID() == CSSValueTop && t oCSSPrimitiveValue(other.first()).getValueID() == CSSValueLeft)) 67 || (toCSSIdentifierValue(offset.first()).getValueID() == CSSValueTop && toCSSIdentifierValue(other.first()).getValueID() == CSSValueLeft))
67 return offset.second().cssText(); 68 return offset.second().cssText();
68 return offset.cssText(); 69 return offset.cssText();
69 } 70 }
70 71
71 static CSSValuePair* buildSerializablePositionOffset(CSSValue* offset, CSSValueI D defaultSide) 72 static CSSValuePair* buildSerializablePositionOffset(CSSValue* offset, CSSValueI D defaultSide)
72 { 73 {
73 CSSValueID side = defaultSide; 74 CSSValueID side = defaultSide;
74 const CSSPrimitiveValue* amount = nullptr; 75 const CSSPrimitiveValue* amount = nullptr;
75 76
76 if (!offset) { 77 if (!offset) {
77 side = CSSValueCenter; 78 side = CSSValueCenter;
78 } else if (offset->isPrimitiveValue() && toCSSPrimitiveValue(offset)->isValu eID()) { 79 } else if (offset->isIdentifierValue()) {
79 side = toCSSPrimitiveValue(offset)->getValueID(); 80 side = toCSSIdentifierValue(offset)->getValueID();
80 } else if (offset->isValuePair()) { 81 } else if (offset->isValuePair()) {
81 side = toCSSPrimitiveValue(toCSSValuePair(*offset).first()).getValueID() ; 82 side = toCSSIdentifierValue(toCSSValuePair(*offset).first()).getValueID( );
82 amount = &toCSSPrimitiveValue(toCSSValuePair(*offset).second()); 83 amount = &toCSSPrimitiveValue(toCSSValuePair(*offset).second());
83 if ((side == CSSValueRight || side == CSSValueBottom) && amount->isPerce ntage()) { 84 if ((side == CSSValueRight || side == CSSValueBottom) && amount->isPerce ntage()) {
84 side = defaultSide; 85 side = defaultSide;
85 amount = CSSPrimitiveValue::create(100 - amount->getFloatValue(), CS SPrimitiveValue::UnitType::Percentage); 86 amount = CSSPrimitiveValue::create(100 - amount->getFloatValue(), CS SPrimitiveValue::UnitType::Percentage);
86 } 87 }
87 } else { 88 } else {
88 amount = toCSSPrimitiveValue(offset); 89 amount = toCSSPrimitiveValue(offset);
89 } 90 }
90 91
91 if (side == CSSValueCenter) { 92 if (side == CSSValueCenter) {
92 side = defaultSide; 93 side = defaultSide;
93 amount = CSSPrimitiveValue::create(50, CSSPrimitiveValue::UnitType::Perc entage); 94 amount = CSSPrimitiveValue::create(50, CSSPrimitiveValue::UnitType::Perc entage);
94 } else if (!amount || (amount->isLength() && !amount->getFloatValue())) { 95 } else if (!amount || (amount->isLength() && !amount->getFloatValue())) {
95 if (side == CSSValueRight || side == CSSValueBottom) 96 if (side == CSSValueRight || side == CSSValueBottom)
96 amount = CSSPrimitiveValue::create(100, CSSPrimitiveValue::UnitType: :Percentage); 97 amount = CSSPrimitiveValue::create(100, CSSPrimitiveValue::UnitType: :Percentage);
97 else 98 else
98 amount = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::P ercentage); 99 amount = CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType::P ercentage);
99 side = defaultSide; 100 side = defaultSide;
100 } 101 }
101 102
102 return CSSValuePair::create(CSSPrimitiveValue::createIdentifier(side), amoun t, CSSValuePair::KeepIdenticalValues); 103 return CSSValuePair::create(CSSIdentifierValue::create(side), amount, CSSVal uePair::KeepIdenticalValues);
103 } 104 }
104 105
105 String CSSBasicShapeCircleValue::customCSSText() const 106 String CSSBasicShapeCircleValue::customCSSText() const
106 { 107 {
107 CSSValuePair* normalizedCX = buildSerializablePositionOffset(m_centerX, CSSV alueLeft); 108 CSSValuePair* normalizedCX = buildSerializablePositionOffset(m_centerX, CSSV alueLeft);
108 CSSValuePair* normalizedCY = buildSerializablePositionOffset(m_centerY, CSSV alueTop); 109 CSSValuePair* normalizedCY = buildSerializablePositionOffset(m_centerY, CSSV alueTop);
109 110
110 String radius; 111 String radius;
111 if (m_radius && m_radius->getValueID() != CSSValueClosestSide) 112 if (m_radius && !(m_radius->isIdentifierValue() && toCSSIdentifierValue(*m_r adius).getValueID() == CSSValueClosestSide))
112 radius = m_radius->cssText(); 113 radius = m_radius->cssText();
113 114
114 return buildCircleString(radius, 115 return buildCircleString(radius,
115 serializePositionOffset(*normalizedCX, *normalizedCY), 116 serializePositionOffset(*normalizedCX, *normalizedCY),
116 serializePositionOffset(*normalizedCY, *normalizedCX)); 117 serializePositionOffset(*normalizedCY, *normalizedCX));
117 } 118 }
118 119
119 bool CSSBasicShapeCircleValue::equals(const CSSBasicShapeCircleValue& other) con st 120 bool CSSBasicShapeCircleValue::equals(const CSSBasicShapeCircleValue& other) con st
120 { 121 {
121 return compareCSSValuePtr(m_centerX, other.m_centerX) 122 return compareCSSValuePtr(m_centerX, other.m_centerX)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 164 }
164 165
165 String CSSBasicShapeEllipseValue::customCSSText() const 166 String CSSBasicShapeEllipseValue::customCSSText() const
166 { 167 {
167 CSSValuePair* normalizedCX = buildSerializablePositionOffset(m_centerX, CSSV alueLeft); 168 CSSValuePair* normalizedCX = buildSerializablePositionOffset(m_centerX, CSSV alueLeft);
168 CSSValuePair* normalizedCY = buildSerializablePositionOffset(m_centerY, CSSV alueTop); 169 CSSValuePair* normalizedCY = buildSerializablePositionOffset(m_centerY, CSSV alueTop);
169 170
170 String radiusX; 171 String radiusX;
171 String radiusY; 172 String radiusY;
172 if (m_radiusX) { 173 if (m_radiusX) {
173 bool shouldSerializeRadiusXValue = m_radiusX->getValueID() != CSSValueCl osestSide; 174 bool shouldSerializeRadiusXValue = !(m_radiusX->isIdentifierValue() && t oCSSIdentifierValue(*m_radiusX).getValueID() == CSSValueClosestSide);
174 bool shouldSerializeRadiusYValue = false; 175 bool shouldSerializeRadiusYValue = false;
175 176
176 if (m_radiusY) { 177 if (m_radiusY) {
177 shouldSerializeRadiusYValue = m_radiusY->getValueID() != CSSValueClo sestSide; 178 shouldSerializeRadiusYValue = !(m_radiusY->isIdentifierValue() && to CSSIdentifierValue(*m_radiusY).getValueID() == CSSValueClosestSide);
178 if (shouldSerializeRadiusYValue) 179 if (shouldSerializeRadiusYValue)
179 radiusY = m_radiusY->cssText(); 180 radiusY = m_radiusY->cssText();
180 } 181 }
181 if (shouldSerializeRadiusXValue || (!shouldSerializeRadiusXValue && shou ldSerializeRadiusYValue)) 182 if (shouldSerializeRadiusXValue || (!shouldSerializeRadiusXValue && shou ldSerializeRadiusYValue))
182 radiusX = m_radiusX->cssText(); 183 radiusX = m_radiusX->cssText();
183 } 184 }
184 185
185 return buildEllipseString(radiusX, radiusY, 186 return buildEllipseString(radiusX, radiusY,
186 serializePositionOffset(*normalizedCX, *normalizedCY), 187 serializePositionOffset(*normalizedCX, *normalizedCY),
187 serializePositionOffset(*normalizedCY, *normalizedCX)); 188 serializePositionOffset(*normalizedCY, *normalizedCX));
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 visitor->trace(m_left); 399 visitor->trace(m_left);
399 visitor->trace(m_topLeftRadius); 400 visitor->trace(m_topLeftRadius);
400 visitor->trace(m_topRightRadius); 401 visitor->trace(m_topRightRadius);
401 visitor->trace(m_bottomRightRadius); 402 visitor->trace(m_bottomRightRadius);
402 visitor->trace(m_bottomLeftRadius); 403 visitor->trace(m_bottomLeftRadius);
403 CSSValue::traceAfterDispatch(visitor); 404 CSSValue::traceAfterDispatch(visitor);
404 } 405 }
405 406
406 } // namespace blink 407 } // namespace blink
407 408
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698