Merge of c4624 from branches/snapshot-2009.01.29.
git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4655 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/dom/client/ButtonElement.java b/user/src/com/google/gwt/dom/client/ButtonElement.java
index 5823486..f5eb93a 100644
--- a/user/src/com/google/gwt/dom/client/ButtonElement.java
+++ b/user/src/com/google/gwt/dom/client/ButtonElement.java
@@ -40,9 +40,9 @@
/**
* Simulate a mouse-click.
*/
- public final native void click() /*-{
- this.click();
- }-*/;
+ public final void click() {
+ DOMImpl.impl.buttonClick(this);
+ }
/**
* A single character access key to give access to the form control.
diff --git a/user/src/com/google/gwt/dom/client/DOMImpl.java b/user/src/com/google/gwt/dom/client/DOMImpl.java
index 2b755c6..738849d 100644
--- a/user/src/com/google/gwt/dom/client/DOMImpl.java
+++ b/user/src/com/google/gwt/dom/client/DOMImpl.java
@@ -21,6 +21,10 @@
static final DOMImpl impl = GWT.create(DOMImpl.class);
+ public native void buttonClick(ButtonElement button) /*-{
+ button.click();
+ }-*/;
+
public native Element createElement(String tag) /*-{
return $doc.createElement(tag);
}-*/;
diff --git a/user/src/com/google/gwt/dom/client/DOMImplMozillaOld.java b/user/src/com/google/gwt/dom/client/DOMImplMozillaOld.java
index b4e375b..6b22e52 100644
--- a/user/src/com/google/gwt/dom/client/DOMImplMozillaOld.java
+++ b/user/src/com/google/gwt/dom/client/DOMImplMozillaOld.java
@@ -24,6 +24,16 @@
*/
class DOMImplMozillaOld extends DOMImplMozilla {
+ public native void buttonClick(ButtonElement button) /*-{
+ var doc = button.ownerDocument;
+ if (doc != null) {
+ var evt = doc.createEvent('MouseEvents');
+ evt.initMouseEvent('click', true, true, null, 0, 0,
+ 0, 0, 0, false, false, false, false, 0, null);
+ button.dispatchEvent(evt);
+ }
+ }-*/;
+
@Override
public native int getAbsoluteLeft(Element elem) /*-{
var style = $doc.defaultView.getComputedStyle(elem, null);
diff --git a/user/src/com/google/gwt/user/client/ui/Button.java b/user/src/com/google/gwt/user/client/ui/Button.java
index e571bbd..33d17f4 100644
--- a/user/src/com/google/gwt/user/client/ui/Button.java
+++ b/user/src/com/google/gwt/user/client/ui/Button.java
@@ -18,6 +18,7 @@
import com.google.gwt.dom.client.ButtonElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
+import com.google.gwt.dom.client.ButtonElement;
import com.google.gwt.event.dom.client.ClickHandler;
/**
@@ -71,10 +72,6 @@
}
}-*/;
- static native void click(Element button) /*-{
- button.click();
- }-*/;
-
/**
* Creates a button with no caption.
*/
@@ -133,6 +130,11 @@
* Programmatic equivalent of the user clicking the button.
*/
public void click() {
- click(getElement());
+ getButtonElement().click();
+ }
+
+ private ButtonElement getButtonElement() {
+ return getElement().cast();
}
}
+
diff --git a/user/test/com/google/gwt/user/UISuite.java b/user/test/com/google/gwt/user/UISuite.java
index dcedbbc..e243edd 100644
--- a/user/test/com/google/gwt/user/UISuite.java
+++ b/user/test/com/google/gwt/user/UISuite.java
@@ -22,6 +22,7 @@
import com.google.gwt.user.client.WindowTest;
import com.google.gwt.user.client.ui.AbsolutePanelTest;
import com.google.gwt.user.client.ui.AnchorTest;
+import com.google.gwt.user.client.ui.ButtonTest;
import com.google.gwt.user.client.ui.CaptionPanelTest;
import com.google.gwt.user.client.ui.CheckBoxTest;
import com.google.gwt.user.client.ui.CompositeTest;
@@ -94,6 +95,7 @@
suite.addTestSuite(AbsolutePanelTest.class);
suite.addTestSuite(AnchorTest.class);
+ suite.addTestSuite(ButtonTest.class);
suite.addTestSuite(CaptionPanelTest.class);
suite.addTestSuite(CheckBoxTest.class);
suite.addTestSuite(ClippedImagePrototypeTest.class);
diff --git a/user/test/com/google/gwt/user/client/ui/ButtonTest.java b/user/test/com/google/gwt/user/client/ui/ButtonTest.java
new file mode 100644
index 0000000..83777e7
--- /dev/null
+++ b/user/test/com/google/gwt/user/client/ui/ButtonTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.user.client.ui;
+
+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.client.GWTTestCase;
+
+/**
+ * Tests for {@link Button}.
+ */
+public class ButtonTest extends GWTTestCase {
+
+ public String getModuleName() {
+ return "com.google.gwt.user.User";
+ }
+
+ private class H implements ClickHandler {
+ boolean clicked;
+ Element target;
+
+ public void onClick(ClickEvent event) {
+ target = event.getNativeEvent().getTarget();
+ clicked = true;
+ }
+ }
+
+ public void testClick() {
+ Button b = new Button();
+ RootPanel.get().add(b);
+
+ H h = new H();
+ b.addClickHandler(h);
+
+ b.click();
+ assertTrue(h.clicked);
+
+ // Old Mozilla browsers don't set up the event target properly for
+ // synthesized clicks. This tests the workaround in DOMImplMozillaOld.
+ assertEquals(b.getElement(), h.target);
+ }
+}
+