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