Skip to content

Commit 150e474

Browse files
committed
Improve getContext2D binding
1 parent c3fc571 commit 150e474

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/DOMAPI.res

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9354,6 +9354,16 @@ type domPoint = {
93549354
...domPointReadOnly,
93559355
}
93569356

9357+
/**
9358+
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#contextattributes)
9359+
*/
9360+
type canvasContext2DAttributes = {
9361+
alpha: bool,
9362+
colorspace?: predefinedColorSpace,
9363+
desynchronized: bool,
9364+
willReadFrequently: bool,
9365+
}
9366+
93579367
/**
93589368
The CanvasRenderingContext2D interface, part of the Canvas API, provides the 2D rendering context for the drawing surface of a <canvas> element. It is used for drawing shapes, text, images, and other objects.
93599369
[See CanvasRenderingContext2D on MDN](https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D)

src/DOMAPI/HTMLCanvasElement.res

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -696,14 +696,15 @@ external togglePopover: (htmlCanvasElement, ~force: bool=?) => bool = "togglePop
696696

697697
/**
698698
Returns an object that provides methods and properties for drawing and manipulating images and graphics on a canvas element in a document. A context object includes information about colors, line widths, fonts, and other graphic parameters that can be drawn on a canvas.
699-
@param contextId The identifier (ID) of the type of canvas to create. Internet Explorer 9 and Internet Explorer 10 support only a 2-D context using canvas.getContext("2d"); IE11 Preview also supports 3-D or WebGL context using canvas.getContext("experimental-webgl");
700-
[Read more on MDN](https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement/getContext)
699+
Creates a CanvasRenderingContext2D object representing a two-dimensional rendering context.
700+
701+
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#2d)
701702
*/
702703
@send
703-
external getContext: (
704+
external getContext2D: (
704705
htmlCanvasElement,
705-
~contextId: string,
706-
~options: JSON.t=?,
706+
@as("2d") _,
707+
~options: canvasRenderingContext2D=?,
707708
) => canvasRenderingContext2D = "getContext"
708709

709710
/**

tests/DOMAPI/HTMLCanvasInputElement__tes.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
open Global
1+
open WebAPI.Global
22

33
let myCanvas: DOMAPI.htmlCanvasElement =
44
document->Document.getElementById("myCanvas")->Prelude.unsafeConversation
5-
let ctx = myCanvas->HTMLCanvasElement.getContext(~contextId="2d")
5+
let ctx = myCanvas->HTMLCanvasElement.getContext2D
66

77
ctx.fillStyle = Prelude.unsafeConversation("red")
88
ctx->CanvasRenderingContext2D.fillRect(~x=50., ~y=50., ~w=200., ~h=200.)

0 commit comments

Comments
 (0)