Skip to content
Permalink
Browse files
[Web IDL] Specify default values for optional parameters of type 'flo…
…at' / '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:

Canonical link: https://commits.webkit.org/175114@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200058 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Apr 25, 2016
1 parent 18f5924 commit 1c773f84b4090dc3e8bf61cd80b219069464764c
@@ -1,3 +1,32 @@
2016-04-25 Chris Dumez <cdumez@apple.com>

[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:

2016-04-25 Brent Fulgham <bfulgham@apple.com>

Add port 4190 (managesieve) to port blacklist
@@ -3386,9 +3386,7 @@ sub CanUseWTFOptionalForParameter
return 0 if $type eq "DOMString";
return 0 if $type eq "Dictionary";
return 0 if $type eq "any";
return 0 if $type eq "float";
return 0 if $type eq "long";
return 0 if $type eq "unrestricted float";
return 0 if $type eq "unrestricted double";
return 0 if $type eq "unsigned long";

@@ -499,12 +499,7 @@ EncodedJSValue JSC_HOST_CALL jsTestTypedefsPrototypeFunctionSetShadow(ExecState*
String color = state->argument(3).toString(state)->value(state);
if (UNLIKELY(state->hadException()))
return JSValue::encode(jsUndefined());
if (argsCount <= 4) {
impl.setShadow(width, height, blur, color);
return JSValue::encode(jsUndefined());
}

float alpha = state->argument(4).toFloat(state);
Optional<float> alpha = state->argument(4).isUndefined() ? Optional<float>() : state->uncheckedArgument(4).toFloat(state);
if (UNLIKELY(state->hadException()))
return JSValue::encode(jsUndefined());
impl.setShadow(width, height, blur, color, alpha);
@@ -819,27 +819,21 @@ void CanvasRenderingContext2D::setTransform(float m11, float m12, float m21, flo
transform(m11, m12, m21, m22, dx, dy);
}

void CanvasRenderingContext2D::setStrokeColor(const String& color)
void CanvasRenderingContext2D::setStrokeColor(const String& color, Optional<float> alpha)
{
if (alpha) {
setStrokeStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha.value()));
return;
}

if (color == state().unparsedStrokeColor)
return;

realizeSaves();
setStrokeStyle(CanvasStyle::createFromString(color, &canvas()->document()));
modifiableState().unparsedStrokeColor = color;
}

void CanvasRenderingContext2D::setStrokeColor(float grayLevel)
{
if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, 1.0f))
return;
setStrokeStyle(CanvasStyle(grayLevel, 1.0f));
}

void CanvasRenderingContext2D::setStrokeColor(const String& color, float alpha)
{
setStrokeStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha));
}

void CanvasRenderingContext2D::setStrokeColor(float grayLevel, float alpha)
{
if (state().strokeStyle.isValid() && state().strokeStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, alpha))
@@ -861,27 +855,21 @@ void CanvasRenderingContext2D::setStrokeColor(float c, float m, float y, float k
setStrokeStyle(CanvasStyle(c, m, y, k, a));
}

void CanvasRenderingContext2D::setFillColor(const String& color)
void CanvasRenderingContext2D::setFillColor(const String& color, Optional<float> alpha)
{
if (alpha) {
setFillStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha.value()));
return;
}

if (color == state().unparsedFillColor)
return;

realizeSaves();
setFillStyle(CanvasStyle::createFromString(color, &canvas()->document()));
modifiableState().unparsedFillColor = color;
}

void CanvasRenderingContext2D::setFillColor(float grayLevel)
{
if (state().fillStyle.isValid() && state().fillStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, 1.0f))
return;
setFillStyle(CanvasStyle(grayLevel, 1.0f));
}

void CanvasRenderingContext2D::setFillColor(const String& color, float alpha)
{
setFillStyle(CanvasStyle::createFromStringWithOverrideAlpha(color, alpha));
}

void CanvasRenderingContext2D::setFillColor(float grayLevel, float alpha)
{
if (state().fillStyle.isValid() && state().fillStyle.isEquivalentRGBA(grayLevel, grayLevel, grayLevel, alpha))
@@ -1271,20 +1259,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur)
setShadow(FloatSize(width, height), blur, Color::transparent);
}

void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color)
{
RGBA32 rgba;
if (!parseColorOrCurrentColor(rgba, color, canvas()))
return;
setShadow(FloatSize(width, height), blur, rgba);
}

void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float grayLevel)
{
setShadow(FloatSize(width, height), blur, makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, 1));
}

void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, float alpha)
void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, Optional<float> alpha)
{
RGBA32 rgba;
if (!parseColorOrCurrentColor(rgba, color, canvas()))
@@ -2327,24 +2302,14 @@ void CanvasRenderingContext2D::setDirection(const String& directionString)
modifiableState().direction = direction;
}

void CanvasRenderingContext2D::fillText(const String& text, float x, float y)
{
drawTextInternal(text, x, y, true);
}

void CanvasRenderingContext2D::fillText(const String& text, float x, float y, float maxWidth)
{
drawTextInternal(text, x, y, true, maxWidth, true);
}

void CanvasRenderingContext2D::strokeText(const String& text, float x, float y)
void CanvasRenderingContext2D::fillText(const String& text, float x, float y, Optional<float> maxWidth)
{
drawTextInternal(text, x, y, false);
drawTextInternal(text, x, y, true, maxWidth);
}

void CanvasRenderingContext2D::strokeText(const String& text, float x, float y, float maxWidth)
void CanvasRenderingContext2D::strokeText(const String& text, float x, float y, Optional<float> maxWidth)
{
drawTextInternal(text, x, y, false, maxWidth, true);
drawTextInternal(text, x, y, false, maxWidth);
}

static inline bool isSpaceThatNeedsReplacing(UChar c)
@@ -2390,7 +2355,7 @@ Ref<TextMetrics> CanvasRenderingContext2D::measureText(const String& text)
return metrics;
}

void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, float y, bool fill, float maxWidth, bool useMaxWidth)
void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, float y, bool fill, Optional<float> maxWidth)
{
const auto& fontProxy = this->fontProxy();
const FontMetrics& fontMetrics = fontProxy.fontMetrics();
@@ -2402,7 +2367,7 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo
return;
if (!std::isfinite(x) | !std::isfinite(y))
return;
if (useMaxWidth && (!std::isfinite(maxWidth) || maxWidth <= 0))
if (maxWidth && (!std::isfinite(maxWidth.value()) || maxWidth.value() <= 0))
return;

// If gradient size is zero, then paint nothing.
@@ -2447,8 +2412,8 @@ void CanvasRenderingContext2D::drawTextInternal(const String& text, float x, flo

float fontWidth = fontProxy.width(TextRun(normalizedText, 0, 0, AllowTrailingExpansion, direction, override));

useMaxWidth = (useMaxWidth && maxWidth < fontWidth);
float width = useMaxWidth ? maxWidth : fontWidth;
bool useMaxWidth = maxWidth && maxWidth.value() < fontWidth;
float width = useMaxWidth ? maxWidth.value() : fontWidth;

TextAlign align = state().textAlign;
if (align == StartTextAlign)
@@ -117,17 +117,13 @@ class CanvasRenderingContext2D final : public CanvasRenderingContext, public Can
void transform(float m11, float m12, float m21, float m22, float dx, float dy);
void setTransform(float m11, float m12, float m21, float m22, float dx, float dy);

void setStrokeColor(const String& color);
void setStrokeColor(float grayLevel);
void setStrokeColor(const String& color, float alpha);
void setStrokeColor(float grayLevel, float alpha);
void setStrokeColor(const String& color, Optional<float> alpha = Nullopt);
void setStrokeColor(float grayLevel, float alpha = 1.0);
void setStrokeColor(float r, float g, float b, float a);
void setStrokeColor(float c, float m, float y, float k, float a);

void setFillColor(const String& color);
void setFillColor(float grayLevel);
void setFillColor(const String& color, float alpha);
void setFillColor(float grayLevel, float alpha);
void setFillColor(const String& color, Optional<float> alpha = Nullopt);
void setFillColor(float grayLevel, float alpha = 1.0f);
void setFillColor(float r, float g, float b, float a);
void setFillColor(float c, float m, float y, float k, float a);

@@ -152,10 +148,9 @@ class CanvasRenderingContext2D final : public CanvasRenderingContext, public Can
void strokeRect(float x, float y, float width, float height);

void setShadow(float width, float height, float blur);
void setShadow(float width, float height, float blur, const String& color);
void setShadow(float width, float height, float blur, float grayLevel);
void setShadow(float width, float height, float blur, const String& color, float alpha);
void setShadow(float width, float height, float blur, float grayLevel, float alpha);
void setShadow(float width, float height, float blur, const String& color, Optional<float> alpha = Nullopt);
void setShadow(float width, float height, float blur, float grayLevel, float alpha = 1.0);
void setShadow(float width, float height, float blur, float r, float g, float b, float a);
void setShadow(float width, float height, float blur, float c, float m, float y, float k, float a);

@@ -217,10 +212,8 @@ class CanvasRenderingContext2D final : public CanvasRenderingContext, public Can
String direction() const;
void setDirection(const String&);

void fillText(const String& text, float x, float y);
void fillText(const String& text, float x, float y, float maxWidth);
void strokeText(const String& text, float x, float y);
void strokeText(const String& text, float x, float y, float maxWidth);
void fillText(const String& text, float x, float y, Optional<float> maxWidth = Nullopt);
void strokeText(const String& text, float x, float y, Optional<float> maxWidth = Nullopt);
Ref<TextMetrics> measureText(const String& text);

LineCap getLineCap() const { return state().lineCap; }
@@ -345,7 +338,7 @@ class CanvasRenderingContext2D final : public CanvasRenderingContext, public Can
void applyStrokePattern();
void applyFillPattern();

void drawTextInternal(const String& text, float x, float y, bool fill, float maxWidth = 0, bool useMaxWidth = false);
void drawTextInternal(const String& text, float x, float y, bool fill, Optional<float> maxWidth = Nullopt);

// The relationship between FontCascade and CanvasRenderingContext2D::FontProxy must hold certain invariants.
// Therefore, all font operations must pass through the State.
@@ -128,12 +128,12 @@ interface CanvasRenderingContext2D : CanvasRenderingContext {
void strokeText(DOMString text, unrestricted float x, unrestricted float y, optional unrestricted float maxWidth);

void setStrokeColor([StrictTypeChecking] DOMString color, optional unrestricted float alpha);
void setStrokeColor(unrestricted float grayLevel, optional float alpha);
void setStrokeColor(unrestricted float grayLevel, optional float alpha = 1);
void setStrokeColor(unrestricted float r, unrestricted float g, unrestricted float b, unrestricted float a);
void setStrokeColor(unrestricted float c, unrestricted float m, unrestricted float y, unrestricted float k, unrestricted float a);

void setFillColor([StrictTypeChecking] DOMString color, optional unrestricted float alpha);
void setFillColor(unrestricted float grayLevel, optional unrestricted float alpha);
void setFillColor(unrestricted float grayLevel, optional unrestricted float alpha = 1);
void setFillColor(unrestricted float r, unrestricted float g, unrestricted float b, unrestricted float a);
void setFillColor(unrestricted float c, unrestricted float m, unrestricted float y, unrestricted float k, unrestricted float a);

@@ -156,14 +156,14 @@ interface CanvasRenderingContext2D : CanvasRenderingContext {
unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);

void drawImageFromRect(HTMLImageElement image,
optional unrestricted float sx, optional unrestricted float sy, optional unrestricted float sw, optional unrestricted float sh,
optional unrestricted float dx, optional unrestricted float dy, optional unrestricted float dw, optional unrestricted float dh,
optional DOMString compositeOperation);
optional unrestricted float sx = 0, optional unrestricted float sy = 0, optional unrestricted float sw = 0, optional unrestricted float sh = 0,
optional unrestricted float dx = 0, optional unrestricted float dy = 0, optional unrestricted float dw = 0, optional unrestricted float dh = 0,
optional DOMString compositeOperation = "");

void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur,
[StrictTypeChecking] optional DOMString color, optional unrestricted float alpha);
void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, unrestricted float grayLevel,
optional unrestricted float alpha);
optional unrestricted float alpha = 1);
void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, unrestricted float r,
unrestricted float g, unrestricted float b, unrestricted float a);
void setShadow(float width, unrestricted float height, unrestricted float blur, unrestricted float c, unrestricted float m,
@@ -32,6 +32,7 @@
#include <cmath>
#include <unicode/uchar.h>
#include <wtf/Forward.h>
#include <wtf/Optional.h>
#include <wtf/text/LChar.h>

#if USE(CG)
@@ -55,6 +56,8 @@ WEBCORE_EXPORT RGBA32 makeRGB(int r, int g, int b);
WEBCORE_EXPORT RGBA32 makeRGBA(int r, int g, int b, int a);

WEBCORE_EXPORT RGBA32 colorWithOverrideAlpha(RGBA32 color, float overrideAlpha);
WEBCORE_EXPORT RGBA32 colorWithOverrideAlpha(RGBA32 color, Optional<float> overrideAlpha);

WEBCORE_EXPORT RGBA32 makeRGBA32FromFloats(float r, float g, float b, float a);
RGBA32 makeRGBAFromHSLA(double h, double s, double l, double a);
RGBA32 makeRGBAFromCMYKA(float c, float m, float y, float k, float a);
@@ -295,6 +298,11 @@ inline uint16_t fastDivideBy255(uint16_t value)
return approximation + (remainder >> 8);
}

inline RGBA32 colorWithOverrideAlpha(RGBA32 color, Optional<float> overrideAlpha)
{
return overrideAlpha ? colorWithOverrideAlpha(color, overrideAlpha.value()) : color;
}

WEBCORE_EXPORT TextStream& operator<<(TextStream&, const Color&);

} // namespace WebCore
@@ -271,7 +271,7 @@ enum AutoFillButtonType {
[RaisesException] void setInspectorIsUnderTest(boolean isUnderTest);

DOMString counterValue(Element element);
long pageNumber(Element element, optional unrestricted float pageWidth, optional unrestricted float pageHeight);
long pageNumber(Element element, optional unrestricted float pageWidth = 800, optional unrestricted float pageHeight = 600);
DOMString[] shortcutIconURLs();
long numberOfPages(optional unrestricted double pageWidthInPixels, optional unrestricted double pageHeightInPixels);
[RaisesException] DOMString pageProperty(DOMString propertyName, long pageNumber);

0 comments on commit 1c773f8

Please sign in to comment.