Changeset 197617 in webkit


Ignore:
Timestamp:
Mar 5, 2016, 3:23:40 PM (9 years ago)
Author:
Simon Fraser
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.
Location:
trunk
Files:
5 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r197616 r197617  
     12016-03-05  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Add parsing support for object-position
     4        https://bugs.webkit.org/show_bug.cgi?id=155065
     5
     6        Reviewed by Sam Weinig.
     7       
     8        object-position parsing test.
     9
     10        * fast/css/object-position/parsing-object-position-expected.txt: Added.
     11        * fast/css/object-position/parsing-object-position.html: Added.
     12
    1132016-03-05  Joanmarie Diggs  <jdiggs@igalia.com>
    214
  • trunk/Source/WebCore/CMakeLists.txt

    r197616 r197617  
    21062106    platform/Language.cpp
    21072107    platform/Length.cpp
     2108    platform/LengthPoint.cpp
    21082109    platform/LengthSize.cpp
    21092110    platform/LinkHash.cpp
  • trunk/Source/WebCore/ChangeLog

    r197616 r197617  
     12016-03-05  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Add parsing support for object-position
     4        https://bugs.webkit.org/show_bug.cgi?id=155065
     5
     6        Reviewed by Sam Weinig.
     7       
     8        Add parsing support for object-position. This is the first property with
     9        CSS <position> values which does not have equivalent -x and -y shorthands,
     10        so we can store it as a new LengthPoint type.
     11       
     12        Per the CSS Values spec, bottom- and right-relative values are translated
     13        into calc() expressions, which are exposed via computed style. For example,
     14        "right 10px bottom" becomes "calc(100% - 10px) 100%". This also allows transitions
     15        between, say, "left 10px bottom" and "right 10px bottom".
     16
     17        Test: fast/css/object-position/parsing-object-position.html
     18
     19        * CMakeLists.txt:
     20        * WebCore.xcodeproj/project.pbxproj:
     21        * css/CSSComputedStyleDeclaration.cpp:
     22        (WebCore::ComputedStyleExtractor::propertyValue):
     23        * css/CSSParser.cpp:
     24        (WebCore::CSSParser::parseValue):
     25        * css/CSSPrimitiveValue.h:
     26        (WebCore::CSSPrimitiveValue::isPair):
     27        * css/CSSPropertyNames.in:
     28        * css/CSSValue.h:
     29        * css/StyleBuilderConverter.h:
     30        (WebCore::StyleBuilderConverter::convertLength):
     31        (WebCore::StyleBuilderConverter::convertTo100PercentMinusLength):
     32        (WebCore::StyleBuilderConverter::convertPositionComponent):
     33        (WebCore::StyleBuilderConverter::convertObjectPosition):
     34        * platform/LengthPoint.cpp: Added.
     35        (WebCore::operator<<):
     36        * platform/LengthPoint.h: Added.
     37        (WebCore::LengthPoint::LengthPoint):
     38        (WebCore::LengthPoint::operator==):
     39        (WebCore::LengthPoint::setX):
     40        (WebCore::LengthPoint::x):
     41        (WebCore::LengthPoint::setY):
     42        (WebCore::LengthPoint::y):
     43        (WebCore::LengthPoint::blend):
     44        * rendering/style/RenderStyle.cpp:
     45        (WebCore::RenderStyle::changeRequiresRepaint):
     46        * rendering/style/RenderStyle.h:
     47        * rendering/style/StyleRareNonInheritedData.cpp:
     48        (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData):
     49        (WebCore::StyleRareNonInheritedData::operator==):
     50        * rendering/style/StyleRareNonInheritedData.h:
     51
    1522016-03-05  Joanmarie Diggs  <jdiggs@igalia.com>
    253
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r197616 r197617  
    509509                0F6A12BE1A00923700C6DE72 /* DebugPageOverlays.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F6A12BC1A00923700C6DE72 /* DebugPageOverlays.h */; settings = {ATTRIBUTES = (Private, ); }; };
    510510                0F7D07331884C56C00B4AF86 /* PlatformTextTrack.h in Headers */ = {isa = PBXBuildFile; fileRef = 072847E216EBC5B00043CFA4 /* PlatformTextTrack.h */; settings = {ATTRIBUTES = (Private, ); }; };
     511                0F87166F1C869D83004FF0DE /* LengthPoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F87166D1C869D83004FF0DE /* LengthPoint.cpp */; };
     512                0F8716701C869D83004FF0DE /* LengthPoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F87166E1C869D83004FF0DE /* LengthPoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
    511513                0F97A658155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F97A657155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm */; };
    512514                0FA24D79162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FA24D77162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp */; };
     
    79027904                0F6A12BB1A00923700C6DE72 /* DebugPageOverlays.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DebugPageOverlays.cpp; sourceTree = "<group>"; };
    79037905                0F6A12BC1A00923700C6DE72 /* DebugPageOverlays.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DebugPageOverlays.h; sourceTree = "<group>"; };
     7906                0F87166D1C869D83004FF0DE /* LengthPoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LengthPoint.cpp; sourceTree = "<group>"; };
     7907                0F87166E1C869D83004FF0DE /* LengthPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LengthPoint.h; sourceTree = "<group>"; };
    79047908                0F97A657155DA81E00FADD4C /* DisplayRefreshMonitorIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DisplayRefreshMonitorIOS.mm; sourceTree = "<group>"; };
    79057909                0FA24D77162DF91900A3F4C0 /* GraphicsLayerUpdater.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsLayerUpdater.cpp; sourceTree = "<group>"; };
     
    2287822882                                BCE65BE90EACDF16007E4533 /* Length.h */,
    2287922883                                BCFF648F0EAD15C200C1D6F7 /* LengthBox.h */,
     22884                                0F87166D1C869D83004FF0DE /* LengthPoint.cpp */,
     22885                                0F87166E1C869D83004FF0DE /* LengthPoint.h */,
    2288022886                                0FEF20CD1BD4A24100128E5D /* LengthSize.cpp */,
    2288122887                                BCFF64900EAD15C200C1D6F7 /* LengthSize.h */,
     
    2784227848                                FD00D7A514A3F61900734011 /* SincResampler.h in Headers */,
    2784327849                                51327D6011A33A2B004F9D65 /* SinkDocument.h in Headers */,
     27850                                0F8716701C869D83004FF0DE /* LengthPoint.h in Headers */,
    2784427851                                49E911CD0EF86D47009D0CAF /* SkewTransformOperation.h in Headers */,
    2784527852                                4150F9F112B6E0E70008C860 /* SliderThumbElement.h in Headers */,
     
    3045130458                                77A17AA612F28B2A004E02F6 /* JSOESVertexArrayObject.cpp in Sources */,
    3045230459                                FDF6BAF8134A4C9800822920 /* JSOfflineAudioCompletionEvent.cpp in Sources */,
     30460                                0F87166F1C869D83004FF0DE /* LengthPoint.cpp in Sources */,
    3045330461                                FDA9326616703BA9008982DC /* JSOfflineAudioContext.cpp in Sources */,
    3045430462                                FDEA6242152102E200479DF0 /* JSOscillatorNode.cpp in Sources */,
  • trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp

    r197503 r197617  
    29712971        case CSSPropertyObjectFit:
    29722972            return cssValuePool.createValue(style->objectFit());
     2973        case CSSPropertyObjectPosition: {
     2974            RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
     2975            list->append(zoomAdjustedPixelValueForLength(style->objectPosition().x(), *style));
     2976            list->append(zoomAdjustedPixelValueForLength(style->objectPosition().y(), *style));
     2977            return list;
     2978        }
    29732979        case CSSPropertyOpacity:
    29742980            return cssValuePool.createValue(style->opacity(), CSSPrimitiveValue::CSS_NUMBER);
  • trunk/Source/WebCore/css/CSSParser.cpp

    r197503 r197617  
    28872887        parsedValue = parseColumnWidth();
    28882888        break;
     2889    case CSSPropertyObjectPosition: {
     2890        RefPtr<CSSPrimitiveValue> val1;
     2891        RefPtr<CSSPrimitiveValue> val2;
     2892        parseFillPosition(*m_valueList, val1, val2);
     2893        if (val1) {
     2894            addProperty(CSSPropertyObjectPosition, createPrimitiveValuePair(val1.release(), val2.release()), important);
     2895            return true;
     2896        }
     2897        return false;
     2898        }
    28892899    // End of CSS3 properties
    28902900
  • trunk/Source/WebCore/css/CSSPrimitiveValue.h

    r196991 r197617  
    211211    bool isLengthRepeat() const { return m_primitiveUnitType == CSS_LENGTH_REPEAT; }
    212212#endif
     213    bool isPair() const { return m_primitiveUnitType == CSS_PAIR; }
    213214    bool isPropertyID() const { return m_primitiveUnitType == CSS_PROPERTY_ID; }
    214215    bool isRGBColor() const { return m_primitiveUnitType == CSS_RGBCOLOR; }
  • trunk/Source/WebCore/css/CSSPropertyNames.in

    r197511 r197617  
    275275min-width [Initial=initialMinSize, Converter=LengthSizing]
    276276object-fit
     277object-position [Converter=ObjectPosition]
    277278opacity
    278279// Honor -webkit-opacity as a synonym for opacity. This was the only syntax that worked in Safari 1.1,
  • trunk/Source/WebCore/css/StyleBuilderConverter.h

    r197400 r197617  
    5757class StyleBuilderConverter {
    5858public:
    59     static Length convertLength(StyleResolver&, CSSValue&);
     59    static Length convertLength(StyleResolver&, const CSSValue&);
    6060    static Length convertLengthOrAuto(StyleResolver&, CSSValue&);
    6161    static Length convertLengthSizing(StyleResolver&, CSSValue&);
     
    6565    static float convertSpacing(StyleResolver&, CSSValue&);
    6666    static LengthSize convertRadius(StyleResolver&, CSSValue&);
     67    static LengthPoint convertObjectPosition(StyleResolver&, CSSValue&);
    6768    static TextDecoration convertTextDecoration(StyleResolver&, CSSValue&);
    6869    template <typename T> static T convertNumber(StyleResolver&, CSSValue&);
     
    148149    static Length parseSnapCoordinate(StyleResolver&, const CSSValue&);
    149150#endif
     151
     152    static Length convertTo100PercentMinusLength(const Length&);
     153    static Length convertPositionComponent(StyleResolver&, const CSSPrimitiveValue&);
     154
    150155#if ENABLE(CSS_GRID_LAYOUT)
    151156    static GridLength createGridTrackBreadth(CSSPrimitiveValue&, StyleResolver&);
     
    158163};
    159164
    160 inline Length StyleBuilderConverter::convertLength(StyleResolver& styleResolver, CSSValue& value)
     165inline Length StyleBuilderConverter::convertLength(StyleResolver& styleResolver, const CSSValue& value)
    161166{
    162167    auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
     
    296301
    297302    return LengthSize(radiusWidth, radiusHeight);
     303}
     304
     305inline Length StyleBuilderConverter::convertTo100PercentMinusLength(const Length& length)
     306{
     307    if (length.isPercent())
     308        return Length(100 - length.value(), Percent);
     309   
     310    // Turn this into a calc expression: calc(100% - length)
     311    auto lhs = std::make_unique<CalcExpressionLength>(Length(100, Percent));
     312    auto rhs = std::make_unique<CalcExpressionLength>(length);
     313    auto op = std::make_unique<CalcExpressionBinaryOperation>(WTFMove(lhs), WTFMove(rhs), CalcSubtract);
     314    return Length(CalculationValue::create(WTFMove(op), CalculationRangeAll));
     315}
     316
     317inline Length StyleBuilderConverter::convertPositionComponent(StyleResolver& styleResolver, const CSSPrimitiveValue& value)
     318{
     319    Length length;
     320
     321    auto* lengthValue = &value;
     322    bool relativeToTrailingEdge = false;
     323   
     324    if (value.isPair()) {
     325        auto& first = *value.getPairValue()->first();
     326        if (first.getValueID() == CSSValueRight || first.getValueID() == CSSValueBottom)
     327            relativeToTrailingEdge = true;
     328
     329        lengthValue = value.getPairValue()->second();
     330    }
     331
     332    length = convertLength(styleResolver, *lengthValue);
     333
     334    if (relativeToTrailingEdge)
     335        length = convertTo100PercentMinusLength(length);
     336
     337    return length;
     338}
     339
     340inline LengthPoint StyleBuilderConverter::convertObjectPosition(StyleResolver& styleResolver, CSSValue& value)
     341{
     342    auto& primitiveValue = downcast<CSSPrimitiveValue>(value);
     343    Pair* pair = primitiveValue.getPairValue();
     344    if (!pair || !pair->first() || !pair->second())
     345        return RenderStyle::initialObjectPosition();
     346
     347    Length lengthX = convertPositionComponent(styleResolver, *pair->first());
     348    Length lengthY = convertPositionComponent(styleResolver, *pair->second());
     349
     350    return LengthPoint(lengthX, lengthY);
    298351}
    299352
  • trunk/Source/WebCore/rendering/style/RenderStyle.cpp

    r197503 r197617  
    810810        || rareNonInheritedData->m_borderFit != other.rareNonInheritedData->m_borderFit
    811811        || rareNonInheritedData->m_objectFit != other.rareNonInheritedData->m_objectFit
     812        || rareNonInheritedData->m_objectPosition != other.rareNonInheritedData->m_objectPosition
    812813        || rareInheritedData->m_imageRendering != other.rareInheritedData->m_imageRendering)
    813814        return true;
  • trunk/Source/WebCore/rendering/style/RenderStyle.h

    r197503 r197617  
    4141#include "LengthBox.h"
    4242#include "LengthFunctions.h"
     43#include "LengthPoint.h"
    4344#include "LengthSize.h"
    4445#include "LineClampValue.h"
     
    10321033
    10331034    ObjectFit objectFit() const { return static_cast<ObjectFit>(rareNonInheritedData->m_objectFit); }
    1034    
    1035     // Return true if any transform related property (currently transform, transformStyle3D or perspective)
     1035    LengthPoint objectPosition() const { return rareNonInheritedData->m_objectPosition; }
     1036
     1037    // Return true if any transform related property (currently transform, transformStyle3D or perspective)
    10361038    // indicates that we are transforming
    10371039    bool hasTransformRelatedProperty() const { return hasTransform() || preserves3D() || hasPerspective(); }
     
    16021604
    16031605    void setObjectFit(ObjectFit fit) { SET_VAR(rareNonInheritedData, m_objectFit, fit); }
     1606    void setObjectPosition(const LengthPoint& position) { SET_VAR(rareNonInheritedData, m_objectPosition, position); }
    16041607
    16051608    void setRubyPosition(RubyPosition position) { SET_VAR(rareInheritedData, m_rubyPosition, position); }
     
    18921895    Mixed; }
    18931896    static ObjectFit initialObjectFit() { return ObjectFitFill; }
     1897    static LengthPoint initialObjectPosition() { return LengthPoint(Length(50.0f, Percent), Length(50.0f, Percent)); }
    18941898    static EEmptyCell initialEmptyCells() { return SHOW; }
    18951899    static EListStylePosition initialListStylePosition() { return OUTSIDE; }
  • trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.cpp

    r195892 r197617  
    6464    , m_willChange(RenderStyle::initialWillChange())
    6565    , m_mask(FillLayer(MaskFillLayer))
     66    , m_objectPosition(RenderStyle::initialObjectPosition())
    6667#if ENABLE(CSS_SHAPES)
    6768    , m_shapeOutside(RenderStyle::initialShapeOutside())
     
    149150    , m_maskBoxImage(o.m_maskBoxImage)
    150151    , m_pageSize(o.m_pageSize)
     152    , m_objectPosition(o.m_objectPosition)
    151153#if ENABLE(CSS_SHAPES)
    152154    , m_shapeOutside(o.m_shapeOutside)
     
    251253        && m_maskBoxImage == o.m_maskBoxImage
    252254        && m_pageSize == o.m_pageSize
     255        && m_objectPosition == o.m_objectPosition
    253256#if ENABLE(CSS_SHAPES)
    254257        && arePointingToEqualData(m_shapeOutside, o.m_shapeOutside)
  • trunk/Source/WebCore/rendering/style/StyleRareNonInheritedData.h

    r195892 r197617  
    3333#include "DataRef.h"
    3434#include "FillLayer.h"
     35#include "LengthPoint.h"
    3536#include "LineClampValue.h"
    3637#include "NinePieceImage.h"
     
    155156
    156157    LengthSize m_pageSize;
     158    LengthPoint m_objectPosition;
    157159
    158160#if ENABLE(CSS_SHAPES)
Note: See TracChangeset for help on using the changeset viewer.