1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.event;
16
17 import static org.htmlunit.javascript.configuration.SupportedBrowser.FF;
18 import static org.htmlunit.javascript.configuration.SupportedBrowser.FF_ESR;
19
20 import org.htmlunit.corejs.javascript.Scriptable;
21 import org.htmlunit.corejs.javascript.ScriptableObject;
22 import org.htmlunit.html.DomNode;
23 import org.htmlunit.javascript.JavaScriptEngine;
24 import org.htmlunit.javascript.configuration.JsxClass;
25 import org.htmlunit.javascript.configuration.JsxConstant;
26 import org.htmlunit.javascript.configuration.JsxConstructor;
27 import org.htmlunit.javascript.configuration.JsxFunction;
28 import org.htmlunit.javascript.configuration.JsxGetter;
29 import org.htmlunit.javascript.host.Window;
30
31
32
33
34
35
36
37
38
39
40 @JsxClass
41 public class UIEvent extends Event {
42
43
44 @JsxConstant({FF, FF_ESR})
45 public static final int SCROLL_PAGE_DOWN = 0x8000;
46
47
48 @JsxConstant({FF, FF_ESR})
49 public static final int SCROLL_PAGE_UP = 0xFFFF8000;
50
51
52 private long detail_;
53
54
55 private Object view_;
56 private static final Object NO_VIEW = new Object();
57
58
59
60
61 public UIEvent() {
62 super();
63 }
64
65
66
67
68
69
70
71 @JsxConstructor
72 @Override
73 public void jsConstructor(final String type, final ScriptableObject details) {
74 super.jsConstructor(type, details);
75
76 view_ = NO_VIEW;
77 if (details != null && !JavaScriptEngine.isUndefined(details)) {
78 final Object view = details.get("view", details);
79 if (view instanceof Window) {
80 view_ = view;
81 }
82 else if (view != Scriptable.NOT_FOUND) {
83 throw JavaScriptEngine.typeError("View must be a window.");
84 }
85 }
86 }
87
88
89
90
91
92
93
94 public UIEvent(final DomNode domNode, final String type) {
95 super(domNode, type);
96 }
97
98
99
100
101
102
103 public UIEvent(final EventTarget target, final String type) {
104 super(target, type);
105 }
106
107
108
109
110
111
112
113
114 @JsxGetter
115 public long getDetail() {
116 return detail_;
117 }
118
119
120
121
122
123
124 protected void setDetail(final long detail) {
125 detail_ = detail;
126 }
127
128
129
130
131
132
133 @JsxGetter
134 public Window getView() {
135 if (view_ == NO_VIEW) {
136 return null;
137 }
138 if (view_ != null) {
139 return (Window) view_;
140 }
141 return getWindow();
142 }
143
144
145
146
147
148
149
150
151
152
153 @JsxFunction
154 public void initUIEvent(
155 final String type,
156 final boolean bubbles,
157 final boolean cancelable,
158 final Object view,
159 final int detail) {
160 initEvent(type, bubbles, cancelable);
161
162 setDetail(detail);
163 }
164
165
166
167
168
169 @JsxGetter
170 public int getWhich() {
171 return 0;
172 }
173 }