Changeset 200058 in webkit


Ignore:
Timestamp:
Apr 25, 2016 4:39:01 PM (8 years ago)
Author:
Chris Dumez
Message:

[Web IDL] Specify default values for optional parameters of type 'float' / 'unrestricted float'
https://bugs.webkit.org/show_bug.cgi?id=156995

Reviewed by Darin Adler.

Specify default values for optional parameters of type 'float' / 'unrestricted float'
and let the bindings generator use WTF::Optional<> for the ones that do not have a
default value.

  • bindings/scripts/CodeGeneratorJS.pm:

(CanUseWTFOptionalForParameter): Deleted.

  • bindings/scripts/test/JS/JSTestTypedefs.cpp:

(WebCore::jsTestTypedefsPrototypeFunctionSetShadow):

  • html/canvas/CanvasRenderingContext2D.cpp:

(WebCore::CanvasRenderingContext2D::setStrokeColor):
(WebCore::CanvasRenderingContext2D::setFillColor):
(WebCore::CanvasRenderingContext2D::setShadow):
(WebCore::CanvasRenderingContext2D::fillText):
(WebCore::CanvasRenderingContext2D::strokeText):
(WebCore::CanvasRenderingContext2D::drawTextInternal):
(WebCore::CanvasRenderingContext2D::clearShadow): Deleted.
(WebCore::normalizeSpaces): Deleted.
(WebCore::CanvasRenderingContext2D::measureText): Deleted.

  • html/canvas/CanvasRenderingContext2D.h:
  • html/canvas/CanvasRenderingContext2D.idl:
  • testing/Internals.idl:
Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r200056 r200058  
     12016-04-25  Chris Dumez  <cdumez@apple.com>
     2
     3        [Web IDL] Specify default values for optional parameters of type 'float' / 'unrestricted float'
     4        https://bugs.webkit.org/show_bug.cgi?id=156995
     5
     6        Reviewed by Darin Adler.
     7
     8        Specify default values for optional parameters of type 'float' / 'unrestricted float'
     9        and let the bindings generator use WTF::Optional<> for the ones that do not have a
     10        default value.
     11
     12        * bindings/scripts/CodeGeneratorJS.pm:
     13        (CanUseWTFOptionalForParameter): Deleted.
     14        * bindings/scripts/test/JS/JSTestTypedefs.cpp:
     15        (WebCore::jsTestTypedefsPrototypeFunctionSetShadow):
     16        * html/canvas/CanvasRenderingContext2D.cpp:
     17        (WebCore::CanvasRenderingContext2D::setStrokeColor):
     18        (WebCore::CanvasRenderingContext2D::setFillColor):
     19        (WebCore::CanvasRenderingContext2D::setShadow):
     20        (WebCore::CanvasRenderingContext2D::fillText):
     21        (WebCore::CanvasRenderingContext2D::strokeText):
     22        (WebCore::CanvasRenderingContext2D::drawTextInternal):
     23        (WebCore::CanvasRenderingContext2D::clearShadow): Deleted.
     24        (WebCore::normalizeSpaces): Deleted.
     25        (WebCore::CanvasRenderingContext2D::measureText): Deleted.
     26        * html/canvas/CanvasRenderingContext2D.h:
     27        * html/canvas/CanvasRenderingContext2D.idl:
     28        * testing/Internals.idl:
     29
    1302016-04-25  Brent Fulgham  <bfulgham@apple.com>
    231
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r200037 r200058  
    33873387    return 0 if $type eq "Dictionary";
    33883388    return 0 if $type eq "any";
    3389     return 0 if $type eq "float";
    33903389    return 0 if $type eq "long";
    3391     return 0 if $type eq "unrestricted float";
    33923390    return 0 if $type eq "unrestricted double";
    33933391    return 0 if $type eq "unsigned long";
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.cpp

    r200044 r200058  
    500500    if (UNLIKELY(state->hadException()))
    501501        return JSValue::encode(jsUndefined());
    502     if (argsCount <= 4) {
    503         impl.setShadow(width, height, blur, color);
    504         return JSValue::encode(jsUndefined());
    505     }
    506 
    507     float alpha = state->argument(4).toFloat(state);
     502    Optional<float> alpha = state->argument(4).isUndefined() ? Optional<float>() : state->uncheckedArgument(4).toFloat(state);
    508503    if (UNLIKELY(state->hadException()))
    509504        return JSValue::encode(jsUndefined());
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

    r200041 r200058  
    820820}
    821821
    822 void CanvasRenderingContext2D::setStrokeColor(const String& color)
    823 {
     822void CanvasRenderingContext2D::setStrokeColor(const String& color, Optional<float> alpha)
     823{
     824    if (alpha) {
     825        setStrokeStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha.value()));
     826        return;
     827    }
     828
    824829    if (color == state().unparsedStrokeColor)
    825830        return;
     831
    826832    realizeSaves();
    827833    setStrokeStyle(CanvasStyle::createFromString(color, &canvas()->document()));
     
    829835}
    830836
    831 void CanvasRenderingContext2D::setStrokeColor(float grayLevel)
    832 {
    833     if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, 1.0f))
    834         return;
    835     setStrokeStyle(CanvasStyle(grayLevel, 1.0f));
    836 }
    837 
    838 void CanvasRenderingContext2D::setStrokeColor(const String& color, float alpha)
    839 {
    840     setStrokeStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha));
    841 }
    842 
    843837void CanvasRenderingContext2D::setStrokeColor(float grayLevel, float alpha)
    844838{
     
    862856}
    863857
    864 void CanvasRenderingContext2D::setFillColor(const String& color)
    865 {
     858void CanvasRenderingContext2D::setFillColor(const String& color, Optional<float> alpha)
     859{
     860    if (alpha) {
     861        setFillStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha.value()));
     862        return;
     863    }
     864
    866865    if (color == state().unparsedFillColor)
    867866        return;
     867
    868868    realizeSaves();
    869869    setFillStyle(CanvasStyle::createFromString(color, &canvas()->document()));
    870870    modifiableState().unparsedFillColor = color;
    871 }
    872 
    873 void CanvasRenderingContext2D::setFillColor(float grayLevel)
    874 {
    875     if (state().fillStyle.isValid() && state().fillStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, 1.0f))
    876         return;
    877     setFillStyle(CanvasStyle(grayLevel, 1.0f));
    878 }
    879 
    880 void CanvasRenderingContext2D::setFillColor(const String& color, float alpha)
    881 {
    882     setFillStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha));
    883871}
    884872
     
    12721260}
    12731261
    1274 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color)
    1275 {
    1276     RGBA32 rgba;
    1277     if (!parseColorOrCurrentColor(rgba, color, canvas()))
    1278         return;
    1279     setShadow(FloatSize(width, height), blur, rgba);
    1280 }
    1281 
    1282 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float grayLevel)
    1283 {
    1284     setShadow(FloatSize(width, height), blur, makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, 1));
    1285 }
    1286 
    1287 void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, float alpha)
     1262void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, Optional<float> alpha)
    12881263{
    12891264    RGBA32 rgba;
     
    23282303}
    23292304
    2330 void CanvasRenderingContext2D::fillText(const String& text, float x, float y)
    2331 {
    2332     drawTextInternal(text, x, y, true);
    2333 }
    2334 
    2335 void CanvasRenderingContext2D::fillText(const String& text, float x, float y, float maxWidth)
    2336 {
    2337     drawTextInternal(text, x, y, true, maxWidth, true);
    2338 }
    2339 
    2340 void CanvasRenderingContext2D::strokeText(const String& text, float x, float y)
    2341 {
    2342     drawTextInternal(text, x, y, false);
    2343 }
    2344 
    2345 void CanvasRenderingContext2D::strokeText(const String& text, float x, float y, float maxWidth)
    2346 {
    2347     drawTextInternal(text, x, y, false, maxWidth, true);
     2305void CanvasRenderingContext2D::fillText(const String& text, float x, float y, Optional<float> maxWidth)
     2306{
     2307    drawTextInternal(text, x, y, true, maxWidth);
     2308}
     2309
     2310void CanvasRenderingContext2D::strokeText(const String& text, float x, float y, Optional<float> maxWidth)
     2311{
     2312    drawTextInternal(text, x, y, false, maxWidth);
    23482313}
    23492314
     
    23912356}
    23922357
    2393 void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, float y, bool fill, float maxWidth, bool useMaxWidth)
     2358void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, float y, bool fill, Optional<float> maxWidth)
    23942359{
    23952360    const auto& fontProxy = this->fontProxy();
     
    24032368    if (!std::isfinite(x) | !std::isfinite(y))
    24042369        return;
    2405     if (useMaxWidth && (!std::isfinite(maxWidth) || maxWidth <= 0))
     2370    if (maxWidth && (!std::isfinite(maxWidth.value()) || maxWidth.value() <= 0))
    24062371        return;
    24072372
     
    24482413    float fontWidth = fontProxy.width(TextRun(normalizedText, 0, 0, AllowTrailingExpansion, direction, override));
    24492414
    2450     useMaxWidth = (useMaxWidth && maxWidth < fontWidth);
    2451     float width = useMaxWidth ? maxWidth : fontWidth;
     2415    bool useMaxWidth = maxWidth && maxWidth.value() < fontWidth;
     2416    float width = useMaxWidth ? maxWidth.value() : fontWidth;
    24522417
    24532418    TextAlign align = state().textAlign;
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h

    r199776 r200058  
    118118    void setTransform(float m11, float m12, float m21, float m22, float dx, float dy);
    119119
    120     void setStrokeColor(const String& color);
    121     void setStrokeColor(float grayLevel);
    122     void setStrokeColor(const String& color, float alpha);
    123     void setStrokeColor(float grayLevel, float alpha);
     120    void setStrokeColor(const String& color, Optional<float> alpha = Nullopt);
     121    void setStrokeColor(float grayLevel, float alpha = 1.0);
    124122    void setStrokeColor(float r, float g, float b, float a);
    125123    void setStrokeColor(float c, float m, float y, float k, float a);
    126124
    127     void setFillColor(const String& color);
    128     void setFillColor(float grayLevel);
    129     void setFillColor(const String& color, float alpha);
    130     void setFillColor(float grayLevel, float alpha);
     125    void setFillColor(const String& color, Optional<float> alpha = Nullopt);
     126    void setFillColor(float grayLevel, float alpha = 1.0f);
    131127    void setFillColor(float r, float g, float b, float a);
    132128    void setFillColor(float c, float m, float y, float k, float a);
     
    153149
    154150    void setShadow(float width, float height, float blur);
    155     void setShadow(float width, float height, float blur, const String& color);
    156151    void setShadow(float width, float height, float blur, float grayLevel);
    157     void setShadow(float width, float height, float blur, const String& color, float alpha);
    158     void setShadow(float width, float height, float blur, float grayLevel, float alpha);
     152    void setShadow(float width, float height, float blur, const String& color, Optional<float> alpha = Nullopt);
     153    void setShadow(float width, float height, float blur, float grayLevel, float alpha = 1.0);
    159154    void setShadow(float width, float height, float blur, float r, float g, float b, float a);
    160155    void setShadow(float width, float height, float blur, float c, float m, float y, float k, float a);
     
    218213    void setDirection(const String&);
    219214
    220     void fillText(const String& text, float x, float y);
    221     void fillText(const String& text, float x, float y, float maxWidth);
    222     void strokeText(const String& text, float x, float y);
    223     void strokeText(const String& text, float x, float y, float maxWidth);
     215    void fillText(const String& text, float x, float y, Optional<float> maxWidth = Nullopt);
     216    void strokeText(const String& text, float x, float y, Optional<float> maxWidth = Nullopt);
    224217    Ref<TextMetrics> measureText(const String& text);
    225218
     
    346339    void applyFillPattern();
    347340
    348     void drawTextInternal(const String& text, float x, float y, bool fill, float maxWidth = 0, bool useMaxWidth = false);
     341    void drawTextInternal(const String& text, float x, float y, bool fill, Optional<float> maxWidth = Nullopt);
    349342
    350343    // The relationship between FontCascade and CanvasRenderingContext2D::FontProxy must hold certain invariants.
  • trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl

    r199969 r200058  
    129129
    130130    void setStrokeColor([StrictTypeChecking] DOMString color, optional unrestricted float alpha);
    131     void setStrokeColor(unrestricted float grayLevel, optional float alpha);
     131    void setStrokeColor(unrestricted float grayLevel, optional float alpha = 1);
    132132    void setStrokeColor(unrestricted float r, unrestricted float g, unrestricted float b, unrestricted float a);
    133133    void setStrokeColor(unrestricted float c, unrestricted float m, unrestricted float y, unrestricted float k, unrestricted float a);
    134134
    135135    void setFillColor([StrictTypeChecking] DOMString color, optional unrestricted float alpha);
    136     void setFillColor(unrestricted float grayLevel, optional unrestricted float alpha);
     136    void setFillColor(unrestricted float grayLevel, optional unrestricted float alpha = 1);
    137137    void setFillColor(unrestricted float r, unrestricted float g, unrestricted float b, unrestricted float a);
    138138    void setFillColor(unrestricted float c, unrestricted float m, unrestricted float y, unrestricted float k, unrestricted float a);
     
    157157
    158158    void drawImageFromRect(HTMLImageElement image,
    159         optional unrestricted float sx, optional unrestricted float sy, optional unrestricted float sw, optional unrestricted float sh,
    160         optional unrestricted float dx, optional unrestricted float dy, optional unrestricted float dw, optional unrestricted float dh,
    161         optional DOMString compositeOperation);
     159        optional unrestricted float sx = 0, optional unrestricted float sy = 0, optional unrestricted float sw = 0, optional unrestricted float sh = 0,
     160        optional unrestricted float dx = 0, optional unrestricted float dy = 0, optional unrestricted float dw = 0, optional unrestricted float dh = 0,
     161        optional DOMString compositeOperation = "");
    162162
    163163    void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur,
    164164        [StrictTypeChecking] optional DOMString color, optional unrestricted float alpha);
    165165    void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, unrestricted float grayLevel,
    166         optional unrestricted float alpha);
     166        optional unrestricted float alpha = 1);
    167167    void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, unrestricted float r,
    168168        unrestricted float g, unrestricted float b, unrestricted float a);
  • trunk/Source/WebCore/platform/graphics/Color.h

    r196360 r200058  
    3333#include <unicode/uchar.h>
    3434#include <wtf/Forward.h>
     35#include <wtf/Optional.h>
    3536#include <wtf/text/LChar.h>
    3637
     
    5657
    5758WEBCORE_EXPORT RGBA32 colorWithOverrideAlpha(RGBA32 color, float overrideAlpha);
     59WEBCORE_EXPORT RGBA32 colorWithOverrideAlpha(RGBA32 color, Optional<float> overrideAlpha);
     60
    5861WEBCORE_EXPORT RGBA32 makeRGBA32FromFloats(float r, float g, float b, float a);
    5962RGBA32 makeRGBAFromHSLA(double h, double s, double l, double a);
     
    296299}
    297300
     301inline RGBA32 colorWithOverrideAlpha(RGBA32 color, Optional<float> overrideAlpha)
     302{
     303    return overrideAlpha ? colorWithOverrideAlpha(color, overrideAlpha.value()) : color;
     304}
     305
    298306WEBCORE_EXPORT TextStream& operator<<(TextStream&, const Color&);
    299307
  • trunk/Source/WebCore/testing/Internals.idl

    r200037 r200058  
    272272
    273273    DOMString counterValue(Element element);
    274     long pageNumber(Element element, optional unrestricted float pageWidth, optional unrestricted float pageHeight);
     274    long pageNumber(Element element, optional unrestricted float pageWidth = 800, optional unrestricted float pageHeight = 600);
    275275    DOMString[] shortcutIconURLs();
    276276    long numberOfPages(optional unrestricted double pageWidthInPixels, optional unrestricted double pageHeightInPixels);
Note: See TracChangeset for help on using the changeset viewer.