Changeset 219619 in webkit


Ignore:
Timestamp:
Jul 18, 2017 11:54:32 AM (7 years ago)
Author:
Devin Rousso
Message:

Add CanvasRenderingContext2D::getTransform
https://bugs.webkit.org/show_bug.cgi?id=174278

Reviewed by Dean Jackson.

Source/WebCore:

Tests: fast/canvas/2d.getTransform.modification.html

fast/canvas/2d.getTransform.newobject.html
fast/canvas/2d.setTransform.matrix.html

  • css/DOMMatrixReadOnly.h:

Make DOMMatrixReadOnly::validateAndFixup public so that values of DOMMatrixInit are still
usable without having to construct a DOMMatrixReadOnly. This is beneficial in the case that
an exception is thrown, as the validateAndFixup check can happen without any allocations.

  • html/canvas/CanvasRenderingContext2D.idl:
  • html/canvas/CanvasRenderingContext2D.h:
  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::CanvasRenderingContext2D::getTransform):
(WebCore::CanvasRenderingContext2D::setTransform):

LayoutTests:

  • canvas/philip/tests/2d.missingargs.html:

CanvasRenderingContext2D.prototype.setTransform no longer throws an error with no arguments.

  • fast/canvas/2d.getTransform.modification-expected.txt: Added.
  • fast/canvas/2d.getTransform.modification.html: Added.
  • fast/canvas/2d.getTransform.newobject-expected.txt: Added.
  • fast/canvas/2d.getTransform.newobject.html: Added.
  • fast/canvas/2d.setTransform.matrix-expected.txt: Added.
  • fast/canvas/2d.setTransform.matrix.html: Added.
Location:
trunk
Files:
6 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r219612 r219619  
     12017-07-18  Devin Rousso  <drousso@apple.com>
     2
     3        Add CanvasRenderingContext2D::getTransform
     4        https://bugs.webkit.org/show_bug.cgi?id=174278
     5
     6        Reviewed by Dean Jackson.
     7
     8        * canvas/philip/tests/2d.missingargs.html:
     9        CanvasRenderingContext2D.prototype.setTransform no longer throws an error with no arguments.
     10
     11        * fast/canvas/2d.getTransform.modification-expected.txt: Added.
     12        * fast/canvas/2d.getTransform.modification.html: Added.
     13        * fast/canvas/2d.getTransform.newobject-expected.txt: Added.
     14        * fast/canvas/2d.getTransform.newobject.html: Added.
     15        * fast/canvas/2d.setTransform.matrix-expected.txt: Added.
     16        * fast/canvas/2d.setTransform.matrix.html: Added.
     17
    1182017-07-18  Matt Lewis  <jlewis3@apple.com>
    219
  • trunk/LayoutTests/canvas/philip/tests/2d.missingargs.html

    r203333 r219619  
    5050if (ctx.setTransform) {
    5151    try { var _thrown = false;
    52   ctx.setTransform();
    53 } catch (e) { if (!(e instanceof TypeError)) _fail("Failed assertion: expected exception of type TypeError, got: "+e); _thrown = true; } finally { _assert(_thrown, "should throw exception of type TypeError: ctx.setTransform()"); }
    54     try { var _thrown = false;
    5552  ctx.setTransform(1);
    5653} catch (e) { if (!(e instanceof TypeError)) _fail("Failed assertion: expected exception of type TypeError, got: "+e); _thrown = true; } finally { _assert(_thrown, "should throw exception of type TypeError: ctx.setTransform(1)"); }
  • trunk/Source/WebCore/ChangeLog

    r219618 r219619  
     12017-07-18  Devin Rousso  <drousso@apple.com>
     2
     3        Add CanvasRenderingContext2D::getTransform
     4        https://bugs.webkit.org/show_bug.cgi?id=174278
     5
     6        Reviewed by Dean Jackson.
     7
     8        Tests: fast/canvas/2d.getTransform.modification.html
     9               fast/canvas/2d.getTransform.newobject.html
     10               fast/canvas/2d.setTransform.matrix.html
     11
     12        * css/DOMMatrixReadOnly.h:
     13        Make DOMMatrixReadOnly::validateAndFixup public so that values of DOMMatrixInit are still
     14        usable without having to construct a DOMMatrixReadOnly. This is beneficial in the case that
     15        an exception is thrown, as the validateAndFixup check can happen without any allocations.
     16
     17        * html/canvas/CanvasRenderingContext2D.idl:
     18        * html/canvas/CanvasRenderingContext2D.h:
     19        * html/canvas/CanvasRenderingContext2D.cpp:
     20        (WebCore::CanvasRenderingContext2D::getTransform):
     21        (WebCore::CanvasRenderingContext2D::setTransform):
     22
    1232017-07-18  Andy Estes  <aestes@apple.com>
    224
  • trunk/Source/WebCore/css/DOMMatrixReadOnly.h

    r218644 r219619  
    7676    static ExceptionOr<Ref<DOMMatrixReadOnly>> fromFloat64Array(Ref<Float64Array>&&);
    7777
     78    static ExceptionOr<void> validateAndFixup(DOMMatrixInit&);
     79
    7880    double a() const { return m_matrix.a(); }
    7981    double b() const { return m_matrix.b(); }
     
    138140    static ExceptionOr<Ref<T>> fromMatrixHelper(DOMMatrixInit&&);
    139141
    140     static ExceptionOr<void> validateAndFixup(DOMMatrixInit&);
    141 
    142142    TransformationMatrix m_matrix;
    143143    bool m_is2D { true };
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r216902 r219619  
    4141#include "CanvasGradient.h"
    4242#include "CanvasPattern.h"
     43#include "DOMMatrix.h"
     44#include "DOMMatrixInit.h"
    4345#include "DOMPath.h"
    4446#include "DisplayListRecorder.h"
     
    796798}
    797799
     800Ref<DOMMatrix> CanvasRenderingContext2D::getTransform() const
     801{
     802    return DOMMatrix::create(state().transform.toTransformationMatrix(), DOMMatrixReadOnly::Is2D::Yes);
     803}
     804
    798805void CanvasRenderingContext2D::setTransform(float m11, float m12, float m21, float m22, float dx, float dy)
    799806{
     
    807814    resetTransform();
    808815    transform(m11, m12, m21, m22, dx, dy);
     816}
     817
     818ExceptionOr<void> CanvasRenderingContext2D::setTransform(DOMMatrixInit&& matrixInit)
     819{
     820    auto checkValid = DOMMatrixReadOnly::validateAndFixup(matrixInit);
     821    if (checkValid.hasException())
     822        return checkValid.releaseException();
     823
     824    setTransform(matrixInit.a.value_or(1), matrixInit.b.value_or(0), matrixInit.c.value_or(0), matrixInit.d.value_or(1), matrixInit.e.value_or(0), matrixInit.f.value_or(0));
     825
     826    return { };
    809827}
    810828
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h

    r218748 r219619  
    4646class CanvasGradient;
    4747class CanvasPattern;
     48class DOMMatrix;
    4849class DOMPath;
    4950class FloatRect;
     
    5556class TextMetrics;
    5657
     58struct DOMMatrixInit;
     59
    5760#if ENABLE(VIDEO)
    5861using CanvasImageSource = Variant<RefPtr<HTMLImageElement>, RefPtr<HTMLVideoElement>, RefPtr<HTMLCanvasElement>>;
     
    114117    void translate(float tx, float ty);
    115118    void transform(float m11, float m12, float m21, float m22, float dx, float dy);
     119
     120    Ref<DOMMatrix> getTransform() const;
    116121    void setTransform(float m11, float m12, float m21, float m22, float dx, float dy);
     122    ExceptionOr<void> setTransform(DOMMatrixInit&&);
    117123    void resetTransform();
    118124
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl

    r210470 r219619  
    5353    void transform(unrestricted float m11, unrestricted float m12, unrestricted float m21, unrestricted float m22,
    5454        unrestricted float dx, unrestricted float dy);
     55
     56    [NewObject] DOMMatrix getTransform();
    5557    void setTransform(unrestricted float m11, unrestricted float m12, unrestricted float m21, unrestricted float m22,
    5658        unrestricted float dx, unrestricted float dy);
     59    [MayThrowException] void setTransform(optional DOMMatrixInit transform);
    5760    void resetTransform();
    5861
Note: See TracChangeset for help on using the changeset viewer.