diff options
author | Manolo Carrasco <manolo@apache.org> | 2010-05-05 10:35:52 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2010-05-05 10:35:52 +0000 |
commit | b3b463d39b0494a3385c876d0dc67668579480c2 (patch) | |
tree | c4599196868194fade87b5e64eae17fd1442ae54 /gwtquery-core/src | |
parent | 2f674aae80afb5958258043404aca4e247d54eee (diff) | |
download | gwtquery-b3b463d39b0494a3385c876d0dc67668579480c2.tar.gz gwtquery-b3b463d39b0494a3385c876d0dc67668579480c2.zip |
Do not override original Gwt EventListeners, fixes Issue_10
Diffstat (limited to 'gwtquery-core/src')
-rw-r--r-- | gwtquery-core/src/main/java/com/google/gwt/query/client/EventsListener.java | 43 | ||||
-rw-r--r-- | gwtquery-core/src/test/java/com/google/gwt/query/client/GwtEventsTest.java | 23 |
2 files changed, 49 insertions, 17 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/EventsListener.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/EventsListener.java index 43c50f3b..5de960e4 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/EventsListener.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/EventsListener.java @@ -34,14 +34,14 @@ class EventsListener implements EventListener { private static class BindFunction { - int type; + Object data; Function function; - Object data; - int times = -1; + int type; + BindFunction(int t, Function f, Object d) { type = t; function = f; @@ -67,32 +67,44 @@ class EventsListener implements EventListener { } public static EventsListener getInstance(Element e) { - EventsListener ret = getWidgetElementImpl(e); + EventsListener ret = getGQueryEventLinstener(e); return ret != null ? ret : new EventsListener(e); } - private static native EventsListener getWidgetElementImpl(Element elem) /*-{ + private static native EventsListener getGQueryEventLinstener(Element elem) /*-{ return elem.__gqueryevent; }-*/; + private static native EventListener getOriginalEventListener(Element elem) /*-{ + return elem.__listener; + }-*/; + private static native void setFocusable(Element elem) /*-{ elem.tabIndex = 0; }-*/; - private static native void setWidgetElementImpl(Element elem, + private static native void setGQueryEventListener(Element elem, EventsListener gqevent) /*-{ elem.__gqueryevent = gqevent; }-*/; + private Element element; + private JsObjectArray<EventsListener.BindFunction> elementEvents = JsObjectArray .createArray().cast(); + private EventListener originalEventListener; - private Element element; + private EventsListener(Element element) { + this.element = element; + originalEventListener = getOriginalEventListener(element); + setGQueryEventListener(element, this); + DOM.setEventListener((com.google.gwt.user.client.Element) element, this); + } - private EventsListener(Element e) { - element = e; - setWidgetElementImpl(element, this); - DOM.setEventListener((com.google.gwt.user.client.Element) e, this); + public void bind(int eventbits, final Object data, Function...funcs) { + for (Function function: funcs) { + bind(eventbits, data, function, -1); + } } public void bind(int eventbits, final Object data, final Function function, @@ -112,13 +124,10 @@ class EventsListener implements EventListener { } } - public void bind(int eventbits, final Object data, Function...funcs) { - for (Function function: funcs) { - bind(eventbits, data, function, -1); - } - } - public void onBrowserEvent(Event event) { + if (originalEventListener != null) { + originalEventListener.onBrowserEvent(event); + } int etype = DOM.eventGetType(event); for (int i = 0; i < elementEvents.length(); i++) { EventsListener.BindFunction listener = elementEvents.get(i); diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GwtEventsTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GwtEventsTest.java index fe8793e1..ca28b0f7 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GwtEventsTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GwtEventsTest.java @@ -18,10 +18,13 @@ package com.google.gwt.query.client; import static com.google.gwt.query.client.GQuery.$; import com.google.gwt.dom.client.Element; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.junit.DoNotRunWith; import com.google.gwt.junit.Platform; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.RootPanel; @@ -170,4 +173,24 @@ public class GwtEventsTest extends GWTTestCase { $("p", e).dblclick(); assertEquals("yellow", $("p", e).css("color")); } + + public void testWidgetEvents() { + final Button b = new Button("click-me"); + b.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent event) { + b.getElement().getStyle().setBackgroundColor("black"); + } + }); + RootPanel.get().add(b); + $("button").click(new Function(){ + public boolean f(Event e) { + $(e).css("color", "red"); + return true; + } + }); + $("button").click(); + assertEquals("red", $("button").css("color")); + assertEquals("black", $("button").css("background-color")); + RootPanel.get().remove(b); + } } |