summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-01-17 16:56:33 +0200
committerelmot <elmot@vaadin.com>2016-01-26 17:00:01 +0200
commit741830053cce3b63b6f083a2f4932c5b1c668de4 (patch)
tree86c1ea5b194d8ddac24b2336b56fcb4e3825beca
parentbd79d2ba5fa67c84b9d589ccb58556ee331379a0 (diff)
downloadvaadin-framework-741830053cce3b63b6f083a2f4932c5b1c668de4.tar.gz
vaadin-framework-741830053cce3b63b6f083a2f4932c5b1c668de4.zip
Make Checkbox label send context click events also (#19456)
Change-Id: I922375554be313f0ee7d753b3de444cfe1964ebe
-rw-r--r--client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java15
-rw-r--r--uitest/src/com/vaadin/tests/components/checkbox/CheckboxContextClick.java38
-rw-r--r--uitest/src/com/vaadin/tests/components/checkbox/CheckboxContextClickTest.java54
3 files changed, 107 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java b/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java
index 8cfcf7feb1..0dc9810c51 100644
--- a/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java
+++ b/client/src/com/vaadin/client/ui/checkbox/CheckBoxConnector.java
@@ -23,11 +23,13 @@ import com.google.gwt.user.client.Event;
import com.vaadin.client.MouseEventDetailsBuilder;
import com.vaadin.client.VCaption;
import com.vaadin.client.VTooltip;
+import com.vaadin.client.annotations.OnStateChange;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.ConnectorFocusAndBlurHandler;
import com.vaadin.client.ui.Icon;
import com.vaadin.client.ui.VCheckBox;
+import com.vaadin.shared.EventId;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.checkbox.CheckBoxServerRpc;
@@ -137,4 +139,17 @@ public class CheckBoxConnector extends AbstractFieldConnector implements
}
}
}
+
+ private boolean contextEventSunk = false;
+
+ @OnStateChange("registeredEventListeners")
+ void sinkContextClickEvent() {
+ if (!contextEventSunk && hasEventListener(EventId.CONTEXT_CLICK)) {
+ // CheckBox.sinkEvents works differently than all other widgets:
+ // "Unlike other widgets the CheckBox sinks on its inputElement, not
+ // its wrapper"
+ DOM.sinkEvents(getWidget().getElement(), Event.ONCONTEXTMENU);
+ contextEventSunk = true;
+ }
+ }
}
diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckboxContextClick.java b/uitest/src/com/vaadin/tests/components/checkbox/CheckboxContextClick.java
new file mode 100644
index 0000000000..9b37db10b1
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/checkbox/CheckboxContextClick.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * 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.vaadin.tests.components.checkbox;
+
+import com.vaadin.event.ContextClickEvent;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.CheckBox;
+
+public class CheckboxContextClick extends AbstractTestUIWithLog {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final CheckBox cb = new CheckBox("Right-click me", true);
+ cb.addContextClickListener(new ContextClickEvent.ContextClickListener() {
+ @Override
+ public void contextClick(ContextClickEvent event) {
+ log("checkbox context clicked");
+ }
+ });
+
+ addComponent(cb);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/checkbox/CheckboxContextClickTest.java b/uitest/src/com/vaadin/tests/components/checkbox/CheckboxContextClickTest.java
new file mode 100644
index 0000000000..1903687527
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/checkbox/CheckboxContextClickTest.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * 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.vaadin.tests.components.checkbox;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.CheckBoxElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class CheckboxContextClickTest extends MultiBrowserTest {
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ return getBrowsersSupportingContextMenu();
+ }
+
+ @Test
+ public void contextClickCheckboxAndText() {
+ openTestURL();
+ CheckBoxElement checkbox = $(CheckBoxElement.class).first();
+ Assert.assertEquals("checked", checkbox.getValue());
+ WebElement input = checkbox.findElement(By.xpath("input"));
+ WebElement label = checkbox.findElement(By.xpath("label"));
+
+ new Actions(getDriver()).contextClick(input).perform();
+ Assert.assertEquals("1. checkbox context clicked", getLogRow(0));
+ Assert.assertEquals("checked", checkbox.getValue());
+
+ new Actions(getDriver()).contextClick(label).perform();
+ Assert.assertEquals("2. checkbox context clicked", getLogRow(0));
+ Assert.assertEquals("checked", checkbox.getValue());
+ }
+
+}