Changeset 96626 in webkit


Ignore:
Timestamp:
Oct 4, 2011 11:58:47 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

HTML canvas strokes with dash and dashOffset
https://bugs.webkit.org/show_bug.cgi?id=63933

Patch by Young Han Lee <joybro201@gmail.com> on 2011-10-04
Reviewed by Simon Fraser.

Add webkitLineDash and webkitLineDashOffset attributes to CanvasRenderingContext2D for JSC.
These attributes can be used to determine the dash-style of stroke in HTML Canvas.

As this kind of attributes are not specified in the HTML Canvas specification yet,
the 'webkit' prefix is added to its names.

Mozilla already implemented these attributes, mozDash and mozDashOffset [1], and this patch
is created by referring to the implementation. This patch is basically using the specified
behavior of stroke-dasharray and stroke-dashoffset in the SVG specification [2], except
that doesn't support units or percentages, just floating point numbers.

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=662038
[2] http://www.w3.org/TR/SVG/painting.html#StrokeProperties

Source/WebCore:

Tests: fast/canvas/canvas-webkitLineDash-invalid.html

fast/canvas/canvas-webkitLineDash.html

  • bindings/js/JSCanvasRenderingContext2DCustom.cpp:

(WebCore::JSCanvasRenderingContext2D::webkitLineDash):
(WebCore::JSCanvasRenderingContext2D::setWebkitLineDash):

  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::CanvasRenderingContext2D::State::State):
(WebCore::CanvasRenderingContext2D::webkitLineDash):
(WebCore::CanvasRenderingContext2D::setWebkitLineDash):
(WebCore::CanvasRenderingContext2D::webkitLineDashOffset):
(WebCore::CanvasRenderingContext2D::setWebkitLineDashOffset):

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

LayoutTests:

  • fast/canvas/canvas-webkitLineDash-expected.txt: Added.
  • fast/canvas/canvas-webkitLineDash-invalid-expected.txt: Added.
  • fast/canvas/canvas-webkitLineDash-invalid.html: Added.
  • fast/canvas/canvas-webkitLineDash.html: Added.
  • fast/canvas/script-tests/canvas-webkitLineDash-invalid.js: Added.

(trySettingLineDash):
(trySettingLineDashOffset):

  • fast/canvas/script-tests/canvas-webkitLineDash.js: Added.
  • platform/chromium/test_expectations.txt:
Location:
trunk
Files:
6 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r96625 r96626  
     12011-10-04  Young Han Lee  <joybro201@gmail.com>
     2
     3        HTML canvas strokes with dash and dashOffset
     4        https://bugs.webkit.org/show_bug.cgi?id=63933
     5
     6        Reviewed by Simon Fraser.
     7
     8        Add webkitLineDash and webkitLineDashOffset attributes to CanvasRenderingContext2D for JSC.
     9        These attributes can be used to determine the dash-style of stroke in HTML Canvas.
     10
     11        As this kind of attributes are not specified in the HTML Canvas specification yet,
     12        the 'webkit' prefix is added to its names.
     13
     14        Mozilla already implemented these attributes, mozDash and mozDashOffset [1], and this patch
     15        is created by referring to the implementation. This patch is basically using the specified
     16        behavior of stroke-dasharray and stroke-dashoffset in the SVG specification [2], except
     17        that doesn't support units or percentages, just floating point numbers.
     18
     19        [1] https://bugzilla.mozilla.org/show_bug.cgi?id=662038
     20        [2] http://www.w3.org/TR/SVG/painting.html#StrokeProperties
     21
     22        * fast/canvas/canvas-webkitLineDash-expected.txt: Added.
     23        * fast/canvas/canvas-webkitLineDash-invalid-expected.txt: Added.
     24        * fast/canvas/canvas-webkitLineDash-invalid.html: Added.
     25        * fast/canvas/canvas-webkitLineDash.html: Added.
     26        * fast/canvas/script-tests/canvas-webkitLineDash-invalid.js: Added.
     27        (trySettingLineDash):
     28        (trySettingLineDashOffset):
     29        * fast/canvas/script-tests/canvas-webkitLineDash.js: Added.
     30        * platform/chromium/test_expectations.txt:
     31
    1322011-10-04  Tim Horton  <timothy_horton@apple.com>
    233
  • trunk/LayoutTests/platform/chromium/test_expectations.txt

    r96593 r96626  
    9797// fails for other platforms...
    9898BUGCR20404 : editing/execCommand/copy-without-selection.html = TEXT
     99
     100// This will soon be fixed after implementing webkitLineDash for V8.
     101BUGWK63933 : fast/canvas/canvas-webkitLineDash.html = FAIL
     102BUGWK63933 : fast/canvas/canvas-webkitLineDash-invalid.html = FAIL
    99103
    100104// -----------------------------------------------------------------
  • trunk/Source/WebCore/ChangeLog

    r96624 r96626  
     12011-10-04  Young Han Lee  <joybro201@gmail.com>
     2
     3        HTML canvas strokes with dash and dashOffset
     4        https://bugs.webkit.org/show_bug.cgi?id=63933
     5
     6        Reviewed by Simon Fraser.
     7
     8        Add webkitLineDash and webkitLineDashOffset attributes to CanvasRenderingContext2D for JSC.
     9        These attributes can be used to determine the dash-style of stroke in HTML Canvas.
     10
     11        As this kind of attributes are not specified in the HTML Canvas specification yet,
     12        the 'webkit' prefix is added to its names.
     13
     14        Mozilla already implemented these attributes, mozDash and mozDashOffset [1], and this patch
     15        is created by referring to the implementation. This patch is basically using the specified
     16        behavior of stroke-dasharray and stroke-dashoffset in the SVG specification [2], except
     17        that doesn't support units or percentages, just floating point numbers.
     18
     19        [1] https://bugzilla.mozilla.org/show_bug.cgi?id=662038
     20        [2] http://www.w3.org/TR/SVG/painting.html#StrokeProperties
     21
     22        Tests: fast/canvas/canvas-webkitLineDash-invalid.html
     23               fast/canvas/canvas-webkitLineDash.html
     24
     25        * bindings/js/JSCanvasRenderingContext2DCustom.cpp:
     26        (WebCore::JSCanvasRenderingContext2D::webkitLineDash):
     27        (WebCore::JSCanvasRenderingContext2D::setWebkitLineDash):
     28        * html/canvas/CanvasRenderingContext2D.cpp:
     29        (WebCore::CanvasRenderingContext2D::State::State):
     30        (WebCore::CanvasRenderingContext2D::webkitLineDash):
     31        (WebCore::CanvasRenderingContext2D::setWebkitLineDash):
     32        (WebCore::CanvasRenderingContext2D::webkitLineDashOffset):
     33        (WebCore::CanvasRenderingContext2D::setWebkitLineDashOffset):
     34        * html/canvas/CanvasRenderingContext2D.h:
     35        * html/canvas/CanvasRenderingContext2D.idl:
     36
    1372011-10-04  Matthew Delaney  <mdelaney@apple.com>
    238
  • trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp

    r88794 r96626  
    159159}
    160160
     161JSValue JSCanvasRenderingContext2D::webkitLineDash(ExecState* exec) const
     162{
     163    CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl());
     164    const DashArray* dash = context->webkitLineDash();
     165
     166    MarkedArgumentBuffer list;
     167    DashArray::const_iterator end = dash->end();
     168    for (DashArray::const_iterator it = dash->begin(); it != end; ++it)
     169        list.append(JSValue(*it));
     170    return constructArray(exec, globalObject(), list);
     171}
     172
     173void JSCanvasRenderingContext2D::setWebkitLineDash(ExecState* exec, JSValue value)
     174{
     175    if (!isJSArray(&exec->globalData(), value))
     176        return;
     177
     178    DashArray dash;
     179    JSArray* valueArray = asArray(value);
     180    for (unsigned i = 0; i < valueArray->length(); ++i) {
     181        float elem = valueArray->getIndex(i).toFloat(exec);
     182        if (elem <= 0 || !isfinite(elem))
     183            return;
     184
     185        dash.append(elem);
     186    }
     187
     188    CanvasRenderingContext2D* context = static_cast<CanvasRenderingContext2D*>(impl());
     189    context->setWebkitLineDash(dash);
     190}
     191
    161192} // namespace WebCore
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r96624 r96626  
    193193    , m_globalComposite(CompositeSourceOver)
    194194    , m_invertibleCTM(true)
     195    , m_lineDashOffset(0)
    195196    , m_textAlign(StartTextAlign)
    196197    , m_textBaseline(AlphabeticTextBaseline)
     
    497498}
    498499
     500const DashArray* CanvasRenderingContext2D::webkitLineDash() const
     501{
     502    return &state().m_lineDash;
     503}
     504
     505void CanvasRenderingContext2D::setWebkitLineDash(const DashArray& dash)
     506{
     507    state().m_lineDash = dash;
     508
     509    GraphicsContext* c = drawingContext();
     510    if (!c)
     511        return;
     512    c->setLineDash(state().m_lineDash, state().m_lineDashOffset);
     513}
     514
     515float CanvasRenderingContext2D::webkitLineDashOffset() const
     516{
     517    return state().m_lineDashOffset;
     518}
     519
     520void CanvasRenderingContext2D::setWebkitLineDashOffset(float offset)
     521{
     522    if (!isfinite(offset))
     523        return;
     524
     525    state().m_lineDashOffset = offset;
     526
     527    GraphicsContext* c = drawingContext();
     528    if (!c)
     529        return;
     530    c->setLineDash(state().m_lineDash, state().m_lineDashOffset);
     531}
     532
    499533float CanvasRenderingContext2D::globalAlpha() const
    500534{
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h

    r93901 r96626  
    3030#include "CanvasRenderingContext.h"
    3131#include "Color.h"
     32#include "DashArray.h"
    3233#include "FloatSize.h"
    3334#include "Font.h"
     
    8586    float miterLimit() const;
    8687    void setMiterLimit(float);
     88
     89    const DashArray* webkitLineDash() const;
     90    void setWebkitLineDash(const DashArray&);
     91
     92    float webkitLineDashOffset() const;
     93    void setWebkitLineDashOffset(float);
    8794
    8895    float shadowOffsetX() const;
     
    243250        AffineTransform m_transform;
    244251        bool m_invertibleCTM;
     252        DashArray m_lineDash;
     253        float m_lineDashOffset;
    245254
    246255        // Text state.
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl

    r89148 r96626  
    6060        attribute float shadowBlur;
    6161        attribute [ConvertNullToNullString] DOMString shadowColor;
     62
     63        // FIXME: These attributes should also be implemented for V8.
     64#if !(defined(V8_BINDING) && V8_BINDING)
     65        attribute [Custom] Array webkitLineDash;
     66        attribute float webkitLineDashOffset;
     67#endif
    6268
    6369        void clearRect(in float x, in float y, in float width, in float height);
Note: See TracChangeset for help on using the changeset viewer.