Changeset 274415 in webkit


Ignore:
Timestamp:
Mar 15, 2021 6:00:06 AM (16 months ago)
Author:
commit-queue@webkit.org
Message:

CSS aspect-ratio interpolation
https://bugs.webkit.org/show_bug.cgi?id=220848

Patch by Rob Buis <rbuis@igalia.com> on 2021-03-15
Reviewed by Antoine Quint.

LayoutTests/imported/w3c:

Import relevant test.

  • web-platform-tests/css/css-sizing/animation/aspect-ratio-interpolation-expected.txt: Added.
  • web-platform-tests/css/css-sizing/animation/aspect-ratio-interpolation.html: Added.

Source/WebCore:

Implement CSS aspect-ratio interpolation as defined here:
https://drafts.csswg.org/css-values/#combine-ratio

Test: imported/w3c/web-platform-tests/css/css-sizing/animation/aspect-ratio-interpolation.html

  • animation/CSSPropertyAnimation.cpp:

(WebCore::CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap):

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r274411 r274415  
     12021-03-15  Rob Buis  <rbuis@igalia.com>
     2
     3        CSS aspect-ratio interpolation
     4        https://bugs.webkit.org/show_bug.cgi?id=220848
     5
     6        Reviewed by Antoine Quint.
     7
     8        Import relevant test.
     9
     10        * web-platform-tests/css/css-sizing/animation/aspect-ratio-interpolation-expected.txt: Added.
     11        * web-platform-tests/css/css-sizing/animation/aspect-ratio-interpolation.html: Added.
     12
    1132021-03-10  Sergio Villar Senin  <svillar@igalia.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r274414 r274415  
     12021-03-15  Rob Buis  <rbuis@igalia.com>
     2
     3        CSS aspect-ratio interpolation
     4        https://bugs.webkit.org/show_bug.cgi?id=220848
     5
     6        Reviewed by Antoine Quint.
     7
     8        Implement CSS aspect-ratio interpolation as defined here:
     9        https://drafts.csswg.org/css-values/#combine-ratio
     10
     11        Test: imported/w3c/web-platform-tests/css/css-sizing/animation/aspect-ratio-interpolation.html
     12
     13        * animation/CSSPropertyAnimation.cpp:
     14        (WebCore::CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap):
     15
    1162021-03-15  Kimmo Kinnunen  <kkinnunen@apple.com>
    217
  • trunk/Source/WebCore/animation/CSSPropertyAnimation.cpp

    r274409 r274415  
    18531853        else
    18541854            NonNegativeFloatPropertyWrapper::blend(client, destination, from, to, progress);
     1855    }
     1856};
     1857
     1858class PropertyWrapperAspectRatio final : public AnimationPropertyWrapperBase {
     1859    WTF_MAKE_FAST_ALLOCATED;
     1860public:
     1861    PropertyWrapperAspectRatio()
     1862        : AnimationPropertyWrapperBase(CSSPropertyAspectRatio)
     1863    {
     1864    }
     1865
     1866    bool equals(const RenderStyle* a, const RenderStyle* b) const final
     1867    {
     1868        if (a == b)
     1869            return true;
     1870        if (!a || !b)
     1871            return false;
     1872
     1873        return a->aspectRatioType() == b->aspectRatioType() && a->aspectRatioWidth() == b->aspectRatioWidth() && a->aspectRatioHeight() == b->aspectRatioHeight();
     1874    }
     1875
     1876    bool canInterpolate(const RenderStyle* from, const RenderStyle* to) const final
     1877    {
     1878        return (from->aspectRatioType() == AspectRatioType::Ratio && to->aspectRatioType() == AspectRatioType::Ratio) || (from->aspectRatioType() == AspectRatioType::AutoAndRatio && to->aspectRatioType() == AspectRatioType::AutoAndRatio);
     1879    }
     1880
     1881#if !LOG_DISABLED
     1882    void logBlend(const RenderStyle* from, const RenderStyle* to, const RenderStyle* result, double progress) const final
     1883    {
     1884        LOG_WITH_STREAM(Animations, stream << "  blending " << getPropertyName(property()) << " from " << from->logicalAspectRatio() << " to " << to->logicalAspectRatio() << " at " << TextStream::FormatNumberRespectingIntegers(progress) << " -> " << result->logicalAspectRatio());
     1885    }
     1886#endif
     1887
     1888    void blend(const CSSPropertyBlendingClient*, RenderStyle* destination, const RenderStyle* from, const RenderStyle* to, double progress) const final
     1889    {
     1890        destination->setAspectRatioType(progress < 0.5 ? from->aspectRatioType() : to->aspectRatioType());
     1891        if (canInterpolate(from, to)) {
     1892            auto aspectRatioDst = WebCore::blend(log(from->logicalAspectRatio()), log(to->logicalAspectRatio()), progress);
     1893            destination->setAspectRatio(exp(aspectRatioDst), 1);
     1894            return;
     1895        }
     1896        // For auto/auto-zero aspect-ratio we use discrete values, we can't use general
     1897        // logic since logicalAspectRatio asserts on aspect-ratio type.
     1898        ASSERT(!progress || progress == 1);
     1899        auto* applicableStyle = progress ? to : from;
     1900        destination->setAspectRatio(applicableStyle->aspectRatioWidth(), applicableStyle->aspectRatioHeight());
    18551901    }
    18561902};
     
    21542200        new DiscretePropertyWrapper<BlendMode>(CSSPropertyMixBlendMode, &RenderStyle::blendMode, &RenderStyle::setBlendMode),
    21552201#endif
     2202        new PropertyWrapperAspectRatio,
    21562203    };
    21572204    const unsigned animatableLonghandPropertiesCount = WTF_ARRAY_LENGTH(animatableLonghandPropertyWrappers);
Note: See TracChangeset for help on using the changeset viewer.