rubyjs 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +128 -0
- data/Rakefile +9 -0
- data/bin/rubyjs +140 -0
- data/examples/ex1/Rakefile +7 -0
- data/examples/ex1/ex1.js +771 -0
- data/examples/ex1/ex1.rb +42 -0
- data/examples/ex1/index.html +7 -0
- data/examples/hw/Rakefile +9 -0
- data/examples/hw/hw.js +635 -0
- data/examples/hw/hw.rb +7 -0
- data/examples/hw/index.html +7 -0
- data/patches/parse_tree.rb.diff +34 -0
- data/rubyjs.gemspec +24 -0
- data/src/rubyjs.rb +4 -0
- data/src/rubyjs/code_generator.rb +474 -0
- data/src/rubyjs/compiler.rb +2007 -0
- data/src/rubyjs/debug_name_generator.rb +75 -0
- data/src/rubyjs/encoder.rb +171 -0
- data/src/rubyjs/eval_into.rb +59 -0
- data/src/rubyjs/lib/core.rb +1008 -0
- data/src/rubyjs/lib/json.rb +101 -0
- data/src/rubyjs/model.rb +287 -0
- data/src/rubyjs/name_generator.rb +71 -0
- data/src/rwt/AbsolutePanel.rb +161 -0
- data/src/rwt/DOM.Konqueror.rb +89 -0
- data/src/rwt/DOM.Opera.rb +65 -0
- data/src/rwt/DOM.rb +1044 -0
- data/src/rwt/Event.Opera.rb +35 -0
- data/src/rwt/Event.rb +429 -0
- data/src/rwt/HTTPRequest.IE6.rb +5 -0
- data/src/rwt/HTTPRequest.rb +74 -0
- data/src/rwt/Label.rb +164 -0
- data/src/rwt/Panel.rb +90 -0
- data/src/rwt/RootPanel.rb +16 -0
- data/src/rwt/UIObject.rb +495 -0
- data/src/rwt/Widget.rb +193 -0
- data/src/rwt/ported-from/AbsolutePanel.java +158 -0
- data/src/rwt/ported-from/DOM.java +571 -0
- data/src/rwt/ported-from/DOMImpl.java +426 -0
- data/src/rwt/ported-from/DOMImplOpera.java +82 -0
- data/src/rwt/ported-from/DOMImplStandard.java +234 -0
- data/src/rwt/ported-from/HTTPRequest.java +81 -0
- data/src/rwt/ported-from/HTTPRequestImpl.java +103 -0
- data/src/rwt/ported-from/Label.java +163 -0
- data/src/rwt/ported-from/Panel.java +99 -0
- data/src/rwt/ported-from/UIObject.java +614 -0
- data/src/rwt/ported-from/Widget.java +221 -0
- data/test/benchmark/bm_call_conv1.js +16 -0
- data/test/benchmark/bm_call_conv2.js +14 -0
- data/test/benchmark/bm_var_acc1.js +13 -0
- data/test/benchmark/bm_var_acc2.js +11 -0
- data/test/benchmark/bm_vm1_block.js +15 -0
- data/test/benchmark/bm_vm1_block.rb +15 -0
- data/test/benchmark/bm_vm1_const.js +13 -0
- data/test/benchmark/bm_vm1_const.rb +13 -0
- data/test/benchmark/bm_vm1_ensure.js +17 -0
- data/test/benchmark/bm_vm1_ensure.rb +15 -0
- data/test/benchmark/common.js +4 -0
- data/test/benchmark/common.rb +5 -0
- data/test/benchmark/params.yaml +7 -0
- data/test/browser.test.html +4059 -0
- data/test/browser.test.js +3225 -0
- data/test/common.Browser.rb +13 -0
- data/test/common.rb +8 -0
- data/test/gen_browser_test_suite.rb +129 -0
- data/test/gen_test_suite.rb +41 -0
- data/test/run_benchs.rb +58 -0
- data/test/run_tests.rb +22 -0
- data/test/test_args.rb +24 -0
- data/test/test_array.rb +26 -0
- data/test/test_case.rb +35 -0
- data/test/test_class.rb +55 -0
- data/test/test_eql.rb +9 -0
- data/test/test_exception.rb +61 -0
- data/test/test_expr.rb +12 -0
- data/test/test_hash.rb +29 -0
- data/test/test_if.rb +28 -0
- data/test/test_inspect.rb +10 -0
- data/test/test_lebewesen.rb +39 -0
- data/test/test_massign.rb +66 -0
- data/test/test_new.rb +12 -0
- data/test/test_range.rb +53 -0
- data/test/test_regexp.rb +22 -0
- data/test/test_send.rb +65 -0
- data/test/test_simple_output.rb +5 -0
- data/test/test_splat.rb +21 -0
- data/test/test_string.rb +51 -0
- data/test/test_yield.rb +152 -0
- data/utils/js/Makefile +9 -0
- data/utils/js/RunScript.class +0 -0
- data/utils/js/RunScript.java +73 -0
- data/utils/js/js.jar +0 -0
- data/utils/js/run.sh +3 -0
- data/utils/jsc/Makefile +7 -0
- data/utils/jsc/README +3 -0
- data/utils/jsc/RunScript.c +93 -0
- data/utils/jsc/run.sh +15 -0
- data/utils/yuicompressor/README +1 -0
- data/utils/yuicompressor/yuicompressor-2.2.5.jar +0 -0
- data/vendor/ParseTree-1.7.1-patched/History.txt +217 -0
- data/vendor/ParseTree-1.7.1-patched/Manifest.txt +22 -0
- data/vendor/ParseTree-1.7.1-patched/README.txt +110 -0
- data/vendor/ParseTree-1.7.1-patched/Rakefile +41 -0
- data/vendor/ParseTree-1.7.1-patched/bin/parse_tree_abc +89 -0
- data/vendor/ParseTree-1.7.1-patched/bin/parse_tree_audit +28 -0
- data/vendor/ParseTree-1.7.1-patched/bin/parse_tree_deps +62 -0
- data/vendor/ParseTree-1.7.1-patched/bin/parse_tree_show +49 -0
- data/vendor/ParseTree-1.7.1-patched/demo/printer.rb +20 -0
- data/vendor/ParseTree-1.7.1-patched/lib/composite_sexp_processor.rb +49 -0
- data/vendor/ParseTree-1.7.1-patched/lib/parse_tree.rb +1013 -0
- data/vendor/ParseTree-1.7.1-patched/lib/sexp.rb +235 -0
- data/vendor/ParseTree-1.7.1-patched/lib/sexp_processor.rb +330 -0
- data/vendor/ParseTree-1.7.1-patched/lib/unique.rb +15 -0
- data/vendor/ParseTree-1.7.1-patched/test/pt_testcase.rb +1221 -0
- data/vendor/ParseTree-1.7.1-patched/test/something.rb +53 -0
- data/vendor/ParseTree-1.7.1-patched/test/test_all.rb +13 -0
- data/vendor/ParseTree-1.7.1-patched/test/test_composite_sexp_processor.rb +69 -0
- data/vendor/ParseTree-1.7.1-patched/test/test_parse_tree.rb +216 -0
- data/vendor/ParseTree-1.7.1-patched/test/test_sexp.rb +291 -0
- data/vendor/ParseTree-1.7.1-patched/test/test_sexp_processor.rb +244 -0
- data/vendor/ParseTree-1.7.1-patched/validate.sh +31 -0
- data/vendor/ParseTree-1.7.1/History.txt +217 -0
- data/vendor/ParseTree-1.7.1/Manifest.txt +22 -0
- data/vendor/ParseTree-1.7.1/README.txt +110 -0
- data/vendor/ParseTree-1.7.1/Rakefile +41 -0
- data/vendor/ParseTree-1.7.1/bin/parse_tree_abc +89 -0
- data/vendor/ParseTree-1.7.1/bin/parse_tree_audit +28 -0
- data/vendor/ParseTree-1.7.1/bin/parse_tree_deps +62 -0
- data/vendor/ParseTree-1.7.1/bin/parse_tree_show +49 -0
- data/vendor/ParseTree-1.7.1/demo/printer.rb +20 -0
- data/vendor/ParseTree-1.7.1/lib/composite_sexp_processor.rb +49 -0
- data/vendor/ParseTree-1.7.1/lib/parse_tree.rb +1004 -0
- data/vendor/ParseTree-1.7.1/lib/sexp.rb +235 -0
- data/vendor/ParseTree-1.7.1/lib/sexp_processor.rb +330 -0
- data/vendor/ParseTree-1.7.1/lib/unique.rb +15 -0
- data/vendor/ParseTree-1.7.1/test/pt_testcase.rb +1221 -0
- data/vendor/ParseTree-1.7.1/test/something.rb +53 -0
- data/vendor/ParseTree-1.7.1/test/test_all.rb +13 -0
- data/vendor/ParseTree-1.7.1/test/test_composite_sexp_processor.rb +69 -0
- data/vendor/ParseTree-1.7.1/test/test_parse_tree.rb +216 -0
- data/vendor/ParseTree-1.7.1/test/test_sexp.rb +291 -0
- data/vendor/ParseTree-1.7.1/test/test_sexp_processor.rb +244 -0
- data/vendor/ParseTree-1.7.1/validate.sh +31 -0
- metadata +230 -0
@@ -0,0 +1,234 @@
|
|
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.impl;
|
17
|
+
|
18
|
+
import com.google.gwt.user.client.Element;
|
19
|
+
import com.google.gwt.user.client.Event;
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Base implementation of {@link com.google.gwt.user.client.impl.DOMImpl} shared
|
23
|
+
* by those browsers that come a bit closer to supporting a common standard (ie,
|
24
|
+
* not IE).
|
25
|
+
*/
|
26
|
+
abstract class DOMImplStandard extends DOMImpl {
|
27
|
+
|
28
|
+
public native boolean compare(Element elem1, Element elem2) /*-{
|
29
|
+
return (elem1 == elem2);
|
30
|
+
}-*/;
|
31
|
+
|
32
|
+
public native Element createInputRadioElement(String name) /*-{
|
33
|
+
var elem = $doc.createElement("INPUT");
|
34
|
+
elem.type = 'radio';
|
35
|
+
elem.name = name;
|
36
|
+
return elem;
|
37
|
+
}-*/;
|
38
|
+
|
39
|
+
public native Element eventGetFromElement(Event evt) /*-{
|
40
|
+
// Standard browsers use relatedTarget rather than fromElement.
|
41
|
+
return evt.relatedTarget ? evt.relatedTarget : null;
|
42
|
+
}-*/;
|
43
|
+
|
44
|
+
public native Element eventGetTarget(Event evt) /*-{
|
45
|
+
return evt.target || null;
|
46
|
+
}-*/;
|
47
|
+
|
48
|
+
public native Element eventGetToElement(Event evt) /*-{
|
49
|
+
// Standard browsers use relatedTarget rather than toElement.
|
50
|
+
return evt.relatedTarget || null;
|
51
|
+
}-*/;
|
52
|
+
|
53
|
+
public native void eventPreventDefault(Event evt) /*-{
|
54
|
+
evt.preventDefault();
|
55
|
+
}-*/;
|
56
|
+
|
57
|
+
public native String eventToString(Event evt) /*-{
|
58
|
+
return evt.toString();
|
59
|
+
}-*/;
|
60
|
+
|
61
|
+
public native Element getChild(Element elem, int index) /*-{
|
62
|
+
var count = 0, child = elem.firstChild;
|
63
|
+
while (child) {
|
64
|
+
var next = child.nextSibling;
|
65
|
+
if (child.nodeType == 1) {
|
66
|
+
if (index == count)
|
67
|
+
return child;
|
68
|
+
++count;
|
69
|
+
}
|
70
|
+
child = next;
|
71
|
+
}
|
72
|
+
|
73
|
+
return null;
|
74
|
+
}-*/;
|
75
|
+
|
76
|
+
public native int getChildCount(Element elem) /*-{
|
77
|
+
var count = 0, child = elem.firstChild;
|
78
|
+
while (child) {
|
79
|
+
if (child.nodeType == 1)
|
80
|
+
++count;
|
81
|
+
child = child.nextSibling;
|
82
|
+
}
|
83
|
+
return count;
|
84
|
+
}-*/;
|
85
|
+
|
86
|
+
public native int getChildIndex(Element parent, Element toFind) /*-{
|
87
|
+
var count = 0, child = parent.firstChild;
|
88
|
+
while (child) {
|
89
|
+
if (child == toFind)
|
90
|
+
return count;
|
91
|
+
if (child.nodeType == 1)
|
92
|
+
++count;
|
93
|
+
child = child.nextSibling;
|
94
|
+
}
|
95
|
+
|
96
|
+
return -1;
|
97
|
+
}-*/;
|
98
|
+
|
99
|
+
public native Element getFirstChild(Element elem) /*-{
|
100
|
+
var child = elem.firstChild;
|
101
|
+
while (child && child.nodeType != 1)
|
102
|
+
child = child.nextSibling;
|
103
|
+
return child || null;
|
104
|
+
}-*/;
|
105
|
+
|
106
|
+
public native Element getNextSibling(Element elem) /*-{
|
107
|
+
var sib = elem.nextSibling;
|
108
|
+
while (sib && sib.nodeType != 1)
|
109
|
+
sib = sib.nextSibling;
|
110
|
+
return sib || null;
|
111
|
+
}-*/;
|
112
|
+
|
113
|
+
public native Element getParent(Element elem) /*-{
|
114
|
+
var parent = elem.parentNode;
|
115
|
+
if(parent == null) {
|
116
|
+
return null;
|
117
|
+
}
|
118
|
+
if (parent.nodeType != 1)
|
119
|
+
parent = null;
|
120
|
+
return parent || null;
|
121
|
+
}-*/;
|
122
|
+
|
123
|
+
public native String iframeGetSrc(Element elem) /*-{
|
124
|
+
return elem.src;
|
125
|
+
}-*/;
|
126
|
+
|
127
|
+
public native void init() /*-{
|
128
|
+
// Set up capture event dispatchers.
|
129
|
+
$wnd.__dispatchCapturedMouseEvent = function(evt) {
|
130
|
+
if ($wnd.__dispatchCapturedEvent(evt)) {
|
131
|
+
var cap = $wnd.__captureElem;
|
132
|
+
if (cap && cap.__listener) {
|
133
|
+
@com.google.gwt.user.client.DOM::dispatchEvent(Lcom/google/gwt/user/client/Event;Lcom/google/gwt/user/client/Element;Lcom/google/gwt/user/client/EventListener;)(evt, cap, cap.__listener);
|
134
|
+
evt.stopPropagation();
|
135
|
+
}
|
136
|
+
}
|
137
|
+
};
|
138
|
+
|
139
|
+
$wnd.__dispatchCapturedEvent = function(evt) {
|
140
|
+
if (!@com.google.gwt.user.client.DOM::previewEvent(Lcom/google/gwt/user/client/Event;)(evt)) {
|
141
|
+
evt.stopPropagation();
|
142
|
+
evt.preventDefault();
|
143
|
+
return false;
|
144
|
+
}
|
145
|
+
|
146
|
+
return true;
|
147
|
+
};
|
148
|
+
|
149
|
+
$wnd.addEventListener('click', $wnd.__dispatchCapturedMouseEvent, true);
|
150
|
+
$wnd.addEventListener('dblclick', $wnd.__dispatchCapturedMouseEvent, true);
|
151
|
+
$wnd.addEventListener('mousedown', $wnd.__dispatchCapturedMouseEvent, true);
|
152
|
+
$wnd.addEventListener('mouseup', $wnd.__dispatchCapturedMouseEvent, true);
|
153
|
+
$wnd.addEventListener('mousemove', $wnd.__dispatchCapturedMouseEvent, true);
|
154
|
+
$wnd.addEventListener('mousewheel', $wnd.__dispatchCapturedMouseEvent, true);
|
155
|
+
$wnd.addEventListener('keydown', $wnd.__dispatchCapturedEvent, true);
|
156
|
+
$wnd.addEventListener('keyup', $wnd.__dispatchCapturedEvent, true);
|
157
|
+
$wnd.addEventListener('keypress', $wnd.__dispatchCapturedEvent, true);
|
158
|
+
|
159
|
+
// Set up normal event dispatcher.
|
160
|
+
$wnd.__dispatchEvent = function(evt) {
|
161
|
+
var listener, curElem = this;
|
162
|
+
while (curElem && !(listener = curElem.__listener))
|
163
|
+
curElem = curElem.parentNode;
|
164
|
+
if (curElem && curElem.nodeType != 1)
|
165
|
+
curElem = null;
|
166
|
+
|
167
|
+
if (listener)
|
168
|
+
@com.google.gwt.user.client.DOM::dispatchEvent(Lcom/google/gwt/user/client/Event;Lcom/google/gwt/user/client/Element;Lcom/google/gwt/user/client/EventListener;)(evt, curElem, listener);
|
169
|
+
};
|
170
|
+
|
171
|
+
$wnd.__captureElem = null;
|
172
|
+
}-*/;
|
173
|
+
|
174
|
+
public native void insertChild(Element parent, Element toAdd, int index) /*-{
|
175
|
+
var count = 0, child = parent.firstChild, before = null;
|
176
|
+
while (child) {
|
177
|
+
if (child.nodeType == 1) {
|
178
|
+
if (count == index) {
|
179
|
+
before = child;
|
180
|
+
break;
|
181
|
+
}
|
182
|
+
++count;
|
183
|
+
}
|
184
|
+
child = child.nextSibling;
|
185
|
+
}
|
186
|
+
|
187
|
+
parent.insertBefore(toAdd, before);
|
188
|
+
}-*/;
|
189
|
+
|
190
|
+
public native boolean isOrHasChild(Element parent, Element child) /*-{
|
191
|
+
while (child) {
|
192
|
+
if (parent == child) {
|
193
|
+
return true;
|
194
|
+
}
|
195
|
+
child = child.parentNode;
|
196
|
+
if (child && (child.nodeType != 1)) {
|
197
|
+
child = null;
|
198
|
+
}
|
199
|
+
}
|
200
|
+
return false;
|
201
|
+
}-*/;
|
202
|
+
|
203
|
+
public native void releaseCapture(Element elem) /*-{
|
204
|
+
if (elem == $wnd.__captureElem)
|
205
|
+
$wnd.__captureElem = null;
|
206
|
+
}-*/;
|
207
|
+
|
208
|
+
public native void setCapture(Element elem) /*-{
|
209
|
+
$wnd.__captureElem = elem;
|
210
|
+
}-*/;
|
211
|
+
|
212
|
+
public native void sinkEvents(Element elem, int bits) /*-{
|
213
|
+
elem.__eventBits = bits;
|
214
|
+
|
215
|
+
elem.onclick = (bits & 0x00001) ? $wnd.__dispatchEvent : null;
|
216
|
+
elem.ondblclick = (bits & 0x00002) ? $wnd.__dispatchEvent : null;
|
217
|
+
elem.onmousedown = (bits & 0x00004) ? $wnd.__dispatchEvent : null;
|
218
|
+
elem.onmouseup = (bits & 0x00008) ? $wnd.__dispatchEvent : null;
|
219
|
+
elem.onmouseover = (bits & 0x00010) ? $wnd.__dispatchEvent : null;
|
220
|
+
elem.onmouseout = (bits & 0x00020) ? $wnd.__dispatchEvent : null;
|
221
|
+
elem.onmousemove = (bits & 0x00040) ? $wnd.__dispatchEvent : null;
|
222
|
+
elem.onkeydown = (bits & 0x00080) ? $wnd.__dispatchEvent : null;
|
223
|
+
elem.onkeypress = (bits & 0x00100) ? $wnd.__dispatchEvent : null;
|
224
|
+
elem.onkeyup = (bits & 0x00200) ? $wnd.__dispatchEvent : null;
|
225
|
+
elem.onchange = (bits & 0x00400) ? $wnd.__dispatchEvent : null;
|
226
|
+
elem.onfocus = (bits & 0x00800) ? $wnd.__dispatchEvent : null;
|
227
|
+
elem.onblur = (bits & 0x01000) ? $wnd.__dispatchEvent : null;
|
228
|
+
elem.onlosecapture = (bits & 0x02000) ? $wnd.__dispatchEvent : null;
|
229
|
+
elem.onscroll = (bits & 0x04000) ? $wnd.__dispatchEvent : null;
|
230
|
+
elem.onload = (bits & 0x08000) ? $wnd.__dispatchEvent : null;
|
231
|
+
elem.onerror = (bits & 0x10000) ? $wnd.__dispatchEvent : null;
|
232
|
+
elem.onmousewheel = (bits & 0x20000) ? $wnd.__dispatchEvent : null;
|
233
|
+
}-*/;
|
234
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2006 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.user.client.impl.HTTPRequestImpl;
|
20
|
+
|
21
|
+
/**
|
22
|
+
* This class allows you to make asynchronous HTTP requests to the originating
|
23
|
+
* server.
|
24
|
+
*/
|
25
|
+
public class HTTPRequest {
|
26
|
+
|
27
|
+
private static final HTTPRequestImpl httpRequest = (HTTPRequestImpl) GWT.create(HTTPRequestImpl.class);
|
28
|
+
|
29
|
+
/**
|
30
|
+
* Makes an asynchronous HTTP GET to a remote server.
|
31
|
+
*
|
32
|
+
* @param url the absolute url to GET
|
33
|
+
* @param handler the response handler to be notified when either the request
|
34
|
+
* fails, or is completed successfully
|
35
|
+
* @return <code>false</code> if the invocation fails to issue
|
36
|
+
*/
|
37
|
+
public static boolean asyncGet(String url, ResponseTextHandler handler) {
|
38
|
+
return httpRequest.asyncGet(url, handler);
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Makes an asynchronous HTTP GET to a remote server.
|
43
|
+
*
|
44
|
+
* @param url the absolute url to GET
|
45
|
+
* @param handler the response handler to be notified when either the request
|
46
|
+
* fails, or is completed successfully
|
47
|
+
* @return <code>false</code> if the invocation fails to issue
|
48
|
+
*/
|
49
|
+
public static boolean asyncGet(String user, String pwd, String url,
|
50
|
+
ResponseTextHandler handler) {
|
51
|
+
return httpRequest.asyncGet(user, pwd, url, handler);
|
52
|
+
};
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Makes an asynchronous HTTP POST to a remote server.
|
56
|
+
*
|
57
|
+
* @param url the absolute url to which the POST data is delivered
|
58
|
+
* @param postData the data to post
|
59
|
+
* @param handler the response handler to be notified when either the request
|
60
|
+
* fails, or is completed successfully
|
61
|
+
* @return <code>false</code> if the invocation fails to issue
|
62
|
+
*/
|
63
|
+
public static boolean asyncPost(String url, String postData,
|
64
|
+
ResponseTextHandler handler) {
|
65
|
+
return httpRequest.asyncPost(url, postData, handler);
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Makes an asynchronous HTTP POST to a remote server.
|
70
|
+
*
|
71
|
+
* @param url the absolute url to which the POST data is delivered
|
72
|
+
* @param postData the data to post
|
73
|
+
* @param handler the response handler to be notified when either the request
|
74
|
+
* fails, or is completed successfully
|
75
|
+
* @return <code>false</code> if the invocation fails to issue
|
76
|
+
*/
|
77
|
+
public static boolean asyncPost(String user, String pwd, String url,
|
78
|
+
String postData, ResponseTextHandler handler) {
|
79
|
+
return httpRequest.asyncPost(user, pwd, url, postData, handler);
|
80
|
+
};
|
81
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright 2006 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.impl;
|
17
|
+
|
18
|
+
import com.google.gwt.core.client.JavaScriptObject;
|
19
|
+
import com.google.gwt.user.client.ResponseTextHandler;
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Native implementation associated with
|
23
|
+
* {@link com.google.gwt.user.client.HTTPRequest}.
|
24
|
+
*/
|
25
|
+
public class HTTPRequestImpl {
|
26
|
+
|
27
|
+
static JavaScriptObject nullFunc;
|
28
|
+
|
29
|
+
public HTTPRequestImpl() {
|
30
|
+
nullFunc = JavaScriptObject.createFunction();
|
31
|
+
}
|
32
|
+
|
33
|
+
public boolean asyncGet(String url, ResponseTextHandler handler) {
|
34
|
+
return asyncGet(null, null, url, handler);
|
35
|
+
}
|
36
|
+
|
37
|
+
public boolean asyncGet(String user, String pwd, String url,
|
38
|
+
ResponseTextHandler handler) {
|
39
|
+
return asyncGetImpl(user, pwd, url, handler);
|
40
|
+
}
|
41
|
+
|
42
|
+
public boolean asyncPost(String url, String postData,
|
43
|
+
ResponseTextHandler handler) {
|
44
|
+
return asyncPost(null, null, url, postData, handler);
|
45
|
+
}
|
46
|
+
|
47
|
+
public boolean asyncPost(String user, String pwd, String url,
|
48
|
+
String postData, ResponseTextHandler handler) {
|
49
|
+
return asyncPostImpl(user, pwd, url, postData, handler);
|
50
|
+
}
|
51
|
+
|
52
|
+
public JavaScriptObject createXmlHTTPRequest() {
|
53
|
+
return doCreateXmlHTTPRequest();
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* All the supported browsers except for IE instantiate it as shown.
|
58
|
+
*/
|
59
|
+
protected native JavaScriptObject doCreateXmlHTTPRequest() /*-{
|
60
|
+
return new XMLHttpRequest();
|
61
|
+
}-*/;
|
62
|
+
|
63
|
+
private native boolean asyncGetImpl(String user, String pwd, String url,
|
64
|
+
ResponseTextHandler handler) /*-{
|
65
|
+
var xmlHttp = this.@com.google.gwt.user.client.impl.HTTPRequestImpl::doCreateXmlHTTPRequest()();
|
66
|
+
try {
|
67
|
+
xmlHttp.open("GET", url, true);
|
68
|
+
xmlHttp.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
|
69
|
+
xmlHttp.onreadystatechange = function() {
|
70
|
+
if (xmlHttp.readyState == 4) {
|
71
|
+
xmlHttp.onreadystatechange = @com.google.gwt.user.client.impl.HTTPRequestImpl::nullFunc;
|
72
|
+
handler.@com.google.gwt.user.client.ResponseTextHandler::onCompletion(Ljava/lang/String;)(xmlHttp.responseText || "");
|
73
|
+
}
|
74
|
+
};
|
75
|
+
xmlHttp.send('');
|
76
|
+
return true;
|
77
|
+
} catch (e) {
|
78
|
+
xmlHttp.onreadystatechange = @com.google.gwt.user.client.impl.HTTPRequestImpl::nullFunc;
|
79
|
+
return false;
|
80
|
+
}
|
81
|
+
}-*/;
|
82
|
+
|
83
|
+
private native boolean asyncPostImpl(String user, String pwd, String url,
|
84
|
+
String postData, ResponseTextHandler handler) /*-{
|
85
|
+
var xmlHttp = this.@com.google.gwt.user.client.impl.HTTPRequestImpl::doCreateXmlHTTPRequest()();
|
86
|
+
try {
|
87
|
+
xmlHttp.open("POST", url, true);
|
88
|
+
xmlHttp.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
|
89
|
+
xmlHttp.onreadystatechange = function() {
|
90
|
+
if (xmlHttp.readyState == 4) {
|
91
|
+
xmlHttp.onreadystatechange = @com.google.gwt.user.client.impl.HTTPRequestImpl::nullFunc;
|
92
|
+
handler.@com.google.gwt.user.client.ResponseTextHandler::onCompletion(Ljava/lang/String;)(xmlHttp.responseText || "");
|
93
|
+
}
|
94
|
+
};
|
95
|
+
xmlHttp.send(postData);
|
96
|
+
return true;
|
97
|
+
}
|
98
|
+
catch (e) {
|
99
|
+
xmlHttp.onreadystatechange = @com.google.gwt.user.client.impl.HTTPRequestImpl::nullFunc;
|
100
|
+
return false;
|
101
|
+
}
|
102
|
+
}-*/;
|
103
|
+
}
|
@@ -0,0 +1,163 @@
|
|
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.Event;
|
20
|
+
|
21
|
+
/**
|
22
|
+
* A widget that contains arbitrary text, <i>not</i> interpreted as HTML.
|
23
|
+
*
|
24
|
+
* <h3>CSS Style Rules</h3>
|
25
|
+
* <ul class='css'>
|
26
|
+
* <li>.gwt-Label { }</li>
|
27
|
+
* </ul>
|
28
|
+
*
|
29
|
+
* <p>
|
30
|
+
* <h3>Example</h3> {@example com.google.gwt.examples.HTMLExample}
|
31
|
+
* </p>
|
32
|
+
*/
|
33
|
+
public class Label extends Widget implements SourcesClickEvents,
|
34
|
+
SourcesMouseEvents, SourcesMouseWheelEvents,
|
35
|
+
HasHorizontalAlignment, HasText, HasWordWrap {
|
36
|
+
|
37
|
+
private ClickListenerCollection clickListeners;
|
38
|
+
private HorizontalAlignmentConstant horzAlign;
|
39
|
+
private MouseListenerCollection mouseListeners;
|
40
|
+
private MouseWheelListenerCollection mouseWheelListeners;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Creates an empty label.
|
44
|
+
*/
|
45
|
+
public Label() {
|
46
|
+
setElement(DOM.createDiv());
|
47
|
+
sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.ONMOUSEWHEEL);
|
48
|
+
setStyleName("gwt-Label");
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Creates a label with the specified text.
|
53
|
+
*
|
54
|
+
* @param text the new label's text
|
55
|
+
*/
|
56
|
+
public Label(String text) {
|
57
|
+
this();
|
58
|
+
setText(text);
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Creates a label with the specified text.
|
63
|
+
*
|
64
|
+
* @param text the new label's text
|
65
|
+
* @param wordWrap <code>false</code> to disable word wrapping
|
66
|
+
*/
|
67
|
+
public Label(String text, boolean wordWrap) {
|
68
|
+
this(text);
|
69
|
+
setWordWrap(wordWrap);
|
70
|
+
}
|
71
|
+
|
72
|
+
public void addClickListener(ClickListener listener) {
|
73
|
+
if (clickListeners == null) {
|
74
|
+
clickListeners = new ClickListenerCollection();
|
75
|
+
}
|
76
|
+
clickListeners.add(listener);
|
77
|
+
}
|
78
|
+
|
79
|
+
public void addMouseListener(MouseListener listener) {
|
80
|
+
if (mouseListeners == null) {
|
81
|
+
mouseListeners = new MouseListenerCollection();
|
82
|
+
}
|
83
|
+
mouseListeners.add(listener);
|
84
|
+
}
|
85
|
+
|
86
|
+
public void addMouseWheelListener(MouseWheelListener listener) {
|
87
|
+
if (mouseWheelListeners == null) {
|
88
|
+
mouseWheelListeners = new MouseWheelListenerCollection();
|
89
|
+
}
|
90
|
+
mouseWheelListeners.add(listener);
|
91
|
+
}
|
92
|
+
|
93
|
+
public HorizontalAlignmentConstant getHorizontalAlignment() {
|
94
|
+
return horzAlign;
|
95
|
+
}
|
96
|
+
|
97
|
+
public String getText() {
|
98
|
+
return DOM.getInnerText(getElement());
|
99
|
+
}
|
100
|
+
|
101
|
+
public boolean getWordWrap() {
|
102
|
+
return !DOM.getStyleAttribute(getElement(), "whiteSpace").equals("nowrap");
|
103
|
+
}
|
104
|
+
|
105
|
+
public void onBrowserEvent(Event event) {
|
106
|
+
switch (DOM.eventGetType(event)) {
|
107
|
+
case Event.ONCLICK:
|
108
|
+
if (clickListeners != null) {
|
109
|
+
clickListeners.fireClick(this);
|
110
|
+
}
|
111
|
+
break;
|
112
|
+
|
113
|
+
case Event.ONMOUSEDOWN:
|
114
|
+
case Event.ONMOUSEUP:
|
115
|
+
case Event.ONMOUSEMOVE:
|
116
|
+
case Event.ONMOUSEOVER:
|
117
|
+
case Event.ONMOUSEOUT:
|
118
|
+
if (mouseListeners != null) {
|
119
|
+
mouseListeners.fireMouseEvent(this, event);
|
120
|
+
}
|
121
|
+
break;
|
122
|
+
|
123
|
+
case Event.ONMOUSEWHEEL:
|
124
|
+
if (mouseWheelListeners != null) {
|
125
|
+
mouseWheelListeners.fireMouseWheelEvent(this, event);
|
126
|
+
}
|
127
|
+
break;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
public void removeClickListener(ClickListener listener) {
|
132
|
+
if (clickListeners != null) {
|
133
|
+
clickListeners.remove(listener);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
public void removeMouseListener(MouseListener listener) {
|
138
|
+
if (mouseListeners != null) {
|
139
|
+
mouseListeners.remove(listener);
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
public void removeMouseWheelListener(MouseWheelListener listener) {
|
144
|
+
if (mouseWheelListeners != null) {
|
145
|
+
mouseWheelListeners.remove(listener);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
public void setHorizontalAlignment(HorizontalAlignmentConstant align) {
|
150
|
+
horzAlign = align;
|
151
|
+
DOM
|
152
|
+
.setStyleAttribute(getElement(), "textAlign", align.getTextAlignString());
|
153
|
+
}
|
154
|
+
|
155
|
+
public void setText(String text) {
|
156
|
+
DOM.setInnerText(getElement(), text);
|
157
|
+
}
|
158
|
+
|
159
|
+
public void setWordWrap(boolean wrap) {
|
160
|
+
DOM.setStyleAttribute(getElement(), "whiteSpace", wrap ? "normal"
|
161
|
+
: "nowrap");
|
162
|
+
}
|
163
|
+
}
|