Title: [197617] trunk
Revision
197617
Author
[email protected]
Date
2016-03-05 15:23:40 -0800 (Sat, 05 Mar 2016)

Log Message

Add parsing support for object-position
https://bugs.webkit.org/show_bug.cgi?id=155065

Reviewed by Sam Weinig.

Source/WebCore:

Add parsing support for object-position. This is the first property with
CSS <position> values which does not have equivalent -x and -y shorthands,
so we can store it as a new LengthPoint type.

Per the CSS Values spec, bottom- and right-relative values are translated
into calc() expressions, which are exposed via computed style. For example,
"right 10px bottom" becomes "calc(100% - 10px) 100%". This also allows transitions
between, say, "left 10px bottom" and "right 10px bottom".

Test: fast/css/object-position/parsing-object-position.html

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::propertyValue):
* css/CSSParser.cpp:
(WebCore::CSSParser::parseValue):
* css/CSSPrimitiveValue.h:
(WebCore::CSSPrimitiveValue::isPair):
* css/CSSPropertyNames.in:
* css/CSSValue.h:
* css/StyleBuilderConverter.h:
(WebCore::StyleBuilderConverter::convertLength):
(WebCore::StyleBuilderConverter::convertTo100PercentMinusLength):
(WebCore::StyleBuilderConverter::convertPositionComponent):
(WebCore::StyleBuilderConverter::convertObjectPosition):
* platform/LengthPoint.cpp: Added.
(WebCore::operator<<):
* platform/LengthPoint.h: Added.
(WebCore::LengthPoint::LengthPoint):
(WebCore::LengthPoint::operator==):
(WebCore::LengthPoint::setX):
(WebCore::LengthPoint::x):
(WebCore::LengthPoint::setY):
(WebCore::LengthPoint::y):
(WebCore::LengthPoint::blend):
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::changeRequiresRepaint):
* rendering/style/RenderStyle.h:
* rendering/style/StyleRareNonInheritedData.cpp:
(WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData):
(WebCore::StyleRareNonInheritedData::operator==):
* rendering/style/StyleRareNonInheritedData.h:

LayoutTests:

object-position parsing test.

* fast/css/object-position/parsing-object-position-expected.txt: Added.
* fast/css/object-position/parsing-object-position.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (197616 => 197617)


--- trunk/LayoutTests/ChangeLog	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/LayoutTests/ChangeLog	2016-03-05 23:23:40 UTC (rev 197617)
@@ -1,3 +1,15 @@
+2016-03-05  Simon Fraser  <[email protected]>
+
+        Add parsing support for object-position
+        https://bugs.webkit.org/show_bug.cgi?id=155065
+
+        Reviewed by Sam Weinig.
+        
+        object-position parsing test.
+
+        * fast/css/object-position/parsing-object-position-expected.txt: Added.
+        * fast/css/object-position/parsing-object-position.html: Added.
+
 2016-03-05  Joanmarie Diggs  <[email protected]>
 
         AX: Implement missing/different accessibility API mappings for SVG

Added: trunk/LayoutTests/fast/css/object-position/parsing-object-position-expected.txt (0 => 197617)


--- trunk/LayoutTests/fast/css/object-position/parsing-object-position-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/object-position/parsing-object-position-expected.txt	2016-03-05 23:23:40 UTC (rev 197617)
@@ -0,0 +1,28 @@
+This tests checks that all of the input values for object-position parse correctly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS testComputedStyle(";") is "50% 50%"
+PASS test("object-position: inherit;") is "inherit"
+PASS test("object-position: initial;") is "initial"
+PASS test("object-position: 23px;") is "23px 50%"
+PASS test("object-position: center 23px;") is "50% 23px"
+PASS test("object-position: 50% 23px;") is "50% 23px"
+PASS test("object-position: 50% left;") is ""
+PASS test("object-position: left 10px top 15px;") is "left 10px top 15px"
+PASS test("object-position: right 10px bottom 15px;") is "right 10px bottom 15px"
+PASS testComputedStyle("object-position: bottom 20%;") is "50% 50%"
+PASS testComputedStyle("object-position: right 20%;") is "100% 20%"
+PASS testComputedStyle("object-position: right") is "100% 50%"
+PASS testComputedStyle("object-position: center bottom 20%;") is "50% 80%"
+PASS testComputedStyle("object-position: right bottom") is "100% 100%"
+PASS testComputedStyle("object-position: left 10px top 15px;") is "10px 15px"
+PASS testComputedStyle("object-position: right 10px bottom 15px;") is "calc(100% - 10px) calc(100% - 15px)"
+PASS testComputedStyle("object-position: bottom 20% right -20px;") is "calc(100% - -20px) 80%"
+PASS testComputedStyle("object-position: calc(100% - 20px) calc(100% - 10%)") is "calc(100% - 20px) 90%"
+PASS testComputedStyle("object-position: right calc(100% - 20px) bottom calc(100% - 10%)") is "calc(100% - (100% - 20px)) 10%"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/object-position/parsing-object-position.html (0 => 197617)


--- trunk/LayoutTests/fast/css/object-position/parsing-object-position.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/object-position/parsing-object-position.html	2016-03-05 23:23:40 UTC (rev 197617)
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <script src=""
+    </head>
+    <body>
+        <script>
+            description("This tests checks that all of the input values for object-position parse correctly.");
+
+            function test(value)
+            {
+                var div = document.createElement("div");
+                div.setAttribute("style", value);
+                document.body.appendChild(div);
+
+                var result = div.style.getPropertyValue("object-position");
+                document.body.removeChild(div);
+                return result;
+            }
+
+            function testComputedStyle(value)
+            {
+                var div = document.createElement("div");
+                div.setAttribute("style", value);
+                document.body.appendChild(div);
+
+                var result = window.getComputedStyle(div).objectPosition;
+                document.body.removeChild(div);
+                return result;
+            }
+
+            shouldBe('testComputedStyle(";")', '"50% 50%"');
+            shouldBe('test("object-position: inherit;")', '"inherit"');
+            shouldBe('test("object-position: initial;")', '"initial"');
+            
+            shouldBeEqualToString('test("object-position: 23px;")', '23px 50%');
+            shouldBeEqualToString('test("object-position: center 23px;")', '50% 23px');
+            shouldBeEqualToString('test("object-position: 50% 23px;")', '50% 23px');
+            shouldBeEqualToString('test("object-position: 50% left;")', '');
+            
+            shouldBeEqualToString('test("object-position: left 10px top 15px;")', 'left 10px top 15px');
+            shouldBeEqualToString('test("object-position: right 10px bottom 15px;")', 'right 10px bottom 15px');
+
+            shouldBeEqualToString('testComputedStyle("object-position: bottom 20%;")', '50% 50%');
+            shouldBeEqualToString('testComputedStyle("object-position: right 20%;")', '100% 20%');
+            shouldBeEqualToString('testComputedStyle("object-position: right")', '100% 50%');
+            shouldBeEqualToString('testComputedStyle("object-position: center bottom 20%;")', '50% 80%');
+            shouldBeEqualToString('testComputedStyle("object-position: right bottom")', '100% 100%');
+
+            shouldBeEqualToString('testComputedStyle("object-position: left 10px top 15px;")', '10px 15px');
+            shouldBeEqualToString('testComputedStyle("object-position: right 10px bottom 15px;")', 'calc(100% - 10px) calc(100% - 15px)');
+            shouldBeEqualToString('testComputedStyle("object-position: bottom 20% right -20px;")', 'calc(100% - -20px) 80%');
+            shouldBeEqualToString('testComputedStyle("object-position: calc(100% - 20px) calc(100% - 10%)")', 'calc(100% - 20px) 90%');
+            shouldBeEqualToString('testComputedStyle("object-position: right calc(100% - 20px) bottom calc(100% - 10%)")', 'calc(100% - (100% - 20px)) 10%');
+            
+        </script>
+        <script src=""
+    </body>
+</html>

Modified: trunk/Source/WebCore/CMakeLists.txt (197616 => 197617)


--- trunk/Source/WebCore/CMakeLists.txt	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/Source/WebCore/CMakeLists.txt	2016-03-05 23:23:40 UTC (rev 197617)
@@ -2105,6 +2105,7 @@
     platform/FileSystem.cpp
     platform/Language.cpp
     platform/Length.cpp
+    platform/LengthPoint.cpp
     platform/LengthSize.cpp
     platform/LinkHash.cpp
     platform/Logging.cpp

Modified: trunk/Source/WebCore/ChangeLog (197616 => 197617)


--- trunk/Source/WebCore/ChangeLog	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/Source/WebCore/ChangeLog	2016-03-05 23:23:40 UTC (rev 197617)
@@ -1,3 +1,54 @@
+2016-03-05  Simon Fraser  <[email protected]>
+
+        Add parsing support for object-position
+        https://bugs.webkit.org/show_bug.cgi?id=155065
+
+        Reviewed by Sam Weinig.
+        
+        Add parsing support for object-position. This is the first property with
+        CSS <position> values which does not have equivalent -x and -y shorthands,
+        so we can store it as a new LengthPoint type.
+        
+        Per the CSS Values spec, bottom- and right-relative values are translated
+        into calc() expressions, which are exposed via computed style. For example,
+        "right 10px bottom" becomes "calc(100% - 10px) 100%". This also allows transitions
+        between, say, "left 10px bottom" and "right 10px bottom".
+
+        Test: fast/css/object-position/parsing-object-position.html
+
+        * CMakeLists.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::ComputedStyleExtractor::propertyValue):
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseValue):
+        * css/CSSPrimitiveValue.h:
+        (WebCore::CSSPrimitiveValue::isPair):
+        * css/CSSPropertyNames.in:
+        * css/CSSValue.h:
+        * css/StyleBuilderConverter.h:
+        (WebCore::StyleBuilderConverter::convertLength):
+        (WebCore::StyleBuilderConverter::convertTo100PercentMinusLength):
+        (WebCore::StyleBuilderConverter::convertPositionComponent):
+        (WebCore::StyleBuilderConverter::convertObjectPosition):
+        * platform/LengthPoint.cpp: Added.
+        (WebCore::operator<<):
+        * platform/LengthPoint.h: Added.
+        (WebCore::LengthPoint::LengthPoint):
+        (WebCore::LengthPoint::operator==):
+        (WebCore::LengthPoint::setX):
+        (WebCore::LengthPoint::x):
+        (WebCore::LengthPoint::setY):
+        (WebCore::LengthPoint::y):
+        (WebCore::LengthPoint::blend):
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::changeRequiresRepaint):
+        * rendering/style/RenderStyle.h:
+        * rendering/style/StyleRareNonInheritedData.cpp:
+        (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData):
+        (WebCore::StyleRareNonInheritedData::operator==):
+        * rendering/style/StyleRareNonInheritedData.h:
+
 2016-03-05  Joanmarie Diggs  <[email protected]>
 
         AX: Implement missing/different accessibility API mappings for SVG

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (197616 => 197617)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-03-05 23:23:40 UTC (rev 197617)
@@ -508,6 +508,8 @@
 		0F6A12BD1A00923700C6DE72 /* DebugPageOverlays.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F6A12BB1A00923700C6DE72 /* DebugPageOverlays.cpp */; };
 		0F6A12BE1A00923700C6DE72 /* DebugPageOverlays.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F6A12BC1A00923700C6DE72 /* DebugPageOverlays.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		0F7D07331884C56C00B4AF86 /* PlatformTextTrack.h in Headers */ = {isa = PBXBuildFile; fileRef = 072847E216EBC5B00043CFA4 /* PlatformTextTrack.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		0F87166F1C869D83004FF0DE /* LengthPoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F87166D1C869D83004FF0DE /* LengthPoint.cpp */; };
+		0F8716701C869D83004FF0DE /* LengthPoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F87166E1C869D83004FF0DE /* LengthPoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		0F97A658155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F97A657155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm */; };
 		0FA24D79162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FA24D77162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp */; };
 		0FA24D7A162DF91900A3F4C0 /* GraphicsLayerUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FA24D78162DF91900A3F4C0 /* GraphicsLayerUpdater.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -7901,6 +7903,8 @@
 		0F6383DC18615B29003E5DB5 /* ThreadedScrollingTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadedScrollingTree.h; sourceTree = "<group>"; };
 		0F6A12BB1A00923700C6DE72 /* DebugPageOverlays.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DebugPageOverlays.cpp; sourceTree = "<group>"; };
 		0F6A12BC1A00923700C6DE72 /* DebugPageOverlays.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugPageOverlays.h; sourceTree = "<group>"; };
+		0F87166D1C869D83004FF0DE /* LengthPoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LengthPoint.cpp; sourceTree = "<group>"; };
+		0F87166E1C869D83004FF0DE /* LengthPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LengthPoint.h; sourceTree = "<group>"; };
 		0F97A657155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DisplayRefreshMonitorIOS.mm; sourceTree = "<group>"; };
 		0FA24D77162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsLayerUpdater.cpp; sourceTree = "<group>"; };
 		0FA24D78162DF91900A3F4C0 /* GraphicsLayerUpdater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsLayerUpdater.h; sourceTree = "<group>"; };
@@ -22877,6 +22881,8 @@
 				BCE65BE80EACDF16007E4533 /* Length.cpp */,
 				BCE65BE90EACDF16007E4533 /* Length.h */,
 				BCFF648F0EAD15C200C1D6F7 /* LengthBox.h */,
+				0F87166D1C869D83004FF0DE /* LengthPoint.cpp */,
+				0F87166E1C869D83004FF0DE /* LengthPoint.h */,
 				0FEF20CD1BD4A24100128E5D /* LengthSize.cpp */,
 				BCFF64900EAD15C200C1D6F7 /* LengthSize.h */,
 				A7AD2F850EC89D07008AB002 /* LinkHash.cpp */,
@@ -27841,6 +27847,7 @@
 				31741AAD16636609008A5B7E /* SimulatedClickOptions.h in Headers */,
 				FD00D7A514A3F61900734011 /* SincResampler.h in Headers */,
 				51327D6011A33A2B004F9D65 /* SinkDocument.h in Headers */,
+				0F8716701C869D83004FF0DE /* LengthPoint.h in Headers */,
 				49E911CD0EF86D47009D0CAF /* SkewTransformOperation.h in Headers */,
 				4150F9F112B6E0E70008C860 /* SliderThumbElement.h in Headers */,
 				9B532EA41BA928570038A827 /* SlotAssignment.h in Headers */,
@@ -30450,6 +30457,7 @@
 				31078CC91880AAC9008099DC /* JSOESTextureHalfFloatLinear.cpp in Sources */,
 				77A17AA612F28B2A004E02F6 /* JSOESVertexArrayObject.cpp in Sources */,
 				FDF6BAF8134A4C9800822920 /* JSOfflineAudioCompletionEvent.cpp in Sources */,
+				0F87166F1C869D83004FF0DE /* LengthPoint.cpp in Sources */,
 				FDA9326616703BA9008982DC /* JSOfflineAudioContext.cpp in Sources */,
 				FDEA6242152102E200479DF0 /* JSOscillatorNode.cpp in Sources */,
 				FDBD1DFC167FE27D0051A11E /* JSOscillatorNodeCustom.cpp in Sources */,

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (197616 => 197617)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2016-03-05 23:23:40 UTC (rev 197617)
@@ -2970,6 +2970,12 @@
             return zoomAdjustedPixelValueForLength(style->minWidth(), *style);
         case CSSPropertyObjectFit:
             return cssValuePool.createValue(style->objectFit());
+        case CSSPropertyObjectPosition: {
+            RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
+            list->append(zoomAdjustedPixelValueForLength(style->objectPosition().x(), *style));
+            list->append(zoomAdjustedPixelValueForLength(style->objectPosition().y(), *style));
+            return list;
+        }
         case CSSPropertyOpacity:
             return cssValuePool.createValue(style->opacity(), CSSPrimitiveValue::CSS_NUMBER);
         case CSSPropertyOrphans:

Modified: trunk/Source/WebCore/css/CSSParser.cpp (197616 => 197617)


--- trunk/Source/WebCore/css/CSSParser.cpp	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2016-03-05 23:23:40 UTC (rev 197617)
@@ -2886,6 +2886,16 @@
     case CSSPropertyColumnWidth: // auto | <length>
         parsedValue = parseColumnWidth();
         break;
+    case CSSPropertyObjectPosition: {
+        RefPtr<CSSPrimitiveValue> val1;
+        RefPtr<CSSPrimitiveValue> val2;
+        parseFillPosition(*m_valueList, val1, val2);
+        if (val1) {
+            addProperty(CSSPropertyObjectPosition, createPrimitiveValuePair(val1.release(), val2.release()), important);
+            return true;
+        }
+        return false;
+        }
     // End of CSS3 properties
 
     case CSSPropertyWillChange: // auto | [scroll-position | contents | <custom-ident>]#

Modified: trunk/Source/WebCore/css/CSSPrimitiveValue.h (197616 => 197617)


--- trunk/Source/WebCore/css/CSSPrimitiveValue.h	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/Source/WebCore/css/CSSPrimitiveValue.h	2016-03-05 23:23:40 UTC (rev 197617)
@@ -210,6 +210,7 @@
 #if ENABLE(CSS_SCROLL_SNAP)
     bool isLengthRepeat() const { return m_primitiveUnitType == CSS_LENGTH_REPEAT; }
 #endif
+    bool isPair() const { return m_primitiveUnitType == CSS_PAIR; }
     bool isPropertyID() const { return m_primitiveUnitType == CSS_PROPERTY_ID; }
     bool isRGBColor() const { return m_primitiveUnitType == CSS_RGBCOLOR; }
     bool isShape() const { return m_primitiveUnitType == CSS_SHAPE; }

Modified: trunk/Source/WebCore/css/CSSPropertyNames.in (197616 => 197617)


--- trunk/Source/WebCore/css/CSSPropertyNames.in	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/Source/WebCore/css/CSSPropertyNames.in	2016-03-05 23:23:40 UTC (rev 197617)
@@ -274,6 +274,7 @@
 min-height [Initial=initialMinSize, Converter=LengthSizing]
 min-width [Initial=initialMinSize, Converter=LengthSizing]
 object-fit
+object-position [Converter=ObjectPosition]
 opacity
 // Honor -webkit-opacity as a synonym for opacity. This was the only syntax that worked in Safari 1.1,
 // and may be in use on some websites and widgets.

Modified: trunk/Source/WebCore/css/StyleBuilderConverter.h (197616 => 197617)


--- trunk/Source/WebCore/css/StyleBuilderConverter.h	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/Source/WebCore/css/StyleBuilderConverter.h	2016-03-05 23:23:40 UTC (rev 197617)
@@ -56,7 +56,7 @@
 // Note that we assume the CSS parser only allows valid CSSValue types.
 class StyleBuilderConverter {
 public:
-    static Length convertLength(StyleResolver&, CSSValue&);
+    static Length convertLength(StyleResolver&, const CSSValue&);
     static Length convertLengthOrAuto(StyleResolver&, CSSValue&);
     static Length convertLengthSizing(StyleResolver&, CSSValue&);
     static Length convertLengthMaxSizing(StyleResolver&, CSSValue&);
@@ -64,6 +64,7 @@
     template <typename T> static T convertLineWidth(StyleResolver&, CSSValue&);
     static float convertSpacing(StyleResolver&, CSSValue&);
     static LengthSize convertRadius(StyleResolver&, CSSValue&);
+    static LengthPoint convertObjectPosition(StyleResolver&, CSSValue&);
     static TextDecoration convertTextDecoration(StyleResolver&, CSSValue&);
     template <typename T> static T convertNumber(StyleResolver&, CSSValue&);
     template <typename T> static T convertNumberOrAuto(StyleResolver&, CSSValue&);
@@ -147,6 +148,10 @@
 #if ENABLE(CSS_SCROLL_SNAP)
     static Length parseSnapCoordinate(StyleResolver&, const CSSValue&);
 #endif
+
+    static Length convertTo100PercentMinusLength(const Length&);
+    static Length convertPositionComponent(StyleResolver&, const CSSPrimitiveValue&);
+
 #if ENABLE(CSS_GRID_LAYOUT)
     static GridLength createGridTrackBreadth(CSSPrimitiveValue&, StyleResolver&);
     static GridTrackSize createGridTrackSize(CSSValue&, StyleResolver&);
@@ -157,7 +162,7 @@
     static CSSToLengthConversionData csstoLengthConversionDataWithTextZoomFactor(StyleResolver&);
 };
 
-inline Length StyleBuilderConverter::convertLength(StyleResolver& styleResolver, CSSValue& value)
+inline Length StyleBuilderConverter::convertLength(StyleResolver& styleResolver, const CSSValue& value)
 {
     auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
     CSSToLengthConversionData conversionData = styleResolver.useSVGZoomRulesForLength() ?
@@ -297,6 +302,54 @@
     return LengthSize(radiusWidth, radiusHeight);
 }
 
+inline Length StyleBuilderConverter::convertTo100PercentMinusLength(const Length& length)
+{
+    if (length.isPercent())
+        return Length(100 - length.value(), Percent);
+    
+    // Turn this into a calc _expression_: calc(100% - length)
+    auto lhs = std::make_unique<CalcExpressionLength>(Length(100, Percent));
+    auto rhs = std::make_unique<CalcExpressionLength>(length);
+    auto op = std::make_unique<CalcExpressionBinaryOperation>(WTFMove(lhs), WTFMove(rhs), CalcSubtract);
+    return Length(CalculationValue::create(WTFMove(op), CalculationRangeAll));
+}
+
+inline Length StyleBuilderConverter::convertPositionComponent(StyleResolver& styleResolver, const CSSPrimitiveValue& value)
+{
+    Length length;
+
+    auto* lengthValue = &value;
+    bool relativeToTrailingEdge = false;
+    
+    if (value.isPair()) {
+        auto& first = *value.getPairValue()->first();
+        if (first.getValueID() == CSSValueRight || first.getValueID() == CSSValueBottom)
+            relativeToTrailingEdge = true;
+
+        lengthValue = value.getPairValue()->second();
+    }
+
+    length = convertLength(styleResolver, *lengthValue);
+
+    if (relativeToTrailingEdge)
+        length = convertTo100PercentMinusLength(length);
+
+    return length;
+}
+
+inline LengthPoint StyleBuilderConverter::convertObjectPosition(StyleResolver& styleResolver, CSSValue& value)
+{
+    auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
+    Pair* pair = primitiveValue.getPairValue();
+    if (!pair || !pair->first() || !pair->second())
+        return RenderStyle::initialObjectPosition();
+
+    Length lengthX = convertPositionComponent(styleResolver, *pair->first());
+    Length lengthY = convertPositionComponent(styleResolver, *pair->second());
+
+    return LengthPoint(lengthX, lengthY);
+}
+
 inline TextDecoration StyleBuilderConverter::convertTextDecoration(StyleResolver&, CSSValue& value)
 {
     TextDecoration result = RenderStyle::initialTextDecoration();

Added: trunk/Source/WebCore/platform/LengthPoint.cpp (0 => 197617)


--- trunk/Source/WebCore/platform/LengthPoint.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/LengthPoint.cpp	2016-03-05 23:23:40 UTC (rev 197617)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "LengthPoint.h"
+
+#include "TextStream.h"
+
+namespace WebCore {
+
+TextStream& operator<<(TextStream& ts, const LengthPoint& size)
+{
+    return ts << size.x() << " " << size.y();
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/platform/LengthPoint.h (0 => 197617)


--- trunk/Source/WebCore/platform/LengthPoint.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/LengthPoint.h	2016-03-05 23:23:40 UTC (rev 197617)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef LengthPoint_h
+#define LengthPoint_h
+
+#include "Length.h"
+
+namespace WebCore {
+
+struct LengthPoint {
+public:
+    LengthPoint()
+    {
+    }
+    
+    LengthPoint(Length x, Length y)
+        : m_x(WTFMove(x))
+        , m_y(WTFMove(y))
+    {
+    }
+
+    bool operator==(const LengthPoint& o) const
+    {
+        return m_x == o.m_x && m_y == o.m_y;
+    }
+
+    bool operator!=(const LengthPoint& o) const
+    {
+        return !(*this == o);
+    }
+
+    void setX(Length x) { m_x = WTFMove(x); }
+    const Length& x() const { return m_x; }
+
+    void setY(Length y) { m_y = WTFMove(y); }
+    const Length& y() const { return m_y; }
+
+    LengthPoint blend(const LengthPoint& from, double progress) const
+    {
+        return LengthPoint(m_x.blend(from.x(), progress), m_y.blend(from.y(), progress));
+    }
+
+private:
+    // FIXME: it would be nice to pack the two Lengths together better somehow (to avoid padding between them).
+    Length m_x;
+    Length m_y;
+};
+
+TextStream& operator<<(TextStream&, const LengthPoint&);
+
+} // namespace WebCore
+
+#endif // LengthPoint_h

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.cpp (197616 => 197617)


--- trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.cpp	2016-03-05 23:23:40 UTC (rev 197617)
@@ -809,6 +809,7 @@
         || rareNonInheritedData->userDrag != other.rareNonInheritedData->userDrag
         || rareNonInheritedData->m_borderFit != other.rareNonInheritedData->m_borderFit
         || rareNonInheritedData->m_objectFit != other.rareNonInheritedData->m_objectFit
+        || rareNonInheritedData->m_objectPosition != other.rareNonInheritedData->m_objectPosition
         || rareInheritedData->m_imageRendering != other.rareInheritedData->m_imageRendering)
         return true;
 

Modified: trunk/Source/WebCore/rendering/style/RenderStyle.h (197616 => 197617)


--- trunk/Source/WebCore/rendering/style/RenderStyle.h	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/Source/WebCore/rendering/style/RenderStyle.h	2016-03-05 23:23:40 UTC (rev 197617)
@@ -40,6 +40,7 @@
 #include "Length.h"
 #include "LengthBox.h"
 #include "LengthFunctions.h"
+#include "LengthPoint.h"
 #include "LengthSize.h"
 #include "LineClampValue.h"
 #include "NinePieceImage.h"
@@ -1031,8 +1032,9 @@
     TextOrientation textOrientation() const { return static_cast<TextOrientation>(rareInheritedData->m_textOrientation); }
 
     ObjectFit objectFit() const { return static_cast<ObjectFit>(rareNonInheritedData->m_objectFit); }
-    
-    // Return true if any transform related property (currently transform, transformStyle3D or perspective) 
+    LengthPoint objectPosition() const { return rareNonInheritedData->m_objectPosition; }
+
+    // Return true if any transform related property (currently transform, transformStyle3D or perspective)
     // indicates that we are transforming
     bool hasTransformRelatedProperty() const { return hasTransform() || preserves3D() || hasPerspective(); }
 
@@ -1601,6 +1603,7 @@
     bool setTextOrientation(TextOrientation);
 
     void setObjectFit(ObjectFit fit) { SET_VAR(rareNonInheritedData, m_objectFit, fit); }
+    void setObjectPosition(const LengthPoint& position) { SET_VAR(rareNonInheritedData, m_objectPosition, position); }
 
     void setRubyPosition(RubyPosition position) { SET_VAR(rareInheritedData, m_rubyPosition, position); }
 
@@ -1891,6 +1894,7 @@
     static TextOrientation initialTextOrientation() { return TextOrientation::
     Mixed; }
     static ObjectFit initialObjectFit() { return ObjectFitFill; }
+    static LengthPoint initialObjectPosition() { return LengthPoint(Length(50.0f, Percent), Length(50.0f, Percent)); }
     static EEmptyCell initialEmptyCells() { return SHOW; }
     static EListStylePosition initialListStylePosition() { return OUTSIDE; }
     static EListStyleType initialListStyleType() { return Disc; }

Modified: trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp (197616 => 197617)


--- trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp	2016-03-05 23:23:40 UTC (rev 197617)
@@ -63,6 +63,7 @@
 #endif
     , m_willChange(RenderStyle::initialWillChange())
     , m_mask(FillLayer(MaskFillLayer))
+    , m_objectPosition(RenderStyle::initialObjectPosition())
 #if ENABLE(CSS_SHAPES)
     , m_shapeOutside(RenderStyle::initialShapeOutside())
     , m_shapeMargin(RenderStyle::initialShapeMargin())
@@ -148,6 +149,7 @@
     , m_mask(o.m_mask)
     , m_maskBoxImage(o.m_maskBoxImage)
     , m_pageSize(o.m_pageSize)
+    , m_objectPosition(o.m_objectPosition)
 #if ENABLE(CSS_SHAPES)
     , m_shapeOutside(o.m_shapeOutside)
     , m_shapeMargin(o.m_shapeMargin)
@@ -250,6 +252,7 @@
         && m_mask == o.m_mask
         && m_maskBoxImage == o.m_maskBoxImage
         && m_pageSize == o.m_pageSize
+        && m_objectPosition == o.m_objectPosition
 #if ENABLE(CSS_SHAPES)
         && arePointingToEqualData(m_shapeOutside, o.m_shapeOutside)
         && m_shapeMargin == o.m_shapeMargin

Modified: trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.h (197616 => 197617)


--- trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.h	2016-03-05 21:35:57 UTC (rev 197616)
+++ trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.h	2016-03-05 23:23:40 UTC (rev 197617)
@@ -32,6 +32,7 @@
 #include "CursorData.h"
 #include "DataRef.h"
 #include "FillLayer.h"
+#include "LengthPoint.h"
 #include "LineClampValue.h"
 #include "NinePieceImage.h"
 #include "ShapeValue.h"
@@ -154,6 +155,7 @@
     NinePieceImage m_maskBoxImage;
 
     LengthSize m_pageSize;
+    LengthPoint m_objectPosition;
 
 #if ENABLE(CSS_SHAPES)
     RefPtr<ShapeValue> m_shapeOutside;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to