import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.Node;
+import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.GQuery;
import com.google.gwt.query.client.js.JsUtils;
* Example: fire(Event.ONCLICK | Event.ONFOCUS) Example: fire(Event.ONKEYDOWN.
* 'a');
*/
- @SuppressWarnings("deprecation")
public Events trigger(int eventbits, int... keys) {
if ((eventbits | Event.ONBLUR) == Event.ONBLUR)
dispatchEvent(document.createBlurEvent());
dispatchEvent(document.createFocusEvent());
if ((eventbits | Event.ONKEYDOWN) == Event.ONKEYDOWN)
dispatchEvent(document.createKeyDownEvent(false, false, false, false,
- keys[0], 0));
+ keys[0]));
if ((eventbits | Event.ONKEYPRESS) == Event.ONKEYPRESS)
dispatchEvent(document.createKeyPressEvent(false, false, false, false,
keys[0], 0));
if ((eventbits | Event.ONKEYUP) == Event.ONKEYUP)
dispatchEvent(document.createKeyUpEvent(false, false, false, false,
- keys[0], 0));
+ keys[0]));
if ((eventbits | Event.ONLOSECAPTURE) == Event.ONLOSECAPTURE)
triggerHtmlEvent("losecapture");
if ((eventbits | Event.ONMOUSEDOWN) == Event.ONMOUSEDOWN)
assertEquals("yellow", $("p", e).css("color", false));
}
+ /**
+ * TODO: focus/blur doesn't work with HtmlUnit, investigate and report.
+ */
+ @DoNotRunWith({Platform.HtmlUnitLayout})
+ public void testFocusBlur() {
+ $(e).html("<p>Content</p>");
+
+ // focus
+ // FIXME: Html 2.1.0 failing but FF do not
+ $("p", e).focus(new Function() {
+ public void f(Element elem) {
+ $(elem).css("border", "1px dotted black");
+ }
+ });
+ $("p", e).focus();
+ assertEquals("black", $("p", e).css("border-top-color", false));
+ assertEquals("dotted", $("p", e).css("border-top-style", false));
+ assertEquals("1px", $("p", e).css("border-top-width", false));
+
+ // blur
+ $("p", e).blur(new Function() {
+ public void f(Element elem) {
+ $(elem).css("border", "");
+ }
+ });
+ $("p", e).blur();
+ assertEquals("", $("p", e).css("border", false));
+ }
+
public void testEventsPlugin() {
$(e).html("<p>Content</p>");
$("p", e).trigger(Event.ONMOUSEOUT);
assertEquals("white", $("p", e).css("background-color", false));
-// // focus
-// FIXME: Html 2.1.0 failing but FF do not
-// $("p", e).focus(new Function() {
-// public void f(Element elem) {
-// $(elem).css("border", "1px dotted black");
-// }
-// });
-// $("p", e).focus();
-// assertEquals("black", $("p", e).css("border-top-color", false));
-// assertEquals("dotted", $("p", e).css("border-top-style", false));
-// assertEquals("1px", $("p", e).css("border-top-width", false));
-//
-// // blur
-// $("p", e).blur(new Function() {
-// public void f(Element elem) {
-// $(elem).css("border", "");
-// }
-// });
-// $("p", e).blur();
-// assertEquals("", $("p", e).css("border", false));
-
// key events
$(e).html("<input type='text'/>");
Function keyEventAction = new Function() {
public boolean f(Event evnt) {
GQuery gq = $(evnt);
- gq.val(gq.val() + Character.toString((char) evnt.getKeyCode()));
+ int c = evnt.getCharCode() > 0 ? evnt.getCharCode() : evnt.getKeyCode();
+ System.out.println(evnt.getCharCode() + " " + evnt.getKeyCode());
+ gq.val(gq.val() + Character.toString((char)c));
return false;
}
};
$("input", e).keydown(keyEventAction);
$("input", e).keyup(keyEventAction);
$("input", e).focus();
+ $("input", e).keydown('A');
+ $("input", e).keypress('B');
+ $("input", e).keyup('C');
$("input", e).keydown('a');
$("input", e).keypress('b');
$("input", e).keyup('c');
- assertEquals("abc", $("input", e).val());
+ assertEquals("ABCabc", $("input", e).val());
}
public void testLazyMethods() {