OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "config.h" | 5 #include "config.h" |
6 #include "core/animation/LengthPropertyFunctions.h" | 6 #include "core/animation/LengthPropertyFunctions.h" |
7 | 7 |
8 #include "core/style/ComputedStyle.h" | 8 #include "core/style/ComputedStyle.h" |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
12 // TODO(alancutter): Generate these functions. | 12 // TODO(alancutter): Generate these functions. |
13 | 13 |
14 ValueRange LengthPropertyFunctions::valueRange(CSSPropertyID property) | 14 ValueRange LengthPropertyFunctions::valueRange(CSSPropertyID property) |
15 { | 15 { |
16 ASSERT(property == CSSPropertyLeft); | 16 switch (property) { |
17 return ValueRangeAll; | 17 case CSSPropertyBorderBottomWidth: |
| 18 case CSSPropertyBorderLeftWidth: |
| 19 case CSSPropertyBorderRightWidth: |
| 20 case CSSPropertyBorderTopWidth: |
| 21 case CSSPropertyFlexBasis: |
| 22 case CSSPropertyHeight: |
| 23 case CSSPropertyLineHeight: |
| 24 case CSSPropertyMaxHeight: |
| 25 case CSSPropertyMaxWidth: |
| 26 case CSSPropertyMinHeight: |
| 27 case CSSPropertyMinWidth: |
| 28 case CSSPropertyOutlineWidth: |
| 29 case CSSPropertyPaddingBottom: |
| 30 case CSSPropertyPaddingLeft: |
| 31 case CSSPropertyPaddingRight: |
| 32 case CSSPropertyPaddingTop: |
| 33 case CSSPropertyPerspective: |
| 34 case CSSPropertyR: |
| 35 case CSSPropertyRx: |
| 36 case CSSPropertyRy: |
| 37 case CSSPropertyShapeMargin: |
| 38 case CSSPropertyStrokeWidth: |
| 39 case CSSPropertyWebkitBorderHorizontalSpacing: |
| 40 case CSSPropertyWebkitBorderVerticalSpacing: |
| 41 case CSSPropertyWebkitColumnGap: |
| 42 case CSSPropertyWebkitColumnWidth: |
| 43 case CSSPropertyWidth: |
| 44 return ValueRangeNonNegative; |
| 45 default: |
| 46 return ValueRangeAll; |
| 47 } |
| 48 } |
| 49 |
| 50 bool LengthPropertyFunctions::isZoomedLength(CSSPropertyID property) |
| 51 { |
| 52 return property != CSSPropertyStrokeWidth; |
18 } | 53 } |
19 | 54 |
20 bool LengthPropertyFunctions::getPixelsForKeyword(CSSPropertyID property, CSSVal
ueID valueID, double& result) | 55 bool LengthPropertyFunctions::getPixelsForKeyword(CSSPropertyID property, CSSVal
ueID valueID, double& result) |
21 { | 56 { |
22 ASSERT(property == CSSPropertyLeft); | 57 switch (property) { |
23 return false; | 58 case CSSPropertyBaselineShift: |
| 59 if (valueID == CSSValueBaseline) { |
| 60 result = 0; |
| 61 return true; |
| 62 } |
| 63 return false; |
| 64 case CSSPropertyBorderBottomWidth: |
| 65 case CSSPropertyBorderLeftWidth: |
| 66 case CSSPropertyBorderRightWidth: |
| 67 case CSSPropertyBorderTopWidth: |
| 68 case CSSPropertyWebkitColumnRuleWidth: |
| 69 case CSSPropertyOutlineWidth: |
| 70 if (valueID == CSSValueThin) { |
| 71 result = 1; |
| 72 return true; |
| 73 } |
| 74 if (valueID == CSSValueMedium) { |
| 75 result = 3; |
| 76 return true; |
| 77 } |
| 78 if (valueID == CSSValueThick) { |
| 79 result = 5; |
| 80 return true; |
| 81 } |
| 82 return false; |
| 83 case CSSPropertyLetterSpacing: |
| 84 case CSSPropertyWordSpacing: |
| 85 if (valueID == CSSValueNormal) { |
| 86 result = 0; |
| 87 return true; |
| 88 } |
| 89 return false; |
| 90 default: |
| 91 return false; |
| 92 } |
| 93 } |
| 94 |
| 95 static Length lengthFromUnsigned(unsigned short value) |
| 96 { |
| 97 return Length(static_cast<float>(value), Fixed); |
| 98 } |
| 99 |
| 100 bool LengthPropertyFunctions::getInitialLength(CSSPropertyID property, Length& r
esult) |
| 101 { |
| 102 switch (property) { |
| 103 // The computed value of "initial" for the following properties is 0px if th
e associated *-style property resolves to "none" or "hidden". |
| 104 // border-width: https://drafts.csswg.org/css-backgrounds-3/#the-border-widt
h |
| 105 // outline-width: https://drafts.csswg.org/css-ui-3/#outline-width |
| 106 // -webkit-column-rule-width: https://drafts.csswg.org/css-multicol-1/#crw |
| 107 // We ignore this value adjustment for animations and use the wrong value fo
r hidden widths to avoid |
| 108 // having to restart our animations based on the computed *-style values. |
| 109 // This is acceptable since animations running on hidden widths are unobserv
able to the user, even via getComputedStyle(). |
| 110 case CSSPropertyBorderBottomWidth: |
| 111 case CSSPropertyBorderLeftWidth: |
| 112 case CSSPropertyBorderRightWidth: |
| 113 case CSSPropertyBorderTopWidth: |
| 114 result = lengthFromUnsigned(ComputedStyle::initialBorderWidth()); |
| 115 return true; |
| 116 case CSSPropertyOutlineWidth: |
| 117 result = lengthFromUnsigned(ComputedStyle::initialOutlineWidth()); |
| 118 return true; |
| 119 case CSSPropertyWebkitColumnRuleWidth: |
| 120 result = lengthFromUnsigned(ComputedStyle::initialColumnRuleWidth()); |
| 121 return true; |
| 122 |
| 123 default: |
| 124 return getLength(property, *ComputedStyle::initialStyle(), result); |
| 125 } |
24 } | 126 } |
25 | 127 |
26 bool LengthPropertyFunctions::getLength(CSSPropertyID property, const ComputedSt
yle& style, Length& result) | 128 bool LengthPropertyFunctions::getLength(CSSPropertyID property, const ComputedSt
yle& style, Length& result) |
27 { | 129 { |
28 ASSERT(property == CSSPropertyLeft); | 130 switch (property) { |
29 result = style.left(); | 131 case CSSPropertyBottom: |
30 return true; | 132 result = style.bottom(); |
31 } | 133 return true; |
32 | 134 case CSSPropertyCx: |
33 bool LengthPropertyFunctions::getInitialLength(CSSPropertyID property, Length& r
esult) | 135 result = style.svgStyle().cx(); |
34 { | 136 return true; |
35 return getLength(property, *ComputedStyle::initialStyle(), result); | 137 case CSSPropertyCy: |
| 138 result = style.svgStyle().cy(); |
| 139 return true; |
| 140 case CSSPropertyFlexBasis: |
| 141 result = style.flexBasis(); |
| 142 return true; |
| 143 case CSSPropertyHeight: |
| 144 result = style.height(); |
| 145 return true; |
| 146 case CSSPropertyLeft: |
| 147 result = style.left(); |
| 148 return true; |
| 149 case CSSPropertyMarginBottom: |
| 150 result = style.marginBottom(); |
| 151 return true; |
| 152 case CSSPropertyMarginLeft: |
| 153 result = style.marginLeft(); |
| 154 return true; |
| 155 case CSSPropertyMarginRight: |
| 156 result = style.marginRight(); |
| 157 return true; |
| 158 case CSSPropertyMarginTop: |
| 159 result = style.marginTop(); |
| 160 return true; |
| 161 case CSSPropertyMaxHeight: |
| 162 result = style.maxHeight(); |
| 163 return true; |
| 164 case CSSPropertyMaxWidth: |
| 165 result = style.maxWidth(); |
| 166 return true; |
| 167 case CSSPropertyMinHeight: |
| 168 result = style.minHeight(); |
| 169 return true; |
| 170 case CSSPropertyMinWidth: |
| 171 result = style.minWidth(); |
| 172 return true; |
| 173 case CSSPropertyMotionOffset: |
| 174 result = style.motionOffset(); |
| 175 return true; |
| 176 case CSSPropertyPaddingBottom: |
| 177 result = style.paddingBottom(); |
| 178 return true; |
| 179 case CSSPropertyPaddingLeft: |
| 180 result = style.paddingLeft(); |
| 181 return true; |
| 182 case CSSPropertyPaddingRight: |
| 183 result = style.paddingRight(); |
| 184 return true; |
| 185 case CSSPropertyPaddingTop: |
| 186 result = style.paddingTop(); |
| 187 return true; |
| 188 case CSSPropertyR: |
| 189 result = style.svgStyle().r(); |
| 190 return true; |
| 191 case CSSPropertyRight: |
| 192 result = style.right(); |
| 193 return true; |
| 194 case CSSPropertyRx: |
| 195 result = style.svgStyle().rx(); |
| 196 return true; |
| 197 case CSSPropertyRy: |
| 198 result = style.svgStyle().ry(); |
| 199 return true; |
| 200 case CSSPropertyShapeMargin: |
| 201 result = style.shapeMargin(); |
| 202 return true; |
| 203 case CSSPropertyStrokeDashoffset: |
| 204 result = style.strokeDashOffset(); |
| 205 return true; |
| 206 case CSSPropertyTextIndent: |
| 207 result = style.textIndent(); |
| 208 return true; |
| 209 case CSSPropertyTop: |
| 210 result = style.top(); |
| 211 return true; |
| 212 case CSSPropertyWebkitPerspectiveOriginX: |
| 213 result = style.perspectiveOriginX(); |
| 214 return true; |
| 215 case CSSPropertyWebkitPerspectiveOriginY: |
| 216 result = style.perspectiveOriginY(); |
| 217 return true; |
| 218 case CSSPropertyWebkitTransformOriginX: |
| 219 result = style.transformOriginX(); |
| 220 return true; |
| 221 case CSSPropertyWebkitTransformOriginY: |
| 222 result = style.transformOriginY(); |
| 223 return true; |
| 224 case CSSPropertyWidth: |
| 225 result = style.width(); |
| 226 return true; |
| 227 case CSSPropertyX: |
| 228 result = style.svgStyle().x(); |
| 229 return true; |
| 230 case CSSPropertyY: |
| 231 result = style.svgStyle().y(); |
| 232 return true; |
| 233 |
| 234 case CSSPropertyBorderBottomWidth: |
| 235 result = Length(style.borderBottomWidth(), Fixed); |
| 236 return true; |
| 237 case CSSPropertyBorderLeftWidth: |
| 238 result = Length(style.borderLeftWidth(), Fixed); |
| 239 return true; |
| 240 case CSSPropertyBorderRightWidth: |
| 241 result = Length(style.borderRightWidth(), Fixed); |
| 242 return true; |
| 243 case CSSPropertyBorderTopWidth: |
| 244 result = Length(style.borderTopWidth(), Fixed); |
| 245 return true; |
| 246 case CSSPropertyLetterSpacing: |
| 247 result = Length(style.letterSpacing(), Fixed); |
| 248 return true; |
| 249 case CSSPropertyOutlineOffset: |
| 250 result = Length(style.outlineOffset(), Fixed); |
| 251 return true; |
| 252 case CSSPropertyOutlineWidth: |
| 253 result = Length(style.outlineWidth(), Fixed); |
| 254 return true; |
| 255 case CSSPropertyWebkitBorderHorizontalSpacing: |
| 256 result = Length(style.horizontalBorderSpacing(), Fixed); |
| 257 return true; |
| 258 case CSSPropertyWebkitBorderVerticalSpacing: |
| 259 result = Length(style.verticalBorderSpacing(), Fixed); |
| 260 return true; |
| 261 case CSSPropertyWebkitColumnGap: |
| 262 result = Length(style.columnGap(), Fixed); |
| 263 return true; |
| 264 case CSSPropertyWebkitColumnRuleWidth: |
| 265 result = Length(style.columnRuleWidth(), Fixed); |
| 266 return true; |
| 267 case CSSPropertyWebkitTransformOriginZ: |
| 268 result = Length(style.transformOriginZ(), Fixed); |
| 269 return true; |
| 270 case CSSPropertyWordSpacing: |
| 271 result = Length(style.wordSpacing(), Fixed); |
| 272 return true; |
| 273 |
| 274 case CSSPropertyBaselineShift: |
| 275 if (style.baselineShift() != BS_LENGTH) |
| 276 return false; |
| 277 result = style.baselineShiftValue(); |
| 278 return true; |
| 279 case CSSPropertyPerspective: |
| 280 if (!style.hasPerspective()) |
| 281 return false; |
| 282 result = Length(style.perspective(), Fixed); |
| 283 return true; |
| 284 case CSSPropertyStrokeWidth: |
| 285 ASSERT(!isZoomedLength(CSSPropertyStrokeWidth)); |
| 286 result = style.strokeWidth().length(); |
| 287 return true; |
| 288 case CSSPropertyVerticalAlign: |
| 289 if (style.verticalAlign() != LENGTH) |
| 290 return false; |
| 291 result = style.verticalAlignLength(); |
| 292 return true; |
| 293 case CSSPropertyWebkitColumnWidth: |
| 294 if (style.hasAutoColumnWidth()) |
| 295 return false; |
| 296 result = Length(style.columnWidth(), Fixed); |
| 297 return true; |
| 298 default: |
| 299 return false; |
| 300 } |
| 301 } |
| 302 |
| 303 bool LengthPropertyFunctions::setLength(CSSPropertyID property, ComputedStyle& s
tyle, const Length& value) |
| 304 { |
| 305 switch (property) { |
| 306 // Setters that take a Length value. |
| 307 case CSSPropertyBaselineShift: |
| 308 style.setBaselineShiftValue(value); |
| 309 return true; |
| 310 case CSSPropertyBottom: |
| 311 style.setBottom(value); |
| 312 return true; |
| 313 case CSSPropertyCx: |
| 314 style.setCx(value); |
| 315 return true; |
| 316 case CSSPropertyCy: |
| 317 style.setCy(value); |
| 318 return true; |
| 319 case CSSPropertyFlexBasis: |
| 320 style.setFlexBasis(value); |
| 321 return true; |
| 322 case CSSPropertyHeight: |
| 323 style.setHeight(value); |
| 324 return true; |
| 325 case CSSPropertyLeft: |
| 326 style.setLeft(value); |
| 327 return true; |
| 328 case CSSPropertyLineHeight: |
| 329 style.setLineHeight(value); |
| 330 return true; |
| 331 case CSSPropertyMarginBottom: |
| 332 style.setMarginBottom(value); |
| 333 return true; |
| 334 case CSSPropertyMarginLeft: |
| 335 style.setMarginLeft(value); |
| 336 return true; |
| 337 case CSSPropertyMarginRight: |
| 338 style.setMarginRight(value); |
| 339 return true; |
| 340 case CSSPropertyMarginTop: |
| 341 style.setMarginTop(value); |
| 342 return true; |
| 343 case CSSPropertyMaxHeight: |
| 344 style.setMaxHeight(value); |
| 345 return true; |
| 346 case CSSPropertyMaxWidth: |
| 347 style.setMaxWidth(value); |
| 348 return true; |
| 349 case CSSPropertyMinHeight: |
| 350 style.setMinHeight(value); |
| 351 return true; |
| 352 case CSSPropertyMinWidth: |
| 353 style.setMinWidth(value); |
| 354 return true; |
| 355 case CSSPropertyMotionOffset: |
| 356 style.setMotionOffset(value); |
| 357 return true; |
| 358 case CSSPropertyPaddingBottom: |
| 359 style.setPaddingBottom(value); |
| 360 return true; |
| 361 case CSSPropertyPaddingLeft: |
| 362 style.setPaddingLeft(value); |
| 363 return true; |
| 364 case CSSPropertyPaddingRight: |
| 365 style.setPaddingRight(value); |
| 366 return true; |
| 367 case CSSPropertyPaddingTop: |
| 368 style.setPaddingTop(value); |
| 369 return true; |
| 370 case CSSPropertyR: |
| 371 style.setR(value); |
| 372 return true; |
| 373 case CSSPropertyRx: |
| 374 style.setRx(value); |
| 375 return true; |
| 376 case CSSPropertyRy: |
| 377 style.setRy(value); |
| 378 return true; |
| 379 case CSSPropertyRight: |
| 380 style.setRight(value); |
| 381 return true; |
| 382 case CSSPropertyShapeMargin: |
| 383 style.setShapeMargin(value); |
| 384 return true; |
| 385 case CSSPropertyStrokeDashoffset: |
| 386 style.setStrokeDashOffset(value); |
| 387 return true; |
| 388 case CSSPropertyTop: |
| 389 style.setTop(value); |
| 390 return true; |
| 391 case CSSPropertyWidth: |
| 392 style.setWidth(value); |
| 393 return true; |
| 394 case CSSPropertyWebkitPerspectiveOriginX: |
| 395 style.setPerspectiveOriginX(value); |
| 396 return true; |
| 397 case CSSPropertyWebkitPerspectiveOriginY: |
| 398 style.setPerspectiveOriginY(value); |
| 399 return true; |
| 400 case CSSPropertyWebkitTransformOriginX: |
| 401 style.setTransformOriginX(value); |
| 402 return true; |
| 403 case CSSPropertyWebkitTransformOriginY: |
| 404 style.setTransformOriginY(value); |
| 405 return true; |
| 406 case CSSPropertyX: |
| 407 style.setX(value); |
| 408 return true; |
| 409 case CSSPropertyY: |
| 410 style.setY(value); |
| 411 return true; |
| 412 |
| 413 // TODO(alancutter): Support setters that take a numeric value (need to reso
lve percentages). |
| 414 case CSSPropertyBorderBottomWidth: |
| 415 case CSSPropertyBorderLeftWidth: |
| 416 case CSSPropertyBorderRightWidth: |
| 417 case CSSPropertyBorderTopWidth: |
| 418 case CSSPropertyLetterSpacing: |
| 419 case CSSPropertyOutlineOffset: |
| 420 case CSSPropertyOutlineWidth: |
| 421 case CSSPropertyPerspective: |
| 422 case CSSPropertyStrokeWidth: |
| 423 case CSSPropertyVerticalAlign: |
| 424 case CSSPropertyWebkitBorderHorizontalSpacing: |
| 425 case CSSPropertyWebkitBorderVerticalSpacing: |
| 426 case CSSPropertyWebkitColumnGap: |
| 427 case CSSPropertyWebkitColumnRuleWidth: |
| 428 case CSSPropertyWebkitColumnWidth: |
| 429 case CSSPropertyWebkitTransformOriginZ: |
| 430 case CSSPropertyWordSpacing: |
| 431 return false; |
| 432 |
| 433 default: |
| 434 return false; |
| 435 } |
36 } | 436 } |
37 | 437 |
38 } // namespace blink | 438 } // namespace blink |
OLD | NEW |