diff options
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()); + } + +} |