-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathWindow.java
More file actions
110 lines (92 loc) · 2.91 KB
/
Window.java
File metadata and controls
110 lines (92 loc) · 2.91 KB
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
package snap.webapi;
import java.util.function.DoubleConsumer;
/**
* This class is a wrapper for Web API Window (https://developer.mozilla.org/en-US/docs/Web/API/Window).
*/
public class Window extends JSProxy implements EventTarget {
// The current Window
private static Window _window;
// The current document
private static HTMLDocument _document;
// The current Location
private static Location _location;
/**
* Constructor.
*/
public Window(Object winJS)
{
super(winJS);
}
/**
* Returns the ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device.
*/
public static double getDevicePixelRatio() { return get().getMemberDouble("devicePixelRatio"); }
/**
* Return window InnerWidth.
*/
public int getInnerWidth() { return getMemberInt("innerWidth"); }
/**
* Return window InnerHeight.
*/
public int getInnerHeight() { return getMemberInt("innerHeight"); }
/**
* Wrapper method for Web API method.
*/
public void open(String url, String target) { open(url, target, null); }
/**
* Wrapper method for Web API method.
*/
public void open(String url, String target, String windowFeatures)
{
WebEnv.get().open(url, target, windowFeatures);
}
/**
* Request animation frame.
*/
public static int requestAnimationFrame(DoubleConsumer callback)
{
return WebEnv.get().requestAnimationFrame(callback);
}
/**
* Schedules a runnable to execute after a delay of given milliseconds.
*/
public static void setTimeout(Runnable aRun, int aDelay) { WebEnv.get().setTimeout(aRun, aDelay); }
/**
* Schedules a runnable to execute every time a given number of milliseconds elapses.
*/
public static int setInterval(Runnable aRun, int aPeriod) { return WebEnv.get().setInterval(aRun, aPeriod); }
/**
* Stops intervals for given id.
*/
public static void clearInterval(int anId) { WebEnv.get().clearInterval(anId); }
/**
* Returns the current window.
*/
public static Window get()
{
if (_window != null) return _window;
return _window = WebEnv.get().window();
}
/**
* Returns the current location.
*/
public static Location location()
{
if (_location != null) return _location;
Window window = get();
Object locationJS = window.getMember("location");
return _location = new Location(locationJS);
}
/**
* Returns the current window.
*/
public static HTMLDocument getDocument()
{
if (_document != null) return _document;
Window window = get();
Object documentJS = window.getMember("document");
return _document = new HTMLDocument(documentJS);
}
@Deprecated
public static Window current() { return get(); }
}