Chromium Code Reviews| 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::hasZoomedLength(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) |
|
dstockwell
2015/08/31 05:33:39
Do we usually say 'pixels' or 'px'?
Why do we onl
alancutter (OOO until 2018)
2015/08/31 07:15:30
All the existing keywords are in pixels.
| |
| 21 { | 56 { |
| 22 ASSERT(property == CSSPropertyLeft); | 57 switch (property) { |
| 23 return false; | 58 case CSSPropertyBaselineShift: |
| 59 if (valueID == CSSValueBaseline) { | |
|
dstockwell
2015/08/31 05:33:39
This looks painful to maintain, how can we keep it
alancutter (OOO until 2018)
2015/08/31 07:15:29
We could expose this function to StyleBuilderConve
| |
| 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 use the wrong value for hi dden widths. | |
| 108 // This is acceptable since animations on hidden widths are unobservable to the user, even via getComputedStyle(). | |
| 109 case CSSPropertyBorderBottomWidth: | |
|
dstockwell
2015/08/31 05:33:39
Why do we need to treat these differently?
alancutter (OOO until 2018)
2015/08/31 07:15:30
See above comment.
alancutter (OOO until 2018)
2015/08/31 07:20:51
Updated comment to not have grammatical error.
| |
| 110 case CSSPropertyBorderLeftWidth: | |
| 111 case CSSPropertyBorderRightWidth: | |
| 112 case CSSPropertyBorderTopWidth: | |
| 113 result = lengthFromUnsigned(ComputedStyle::initialBorderWidth()); | |
| 114 return true; | |
| 115 case CSSPropertyOutlineWidth: | |
| 116 result = lengthFromUnsigned(ComputedStyle::initialOutlineWidth()); | |
| 117 return true; | |
| 118 case CSSPropertyWebkitColumnRuleWidth: | |
| 119 result = lengthFromUnsigned(ComputedStyle::initialColumnRuleWidth()); | |
| 120 return true; | |
| 121 | |
| 122 default: | |
| 123 return getLength(property, *ComputedStyle::initialStyle(), result); | |
| 124 } | |
| 24 } | 125 } |
| 25 | 126 |
| 26 bool LengthPropertyFunctions::getLength(CSSPropertyID property, const ComputedSt yle& style, Length& result) | 127 bool LengthPropertyFunctions::getLength(CSSPropertyID property, const ComputedSt yle& style, Length& result) |
| 27 { | 128 { |
| 28 ASSERT(property == CSSPropertyLeft); | 129 switch (property) { |
| 29 result = style.left(); | 130 case CSSPropertyBottom: |
| 30 return true; | 131 result = style.bottom(); |
| 31 } | 132 return true; |
| 32 | 133 case CSSPropertyCx: |
| 33 bool LengthPropertyFunctions::getInitialLength(CSSPropertyID property, Length& r esult) | 134 result = style.svgStyle().cx(); |
| 34 { | 135 return true; |
| 35 return getLength(property, *ComputedStyle::initialStyle(), result); | 136 case CSSPropertyCy: |
| 137 result = style.svgStyle().cy(); | |
| 138 return true; | |
| 139 case CSSPropertyFlexBasis: | |
| 140 result = style.flexBasis(); | |
| 141 return true; | |
| 142 case CSSPropertyHeight: | |
| 143 result = style.height(); | |
| 144 return true; | |
| 145 case CSSPropertyLeft: | |
| 146 result = style.left(); | |
| 147 return true; | |
| 148 case CSSPropertyMarginBottom: | |
| 149 result = style.marginBottom(); | |
| 150 return true; | |
| 151 case CSSPropertyMarginLeft: | |
| 152 result = style.marginLeft(); | |
| 153 return true; | |
| 154 case CSSPropertyMarginRight: | |
| 155 result = style.marginRight(); | |
| 156 return true; | |
| 157 case CSSPropertyMarginTop: | |
| 158 result = style.marginTop(); | |
| 159 return true; | |
| 160 case CSSPropertyMaxHeight: | |
| 161 result = style.maxHeight(); | |
| 162 return true; | |
| 163 case CSSPropertyMaxWidth: | |
| 164 result = style.maxWidth(); | |
| 165 return true; | |
| 166 case CSSPropertyMinHeight: | |
| 167 result = style.minHeight(); | |
| 168 return true; | |
| 169 case CSSPropertyMinWidth: | |
| 170 result = style.minWidth(); | |
| 171 return true; | |
| 172 case CSSPropertyMotionOffset: | |
| 173 result = style.motionOffset(); | |
| 174 return true; | |
| 175 case CSSPropertyPaddingBottom: | |
| 176 result = style.paddingBottom(); | |
| 177 return true; | |
| 178 case CSSPropertyPaddingLeft: | |
| 179 result = style.paddingLeft(); | |
| 180 return true; | |
| 181 case CSSPropertyPaddingRight: | |
| 182 result = style.paddingRight(); | |
| 183 return true; | |
| 184 case CSSPropertyPaddingTop: | |
| 185 result = style.paddingTop(); | |
| 186 return true; | |
| 187 case CSSPropertyR: | |
| 188 result = style.svgStyle().r(); | |
| 189 return true; | |
| 190 case CSSPropertyRight: | |
| 191 result = style.right(); | |
| 192 return true; | |
| 193 case CSSPropertyRx: | |
| 194 result = style.svgStyle().rx(); | |
| 195 return true; | |
| 196 case CSSPropertyRy: | |
| 197 result = style.svgStyle().ry(); | |
| 198 return true; | |
| 199 case CSSPropertyShapeMargin: | |
| 200 result = style.shapeMargin(); | |
| 201 return true; | |
| 202 case CSSPropertyStrokeDashoffset: | |
| 203 result = style.strokeDashOffset(); | |
| 204 return true; | |
| 205 case CSSPropertyTextIndent: | |
| 206 result = style.textIndent(); | |
| 207 return true; | |
| 208 case CSSPropertyTop: | |
| 209 result = style.top(); | |
| 210 return true; | |
| 211 case CSSPropertyWebkitPerspectiveOriginX: | |
| 212 result = style.perspectiveOriginX(); | |
| 213 return true; | |
| 214 case CSSPropertyWebkitPerspectiveOriginY: | |
| 215 result = style.perspectiveOriginY(); | |
| 216 return true; | |
| 217 case CSSPropertyWebkitTransformOriginX: | |
| 218 result = style.transformOriginX(); | |
| 219 return true; | |
| 220 case CSSPropertyWebkitTransformOriginY: | |
| 221 result = style.transformOriginY(); | |
| 222 return true; | |
| 223 case CSSPropertyWidth: | |
| 224 result = style.width(); | |
| 225 return true; | |
| 226 case CSSPropertyX: | |
| 227 result = style.svgStyle().x(); | |
| 228 return true; | |
| 229 case CSSPropertyY: | |
| 230 result = style.svgStyle().y(); | |
| 231 return true; | |
| 232 | |
| 233 case CSSPropertyBorderBottomWidth: | |
| 234 result = Length(style.borderBottomWidth(), Fixed); | |
| 235 return true; | |
| 236 case CSSPropertyBorderLeftWidth: | |
| 237 result = Length(style.borderLeftWidth(), Fixed); | |
| 238 return true; | |
| 239 case CSSPropertyBorderRightWidth: | |
| 240 result = Length(style.borderRightWidth(), Fixed); | |
| 241 return true; | |
| 242 case CSSPropertyBorderTopWidth: | |
| 243 result = Length(style.borderTopWidth(), Fixed); | |
| 244 return true; | |
| 245 case CSSPropertyLetterSpacing: | |
| 246 result = Length(style.letterSpacing(), Fixed); | |
| 247 return true; | |
| 248 case CSSPropertyOutlineOffset: | |
| 249 result = Length(style.outlineOffset(), Fixed); | |
| 250 return true; | |
| 251 case CSSPropertyOutlineWidth: | |
| 252 result = Length(style.outlineWidth(), Fixed); | |
| 253 return true; | |
| 254 case CSSPropertyWebkitBorderHorizontalSpacing: | |
| 255 result = Length(style.horizontalBorderSpacing(), Fixed); | |
| 256 return true; | |
| 257 case CSSPropertyWebkitBorderVerticalSpacing: | |
| 258 result = Length(style.verticalBorderSpacing(), Fixed); | |
| 259 return true; | |
| 260 case CSSPropertyWebkitColumnGap: | |
| 261 result = Length(style.columnGap(), Fixed); | |
| 262 return true; | |
| 263 case CSSPropertyWebkitColumnRuleWidth: | |
| 264 result = Length(style.columnRuleWidth(), Fixed); | |
| 265 return true; | |
| 266 case CSSPropertyWebkitTransformOriginZ: | |
| 267 result = Length(style.transformOriginZ(), Fixed); | |
| 268 return true; | |
| 269 case CSSPropertyWordSpacing: | |
| 270 result = Length(style.wordSpacing(), Fixed); | |
| 271 return true; | |
| 272 | |
| 273 case CSSPropertyBaselineShift: | |
| 274 if (style.baselineShift() != BS_LENGTH) | |
| 275 return false; | |
| 276 result = style.baselineShiftValue(); | |
| 277 return true; | |
| 278 case CSSPropertyPerspective: | |
| 279 // 0 represents the "none" keyword. | |
|
dstockwell
2015/08/31 05:33:39
We should add a style.hasPerspective and assert in
alancutter (OOO until 2018)
2015/08/31 07:15:30
Turns out hasPerspective() already exists. Adding
| |
| 280 if (style.perspective() == 0) | |
| 281 return false; | |
| 282 result = Length(style.perspective(), Fixed); | |
| 283 return true; | |
| 284 case CSSPropertyStrokeWidth: | |
| 285 ASSERT(!hasZoomedLength(CSSPropertyStrokeWidth)); | |
|
dstockwell
2015/08/31 05:33:39
Why do we assert this?
alancutter (OOO until 2018)
2015/08/31 07:15:29
style.strokeWidth() returns an UnzoomedLength from
| |
| 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) | |
|
dstockwell
2015/08/31 05:33:39
Why did we move away from the setter based approac
alancutter (OOO until 2018)
2015/08/31 07:15:30
Windows was getting crazy pants runtime crashes th
| |
| 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 |