1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
use super::*;
/// The OffscreenCanvas class.
/// [`OffscreenCanvas`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas)
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct OffscreenCanvas {
inner: EventTarget,
}
impl FromVal for OffscreenCanvas {
fn from_val(v: &Any) -> Self {
OffscreenCanvas {
inner: EventTarget::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for OffscreenCanvas {
type Target = EventTarget;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for OffscreenCanvas {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for OffscreenCanvas {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for OffscreenCanvas {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<OffscreenCanvas> for Any {
fn from(s: OffscreenCanvas) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&OffscreenCanvas> for Any {
fn from(s: &OffscreenCanvas) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(OffscreenCanvas);
impl OffscreenCanvas {
/// Getter of the `width` attribute.
/// [`OffscreenCanvas.width`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/width)
pub fn width(&self) -> u64 {
self.inner.get("width").as_::<u64>()
}
/// Setter of the `width` attribute.
/// [`OffscreenCanvas.width`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/width)
pub fn set_width(&mut self, value: u64) {
self.inner.set("width", value);
}
}
impl OffscreenCanvas {
/// Getter of the `height` attribute.
/// [`OffscreenCanvas.height`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/height)
pub fn height(&self) -> u64 {
self.inner.get("height").as_::<u64>()
}
/// Setter of the `height` attribute.
/// [`OffscreenCanvas.height`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/height)
pub fn set_height(&mut self, value: u64) {
self.inner.set("height", value);
}
}
impl OffscreenCanvas {
/// Getter of the `oncontextlost` attribute.
/// [`OffscreenCanvas.oncontextlost`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/oncontextlost)
pub fn oncontextlost(&self) -> Any {
self.inner.get("oncontextlost").as_::<Any>()
}
/// Setter of the `oncontextlost` attribute.
/// [`OffscreenCanvas.oncontextlost`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/oncontextlost)
pub fn set_oncontextlost(&mut self, value: &Any) {
self.inner.set("oncontextlost", value);
}
}
impl OffscreenCanvas {
/// Getter of the `oncontextrestored` attribute.
/// [`OffscreenCanvas.oncontextrestored`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/oncontextrestored)
pub fn oncontextrestored(&self) -> Any {
self.inner.get("oncontextrestored").as_::<Any>()
}
/// Setter of the `oncontextrestored` attribute.
/// [`OffscreenCanvas.oncontextrestored`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/oncontextrestored)
pub fn set_oncontextrestored(&mut self, value: &Any) {
self.inner.set("oncontextrestored", value);
}
}
impl OffscreenCanvas {
/// The `new OffscreenCanvas(..)` constructor, creating a new OffscreenCanvas instance
pub fn new(width: u64, height: u64) -> OffscreenCanvas {
Self {
inner: Any::global("OffscreenCanvas")
.new(&[width.into(), height.into()])
.as_::<EventTarget>(),
}
}
}
impl OffscreenCanvas {
/// The getContext method.
/// [`OffscreenCanvas.getContext`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/getContext)
pub fn get_context(&self, context_id: &OffscreenRenderingContextId) -> Any {
self.inner
.call("getContext", &[context_id.into()])
.as_::<Any>()
}
}
impl OffscreenCanvas {
/// The getContext method.
/// [`OffscreenCanvas.getContext`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/getContext)
pub fn get_context_with_options(
&self,
context_id: &OffscreenRenderingContextId,
options: &Any,
) -> Any {
self.inner
.call("getContext", &[context_id.into(), options.into()])
.as_::<Any>()
}
}
impl OffscreenCanvas {
/// The transferToImageBitmap method.
/// [`OffscreenCanvas.transferToImageBitmap`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/transferToImageBitmap)
pub fn transfer_to_image_bitmap(&self) -> ImageBitmap {
self.inner
.call("transferToImageBitmap", &[])
.as_::<ImageBitmap>()
}
}
impl OffscreenCanvas {
/// The convertToBlob method.
/// [`OffscreenCanvas.convertToBlob`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/convertToBlob)
pub fn convert_to_blob(&self) -> Promise<Blob> {
self.inner.call("convertToBlob", &[]).as_::<Promise<Blob>>()
}
}
impl OffscreenCanvas {
/// The convertToBlob method.
/// [`OffscreenCanvas.convertToBlob`](https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/convertToBlob)
pub fn convert_to_blob_with_options(&self, options: &ImageEncodeOptions) -> Promise<Blob> {
self.inner
.call("convertToBlob", &[options.into()])
.as_::<Promise<Blob>>()
}
}