Skip to content

Commit 71126c1

Browse files
committed
Merge exoego's WindowOrWorkerGlobalScope PR #416
commit c794a67 Author: exoego <[email protected]> Date: Thu Jun 25 12:21:53 2020 +0900 Add WindowOrWorkerGlobalScope
1 parent c900f3b commit 71126c1

File tree

3 files changed

+145
-3
lines changed

3 files changed

+145
-3
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.scalajs.dom.raw
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSGlobal
5+
6+
/**
7+
* The OffscreenCanvas interface provides a canvas that can be rendered off
8+
* screen.
9+
* It is available in both the window and worker contexts.
10+
*
11+
* MDN
12+
*/
13+
@js.native
14+
@JSGlobal
15+
class OffscreenCanvas(var width: Double, var height: Double)
16+
extends js.Object {
17+
18+
/**
19+
* Returns a rendering context for the offscreen canvas.
20+
*
21+
* MDN
22+
*/
23+
def getContext(contextType: String): js.Dynamic = js.native
24+
def getContext(contextType: String,
25+
contextAttributes: WebGLContextAttributes): js.Dynamic = js.native
26+
def getContext(contextType: String,
27+
contextAttributes: TwoDContextAttributes): js.Dynamic = js.native
28+
29+
/**
30+
* Creates a Blob object representing the image contained in the canvas.
31+
*
32+
* MDN
33+
*/
34+
def convertToBlob(
35+
options: ConvertToBlobOptions = ???): js.Promise[Blob] = js.native
36+
37+
/**
38+
* Creates an ImageBitmap object from the most recently rendered image of
39+
* the OffscreenCanvas.
40+
*
41+
* MDN
42+
*/
43+
def transferToImageBitmap(): ImageBitmap = js.native
44+
}
45+
46+
trait TwoDContextAttributes extends js.Object {
47+
var alpha: js.UndefOr[Boolean] = js.undefined
48+
49+
var willReadFrequently: js.UndefOr[Boolean] = js.undefined
50+
51+
var storage: js.UndefOr[String] = js.undefined
52+
}
53+
54+
trait ConvertToBlobOptions extends js.Object {
55+
var `type`: js.UndefOr[String] = js.undefined
56+
57+
var quality: js.UndefOr[Double] = js.undefined
58+
}

src/main/scala/org/scalajs/dom/raw/WindowOrWorkerGlobalScope.scala

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.scalajs.dom.raw
22

33
import scala.scalajs.js
4+
import scala.scalajs.js.|
45
import scala.scalajs.js.annotation._
56
import org.scalajs.dom.experimental.cachestorage.CacheStorage
7+
import org.scalajs.dom.experimental.{RequestInfo, RequestInit, Response}
68

79
/**
810
* The WindowOrWorkerGlobalScope mixin describes several features common to the
@@ -14,7 +16,8 @@ import org.scalajs.dom.experimental.cachestorage.CacheStorage
1416
* MDN
1517
*/
1618
@js.native
17-
trait WindowOrWorkerGlobalScope extends js.Object {
19+
trait WindowOrWorkerGlobalScope extends WindowBase64 with WindowTimers {
20+
import WindowOrWorkerGlobalScope._
1821

1922
/**
2023
* Returns the CacheStorage object associated with the current context.
@@ -54,4 +57,86 @@ trait WindowOrWorkerGlobalScope extends js.Object {
5457
* MDN
5558
*/
5659
def origin: String = js.native //should be USVString
60+
61+
/**
62+
* Starts the process of fetching a resource from the network.
63+
*
64+
* MDN
65+
*/
66+
def fetch(info: RequestInfo,
67+
init: RequestInit = null): js.Promise[Response] = js.native
68+
69+
/**
70+
* Enqueues a microtask—a short function to be executed after execution of
71+
* the JavaScript code completes and control isn't being returned to a
72+
* JavaScript caller, but before handling callbacks and other tasks.
73+
*
74+
* This lets your code run without interfering with other, possibly higher
75+
* priority, code, but before the browser runtime regains control,
76+
* potentially depending upon the work you need to complete.
77+
*
78+
* MDN
79+
*/
80+
def queueMicrotask(function: js.Function0[Any]): Unit = js.native
81+
82+
/**
83+
* Accepts a variety of different image sources, and returns a Promise which
84+
* resolves to an ImageBitmap.
85+
* Optionally the source is cropped to the rectangle of pixels originating at
86+
* (sx, sy) with width sw, and height sh.
87+
*
88+
* MDN
89+
*/
90+
def createImageBitmap(
91+
image: CreateImageBitmapInput): js.Promise[ImageBitmap] = js.native
92+
93+
def createImageBitmap(image: CreateImageBitmapInput,
94+
options: CreateImageBitmapOptions): js.Promise[ImageBitmap] = js.native
95+
96+
def createImageBitmap(image: CreateImageBitmapInput, sx: Double, sy: Double,
97+
sw: Double, sh: Double): js.Promise[ImageBitmap] = js.native
98+
99+
def createImageBitmap(image: CreateImageBitmapInput, sx: Double, sy: Double,
100+
sw: Double, sh: Double,
101+
options: CreateImageBitmapOptions): js.Promise[ImageBitmap] = js.native
102+
}
103+
104+
/**
105+
* The ImageBitmap interface represents a bitmap image which can be drawn to a
106+
* &lt;canvas&gt; without undue latency.
107+
* It can be created from a variety of source objects using the
108+
* createImageBitmap() factory method.
109+
* ImageBitmap provides an asynchronous and resource efficient pathway to
110+
* prepare textures for rendering in WebGL.
111+
*
112+
* MDN
113+
*/
114+
@js.native
115+
trait ImageBitmap extends js.Object {
116+
117+
/**
118+
* An unsigned long representing the height, in CSS pixels, of the ImageData.
119+
*/
120+
def height: Double = js.native
121+
122+
/**
123+
* An unsigned long representing the width, in CSS pixels, of the ImageData.
124+
*/
125+
def width: Double = js.native
126+
}
127+
128+
trait CreateImageBitmapOptions extends js.Object {
129+
var imageOrientation: js.UndefOr[String] = js.undefined
130+
var premultiplyAlpha: js.UndefOr[String] = js.undefined
131+
var colorSpaceConversion: js.UndefOr[String] = js.undefined
132+
var resizeWidth: js.UndefOr[Double] = js.undefined
133+
var resizeHeight: js.UndefOr[Double] = js.undefined
134+
var resizeQuality: js.UndefOr[String] = js.undefined
135+
}
136+
137+
object WindowOrWorkerGlobalScope {
138+
139+
type CreateImageBitmapInput =
140+
HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | HTMLCanvasElement | Blob | ImageData | ImageBitmap | OffscreenCanvas
141+
57142
}

src/main/scala/org/scalajs/dom/raw/lib.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,8 +2057,7 @@ trait WindowSessionStorage extends js.Object {
20572057
@JSGlobal
20582058
class Window
20592059
extends EventTarget with WindowLocalStorage with WindowSessionStorage
2060-
with WindowTimers with WindowBase64 with WindowOrWorkerGlobalScope
2061-
with WindowConsole {
2060+
with WindowOrWorkerGlobalScope with WindowConsole {
20622061
var ondragend: js.Function1[DragEvent, _] = js.native
20632062

20642063
/**

0 commit comments

Comments
 (0)