1 /* 2 * Copyright (C) 2004 Zack Rusin <zack (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 4 * Copyright (C) 2007 Alexey Proskuryakov <ap (at) webkit.org> 5 * Copyright (C) 2007 Nicholas Shanks <webkit (at) nickshanks.com> 6 * Copyright (C) 2011 Sencha, Inc. All rights reserved. 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 21 * 02110-1301 USA 22 */ 23 24 #include "config.h" 25 #include "core/css/CSSComputedStyleDeclaration.h" 26 27 #include "bindings/core/v8/ExceptionState.h" 28 #include "core/CSSPropertyNames.h" 29 #include "core/StylePropertyShorthand.h" 30 #include "core/animation/DocumentAnimations.h" 31 #include "core/css/BasicShapeFunctions.h" 32 #include "core/css/CSSAspectRatioValue.h" 33 #include "core/css/CSSBorderImage.h" 34 #include "core/css/CSSFilterValue.h" 35 #include "core/css/CSSFontFeatureValue.h" 36 #include "core/css/CSSFontValue.h" 37 #include "core/css/CSSFunctionValue.h" 38 #include "core/css/CSSGridLineNamesValue.h" 39 #include "core/css/CSSGridTemplateAreasValue.h" 40 #include "core/css/CSSLineBoxContainValue.h" 41 #include "core/css/CSSPrimitiveValue.h" 42 #include "core/css/CSSPrimitiveValueMappings.h" 43 #include "core/css/CSSPropertyMetadata.h" 44 #include "core/css/CSSReflectValue.h" 45 #include "core/css/CSSSelector.h" 46 #include "core/css/CSSShadowValue.h" 47 #include "core/css/CSSTimingFunctionValue.h" 48 #include "core/css/CSSTransformValue.h" 49 #include "core/css/CSSValueList.h" 50 #include "core/css/CSSValuePool.h" 51 #include "core/css/Pair.h" 52 #include "core/css/Rect.h" 53 #include "core/css/StylePropertySet.h" 54 #include "core/css/parser/CSSParser.h" 55 #include "core/css/resolver/StyleResolver.h" 56 #include "core/dom/Document.h" 57 #include "core/dom/ExceptionCode.h" 58 #include "core/dom/PseudoElement.h" 59 #include "core/rendering/RenderBox.h" 60 #include "core/rendering/RenderGrid.h" 61 #include "core/rendering/style/ContentData.h" 62 #include "core/rendering/style/CounterContent.h" 63 #include "core/rendering/style/RenderStyle.h" 64 #include "core/rendering/style/ShadowList.h" 65 #include "core/rendering/style/ShapeValue.h" 66 #include "platform/FontFamilyNames.h" 67 #include "platform/RuntimeEnabledFeatures.h" 68 #include "platform/fonts/FontFeatureSettings.h" 69 #include "wtf/text/StringBuilder.h" 70 71 namespace blink { 72 73 // List of all properties we know how to compute, omitting shorthands. 74 // NOTE: Do not use this list, use computableProperties() instead 75 // to respect runtime enabling of CSS properties. 76 static const CSSPropertyID staticComputableProperties[] = { 77 CSSPropertyAnimationDelay, 78 CSSPropertyAnimationDirection, 79 CSSPropertyAnimationDuration, 80 CSSPropertyAnimationFillMode, 81 CSSPropertyAnimationIterationCount, 82 CSSPropertyAnimationName, 83 CSSPropertyAnimationPlayState, 84 CSSPropertyAnimationTimingFunction, 85 CSSPropertyBackgroundAttachment, 86 CSSPropertyBackgroundBlendMode, 87 CSSPropertyBackgroundClip, 88 CSSPropertyBackgroundColor, 89 CSSPropertyBackgroundImage, 90 CSSPropertyBackgroundOrigin, 91 CSSPropertyBackgroundPosition, // more-specific background-position-x/y are non-standard 92 CSSPropertyBackgroundRepeat, 93 CSSPropertyBackgroundSize, 94 CSSPropertyBorderBottomColor, 95 CSSPropertyBorderBottomLeftRadius, 96 CSSPropertyBorderBottomRightRadius, 97 CSSPropertyBorderBottomStyle, 98 CSSPropertyBorderBottomWidth, 99 CSSPropertyBorderCollapse, 100 CSSPropertyBorderImageOutset, 101 CSSPropertyBorderImageRepeat, 102 CSSPropertyBorderImageSlice, 103 CSSPropertyBorderImageSource, 104 CSSPropertyBorderImageWidth, 105 CSSPropertyBorderLeftColor, 106 CSSPropertyBorderLeftStyle, 107 CSSPropertyBorderLeftWidth, 108 CSSPropertyBorderRightColor, 109 CSSPropertyBorderRightStyle, 110 CSSPropertyBorderRightWidth, 111 CSSPropertyBorderTopColor, 112 CSSPropertyBorderTopLeftRadius, 113 CSSPropertyBorderTopRightRadius, 114 CSSPropertyBorderTopStyle, 115 CSSPropertyBorderTopWidth, 116 CSSPropertyBottom, 117 CSSPropertyBoxShadow, 118 CSSPropertyBoxSizing, 119 CSSPropertyCaptionSide, 120 CSSPropertyClear, 121 CSSPropertyClip, 122 CSSPropertyColor, 123 CSSPropertyCursor, 124 CSSPropertyDirection, 125 CSSPropertyDisplay, 126 CSSPropertyEmptyCells, 127 CSSPropertyFloat, 128 CSSPropertyFontFamily, 129 CSSPropertyFontKerning, 130 CSSPropertyFontSize, 131 CSSPropertyFontStretch, 132 CSSPropertyFontStyle, 133 CSSPropertyFontVariant, 134 CSSPropertyFontVariantLigatures, 135 CSSPropertyFontWeight, 136 CSSPropertyHeight, 137 CSSPropertyImageRendering, 138 CSSPropertyIsolation, 139 CSSPropertyJustifyItems, 140 CSSPropertyJustifySelf, 141 CSSPropertyLeft, 142 CSSPropertyLetterSpacing, 143 CSSPropertyLineHeight, 144 CSSPropertyListStyleImage, 145 CSSPropertyListStylePosition, 146 CSSPropertyListStyleType, 147 CSSPropertyMarginBottom, 148 CSSPropertyMarginLeft, 149 CSSPropertyMarginRight, 150 CSSPropertyMarginTop, 151 CSSPropertyMaxHeight, 152 CSSPropertyMaxWidth, 153 CSSPropertyMinHeight, 154 CSSPropertyMinWidth, 155 CSSPropertyMixBlendMode, 156 CSSPropertyObjectFit, 157 CSSPropertyObjectPosition, 158 CSSPropertyOpacity, 159 CSSPropertyOrphans, 160 CSSPropertyOutlineColor, 161 CSSPropertyOutlineOffset, 162 CSSPropertyOutlineStyle, 163 CSSPropertyOutlineWidth, 164 CSSPropertyOverflowWrap, 165 CSSPropertyOverflowX, 166 CSSPropertyOverflowY, 167 CSSPropertyPaddingBottom, 168 CSSPropertyPaddingLeft, 169 CSSPropertyPaddingRight, 170 CSSPropertyPaddingTop, 171 CSSPropertyPageBreakAfter, 172 CSSPropertyPageBreakBefore, 173 CSSPropertyPageBreakInside, 174 CSSPropertyPointerEvents, 175 CSSPropertyPosition, 176 CSSPropertyResize, 177 CSSPropertyRight, 178 CSSPropertyScrollBehavior, 179 CSSPropertySpeak, 180 CSSPropertyTableLayout, 181 CSSPropertyTabSize, 182 CSSPropertyTextAlign, 183 CSSPropertyTextAlignLast, 184 CSSPropertyTextDecoration, 185 CSSPropertyTextDecorationLine, 186 CSSPropertyTextDecorationStyle, 187 CSSPropertyTextDecorationColor, 188 CSSPropertyTextJustify, 189 CSSPropertyTextUnderlinePosition, 190 CSSPropertyTextIndent, 191 CSSPropertyTextRendering, 192 CSSPropertyTextShadow, 193 CSSPropertyTextOverflow, 194 CSSPropertyTextTransform, 195 CSSPropertyTop, 196 CSSPropertyTouchAction, 197 CSSPropertyTouchActionDelay, 198 CSSPropertyTransitionDelay, 199 CSSPropertyTransitionDuration, 200 CSSPropertyTransitionProperty, 201 CSSPropertyTransitionTimingFunction, 202 CSSPropertyUnicodeBidi, 203 CSSPropertyVerticalAlign, 204 CSSPropertyVisibility, 205 CSSPropertyWhiteSpace, 206 CSSPropertyWidows, 207 CSSPropertyWidth, 208 CSSPropertyWillChange, 209 CSSPropertyWordBreak, 210 CSSPropertyWordSpacing, 211 CSSPropertyWordWrap, 212 CSSPropertyZIndex, 213 CSSPropertyZoom, 214 215 CSSPropertyWebkitAnimationDelay, 216 CSSPropertyWebkitAnimationDirection, 217 CSSPropertyWebkitAnimationDuration, 218 CSSPropertyWebkitAnimationFillMode, 219 CSSPropertyWebkitAnimationIterationCount, 220 CSSPropertyWebkitAnimationName, 221 CSSPropertyWebkitAnimationPlayState, 222 CSSPropertyWebkitAnimationTimingFunction, 223 CSSPropertyWebkitAppearance, 224 CSSPropertyBackfaceVisibility, 225 CSSPropertyWebkitBackfaceVisibility, 226 CSSPropertyWebkitBackgroundClip, 227 CSSPropertyWebkitBackgroundComposite, 228 CSSPropertyWebkitBackgroundOrigin, 229 CSSPropertyWebkitBackgroundSize, 230 CSSPropertyWebkitBorderFit, 231 CSSPropertyWebkitBorderHorizontalSpacing, 232 CSSPropertyWebkitBorderImage, 233 CSSPropertyWebkitBorderVerticalSpacing, 234 CSSPropertyWebkitBoxAlign, 235 CSSPropertyWebkitBoxDecorationBreak, 236 CSSPropertyWebkitBoxDirection, 237 CSSPropertyWebkitBoxFlex, 238 CSSPropertyWebkitBoxFlexGroup, 239 CSSPropertyWebkitBoxLines, 240 CSSPropertyWebkitBoxOrdinalGroup, 241 CSSPropertyWebkitBoxOrient, 242 CSSPropertyWebkitBoxPack, 243 CSSPropertyWebkitBoxReflect, 244 CSSPropertyWebkitBoxShadow, 245 CSSPropertyWebkitClipPath, 246 CSSPropertyWebkitColumnBreakAfter, 247 CSSPropertyWebkitColumnBreakBefore, 248 CSSPropertyWebkitColumnBreakInside, 249 CSSPropertyWebkitColumnCount, 250 CSSPropertyWebkitColumnGap, 251 CSSPropertyWebkitColumnRuleColor, 252 CSSPropertyWebkitColumnRuleStyle, 253 CSSPropertyWebkitColumnRuleWidth, 254 CSSPropertyWebkitColumnSpan, 255 CSSPropertyWebkitColumnWidth, 256 CSSPropertyWebkitFilter, 257 CSSPropertyAlignContent, 258 CSSPropertyAlignItems, 259 CSSPropertyAlignSelf, 260 CSSPropertyFlexBasis, 261 CSSPropertyFlexGrow, 262 CSSPropertyFlexShrink, 263 CSSPropertyFlexDirection, 264 CSSPropertyFlexWrap, 265 CSSPropertyJustifyContent, 266 CSSPropertyWebkitFontSmoothing, 267 CSSPropertyGridAutoColumns, 268 CSSPropertyGridAutoFlow, 269 CSSPropertyGridAutoRows, 270 CSSPropertyGridColumnEnd, 271 CSSPropertyGridColumnStart, 272 CSSPropertyGridTemplateAreas, 273 CSSPropertyGridTemplateColumns, 274 CSSPropertyGridTemplateRows, 275 CSSPropertyGridRowEnd, 276 CSSPropertyGridRowStart, 277 CSSPropertyWebkitHighlight, 278 CSSPropertyWebkitHyphenateCharacter, 279 CSSPropertyWebkitLineBoxContain, 280 CSSPropertyWebkitLineBreak, 281 CSSPropertyWebkitLineClamp, 282 CSSPropertyWebkitLocale, 283 CSSPropertyWebkitMarginBeforeCollapse, 284 CSSPropertyWebkitMarginAfterCollapse, 285 CSSPropertyWebkitMaskBoxImage, 286 CSSPropertyWebkitMaskBoxImageOutset, 287 CSSPropertyWebkitMaskBoxImageRepeat, 288 CSSPropertyWebkitMaskBoxImageSlice, 289 CSSPropertyWebkitMaskBoxImageSource, 290 CSSPropertyWebkitMaskBoxImageWidth, 291 CSSPropertyWebkitMaskClip, 292 CSSPropertyWebkitMaskComposite, 293 CSSPropertyWebkitMaskImage, 294 CSSPropertyWebkitMaskOrigin, 295 CSSPropertyWebkitMaskPosition, 296 CSSPropertyWebkitMaskRepeat, 297 CSSPropertyWebkitMaskSize, 298 CSSPropertyOrder, 299 CSSPropertyPerspective, 300 CSSPropertyWebkitPerspective, 301 CSSPropertyPerspectiveOrigin, 302 CSSPropertyWebkitPerspectiveOrigin, 303 CSSPropertyWebkitPrintColorAdjust, 304 CSSPropertyWebkitRtlOrdering, 305 CSSPropertyShapeOutside, 306 CSSPropertyShapeImageThreshold, 307 CSSPropertyShapeMargin, 308 CSSPropertyWebkitTapHighlightColor, 309 CSSPropertyWebkitTextCombine, 310 CSSPropertyWebkitTextDecorationsInEffect, 311 CSSPropertyWebkitTextEmphasisColor, 312 CSSPropertyWebkitTextEmphasisPosition, 313 CSSPropertyWebkitTextEmphasisStyle, 314 CSSPropertyWebkitTextFillColor, 315 CSSPropertyWebkitTextOrientation, 316 CSSPropertyWebkitTextSecurity, 317 CSSPropertyWebkitTextStrokeColor, 318 CSSPropertyWebkitTextStrokeWidth, 319 CSSPropertyTransform, 320 CSSPropertyWebkitTransform, 321 CSSPropertyTransformOrigin, 322 CSSPropertyWebkitTransformOrigin, 323 CSSPropertyTransformStyle, 324 CSSPropertyWebkitTransformStyle, 325 CSSPropertyWebkitTransitionDelay, 326 CSSPropertyWebkitTransitionDuration, 327 CSSPropertyWebkitTransitionProperty, 328 CSSPropertyWebkitTransitionTimingFunction, 329 CSSPropertyWebkitUserDrag, 330 CSSPropertyWebkitUserModify, 331 CSSPropertyWebkitUserSelect, 332 CSSPropertyWebkitWritingMode, 333 CSSPropertyWebkitAppRegion, 334 CSSPropertyBufferedRendering, 335 CSSPropertyClipPath, 336 CSSPropertyClipRule, 337 CSSPropertyMask, 338 CSSPropertyFilter, 339 CSSPropertyFloodColor, 340 CSSPropertyFloodOpacity, 341 CSSPropertyLightingColor, 342 CSSPropertyStopColor, 343 CSSPropertyStopOpacity, 344 CSSPropertyColorInterpolation, 345 CSSPropertyColorInterpolationFilters, 346 CSSPropertyColorRendering, 347 CSSPropertyFill, 348 CSSPropertyFillOpacity, 349 CSSPropertyFillRule, 350 CSSPropertyMarkerEnd, 351 CSSPropertyMarkerMid, 352 CSSPropertyMarkerStart, 353 CSSPropertyMaskType, 354 CSSPropertyMaskSourceType, 355 CSSPropertyShapeRendering, 356 CSSPropertyStroke, 357 CSSPropertyStrokeDasharray, 358 CSSPropertyStrokeDashoffset, 359 CSSPropertyStrokeLinecap, 360 CSSPropertyStrokeLinejoin, 361 CSSPropertyStrokeMiterlimit, 362 CSSPropertyStrokeOpacity, 363 CSSPropertyStrokeWidth, 364 CSSPropertyAlignmentBaseline, 365 CSSPropertyBaselineShift, 366 CSSPropertyDominantBaseline, 367 CSSPropertyTextAnchor, 368 CSSPropertyWritingMode, 369 CSSPropertyGlyphOrientationHorizontal, 370 CSSPropertyGlyphOrientationVertical, 371 CSSPropertyVectorEffect, 372 CSSPropertyPaintOrder 373 }; 374 375 static const Vector<CSSPropertyID>& computableProperties() 376 { 377 DEFINE_STATIC_LOCAL(Vector<CSSPropertyID>, properties, ()); 378 if (properties.isEmpty()) 379 CSSPropertyMetadata::filterEnabledCSSPropertiesIntoVector(staticComputableProperties, WTF_ARRAY_LENGTH(staticComputableProperties), properties); 380 return properties; 381 } 382 383 static CSSValueID valueForRepeatRule(int rule) 384 { 385 switch (rule) { 386 case RepeatImageRule: 387 return CSSValueRepeat; 388 case RoundImageRule: 389 return CSSValueRound; 390 case SpaceImageRule: 391 return CSSValueSpace; 392 default: 393 return CSSValueStretch; 394 } 395 } 396 397 static PassRefPtrWillBeRawPtr<CSSBorderImageSliceValue> valueForNinePieceImageSlice(const NinePieceImage& image) 398 { 399 // Create the slices. 400 RefPtrWillBeRawPtr<CSSPrimitiveValue> top = nullptr; 401 RefPtrWillBeRawPtr<CSSPrimitiveValue> right = nullptr; 402 RefPtrWillBeRawPtr<CSSPrimitiveValue> bottom = nullptr; 403 RefPtrWillBeRawPtr<CSSPrimitiveValue> left = nullptr; 404 405 if (image.imageSlices().top().isPercent()) 406 top = cssValuePool().createValue(image.imageSlices().top().value(), CSSPrimitiveValue::CSS_PERCENTAGE); 407 else 408 top = cssValuePool().createValue(image.imageSlices().top().value(), CSSPrimitiveValue::CSS_NUMBER); 409 410 if (image.imageSlices().right() == image.imageSlices().top() && image.imageSlices().bottom() == image.imageSlices().top() 411 && image.imageSlices().left() == image.imageSlices().top()) { 412 right = top; 413 bottom = top; 414 left = top; 415 } else { 416 if (image.imageSlices().right().isPercent()) 417 right = cssValuePool().createValue(image.imageSlices().right().value(), CSSPrimitiveValue::CSS_PERCENTAGE); 418 else 419 right = cssValuePool().createValue(image.imageSlices().right().value(), CSSPrimitiveValue::CSS_NUMBER); 420 421 if (image.imageSlices().bottom() == image.imageSlices().top() && image.imageSlices().right() == image.imageSlices().left()) { 422 bottom = top; 423 left = right; 424 } else { 425 if (image.imageSlices().bottom().isPercent()) 426 bottom = cssValuePool().createValue(image.imageSlices().bottom().value(), CSSPrimitiveValue::CSS_PERCENTAGE); 427 else 428 bottom = cssValuePool().createValue(image.imageSlices().bottom().value(), CSSPrimitiveValue::CSS_NUMBER); 429 430 if (image.imageSlices().left() == image.imageSlices().right()) 431 left = right; 432 else { 433 if (image.imageSlices().left().isPercent()) 434 left = cssValuePool().createValue(image.imageSlices().left().value(), CSSPrimitiveValue::CSS_PERCENTAGE); 435 else 436 left = cssValuePool().createValue(image.imageSlices().left().value(), CSSPrimitiveValue::CSS_NUMBER); 437 } 438 } 439 } 440 441 RefPtrWillBeRawPtr<Quad> quad = Quad::create(); 442 quad->setTop(top); 443 quad->setRight(right); 444 quad->setBottom(bottom); 445 quad->setLeft(left); 446 447 return CSSBorderImageSliceValue::create(cssValuePool().createValue(quad.release()), image.fill()); 448 } 449 450 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForNinePieceImageQuad(const BorderImageLengthBox& box, const RenderStyle& style) 451 { 452 // Create the slices. 453 RefPtrWillBeRawPtr<CSSPrimitiveValue> top = nullptr; 454 RefPtrWillBeRawPtr<CSSPrimitiveValue> right = nullptr; 455 RefPtrWillBeRawPtr<CSSPrimitiveValue> bottom = nullptr; 456 RefPtrWillBeRawPtr<CSSPrimitiveValue> left = nullptr; 457 458 if (box.top().isNumber()) 459 top = cssValuePool().createValue(box.top().number(), CSSPrimitiveValue::CSS_NUMBER); 460 else 461 top = cssValuePool().createValue(box.top().length(), style); 462 463 if (box.right() == box.top() && box.bottom() == box.top() && box.left() == box.top()) { 464 right = top; 465 bottom = top; 466 left = top; 467 } else { 468 if (box.right().isNumber()) 469 right = cssValuePool().createValue(box.right().number(), CSSPrimitiveValue::CSS_NUMBER); 470 else 471 right = cssValuePool().createValue(box.right().length(), style); 472 473 if (box.bottom() == box.top() && box.right() == box.left()) { 474 bottom = top; 475 left = right; 476 } else { 477 if (box.bottom().isNumber()) 478 bottom = cssValuePool().createValue(box.bottom().number(), CSSPrimitiveValue::CSS_NUMBER); 479 else 480 bottom = cssValuePool().createValue(box.bottom().length(), style); 481 482 if (box.left() == box.right()) 483 left = right; 484 else { 485 if (box.left().isNumber()) 486 left = cssValuePool().createValue(box.left().number(), CSSPrimitiveValue::CSS_NUMBER); 487 else 488 left = cssValuePool().createValue(box.left().length(), style); 489 } 490 } 491 } 492 493 RefPtrWillBeRawPtr<Quad> quad = Quad::create(); 494 quad->setTop(top); 495 quad->setRight(right); 496 quad->setBottom(bottom); 497 quad->setLeft(left); 498 499 return cssValuePool().createValue(quad.release()); 500 } 501 502 static PassRefPtrWillBeRawPtr<CSSValue> valueForNinePieceImageRepeat(const NinePieceImage& image) 503 { 504 RefPtrWillBeRawPtr<CSSPrimitiveValue> horizontalRepeat = nullptr; 505 RefPtrWillBeRawPtr<CSSPrimitiveValue> verticalRepeat = nullptr; 506 507 horizontalRepeat = cssValuePool().createIdentifierValue(valueForRepeatRule(image.horizontalRule())); 508 if (image.horizontalRule() == image.verticalRule()) 509 verticalRepeat = horizontalRepeat; 510 else 511 verticalRepeat = cssValuePool().createIdentifierValue(valueForRepeatRule(image.verticalRule())); 512 return cssValuePool().createValue(Pair::create(horizontalRepeat.release(), verticalRepeat.release(), Pair::DropIdenticalValues)); 513 } 514 515 static PassRefPtrWillBeRawPtr<CSSValue> valueForNinePieceImage(const NinePieceImage& image, const RenderStyle& style) 516 { 517 if (!image.hasImage()) 518 return cssValuePool().createIdentifierValue(CSSValueNone); 519 520 // Image first. 521 RefPtrWillBeRawPtr<CSSValue> imageValue = nullptr; 522 if (image.image()) 523 imageValue = image.image()->cssValue(); 524 525 // Create the image slice. 526 RefPtrWillBeRawPtr<CSSBorderImageSliceValue> imageSlices = valueForNinePieceImageSlice(image); 527 528 // Create the border area slices. 529 RefPtrWillBeRawPtr<CSSValue> borderSlices = valueForNinePieceImageQuad(image.borderSlices(), style); 530 531 // Create the border outset. 532 RefPtrWillBeRawPtr<CSSValue> outset = valueForNinePieceImageQuad(image.outset(), style); 533 534 // Create the repeat rules. 535 RefPtrWillBeRawPtr<CSSValue> repeat = valueForNinePieceImageRepeat(image); 536 537 return createBorderImageValue(imageValue.release(), imageSlices.release(), borderSlices.release(), outset.release(), repeat.release()); 538 } 539 540 inline static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> zoomAdjustedPixelValue(double value, const RenderStyle& style) 541 { 542 return cssValuePool().createValue(adjustFloatForAbsoluteZoom(value, style), CSSPrimitiveValue::CSS_PX); 543 } 544 545 inline static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> zoomAdjustedNumberValue(double value, const RenderStyle& style) 546 { 547 return cssValuePool().createValue(value / style.effectiveZoom(), CSSPrimitiveValue::CSS_NUMBER); 548 } 549 550 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> zoomAdjustedPixelValueForLength(const Length& length, const RenderStyle& style) 551 { 552 if (length.isFixed()) 553 return zoomAdjustedPixelValue(length.value(), style); 554 return cssValuePool().createValue(length, style); 555 } 556 557 static PassRefPtrWillBeRawPtr<CSSValue> valueForReflection(const StyleReflection* reflection, const RenderStyle& style) 558 { 559 if (!reflection) 560 return cssValuePool().createIdentifierValue(CSSValueNone); 561 562 RefPtrWillBeRawPtr<CSSPrimitiveValue> offset = nullptr; 563 if (reflection->offset().isPercent()) 564 offset = cssValuePool().createValue(reflection->offset().percent(), CSSPrimitiveValue::CSS_PERCENTAGE); 565 else 566 offset = zoomAdjustedPixelValue(reflection->offset().value(), style); 567 568 RefPtrWillBeRawPtr<CSSPrimitiveValue> direction = nullptr; 569 switch (reflection->direction()) { 570 case ReflectionBelow: 571 direction = cssValuePool().createIdentifierValue(CSSValueBelow); 572 break; 573 case ReflectionAbove: 574 direction = cssValuePool().createIdentifierValue(CSSValueAbove); 575 break; 576 case ReflectionLeft: 577 direction = cssValuePool().createIdentifierValue(CSSValueLeft); 578 break; 579 case ReflectionRight: 580 direction = cssValuePool().createIdentifierValue(CSSValueRight); 581 break; 582 } 583 584 return CSSReflectValue::create(direction.release(), offset.release(), valueForNinePieceImage(reflection->mask(), style)); 585 } 586 587 static PassRefPtrWillBeRawPtr<CSSValueList> createPositionListForLayer(CSSPropertyID propertyID, const FillLayer& layer, const RenderStyle& style) 588 { 589 RefPtrWillBeRawPtr<CSSValueList> positionList = CSSValueList::createSpaceSeparated(); 590 if (layer.isBackgroundXOriginSet()) { 591 ASSERT_UNUSED(propertyID, propertyID == CSSPropertyBackgroundPosition || propertyID == CSSPropertyWebkitMaskPosition); 592 positionList->append(cssValuePool().createValue(layer.backgroundXOrigin())); 593 } 594 positionList->append(zoomAdjustedPixelValueForLength(layer.xPosition(), style)); 595 if (layer.isBackgroundYOriginSet()) { 596 ASSERT(propertyID == CSSPropertyBackgroundPosition || propertyID == CSSPropertyWebkitMaskPosition); 597 positionList->append(cssValuePool().createValue(layer.backgroundYOrigin())); 598 } 599 positionList->append(zoomAdjustedPixelValueForLength(layer.yPosition(), style)); 600 return positionList.release(); 601 } 602 603 static PassRefPtrWillBeRawPtr<CSSValue> valueForPositionOffset(RenderStyle& style, CSSPropertyID propertyID, const RenderObject* renderer) 604 { 605 Length l; 606 switch (propertyID) { 607 case CSSPropertyLeft: 608 l = style.left(); 609 break; 610 case CSSPropertyRight: 611 l = style.right(); 612 break; 613 case CSSPropertyTop: 614 l = style.top(); 615 break; 616 case CSSPropertyBottom: 617 l = style.bottom(); 618 break; 619 default: 620 return nullptr; 621 } 622 623 if (l.isPercent() && renderer && renderer->isBox()) { 624 LayoutUnit containingBlockSize = (propertyID == CSSPropertyLeft || propertyID == CSSPropertyRight) ? 625 toRenderBox(renderer)->containingBlockLogicalWidthForContent() : 626 toRenderBox(renderer)->containingBlockLogicalHeightForContent(ExcludeMarginBorderPadding); 627 return zoomAdjustedPixelValue(valueForLength(l, containingBlockSize), style); 628 } 629 if (l.isAuto()) { 630 // FIXME: It's not enough to simply return "auto" values for one offset if the other side is defined. 631 // In other words if left is auto and right is not auto, then left's computed value is negative right(). 632 // So we should get the opposite length unit and see if it is auto. 633 return cssValuePool().createIdentifierValue(CSSValueAuto); 634 } 635 636 return zoomAdjustedPixelValueForLength(l, style); 637 } 638 639 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSComputedStyleDeclaration::currentColorOrValidColor(const RenderStyle& style, const StyleColor& color) const 640 { 641 // This function does NOT look at visited information, so that computed style doesn't expose that. 642 return cssValuePool().createColorValue(color.resolve(style.color()).rgb()); 643 } 644 645 static PassRefPtrWillBeRawPtr<CSSValueList> valuesForBorderRadiusCorner(LengthSize radius, const RenderStyle& style) 646 { 647 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 648 if (radius.width().type() == Percent) 649 list->append(cssValuePool().createValue(radius.width().percent(), CSSPrimitiveValue::CSS_PERCENTAGE)); 650 else 651 list->append(zoomAdjustedPixelValueForLength(radius.width(), style)); 652 if (radius.height().type() == Percent) 653 list->append(cssValuePool().createValue(radius.height().percent(), CSSPrimitiveValue::CSS_PERCENTAGE)); 654 else 655 list->append(zoomAdjustedPixelValueForLength(radius.height(), style)); 656 return list.release(); 657 } 658 659 static PassRefPtrWillBeRawPtr<CSSValue> valueForBorderRadiusCorner(LengthSize radius, const RenderStyle& style) 660 { 661 RefPtrWillBeRawPtr<CSSValueList> list = valuesForBorderRadiusCorner(radius, style); 662 if (list->item(0)->equals(*list->item(1))) 663 return list->item(0); 664 return list.release(); 665 } 666 667 static PassRefPtrWillBeRawPtr<CSSValueList> valueForBorderRadiusShorthand(const RenderStyle& style) 668 { 669 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSlashSeparated(); 670 671 bool showHorizontalBottomLeft = style.borderTopRightRadius().width() != style.borderBottomLeftRadius().width(); 672 bool showHorizontalBottomRight = showHorizontalBottomLeft || (style.borderBottomRightRadius().width() != style.borderTopLeftRadius().width()); 673 bool showHorizontalTopRight = showHorizontalBottomRight || (style.borderTopRightRadius().width() != style.borderTopLeftRadius().width()); 674 675 bool showVerticalBottomLeft = style.borderTopRightRadius().height() != style.borderBottomLeftRadius().height(); 676 bool showVerticalBottomRight = showVerticalBottomLeft || (style.borderBottomRightRadius().height() != style.borderTopLeftRadius().height()); 677 bool showVerticalTopRight = showVerticalBottomRight || (style.borderTopRightRadius().height() != style.borderTopLeftRadius().height()); 678 679 RefPtrWillBeRawPtr<CSSValueList> topLeftRadius = valuesForBorderRadiusCorner(style.borderTopLeftRadius(), style); 680 RefPtrWillBeRawPtr<CSSValueList> topRightRadius = valuesForBorderRadiusCorner(style.borderTopRightRadius(), style); 681 RefPtrWillBeRawPtr<CSSValueList> bottomRightRadius = valuesForBorderRadiusCorner(style.borderBottomRightRadius(), style); 682 RefPtrWillBeRawPtr<CSSValueList> bottomLeftRadius = valuesForBorderRadiusCorner(style.borderBottomLeftRadius(), style); 683 684 RefPtrWillBeRawPtr<CSSValueList> horizontalRadii = CSSValueList::createSpaceSeparated(); 685 horizontalRadii->append(topLeftRadius->item(0)); 686 if (showHorizontalTopRight) 687 horizontalRadii->append(topRightRadius->item(0)); 688 if (showHorizontalBottomRight) 689 horizontalRadii->append(bottomRightRadius->item(0)); 690 if (showHorizontalBottomLeft) 691 horizontalRadii->append(bottomLeftRadius->item(0)); 692 693 list->append(horizontalRadii.release()); 694 695 RefPtrWillBeRawPtr<CSSValueList> verticalRadii = CSSValueList::createSpaceSeparated(); 696 verticalRadii->append(topLeftRadius->item(1)); 697 if (showVerticalTopRight) 698 verticalRadii->append(topRightRadius->item(1)); 699 if (showVerticalBottomRight) 700 verticalRadii->append(bottomRightRadius->item(1)); 701 if (showVerticalBottomLeft) 702 verticalRadii->append(bottomLeftRadius->item(1)); 703 704 if (!verticalRadii->equals(*toCSSValueList(list->item(0)))) 705 list->append(verticalRadii.release()); 706 707 return list.release(); 708 } 709 710 static LayoutRect sizingBox(RenderObject* renderer) 711 { 712 if (!renderer->isBox()) 713 return LayoutRect(); 714 715 RenderBox* box = toRenderBox(renderer); 716 return box->style()->boxSizing() == BORDER_BOX ? box->borderBoxRect() : box->computedCSSContentBoxRect(); 717 } 718 719 static PassRefPtrWillBeRawPtr<CSSTransformValue> valueForMatrixTransform(const TransformationMatrix& transform, const RenderStyle& style) 720 { 721 RefPtrWillBeRawPtr<CSSTransformValue> transformValue = nullptr; 722 if (transform.isAffine()) { 723 transformValue = CSSTransformValue::create(CSSTransformValue::MatrixTransformOperation); 724 725 transformValue->append(cssValuePool().createValue(transform.a(), CSSPrimitiveValue::CSS_NUMBER)); 726 transformValue->append(cssValuePool().createValue(transform.b(), CSSPrimitiveValue::CSS_NUMBER)); 727 transformValue->append(cssValuePool().createValue(transform.c(), CSSPrimitiveValue::CSS_NUMBER)); 728 transformValue->append(cssValuePool().createValue(transform.d(), CSSPrimitiveValue::CSS_NUMBER)); 729 transformValue->append(zoomAdjustedNumberValue(transform.e(), style)); 730 transformValue->append(zoomAdjustedNumberValue(transform.f(), style)); 731 } else { 732 transformValue = CSSTransformValue::create(CSSTransformValue::Matrix3DTransformOperation); 733 734 transformValue->append(cssValuePool().createValue(transform.m11(), CSSPrimitiveValue::CSS_NUMBER)); 735 transformValue->append(cssValuePool().createValue(transform.m12(), CSSPrimitiveValue::CSS_NUMBER)); 736 transformValue->append(cssValuePool().createValue(transform.m13(), CSSPrimitiveValue::CSS_NUMBER)); 737 transformValue->append(cssValuePool().createValue(transform.m14(), CSSPrimitiveValue::CSS_NUMBER)); 738 739 transformValue->append(cssValuePool().createValue(transform.m21(), CSSPrimitiveValue::CSS_NUMBER)); 740 transformValue->append(cssValuePool().createValue(transform.m22(), CSSPrimitiveValue::CSS_NUMBER)); 741 transformValue->append(cssValuePool().createValue(transform.m23(), CSSPrimitiveValue::CSS_NUMBER)); 742 transformValue->append(cssValuePool().createValue(transform.m24(), CSSPrimitiveValue::CSS_NUMBER)); 743 744 transformValue->append(cssValuePool().createValue(transform.m31(), CSSPrimitiveValue::CSS_NUMBER)); 745 transformValue->append(cssValuePool().createValue(transform.m32(), CSSPrimitiveValue::CSS_NUMBER)); 746 transformValue->append(cssValuePool().createValue(transform.m33(), CSSPrimitiveValue::CSS_NUMBER)); 747 transformValue->append(cssValuePool().createValue(transform.m34(), CSSPrimitiveValue::CSS_NUMBER)); 748 749 transformValue->append(zoomAdjustedNumberValue(transform.m41(), style)); 750 transformValue->append(zoomAdjustedNumberValue(transform.m42(), style)); 751 transformValue->append(zoomAdjustedNumberValue(transform.m43(), style)); 752 transformValue->append(cssValuePool().createValue(transform.m44(), CSSPrimitiveValue::CSS_NUMBER)); 753 } 754 755 return transformValue.release(); 756 } 757 758 static PassRefPtrWillBeRawPtr<CSSValue> computedTransform(RenderObject* renderer, const RenderStyle& style) 759 { 760 if (!renderer || !renderer->hasTransform() || !style.hasTransform()) 761 return cssValuePool().createIdentifierValue(CSSValueNone); 762 763 IntRect box; 764 if (renderer->isBox()) 765 box = pixelSnappedIntRect(toRenderBox(renderer)->borderBoxRect()); 766 767 TransformationMatrix transform; 768 style.applyTransform(transform, box.size(), RenderStyle::ExcludeTransformOrigin); 769 770 // FIXME: Need to print out individual functions (https://bugs.webkit.org/show_bug.cgi?id=23924) 771 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 772 list->append(valueForMatrixTransform(transform, style)); 773 774 return list.release(); 775 } 776 777 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::valueForFilter(const RenderObject* renderer, const RenderStyle& style) const 778 { 779 if (style.filter().operations().isEmpty()) 780 return cssValuePool().createIdentifierValue(CSSValueNone); 781 782 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 783 784 RefPtrWillBeRawPtr<CSSFilterValue> filterValue = nullptr; 785 786 Vector<RefPtr<FilterOperation> >::const_iterator end = style.filter().operations().end(); 787 for (Vector<RefPtr<FilterOperation> >::const_iterator it = style.filter().operations().begin(); it != end; ++it) { 788 FilterOperation* filterOperation = it->get(); 789 switch (filterOperation->type()) { 790 case FilterOperation::REFERENCE: 791 filterValue = CSSFilterValue::create(CSSFilterValue::ReferenceFilterOperation); 792 filterValue->append(cssValuePool().createValue(toReferenceFilterOperation(filterOperation)->url(), CSSPrimitiveValue::CSS_STRING)); 793 break; 794 case FilterOperation::GRAYSCALE: 795 filterValue = CSSFilterValue::create(CSSFilterValue::GrayscaleFilterOperation); 796 filterValue->append(cssValuePool().createValue(toBasicColorMatrixFilterOperation(filterOperation)->amount(), CSSPrimitiveValue::CSS_NUMBER)); 797 break; 798 case FilterOperation::SEPIA: 799 filterValue = CSSFilterValue::create(CSSFilterValue::SepiaFilterOperation); 800 filterValue->append(cssValuePool().createValue(toBasicColorMatrixFilterOperation(filterOperation)->amount(), CSSPrimitiveValue::CSS_NUMBER)); 801 break; 802 case FilterOperation::SATURATE: 803 filterValue = CSSFilterValue::create(CSSFilterValue::SaturateFilterOperation); 804 filterValue->append(cssValuePool().createValue(toBasicColorMatrixFilterOperation(filterOperation)->amount(), CSSPrimitiveValue::CSS_NUMBER)); 805 break; 806 case FilterOperation::HUE_ROTATE: 807 filterValue = CSSFilterValue::create(CSSFilterValue::HueRotateFilterOperation); 808 filterValue->append(cssValuePool().createValue(toBasicColorMatrixFilterOperation(filterOperation)->amount(), CSSPrimitiveValue::CSS_DEG)); 809 break; 810 case FilterOperation::INVERT: 811 filterValue = CSSFilterValue::create(CSSFilterValue::InvertFilterOperation); 812 filterValue->append(cssValuePool().createValue(toBasicComponentTransferFilterOperation(filterOperation)->amount(), CSSPrimitiveValue::CSS_NUMBER)); 813 break; 814 case FilterOperation::OPACITY: 815 filterValue = CSSFilterValue::create(CSSFilterValue::OpacityFilterOperation); 816 filterValue->append(cssValuePool().createValue(toBasicComponentTransferFilterOperation(filterOperation)->amount(), CSSPrimitiveValue::CSS_NUMBER)); 817 break; 818 case FilterOperation::BRIGHTNESS: 819 filterValue = CSSFilterValue::create(CSSFilterValue::BrightnessFilterOperation); 820 filterValue->append(cssValuePool().createValue(toBasicComponentTransferFilterOperation(filterOperation)->amount(), CSSPrimitiveValue::CSS_NUMBER)); 821 break; 822 case FilterOperation::CONTRAST: 823 filterValue = CSSFilterValue::create(CSSFilterValue::ContrastFilterOperation); 824 filterValue->append(cssValuePool().createValue(toBasicComponentTransferFilterOperation(filterOperation)->amount(), CSSPrimitiveValue::CSS_NUMBER)); 825 break; 826 case FilterOperation::BLUR: 827 filterValue = CSSFilterValue::create(CSSFilterValue::BlurFilterOperation); 828 filterValue->append(zoomAdjustedPixelValue(toBlurFilterOperation(filterOperation)->stdDeviation().value(), style)); 829 break; 830 case FilterOperation::DROP_SHADOW: { 831 DropShadowFilterOperation* dropShadowOperation = toDropShadowFilterOperation(filterOperation); 832 filterValue = CSSFilterValue::create(CSSFilterValue::DropShadowFilterOperation); 833 // We want our computed style to look like that of a text shadow (has neither spread nor inset style). 834 ShadowData shadow(dropShadowOperation->location(), dropShadowOperation->stdDeviation(), 0, Normal, dropShadowOperation->color()); 835 filterValue->append(valueForShadowData(shadow, style, false)); 836 break; 837 } 838 default: 839 filterValue = CSSFilterValue::create(CSSFilterValue::UnknownFilterOperation); 840 break; 841 } 842 list->append(filterValue.release()); 843 } 844 845 return list.release(); 846 } 847 848 static PassRefPtrWillBeRawPtr<CSSValue> specifiedValueForGridTrackBreadth(const GridLength& trackBreadth, const RenderStyle& style) 849 { 850 if (!trackBreadth.isLength()) 851 return cssValuePool().createValue(trackBreadth.flex(), CSSPrimitiveValue::CSS_FR); 852 853 const Length& trackBreadthLength = trackBreadth.length(); 854 if (trackBreadthLength.isAuto()) 855 return cssValuePool().createIdentifierValue(CSSValueAuto); 856 return zoomAdjustedPixelValueForLength(trackBreadthLength, style); 857 } 858 859 static PassRefPtrWillBeRawPtr<CSSValue> specifiedValueForGridTrackSize(const GridTrackSize& trackSize, const RenderStyle& style) 860 { 861 switch (trackSize.type()) { 862 case LengthTrackSizing: 863 return specifiedValueForGridTrackBreadth(trackSize.length(), style); 864 case MinMaxTrackSizing: 865 RefPtrWillBeRawPtr<CSSValueList> minMaxTrackBreadths = CSSValueList::createCommaSeparated(); 866 minMaxTrackBreadths->append(specifiedValueForGridTrackBreadth(trackSize.minTrackBreadth(), style)); 867 minMaxTrackBreadths->append(specifiedValueForGridTrackBreadth(trackSize.maxTrackBreadth(), style)); 868 return CSSFunctionValue::create("minmax(", minMaxTrackBreadths); 869 } 870 ASSERT_NOT_REACHED(); 871 return nullptr; 872 } 873 874 static void addValuesForNamedGridLinesAtIndex(const OrderedNamedGridLines& orderedNamedGridLines, size_t i, CSSValueList& list) 875 { 876 const Vector<String>& namedGridLines = orderedNamedGridLines.get(i); 877 if (namedGridLines.isEmpty()) 878 return; 879 880 RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = CSSGridLineNamesValue::create(); 881 for (size_t j = 0; j < namedGridLines.size(); ++j) 882 lineNames->append(cssValuePool().createValue(namedGridLines[j], CSSPrimitiveValue::CSS_STRING)); 883 list.append(lineNames.release()); 884 } 885 886 static PassRefPtrWillBeRawPtr<CSSValue> valueForGridTrackList(GridTrackSizingDirection direction, RenderObject* renderer, const RenderStyle& style) 887 { 888 const Vector<GridTrackSize>& trackSizes = direction == ForColumns ? style.gridTemplateColumns() : style.gridTemplateRows(); 889 const OrderedNamedGridLines& orderedNamedGridLines = direction == ForColumns ? style.orderedNamedGridColumnLines() : style.orderedNamedGridRowLines(); 890 bool isRenderGrid = renderer && renderer->isRenderGrid(); 891 892 // Handle the 'none' case. 893 bool trackListIsEmpty = trackSizes.isEmpty(); 894 if (isRenderGrid && trackListIsEmpty) { 895 // For grids we should consider every listed track, whether implicitly or explicitly created. If we don't have 896 // any explicit track and there are no children then there are no implicit tracks. We cannot simply check the 897 // number of rows/columns in our internal grid representation because it's always at least 1x1 (see r143331). 898 trackListIsEmpty = !toRenderBlock(renderer)->firstChild(); 899 } 900 901 if (trackListIsEmpty) { 902 ASSERT(orderedNamedGridLines.isEmpty()); 903 return cssValuePool().createIdentifierValue(CSSValueNone); 904 } 905 906 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 907 if (isRenderGrid) { 908 const Vector<LayoutUnit>& trackPositions = direction == ForColumns ? toRenderGrid(renderer)->columnPositions() : toRenderGrid(renderer)->rowPositions(); 909 // There are at least #tracks + 1 grid lines (trackPositions). Apart from that, the grid container can generate implicit grid tracks, 910 // so we'll have more trackPositions than trackSizes as the latter only contain the explicit grid. 911 ASSERT(trackPositions.size() - 1 >= trackSizes.size()); 912 913 for (size_t i = 0; i < trackPositions.size() - 1; ++i) { 914 addValuesForNamedGridLinesAtIndex(orderedNamedGridLines, i, *list); 915 list->append(zoomAdjustedPixelValue(trackPositions[i + 1] - trackPositions[i], style)); 916 } 917 } else { 918 for (size_t i = 0; i < trackSizes.size(); ++i) { 919 addValuesForNamedGridLinesAtIndex(orderedNamedGridLines, i, *list); 920 list->append(specifiedValueForGridTrackSize(trackSizes[i], style)); 921 } 922 } 923 // Those are the trailing <string>* allowed in the syntax. 924 addValuesForNamedGridLinesAtIndex(orderedNamedGridLines, trackSizes.size(), *list); 925 return list.release(); 926 } 927 928 static PassRefPtrWillBeRawPtr<CSSValue> valueForGridPosition(const GridPosition& position) 929 { 930 if (position.isAuto()) 931 return cssValuePool().createIdentifierValue(CSSValueAuto); 932 933 if (position.isNamedGridArea()) 934 return cssValuePool().createValue(position.namedGridLine(), CSSPrimitiveValue::CSS_STRING); 935 936 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 937 if (position.isSpan()) { 938 list->append(cssValuePool().createIdentifierValue(CSSValueSpan)); 939 list->append(cssValuePool().createValue(position.spanPosition(), CSSPrimitiveValue::CSS_NUMBER)); 940 } else 941 list->append(cssValuePool().createValue(position.integerPosition(), CSSPrimitiveValue::CSS_NUMBER)); 942 943 if (!position.namedGridLine().isNull()) 944 list->append(cssValuePool().createValue(position.namedGridLine(), CSSPrimitiveValue::CSS_STRING)); 945 return list; 946 } 947 948 static PassRefPtrWillBeRawPtr<CSSValue> createTransitionPropertyValue(const CSSTransitionData::TransitionProperty& property) 949 { 950 if (property.propertyType == CSSTransitionData::TransitionNone) 951 return cssValuePool().createIdentifierValue(CSSValueNone); 952 if (property.propertyType == CSSTransitionData::TransitionAll) 953 return cssValuePool().createIdentifierValue(CSSValueAll); 954 if (property.propertyType == CSSTransitionData::TransitionUnknown) 955 return cssValuePool().createValue(property.propertyString, CSSPrimitiveValue::CSS_STRING); 956 ASSERT(property.propertyType == CSSTransitionData::TransitionSingleProperty); 957 return cssValuePool().createValue(getPropertyNameString(property.propertyId), CSSPrimitiveValue::CSS_STRING); 958 } 959 960 static PassRefPtrWillBeRawPtr<CSSValue> valueForTransitionProperty(const CSSTransitionData* transitionData) 961 { 962 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 963 if (transitionData) { 964 for (size_t i = 0; i < transitionData->propertyList().size(); ++i) 965 list->append(createTransitionPropertyValue(transitionData->propertyList()[i])); 966 } else { 967 list->append(cssValuePool().createIdentifierValue(CSSValueAll)); 968 } 969 return list.release(); 970 } 971 972 static PassRefPtrWillBeRawPtr<CSSValue> valueForAnimationDelay(const CSSTimingData* timingData) 973 { 974 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 975 if (timingData) { 976 for (size_t i = 0; i < timingData->delayList().size(); ++i) 977 list->append(cssValuePool().createValue(timingData->delayList()[i], CSSPrimitiveValue::CSS_S)); 978 } else { 979 list->append(cssValuePool().createValue(CSSTimingData::initialDelay(), CSSPrimitiveValue::CSS_S)); 980 } 981 return list.release(); 982 } 983 984 static PassRefPtrWillBeRawPtr<CSSValue> valueForAnimationDuration(const CSSTimingData* timingData) 985 { 986 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 987 if (timingData) { 988 for (size_t i = 0; i < timingData->durationList().size(); ++i) 989 list->append(cssValuePool().createValue(timingData->durationList()[i], CSSPrimitiveValue::CSS_S)); 990 } else { 991 list->append(cssValuePool().createValue(CSSTimingData::initialDuration(), CSSPrimitiveValue::CSS_S)); 992 } 993 return list.release(); 994 } 995 996 static PassRefPtrWillBeRawPtr<CSSValue> valueForAnimationIterationCount(double iterationCount) 997 { 998 if (iterationCount == std::numeric_limits<double>::infinity()) 999 return cssValuePool().createIdentifierValue(CSSValueInfinite); 1000 return cssValuePool().createValue(iterationCount, CSSPrimitiveValue::CSS_NUMBER); 1001 } 1002 1003 static PassRefPtrWillBeRawPtr<CSSValue> valueForAnimationPlayState(EAnimPlayState playState) 1004 { 1005 if (playState == AnimPlayStatePlaying) 1006 return cssValuePool().createIdentifierValue(CSSValueRunning); 1007 ASSERT(playState == AnimPlayStatePaused); 1008 return cssValuePool().createIdentifierValue(CSSValuePaused); 1009 } 1010 1011 static PassRefPtrWillBeRawPtr<CSSValue> createTimingFunctionValue(const TimingFunction* timingFunction) 1012 { 1013 switch (timingFunction->type()) { 1014 case TimingFunction::CubicBezierFunction: 1015 { 1016 const CubicBezierTimingFunction* bezierTimingFunction = toCubicBezierTimingFunction(timingFunction); 1017 if (bezierTimingFunction->subType() != CubicBezierTimingFunction::Custom) { 1018 CSSValueID valueId = CSSValueInvalid; 1019 switch (bezierTimingFunction->subType()) { 1020 case CubicBezierTimingFunction::Ease: 1021 valueId = CSSValueEase; 1022 break; 1023 case CubicBezierTimingFunction::EaseIn: 1024 valueId = CSSValueEaseIn; 1025 break; 1026 case CubicBezierTimingFunction::EaseOut: 1027 valueId = CSSValueEaseOut; 1028 break; 1029 case CubicBezierTimingFunction::EaseInOut: 1030 valueId = CSSValueEaseInOut; 1031 break; 1032 default: 1033 ASSERT_NOT_REACHED(); 1034 return nullptr; 1035 } 1036 return cssValuePool().createIdentifierValue(valueId); 1037 } 1038 return CSSCubicBezierTimingFunctionValue::create(bezierTimingFunction->x1(), bezierTimingFunction->y1(), bezierTimingFunction->x2(), bezierTimingFunction->y2()); 1039 } 1040 1041 case TimingFunction::StepsFunction: 1042 { 1043 const StepsTimingFunction* stepsTimingFunction = toStepsTimingFunction(timingFunction); 1044 StepsTimingFunction::StepAtPosition position = stepsTimingFunction->stepAtPosition(); 1045 int steps = stepsTimingFunction->numberOfSteps(); 1046 ASSERT(position == StepsTimingFunction::Start || position == StepsTimingFunction::End); 1047 1048 if (steps > 1) 1049 return CSSStepsTimingFunctionValue::create(steps, position); 1050 CSSValueID valueId = position == StepsTimingFunction::Start ? CSSValueStepStart : CSSValueStepEnd; 1051 return cssValuePool().createIdentifierValue(valueId); 1052 } 1053 1054 default: 1055 return cssValuePool().createIdentifierValue(CSSValueLinear); 1056 } 1057 } 1058 1059 static PassRefPtrWillBeRawPtr<CSSValue> valueForAnimationTimingFunction(const CSSTimingData* timingData) 1060 { 1061 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1062 if (timingData) { 1063 for (size_t i = 0; i < timingData->timingFunctionList().size(); ++i) 1064 list->append(createTimingFunctionValue(timingData->timingFunctionList()[i].get())); 1065 } else { 1066 list->append(createTimingFunctionValue(CSSTimingData::initialTimingFunction().get())); 1067 } 1068 return list.release(); 1069 } 1070 1071 static PassRefPtrWillBeRawPtr<CSSValue> valueForAnimationFillMode(Timing::FillMode fillMode) 1072 { 1073 switch (fillMode) { 1074 case Timing::FillModeNone: 1075 return cssValuePool().createIdentifierValue(CSSValueNone); 1076 case Timing::FillModeForwards: 1077 return cssValuePool().createIdentifierValue(CSSValueForwards); 1078 case Timing::FillModeBackwards: 1079 return cssValuePool().createIdentifierValue(CSSValueBackwards); 1080 case Timing::FillModeBoth: 1081 return cssValuePool().createIdentifierValue(CSSValueBoth); 1082 default: 1083 ASSERT_NOT_REACHED(); 1084 return nullptr; 1085 } 1086 } 1087 1088 static PassRefPtrWillBeRawPtr<CSSValue> valueForAnimationDirection(Timing::PlaybackDirection direction) 1089 { 1090 switch (direction) { 1091 case Timing::PlaybackDirectionNormal: 1092 return cssValuePool().createIdentifierValue(CSSValueNormal); 1093 case Timing::PlaybackDirectionAlternate: 1094 return cssValuePool().createIdentifierValue(CSSValueAlternate); 1095 case Timing::PlaybackDirectionReverse: 1096 return cssValuePool().createIdentifierValue(CSSValueReverse); 1097 case Timing::PlaybackDirectionAlternateReverse: 1098 return cssValuePool().createIdentifierValue(CSSValueAlternateReverse); 1099 default: 1100 ASSERT_NOT_REACHED(); 1101 return nullptr; 1102 } 1103 } 1104 1105 static PassRefPtrWillBeRawPtr<CSSValue> valueForWillChange(const Vector<CSSPropertyID>& willChangeProperties, bool willChangeContents, bool willChangeScrollPosition) 1106 { 1107 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1108 if (willChangeContents) 1109 list->append(cssValuePool().createIdentifierValue(CSSValueContents)); 1110 if (willChangeScrollPosition) 1111 list->append(cssValuePool().createIdentifierValue(CSSValueScrollPosition)); 1112 for (size_t i = 0; i < willChangeProperties.size(); ++i) 1113 list->append(cssValuePool().createIdentifierValue(willChangeProperties[i])); 1114 if (!list->length()) 1115 list->append(cssValuePool().createIdentifierValue(CSSValueAuto)); 1116 return list.release(); 1117 } 1118 1119 static PassRefPtrWillBeRawPtr<CSSValue> createLineBoxContainValue(unsigned lineBoxContain) 1120 { 1121 if (!lineBoxContain) 1122 return cssValuePool().createIdentifierValue(CSSValueNone); 1123 return CSSLineBoxContainValue::create(lineBoxContain); 1124 } 1125 1126 CSSComputedStyleDeclaration::CSSComputedStyleDeclaration(PassRefPtrWillBeRawPtr<Node> n, bool allowVisitedStyle, const String& pseudoElementName) 1127 : m_node(n) 1128 , m_allowVisitedStyle(allowVisitedStyle) 1129 #if !ENABLE(OILPAN) 1130 , m_refCount(1) 1131 #endif 1132 { 1133 unsigned nameWithoutColonsStart = pseudoElementName[0] == ':' ? (pseudoElementName[1] == ':' ? 2 : 1) : 0; 1134 m_pseudoElementSpecifier = CSSSelector::pseudoId(CSSSelector::parsePseudoType( 1135 AtomicString(pseudoElementName.substring(nameWithoutColonsStart)), false)); 1136 } 1137 1138 CSSComputedStyleDeclaration::~CSSComputedStyleDeclaration() 1139 { 1140 } 1141 1142 #if !ENABLE(OILPAN) 1143 void CSSComputedStyleDeclaration::ref() 1144 { 1145 ++m_refCount; 1146 } 1147 1148 void CSSComputedStyleDeclaration::deref() 1149 { 1150 ASSERT(m_refCount); 1151 if (!--m_refCount) 1152 delete this; 1153 } 1154 #endif 1155 1156 String CSSComputedStyleDeclaration::cssText() const 1157 { 1158 StringBuilder result; 1159 const Vector<CSSPropertyID>& properties = computableProperties(); 1160 1161 for (unsigned i = 0; i < properties.size(); i++) { 1162 if (i) 1163 result.append(' '); 1164 result.append(getPropertyName(properties[i])); 1165 result.appendLiteral(": "); 1166 result.append(getPropertyValue(properties[i])); 1167 result.append(';'); 1168 } 1169 1170 return result.toString(); 1171 } 1172 1173 void CSSComputedStyleDeclaration::setCSSText(const String&, ExceptionState& exceptionState) 1174 { 1175 exceptionState.throwDOMException(NoModificationAllowedError, "These styles are computed, and therefore read-only."); 1176 } 1177 1178 static CSSValueID cssIdentifierForFontSizeKeyword(int keywordSize) 1179 { 1180 ASSERT_ARG(keywordSize, keywordSize); 1181 ASSERT_ARG(keywordSize, keywordSize <= 8); 1182 return static_cast<CSSValueID>(CSSValueXxSmall + keywordSize - 1); 1183 } 1184 1185 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::getFontSizeCSSValuePreferringKeyword() const 1186 { 1187 if (!m_node) 1188 return nullptr; 1189 1190 m_node->document().updateLayoutIgnorePendingStylesheets(); 1191 1192 RefPtr<RenderStyle> style = m_node->computedStyle(m_pseudoElementSpecifier); 1193 if (!style) 1194 return nullptr; 1195 1196 if (int keywordSize = style->fontDescription().keywordSize()) 1197 return cssValuePool().createIdentifierValue(cssIdentifierForFontSizeKeyword(keywordSize)); 1198 1199 1200 return zoomAdjustedPixelValue(style->fontDescription().computedPixelSize(), *style); 1201 } 1202 1203 FixedPitchFontType CSSComputedStyleDeclaration::fixedPitchFontType() const 1204 { 1205 if (!m_node) 1206 return NonFixedPitchFont; 1207 1208 RefPtr<RenderStyle> style = m_node->computedStyle(m_pseudoElementSpecifier); 1209 if (!style) 1210 return NonFixedPitchFont; 1211 1212 return style->fontDescription().fixedPitchFontType(); 1213 } 1214 1215 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::valueForShadowData(const ShadowData& shadow, const RenderStyle& style, bool useSpread) const 1216 { 1217 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = zoomAdjustedPixelValue(shadow.x(), style); 1218 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = zoomAdjustedPixelValue(shadow.y(), style); 1219 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = zoomAdjustedPixelValue(shadow.blur(), style); 1220 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = useSpread ? zoomAdjustedPixelValue(shadow.spread(), style) : PassRefPtrWillBeRawPtr<CSSPrimitiveValue>(nullptr); 1221 RefPtrWillBeRawPtr<CSSPrimitiveValue> shadowStyle = shadow.style() == Normal ? PassRefPtrWillBeRawPtr<CSSPrimitiveValue>(nullptr) : cssValuePool().createIdentifierValue(CSSValueInset); 1222 RefPtrWillBeRawPtr<CSSPrimitiveValue> color = currentColorOrValidColor(style, shadow.color()); 1223 return CSSShadowValue::create(x.release(), y.release(), blur.release(), spread.release(), shadowStyle.release(), color.release()); 1224 } 1225 1226 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::valueForShadowList(const ShadowList* shadowList, const RenderStyle& style, bool useSpread) const 1227 { 1228 if (!shadowList) 1229 return cssValuePool().createIdentifierValue(CSSValueNone); 1230 1231 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1232 size_t shadowCount = shadowList->shadows().size(); 1233 for (size_t i = 0; i < shadowCount; ++i) 1234 list->append(valueForShadowData(shadowList->shadows()[i], style, useSpread)); 1235 return list.release(); 1236 } 1237 1238 static CSSValueID identifierForFamily(const AtomicString& family) 1239 { 1240 if (family == FontFamilyNames::webkit_cursive) 1241 return CSSValueCursive; 1242 if (family == FontFamilyNames::webkit_fantasy) 1243 return CSSValueFantasy; 1244 if (family == FontFamilyNames::webkit_monospace) 1245 return CSSValueMonospace; 1246 if (family == FontFamilyNames::webkit_pictograph) 1247 return CSSValueWebkitPictograph; 1248 if (family == FontFamilyNames::webkit_sans_serif) 1249 return CSSValueSansSerif; 1250 if (family == FontFamilyNames::webkit_serif) 1251 return CSSValueSerif; 1252 return CSSValueInvalid; 1253 } 1254 1255 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForFamily(const AtomicString& family) 1256 { 1257 if (CSSValueID familyIdentifier = identifierForFamily(family)) 1258 return cssValuePool().createIdentifierValue(familyIdentifier); 1259 return cssValuePool().createValue(family.string(), CSSPrimitiveValue::CSS_STRING); 1260 } 1261 1262 static PassRefPtrWillBeRawPtr<CSSValue> renderTextDecorationFlagsToCSSValue(int textDecoration) 1263 { 1264 // Blink value is ignored. 1265 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 1266 if (textDecoration & TextDecorationUnderline) 1267 list->append(cssValuePool().createIdentifierValue(CSSValueUnderline)); 1268 if (textDecoration & TextDecorationOverline) 1269 list->append(cssValuePool().createIdentifierValue(CSSValueOverline)); 1270 if (textDecoration & TextDecorationLineThrough) 1271 list->append(cssValuePool().createIdentifierValue(CSSValueLineThrough)); 1272 1273 if (!list->length()) 1274 return cssValuePool().createIdentifierValue(CSSValueNone); 1275 return list.release(); 1276 } 1277 1278 static PassRefPtrWillBeRawPtr<CSSValue> valueForTextDecorationStyle(TextDecorationStyle textDecorationStyle) 1279 { 1280 switch (textDecorationStyle) { 1281 case TextDecorationStyleSolid: 1282 return cssValuePool().createIdentifierValue(CSSValueSolid); 1283 case TextDecorationStyleDouble: 1284 return cssValuePool().createIdentifierValue(CSSValueDouble); 1285 case TextDecorationStyleDotted: 1286 return cssValuePool().createIdentifierValue(CSSValueDotted); 1287 case TextDecorationStyleDashed: 1288 return cssValuePool().createIdentifierValue(CSSValueDashed); 1289 case TextDecorationStyleWavy: 1290 return cssValuePool().createIdentifierValue(CSSValueWavy); 1291 } 1292 1293 ASSERT_NOT_REACHED(); 1294 return cssValuePool().createExplicitInitialValue(); 1295 } 1296 1297 static PassRefPtrWillBeRawPtr<CSSValue> valueForFillRepeat(EFillRepeat xRepeat, EFillRepeat yRepeat) 1298 { 1299 // For backwards compatibility, if both values are equal, just return one of them. And 1300 // if the two values are equivalent to repeat-x or repeat-y, just return the shorthand. 1301 if (xRepeat == yRepeat) 1302 return cssValuePool().createValue(xRepeat); 1303 if (xRepeat == RepeatFill && yRepeat == NoRepeatFill) 1304 return cssValuePool().createIdentifierValue(CSSValueRepeatX); 1305 if (xRepeat == NoRepeatFill && yRepeat == RepeatFill) 1306 return cssValuePool().createIdentifierValue(CSSValueRepeatY); 1307 1308 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 1309 list->append(cssValuePool().createValue(xRepeat)); 1310 list->append(cssValuePool().createValue(yRepeat)); 1311 return list.release(); 1312 } 1313 1314 static PassRefPtrWillBeRawPtr<CSSValue> valueForFillSourceType(EMaskSourceType type) 1315 { 1316 switch (type) { 1317 case MaskAlpha: 1318 return cssValuePool().createValue(CSSValueAlpha); 1319 case MaskLuminance: 1320 return cssValuePool().createValue(CSSValueLuminance); 1321 } 1322 1323 ASSERT_NOT_REACHED(); 1324 1325 return nullptr; 1326 } 1327 1328 static PassRefPtrWillBeRawPtr<CSSValue> valueForFillSize(const FillSize& fillSize, const RenderStyle& style) 1329 { 1330 if (fillSize.type == Contain) 1331 return cssValuePool().createIdentifierValue(CSSValueContain); 1332 1333 if (fillSize.type == Cover) 1334 return cssValuePool().createIdentifierValue(CSSValueCover); 1335 1336 if (fillSize.size.height().isAuto()) 1337 return zoomAdjustedPixelValueForLength(fillSize.size.width(), style); 1338 1339 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 1340 list->append(zoomAdjustedPixelValueForLength(fillSize.size.width(), style)); 1341 list->append(zoomAdjustedPixelValueForLength(fillSize.size.height(), style)); 1342 return list.release(); 1343 } 1344 1345 static PassRefPtrWillBeRawPtr<CSSValue> valueForContentData(const RenderStyle& style) 1346 { 1347 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 1348 for (const ContentData* contentData = style.contentData(); contentData; contentData = contentData->next()) { 1349 if (contentData->isCounter()) { 1350 const CounterContent* counter = toCounterContentData(contentData)->counter(); 1351 ASSERT(counter); 1352 list->append(cssValuePool().createValue(counter->identifier(), CSSPrimitiveValue::CSS_COUNTER_NAME)); 1353 } else if (contentData->isImage()) { 1354 const StyleImage* image = toImageContentData(contentData)->image(); 1355 ASSERT(image); 1356 list->append(image->cssValue()); 1357 } else if (contentData->isText()) { 1358 list->append(cssValuePool().createValue(toTextContentData(contentData)->text(), CSSPrimitiveValue::CSS_STRING)); 1359 } 1360 } 1361 return list.release(); 1362 } 1363 1364 static PassRefPtrWillBeRawPtr<CSSValue> valueForCounterDirectives(const RenderStyle& style, CSSPropertyID propertyID) 1365 { 1366 const CounterDirectiveMap* map = style.counterDirectives(); 1367 if (!map) 1368 return nullptr; 1369 1370 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 1371 for (CounterDirectiveMap::const_iterator it = map->begin(); it != map->end(); ++it) { 1372 list->append(cssValuePool().createValue(it->key, CSSPrimitiveValue::CSS_STRING)); 1373 short number = propertyID == CSSPropertyCounterIncrement ? it->value.incrementValue() : it->value.resetValue(); 1374 list->append(cssValuePool().createValue((double)number, CSSPrimitiveValue::CSS_NUMBER)); 1375 } 1376 return list.release(); 1377 } 1378 1379 static void logUnimplementedPropertyID(CSSPropertyID propertyID) 1380 { 1381 DEFINE_STATIC_LOCAL(HashSet<CSSPropertyID>, propertyIDSet, ()); 1382 if (!propertyIDSet.add(propertyID).isNewEntry) 1383 return; 1384 1385 WTF_LOG_ERROR("WebKit does not yet implement getComputedStyle for '%s'.", getPropertyName(propertyID)); 1386 } 1387 1388 static PassRefPtrWillBeRawPtr<CSSValueList> valueForFontFamily(RenderStyle& style) 1389 { 1390 const FontFamily& firstFamily = style.fontDescription().family(); 1391 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1392 for (const FontFamily* family = &firstFamily; family; family = family->next()) 1393 list->append(valueForFamily(family->family())); 1394 return list.release(); 1395 } 1396 1397 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForLineHeight(RenderStyle& style) 1398 { 1399 Length length = style.lineHeight(); 1400 if (length.isNegative()) 1401 return cssValuePool().createIdentifierValue(CSSValueNormal); 1402 1403 return zoomAdjustedPixelValue(floatValueForLength(length, style.fontDescription().specifiedSize()), style); 1404 } 1405 1406 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForFontSize(RenderStyle& style) 1407 { 1408 return zoomAdjustedPixelValue(style.fontDescription().computedPixelSize(), style); 1409 } 1410 1411 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForFontStretch(RenderStyle& style) 1412 { 1413 return cssValuePool().createValue(style.fontDescription().stretch()); 1414 } 1415 1416 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForFontStyle(RenderStyle& style) 1417 { 1418 return cssValuePool().createValue(style.fontDescription().style()); 1419 } 1420 1421 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForFontVariant(RenderStyle& style) 1422 { 1423 return cssValuePool().createValue(style.fontDescription().variant()); 1424 } 1425 1426 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForFontWeight(RenderStyle& style) 1427 { 1428 return cssValuePool().createValue(style.fontDescription().weight()); 1429 } 1430 1431 static PassRefPtrWillBeRawPtr<CSSValue> valueForShape(const RenderStyle& style, ShapeValue* shapeValue) 1432 { 1433 if (!shapeValue) 1434 return cssValuePool().createIdentifierValue(CSSValueNone); 1435 if (shapeValue->type() == ShapeValue::Box) 1436 return cssValuePool().createValue(shapeValue->cssBox()); 1437 if (shapeValue->type() == ShapeValue::Image) { 1438 if (shapeValue->image()) 1439 return shapeValue->image()->cssValue(); 1440 return cssValuePool().createIdentifierValue(CSSValueNone); 1441 } 1442 1443 ASSERT(shapeValue->type() == ShapeValue::Shape); 1444 1445 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 1446 list->append(valueForBasicShape(style, shapeValue->shape())); 1447 if (shapeValue->cssBox() != BoxMissing) 1448 list->append(cssValuePool().createValue(shapeValue->cssBox())); 1449 return list.release(); 1450 } 1451 1452 static PassRefPtrWillBeRawPtr<CSSValue> touchActionFlagsToCSSValue(TouchAction touchAction) 1453 { 1454 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 1455 if (touchAction == TouchActionAuto) 1456 list->append(cssValuePool().createIdentifierValue(CSSValueAuto)); 1457 if (touchAction & TouchActionNone) { 1458 ASSERT(touchAction == TouchActionNone); 1459 list->append(cssValuePool().createIdentifierValue(CSSValueNone)); 1460 } 1461 if (touchAction == (TouchActionPanX | TouchActionPanY | TouchActionPinchZoom)) { 1462 list->append(cssValuePool().createIdentifierValue(CSSValueManipulation)); 1463 } else { 1464 if (touchAction & TouchActionPanX) 1465 list->append(cssValuePool().createIdentifierValue(CSSValuePanX)); 1466 if (touchAction & TouchActionPanY) 1467 list->append(cssValuePool().createIdentifierValue(CSSValuePanY)); 1468 } 1469 ASSERT(list->length()); 1470 return list.release(); 1471 } 1472 1473 static bool isLayoutDependent(CSSPropertyID propertyID, PassRefPtr<RenderStyle> style, RenderObject* renderer) 1474 { 1475 // Some properties only depend on layout in certain conditions which 1476 // are specified in the main switch statement below. So we can avoid 1477 // forcing layout in those conditions. The conditions in this switch 1478 // statement must remain in sync with the conditions in the main switch. 1479 // FIXME: Some of these cases could be narrowed down or optimized better. 1480 switch (propertyID) { 1481 case CSSPropertyBottom: 1482 case CSSPropertyGridTemplateColumns: 1483 case CSSPropertyGridTemplateRows: 1484 case CSSPropertyHeight: 1485 case CSSPropertyLeft: 1486 case CSSPropertyRight: 1487 case CSSPropertyTop: 1488 case CSSPropertyPerspectiveOrigin: 1489 case CSSPropertyWebkitPerspectiveOrigin: 1490 case CSSPropertyTransform: 1491 case CSSPropertyWebkitTransform: 1492 case CSSPropertyTransformOrigin: 1493 case CSSPropertyWebkitTransformOrigin: 1494 case CSSPropertyWidth: 1495 case CSSPropertyWebkitFilter: 1496 return true; 1497 case CSSPropertyMargin: 1498 return renderer && renderer->isBox() && (!style || !style->marginBottom().isFixed() || !style->marginTop().isFixed() || !style->marginLeft().isFixed() || !style->marginRight().isFixed()); 1499 case CSSPropertyMarginLeft: 1500 return renderer && renderer->isBox() && (!style || !style->marginLeft().isFixed()); 1501 case CSSPropertyMarginRight: 1502 return renderer && renderer->isBox() && (!style || !style->marginRight().isFixed()); 1503 case CSSPropertyMarginTop: 1504 return renderer && renderer->isBox() && (!style || !style->marginTop().isFixed()); 1505 case CSSPropertyMarginBottom: 1506 return renderer && renderer->isBox() && (!style || !style->marginBottom().isFixed()); 1507 case CSSPropertyPadding: 1508 return renderer && renderer->isBox() && (!style || !style->paddingBottom().isFixed() || !style->paddingTop().isFixed() || !style->paddingLeft().isFixed() || !style->paddingRight().isFixed()); 1509 case CSSPropertyPaddingBottom: 1510 return renderer && renderer->isBox() && (!style || !style->paddingBottom().isFixed()); 1511 case CSSPropertyPaddingLeft: 1512 return renderer && renderer->isBox() && (!style || !style->paddingLeft().isFixed()); 1513 case CSSPropertyPaddingRight: 1514 return renderer && renderer->isBox() && (!style || !style->paddingRight().isFixed()); 1515 case CSSPropertyPaddingTop: 1516 return renderer && renderer->isBox() && (!style || !style->paddingTop().isFixed()); 1517 default: 1518 return false; 1519 } 1520 } 1521 1522 PassRefPtr<RenderStyle> CSSComputedStyleDeclaration::computeRenderStyle() const 1523 { 1524 Node* styledNode = this->styledNode(); 1525 ASSERT(styledNode); 1526 return styledNode->computedStyle(styledNode->isPseudoElement() ? NOPSEUDO : m_pseudoElementSpecifier); 1527 } 1528 1529 Node* CSSComputedStyleDeclaration::styledNode() const 1530 { 1531 if (!m_node) 1532 return 0; 1533 if (m_node->isElementNode()) { 1534 if (PseudoElement* element = toElement(m_node)->pseudoElement(m_pseudoElementSpecifier)) 1535 return element; 1536 } 1537 return m_node.get(); 1538 } 1539 1540 static ItemPosition resolveAlignmentAuto(ItemPosition position, Node* element) 1541 { 1542 if (position != ItemPositionAuto) 1543 return position; 1544 1545 bool isFlexOrGrid = element && element->computedStyle() 1546 && element->computedStyle()->isDisplayFlexibleOrGridBox(); 1547 1548 return isFlexOrGrid ? ItemPositionStretch : ItemPositionStart; 1549 } 1550 1551 static PassRefPtrWillBeRawPtr<CSSValueList> valueForItemPositionWithOverflowAlignment(ItemPosition itemPosition, OverflowAlignment overflowAlignment, ItemPositionType positionType) 1552 { 1553 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createSpaceSeparated(); 1554 if (positionType == LegacyPosition) 1555 result->append(CSSPrimitiveValue::createIdentifier(CSSValueLegacy)); 1556 result->append(CSSPrimitiveValue::create(itemPosition)); 1557 if (itemPosition >= ItemPositionCenter && overflowAlignment != OverflowAlignmentDefault) 1558 result->append(CSSPrimitiveValue::create(overflowAlignment)); 1559 ASSERT(result->length() <= 2); 1560 return result.release(); 1561 } 1562 1563 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID propertyID, EUpdateLayout updateLayout) const 1564 { 1565 Node* styledNode = this->styledNode(); 1566 if (!styledNode) 1567 return nullptr; 1568 RenderObject* renderer = styledNode->renderer(); 1569 RefPtr<RenderStyle> style; 1570 1571 if (updateLayout) { 1572 Document& document = styledNode->document(); 1573 1574 // A timing update may be required if a compositor animation is running. 1575 DocumentAnimations::updateAnimationTimingForGetComputedStyle(*styledNode, propertyID); 1576 1577 document.updateRenderTreeForNodeIfNeeded(styledNode); 1578 1579 // The style recalc could have caused the styled node to be discarded or replaced 1580 // if it was a PseudoElement so we need to update it. 1581 styledNode = this->styledNode(); 1582 renderer = styledNode->renderer(); 1583 1584 style = computeRenderStyle(); 1585 1586 bool forceFullLayout = isLayoutDependent(propertyID, style, renderer) 1587 || styledNode->isInShadowTree() 1588 || (document.ownerElement() && document.ensureStyleResolver().hasViewportDependentMediaQueries()); 1589 1590 if (forceFullLayout) { 1591 document.updateLayoutIgnorePendingStylesheets(); 1592 styledNode = this->styledNode(); 1593 style = computeRenderStyle(); 1594 renderer = styledNode->renderer(); 1595 } 1596 } else { 1597 style = computeRenderStyle(); 1598 } 1599 1600 if (!style) 1601 return nullptr; 1602 1603 propertyID = CSSProperty::resolveDirectionAwareProperty(propertyID, style->direction(), style->writingMode()); 1604 1605 switch (propertyID) { 1606 case CSSPropertyInvalid: 1607 break; 1608 1609 case CSSPropertyBackgroundColor: 1610 return m_allowVisitedStyle ? cssValuePool().createColorValue(style->visitedDependentColor(CSSPropertyBackgroundColor).rgb()) : currentColorOrValidColor(*style, style->backgroundColor()); 1611 case CSSPropertyBackgroundImage: 1612 case CSSPropertyWebkitMaskImage: { 1613 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1614 const FillLayer* currLayer = propertyID == CSSPropertyWebkitMaskImage ? &style->maskLayers() : &style->backgroundLayers(); 1615 for (; currLayer; currLayer = currLayer->next()) { 1616 if (currLayer->image()) 1617 list->append(currLayer->image()->cssValue()); 1618 else 1619 list->append(cssValuePool().createIdentifierValue(CSSValueNone)); 1620 } 1621 return list.release(); 1622 } 1623 case CSSPropertyBackgroundSize: 1624 case CSSPropertyWebkitBackgroundSize: 1625 case CSSPropertyWebkitMaskSize: { 1626 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1627 const FillLayer* currLayer = propertyID == CSSPropertyWebkitMaskSize ? &style->maskLayers() : &style->backgroundLayers(); 1628 for (; currLayer; currLayer = currLayer->next()) 1629 list->append(valueForFillSize(currLayer->size(), *style)); 1630 return list.release(); 1631 } 1632 case CSSPropertyBackgroundRepeat: 1633 case CSSPropertyWebkitMaskRepeat: { 1634 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1635 const FillLayer* currLayer = propertyID == CSSPropertyWebkitMaskRepeat ? &style->maskLayers() : &style->backgroundLayers(); 1636 for (; currLayer; currLayer = currLayer->next()) 1637 list->append(valueForFillRepeat(currLayer->repeatX(), currLayer->repeatY())); 1638 return list.release(); 1639 } 1640 case CSSPropertyMaskSourceType: { 1641 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1642 for (const FillLayer* currLayer = &style->maskLayers(); currLayer; currLayer = currLayer->next()) 1643 list->append(valueForFillSourceType(currLayer->maskSourceType())); 1644 return list.release(); 1645 } 1646 case CSSPropertyWebkitBackgroundComposite: 1647 case CSSPropertyWebkitMaskComposite: { 1648 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1649 const FillLayer* currLayer = propertyID == CSSPropertyWebkitMaskComposite ? &style->maskLayers() : &style->backgroundLayers(); 1650 for (; currLayer; currLayer = currLayer->next()) 1651 list->append(cssValuePool().createValue(currLayer->composite())); 1652 return list.release(); 1653 } 1654 case CSSPropertyBackgroundAttachment: { 1655 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1656 for (const FillLayer* currLayer = &style->backgroundLayers(); currLayer; currLayer = currLayer->next()) 1657 list->append(cssValuePool().createValue(currLayer->attachment())); 1658 return list.release(); 1659 } 1660 case CSSPropertyBackgroundClip: 1661 case CSSPropertyBackgroundOrigin: 1662 case CSSPropertyWebkitBackgroundClip: 1663 case CSSPropertyWebkitBackgroundOrigin: 1664 case CSSPropertyWebkitMaskClip: 1665 case CSSPropertyWebkitMaskOrigin: { 1666 bool isClip = propertyID == CSSPropertyBackgroundClip || propertyID == CSSPropertyWebkitBackgroundClip || propertyID == CSSPropertyWebkitMaskClip; 1667 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1668 const FillLayer* currLayer = (propertyID == CSSPropertyWebkitMaskClip || propertyID == CSSPropertyWebkitMaskOrigin) ? &style->maskLayers() : &style->backgroundLayers(); 1669 for (; currLayer; currLayer = currLayer->next()) { 1670 EFillBox box = isClip ? currLayer->clip() : currLayer->origin(); 1671 list->append(cssValuePool().createValue(box)); 1672 } 1673 return list.release(); 1674 } 1675 case CSSPropertyBackgroundPosition: 1676 case CSSPropertyWebkitMaskPosition: { 1677 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1678 const FillLayer* currLayer = propertyID == CSSPropertyWebkitMaskPosition ? &style->maskLayers() : &style->backgroundLayers(); 1679 for (; currLayer; currLayer = currLayer->next()) 1680 list->append(createPositionListForLayer(propertyID, *currLayer, *style)); 1681 return list.release(); 1682 } 1683 case CSSPropertyBackgroundPositionX: 1684 case CSSPropertyWebkitMaskPositionX: { 1685 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1686 const FillLayer* currLayer = propertyID == CSSPropertyWebkitMaskPositionX ? &style->maskLayers() : &style->backgroundLayers(); 1687 for (; currLayer; currLayer = currLayer->next()) 1688 list->append(zoomAdjustedPixelValueForLength(currLayer->xPosition(), *style)); 1689 return list.release(); 1690 } 1691 case CSSPropertyBackgroundPositionY: 1692 case CSSPropertyWebkitMaskPositionY: { 1693 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1694 const FillLayer* currLayer = propertyID == CSSPropertyWebkitMaskPositionY ? &style->maskLayers() : &style->backgroundLayers(); 1695 for (; currLayer; currLayer = currLayer->next()) 1696 list->append(zoomAdjustedPixelValueForLength(currLayer->yPosition(), *style)); 1697 return list.release(); 1698 } 1699 case CSSPropertyBorderCollapse: 1700 if (style->borderCollapse()) 1701 return cssValuePool().createIdentifierValue(CSSValueCollapse); 1702 return cssValuePool().createIdentifierValue(CSSValueSeparate); 1703 case CSSPropertyBorderSpacing: { 1704 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 1705 list->append(zoomAdjustedPixelValue(style->horizontalBorderSpacing(), *style)); 1706 list->append(zoomAdjustedPixelValue(style->verticalBorderSpacing(), *style)); 1707 return list.release(); 1708 } 1709 case CSSPropertyWebkitBorderHorizontalSpacing: 1710 return zoomAdjustedPixelValue(style->horizontalBorderSpacing(), *style); 1711 case CSSPropertyWebkitBorderVerticalSpacing: 1712 return zoomAdjustedPixelValue(style->verticalBorderSpacing(), *style); 1713 case CSSPropertyBorderImageSource: 1714 if (style->borderImageSource()) 1715 return style->borderImageSource()->cssValue(); 1716 return cssValuePool().createIdentifierValue(CSSValueNone); 1717 case CSSPropertyBorderTopColor: 1718 return m_allowVisitedStyle ? cssValuePool().createColorValue(style->visitedDependentColor(CSSPropertyBorderTopColor).rgb()) : currentColorOrValidColor(*style, style->borderTopColor()); 1719 case CSSPropertyBorderRightColor: 1720 return m_allowVisitedStyle ? cssValuePool().createColorValue(style->visitedDependentColor(CSSPropertyBorderRightColor).rgb()) : currentColorOrValidColor(*style, style->borderRightColor()); 1721 case CSSPropertyBorderBottomColor: 1722 return m_allowVisitedStyle ? cssValuePool().createColorValue(style->visitedDependentColor(CSSPropertyBorderBottomColor).rgb()) : currentColorOrValidColor(*style, style->borderBottomColor()); 1723 case CSSPropertyBorderLeftColor: 1724 return m_allowVisitedStyle ? cssValuePool().createColorValue(style->visitedDependentColor(CSSPropertyBorderLeftColor).rgb()) : currentColorOrValidColor(*style, style->borderLeftColor()); 1725 case CSSPropertyBorderTopStyle: 1726 return cssValuePool().createValue(style->borderTopStyle()); 1727 case CSSPropertyBorderRightStyle: 1728 return cssValuePool().createValue(style->borderRightStyle()); 1729 case CSSPropertyBorderBottomStyle: 1730 return cssValuePool().createValue(style->borderBottomStyle()); 1731 case CSSPropertyBorderLeftStyle: 1732 return cssValuePool().createValue(style->borderLeftStyle()); 1733 case CSSPropertyBorderTopWidth: 1734 return zoomAdjustedPixelValue(style->borderTopWidth(), *style); 1735 case CSSPropertyBorderRightWidth: 1736 return zoomAdjustedPixelValue(style->borderRightWidth(), *style); 1737 case CSSPropertyBorderBottomWidth: 1738 return zoomAdjustedPixelValue(style->borderBottomWidth(), *style); 1739 case CSSPropertyBorderLeftWidth: 1740 return zoomAdjustedPixelValue(style->borderLeftWidth(), *style); 1741 case CSSPropertyBottom: 1742 return valueForPositionOffset(*style, CSSPropertyBottom, renderer); 1743 case CSSPropertyWebkitBoxAlign: 1744 return cssValuePool().createValue(style->boxAlign()); 1745 case CSSPropertyWebkitBoxDecorationBreak: 1746 if (style->boxDecorationBreak() == DSLICE) 1747 return cssValuePool().createIdentifierValue(CSSValueSlice); 1748 return cssValuePool().createIdentifierValue(CSSValueClone); 1749 case CSSPropertyWebkitBoxDirection: 1750 return cssValuePool().createValue(style->boxDirection()); 1751 case CSSPropertyWebkitBoxFlex: 1752 return cssValuePool().createValue(style->boxFlex(), CSSPrimitiveValue::CSS_NUMBER); 1753 case CSSPropertyWebkitBoxFlexGroup: 1754 return cssValuePool().createValue(style->boxFlexGroup(), CSSPrimitiveValue::CSS_NUMBER); 1755 case CSSPropertyWebkitBoxLines: 1756 return cssValuePool().createValue(style->boxLines()); 1757 case CSSPropertyWebkitBoxOrdinalGroup: 1758 return cssValuePool().createValue(style->boxOrdinalGroup(), CSSPrimitiveValue::CSS_NUMBER); 1759 case CSSPropertyWebkitBoxOrient: 1760 return cssValuePool().createValue(style->boxOrient()); 1761 case CSSPropertyWebkitBoxPack: 1762 return cssValuePool().createValue(style->boxPack()); 1763 case CSSPropertyWebkitBoxReflect: 1764 return valueForReflection(style->boxReflect(), *style); 1765 case CSSPropertyBoxShadow: 1766 case CSSPropertyWebkitBoxShadow: 1767 return valueForShadowList(style->boxShadow(), *style, true); 1768 case CSSPropertyCaptionSide: 1769 return cssValuePool().createValue(style->captionSide()); 1770 case CSSPropertyClear: 1771 return cssValuePool().createValue(style->clear()); 1772 case CSSPropertyColor: 1773 return cssValuePool().createColorValue(m_allowVisitedStyle ? style->visitedDependentColor(CSSPropertyColor).rgb() : style->color().rgb()); 1774 case CSSPropertyWebkitPrintColorAdjust: 1775 return cssValuePool().createValue(style->printColorAdjust()); 1776 case CSSPropertyWebkitColumnCount: 1777 if (style->hasAutoColumnCount()) 1778 return cssValuePool().createIdentifierValue(CSSValueAuto); 1779 return cssValuePool().createValue(style->columnCount(), CSSPrimitiveValue::CSS_NUMBER); 1780 case CSSPropertyColumnFill: 1781 ASSERT(RuntimeEnabledFeatures::regionBasedColumnsEnabled()); 1782 return cssValuePool().createValue(style->columnFill()); 1783 case CSSPropertyWebkitColumnGap: 1784 if (style->hasNormalColumnGap()) 1785 return cssValuePool().createIdentifierValue(CSSValueNormal); 1786 return zoomAdjustedPixelValue(style->columnGap(), *style); 1787 case CSSPropertyWebkitColumnRuleColor: 1788 return m_allowVisitedStyle ? cssValuePool().createColorValue(style->visitedDependentColor(CSSPropertyOutlineColor).rgb()) : currentColorOrValidColor(*style, style->columnRuleColor()); 1789 case CSSPropertyWebkitColumnRuleStyle: 1790 return cssValuePool().createValue(style->columnRuleStyle()); 1791 case CSSPropertyWebkitColumnRuleWidth: 1792 return zoomAdjustedPixelValue(style->columnRuleWidth(), *style); 1793 case CSSPropertyWebkitColumnSpan: 1794 return cssValuePool().createIdentifierValue(style->columnSpan() ? CSSValueAll : CSSValueNone); 1795 case CSSPropertyWebkitColumnBreakAfter: 1796 return cssValuePool().createValue(style->columnBreakAfter()); 1797 case CSSPropertyWebkitColumnBreakBefore: 1798 return cssValuePool().createValue(style->columnBreakBefore()); 1799 case CSSPropertyWebkitColumnBreakInside: 1800 return cssValuePool().createValue(style->columnBreakInside()); 1801 case CSSPropertyWebkitColumnWidth: 1802 if (style->hasAutoColumnWidth()) 1803 return cssValuePool().createIdentifierValue(CSSValueAuto); 1804 return zoomAdjustedPixelValue(style->columnWidth(), *style); 1805 case CSSPropertyTabSize: 1806 return cssValuePool().createValue(style->tabSize(), CSSPrimitiveValue::CSS_NUMBER); 1807 case CSSPropertyCursor: { 1808 RefPtrWillBeRawPtr<CSSValueList> list = nullptr; 1809 CursorList* cursors = style->cursors(); 1810 if (cursors && cursors->size() > 0) { 1811 list = CSSValueList::createCommaSeparated(); 1812 for (unsigned i = 0; i < cursors->size(); ++i) 1813 if (StyleImage* image = cursors->at(i).image()) 1814 list->append(image->cssValue()); 1815 } 1816 RefPtrWillBeRawPtr<CSSValue> value = cssValuePool().createValue(style->cursor()); 1817 if (list) { 1818 list->append(value.release()); 1819 return list.release(); 1820 } 1821 return value.release(); 1822 } 1823 case CSSPropertyDirection: 1824 return cssValuePool().createValue(style->direction()); 1825 case CSSPropertyDisplay: 1826 return cssValuePool().createValue(style->display()); 1827 case CSSPropertyEmptyCells: 1828 return cssValuePool().createValue(style->emptyCells()); 1829 case CSSPropertyAlignContent: 1830 return cssValuePool().createValue(style->alignContent()); 1831 case CSSPropertyAlignItems: 1832 return valueForItemPositionWithOverflowAlignment(resolveAlignmentAuto(style->alignItems(), styledNode), style->alignItemsOverflowAlignment(), NonLegacyPosition); 1833 case CSSPropertyAlignSelf: 1834 return valueForItemPositionWithOverflowAlignment(resolveAlignmentAuto(style->alignSelf(), styledNode->parentNode()), style->alignSelfOverflowAlignment(), NonLegacyPosition); 1835 case CSSPropertyFlex: 1836 return valuesForShorthandProperty(flexShorthand()); 1837 case CSSPropertyFlexBasis: 1838 return zoomAdjustedPixelValueForLength(style->flexBasis(), *style); 1839 case CSSPropertyFlexDirection: 1840 return cssValuePool().createValue(style->flexDirection()); 1841 case CSSPropertyFlexFlow: 1842 return valuesForShorthandProperty(flexFlowShorthand()); 1843 case CSSPropertyFlexGrow: 1844 return cssValuePool().createValue(style->flexGrow()); 1845 case CSSPropertyFlexShrink: 1846 return cssValuePool().createValue(style->flexShrink()); 1847 case CSSPropertyFlexWrap: 1848 return cssValuePool().createValue(style->flexWrap()); 1849 case CSSPropertyJustifyContent: 1850 return cssValuePool().createValue(style->justifyContent()); 1851 case CSSPropertyOrder: 1852 return cssValuePool().createValue(style->order(), CSSPrimitiveValue::CSS_NUMBER); 1853 case CSSPropertyFloat: 1854 if (style->display() != NONE && style->hasOutOfFlowPosition()) 1855 return cssValuePool().createIdentifierValue(CSSValueNone); 1856 return cssValuePool().createValue(style->floating()); 1857 case CSSPropertyFont: { 1858 RefPtrWillBeRawPtr<CSSFontValue> computedFont = CSSFontValue::create(); 1859 computedFont->style = valueForFontStyle(*style); 1860 computedFont->variant = valueForFontVariant(*style); 1861 computedFont->weight = valueForFontWeight(*style); 1862 computedFont->stretch = valueForFontStretch(*style); 1863 computedFont->size = valueForFontSize(*style); 1864 computedFont->lineHeight = valueForLineHeight(*style); 1865 computedFont->family = valueForFontFamily(*style); 1866 return computedFont.release(); 1867 } 1868 case CSSPropertyFontFamily: { 1869 RefPtrWillBeRawPtr<CSSValueList> fontFamilyList = valueForFontFamily(*style); 1870 // If there's only a single family, return that as a CSSPrimitiveValue. 1871 // NOTE: Gecko always returns this as a comma-separated CSSPrimitiveValue string. 1872 if (fontFamilyList->length() == 1) 1873 return fontFamilyList->item(0); 1874 return fontFamilyList.release(); 1875 } 1876 case CSSPropertyFontSize: 1877 return valueForFontSize(*style); 1878 case CSSPropertyFontStretch: 1879 return valueForFontStretch(*style); 1880 case CSSPropertyFontStyle: 1881 return valueForFontStyle(*style); 1882 case CSSPropertyFontVariant: 1883 return valueForFontVariant(*style); 1884 case CSSPropertyFontWeight: 1885 return valueForFontWeight(*style); 1886 case CSSPropertyWebkitFontFeatureSettings: { 1887 const FontFeatureSettings* featureSettings = style->fontDescription().featureSettings(); 1888 if (!featureSettings || !featureSettings->size()) 1889 return cssValuePool().createIdentifierValue(CSSValueNormal); 1890 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 1891 for (unsigned i = 0; i < featureSettings->size(); ++i) { 1892 const FontFeature& feature = featureSettings->at(i); 1893 RefPtrWillBeRawPtr<CSSFontFeatureValue> featureValue = CSSFontFeatureValue::create(feature.tag(), feature.value()); 1894 list->append(featureValue.release()); 1895 } 1896 return list.release(); 1897 } 1898 case CSSPropertyGridAutoFlow: { 1899 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 1900 switch (style->gridAutoFlow()) { 1901 case AutoFlowRow: 1902 case AutoFlowRowDense: 1903 list->append(cssValuePool().createIdentifierValue(CSSValueRow)); 1904 break; 1905 case AutoFlowColumn: 1906 case AutoFlowColumnDense: 1907 list->append(cssValuePool().createIdentifierValue(CSSValueColumn)); 1908 break; 1909 case AutoFlowStackRow: 1910 case AutoFlowStackColumn: 1911 list->append(cssValuePool().createIdentifierValue(CSSValueStack)); 1912 break; 1913 default: 1914 ASSERT_NOT_REACHED(); 1915 } 1916 1917 switch (style->gridAutoFlow()) { 1918 case AutoFlowRowDense: 1919 case AutoFlowColumnDense: 1920 list->append(cssValuePool().createIdentifierValue(CSSValueDense)); 1921 break; 1922 case AutoFlowStackRow: 1923 list->append(cssValuePool().createIdentifierValue(CSSValueRow)); 1924 break; 1925 case AutoFlowStackColumn: 1926 list->append(cssValuePool().createIdentifierValue(CSSValueColumn)); 1927 break; 1928 default: 1929 // Do nothing. 1930 break; 1931 } 1932 1933 return list.release(); 1934 } 1935 // Specs mention that getComputedStyle() should return the used value of the property instead of the computed 1936 // one for grid-definition-{rows|columns} but not for the grid-auto-{rows|columns} as things like 1937 // grid-auto-columns: 2fr; cannot be resolved to a value in pixels as the '2fr' means very different things 1938 // depending on the size of the explicit grid or the number of implicit tracks added to the grid. See 1939 // http://lists.w3.org/Archives/Public/www-style/2013Nov/0014.html 1940 case CSSPropertyGridAutoColumns: 1941 return specifiedValueForGridTrackSize(style->gridAutoColumns(), *style); 1942 case CSSPropertyGridAutoRows: 1943 return specifiedValueForGridTrackSize(style->gridAutoRows(), *style); 1944 1945 case CSSPropertyGridTemplateColumns: 1946 return valueForGridTrackList(ForColumns, renderer, *style); 1947 case CSSPropertyGridTemplateRows: 1948 return valueForGridTrackList(ForRows, renderer, *style); 1949 1950 case CSSPropertyGridColumnStart: 1951 return valueForGridPosition(style->gridColumnStart()); 1952 case CSSPropertyGridColumnEnd: 1953 return valueForGridPosition(style->gridColumnEnd()); 1954 case CSSPropertyGridRowStart: 1955 return valueForGridPosition(style->gridRowStart()); 1956 case CSSPropertyGridRowEnd: 1957 return valueForGridPosition(style->gridRowEnd()); 1958 case CSSPropertyGridColumn: 1959 return valuesForGridShorthand(gridColumnShorthand()); 1960 case CSSPropertyGridRow: 1961 return valuesForGridShorthand(gridRowShorthand()); 1962 case CSSPropertyGridArea: 1963 return valuesForGridShorthand(gridAreaShorthand()); 1964 case CSSPropertyGridTemplate: 1965 return valuesForGridShorthand(gridTemplateShorthand()); 1966 case CSSPropertyGrid: 1967 return valuesForGridShorthand(gridShorthand()); 1968 case CSSPropertyGridTemplateAreas: 1969 if (!style->namedGridAreaRowCount()) { 1970 ASSERT(!style->namedGridAreaColumnCount()); 1971 return cssValuePool().createIdentifierValue(CSSValueNone); 1972 } 1973 1974 return CSSGridTemplateAreasValue::create(style->namedGridArea(), style->namedGridAreaRowCount(), style->namedGridAreaColumnCount()); 1975 1976 case CSSPropertyHeight: 1977 if (renderer) { 1978 // According to http://www.w3.org/TR/CSS2/visudet.html#the-height-property, 1979 // the "height" property does not apply for non-replaced inline elements. 1980 if (!renderer->isReplaced() && renderer->isInline()) 1981 return cssValuePool().createIdentifierValue(CSSValueAuto); 1982 return zoomAdjustedPixelValue(sizingBox(renderer).height(), *style); 1983 } 1984 return zoomAdjustedPixelValueForLength(style->height(), *style); 1985 case CSSPropertyWebkitHighlight: 1986 if (style->highlight() == nullAtom) 1987 return cssValuePool().createIdentifierValue(CSSValueNone); 1988 return cssValuePool().createValue(style->highlight(), CSSPrimitiveValue::CSS_STRING); 1989 case CSSPropertyWebkitHyphenateCharacter: 1990 if (style->hyphenationString().isNull()) 1991 return cssValuePool().createIdentifierValue(CSSValueAuto); 1992 return cssValuePool().createValue(style->hyphenationString(), CSSPrimitiveValue::CSS_STRING); 1993 case CSSPropertyWebkitBorderFit: 1994 if (style->borderFit() == BorderFitBorder) 1995 return cssValuePool().createIdentifierValue(CSSValueBorder); 1996 return cssValuePool().createIdentifierValue(CSSValueLines); 1997 case CSSPropertyImageRendering: 1998 return CSSPrimitiveValue::create(style->imageRendering()); 1999 case CSSPropertyIsolation: 2000 return cssValuePool().createValue(style->isolation()); 2001 case CSSPropertyJustifyItems: 2002 return valueForItemPositionWithOverflowAlignment(resolveAlignmentAuto(style->justifyItems(), styledNode), style->justifyItemsOverflowAlignment(), style->justifyItemsPositionType()); 2003 case CSSPropertyJustifySelf: 2004 return valueForItemPositionWithOverflowAlignment(resolveAlignmentAuto(style->justifySelf(), styledNode->parentNode()), style->justifySelfOverflowAlignment(), NonLegacyPosition); 2005 case CSSPropertyLeft: 2006 return valueForPositionOffset(*style, CSSPropertyLeft, renderer); 2007 case CSSPropertyLetterSpacing: 2008 if (!style->letterSpacing()) 2009 return cssValuePool().createIdentifierValue(CSSValueNormal); 2010 return zoomAdjustedPixelValue(style->letterSpacing(), *style); 2011 case CSSPropertyWebkitLineClamp: 2012 if (style->lineClamp().isNone()) 2013 return cssValuePool().createIdentifierValue(CSSValueNone); 2014 return cssValuePool().createValue(style->lineClamp().value(), style->lineClamp().isPercentage() ? CSSPrimitiveValue::CSS_PERCENTAGE : CSSPrimitiveValue::CSS_NUMBER); 2015 case CSSPropertyLineHeight: 2016 return valueForLineHeight(*style); 2017 case CSSPropertyListStyleImage: 2018 if (style->listStyleImage()) 2019 return style->listStyleImage()->cssValue(); 2020 return cssValuePool().createIdentifierValue(CSSValueNone); 2021 case CSSPropertyListStylePosition: 2022 return cssValuePool().createValue(style->listStylePosition()); 2023 case CSSPropertyListStyleType: 2024 return cssValuePool().createValue(style->listStyleType()); 2025 case CSSPropertyWebkitLocale: 2026 if (style->locale().isNull()) 2027 return cssValuePool().createIdentifierValue(CSSValueAuto); 2028 return cssValuePool().createValue(style->locale(), CSSPrimitiveValue::CSS_STRING); 2029 case CSSPropertyMarginTop: { 2030 Length marginTop = style->marginTop(); 2031 if (marginTop.isFixed() || !renderer || !renderer->isBox()) 2032 return zoomAdjustedPixelValueForLength(marginTop, *style); 2033 return zoomAdjustedPixelValue(toRenderBox(renderer)->marginTop(), *style); 2034 } 2035 case CSSPropertyMarginRight: { 2036 Length marginRight = style->marginRight(); 2037 if (marginRight.isFixed() || !renderer || !renderer->isBox()) 2038 return zoomAdjustedPixelValueForLength(marginRight, *style); 2039 float value; 2040 if (marginRight.isPercent()) { 2041 // RenderBox gives a marginRight() that is the distance between the right-edge of the child box 2042 // and the right-edge of the containing box, when display == BLOCK. Let's calculate the absolute 2043 // value of the specified margin-right % instead of relying on RenderBox's marginRight() value. 2044 value = minimumValueForLength(marginRight, toRenderBox(renderer)->containingBlockLogicalWidthForContent()).toFloat(); 2045 } else { 2046 value = toRenderBox(renderer)->marginRight().toFloat(); 2047 } 2048 return zoomAdjustedPixelValue(value, *style); 2049 } 2050 case CSSPropertyMarginBottom: { 2051 Length marginBottom = style->marginBottom(); 2052 if (marginBottom.isFixed() || !renderer || !renderer->isBox()) 2053 return zoomAdjustedPixelValueForLength(marginBottom, *style); 2054 return zoomAdjustedPixelValue(toRenderBox(renderer)->marginBottom(), *style); 2055 } 2056 case CSSPropertyMarginLeft: { 2057 Length marginLeft = style->marginLeft(); 2058 if (marginLeft.isFixed() || !renderer || !renderer->isBox()) 2059 return zoomAdjustedPixelValueForLength(marginLeft, *style); 2060 return zoomAdjustedPixelValue(toRenderBox(renderer)->marginLeft(), *style); 2061 } 2062 case CSSPropertyWebkitUserModify: 2063 return cssValuePool().createValue(style->userModify()); 2064 case CSSPropertyMaxHeight: { 2065 const Length& maxHeight = style->maxHeight(); 2066 if (maxHeight.isMaxSizeNone()) 2067 return cssValuePool().createIdentifierValue(CSSValueNone); 2068 return zoomAdjustedPixelValueForLength(maxHeight, *style); 2069 } 2070 case CSSPropertyMaxWidth: { 2071 const Length& maxWidth = style->maxWidth(); 2072 if (maxWidth.isMaxSizeNone()) 2073 return cssValuePool().createIdentifierValue(CSSValueNone); 2074 return zoomAdjustedPixelValueForLength(maxWidth, *style); 2075 } 2076 case CSSPropertyMinHeight: 2077 // FIXME: For flex-items, min-height:auto should compute to min-content. 2078 if (style->minHeight().isAuto()) 2079 return zoomAdjustedPixelValue(0, *style); 2080 return zoomAdjustedPixelValueForLength(style->minHeight(), *style); 2081 case CSSPropertyMinWidth: 2082 // FIXME: For flex-items, min-width:auto should compute to min-content. 2083 if (style->minWidth().isAuto()) 2084 return zoomAdjustedPixelValue(0, *style); 2085 return zoomAdjustedPixelValueForLength(style->minWidth(), *style); 2086 case CSSPropertyObjectFit: 2087 return cssValuePool().createValue(style->objectFit()); 2088 case CSSPropertyObjectPosition: 2089 return cssValuePool().createValue( 2090 Pair::create( 2091 zoomAdjustedPixelValueForLength(style->objectPosition().x(), *style), 2092 zoomAdjustedPixelValueForLength(style->objectPosition().y(), *style), 2093 Pair::KeepIdenticalValues)); 2094 case CSSPropertyOpacity: 2095 return cssValuePool().createValue(style->opacity(), CSSPrimitiveValue::CSS_NUMBER); 2096 case CSSPropertyOrphans: 2097 if (style->hasAutoOrphans()) 2098 return cssValuePool().createIdentifierValue(CSSValueAuto); 2099 return cssValuePool().createValue(style->orphans(), CSSPrimitiveValue::CSS_NUMBER); 2100 case CSSPropertyOutlineColor: 2101 return m_allowVisitedStyle ? cssValuePool().createColorValue(style->visitedDependentColor(CSSPropertyOutlineColor).rgb()) : currentColorOrValidColor(*style, style->outlineColor()); 2102 case CSSPropertyOutlineOffset: 2103 return zoomAdjustedPixelValue(style->outlineOffset(), *style); 2104 case CSSPropertyOutlineStyle: 2105 if (style->outlineStyleIsAuto()) 2106 return cssValuePool().createIdentifierValue(CSSValueAuto); 2107 return cssValuePool().createValue(style->outlineStyle()); 2108 case CSSPropertyOutlineWidth: 2109 return zoomAdjustedPixelValue(style->outlineWidth(), *style); 2110 case CSSPropertyOverflow: 2111 return cssValuePool().createValue(max(style->overflowX(), style->overflowY())); 2112 case CSSPropertyOverflowWrap: 2113 return cssValuePool().createValue(style->overflowWrap()); 2114 case CSSPropertyOverflowX: 2115 return cssValuePool().createValue(style->overflowX()); 2116 case CSSPropertyOverflowY: 2117 return cssValuePool().createValue(style->overflowY()); 2118 case CSSPropertyPaddingTop: { 2119 Length paddingTop = style->paddingTop(); 2120 if (paddingTop.isFixed() || !renderer || !renderer->isBox()) 2121 return zoomAdjustedPixelValueForLength(paddingTop, *style); 2122 return zoomAdjustedPixelValue(toRenderBox(renderer)->computedCSSPaddingTop(), *style); 2123 } 2124 case CSSPropertyPaddingRight: { 2125 Length paddingRight = style->paddingRight(); 2126 if (paddingRight.isFixed() || !renderer || !renderer->isBox()) 2127 return zoomAdjustedPixelValueForLength(paddingRight, *style); 2128 return zoomAdjustedPixelValue(toRenderBox(renderer)->computedCSSPaddingRight(), *style); 2129 } 2130 case CSSPropertyPaddingBottom: { 2131 Length paddingBottom = style->paddingBottom(); 2132 if (paddingBottom.isFixed() || !renderer || !renderer->isBox()) 2133 return zoomAdjustedPixelValueForLength(paddingBottom, *style); 2134 return zoomAdjustedPixelValue(toRenderBox(renderer)->computedCSSPaddingBottom(), *style); 2135 } 2136 case CSSPropertyPaddingLeft: { 2137 Length paddingLeft = style->paddingLeft(); 2138 if (paddingLeft.isFixed() || !renderer || !renderer->isBox()) 2139 return zoomAdjustedPixelValueForLength(paddingLeft, *style); 2140 return zoomAdjustedPixelValue(toRenderBox(renderer)->computedCSSPaddingLeft(), *style); 2141 } 2142 case CSSPropertyPageBreakAfter: 2143 return cssValuePool().createValue(style->pageBreakAfter()); 2144 case CSSPropertyPageBreakBefore: 2145 return cssValuePool().createValue(style->pageBreakBefore()); 2146 case CSSPropertyPageBreakInside: { 2147 EPageBreak pageBreak = style->pageBreakInside(); 2148 ASSERT(pageBreak != PBALWAYS); 2149 if (pageBreak == PBALWAYS) 2150 return nullptr; 2151 return cssValuePool().createValue(style->pageBreakInside()); 2152 } 2153 case CSSPropertyPosition: 2154 return cssValuePool().createValue(style->position()); 2155 case CSSPropertyRight: 2156 return valueForPositionOffset(*style, CSSPropertyRight, renderer); 2157 case CSSPropertyWebkitRubyPosition: 2158 return cssValuePool().createValue(style->rubyPosition()); 2159 case CSSPropertyScrollBehavior: 2160 return cssValuePool().createValue(style->scrollBehavior()); 2161 case CSSPropertyTableLayout: 2162 return cssValuePool().createValue(style->tableLayout()); 2163 case CSSPropertyTextAlign: 2164 return cssValuePool().createValue(style->textAlign()); 2165 case CSSPropertyTextAlignLast: 2166 return cssValuePool().createValue(style->textAlignLast()); 2167 case CSSPropertyTextDecoration: 2168 if (RuntimeEnabledFeatures::css3TextDecorationsEnabled()) 2169 return valuesForShorthandProperty(textDecorationShorthand()); 2170 // Fall through. 2171 case CSSPropertyTextDecorationLine: 2172 return renderTextDecorationFlagsToCSSValue(style->textDecoration()); 2173 case CSSPropertyTextDecorationStyle: 2174 return valueForTextDecorationStyle(style->textDecorationStyle()); 2175 case CSSPropertyTextDecorationColor: 2176 return currentColorOrValidColor(*style, style->textDecorationColor()); 2177 case CSSPropertyTextJustify: 2178 return cssValuePool().createValue(style->textJustify()); 2179 case CSSPropertyTextUnderlinePosition: 2180 return cssValuePool().createValue(style->textUnderlinePosition()); 2181 case CSSPropertyWebkitTextDecorationsInEffect: 2182 return renderTextDecorationFlagsToCSSValue(style->textDecorationsInEffect()); 2183 case CSSPropertyWebkitTextFillColor: 2184 return currentColorOrValidColor(*style, style->textFillColor()); 2185 case CSSPropertyWebkitTextEmphasisColor: 2186 return currentColorOrValidColor(*style, style->textEmphasisColor()); 2187 case CSSPropertyWebkitTextEmphasisPosition: 2188 return cssValuePool().createValue(style->textEmphasisPosition()); 2189 case CSSPropertyWebkitTextEmphasisStyle: 2190 switch (style->textEmphasisMark()) { 2191 case TextEmphasisMarkNone: 2192 return cssValuePool().createIdentifierValue(CSSValueNone); 2193 case TextEmphasisMarkCustom: 2194 return cssValuePool().createValue(style->textEmphasisCustomMark(), CSSPrimitiveValue::CSS_STRING); 2195 case TextEmphasisMarkAuto: 2196 ASSERT_NOT_REACHED(); 2197 // Fall through 2198 case TextEmphasisMarkDot: 2199 case TextEmphasisMarkCircle: 2200 case TextEmphasisMarkDoubleCircle: 2201 case TextEmphasisMarkTriangle: 2202 case TextEmphasisMarkSesame: { 2203 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2204 list->append(cssValuePool().createValue(style->textEmphasisFill())); 2205 list->append(cssValuePool().createValue(style->textEmphasisMark())); 2206 return list.release(); 2207 } 2208 } 2209 case CSSPropertyTextIndent: { 2210 // If RuntimeEnabledFeatures::css3TextEnabled() returns false or text-indent has only one value(<length> | <percentage>), 2211 // getPropertyCSSValue() returns CSSValue. 2212 // If RuntimeEnabledFeatures::css3TextEnabled() returns true and text-indent has each-line or hanging, 2213 // getPropertyCSSValue() returns CSSValueList. 2214 RefPtrWillBeRawPtr<CSSValue> textIndent = zoomAdjustedPixelValueForLength(style->textIndent(), *style); 2215 if (RuntimeEnabledFeatures::css3TextEnabled() && (style->textIndentLine() == TextIndentEachLine || style->textIndentType() == TextIndentHanging)) { 2216 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2217 list->append(textIndent.release()); 2218 if (style->textIndentLine() == TextIndentEachLine) 2219 list->append(cssValuePool().createIdentifierValue(CSSValueEachLine)); 2220 if (style->textIndentType() == TextIndentHanging) 2221 list->append(cssValuePool().createIdentifierValue(CSSValueHanging)); 2222 return list.release(); 2223 } 2224 return textIndent.release(); 2225 } 2226 case CSSPropertyTextShadow: 2227 return valueForShadowList(style->textShadow(), *style, false); 2228 case CSSPropertyTextRendering: 2229 return cssValuePool().createValue(style->fontDescription().textRendering()); 2230 case CSSPropertyTextOverflow: 2231 if (style->textOverflow()) 2232 return cssValuePool().createIdentifierValue(CSSValueEllipsis); 2233 return cssValuePool().createIdentifierValue(CSSValueClip); 2234 case CSSPropertyWebkitTextSecurity: 2235 return cssValuePool().createValue(style->textSecurity()); 2236 case CSSPropertyWebkitTextStrokeColor: 2237 return currentColorOrValidColor(*style, style->textStrokeColor()); 2238 case CSSPropertyWebkitTextStrokeWidth: 2239 return zoomAdjustedPixelValue(style->textStrokeWidth(), *style); 2240 case CSSPropertyTextTransform: 2241 return cssValuePool().createValue(style->textTransform()); 2242 case CSSPropertyTop: 2243 return valueForPositionOffset(*style, CSSPropertyTop, renderer); 2244 case CSSPropertyTouchAction: 2245 return touchActionFlagsToCSSValue(style->touchAction()); 2246 case CSSPropertyTouchActionDelay: 2247 return cssValuePool().createValue(style->touchActionDelay()); 2248 case CSSPropertyUnicodeBidi: 2249 return cssValuePool().createValue(style->unicodeBidi()); 2250 case CSSPropertyVerticalAlign: 2251 switch (style->verticalAlign()) { 2252 case BASELINE: 2253 return cssValuePool().createIdentifierValue(CSSValueBaseline); 2254 case MIDDLE: 2255 return cssValuePool().createIdentifierValue(CSSValueMiddle); 2256 case SUB: 2257 return cssValuePool().createIdentifierValue(CSSValueSub); 2258 case SUPER: 2259 return cssValuePool().createIdentifierValue(CSSValueSuper); 2260 case TEXT_TOP: 2261 return cssValuePool().createIdentifierValue(CSSValueTextTop); 2262 case TEXT_BOTTOM: 2263 return cssValuePool().createIdentifierValue(CSSValueTextBottom); 2264 case TOP: 2265 return cssValuePool().createIdentifierValue(CSSValueTop); 2266 case BOTTOM: 2267 return cssValuePool().createIdentifierValue(CSSValueBottom); 2268 case BASELINE_MIDDLE: 2269 return cssValuePool().createIdentifierValue(CSSValueWebkitBaselineMiddle); 2270 case LENGTH: 2271 return zoomAdjustedPixelValueForLength(style->verticalAlignLength(), *style); 2272 } 2273 ASSERT_NOT_REACHED(); 2274 return nullptr; 2275 case CSSPropertyVisibility: 2276 return cssValuePool().createValue(style->visibility()); 2277 case CSSPropertyWhiteSpace: 2278 return cssValuePool().createValue(style->whiteSpace()); 2279 case CSSPropertyWidows: 2280 if (style->hasAutoWidows()) 2281 return cssValuePool().createIdentifierValue(CSSValueAuto); 2282 return cssValuePool().createValue(style->widows(), CSSPrimitiveValue::CSS_NUMBER); 2283 case CSSPropertyWidth: 2284 if (renderer) { 2285 // According to http://www.w3.org/TR/CSS2/visudet.html#the-width-property, 2286 // the "width" property does not apply for non-replaced inline elements. 2287 if (!renderer->isReplaced() && renderer->isInline()) 2288 return cssValuePool().createIdentifierValue(CSSValueAuto); 2289 return zoomAdjustedPixelValue(sizingBox(renderer).width(), *style); 2290 } 2291 return zoomAdjustedPixelValueForLength(style->width(), *style); 2292 case CSSPropertyWillChange: 2293 return valueForWillChange(style->willChangeProperties(), style->willChangeContents(), style->willChangeScrollPosition()); 2294 case CSSPropertyWordBreak: 2295 return cssValuePool().createValue(style->wordBreak()); 2296 case CSSPropertyWordSpacing: 2297 return zoomAdjustedPixelValue(style->wordSpacing(), *style); 2298 case CSSPropertyWordWrap: 2299 return cssValuePool().createValue(style->overflowWrap()); 2300 case CSSPropertyWebkitLineBreak: 2301 return cssValuePool().createValue(style->lineBreak()); 2302 case CSSPropertyResize: 2303 return cssValuePool().createValue(style->resize()); 2304 case CSSPropertyFontKerning: 2305 return cssValuePool().createValue(style->fontDescription().kerning()); 2306 case CSSPropertyWebkitFontSmoothing: 2307 return cssValuePool().createValue(style->fontDescription().fontSmoothing()); 2308 case CSSPropertyFontVariantLigatures: { 2309 FontDescription::LigaturesState commonLigaturesState = style->fontDescription().commonLigaturesState(); 2310 FontDescription::LigaturesState discretionaryLigaturesState = style->fontDescription().discretionaryLigaturesState(); 2311 FontDescription::LigaturesState historicalLigaturesState = style->fontDescription().historicalLigaturesState(); 2312 FontDescription::LigaturesState contextualLigaturesState = style->fontDescription().contextualLigaturesState(); 2313 if (commonLigaturesState == FontDescription::NormalLigaturesState && discretionaryLigaturesState == FontDescription::NormalLigaturesState 2314 && historicalLigaturesState == FontDescription::NormalLigaturesState && contextualLigaturesState == FontDescription::NormalLigaturesState) 2315 return cssValuePool().createIdentifierValue(CSSValueNormal); 2316 2317 RefPtrWillBeRawPtr<CSSValueList> valueList = CSSValueList::createSpaceSeparated(); 2318 if (commonLigaturesState != FontDescription::NormalLigaturesState) 2319 valueList->append(cssValuePool().createIdentifierValue(commonLigaturesState == FontDescription::DisabledLigaturesState ? CSSValueNoCommonLigatures : CSSValueCommonLigatures)); 2320 if (discretionaryLigaturesState != FontDescription::NormalLigaturesState) 2321 valueList->append(cssValuePool().createIdentifierValue(discretionaryLigaturesState == FontDescription::DisabledLigaturesState ? CSSValueNoDiscretionaryLigatures : CSSValueDiscretionaryLigatures)); 2322 if (historicalLigaturesState != FontDescription::NormalLigaturesState) 2323 valueList->append(cssValuePool().createIdentifierValue(historicalLigaturesState == FontDescription::DisabledLigaturesState ? CSSValueNoHistoricalLigatures : CSSValueHistoricalLigatures)); 2324 if (contextualLigaturesState != FontDescription::NormalLigaturesState) 2325 valueList->append(cssValuePool().createIdentifierValue(contextualLigaturesState == FontDescription::DisabledLigaturesState ? CSSValueNoContextual : CSSValueContextual)); 2326 return valueList; 2327 } 2328 case CSSPropertyZIndex: 2329 if (style->hasAutoZIndex()) 2330 return cssValuePool().createIdentifierValue(CSSValueAuto); 2331 return cssValuePool().createValue(style->zIndex(), CSSPrimitiveValue::CSS_NUMBER); 2332 case CSSPropertyZoom: 2333 return cssValuePool().createValue(style->zoom(), CSSPrimitiveValue::CSS_NUMBER); 2334 case CSSPropertyBoxSizing: 2335 if (style->boxSizing() == CONTENT_BOX) 2336 return cssValuePool().createIdentifierValue(CSSValueContentBox); 2337 return cssValuePool().createIdentifierValue(CSSValueBorderBox); 2338 case CSSPropertyWebkitAppRegion: 2339 return cssValuePool().createIdentifierValue(style->getDraggableRegionMode() == DraggableRegionDrag ? CSSValueDrag : CSSValueNoDrag); 2340 case CSSPropertyAnimationDelay: 2341 ASSERT(RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled()); 2342 case CSSPropertyWebkitAnimationDelay: 2343 return valueForAnimationDelay(style->animations()); 2344 case CSSPropertyAnimationDirection: 2345 ASSERT(RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled()); 2346 case CSSPropertyWebkitAnimationDirection: { 2347 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 2348 const CSSAnimationData* animationData = style->animations(); 2349 if (animationData) { 2350 for (size_t i = 0; i < animationData->directionList().size(); ++i) 2351 list->append(valueForAnimationDirection(animationData->directionList()[i])); 2352 } else { 2353 list->append(cssValuePool().createIdentifierValue(CSSValueNormal)); 2354 } 2355 return list.release(); 2356 } 2357 case CSSPropertyAnimationDuration: 2358 ASSERT(RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled()); 2359 case CSSPropertyWebkitAnimationDuration: 2360 return valueForAnimationDuration(style->animations()); 2361 case CSSPropertyAnimationFillMode: 2362 ASSERT(RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled()); 2363 case CSSPropertyWebkitAnimationFillMode: { 2364 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 2365 const CSSAnimationData* animationData = style->animations(); 2366 if (animationData) { 2367 for (size_t i = 0; i < animationData->fillModeList().size(); ++i) 2368 list->append(valueForAnimationFillMode(animationData->fillModeList()[i])); 2369 } else { 2370 list->append(cssValuePool().createIdentifierValue(CSSValueNone)); 2371 } 2372 return list.release(); 2373 } 2374 case CSSPropertyAnimationIterationCount: 2375 ASSERT(RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled()); 2376 case CSSPropertyWebkitAnimationIterationCount: { 2377 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 2378 const CSSAnimationData* animationData = style->animations(); 2379 if (animationData) { 2380 for (size_t i = 0; i < animationData->iterationCountList().size(); ++i) 2381 list->append(valueForAnimationIterationCount(animationData->iterationCountList()[i])); 2382 } else { 2383 list->append(cssValuePool().createValue(CSSAnimationData::initialIterationCount(), CSSPrimitiveValue::CSS_NUMBER)); 2384 } 2385 return list.release(); 2386 } 2387 case CSSPropertyAnimationName: 2388 ASSERT(RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled()); 2389 case CSSPropertyWebkitAnimationName: { 2390 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 2391 const CSSAnimationData* animationData = style->animations(); 2392 if (animationData) { 2393 for (size_t i = 0; i < animationData->nameList().size(); ++i) 2394 list->append(cssValuePool().createValue(animationData->nameList()[i], CSSPrimitiveValue::CSS_STRING)); 2395 } else { 2396 list->append(cssValuePool().createIdentifierValue(CSSValueNone)); 2397 } 2398 return list.release(); 2399 } 2400 case CSSPropertyAnimationPlayState: 2401 ASSERT(RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled()); 2402 case CSSPropertyWebkitAnimationPlayState: { 2403 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 2404 const CSSAnimationData* animationData = style->animations(); 2405 if (animationData) { 2406 for (size_t i = 0; i < animationData->playStateList().size(); ++i) 2407 list->append(valueForAnimationPlayState(animationData->playStateList()[i])); 2408 } else { 2409 list->append(cssValuePool().createIdentifierValue(CSSValueRunning)); 2410 } 2411 return list.release(); 2412 } 2413 case CSSPropertyAnimationTimingFunction: 2414 ASSERT(RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled()); 2415 case CSSPropertyWebkitAnimationTimingFunction: 2416 return valueForAnimationTimingFunction(style->animations()); 2417 case CSSPropertyAnimation: 2418 case CSSPropertyWebkitAnimation: { 2419 const CSSAnimationData* animationData = style->animations(); 2420 if (animationData) { 2421 RefPtrWillBeRawPtr<CSSValueList> animationsList = CSSValueList::createCommaSeparated(); 2422 for (size_t i = 0; i < animationData->nameList().size(); ++i) { 2423 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2424 list->append(cssValuePool().createValue(animationData->nameList()[i], CSSPrimitiveValue::CSS_STRING)); 2425 list->append(cssValuePool().createValue(CSSTimingData::getRepeated(animationData->durationList(), i), CSSPrimitiveValue::CSS_S)); 2426 list->append(createTimingFunctionValue(CSSTimingData::getRepeated(animationData->timingFunctionList(), i).get())); 2427 list->append(cssValuePool().createValue(CSSTimingData::getRepeated(animationData->delayList(), i), CSSPrimitiveValue::CSS_S)); 2428 list->append(valueForAnimationIterationCount(CSSTimingData::getRepeated(animationData->iterationCountList(), i))); 2429 list->append(valueForAnimationDirection(CSSTimingData::getRepeated(animationData->directionList(), i))); 2430 list->append(valueForAnimationFillMode(CSSTimingData::getRepeated(animationData->fillModeList(), i))); 2431 list->append(valueForAnimationPlayState(CSSTimingData::getRepeated(animationData->playStateList(), i))); 2432 animationsList->append(list); 2433 } 2434 return animationsList.release(); 2435 } 2436 2437 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2438 // animation-name default value. 2439 list->append(cssValuePool().createIdentifierValue(CSSValueNone)); 2440 list->append(cssValuePool().createValue(CSSAnimationData::initialDuration(), CSSPrimitiveValue::CSS_S)); 2441 list->append(createTimingFunctionValue(CSSAnimationData::initialTimingFunction().get())); 2442 list->append(cssValuePool().createValue(CSSAnimationData::initialDelay(), CSSPrimitiveValue::CSS_S)); 2443 list->append(cssValuePool().createValue(CSSAnimationData::initialIterationCount(), CSSPrimitiveValue::CSS_NUMBER)); 2444 list->append(valueForAnimationDirection(CSSAnimationData::initialDirection())); 2445 list->append(valueForAnimationFillMode(CSSAnimationData::initialFillMode())); 2446 // Initial animation-play-state. 2447 list->append(cssValuePool().createIdentifierValue(CSSValueRunning)); 2448 return list.release(); 2449 } 2450 case CSSPropertyWebkitAppearance: 2451 return cssValuePool().createValue(style->appearance()); 2452 case CSSPropertyWebkitAspectRatio: 2453 if (!style->hasAspectRatio()) 2454 return cssValuePool().createIdentifierValue(CSSValueNone); 2455 return CSSAspectRatioValue::create(style->aspectRatioNumerator(), style->aspectRatioDenominator()); 2456 case CSSPropertyBackfaceVisibility: 2457 case CSSPropertyWebkitBackfaceVisibility: 2458 return cssValuePool().createIdentifierValue((style->backfaceVisibility() == BackfaceVisibilityHidden) ? CSSValueHidden : CSSValueVisible); 2459 case CSSPropertyWebkitBorderImage: 2460 return valueForNinePieceImage(style->borderImage(), *style); 2461 case CSSPropertyBorderImageOutset: 2462 return valueForNinePieceImageQuad(style->borderImage().outset(), *style); 2463 case CSSPropertyBorderImageRepeat: 2464 return valueForNinePieceImageRepeat(style->borderImage()); 2465 case CSSPropertyBorderImageSlice: 2466 return valueForNinePieceImageSlice(style->borderImage()); 2467 case CSSPropertyBorderImageWidth: 2468 return valueForNinePieceImageQuad(style->borderImage().borderSlices(), *style); 2469 case CSSPropertyWebkitMaskBoxImage: 2470 return valueForNinePieceImage(style->maskBoxImage(), *style); 2471 case CSSPropertyWebkitMaskBoxImageOutset: 2472 return valueForNinePieceImageQuad(style->maskBoxImage().outset(), *style); 2473 case CSSPropertyWebkitMaskBoxImageRepeat: 2474 return valueForNinePieceImageRepeat(style->maskBoxImage()); 2475 case CSSPropertyWebkitMaskBoxImageSlice: 2476 return valueForNinePieceImageSlice(style->maskBoxImage()); 2477 case CSSPropertyWebkitMaskBoxImageWidth: 2478 return valueForNinePieceImageQuad(style->maskBoxImage().borderSlices(), *style); 2479 case CSSPropertyWebkitMaskBoxImageSource: 2480 if (style->maskBoxImageSource()) 2481 return style->maskBoxImageSource()->cssValue(); 2482 return cssValuePool().createIdentifierValue(CSSValueNone); 2483 case CSSPropertyWebkitFontSizeDelta: 2484 // Not a real style property -- used by the editing engine -- so has no computed value. 2485 break; 2486 case CSSPropertyWebkitMarginBottomCollapse: 2487 case CSSPropertyWebkitMarginAfterCollapse: 2488 return cssValuePool().createValue(style->marginAfterCollapse()); 2489 case CSSPropertyWebkitMarginTopCollapse: 2490 case CSSPropertyWebkitMarginBeforeCollapse: 2491 return cssValuePool().createValue(style->marginBeforeCollapse()); 2492 case CSSPropertyPerspective: 2493 case CSSPropertyWebkitPerspective: 2494 if (!style->hasPerspective()) 2495 return cssValuePool().createIdentifierValue(CSSValueNone); 2496 return zoomAdjustedPixelValue(style->perspective(), *style); 2497 case CSSPropertyPerspectiveOrigin: 2498 case CSSPropertyWebkitPerspectiveOrigin: { 2499 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2500 if (renderer) { 2501 LayoutRect box; 2502 if (renderer->isBox()) 2503 box = toRenderBox(renderer)->borderBoxRect(); 2504 2505 list->append(zoomAdjustedPixelValue(minimumValueForLength(style->perspectiveOriginX(), box.width()), *style)); 2506 list->append(zoomAdjustedPixelValue(minimumValueForLength(style->perspectiveOriginY(), box.height()), *style)); 2507 } 2508 else { 2509 list->append(zoomAdjustedPixelValueForLength(style->perspectiveOriginX(), *style)); 2510 list->append(zoomAdjustedPixelValueForLength(style->perspectiveOriginY(), *style)); 2511 2512 } 2513 return list.release(); 2514 } 2515 case CSSPropertyWebkitRtlOrdering: 2516 return cssValuePool().createIdentifierValue(style->rtlOrdering() ? CSSValueVisual : CSSValueLogical); 2517 case CSSPropertyWebkitTapHighlightColor: 2518 return currentColorOrValidColor(*style, style->tapHighlightColor()); 2519 case CSSPropertyWebkitUserDrag: 2520 return cssValuePool().createValue(style->userDrag()); 2521 case CSSPropertyWebkitUserSelect: 2522 return cssValuePool().createValue(style->userSelect()); 2523 case CSSPropertyBorderBottomLeftRadius: 2524 return valueForBorderRadiusCorner(style->borderBottomLeftRadius(), *style); 2525 case CSSPropertyBorderBottomRightRadius: 2526 return valueForBorderRadiusCorner(style->borderBottomRightRadius(), *style); 2527 case CSSPropertyBorderTopLeftRadius: 2528 return valueForBorderRadiusCorner(style->borderTopLeftRadius(), *style); 2529 case CSSPropertyBorderTopRightRadius: 2530 return valueForBorderRadiusCorner(style->borderTopRightRadius(), *style); 2531 case CSSPropertyClip: { 2532 if (style->hasAutoClip()) 2533 return cssValuePool().createIdentifierValue(CSSValueAuto); 2534 RefPtrWillBeRawPtr<Rect> rect = Rect::create(); 2535 rect->setTop(zoomAdjustedPixelValue(style->clip().top().value(), *style)); 2536 rect->setRight(zoomAdjustedPixelValue(style->clip().right().value(), *style)); 2537 rect->setBottom(zoomAdjustedPixelValue(style->clip().bottom().value(), *style)); 2538 rect->setLeft(zoomAdjustedPixelValue(style->clip().left().value(), *style)); 2539 return cssValuePool().createValue(rect.release()); 2540 } 2541 case CSSPropertySpeak: 2542 return cssValuePool().createValue(style->speak()); 2543 case CSSPropertyTransform: 2544 case CSSPropertyWebkitTransform: 2545 return computedTransform(renderer, *style); 2546 case CSSPropertyTransformOrigin: 2547 case CSSPropertyWebkitTransformOrigin: { 2548 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2549 if (renderer) { 2550 LayoutRect box; 2551 if (renderer->isBox()) 2552 box = toRenderBox(renderer)->borderBoxRect(); 2553 2554 list->append(zoomAdjustedPixelValue(minimumValueForLength(style->transformOriginX(), box.width()), *style)); 2555 list->append(zoomAdjustedPixelValue(minimumValueForLength(style->transformOriginY(), box.height()), *style)); 2556 if (style->transformOriginZ() != 0) 2557 list->append(zoomAdjustedPixelValue(style->transformOriginZ(), *style)); 2558 } else { 2559 list->append(zoomAdjustedPixelValueForLength(style->transformOriginX(), *style)); 2560 list->append(zoomAdjustedPixelValueForLength(style->transformOriginY(), *style)); 2561 if (style->transformOriginZ() != 0) 2562 list->append(zoomAdjustedPixelValue(style->transformOriginZ(), *style)); 2563 } 2564 return list.release(); 2565 } 2566 case CSSPropertyTransformStyle: 2567 case CSSPropertyWebkitTransformStyle: 2568 return cssValuePool().createIdentifierValue((style->transformStyle3D() == TransformStyle3DPreserve3D) ? CSSValuePreserve3d : CSSValueFlat); 2569 case CSSPropertyTransitionDelay: 2570 case CSSPropertyWebkitTransitionDelay: 2571 return valueForAnimationDelay(style->transitions()); 2572 case CSSPropertyTransitionDuration: 2573 case CSSPropertyWebkitTransitionDuration: 2574 return valueForAnimationDuration(style->transitions()); 2575 case CSSPropertyTransitionProperty: 2576 case CSSPropertyWebkitTransitionProperty: 2577 return valueForTransitionProperty(style->transitions()); 2578 case CSSPropertyTransitionTimingFunction: 2579 case CSSPropertyWebkitTransitionTimingFunction: 2580 return valueForAnimationTimingFunction(style->transitions()); 2581 case CSSPropertyTransition: 2582 case CSSPropertyWebkitTransition: { 2583 const CSSTransitionData* transitionData = style->transitions(); 2584 if (transitionData) { 2585 RefPtrWillBeRawPtr<CSSValueList> transitionsList = CSSValueList::createCommaSeparated(); 2586 for (size_t i = 0; i < transitionData->propertyList().size(); ++i) { 2587 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2588 list->append(createTransitionPropertyValue(transitionData->propertyList()[i])); 2589 list->append(cssValuePool().createValue(CSSTimingData::getRepeated(transitionData->durationList(), i), CSSPrimitiveValue::CSS_S)); 2590 list->append(createTimingFunctionValue(CSSTimingData::getRepeated(transitionData->timingFunctionList(), i).get())); 2591 list->append(cssValuePool().createValue(CSSTimingData::getRepeated(transitionData->delayList(), i), CSSPrimitiveValue::CSS_S)); 2592 transitionsList->append(list); 2593 } 2594 return transitionsList.release(); 2595 } 2596 2597 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2598 // transition-property default value. 2599 list->append(cssValuePool().createIdentifierValue(CSSValueAll)); 2600 list->append(cssValuePool().createValue(CSSTransitionData::initialDuration(), CSSPrimitiveValue::CSS_S)); 2601 list->append(createTimingFunctionValue(CSSTransitionData::initialTimingFunction().get())); 2602 list->append(cssValuePool().createValue(CSSTransitionData::initialDelay(), CSSPrimitiveValue::CSS_S)); 2603 return list.release(); 2604 } 2605 case CSSPropertyPointerEvents: 2606 return cssValuePool().createValue(style->pointerEvents()); 2607 case CSSPropertyWebkitWritingMode: 2608 return cssValuePool().createValue(style->writingMode()); 2609 case CSSPropertyWebkitTextCombine: 2610 return cssValuePool().createValue(style->textCombine()); 2611 case CSSPropertyWebkitTextOrientation: 2612 return CSSPrimitiveValue::create(style->textOrientation()); 2613 case CSSPropertyWebkitLineBoxContain: 2614 return createLineBoxContainValue(style->lineBoxContain()); 2615 case CSSPropertyContent: 2616 return valueForContentData(*style); 2617 case CSSPropertyCounterIncrement: 2618 return valueForCounterDirectives(*style, propertyID); 2619 case CSSPropertyCounterReset: 2620 return valueForCounterDirectives(*style, propertyID); 2621 case CSSPropertyWebkitClipPath: 2622 if (ClipPathOperation* operation = style->clipPath()) { 2623 if (operation->type() == ClipPathOperation::SHAPE) 2624 return valueForBasicShape(*style, toShapeClipPathOperation(operation)->basicShape()); 2625 if (operation->type() == ClipPathOperation::REFERENCE) 2626 return CSSPrimitiveValue::create(toReferenceClipPathOperation(operation)->url(), CSSPrimitiveValue::CSS_URI); 2627 } 2628 return cssValuePool().createIdentifierValue(CSSValueNone); 2629 case CSSPropertyShapeMargin: 2630 return cssValuePool().createValue(style->shapeMargin(), *style); 2631 case CSSPropertyShapeImageThreshold: 2632 return cssValuePool().createValue(style->shapeImageThreshold(), CSSPrimitiveValue::CSS_NUMBER); 2633 case CSSPropertyShapeOutside: 2634 return valueForShape(*style, style->shapeOutside()); 2635 case CSSPropertyWebkitFilter: 2636 return valueForFilter(renderer, *style); 2637 case CSSPropertyMixBlendMode: 2638 return cssValuePool().createValue(style->blendMode()); 2639 2640 case CSSPropertyBackgroundBlendMode: { 2641 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated(); 2642 for (const FillLayer* currLayer = &style->backgroundLayers(); currLayer; currLayer = currLayer->next()) 2643 list->append(cssValuePool().createValue(currLayer->blendMode())); 2644 return list.release(); 2645 } 2646 case CSSPropertyBackground: 2647 return valuesForBackgroundShorthand(); 2648 case CSSPropertyBorder: { 2649 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(CSSPropertyBorderTop, DoNotUpdateLayout); 2650 const CSSPropertyID properties[3] = { CSSPropertyBorderRight, CSSPropertyBorderBottom, 2651 CSSPropertyBorderLeft }; 2652 for (size_t i = 0; i < WTF_ARRAY_LENGTH(properties); ++i) { 2653 if (!compareCSSValuePtr<CSSValue>(value, getPropertyCSSValue(properties[i], DoNotUpdateLayout))) 2654 return nullptr; 2655 } 2656 return value.release(); 2657 } 2658 case CSSPropertyBorderBottom: 2659 return valuesForShorthandProperty(borderBottomShorthand()); 2660 case CSSPropertyBorderColor: 2661 return valuesForSidesShorthand(borderColorShorthand()); 2662 case CSSPropertyBorderLeft: 2663 return valuesForShorthandProperty(borderLeftShorthand()); 2664 case CSSPropertyBorderImage: 2665 return valueForNinePieceImage(style->borderImage(), *style); 2666 case CSSPropertyBorderRadius: 2667 return valueForBorderRadiusShorthand(*style); 2668 case CSSPropertyBorderRight: 2669 return valuesForShorthandProperty(borderRightShorthand()); 2670 case CSSPropertyBorderStyle: 2671 return valuesForSidesShorthand(borderStyleShorthand()); 2672 case CSSPropertyBorderTop: 2673 return valuesForShorthandProperty(borderTopShorthand()); 2674 case CSSPropertyBorderWidth: 2675 return valuesForSidesShorthand(borderWidthShorthand()); 2676 case CSSPropertyWebkitColumnRule: 2677 return valuesForShorthandProperty(webkitColumnRuleShorthand()); 2678 case CSSPropertyWebkitColumns: 2679 return valuesForShorthandProperty(webkitColumnsShorthand()); 2680 case CSSPropertyListStyle: 2681 return valuesForShorthandProperty(listStyleShorthand()); 2682 case CSSPropertyMargin: 2683 return valuesForSidesShorthand(marginShorthand()); 2684 case CSSPropertyOutline: 2685 return valuesForShorthandProperty(outlineShorthand()); 2686 case CSSPropertyPadding: 2687 return valuesForSidesShorthand(paddingShorthand()); 2688 /* Individual properties not part of the spec */ 2689 case CSSPropertyBackgroundRepeatX: 2690 case CSSPropertyBackgroundRepeatY: 2691 break; 2692 2693 /* Unimplemented CSS 3 properties (including CSS3 shorthand properties) */ 2694 case CSSPropertyWebkitTextEmphasis: 2695 break; 2696 2697 /* Directional properties are resolved by resolveDirectionAwareProperty() before the switch. */ 2698 case CSSPropertyWebkitBorderEnd: 2699 case CSSPropertyWebkitBorderEndColor: 2700 case CSSPropertyWebkitBorderEndStyle: 2701 case CSSPropertyWebkitBorderEndWidth: 2702 case CSSPropertyWebkitBorderStart: 2703 case CSSPropertyWebkitBorderStartColor: 2704 case CSSPropertyWebkitBorderStartStyle: 2705 case CSSPropertyWebkitBorderStartWidth: 2706 case CSSPropertyWebkitBorderAfter: 2707 case CSSPropertyWebkitBorderAfterColor: 2708 case CSSPropertyWebkitBorderAfterStyle: 2709 case CSSPropertyWebkitBorderAfterWidth: 2710 case CSSPropertyWebkitBorderBefore: 2711 case CSSPropertyWebkitBorderBeforeColor: 2712 case CSSPropertyWebkitBorderBeforeStyle: 2713 case CSSPropertyWebkitBorderBeforeWidth: 2714 case CSSPropertyWebkitMarginEnd: 2715 case CSSPropertyWebkitMarginStart: 2716 case CSSPropertyWebkitMarginAfter: 2717 case CSSPropertyWebkitMarginBefore: 2718 case CSSPropertyWebkitPaddingEnd: 2719 case CSSPropertyWebkitPaddingStart: 2720 case CSSPropertyWebkitPaddingAfter: 2721 case CSSPropertyWebkitPaddingBefore: 2722 case CSSPropertyWebkitLogicalWidth: 2723 case CSSPropertyWebkitLogicalHeight: 2724 case CSSPropertyWebkitMinLogicalWidth: 2725 case CSSPropertyWebkitMinLogicalHeight: 2726 case CSSPropertyWebkitMaxLogicalWidth: 2727 case CSSPropertyWebkitMaxLogicalHeight: 2728 ASSERT_NOT_REACHED(); 2729 break; 2730 2731 /* Unimplemented @font-face properties */ 2732 case CSSPropertySrc: 2733 case CSSPropertyUnicodeRange: 2734 break; 2735 2736 /* Other unimplemented properties */ 2737 case CSSPropertyPage: // for @page 2738 case CSSPropertyQuotes: // FIXME: needs implementation 2739 case CSSPropertySize: // for @page 2740 break; 2741 2742 /* Unimplemented -webkit- properties */ 2743 case CSSPropertyWebkitBorderRadius: 2744 case CSSPropertyWebkitMarginCollapse: 2745 case CSSPropertyWebkitMask: 2746 case CSSPropertyWebkitMaskRepeatX: 2747 case CSSPropertyWebkitMaskRepeatY: 2748 case CSSPropertyWebkitPerspectiveOriginX: 2749 case CSSPropertyWebkitPerspectiveOriginY: 2750 case CSSPropertyWebkitTextStroke: 2751 case CSSPropertyWebkitTransformOriginX: 2752 case CSSPropertyWebkitTransformOriginY: 2753 case CSSPropertyWebkitTransformOriginZ: 2754 break; 2755 2756 /* @viewport rule properties */ 2757 case CSSPropertyMaxZoom: 2758 case CSSPropertyMinZoom: 2759 case CSSPropertyOrientation: 2760 case CSSPropertyUserZoom: 2761 break; 2762 2763 // Internal properties that shouldn't be exposed throught getComputedStyle. 2764 case CSSPropertyInternalMarqueeDirection: 2765 case CSSPropertyInternalMarqueeIncrement: 2766 case CSSPropertyInternalMarqueeRepetition: 2767 case CSSPropertyInternalMarqueeSpeed: 2768 case CSSPropertyInternalMarqueeStyle: 2769 ASSERT_NOT_REACHED(); 2770 return nullptr; 2771 2772 case CSSPropertyBufferedRendering: 2773 case CSSPropertyClipPath: 2774 case CSSPropertyClipRule: 2775 case CSSPropertyMask: 2776 case CSSPropertyEnableBackground: 2777 case CSSPropertyFilter: 2778 case CSSPropertyFloodColor: 2779 case CSSPropertyFloodOpacity: 2780 case CSSPropertyLightingColor: 2781 case CSSPropertyStopColor: 2782 case CSSPropertyStopOpacity: 2783 case CSSPropertyColorInterpolation: 2784 case CSSPropertyColorInterpolationFilters: 2785 case CSSPropertyColorRendering: 2786 case CSSPropertyFill: 2787 case CSSPropertyFillOpacity: 2788 case CSSPropertyFillRule: 2789 case CSSPropertyMarker: 2790 case CSSPropertyMarkerEnd: 2791 case CSSPropertyMarkerMid: 2792 case CSSPropertyMarkerStart: 2793 case CSSPropertyMaskType: 2794 case CSSPropertyShapeRendering: 2795 case CSSPropertyStroke: 2796 case CSSPropertyStrokeDasharray: 2797 case CSSPropertyStrokeDashoffset: 2798 case CSSPropertyStrokeLinecap: 2799 case CSSPropertyStrokeLinejoin: 2800 case CSSPropertyStrokeMiterlimit: 2801 case CSSPropertyStrokeOpacity: 2802 case CSSPropertyStrokeWidth: 2803 case CSSPropertyAlignmentBaseline: 2804 case CSSPropertyBaselineShift: 2805 case CSSPropertyDominantBaseline: 2806 case CSSPropertyGlyphOrientationHorizontal: 2807 case CSSPropertyGlyphOrientationVertical: 2808 case CSSPropertyTextAnchor: 2809 case CSSPropertyVectorEffect: 2810 case CSSPropertyPaintOrder: 2811 case CSSPropertyWritingMode: 2812 return getSVGPropertyCSSValue(propertyID, DoNotUpdateLayout); 2813 2814 case CSSPropertyAll: 2815 return nullptr; 2816 } 2817 2818 logUnimplementedPropertyID(propertyID); 2819 return nullptr; 2820 } 2821 2822 String CSSComputedStyleDeclaration::getPropertyValue(CSSPropertyID propertyID) const 2823 { 2824 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); 2825 if (value) 2826 return value->cssText(); 2827 return ""; 2828 } 2829 2830 2831 unsigned CSSComputedStyleDeclaration::length() const 2832 { 2833 if (!m_node || !m_node->inActiveDocument()) 2834 return 0; 2835 return computableProperties().size(); 2836 } 2837 2838 String CSSComputedStyleDeclaration::item(unsigned i) const 2839 { 2840 if (i >= length()) 2841 return ""; 2842 2843 return getPropertyNameString(computableProperties()[i]); 2844 } 2845 2846 bool CSSComputedStyleDeclaration::cssPropertyMatches(CSSPropertyID propertyID, const CSSValue* propertyValue) const 2847 { 2848 if (propertyID == CSSPropertyFontSize && propertyValue->isPrimitiveValue() && m_node) { 2849 m_node->document().updateLayoutIgnorePendingStylesheets(); 2850 RenderStyle* style = m_node->computedStyle(m_pseudoElementSpecifier); 2851 if (style && style->fontDescription().keywordSize()) { 2852 CSSValueID sizeValue = cssIdentifierForFontSizeKeyword(style->fontDescription().keywordSize()); 2853 const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(propertyValue); 2854 if (primitiveValue->isValueID() && primitiveValue->getValueID() == sizeValue) 2855 return true; 2856 } 2857 } 2858 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); 2859 return value && propertyValue && value->equals(*propertyValue); 2860 } 2861 2862 PassRefPtrWillBeRawPtr<MutableStylePropertySet> CSSComputedStyleDeclaration::copyProperties() const 2863 { 2864 return copyPropertiesInSet(computableProperties()); 2865 } 2866 2867 PassRefPtrWillBeRawPtr<CSSValueList> CSSComputedStyleDeclaration::valuesForShorthandProperty(const StylePropertyShorthand& shorthand) const 2868 { 2869 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2870 for (size_t i = 0; i < shorthand.length(); ++i) { 2871 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.properties()[i], DoNotUpdateLayout); 2872 list->append(value); 2873 } 2874 return list.release(); 2875 } 2876 2877 PassRefPtrWillBeRawPtr<CSSValueList> CSSComputedStyleDeclaration::valuesForSidesShorthand(const StylePropertyShorthand& shorthand) const 2878 { 2879 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2880 // Assume the properties are in the usual order top, right, bottom, left. 2881 RefPtrWillBeRawPtr<CSSValue> topValue = getPropertyCSSValue(shorthand.properties()[0], DoNotUpdateLayout); 2882 RefPtrWillBeRawPtr<CSSValue> rightValue = getPropertyCSSValue(shorthand.properties()[1], DoNotUpdateLayout); 2883 RefPtrWillBeRawPtr<CSSValue> bottomValue = getPropertyCSSValue(shorthand.properties()[2], DoNotUpdateLayout); 2884 RefPtrWillBeRawPtr<CSSValue> leftValue = getPropertyCSSValue(shorthand.properties()[3], DoNotUpdateLayout); 2885 2886 // All 4 properties must be specified. 2887 if (!topValue || !rightValue || !bottomValue || !leftValue) 2888 return nullptr; 2889 2890 bool showLeft = !compareCSSValuePtr(rightValue, leftValue); 2891 bool showBottom = !compareCSSValuePtr(topValue, bottomValue) || showLeft; 2892 bool showRight = !compareCSSValuePtr(topValue, rightValue) || showBottom; 2893 2894 list->append(topValue.release()); 2895 if (showRight) 2896 list->append(rightValue.release()); 2897 if (showBottom) 2898 list->append(bottomValue.release()); 2899 if (showLeft) 2900 list->append(leftValue.release()); 2901 2902 return list.release(); 2903 } 2904 2905 PassRefPtrWillBeRawPtr<CSSValueList> CSSComputedStyleDeclaration::valuesForGridShorthand(const StylePropertyShorthand& shorthand) const 2906 { 2907 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSlashSeparated(); 2908 for (size_t i = 0; i < shorthand.length(); ++i) { 2909 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(shorthand.properties()[i], DoNotUpdateLayout); 2910 list->append(value.release()); 2911 } 2912 return list.release(); 2913 } 2914 2915 PassRefPtrWillBeRawPtr<MutableStylePropertySet> CSSComputedStyleDeclaration::copyPropertiesInSet(const Vector<CSSPropertyID>& properties) const 2916 { 2917 WillBeHeapVector<CSSProperty, 256> list; 2918 list.reserveInitialCapacity(properties.size()); 2919 for (unsigned i = 0; i < properties.size(); ++i) { 2920 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(properties[i]); 2921 if (value) 2922 list.append(CSSProperty(properties[i], value.release(), false)); 2923 } 2924 return MutableStylePropertySet::create(list.data(), list.size()); 2925 } 2926 2927 CSSRule* CSSComputedStyleDeclaration::parentRule() const 2928 { 2929 return 0; 2930 } 2931 2932 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValue(const String& propertyName) 2933 { 2934 CSSPropertyID propertyID = cssPropertyID(propertyName); 2935 if (!propertyID) 2936 return nullptr; 2937 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); 2938 return value ? value->cloneForCSSOM() : nullptr; 2939 } 2940 2941 String CSSComputedStyleDeclaration::getPropertyValue(const String& propertyName) 2942 { 2943 CSSPropertyID propertyID = cssPropertyID(propertyName); 2944 if (!propertyID) 2945 return String(); 2946 ASSERT(CSSPropertyMetadata::isEnabledProperty(propertyID)); 2947 return getPropertyValue(propertyID); 2948 } 2949 2950 String CSSComputedStyleDeclaration::getPropertyPriority(const String&) 2951 { 2952 // All computed styles have a priority of not "important". 2953 return ""; 2954 } 2955 2956 String CSSComputedStyleDeclaration::getPropertyShorthand(const String&) 2957 { 2958 return ""; 2959 } 2960 2961 bool CSSComputedStyleDeclaration::isPropertyImplicit(const String&) 2962 { 2963 return false; 2964 } 2965 2966 void CSSComputedStyleDeclaration::setProperty(const String& name, const String&, const String&, ExceptionState& exceptionState) 2967 { 2968 exceptionState.throwDOMException(NoModificationAllowedError, "These styles are computed, and therefore the '" + name + "' property is read-only."); 2969 } 2970 2971 String CSSComputedStyleDeclaration::removeProperty(const String& name, ExceptionState& exceptionState) 2972 { 2973 exceptionState.throwDOMException(NoModificationAllowedError, "These styles are computed, and therefore the '" + name + "' property is read-only."); 2974 return String(); 2975 } 2976 2977 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID) 2978 { 2979 return getPropertyCSSValue(propertyID); 2980 } 2981 2982 String CSSComputedStyleDeclaration::getPropertyValueInternal(CSSPropertyID propertyID) 2983 { 2984 return getPropertyValue(propertyID); 2985 } 2986 2987 void CSSComputedStyleDeclaration::setPropertyInternal(CSSPropertyID id, const String&, bool, ExceptionState& exceptionState) 2988 { 2989 exceptionState.throwDOMException(NoModificationAllowedError, "These styles are computed, and therefore the '" + getPropertyNameString(id) + "' property is read-only."); 2990 } 2991 2992 PassRefPtrWillBeRawPtr<CSSValueList> CSSComputedStyleDeclaration::valuesForBackgroundShorthand() const 2993 { 2994 static const CSSPropertyID propertiesBeforeSlashSeperator[5] = { CSSPropertyBackgroundColor, CSSPropertyBackgroundImage, 2995 CSSPropertyBackgroundRepeat, CSSPropertyBackgroundAttachment, 2996 CSSPropertyBackgroundPosition }; 2997 static const CSSPropertyID propertiesAfterSlashSeperator[3] = { CSSPropertyBackgroundSize, CSSPropertyBackgroundOrigin, 2998 CSSPropertyBackgroundClip }; 2999 3000 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSlashSeparated(); 3001 list->append(valuesForShorthandProperty(StylePropertyShorthand(CSSPropertyBackground, propertiesBeforeSlashSeperator, WTF_ARRAY_LENGTH(propertiesBeforeSlashSeperator)))); 3002 list->append(valuesForShorthandProperty(StylePropertyShorthand(CSSPropertyBackground, propertiesAfterSlashSeperator, WTF_ARRAY_LENGTH(propertiesAfterSlashSeperator)))); 3003 return list.release(); 3004 } 3005 3006 void CSSComputedStyleDeclaration::trace(Visitor* visitor) 3007 { 3008 visitor->trace(m_node); 3009 CSSStyleDeclaration::trace(visitor); 3010 } 3011 3012 } // namespace blink 3013