Changeset 76568 in webkit


Ignore:
Timestamp:
Jan 24, 2011 9:15:56 PM (13 years ago)
Author:
Simon Fraser
Message:

2011-01-24 Simon Fraser <Simon Fraser>

Reviewed by Chris Marrin.

perspective() transform function should take lengths
https://bugs.webkit.org/show_bug.cgi?id=52683

The argument to the perspective() transform function should
be a Length, rather than a bare number. Bare numbers are still
accepted (and treated as px), but this behavior is deprecated.

Test: animations/3d/transform-perspective.html

transforms/3d/general/3dtransform-values.html

  • css/CSSParser.cpp: (WebCore::CSSParser::parseTransform): Check the units for the perspective() function. Allow bare numbers for backwards compatibility.
  • css/CSSStyleSelector.cpp: (WebCore::CSSStyleSelector::createTransformOperations): Convert value to Length.
  • platform/graphics/transforms/PerspectiveTransformOperation.cpp: (WebCore::clampToPostiveInteger): Helper. (WebCore::PerspectiveTransformOperation::blend): Blend via Lengths.
  • platform/graphics/transforms/PerspectiveTransformOperation.h: (WebCore::PerspectiveTransformOperation::create): double -> Length. (WebCore::PerspectiveTransformOperation::perspective): Ditto. (WebCore::PerspectiveTransformOperation::isIdentity): Ditto. (WebCore::PerspectiveTransformOperation::apply): Ditto. (WebCore::PerspectiveTransformOperation::PerspectiveTransformOperation): Assert that the Length is a fixed type.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r76567 r76568  
     12011-01-24  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Reviewed by Chris Marrin.
     4
     5        perspective() transform function should take lengths
     6        https://bugs.webkit.org/show_bug.cgi?id=52683
     7       
     8        Add tests for perspective() handling, and interpolation for animation.
     9
     10        * animations/3d/transform-perspective-expected.txt: Added.
     11        * animations/3d/transform-perspective.html: Added.
     12        * transforms/3d/general/3dtransform-values-expected.txt:
     13        * transforms/3d/general/3dtransform-values.html:
     14
    1152011-01-24  Kent Tamura  <tkent@chromium.org>
    216
  • trunk/LayoutTests/transforms/3d/general/3dtransform-values-expected.txt

    r74156 r76568  
    1010transform "rotate3d(0, 1, 0, 180px)" expected "none" : PASS
    1111transform "rotate3d(0, 1, 0, 180px)" expected "none" : PASS
     12transform "perspective(400)" expected "matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -0.0025, 0, 0, 0, 1)" : PASS
     13transform "perspective(400px)" expected "matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -0.0025, 0, 0, 0, 1)" : PASS
     14transform "perspective(400em)" expected "matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -0.00015625, 0, 0, 0, 1)" : PASS
     15transform "perspective(50%)" expected "none" : PASS
     16transform "perspective(-400)" expected "none" : PASS
     17transform "perspective(0)" expected "matrix(1, 0, 0, 1, 0, 0)" : PASS
     18transform "perspective(400deg)" expected "none" : PASS
     19transform "perspective(banana)" expected "none" : PASS
    1220
  • trunk/LayoutTests/transforms/3d/general/3dtransform-values.html

    r74156 r76568  
    3838      { 'transform' : 'rotate3d(0, 1, 0, 180px)', 'result' : 'none' }, // last value must be an angle
    3939      { 'transform' : 'rotate3d(0, 1, 0, 180px)', 'result' : 'none' }, // last value must be an angle
     40      { 'transform' : 'perspective(400)', 'result' : 'matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -0.0025, 0, 0, 0, 1)' }, // legacy
     41      { 'transform' : 'perspective(400px)', 'result' : 'matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -0.0025, 0, 0, 0, 1)' },
     42      { 'transform' : 'perspective(400em)', 'result' : 'matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -0.00015625, 0, 0, 0, 1)' },
     43      { 'transform' : 'perspective(50%)', 'result' : 'none' },
     44      { 'transform' : 'perspective(-400)', 'result' : 'none' },
     45      { 'transform' : 'perspective(0)', 'result' : 'matrix(1, 0, 0, 1, 0, 0)' },
     46      { 'transform' : 'perspective(400deg)', 'result' : 'none' }, // unit must be length
     47      { 'transform' : 'perspective(banana)', 'result' : 'none' }, // unit must be length
    4048    ];
    4149   
  • trunk/Source/WebCore/ChangeLog

    r76567 r76568  
     12011-01-24  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Reviewed by Chris Marrin.
     4
     5        perspective() transform function should take lengths
     6        https://bugs.webkit.org/show_bug.cgi?id=52683
     7       
     8        The argument to the perspective() transform function should
     9        be a Length, rather than a bare number. Bare numbers are still
     10        accepted (and treated as px), but this behavior is deprecated.
     11
     12        Test: animations/3d/transform-perspective.html
     13              transforms/3d/general/3dtransform-values.html
     14
     15        * css/CSSParser.cpp:
     16        (WebCore::CSSParser::parseTransform): Check the units for the perspective()
     17        function. Allow bare numbers for backwards compatibility.
     18        * css/CSSStyleSelector.cpp:
     19        (WebCore::CSSStyleSelector::createTransformOperations): Convert
     20        value to Length.
     21        * platform/graphics/transforms/PerspectiveTransformOperation.cpp:
     22        (WebCore::clampToPostiveInteger): Helper.
     23        (WebCore::PerspectiveTransformOperation::blend): Blend via Lengths.
     24        * platform/graphics/transforms/PerspectiveTransformOperation.h:
     25        (WebCore::PerspectiveTransformOperation::create): double -> Length.
     26        (WebCore::PerspectiveTransformOperation::perspective): Ditto.
     27        (WebCore::PerspectiveTransformOperation::isIdentity): Ditto.
     28        (WebCore::PerspectiveTransformOperation::apply): Ditto.
     29        (WebCore::PerspectiveTransformOperation::PerspectiveTransformOperation): Assert
     30        that the Length is a fixed type.
     31
    1322011-01-24  Kent Tamura  <tkent@chromium.org>
    233
  • trunk/Source/WebCore/css/CSSParser.cpp

    r76047 r76568  
    53175317                if (!validUnit(a, FLength, true))
    53185318                    return 0;
     5319            } else if (info.type() == WebKitCSSTransformValue::PerspectiveTransformOperation && argNumber == 0) {
     5320                // 1st param of perspective() must be a non-negative number (deprecated) or length.
     5321                if (!validUnit(a, FNumber | FLength | FNonNeg, true))
     5322                    return 0;
    53195323            } else if (!validUnit(a, unit, true))
    53205324                return 0;
  • trunk/Source/WebCore/css/CSSStyleSelector.cpp

    r76378 r76568  
    70537053            }   
    70547054            case WebKitCSSTransformValue::PerspectiveTransformOperation: {
    7055                 double p = firstValue->getDoubleValue();
    7056                 if (p < 0.0)
     7055                bool ok = true;
     7056                Length p = Length(0, Fixed);
     7057                if (CSSPrimitiveValue::isUnitTypeLength(firstValue->primitiveType()))
     7058                    p = convertToLength(firstValue, style, rootStyle, zoomFactor, &ok);
     7059                else {
     7060                    // This is a quirk that should go away when 3d transforms are finalized.
     7061                    double val = firstValue->getDoubleValue();
     7062                    ok = val >= 0;
     7063                    val = min<double>(val, numeric_limits<int>::max());
     7064                    p = Length(static_cast<int>(val), Fixed);
     7065                }
     7066               
     7067                if (!ok)
    70577068                    return false;
     7069
    70587070                operations.operations().append(PerspectiveTransformOperation::create(p));
    70597071                break;
  • trunk/Source/WebCore/platform/graphics/transforms/PerspectiveTransformOperation.cpp

    r41983 r76568  
    2828
    2929#include <algorithm>
     30#include <limits>
    3031
    3132using namespace std;
    3233
    3334namespace WebCore {
     35
     36static int clampToPostiveInteger(double val)
     37{
     38    return static_cast<int>(max<double>(min<double>(val, numeric_limits<int>::max()), 0));
     39}
    3440
    3541PassRefPtr<TransformOperation> PerspectiveTransformOperation::blend(const TransformOperation* from, double progress, bool blendToIdentity)
     
    3844        return this;
    3945   
    40     if (blendToIdentity)
    41         return PerspectiveTransformOperation::create(m_p + (1. - m_p) * progress);
     46    if (blendToIdentity) {
     47        double p = m_p.calcFloatValue(1);
     48        p = p + (1. - p) * progress; // FIXME: this seems wrong. https://bugs.webkit.org/show_bug.cgi?id=52700
     49        return PerspectiveTransformOperation::create(Length(clampToPostiveInteger(p), Fixed));
     50    }
    4251   
    4352    const PerspectiveTransformOperation* fromOp = static_cast<const PerspectiveTransformOperation*>(from);
    44     double fromP = fromOp ? fromOp->m_p : 0;
    45     double toP = m_p;
     53    Length fromP = fromOp ? fromOp->m_p : Length(m_p.type());
     54    Length toP = m_p;
    4655
    4756    TransformationMatrix fromT;
    4857    TransformationMatrix toT;
    49     fromT.applyPerspective(fromP);
    50     toT.applyPerspective(toP);
     58    fromT.applyPerspective(fromP.calcFloatValue(1));
     59    toT.applyPerspective(toP.calcFloatValue(1));
    5160    toT.blend(fromT, progress);
    5261    TransformationMatrix::DecomposedType decomp;
    5362    toT.decompose(decomp);
    54    
    55     return PerspectiveTransformOperation::create(decomp.perspectiveZ ? -1.0 / decomp.perspectiveZ : 0.0);
     63
     64    if (decomp.perspectiveZ) {
     65        double val = -1.0 / decomp.perspectiveZ;
     66        return PerspectiveTransformOperation::create(Length(clampToPostiveInteger(val), Fixed));
     67    }
     68    return PerspectiveTransformOperation::create(Length(0, Fixed));
    5669}
    5770
  • trunk/Source/WebCore/platform/graphics/transforms/PerspectiveTransformOperation.h

    r69884 r76568  
    2727#define PerspectiveTransformOperation_h
    2828
     29#include "Length.h"
    2930#include "TransformOperation.h"
    3031
     
    3334class PerspectiveTransformOperation : public TransformOperation {
    3435public:
    35     static PassRefPtr<PerspectiveTransformOperation> create(double p)
     36    static PassRefPtr<PerspectiveTransformOperation> create(const Length& p)
    3637    {
    3738        return adoptRef(new PerspectiveTransformOperation(p));
    3839    }
    3940
    40     double perspective() const { return m_p; }
     41    Length perspective() const { return m_p; }
    4142   
    4243private:
    43     virtual bool isIdentity() const { return m_p == 0; }
     44    virtual bool isIdentity() const { return m_p.calcFloatValue(1) == 0; }
    4445    virtual OperationType getOperationType() const { return PERSPECTIVE; }
    4546    virtual bool isSameType(const TransformOperation& o) const { return o.getOperationType() == PERSPECTIVE; }
     
    5556    virtual bool apply(TransformationMatrix& transform, const IntSize&) const
    5657    {
    57         transform.applyPerspective(m_p);
     58        transform.applyPerspective(m_p.calcFloatValue(1));
    5859        return false;
    5960    }
     
    6162    virtual PassRefPtr<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false);
    6263
    63     PerspectiveTransformOperation(double p)
     64    PerspectiveTransformOperation(const Length& p)
    6465        : m_p(p)
    6566    {
     67        ASSERT(p.isFixed());
    6668    }
    6769
    68     double m_p;
     70    Length m_p;
    6971};
    7072
Note: See TracChangeset for help on using the changeset viewer.