12011-01-07 Simon Fraser <simon.fraser@apple.com>
2
3 Reviewed by NOBODY (OOPS!).
4
5 Implement object-fit CSS property
6 https://bugs.webkit.org/show_bug.cgi?id=52040
7
8 Implement -webkit-object-fit, as described in
9 <http://dev.w3.org/csswg/css3-images/#object-fit>,
10 with the exception of the overflow behavior.
11
12 This property allows authors to fit replaced elements in their
13 contents box while maintaining aspect ratio.
14
15 Tests: fast/css/object-fit-elements.html
16 fast/css/object-fit-elements2.html
17 fast/css/object-fit-grow.html
18 fast/css/object-fit-shrink.html
19 fast/css/parsing-object-fit.html
20 media/video-object-fit.html
21
22 * css/CSSComputedStyleDeclaration.cpp:
23 (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): Return computed
24 style for the property.
25
26 * css/CSSParser.cpp:
27 (WebCore::CSSParser::parseValue): Handle object-fit, whose value is just keywords.
28
29 * css/CSSPrimitiveValueMappings.h:
30 (WebCore::CSSPrimitiveValue::CSSPrimitiveValue):
31 (WebCore::CSSPrimitiveValue::operator EObjectFitType): Map between RenderStyle enums
32 and the primitive value IDs.
33
34 * css/CSSPropertyNames.in: Add -webkit-object-fit.
35
36 * css/CSSStyleSelector.cpp:
37 (WebCore::CSSStyleSelector::applyProperty): Apply CSSPropertyWebkitObjectFit.
38
39 * css/CSSValueKeywords.in: Commented lines denoting use of existing keywords
40 for this property.
41
42 * platform/graphics/FloatRect.h: Add three new functions.
43 * platform/graphics/FloatRect.cpp:
44 (WebCore::enclosedIntRect): Like enclosingIntRect(), but rounds inwards.
45 (WebCore::centeredRect): Center one rect in another.
46 (WebCore::fitInRectMaintainingAspectRatio): Grow or shrink a rect, maintaining
47 aspect ratio, to fix into another rect (possibly spilling out on one axis).
48
49 * rendering/RenderHTMLCanvas.cpp:
50 (WebCore::RenderHTMLCanvas::paintReplaced): Respect object-fit when rendering, clipping
51 if necessary.
52
53 * rendering/RenderImage.h: Pass tx,ty into paintIntoRect().
54 * rendering/RenderImage.cpp:
55 (WebCore::RenderImage::paintReplaced): Call replacedContentRect() to get the rect
56 to paint into.
57 (WebCore::RenderImage::paintIntoRect): Now that rect can extend outside contentBoxRect(),
58 clip if necessary.
59
60 * rendering/RenderReplaced.h:
61 (WebCore::RenderReplaced::hasIntrinsicSize): New getter.
62 * rendering/RenderReplaced.cpp:
63 (WebCore::RenderReplaced::replacedContentRect): Compute the rect for the replaced content,
64 taking object-fit into account. Map 'auto' values to 'contain' for video, otherwise 'fill'.
65
66 * rendering/RenderVideo.cpp:
67 (WebCore::RenderVideo::videoBox): Replace existing aspect-ratio mapping code with call to
68 replacedContentRect().
69 (WebCore::RenderVideo::paintReplaced): Pass tx, ty.
70
71 * rendering/style/RenderStyle.h:
72 (WebCore::InheritedFlags::objectFit): Getter.
73 (WebCore::InheritedFlags::setObjectFit): Setter.
74 (WebCore::InheritedFlags::initialObjectFit): Initial value.
75 * rendering/style/RenderStyle.cpp:
76 (WebCore::RenderStyle::diff): Compare rareInheritedData->objectFit.
77
78 * rendering/style/RenderStyleConstants.h: New enum for object-fit values.
79
80 * rendering/style/StyleRareInheritedData.h: Add object-fit.
81 * rendering/style/StyleRareInheritedData.cpp:
82 (WebCore::StyleRareInheritedData::StyleRareInheritedData):
83 (WebCore::StyleRareInheritedData::operator==):
84