From 559ecad2d0d68f7fcb590c73de83eaf6d86a25a2 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Fri, 4 Nov 2011 09:40:39 +0000 Subject: [PATCH] fixes issue111 --- .../gwt/query/client/plugins/Events.java | 6 +- .../gwt/query/client/GQueryEventsTestGwt.java | 59 +++++++++++-------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java index e9bfaeaf..1294feb3 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java @@ -18,6 +18,7 @@ package com.google.gwt.query.client.plugins; 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; @@ -181,7 +182,6 @@ public class Events extends GQuery { * 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()); @@ -197,13 +197,13 @@ public class Events extends GQuery { 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) diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java index 5a8ba73e..23eb49cd 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTestGwt.java @@ -164,6 +164,35 @@ public class GQueryEventsTestGwt extends GWTTestCase { 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("

Content

"); + + // 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("

Content

"); @@ -231,33 +260,14 @@ public class GQueryEventsTestGwt extends GWTTestCase { $("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(""); 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; } }; @@ -265,10 +275,13 @@ public class GQueryEventsTestGwt extends GWTTestCase { $("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() { -- 2.39.5