superchris-rubyjs 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. data/README +131 -0
  2. data/Rakefile +65 -0
  3. data/bin/rubyjs +144 -0
  4. data/rubyjs.gemspec +112 -0
  5. data/src/rubyjs.rb +3 -0
  6. data/src/rubyjs/code_generator.rb +474 -0
  7. data/src/rubyjs/compiler.rb +2061 -0
  8. data/src/rubyjs/debug_name_generator.rb +95 -0
  9. data/src/rubyjs/encoder.rb +171 -0
  10. data/src/rubyjs/eval_into.rb +59 -0
  11. data/src/rubyjs/lib/core.rb +1016 -0
  12. data/src/rubyjs/lib/dom_element.rb +66 -0
  13. data/src/rubyjs/lib/json.rb +101 -0
  14. data/src/rubyjs/lib/microunit.rb +188 -0
  15. data/src/rubyjs/model.rb +293 -0
  16. data/src/rubyjs/name_generator.rb +71 -0
  17. data/src/rwt/AbsolutePanel.rb +161 -0
  18. data/src/rwt/DOM.Konqueror.rb +89 -0
  19. data/src/rwt/DOM.Opera.rb +65 -0
  20. data/src/rwt/DOM.rb +1044 -0
  21. data/src/rwt/Event.Opera.rb +35 -0
  22. data/src/rwt/Event.rb +429 -0
  23. data/src/rwt/HTTPRequest.IE6.rb +5 -0
  24. data/src/rwt/HTTPRequest.rb +74 -0
  25. data/src/rwt/Label.rb +164 -0
  26. data/src/rwt/Panel.rb +90 -0
  27. data/src/rwt/RootPanel.rb +16 -0
  28. data/src/rwt/UIObject.rb +495 -0
  29. data/src/rwt/Widget.rb +193 -0
  30. data/src/rwt/ported-from/AbsolutePanel.java +158 -0
  31. data/src/rwt/ported-from/DOM.java +571 -0
  32. data/src/rwt/ported-from/DOMImpl.java +426 -0
  33. data/src/rwt/ported-from/DOMImplOpera.java +82 -0
  34. data/src/rwt/ported-from/DOMImplStandard.java +234 -0
  35. data/src/rwt/ported-from/HTTPRequest.java +81 -0
  36. data/src/rwt/ported-from/HTTPRequestImpl.java +103 -0
  37. data/src/rwt/ported-from/Label.java +163 -0
  38. data/src/rwt/ported-from/Panel.java +99 -0
  39. data/src/rwt/ported-from/UIObject.java +614 -0
  40. data/src/rwt/ported-from/Widget.java +221 -0
  41. data/test/benchmark/bm_vm1_block.rb +15 -0
  42. data/test/benchmark/bm_vm1_const.rb +13 -0
  43. data/test/benchmark/bm_vm1_ensure.rb +15 -0
  44. data/test/benchmark/common.rb +5 -0
  45. data/test/benchmark/params.yaml +7 -0
  46. data/test/common.Browser.rb +13 -0
  47. data/test/common.rb +8 -0
  48. data/test/gen_browser_test_suite.rb +129 -0
  49. data/test/gen_test_suite.rb +41 -0
  50. data/test/run_benchs.rb +58 -0
  51. data/test/run_tests.rb +22 -0
  52. data/test/test_args.rb +24 -0
  53. data/test/test_array.rb +22 -0
  54. data/test/test_case.rb +35 -0
  55. data/test/test_class.rb +55 -0
  56. data/test/test_eql.rb +9 -0
  57. data/test/test_exception.rb +61 -0
  58. data/test/test_expr.rb +12 -0
  59. data/test/test_hash.rb +29 -0
  60. data/test/test_hot_ruby.rb +146 -0
  61. data/test/test_if.rb +28 -0
  62. data/test/test_insertion_sort.rb +25 -0
  63. data/test/test_inspect.rb +10 -0
  64. data/test/test_lebewesen.rb +39 -0
  65. data/test/test_massign.rb +66 -0
  66. data/test/test_new.rb +12 -0
  67. data/test/test_range.rb +70 -0
  68. data/test/test_regexp.rb +22 -0
  69. data/test/test_send.rb +65 -0
  70. data/test/test_simple_output.rb +5 -0
  71. data/test/test_splat.rb +21 -0
  72. data/test/test_string.rb +51 -0
  73. data/test/test_test.rb +17 -0
  74. data/test/test_yield.rb +154 -0
  75. data/utils/js/Makefile +9 -0
  76. data/utils/js/RunScript.class +0 -0
  77. data/utils/js/RunScript.java +73 -0
  78. data/utils/js/js.jar +0 -0
  79. data/utils/js/run.sh +3 -0
  80. data/utils/jsc/Makefile +7 -0
  81. data/utils/jsc/README +3 -0
  82. data/utils/jsc/RunScript.c +93 -0
  83. data/utils/jsc/run.sh +15 -0
  84. data/utils/yuicompressor/README +1 -0
  85. data/utils/yuicompressor/yuicompressor-2.2.5.jar +0 -0
  86. metadata +157 -0
@@ -0,0 +1,193 @@
1
+ #--
2
+ # Copyright (c) 2007 by Michael Neumann (mneumann@ntecs.de)
3
+ #
4
+ # Copyright 2007 Google Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
+ # use this file except in compliance with the License. You may obtain a copy of
8
+ # the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ # License for the specific language governing permissions and limitations under
16
+ # the License.
17
+ #++
18
+
19
+ #
20
+ # The base class for the majority of user-interface objects. Widget adds
21
+ # support for receiving events from the browser and being added directly to
22
+ # panels (class +Panel+).
23
+ #
24
+ class Widget < UIObject
25
+
26
+ #
27
+ # Gets this widget's parent panel.
28
+ #
29
+ # return:: the widget's parent panel
30
+ #
31
+ def getParent
32
+ @parent
33
+ end
34
+
35
+ #
36
+ # Sets this widget's parent. This method should only be called by
37
+ # +Panel+ and +Composite+.
38
+ #
39
+ # parent:: the widget's new parent
40
+ #
41
+ def setParent(parent)
42
+ oldParent = @parent
43
+ @parent = parent
44
+
45
+ if parent.nil?
46
+ # Remove from parent
47
+ onDetach() if oldParent and oldParent.isAttached
48
+ elsif parent.isAttached
49
+ onAttach()
50
+ end
51
+ end
52
+
53
+ #
54
+ # Determines whether this widget is currently attached to the browser's
55
+ # document (i.e., there is an unbroken chain of widgets between this widget
56
+ # and the underlying browser document).
57
+ #
58
+ # return:: +true+ if the widget is attached
59
+ #
60
+ def isAttached
61
+ @attached
62
+ end
63
+
64
+ #
65
+ # Sets this object's browser element. Widget subclasses must call this method
66
+ # before attempting to call any other methods.
67
+ #
68
+ # If a browser element has already been attached, then it is replaced with
69
+ # the new element. The old event listeners are removed from the old browser
70
+ # element, and the event listeners are set up on the new browser element.
71
+ #
72
+ # elem:: the object's new element
73
+ #
74
+ def setElement(elem)
75
+ if @attached
76
+ # Remove old event listener to avoid leaking. onDetach will not do this
77
+ # for us, because it is only called when the widget itself is detached from
78
+ # the document.
79
+ DOM.removeEventListener(getElement())
80
+ end
81
+
82
+ super(elem)
83
+
84
+ if @attached
85
+ # Hook the event listener back up on the new element. onAttach will not
86
+ # do this for us, because it is only called when the widget itself is
87
+ # attached to the document.
88
+ DOM.setEventListener(elem, self)
89
+ end
90
+ end
91
+
92
+ #
93
+ # Removes this widget from its parent widget. If it has no parent, this
94
+ # method does nothing.
95
+ #
96
+ def removeFromParent
97
+ @parent.remove(self) if @parent
98
+ end
99
+
100
+ #-------------------------------------------------------------------
101
+ # Event handlers
102
+ #-------------------------------------------------------------------
103
+
104
+ def onBrowserEvent(event)
105
+ end
106
+
107
+ #
108
+ # This method is called when a widget is attached to the browser's document.
109
+ # To receive notification after a Widget has been added to the
110
+ # document, override the +onLoad+ method.
111
+ #
112
+ # Subclasses that override this method must call <tt>super()</tt> to ensure
113
+ # that the Widget has been attached to the underlying Element.
114
+ #
115
+ def onAttach
116
+ raise "already attached" if @attached
117
+
118
+ @attached = true
119
+
120
+ # Set the main element's event listener. This should only be set
121
+ # while the widget is attached, because it creates a circular
122
+ # reference between JavaScript and the DOM.
123
+ DOM.setEventListener(getElement(), self)
124
+
125
+ # Now that the widget is attached, call onLoad().
126
+ onLoad()
127
+ end
128
+
129
+ #
130
+ # This method is called when a widget is detached from the browser's
131
+ # document. To receive notification before a Widget is removed from the
132
+ # document, override the +onUnload+ method.
133
+ #
134
+ # Subclasses that override this method must call <tt>super()</tt>
135
+ # to ensure that the Widget has been detached from the underlying Element.
136
+ # Failure to do so will result in application memory leaks due to circular
137
+ # references between DOM Elements and JavaScript objects.
138
+ #
139
+ def onDetach
140
+ raise "cannot detached unattached widget" unless @attached
141
+
142
+ # Give the user a chance to clean up, but don't trust the code to not throw
143
+ # TODO: begin onUnload ensure xxx end
144
+ onUnload()
145
+ @attached = false
146
+
147
+ # Clear out the element's event listener (breaking the circular
148
+ # reference between it and the widget).
149
+ DOM.removeEventListener(getElement())
150
+ end
151
+
152
+ #
153
+ # This method is called immediately after a widget becomes attached to the
154
+ # browser's document.
155
+ #
156
+ def onLoad
157
+ end
158
+
159
+ #
160
+ # This method is called immediately before a widget will be detached from the
161
+ # browser's document.
162
+ #
163
+ def onUnload
164
+ end
165
+
166
+ #-------------------------------------------------------------------
167
+ # Layout data
168
+ #-------------------------------------------------------------------
169
+
170
+ #
171
+ # Gets the panel-defined layout data associated with this widget.
172
+ #
173
+ # return:: the widget's layout data
174
+ #
175
+ # See #setLayoutData.
176
+ #
177
+ def getLayoutData
178
+ @layoutData
179
+ end
180
+
181
+ #
182
+ # Sets the panel-defined layout data associated with this widget. Only the
183
+ # panel that currently contains a widget should ever set this value. It
184
+ # serves as a place to store layout bookkeeping data associated with a
185
+ # widget.
186
+ #
187
+ # layoutData:: the widget's layout data
188
+ #
189
+ def setLayoutData(layoutData)
190
+ @layoutData = layoutData
191
+ end
192
+
193
+ end # class Widget
@@ -0,0 +1,158 @@
1
+ /*
2
+ * Copyright 2007 Google Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ * use this file except in compliance with the License. You may obtain a copy of
6
+ * the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ * License for the specific language governing permissions and limitations under
14
+ * the License.
15
+ */
16
+ package com.google.gwt.user.client.ui;
17
+
18
+ import com.google.gwt.user.client.DOM;
19
+ import com.google.gwt.user.client.Element;
20
+
21
+ /**
22
+ * An absolute panel positions all of its children absolutely, allowing them to
23
+ * overlap.
24
+ *
25
+ * <p>
26
+ * Note that this panel will not automatically resize itself to allow enough
27
+ * room for its absolutely-positioned children. It must be explicitly sized in
28
+ * order to make room for them.
29
+ * </p>
30
+ *
31
+ * <p>
32
+ * Once a widget has been added to an absolute panel, the panel effectively
33
+ * "owns" the positioning of the widget. Any existing positioning attributes
34
+ * on the widget may be modified by the panel.
35
+ * </p>
36
+ */
37
+ public class AbsolutePanel extends ComplexPanel {
38
+
39
+ /**
40
+ * Changes a DOM element's positioning to static.
41
+ *
42
+ * @param elem the DOM element
43
+ */
44
+ private static void changeToStaticPositioning(Element elem) {
45
+ DOM.setStyleAttribute(elem, "left", "");
46
+ DOM.setStyleAttribute(elem, "top", "");
47
+ DOM.setStyleAttribute(elem, "position", "static");
48
+ }
49
+
50
+ /**
51
+ * Creates an empty absolute panel.
52
+ */
53
+ public AbsolutePanel() {
54
+ setElement(DOM.createDiv());
55
+
56
+ // Setting the panel's position style to 'relative' causes it to be treated
57
+ // as a new positioning context for its children.
58
+ DOM.setStyleAttribute(getElement(), "position", "relative");
59
+ DOM.setStyleAttribute(getElement(), "overflow", "hidden");
60
+ }
61
+
62
+ /**
63
+ * Adds a child widget to this panel.
64
+ *
65
+ * @param w the child widget to be added
66
+ */
67
+ public void add(Widget w) {
68
+ super.add(w, getElement());
69
+ }
70
+
71
+ /**
72
+ * Adds a widget to the panel at the specified position. Setting a position
73
+ * of <code>(-1, -1)</code> will cause the child widget to be positioned
74
+ * statically.
75
+ *
76
+ * @param w the widget to be added
77
+ * @param left the widget's left position
78
+ * @param top the widget's top position
79
+ */
80
+ public void add(Widget w, int left, int top) {
81
+ // In order to avoid the potential for a flicker effect, it is necessary
82
+ // to set the position of the widget before adding it to the AbsolutePanel.
83
+ // The Widget should be removed from its parent before any positional
84
+ // changes are made to prevent flickering.
85
+ w.removeFromParent();
86
+ setWidgetPositionImpl(w, left, top);
87
+ add(w);
88
+ }
89
+
90
+ /**
91
+ * Gets the position of the left outer border edge of the widget relative to
92
+ * the left outer border edge of the panel.
93
+ *
94
+ * @param w the widget whose position is to be retrieved
95
+ * @return the widget's left position
96
+ */
97
+ public int getWidgetLeft(Widget w) {
98
+ checkWidgetParent(w);
99
+ return DOM.getAbsoluteLeft(w.getElement()) - DOM.getAbsoluteLeft(getElement());
100
+ }
101
+
102
+ /**
103
+ * Gets the position of the top outer border edge of the widget relative to
104
+ * the top outer border edge of the panel.
105
+ *
106
+ * @param w the widget whose position is to be retrieved
107
+ * @return the widget's top position
108
+ */
109
+ public int getWidgetTop(Widget w) {
110
+ checkWidgetParent(w);
111
+ return DOM.getAbsoluteTop(w.getElement()) - DOM.getAbsoluteTop(getElement());
112
+ }
113
+
114
+ /**
115
+ * Sets the position of the specified child widget. Setting a position of
116
+ * <code>(-1, -1)</code> will cause the child widget to be positioned
117
+ * statically.
118
+ *
119
+ * @param w the child widget to be positioned
120
+ * @param left the widget's left position
121
+ * @param top the widget's top position
122
+ */
123
+ public void setWidgetPosition(Widget w, int left, int top) {
124
+ checkWidgetParent(w);
125
+ setWidgetPositionImpl(w, left, top);
126
+ }
127
+
128
+ /**
129
+ * Calls the superclass' <code>disown(Widget)</code> method, and sets the
130
+ * the positioning of the widget to static. This is done so that any
131
+ * positioning changes to the widget that were done by the panel are undone
132
+ * when the widget is disowned from the panel.
133
+ *
134
+ * @param w the widget to be disowned
135
+ */
136
+ protected void disown(Widget w) {
137
+ super.disown(w);
138
+ changeToStaticPositioning(w.getElement());
139
+ }
140
+
141
+ private void checkWidgetParent(Widget w) {
142
+ if (w.getParent() != this) {
143
+ throw new IllegalArgumentException(
144
+ "Widget must be a child of this panel.");
145
+ }
146
+ }
147
+
148
+ private void setWidgetPositionImpl(Widget w, int left, int top) {
149
+ Element h = w.getElement();
150
+ if ((left == -1) && (top == -1)) {
151
+ changeToStaticPositioning(h);
152
+ } else {
153
+ DOM.setStyleAttribute(h, "position", "absolute");
154
+ DOM.setStyleAttribute(h, "left", left + "px");
155
+ DOM.setStyleAttribute(h, "top", top + "px");
156
+ }
157
+ }
158
+ }
@@ -0,0 +1,571 @@
1
+ /*
2
+ * Copyright 2007 Google Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ * use this file except in compliance with the License. You may obtain a copy of
6
+ * the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ * License for the specific language governing permissions and limitations under
14
+ * the License.
15
+ */
16
+ package com.google.gwt.user.client;
17
+
18
+ import com.google.gwt.core.client.GWT;
19
+ import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
20
+ import com.google.gwt.user.client.impl.DOMImpl;
21
+
22
+ import java.util.ArrayList;
23
+
24
+ /**
25
+ * This class provides a set of static methods that allow you to manipulate the
26
+ * browser's Document Object Model (DOM). It contains methods for manipulating
27
+ * both {@link com.google.gwt.user.client.Element elements} and
28
+ * {@link com.google.gwt.user.client.Event events}.
29
+ */
30
+ public class DOM {
31
+
32
+ // The current event being fired
33
+ private static Event currentEvent = null;
34
+ private static DOMImpl impl;
35
+ private static Element sCaptureElem;
36
+
37
+ //<BrowserEventPreview>
38
+ private static ArrayList sEventPreviewStack = new ArrayList();
39
+
40
+ static {
41
+ impl = (DOMImpl) GWT.create(DOMImpl.class);
42
+ impl.init();
43
+ }
44
+
45
+ /**
46
+ * Adds an event preview to the preview stack. As long as this preview remains
47
+ * on the top of the stack, it will receive all events before they are fired
48
+ * to their listeners. Note that the event preview will receive <u>all </u>
49
+ * events, including those received due to bubbling, whereas normal event
50
+ * handlers only receive explicitly sunk events.
51
+ *
52
+ * @param preview the event preview to be added to the stack.
53
+ */
54
+ public static void addEventPreview(EventPreview preview) {
55
+ // Add the event preview to the stack. It will automatically
56
+ // begin receiving events.
57
+ sEventPreviewStack.add(preview);
58
+ }
59
+
60
+ /**
61
+ * Cancels bubbling for the given event. This will stop the event from being
62
+ * propagated to parent elements.
63
+ *
64
+ * @param evt the event on which to cancel bubbling
65
+ * @param cancel <code>true</code> to cancel bubbling
66
+ */
67
+ public static void eventCancelBubble(Event evt, boolean cancel) {
68
+ impl.eventCancelBubble(evt, cancel);
69
+ }
70
+
71
+ /**
72
+ * Gets whether the ALT key was depressed when the given event occurred.
73
+ *
74
+ * @param evt the event to be tested
75
+ * @return <code>true</code> if ALT was depressed when the event occurred
76
+ */
77
+ public static boolean eventGetAltKey(Event evt) {
78
+ return impl.eventGetAltKey(evt);
79
+ }
80
+
81
+ /**
82
+ * Gets the mouse buttons that were depressed when the given event occurred.
83
+ *
84
+ * @param evt the event to be tested
85
+ * @return a bit-field, defined by {@link Event#BUTTON_LEFT},
86
+ * {@link Event#BUTTON_MIDDLE}, and {@link Event#BUTTON_RIGHT}
87
+ */
88
+ public static int eventGetButton(Event evt) {
89
+ return impl.eventGetButton(evt);
90
+ }
91
+
92
+ /**
93
+ * Gets the mouse x-position within the browser window's client area.
94
+ *
95
+ * @param evt the event to be tested
96
+ * @return the mouse x-position
97
+ */
98
+ public static int eventGetClientX(Event evt) {
99
+ return impl.eventGetClientX(evt);
100
+ }
101
+
102
+ /**
103
+ * Gets the mouse y-position within the browser window's client area.
104
+ *
105
+ * @param evt the event to be tested
106
+ * @return the mouse y-position
107
+ */
108
+ public static int eventGetClientY(Event evt) {
109
+ return impl.eventGetClientY(evt);
110
+ }
111
+
112
+ /**
113
+ * Gets whether the CTRL key was depressed when the given event occurred.
114
+ *
115
+ * @param evt the event to be tested
116
+ * @return <code>true</code> if CTRL was depressed when the event occurred
117
+ */
118
+ public static boolean eventGetCtrlKey(Event evt) {
119
+ return impl.eventGetCtrlKey(evt);
120
+ }
121
+
122
+ /**
123
+ * Gets the current event that is being fired. The current event
124
+ * is only available within the lifetime of the onBrowserEvent function.
125
+ * Once the onBrowserEvent method returns, the current event is reset
126
+ * to null.
127
+ *
128
+ * @return the current event
129
+ */
130
+ public static Event eventGetCurrentEvent() {
131
+ return currentEvent;
132
+ }
133
+
134
+ /**
135
+ * Gets the current target element of the given event. This is the element
136
+ * whose listener fired last, not the element which fired the event
137
+ * initially.
138
+ *
139
+ * @param evt the event
140
+ * @return the event's current target element
141
+ * @see DOM#eventGetTarget(Event)
142
+ */
143
+ public static Element eventGetCurrentTarget(Event evt) {
144
+ return impl.eventGetCurrentTarget(evt);
145
+ }
146
+
147
+ /**
148
+ * Gets the element from which the mouse pointer was moved (only valid for
149
+ * {@link Event#ONMOUSEOVER}).
150
+ *
151
+ * @param evt the event to be tested
152
+ * @return the element from which the mouse pointer was moved
153
+ */
154
+ public static Element eventGetFromElement(Event evt) {
155
+ return impl.eventGetFromElement(evt);
156
+ }
157
+
158
+ /**
159
+ * Gets the key code associated with this event.
160
+ *
161
+ * <p>
162
+ * For {@link Event#ONKEYPRESS}, this method returns the Unicode value of the
163
+ * character generated. For {@link Event#ONKEYDOWN} and {@link Event#ONKEYUP},
164
+ * it returns the code associated with the physical key.
165
+ * </p>
166
+ *
167
+ * @param evt the event to be tested
168
+ * @return the Unicode character or key code.
169
+ * @see com.google.gwt.user.client.ui.KeyboardListener
170
+ */
171
+ public static int eventGetKeyCode(Event evt) {
172
+ return impl.eventGetKeyCode(evt);
173
+ }
174
+
175
+ /**
176
+ * Gets whether the META key was depressed when the given event occurred.
177
+ *
178
+ * @param evt the event to be tested
179
+ * @return <code>true</code> if META was depressed when the event occurred
180
+ */
181
+ public static boolean eventGetMetaKey(Event evt) {
182
+ return impl.eventGetMetaKey(evt);
183
+ }
184
+
185
+ /**
186
+ * Gets the velocity of the mouse wheel associated with the event along the
187
+ * Y axis.
188
+ * <p>
189
+ * The velocity of the event is an artifical measurement for relative
190
+ * comparisons of wheel activity. It is affected by some non-browser
191
+ * factors, including choice of input hardware and mouse acceleration
192
+ * settings. The sign of the velocity measurement agrees with the screen
193
+ * coordinate system; negative values are towards the origin and positive
194
+ * values are away from the origin. Standard scrolling speed is approximately
195
+ * ten units per event.
196
+ * </p>
197
+ *
198
+ * @param evt the event to be examined.
199
+ * @return The velocity of the mouse wheel.
200
+ */
201
+ public static int eventGetMouseWheelVelocityY(Event evt) {
202
+ return impl.eventGetMouseWheelVelocityY(evt);
203
+ }
204
+
205
+ /**
206
+ * Gets the key-repeat state of this event.
207
+ *
208
+ * @param evt the event to be tested
209
+ * @return <code>true</code> if this key event was an auto-repeat
210
+ */
211
+ public static boolean eventGetRepeat(Event evt) {
212
+ return impl.eventGetRepeat(evt);
213
+ }
214
+
215
+ /**
216
+ * Gets the mouse x-position on the user's display.
217
+ *
218
+ * @param evt the event to be tested
219
+ * @return the mouse x-position
220
+ */
221
+ public static int eventGetScreenX(Event evt) {
222
+ return impl.eventGetScreenX(evt);
223
+ }
224
+
225
+ /**
226
+ * Gets the mouse y-position on the user's display.
227
+ *
228
+ * @param evt the event to be tested
229
+ * @return the mouse y-position
230
+ */
231
+ public static int eventGetScreenY(Event evt) {
232
+ return impl.eventGetScreenY(evt);
233
+ }
234
+
235
+ /**
236
+ * Gets whether the shift key was depressed when the given event occurred.
237
+ *
238
+ * @param evt the event to be tested
239
+ * @return <code>true</code> if shift was depressed when the event occurred
240
+ */
241
+ public static boolean eventGetShiftKey(Event evt) {
242
+ return impl.eventGetShiftKey(evt);
243
+ }
244
+
245
+ /**
246
+ * Returns the element that was the actual target of the given event.
247
+ *
248
+ * @param evt the event to be tested
249
+ * @return the target element
250
+ */
251
+ public static Element eventGetTarget(Event evt) {
252
+ return impl.eventGetTarget(evt);
253
+ }
254
+
255
+ /**
256
+ * Gets the element to which the mouse pointer was moved (only valid for
257
+ * {@link Event#ONMOUSEOUT}).
258
+ *
259
+ * @param evt the event to be tested
260
+ * @return the element to which the mouse pointer was moved
261
+ */
262
+ public static Element eventGetToElement(Event evt) {
263
+ return impl.eventGetToElement(evt);
264
+ }
265
+
266
+ /**
267
+ * Gets the enumerated type of this event (as defined in {@link Event}).
268
+ *
269
+ * @param evt the event to be tested
270
+ * @return the event's enumerated type
271
+ */
272
+ public static int eventGetType(Event evt) {
273
+ return impl.eventGetTypeInt(evt);
274
+ }
275
+
276
+ /**
277
+ * Gets the type of the given event as a string.
278
+ *
279
+ * @param evt the event to be tested
280
+ * @return the event's type name
281
+ */
282
+ public static String eventGetTypeString(Event evt) {
283
+ return impl.eventGetType(evt);
284
+ }
285
+
286
+ /**
287
+ * Prevents the browser from taking its default action for the given event.
288
+ *
289
+ * @param evt the event whose default action is to be prevented
290
+ */
291
+ public static void eventPreventDefault(Event evt) {
292
+ impl.eventPreventDefault(evt);
293
+ }
294
+
295
+ /**
296
+ * Sets the key code associated with the given keyboard event.
297
+ *
298
+ * @param evt the event whose key code is to be set
299
+ * @param key the new key code
300
+ */
301
+ public static void eventSetKeyCode(Event evt, char key) {
302
+ impl.eventSetKeyCode(evt, key);
303
+ }
304
+
305
+ /**
306
+ * Returns a stringized version of the event. This string is for debugging
307
+ * purposes and will NOT be consistent on different browsers.
308
+ *
309
+ * @param evt the event to stringize
310
+ * @return a string form of the event
311
+ */
312
+ public static String eventToString(Event evt) {
313
+ return impl.eventToString(evt);
314
+ }
315
+
316
+ /**
317
+ * Gets an integer attribute on a given element.
318
+ *
319
+ * @param elem the element whose attribute is to be retrieved
320
+ * @param attr the name of the attribute to be retrieved
321
+ * @return the attribute's value as an integer
322
+ * @deprecated Use the more appropriately named
323
+ * {@link #getElementPropertyInt(Element, String)} instead.
324
+ */
325
+ public static int getIntAttribute(Element elem, String attr) {
326
+ return getElementPropertyInt(elem, attr);
327
+ }
328
+
329
+ /**
330
+ * Gets an integer attribute on a given element's style.
331
+ *
332
+ * @param elem the element whose style attribute is to be retrieved
333
+ * @param attr the name of the attribute to be retrieved
334
+ * @return the style attribute's value as an integer
335
+ */
336
+ public static int getIntStyleAttribute(Element elem, String attr) {
337
+ return impl.getIntStyleAttribute(elem, attr);
338
+ }
339
+
340
+ /**
341
+ * Creates an <code>&lt;option&gt;</code> element and inserts it as a child
342
+ * of the specified <code>&lt;select&gt;</code> element. If the index is
343
+ * less than zero, or greater than or equal to the length of the list, then
344
+ * the option element will be appended to the end of the list.
345
+ *
346
+ * @param select the <code>&lt;select&gt;</code> element
347
+ * @param item the text of the new item; cannot be <code>null</code>
348
+ * @param value the <code>value</code> attribute for the new
349
+ * <code>&lt;option&gt;</code>; cannot be <code>null</code>
350
+ * @param index the index at which to insert the child
351
+ */
352
+ public static void insertListItem(Element select, String item, String value,
353
+ int index) {
354
+ impl.insertListItem(select, item, value, index);
355
+ }
356
+
357
+ /**
358
+ * Releases mouse capture on the given element. Calling this method has no
359
+ * effect if the element does not currently have mouse capture.
360
+ *
361
+ * @param elem the element to release capture
362
+ * @see #setCapture(Element)
363
+ */
364
+ public static void releaseCapture(Element elem) {
365
+ if ((sCaptureElem != null) && compare(elem, sCaptureElem)) {
366
+ sCaptureElem = null;
367
+ }
368
+ impl.releaseCapture(elem);
369
+ }
370
+
371
+ /**
372
+ * Removes an element from the preview stack. This element will no longer
373
+ * capture events, though any preview underneath it will begin to do so.
374
+ *
375
+ * @param preview the event preview to be removed from the stack
376
+ */
377
+ public static void removeEventPreview(EventPreview preview) {
378
+ // Remove the event preview from the stack. If it was on top,
379
+ // any preview underneath it will automatically begin to
380
+ // receive events.
381
+ sEventPreviewStack.remove(preview);
382
+ }
383
+
384
+ /**
385
+ * Scrolls the given element into view.
386
+ *
387
+ * <p>
388
+ * This method crawls up the DOM hierarchy, adjusting the scrollLeft and
389
+ * scrollTop properties of each scrollable element to ensure that the
390
+ * specified element is completely in view. It adjusts each scroll position by
391
+ * the minimum amount necessary.
392
+ * </p>
393
+ *
394
+ * @param elem the element to be made visible
395
+ */
396
+ public static void scrollIntoView(Element elem) {
397
+ impl.scrollIntoView(elem);
398
+ }
399
+
400
+ }
401
+
402
+ /**
403
+ * Sets mouse-capture on the given element. This element will directly receive
404
+ * all mouse events until {@link #releaseCapture(Element)} is called on it.
405
+ *
406
+ * @param elem the element on which to set mouse capture
407
+ */
408
+ public static void setCapture(Element elem) {
409
+ sCaptureElem = elem;
410
+ impl.setCapture(elem);
411
+ }
412
+
413
+
414
+
415
+ /**
416
+ * Sets the src attribute of an img element. This method ensures that imgs
417
+ * only ever have their contents requested one single time from the server.
418
+ *
419
+ * @param img a non-null img whose src attribute will be set.
420
+ * @param src a non-null url for the img
421
+ */
422
+ public static void setImgSrc(Element img, String src) {
423
+ impl.setImgSrc(img, src);
424
+ }
425
+
426
+ /**
427
+ * Sets the HTML contained within an element.
428
+ *
429
+ * @param elem the element whose inner HTML is to be set
430
+ * @param html the new html
431
+ */
432
+ public static void setInnerHTML(Element elem, String html) {
433
+ impl.setInnerHTML(elem, html);
434
+ }
435
+
436
+ /**
437
+ * Sets the text contained within an element. If the element already has
438
+ * children, they will be destroyed.
439
+ *
440
+ * @param elem the element whose inner text is to be set
441
+ * @param text the new text
442
+ */
443
+ public static void setInnerText(Element elem, String text) {
444
+ impl.setInnerText(elem, text);
445
+ }
446
+
447
+ /**
448
+ * Sets an integer attribute on the given element's style.
449
+ *
450
+ * @param elem the element whose style attribute is to be set
451
+ * @param attr the name of the style attribute to be set
452
+ * @param value the style attribute's new integer value
453
+ */
454
+ public static void setIntStyleAttribute(Element elem, String attr,
455
+ int value) {
456
+ impl.setIntStyleAttribute(elem, attr, value);
457
+ }
458
+
459
+ /**
460
+ * Sets the option text of the given select object.
461
+ *
462
+ * @param select the select object whose option text is being set
463
+ * @param text the text to set
464
+ * @param index the index of the option whose text should be set
465
+ */
466
+ public static void setOptionText(Element select, String text, int index) {
467
+ impl.setOptionText(select, text, index);
468
+ }
469
+
470
+ /**
471
+ * Returns a stringized version of the element. This string is for debugging
472
+ * purposes and will NOT be consistent on different browsers.
473
+ *
474
+ * @param elem the element to stringize
475
+ * @return a string form of the element
476
+ */
477
+ public static String toString(Element elem) {
478
+ return impl.toString(elem);
479
+ }
480
+
481
+ /**
482
+ * Gets the height of the browser window's client area excluding the
483
+ * scroll bar.
484
+ *
485
+ * @return the window's client height
486
+ */
487
+ public static int windowGetClientHeight() {
488
+ return impl.windowGetClientHeight();
489
+ }
490
+
491
+ /**
492
+ * Gets the width of the browser window's client area excluding the
493
+ * vertical scroll bar.
494
+ *
495
+ * @return the window's client width
496
+ */
497
+ public static int windowGetClientWidth() {
498
+ return impl.windowGetClientWidth();
499
+ }
500
+
501
+ /**
502
+ * This method is called directly by native code when any event is fired.
503
+ *
504
+ * @param evt the handle to the event being fired.
505
+ * @param elem the handle to the element that received the event.
506
+ * @param listener the listener associated with the element that received the
507
+ * event.
508
+ */
509
+ static void dispatchEvent(Event evt, Element elem, EventListener listener) {
510
+ UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler();
511
+ if (handler != null) {
512
+ dispatchEventAndCatch(evt, elem, listener, handler);
513
+ } else {
514
+ dispatchEventImpl(evt, elem, listener);
515
+ }
516
+ }
517
+
518
+ /**
519
+ * This method is called directly by native code when event preview is being
520
+ * used.
521
+ *
522
+ * @param evt a handle to the event being previewed
523
+ * @return <code>false</code> to cancel the event
524
+ */
525
+ static boolean previewEvent(Event evt) {
526
+ // If event previews are present, redirect events to the topmost of them.
527
+ boolean ret = true;
528
+ if (sEventPreviewStack.size() > 0) {
529
+ EventPreview preview =
530
+ (EventPreview) sEventPreviewStack.get(sEventPreviewStack.size() - 1);
531
+ if (!(ret = preview.onEventPreview(evt))) {
532
+ // If the preview cancels the event, stop it from bubbling and
533
+ // performing its default action.
534
+ eventCancelBubble(evt, true);
535
+ eventPreventDefault(evt);
536
+ }
537
+ }
538
+
539
+ return ret;
540
+ }
541
+
542
+ private static void dispatchEventAndCatch(Event evt, Element elem,
543
+ EventListener listener, UncaughtExceptionHandler handler) {
544
+ try {
545
+ dispatchEventImpl(evt, elem, listener);
546
+ } catch (Throwable e) {
547
+ handler.onUncaughtException(e);
548
+ }
549
+ }
550
+
551
+ private static void dispatchEventImpl(Event evt, Element elem,
552
+ EventListener listener) {
553
+ // If this element has capture...
554
+ if (elem == sCaptureElem) {
555
+ // ... and it's losing capture, clear sCaptureElem.
556
+ if (eventGetType(evt) == Event.ONLOSECAPTURE) {
557
+ sCaptureElem = null;
558
+ }
559
+ }
560
+
561
+ // Preserve the current event in case we are in a reentrant event dispatch.
562
+ Event prevCurrentEvent = currentEvent;
563
+ currentEvent = evt;
564
+ try {
565
+ // Pass the event to the listener.
566
+ listener.onBrowserEvent(evt);
567
+ } finally {
568
+ currentEvent = prevCurrentEvent;
569
+ }
570
+ }
571
+ }