Title: [210470] trunk/Source/WebCore
Revision
210470
Author
[email protected]
Date
2017-01-06 22:19:44 -0800 (Fri, 06 Jan 2017)

Log Message

[WebIDL] Remove custom bindings from CanvasRenderingContext2D
https://bugs.webkit.org/show_bug.cgi?id=166793

Reviewed by Darin Adler.

* WebCore.xcodeproj/project.pbxproj:
Move JSCanvasRenderingContext2DCustom.cpp to the GC only group.

* bindings/js/JSCanvasRenderingContext2DCustom.cpp:
(WebCore::toJS): Deleted.
(WebCore::toHTMLCanvasStyle): Deleted.
(WebCore::JSCanvasRenderingContext2D::strokeStyle): Deleted.
(WebCore::JSCanvasRenderingContext2D::setStrokeStyle): Deleted.
(WebCore::JSCanvasRenderingContext2D::fillStyle): Deleted.
(WebCore::JSCanvasRenderingContext2D::setFillStyle): Deleted.
Remove non-GC related custom bindings.

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::setStrokeStyle):
(WebCore::CanvasRenderingContext2D::setFillStyle):
(WebCore::toStyle):
(WebCore::CanvasRenderingContext2D::strokeStyle):
(WebCore::CanvasRenderingContext2D::fillStyle):
* html/canvas/CanvasRenderingContext2D.h:
* html/canvas/CanvasRenderingContext2D.idl:
Made existing setStrokeStyle/setFillStyle functions (which take CanvasStyle's) 
private, and implemented new ones that operate on Variants, matching the spec.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (210469 => 210470)


--- trunk/Source/WebCore/ChangeLog	2017-01-07 05:23:54 UTC (rev 210469)
+++ trunk/Source/WebCore/ChangeLog	2017-01-07 06:19:44 UTC (rev 210470)
@@ -1,3 +1,33 @@
+2017-01-06  Sam Weinig  <[email protected]>
+
+        [WebIDL] Remove custom bindings from CanvasRenderingContext2D
+        https://bugs.webkit.org/show_bug.cgi?id=166793
+
+        Reviewed by Darin Adler.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        Move JSCanvasRenderingContext2DCustom.cpp to the GC only group.
+
+        * bindings/js/JSCanvasRenderingContext2DCustom.cpp:
+        (WebCore::toJS): Deleted.
+        (WebCore::toHTMLCanvasStyle): Deleted.
+        (WebCore::JSCanvasRenderingContext2D::strokeStyle): Deleted.
+        (WebCore::JSCanvasRenderingContext2D::setStrokeStyle): Deleted.
+        (WebCore::JSCanvasRenderingContext2D::fillStyle): Deleted.
+        (WebCore::JSCanvasRenderingContext2D::setFillStyle): Deleted.
+        Remove non-GC related custom bindings.
+
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::setStrokeStyle):
+        (WebCore::CanvasRenderingContext2D::setFillStyle):
+        (WebCore::toStyle):
+        (WebCore::CanvasRenderingContext2D::strokeStyle):
+        (WebCore::CanvasRenderingContext2D::fillStyle):
+        * html/canvas/CanvasRenderingContext2D.h:
+        * html/canvas/CanvasRenderingContext2D.idl:
+        Made existing setStrokeStyle/setFillStyle functions (which take CanvasStyle's) 
+        private, and implemented new ones that operate on Variants, matching the spec.
+
 2017-01-05  Darin Adler  <[email protected]>
 
         Remove PassRefPtr use from "rendering" directory, other improvements

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (210469 => 210470)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-01-07 05:23:54 UTC (rev 210469)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-01-07 06:19:44 UTC (rev 210470)
@@ -18324,6 +18324,7 @@
 				BC2ED6BB0C6BD2F000920BFF /* JSAttrCustom.cpp */,
 				BE6DF710171CA2DA00DD52B8 /* JSAudioTrackListCustom.cpp */,
 				8931DE5A14C44C44000DC9D2 /* JSBlobCustom.cpp */,
+				49EED14B1051971900099FAB /* JSCanvasRenderingContext2DCustom.cpp */,
 				BC46C1ED0C0DDBDF0020CFC3 /* JSCSSRuleCustom.cpp */,
 				AD726FE916D9F40A003A4E6D /* JSCSSRuleCustom.h */,
 				9392262E10321084006E7D5D /* JSCSSRuleListCustom.cpp */,
@@ -22092,7 +22093,6 @@
 			children = (
 				7C3D8EE41E08BABE0023B084 /* GC / Wrapping Only */,
 				BE6DF70E171CA2DA00DD52B8 /* JSAudioTrackCustom.cpp */,
-				49EED14B1051971900099FAB /* JSCanvasRenderingContext2DCustom.cpp */,
 				A584FE371864DAC100843B10 /* JSCommandLineAPIHostCustom.cpp */,
 				7CEF26181D6A92E300BE905D /* JSCryptoCustom.cpp */,
 				E157A8E618184C67009F821D /* JSCryptoKeyCustom.cpp */,

Modified: trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp (210469 => 210470)


--- trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp	2017-01-07 05:23:54 UTC (rev 210469)
+++ trunk/Source/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp	2017-01-07 06:19:44 UTC (rev 210470)
@@ -50,55 +50,4 @@
     visitor.addOpaqueRoot(root(wrapped().canvas()));
 }
 
-static JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, const CanvasStyle& style)
-{
-    if (style.canvasGradient())
-        return toJS(exec, globalObject, style.canvasGradient());
-    if (style.canvasPattern())
-        return toJS(exec, globalObject, style.canvasPattern());
-    return jsStringWithCache(exec, style.color());
-}
-
-static CanvasStyle toHTMLCanvasStyle(ExecState*, JSValue value)
-{
-    if (!value.isObject())
-        return CanvasStyle();
-    JSObject* object = asObject(value);
-    if (object->inherits(JSCanvasGradient::info()))
-        return jsCast<JSCanvasGradient*>(object)->wrapped();
-    if (object->inherits(JSCanvasPattern::info()))
-        return jsCast<JSCanvasPattern*>(object)->wrapped();
-    return CanvasStyle();
-}
-
-JSValue JSCanvasRenderingContext2D::strokeStyle(ExecState& state) const
-{
-    return toJS(&state, globalObject(), wrapped().strokeStyle());
-}
-
-void JSCanvasRenderingContext2D::setStrokeStyle(ExecState& state, JSValue value)
-{
-    CanvasRenderingContext2D& context = wrapped();
-    if (value.isString()) {
-        context.setStrokeColor(asString(value)->value(&state));
-        return;
-    }
-    context.setStrokeStyle(toHTMLCanvasStyle(&state, value));
-}
-
-JSValue JSCanvasRenderingContext2D::fillStyle(ExecState& state) const
-{
-    return toJS(&state, globalObject(), wrapped().fillStyle());
-}
-
-void JSCanvasRenderingContext2D::setFillStyle(ExecState& state, JSValue value)
-{
-    CanvasRenderingContext2D& context = wrapped();
-    if (value.isString()) {
-        context.setFillColor(asString(value)->value(&state));
-        return;
-    }
-    context.setFillStyle(toHTMLCanvasStyle(&state, value));
-}
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (210469 => 210470)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2017-01-07 05:23:54 UTC (rev 210469)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2017-01-07 06:19:44 UTC (rev 210470)
@@ -1704,6 +1704,43 @@
 #endif
 }
 
+static CanvasRenderingContext2D::Style toStyle(const CanvasStyle& style)
+{
+    if (auto* gradient = style.canvasGradient())
+        return RefPtr<CanvasGradient> { gradient };
+    if (auto* pattern = style.canvasPattern())
+        return RefPtr<CanvasPattern> { pattern };
+    return style.color();
+}
+
+CanvasRenderingContext2D::Style CanvasRenderingContext2D::strokeStyle() const
+{
+    return toStyle(state().strokeStyle);
+}
+
+void CanvasRenderingContext2D::setStrokeStyle(CanvasRenderingContext2D::Style&& style)
+{
+    WTF::switchOn(style,
+        [this] (const String& string) { this->setStrokeColor(string); },
+        [this] (const RefPtr<CanvasGradient>& gradient) { this->setStrokeStyle(CanvasStyle(*gradient)); },
+        [this] (const RefPtr<CanvasPattern>& pattern) { this->setStrokeStyle(CanvasStyle(*pattern)); }
+    );
+}
+
+CanvasRenderingContext2D::Style CanvasRenderingContext2D::fillStyle() const
+{
+    return toStyle(state().fillStyle);
+}
+
+void CanvasRenderingContext2D::setFillStyle(CanvasRenderingContext2D::Style&& style)
+{
+    WTF::switchOn(style,
+        [this] (const String& string) { this->setFillColor(string); },
+        [this] (const RefPtr<CanvasGradient>& gradient) { this->setFillStyle(CanvasStyle(*gradient)); },
+        [this] (const RefPtr<CanvasPattern>& pattern) { this->setFillStyle(CanvasStyle(*pattern)); }
+    );
+}
+
 ExceptionOr<Ref<CanvasGradient>> CanvasRenderingContext2D::createLinearGradient(float x0, float y0, float x1, float y1)
 {
     if (!std::isfinite(x0) || !std::isfinite(y0) || !std::isfinite(x1) || !std::isfinite(y1))

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h (210469 => 210470)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h	2017-01-07 05:23:54 UTC (rev 210469)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h	2017-01-07 06:19:44 UTC (rev 210470)
@@ -66,12 +66,6 @@
     CanvasRenderingContext2D(HTMLCanvasElement&, bool usesCSSCompatibilityParseMode, bool usesDashboardCompatibilityMode);
     virtual ~CanvasRenderingContext2D();
 
-    const CanvasStyle& strokeStyle() const { return state().strokeStyle; }
-    void setStrokeStyle(CanvasStyle);
-
-    const CanvasStyle& fillStyle() const { return state().fillStyle; }
-    void setFillStyle(CanvasStyle);
-
     float lineWidth() const;
     void setLineWidth(float);
 
@@ -172,6 +166,12 @@
 
     void setCompositeOperation(const String&);
 
+    using Style = Variant<String, RefPtr<CanvasGradient>, RefPtr<CanvasPattern>>;
+    Style strokeStyle() const;
+    void setStrokeStyle(Style&&);
+    Style fillStyle() const;
+    void setFillStyle(Style&&);
+
     ExceptionOr<Ref<CanvasGradient>> createLinearGradient(float x0, float y0, float x1, float y1);
     ExceptionOr<Ref<CanvasGradient>> createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1);
     ExceptionOr<RefPtr<CanvasPattern>> createPattern(CanvasImageSource&&, const String& repetition);
@@ -321,6 +321,9 @@
     void applyStrokePattern();
     void applyFillPattern();
 
+    void setStrokeStyle(CanvasStyle);
+    void setFillStyle(CanvasStyle);
+
     ExceptionOr<RefPtr<CanvasPattern>> createPattern(HTMLImageElement&, bool repeatX, bool repeatY);
     ExceptionOr<RefPtr<CanvasPattern>> createPattern(HTMLCanvasElement&, bool repeatX, bool repeatY);
 #if ENABLE(VIDEO)

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl (210469 => 210470)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl	2017-01-07 05:23:54 UTC (rev 210469)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.idl	2017-01-07 06:19:44 UTC (rev 210470)
@@ -166,8 +166,8 @@
     [MayThrowException] ImageData createImageData(ImageData? imagedata);
     [MayThrowException] ImageData createImageData(float sw, float sh);
 
-    [Custom] attribute custom strokeStyle;
-    [Custom] attribute custom fillStyle;
+    attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle;
+    attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle;
     [MayThrowException] CanvasGradient createLinearGradient(float x0, float y0, float x1, float y1);
     [MayThrowException] CanvasGradient createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1);
     [MayThrowException] CanvasPattern? createPattern(CanvasImageSource image, [TreatNullAs=EmptyString] DOMString repetition);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to