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

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

Issue 1373753002: Change CSSToStyleMap functions to take const CSSValue&s (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small fix Created 5 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r ights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All r ights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 25 matching lines...) Expand all
36 #include "core/css/CSSQuadValue.h" 36 #include "core/css/CSSQuadValue.h"
37 #include "core/css/CSSTimingFunctionValue.h" 37 #include "core/css/CSSTimingFunctionValue.h"
38 #include "core/css/CSSValuePair.h" 38 #include "core/css/CSSValuePair.h"
39 #include "core/css/resolver/StyleBuilderConverter.h" 39 #include "core/css/resolver/StyleBuilderConverter.h"
40 #include "core/css/resolver/StyleResolverState.h" 40 #include "core/css/resolver/StyleResolverState.h"
41 #include "core/style/BorderImageLengthBox.h" 41 #include "core/style/BorderImageLengthBox.h"
42 #include "core/style/FillLayer.h" 42 #include "core/style/FillLayer.h"
43 43
44 namespace blink { 44 namespace blink {
45 45
46 void CSSToStyleMap::mapFillAttachment(StyleResolverState&, FillLayer* layer, CSS Value* value) 46 void CSSToStyleMap::mapFillAttachment(StyleResolverState&, FillLayer* layer, con st CSSValue& value)
47 { 47 {
48 if (value->isInitialValue()) { 48 if (value.isInitialValue()) {
49 layer->setAttachment(FillLayer::initialFillAttachment(layer->type())); 49 layer->setAttachment(FillLayer::initialFillAttachment(layer->type()));
50 return; 50 return;
51 } 51 }
52 52
53 if (!value->isPrimitiveValue()) 53 if (!value.isPrimitiveValue())
54 return; 54 return;
55 55
56 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 56 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
57 switch (primitiveValue->getValueID()) { 57 switch (primitiveValue.getValueID()) {
58 case CSSValueFixed: 58 case CSSValueFixed:
59 layer->setAttachment(FixedBackgroundAttachment); 59 layer->setAttachment(FixedBackgroundAttachment);
60 break; 60 break;
61 case CSSValueScroll: 61 case CSSValueScroll:
62 layer->setAttachment(ScrollBackgroundAttachment); 62 layer->setAttachment(ScrollBackgroundAttachment);
63 break; 63 break;
64 case CSSValueLocal: 64 case CSSValueLocal:
65 layer->setAttachment(LocalBackgroundAttachment); 65 layer->setAttachment(LocalBackgroundAttachment);
66 break; 66 break;
67 default: 67 default:
68 return; 68 return;
69 } 69 }
70 } 70 }
71 71
72 void CSSToStyleMap::mapFillClip(StyleResolverState&, FillLayer* layer, CSSValue* value) 72 void CSSToStyleMap::mapFillClip(StyleResolverState&, FillLayer* layer, const CSS Value& value)
73 { 73 {
74 if (value->isInitialValue()) { 74 if (value.isInitialValue()) {
75 layer->setClip(FillLayer::initialFillClip(layer->type())); 75 layer->setClip(FillLayer::initialFillClip(layer->type()));
76 return; 76 return;
77 } 77 }
78 78
79 if (!value->isPrimitiveValue()) 79 if (!value.isPrimitiveValue())
80 return; 80 return;
81 81
82 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 82 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
83 layer->setClip(*primitiveValue); 83 layer->setClip(primitiveValue);
84 } 84 }
85 85
86 void CSSToStyleMap::mapFillComposite(StyleResolverState&, FillLayer* layer, CSSV alue* value) 86 void CSSToStyleMap::mapFillComposite(StyleResolverState&, FillLayer* layer, cons t CSSValue& value)
87 { 87 {
88 if (value->isInitialValue()) { 88 if (value.isInitialValue()) {
89 layer->setComposite(FillLayer::initialFillComposite(layer->type())); 89 layer->setComposite(FillLayer::initialFillComposite(layer->type()));
90 return; 90 return;
91 } 91 }
92 92
93 if (!value->isPrimitiveValue()) 93 if (!value.isPrimitiveValue())
94 return; 94 return;
95 95
96 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 96 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
97 layer->setComposite(*primitiveValue); 97 layer->setComposite(primitiveValue);
98 } 98 }
99 99
100 void CSSToStyleMap::mapFillBlendMode(StyleResolverState&, FillLayer* layer, CSSV alue* value) 100 void CSSToStyleMap::mapFillBlendMode(StyleResolverState&, FillLayer* layer, cons t CSSValue& value)
101 { 101 {
102 if (value->isInitialValue()) { 102 if (value.isInitialValue()) {
103 layer->setBlendMode(FillLayer::initialFillBlendMode(layer->type())); 103 layer->setBlendMode(FillLayer::initialFillBlendMode(layer->type()));
104 return; 104 return;
105 } 105 }
106 106
107 if (!value->isPrimitiveValue()) 107 if (!value.isPrimitiveValue())
108 return; 108 return;
109 109
110 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 110 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
111 layer->setBlendMode(*primitiveValue); 111 layer->setBlendMode(primitiveValue);
112 } 112 }
113 113
114 void CSSToStyleMap::mapFillOrigin(StyleResolverState&, FillLayer* layer, CSSValu e* value) 114 void CSSToStyleMap::mapFillOrigin(StyleResolverState&, FillLayer* layer, const C SSValue& value)
115 { 115 {
116 if (value->isInitialValue()) { 116 if (value.isInitialValue()) {
117 layer->setOrigin(FillLayer::initialFillOrigin(layer->type())); 117 layer->setOrigin(FillLayer::initialFillOrigin(layer->type()));
118 return; 118 return;
119 } 119 }
120 120
121 if (!value->isPrimitiveValue()) 121 if (!value.isPrimitiveValue())
122 return; 122 return;
123 123
124 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 124 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
125 layer->setOrigin(*primitiveValue); 125 layer->setOrigin(primitiveValue);
126 } 126 }
127 127
128 128
129 void CSSToStyleMap::mapFillImage(StyleResolverState& state, FillLayer* layer, CS SValue* value) 129 void CSSToStyleMap::mapFillImage(StyleResolverState& state, FillLayer* layer, co nst CSSValue& value)
130 { 130 {
131 if (value->isInitialValue()) { 131 if (value.isInitialValue()) {
132 layer->setImage(FillLayer::initialFillImage(layer->type())); 132 layer->setImage(FillLayer::initialFillImage(layer->type()));
133 return; 133 return;
134 } 134 }
135 135
136 CSSPropertyID property = layer->type() == BackgroundFillLayer ? CSSPropertyB ackgroundImage : CSSPropertyWebkitMaskImage; 136 CSSPropertyID property = layer->type() == BackgroundFillLayer ? CSSPropertyB ackgroundImage : CSSPropertyWebkitMaskImage;
137 layer->setImage(state.styleImage(property, value)); 137 // TODO(sashab): Make StyleImages have mutable fields and pass them around b y const reference, removing this cast.
138 layer->setImage(state.styleImage(property, const_cast<CSSValue*>(&value)));
138 } 139 }
139 140
140 void CSSToStyleMap::mapFillRepeatX(StyleResolverState&, FillLayer* layer, CSSVal ue* value) 141 void CSSToStyleMap::mapFillRepeatX(StyleResolverState&, FillLayer* layer, const CSSValue& value)
141 { 142 {
142 if (value->isInitialValue()) { 143 if (value.isInitialValue()) {
143 layer->setRepeatX(FillLayer::initialFillRepeatX(layer->type())); 144 layer->setRepeatX(FillLayer::initialFillRepeatX(layer->type()));
144 return; 145 return;
145 } 146 }
146 147
147 if (!value->isPrimitiveValue()) 148 if (!value.isPrimitiveValue())
148 return; 149 return;
149 150
150 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 151 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
151 layer->setRepeatX(*primitiveValue); 152 layer->setRepeatX(primitiveValue);
152 } 153 }
153 154
154 void CSSToStyleMap::mapFillRepeatY(StyleResolverState&, FillLayer* layer, CSSVal ue* value) 155 void CSSToStyleMap::mapFillRepeatY(StyleResolverState&, FillLayer* layer, const CSSValue& value)
155 { 156 {
156 if (value->isInitialValue()) { 157 if (value.isInitialValue()) {
157 layer->setRepeatY(FillLayer::initialFillRepeatY(layer->type())); 158 layer->setRepeatY(FillLayer::initialFillRepeatY(layer->type()));
158 return; 159 return;
159 } 160 }
160 161
161 if (!value->isPrimitiveValue()) 162 if (!value.isPrimitiveValue())
162 return; 163 return;
163 164
164 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 165 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
165 layer->setRepeatY(*primitiveValue); 166 layer->setRepeatY(primitiveValue);
166 } 167 }
167 168
168 void CSSToStyleMap::mapFillSize(StyleResolverState& state, FillLayer* layer, CSS Value* value) 169 void CSSToStyleMap::mapFillSize(StyleResolverState& state, FillLayer* layer, con st CSSValue& value)
169 { 170 {
170 if (value->isInitialValue()) { 171 if (value.isInitialValue()) {
171 layer->setSizeType(FillLayer::initialFillSizeType(layer->type())); 172 layer->setSizeType(FillLayer::initialFillSizeType(layer->type()));
172 layer->setSizeLength(FillLayer::initialFillSizeLength(layer->type())); 173 layer->setSizeLength(FillLayer::initialFillSizeLength(layer->type()));
173 return; 174 return;
174 } 175 }
175 176
176 if (!value->isPrimitiveValue() && !value->isValuePair()) 177 if (!value.isPrimitiveValue() && !value.isValuePair())
177 return; 178 return;
178 179
179 if (value->isPrimitiveValue() && toCSSPrimitiveValue(value)->getValueID() == CSSValueContain) 180 if (value.isPrimitiveValue() && toCSSPrimitiveValue(value).getValueID() == C SSValueContain)
180 layer->setSizeType(Contain); 181 layer->setSizeType(Contain);
181 else if (value->isPrimitiveValue() && toCSSPrimitiveValue(value)->getValueID () == CSSValueCover) 182 else if (value.isPrimitiveValue() && toCSSPrimitiveValue(value).getValueID() == CSSValueCover)
182 layer->setSizeType(Cover); 183 layer->setSizeType(Cover);
183 else 184 else
184 layer->setSizeType(SizeLength); 185 layer->setSizeType(SizeLength);
185 186
186 LengthSize b = FillLayer::initialFillSizeLength(layer->type()); 187 LengthSize b = FillLayer::initialFillSizeLength(layer->type());
187 188
188 if (value->isPrimitiveValue() && (toCSSPrimitiveValue(value)->getValueID() = = CSSValueContain || toCSSPrimitiveValue(value)->getValueID() == CSSValueCover)) { 189 if (value.isPrimitiveValue() && (toCSSPrimitiveValue(value).getValueID() == CSSValueContain || toCSSPrimitiveValue(value).getValueID() == CSSValueCover)) {
189 layer->setSizeLength(b); 190 layer->setSizeLength(b);
190 return; 191 return;
191 } 192 }
192 193
193 Length firstLength; 194 Length firstLength;
194 Length secondLength; 195 Length secondLength;
195 196
196 if (value->isValuePair()) { 197 if (value.isValuePair()) {
197 CSSValuePair* pair = toCSSValuePair(value); 198 const CSSValuePair& pair = toCSSValuePair(value);
198 firstLength = StyleBuilderConverter::convertLengthOrAuto(state, &pair->f irst()); 199 // TODO(sashab): Make convertLengthOrAuto take a const& and remove these const_casts.
199 secondLength = StyleBuilderConverter::convertLengthOrAuto(state, &pair-> second()); 200 firstLength = StyleBuilderConverter::convertLengthOrAuto(state, const_ca st<CSSValue*>(&pair.first()));
201 secondLength = StyleBuilderConverter::convertLengthOrAuto(state, const_c ast<CSSValue*>(&pair.second()));
200 } else { 202 } else {
201 ASSERT(value->isPrimitiveValue()); 203 ASSERT(value.isPrimitiveValue());
202 firstLength = StyleBuilderConverter::convertLengthOrAuto(state, value); 204 firstLength = StyleBuilderConverter::convertLengthOrAuto(state, const_ca st<CSSValue*>(&value));
203 secondLength = Length(); 205 secondLength = Length();
204 } 206 }
205 207
206 b.setWidth(firstLength); 208 b.setWidth(firstLength);
207 b.setHeight(secondLength); 209 b.setHeight(secondLength);
208 layer->setSizeLength(b); 210 layer->setSizeLength(b);
209 } 211 }
210 212
211 void CSSToStyleMap::mapFillXPosition(StyleResolverState& state, FillLayer* layer , CSSValue* value) 213 void CSSToStyleMap::mapFillXPosition(StyleResolverState& state, FillLayer* layer , const CSSValue& value)
212 { 214 {
213 if (value->isInitialValue()) { 215 if (value.isInitialValue()) {
214 layer->setXPosition(FillLayer::initialFillXPosition(layer->type())); 216 layer->setXPosition(FillLayer::initialFillXPosition(layer->type()));
215 return; 217 return;
216 } 218 }
217 219
218 if (!value->isPrimitiveValue() && !value->isValuePair()) 220 if (!value.isPrimitiveValue() && !value.isValuePair())
219 return; 221 return;
220 222
221 Length length; 223 Length length;
222 if (value->isValuePair()) 224 if (value.isValuePair())
223 length = toCSSPrimitiveValue(toCSSValuePair(value)->second()).convertToL ength(state.cssToLengthConversionData()); 225 length = toCSSPrimitiveValue(toCSSValuePair(value).second()).convertToLe ngth(state.cssToLengthConversionData());
224 else 226 else
225 length = toCSSPrimitiveValue(value)->convertToLength(state.cssToLengthCo nversionData()); 227 length = toCSSPrimitiveValue(value).convertToLength(state.cssToLengthCon versionData());
226 228
227 layer->setXPosition(length); 229 layer->setXPosition(length);
228 if (value->isValuePair()) 230 if (value.isValuePair())
229 layer->setBackgroundXOrigin(toCSSPrimitiveValue(toCSSValuePair(value)->f irst())); 231 layer->setBackgroundXOrigin(toCSSPrimitiveValue(toCSSValuePair(value).fi rst()));
230 } 232 }
231 233
232 void CSSToStyleMap::mapFillYPosition(StyleResolverState& state, FillLayer* layer , CSSValue* value) 234 void CSSToStyleMap::mapFillYPosition(StyleResolverState& state, FillLayer* layer , const CSSValue& value)
233 { 235 {
234 if (value->isInitialValue()) { 236 if (value.isInitialValue()) {
235 layer->setYPosition(FillLayer::initialFillYPosition(layer->type())); 237 layer->setYPosition(FillLayer::initialFillYPosition(layer->type()));
236 return; 238 return;
237 } 239 }
238 240
239 if (!value->isPrimitiveValue() && !value->isValuePair()) 241 if (!value.isPrimitiveValue() && !value.isValuePair())
240 return; 242 return;
241 243
242 CSSPrimitiveValue* primitiveValue; 244 Length length;
243 if (value->isValuePair()) 245 if (value.isValuePair())
244 primitiveValue = &toCSSPrimitiveValue(toCSSValuePair(value)->second()); 246 length = toCSSPrimitiveValue(toCSSValuePair(value).second()).convertToLe ngth(state.cssToLengthConversionData());
245 else 247 else
246 primitiveValue = toCSSPrimitiveValue(value); 248 length = toCSSPrimitiveValue(value).convertToLength(state.cssToLengthCon versionData());
247
248 Length length = primitiveValue->convertToLength(state.cssToLengthConversionD ata());
249 249
250 layer->setYPosition(length); 250 layer->setYPosition(length);
251 if (value->isValuePair()) 251 if (value.isValuePair())
252 layer->setBackgroundYOrigin(toCSSPrimitiveValue(toCSSValuePair(value)->f irst())); 252 layer->setBackgroundYOrigin(toCSSPrimitiveValue(toCSSValuePair(value).fi rst()));
253 } 253 }
254 254
255 void CSSToStyleMap::mapFillMaskSourceType(StyleResolverState&, FillLayer* layer, CSSValue* value) 255 void CSSToStyleMap::mapFillMaskSourceType(StyleResolverState&, FillLayer* layer, const CSSValue& value)
256 { 256 {
257 EMaskSourceType type = FillLayer::initialFillMaskSourceType(layer->type()); 257 EMaskSourceType type = FillLayer::initialFillMaskSourceType(layer->type());
258 if (value->isInitialValue()) { 258 if (value.isInitialValue()) {
259 layer->setMaskSourceType(type); 259 layer->setMaskSourceType(type);
260 return; 260 return;
261 } 261 }
262 262
263 if (!value->isPrimitiveValue()) 263 if (!value.isPrimitiveValue())
264 return; 264 return;
265 265
266 switch (toCSSPrimitiveValue(value)->getValueID()) { 266 switch (toCSSPrimitiveValue(value).getValueID()) {
267 case CSSValueAlpha: 267 case CSSValueAlpha:
268 type = MaskAlpha; 268 type = MaskAlpha;
269 break; 269 break;
270 case CSSValueLuminance: 270 case CSSValueLuminance:
271 type = MaskLuminance; 271 type = MaskLuminance;
272 break; 272 break;
273 case CSSValueAuto: 273 case CSSValueAuto:
274 break; 274 break;
275 default: 275 default:
276 ASSERT_NOT_REACHED(); 276 ASSERT_NOT_REACHED();
277 } 277 }
278 278
279 layer->setMaskSourceType(type); 279 layer->setMaskSourceType(type);
280 } 280 }
281 281
282 double CSSToStyleMap::mapAnimationDelay(CSSValue* value) 282 double CSSToStyleMap::mapAnimationDelay(const CSSValue& value)
283 { 283 {
284 if (value->isInitialValue()) 284 if (value.isInitialValue())
285 return CSSTimingData::initialDelay(); 285 return CSSTimingData::initialDelay();
286 return toCSSPrimitiveValue(value)->computeSeconds(); 286 return toCSSPrimitiveValue(value).computeSeconds();
287 } 287 }
288 288
289 Timing::PlaybackDirection CSSToStyleMap::mapAnimationDirection(CSSValue* value) 289 Timing::PlaybackDirection CSSToStyleMap::mapAnimationDirection(const CSSValue& v alue)
290 { 290 {
291 if (value->isInitialValue()) 291 if (value.isInitialValue())
292 return CSSAnimationData::initialDirection(); 292 return CSSAnimationData::initialDirection();
293 293
294 switch (toCSSPrimitiveValue(value)->getValueID()) { 294 switch (toCSSPrimitiveValue(value).getValueID()) {
295 case CSSValueNormal: 295 case CSSValueNormal:
296 return Timing::PlaybackDirectionNormal; 296 return Timing::PlaybackDirectionNormal;
297 case CSSValueAlternate: 297 case CSSValueAlternate:
298 return Timing::PlaybackDirectionAlternate; 298 return Timing::PlaybackDirectionAlternate;
299 case CSSValueReverse: 299 case CSSValueReverse:
300 return Timing::PlaybackDirectionReverse; 300 return Timing::PlaybackDirectionReverse;
301 case CSSValueAlternateReverse: 301 case CSSValueAlternateReverse:
302 return Timing::PlaybackDirectionAlternateReverse; 302 return Timing::PlaybackDirectionAlternateReverse;
303 default: 303 default:
304 ASSERT_NOT_REACHED(); 304 ASSERT_NOT_REACHED();
305 return CSSAnimationData::initialDirection(); 305 return CSSAnimationData::initialDirection();
306 } 306 }
307 } 307 }
308 308
309 double CSSToStyleMap::mapAnimationDuration(CSSValue* value) 309 double CSSToStyleMap::mapAnimationDuration(const CSSValue& value)
310 { 310 {
311 if (value->isInitialValue()) 311 if (value.isInitialValue())
312 return CSSTimingData::initialDuration(); 312 return CSSTimingData::initialDuration();
313 return toCSSPrimitiveValue(value)->computeSeconds(); 313 return toCSSPrimitiveValue(value).computeSeconds();
314 } 314 }
315 315
316 Timing::FillMode CSSToStyleMap::mapAnimationFillMode(CSSValue* value) 316 Timing::FillMode CSSToStyleMap::mapAnimationFillMode(const CSSValue& value)
317 { 317 {
318 if (value->isInitialValue()) 318 if (value.isInitialValue())
319 return CSSAnimationData::initialFillMode(); 319 return CSSAnimationData::initialFillMode();
320 320
321 switch (toCSSPrimitiveValue(value)->getValueID()) { 321 switch (toCSSPrimitiveValue(value).getValueID()) {
322 case CSSValueNone: 322 case CSSValueNone:
323 return Timing::FillModeNone; 323 return Timing::FillModeNone;
324 case CSSValueForwards: 324 case CSSValueForwards:
325 return Timing::FillModeForwards; 325 return Timing::FillModeForwards;
326 case CSSValueBackwards: 326 case CSSValueBackwards:
327 return Timing::FillModeBackwards; 327 return Timing::FillModeBackwards;
328 case CSSValueBoth: 328 case CSSValueBoth:
329 return Timing::FillModeBoth; 329 return Timing::FillModeBoth;
330 default: 330 default:
331 ASSERT_NOT_REACHED(); 331 ASSERT_NOT_REACHED();
332 return CSSAnimationData::initialFillMode(); 332 return CSSAnimationData::initialFillMode();
333 } 333 }
334 } 334 }
335 335
336 double CSSToStyleMap::mapAnimationIterationCount(CSSValue* value) 336 double CSSToStyleMap::mapAnimationIterationCount(const CSSValue& value)
337 { 337 {
338 if (value->isInitialValue()) 338 if (value.isInitialValue())
339 return CSSAnimationData::initialIterationCount(); 339 return CSSAnimationData::initialIterationCount();
340 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 340 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
341 if (primitiveValue->getValueID() == CSSValueInfinite) 341 if (primitiveValue.getValueID() == CSSValueInfinite)
342 return std::numeric_limits<double>::infinity(); 342 return std::numeric_limits<double>::infinity();
343 return primitiveValue->getFloatValue(); 343 return primitiveValue.getFloatValue();
344 } 344 }
345 345
346 AtomicString CSSToStyleMap::mapAnimationName(CSSValue* value) 346 AtomicString CSSToStyleMap::mapAnimationName(const CSSValue& value)
347 { 347 {
348 if (value->isInitialValue()) 348 if (value.isInitialValue())
349 return CSSAnimationData::initialName(); 349 return CSSAnimationData::initialName();
350 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 350 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
351 if (primitiveValue->getValueID() == CSSValueNone) 351 if (primitiveValue.getValueID() == CSSValueNone)
352 return CSSAnimationData::initialName(); 352 return CSSAnimationData::initialName();
353 return AtomicString(primitiveValue->getStringValue()); 353 return AtomicString(primitiveValue.getStringValue());
354 } 354 }
355 355
356 EAnimPlayState CSSToStyleMap::mapAnimationPlayState(CSSValue* value) 356 EAnimPlayState CSSToStyleMap::mapAnimationPlayState(const CSSValue& value)
357 { 357 {
358 if (value->isInitialValue()) 358 if (value.isInitialValue())
359 return CSSAnimationData::initialPlayState(); 359 return CSSAnimationData::initialPlayState();
360 if (toCSSPrimitiveValue(value)->getValueID() == CSSValuePaused) 360 if (toCSSPrimitiveValue(value).getValueID() == CSSValuePaused)
361 return AnimPlayStatePaused; 361 return AnimPlayStatePaused;
362 ASSERT(toCSSPrimitiveValue(value)->getValueID() == CSSValueRunning); 362 ASSERT(toCSSPrimitiveValue(value).getValueID() == CSSValueRunning);
363 return AnimPlayStatePlaying; 363 return AnimPlayStatePlaying;
364 } 364 }
365 365
366 CSSTransitionData::TransitionProperty CSSToStyleMap::mapAnimationProperty(CSSVal ue* value) 366 CSSTransitionData::TransitionProperty CSSToStyleMap::mapAnimationProperty(const CSSValue& value)
367 { 367 {
368 if (value->isInitialValue()) 368 if (value.isInitialValue())
369 return CSSTransitionData::initialProperty(); 369 return CSSTransitionData::initialProperty();
370 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 370 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
371 if (primitiveValue->isCustomIdent()) 371 if (primitiveValue.isCustomIdent())
372 return CSSTransitionData::TransitionProperty(primitiveValue->getStringVa lue()); 372 return CSSTransitionData::TransitionProperty(primitiveValue.getStringVal ue());
373 if (primitiveValue->getValueID() == CSSValueNone) 373 if (primitiveValue.getValueID() == CSSValueNone)
374 return CSSTransitionData::TransitionProperty(CSSTransitionData::Transiti onNone); 374 return CSSTransitionData::TransitionProperty(CSSTransitionData::Transiti onNone);
375 return CSSTransitionData::TransitionProperty(primitiveValue->getPropertyID() ); 375 return CSSTransitionData::TransitionProperty(primitiveValue.getPropertyID()) ;
376 } 376 }
377 377
378 PassRefPtr<TimingFunction> CSSToStyleMap::mapAnimationTimingFunction(CSSValue* v alue, bool allowStepMiddle) 378 PassRefPtr<TimingFunction> CSSToStyleMap::mapAnimationTimingFunction(const CSSVa lue& value, bool allowStepMiddle)
379 { 379 {
380 // FIXME: We should probably only call into this function with a valid 380 // FIXME: We should probably only call into this function with a valid
381 // single timing function value which isn't initial or inherit. We can 381 // single timing function value which isn't initial or inherit. We can
382 // currently get into here with initial since the parser expands unset 382 // currently get into here with initial since the parser expands unset
383 // properties in shorthands to initial. 383 // properties in shorthands to initial.
384 384
385 if (value->isPrimitiveValue()) { 385 if (value.isPrimitiveValue()) {
386 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); 386 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
387 switch (primitiveValue->getValueID()) { 387 switch (primitiveValue.getValueID()) {
388 case CSSValueLinear: 388 case CSSValueLinear:
389 return LinearTimingFunction::shared(); 389 return LinearTimingFunction::shared();
390 case CSSValueEase: 390 case CSSValueEase:
391 return CubicBezierTimingFunction::preset(CubicBezierTimingFunction:: Ease); 391 return CubicBezierTimingFunction::preset(CubicBezierTimingFunction:: Ease);
392 case CSSValueEaseIn: 392 case CSSValueEaseIn:
393 return CubicBezierTimingFunction::preset(CubicBezierTimingFunction:: EaseIn); 393 return CubicBezierTimingFunction::preset(CubicBezierTimingFunction:: EaseIn);
394 case CSSValueEaseOut: 394 case CSSValueEaseOut:
395 return CubicBezierTimingFunction::preset(CubicBezierTimingFunction:: EaseOut); 395 return CubicBezierTimingFunction::preset(CubicBezierTimingFunction:: EaseOut);
396 case CSSValueEaseInOut: 396 case CSSValueEaseInOut:
397 return CubicBezierTimingFunction::preset(CubicBezierTimingFunction:: EaseInOut); 397 return CubicBezierTimingFunction::preset(CubicBezierTimingFunction:: EaseInOut);
398 case CSSValueStepStart: 398 case CSSValueStepStart:
399 return StepsTimingFunction::preset(StepsTimingFunction::Start); 399 return StepsTimingFunction::preset(StepsTimingFunction::Start);
400 case CSSValueStepMiddle: 400 case CSSValueStepMiddle:
401 if (allowStepMiddle) 401 if (allowStepMiddle)
402 return StepsTimingFunction::preset(StepsTimingFunction::Middle); 402 return StepsTimingFunction::preset(StepsTimingFunction::Middle);
403 return CSSTimingData::initialTimingFunction(); 403 return CSSTimingData::initialTimingFunction();
404 case CSSValueStepEnd: 404 case CSSValueStepEnd:
405 return StepsTimingFunction::preset(StepsTimingFunction::End); 405 return StepsTimingFunction::preset(StepsTimingFunction::End);
406 default: 406 default:
407 ASSERT_NOT_REACHED(); 407 ASSERT_NOT_REACHED();
408 return CSSTimingData::initialTimingFunction(); 408 return CSSTimingData::initialTimingFunction();
409 } 409 }
410 } 410 }
411 411
412 if (value->isCubicBezierTimingFunctionValue()) { 412 if (value.isCubicBezierTimingFunctionValue()) {
413 CSSCubicBezierTimingFunctionValue* cubicTimingFunction = toCSSCubicBezie rTimingFunctionValue(value); 413 const CSSCubicBezierTimingFunctionValue& cubicTimingFunction = toCSSCubi cBezierTimingFunctionValue(value);
414 return CubicBezierTimingFunction::create(cubicTimingFunction->x1(), cubi cTimingFunction->y1(), cubicTimingFunction->x2(), cubicTimingFunction->y2()); 414 return CubicBezierTimingFunction::create(cubicTimingFunction.x1(), cubic TimingFunction.y1(), cubicTimingFunction.x2(), cubicTimingFunction.y2());
415 } 415 }
416 416
417 if (value->isInitialValue()) 417 if (value.isInitialValue())
418 return CSSTimingData::initialTimingFunction(); 418 return CSSTimingData::initialTimingFunction();
419 419
420 CSSStepsTimingFunctionValue* stepsTimingFunction = toCSSStepsTimingFunctionV alue(value); 420 const CSSStepsTimingFunctionValue& stepsTimingFunction = toCSSStepsTimingFun ctionValue(value);
421 if (stepsTimingFunction->stepAtPosition() == StepsTimingFunction::Middle && !allowStepMiddle) 421 if (stepsTimingFunction.stepAtPosition() == StepsTimingFunction::Middle && ! allowStepMiddle)
422 return CSSTimingData::initialTimingFunction(); 422 return CSSTimingData::initialTimingFunction();
423 return StepsTimingFunction::create(stepsTimingFunction->numberOfSteps(), ste psTimingFunction->stepAtPosition()); 423 return StepsTimingFunction::create(stepsTimingFunction.numberOfSteps(), step sTimingFunction.stepAtPosition());
424 } 424 }
425 425
426 void CSSToStyleMap::mapNinePieceImage(StyleResolverState& state, CSSPropertyID p roperty, CSSValue* value, NinePieceImage& image) 426 void CSSToStyleMap::mapNinePieceImage(StyleResolverState& state, CSSPropertyID p roperty, const CSSValue& value, NinePieceImage& image)
427 { 427 {
428 // If we're not a value list, then we are "none" and don't need to alter the empty image at all. 428 // If we're not a value list, then we are "none" and don't need to alter the empty image at all.
429 if (!value || !value->isValueList()) 429 if (!value.isValueList())
430 return; 430 return;
431 431
432 // Retrieve the border image value. 432 // Retrieve the border image value.
433 CSSValueList* borderImage = toCSSValueList(value); 433 const CSSValueList& borderImage = toCSSValueList(value);
434 434
435 // Set the image (this kicks off the load). 435 // Set the image (this kicks off the load).
436 CSSPropertyID imageProperty; 436 CSSPropertyID imageProperty;
437 if (property == CSSPropertyWebkitBorderImage) 437 if (property == CSSPropertyWebkitBorderImage)
438 imageProperty = CSSPropertyBorderImageSource; 438 imageProperty = CSSPropertyBorderImageSource;
439 else if (property == CSSPropertyWebkitMaskBoxImage) 439 else if (property == CSSPropertyWebkitMaskBoxImage)
440 imageProperty = CSSPropertyWebkitMaskBoxImageSource; 440 imageProperty = CSSPropertyWebkitMaskBoxImageSource;
441 else 441 else
442 imageProperty = property; 442 imageProperty = property;
443 443
444 for (unsigned i = 0 ; i < borderImage->length() ; ++i) { 444 for (unsigned i = 0 ; i < borderImage.length() ; ++i) {
445 CSSValue* current = borderImage->item(i); 445 const CSSValue* current = borderImage.item(i);
alancutter (OOO until 2018) 2015/10/01 00:37:15 This should be a const CSSValue& since most reads
446 446
447 if (current->isImageValue() || current->isImageGeneratorValue() || curre nt->isImageSetValue()) 447 if (current->isImageValue() || current->isImageGeneratorValue() || curre nt->isImageSetValue()) {
448 image.setImage(state.styleImage(imageProperty, current)); 448 // TODO(sashab): Make StyleImages have mutable fields and pass them around by const reference, removing this cast.
449 else if (current->isBorderImageSliceValue()) 449 image.setImage(state.styleImage(imageProperty, const_cast<CSSValue*> (current)));
450 mapNinePieceImageSlice(state, current, image); 450 } else if (current->isBorderImageSliceValue()) {
451 else if (current->isValueList()) { 451 mapNinePieceImageSlice(state, *current, image);
452 CSSValueList* slashList = toCSSValueList(current); 452 } else if (current->isValueList()) {
453 size_t length = slashList->length(); 453 const CSSValueList& slashList = toCSSValueList(*current);
454 size_t length = slashList.length();
454 // Map in the image slices. 455 // Map in the image slices.
455 if (length && slashList->item(0)->isBorderImageSliceValue()) 456 if (length && slashList.item(0)->isBorderImageSliceValue())
456 mapNinePieceImageSlice(state, slashList->item(0), image); 457 mapNinePieceImageSlice(state, *slashList.item(0), image);
457 458
458 // Map in the border slices. 459 // Map in the border slices.
459 if (length > 1) 460 if (length > 1)
460 image.setBorderSlices(mapNinePieceImageQuad(state, slashList->it em(1))); 461 image.setBorderSlices(mapNinePieceImageQuad(state, *slashList.it em(1)));
461 462
462 // Map in the outset. 463 // Map in the outset.
463 if (length > 2) 464 if (length > 2)
464 image.setOutset(mapNinePieceImageQuad(state, slashList->item(2)) ); 465 image.setOutset(mapNinePieceImageQuad(state, *slashList.item(2)) );
465 } else if (current->isPrimitiveValue() || current->isValuePair()) { 466 } else if (current->isPrimitiveValue() || current->isValuePair()) {
466 // Set the appropriate rules for stretch/round/repeat of the slices. 467 // Set the appropriate rules for stretch/round/repeat of the slices.
467 mapNinePieceImageRepeat(state, current, image); 468 mapNinePieceImageRepeat(state, *current, image);
468 } 469 }
469 } 470 }
470 471
471 if (property == CSSPropertyWebkitBorderImage) { 472 if (property == CSSPropertyWebkitBorderImage) {
472 // We have to preserve the legacy behavior of -webkit-border-image and m ake the border slices 473 // We have to preserve the legacy behavior of -webkit-border-image and m ake the border slices
473 // also set the border widths. We don't need to worry about percentages, since we don't even support 474 // also set the border widths. We don't need to worry about percentages, since we don't even support
474 // those on real borders yet. 475 // those on real borders yet.
475 if (image.borderSlices().top().isLength() && image.borderSlices().top(). length().isFixed()) 476 if (image.borderSlices().top().isLength() && image.borderSlices().top(). length().isFixed())
476 state.style()->setBorderTopWidth(image.borderSlices().top().length() .value()); 477 state.style()->setBorderTopWidth(image.borderSlices().top().length() .value());
477 if (image.borderSlices().right().isLength() && image.borderSlices().righ t().length().isFixed()) 478 if (image.borderSlices().right().isLength() && image.borderSlices().righ t().length().isFixed())
478 state.style()->setBorderRightWidth(image.borderSlices().right().leng th().value()); 479 state.style()->setBorderRightWidth(image.borderSlices().right().leng th().value());
479 if (image.borderSlices().bottom().isLength() && image.borderSlices().bot tom().length().isFixed()) 480 if (image.borderSlices().bottom().isLength() && image.borderSlices().bot tom().length().isFixed())
480 state.style()->setBorderBottomWidth(image.borderSlices().bottom().le ngth().value()); 481 state.style()->setBorderBottomWidth(image.borderSlices().bottom().le ngth().value());
481 if (image.borderSlices().left().isLength() && image.borderSlices().left( ).length().isFixed()) 482 if (image.borderSlices().left().isLength() && image.borderSlices().left( ).length().isFixed())
482 state.style()->setBorderLeftWidth(image.borderSlices().left().length ().value()); 483 state.style()->setBorderLeftWidth(image.borderSlices().left().length ().value());
483 } 484 }
484 } 485 }
485 486
486 void CSSToStyleMap::mapNinePieceImageSlice(StyleResolverState&, CSSValue* value, NinePieceImage& image) 487 void CSSToStyleMap::mapNinePieceImageSlice(StyleResolverState&, const CSSValue& value, NinePieceImage& image)
487 { 488 {
488 if (!value || !value->isBorderImageSliceValue()) 489 if (!value.isBorderImageSliceValue())
489 return; 490 return;
490 491
491 // Retrieve the border image value. 492 // Retrieve the border image value.
492 CSSBorderImageSliceValue* borderImageSlice = toCSSBorderImageSliceValue(valu e); 493 const CSSBorderImageSliceValue& borderImageSlice = toCSSBorderImageSliceValu e(value);
493 494
494 // Set up a length box to represent our image slices. 495 // Set up a length box to represent our image slices.
495 LengthBox box; 496 LengthBox box;
496 CSSQuadValue* slices = borderImageSlice->slices(); 497 CSSQuadValue* slices = borderImageSlice.slices();
497 if (slices->top()->isPercentage()) 498 if (slices->top()->isPercentage())
498 box.m_top = Length(slices->top()->getDoubleValue(), Percent); 499 box.m_top = Length(slices->top()->getDoubleValue(), Percent);
499 else 500 else
500 box.m_top = Length(slices->top()->getIntValue(), Fixed); 501 box.m_top = Length(slices->top()->getIntValue(), Fixed);
501 if (slices->bottom()->isPercentage()) 502 if (slices->bottom()->isPercentage())
502 box.m_bottom = Length(slices->bottom()->getDoubleValue(), Percent); 503 box.m_bottom = Length(slices->bottom()->getDoubleValue(), Percent);
503 else 504 else
504 box.m_bottom = Length(slices->bottom()->getIntValue(), Fixed); 505 box.m_bottom = Length(slices->bottom()->getIntValue(), Fixed);
505 if (slices->left()->isPercentage()) 506 if (slices->left()->isPercentage())
506 box.m_left = Length(slices->left()->getDoubleValue(), Percent); 507 box.m_left = Length(slices->left()->getDoubleValue(), Percent);
507 else 508 else
508 box.m_left = Length(slices->left()->getIntValue(), Fixed); 509 box.m_left = Length(slices->left()->getIntValue(), Fixed);
509 if (slices->right()->isPercentage()) 510 if (slices->right()->isPercentage())
510 box.m_right = Length(slices->right()->getDoubleValue(), Percent); 511 box.m_right = Length(slices->right()->getDoubleValue(), Percent);
511 else 512 else
512 box.m_right = Length(slices->right()->getIntValue(), Fixed); 513 box.m_right = Length(slices->right()->getIntValue(), Fixed);
513 image.setImageSlices(box); 514 image.setImageSlices(box);
514 515
515 // Set our fill mode. 516 // Set our fill mode.
516 image.setFill(borderImageSlice->m_fill); 517 image.setFill(borderImageSlice.m_fill);
517 } 518 }
518 519
519 static BorderImageLength toBorderImageLength(CSSPrimitiveValue& value, const CSS ToLengthConversionData& conversionData) 520 static BorderImageLength toBorderImageLength(CSSPrimitiveValue& value, const CSS ToLengthConversionData& conversionData)
520 { 521 {
521 if (value.isNumber()) 522 if (value.isNumber())
522 return value.getDoubleValue(); 523 return value.getDoubleValue();
523 if (value.isPercentage()) 524 if (value.isPercentage())
524 return Length(value.getDoubleValue(), Percent); 525 return Length(value.getDoubleValue(), Percent);
525 if (value.getValueID() != CSSValueAuto) 526 if (value.getValueID() != CSSValueAuto)
526 return value.computeLength<Length>(conversionData); 527 return value.computeLength<Length>(conversionData);
527 return Length(Auto); 528 return Length(Auto);
528 } 529 }
529 530
530 BorderImageLengthBox CSSToStyleMap::mapNinePieceImageQuad(StyleResolverState& st ate, CSSValue* value) 531 BorderImageLengthBox CSSToStyleMap::mapNinePieceImageQuad(StyleResolverState& st ate, const CSSValue& value)
531 { 532 {
532 if (!value || !value->isQuadValue()) 533 if (!value.isQuadValue())
533 return BorderImageLengthBox(Length(Auto)); 534 return BorderImageLengthBox(Length(Auto));
534 535
535 RefPtrWillBeRawPtr<CSSQuadValue> slices = toCSSQuadValue(value); 536 const CSSQuadValue& slices = toCSSQuadValue(value);
536 537
537 // Set up a border image length box to represent our image slices. 538 // Set up a border image length box to represent our image slices.
538 return BorderImageLengthBox( 539 return BorderImageLengthBox(
539 toBorderImageLength(*slices->top(), state.cssToLengthConversionData()), 540 toBorderImageLength(*slices.top(), state.cssToLengthConversionData()),
540 toBorderImageLength(*slices->right(), state.cssToLengthConversionData()) , 541 toBorderImageLength(*slices.right(), state.cssToLengthConversionData()),
541 toBorderImageLength(*slices->bottom(), state.cssToLengthConversionData() ), 542 toBorderImageLength(*slices.bottom(), state.cssToLengthConversionData()) ,
542 toBorderImageLength(*slices->left(), state.cssToLengthConversionData())) ; 543 toBorderImageLength(*slices.left(), state.cssToLengthConversionData()));
543 } 544 }
544 545
545 void CSSToStyleMap::mapNinePieceImageRepeat(StyleResolverState&, CSSValue* value , NinePieceImage& image) 546 void CSSToStyleMap::mapNinePieceImageRepeat(StyleResolverState&, const CSSValue& value, NinePieceImage& image)
546 { 547 {
547 if (!value || !value->isValuePair()) 548 if (!value.isValuePair())
548 return; 549 return;
549 550
550 const CSSValuePair& pair = toCSSValuePair(*value); 551 const CSSValuePair& pair = toCSSValuePair(value);
551 CSSValueID firstIdentifier = toCSSPrimitiveValue(pair.first()).getValueID(); 552 CSSValueID firstIdentifier = toCSSPrimitiveValue(pair.first()).getValueID();
552 CSSValueID secondIdentifier = toCSSPrimitiveValue(pair.second()).getValueID( ); 553 CSSValueID secondIdentifier = toCSSPrimitiveValue(pair.second()).getValueID( );
553 554
554 ENinePieceImageRule horizontalRule; 555 ENinePieceImageRule horizontalRule;
555 switch (firstIdentifier) { 556 switch (firstIdentifier) {
556 case CSSValueStretch: 557 case CSSValueStretch:
557 horizontalRule = StretchImageRule; 558 horizontalRule = StretchImageRule;
558 break; 559 break;
559 case CSSValueRound: 560 case CSSValueRound:
560 horizontalRule = RoundImageRule; 561 horizontalRule = RoundImageRule;
(...skipping 19 matching lines...) Expand all
580 verticalRule = SpaceImageRule; 581 verticalRule = SpaceImageRule;
581 break; 582 break;
582 default: // CSSValueRepeat 583 default: // CSSValueRepeat
583 verticalRule = RepeatImageRule; 584 verticalRule = RepeatImageRule;
584 break; 585 break;
585 } 586 }
586 image.setVerticalRule(verticalRule); 587 image.setVerticalRule(verticalRule);
587 } 588 }
588 589
589 }; 590 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698