summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-12-11 14:39:56 +0200
committerVaadin Code Review <review@vaadin.com>2015-12-15 09:32:31 +0000
commit05356b0cb628e7f7604991adf82387c746870104 (patch)
treed34b4d95e6ffda571b8808f38e64863ab40ec671 /uitest
parentdace5ab66322c226b2cce79848a9c0518740f020 (diff)
downloadvaadin-framework-05356b0cb628e7f7604991adf82387c746870104.tar.gz
vaadin-framework-05356b0cb628e7f7604991adf82387c746870104.zip
Add a method to clear selected text on context click (#19367)
Change-Id: Id7ec7013bcff446cdf3ce0f2088cb20b0708a56b
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/contextclick/BrowserContextMenuInSubComponent.java84
-rw-r--r--uitest/src/com/vaadin/tests/widgetset/client/extension/BrowserContextMenuExtensionConnector.java49
2 files changed, 133 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/contextclick/BrowserContextMenuInSubComponent.java b/uitest/src/com/vaadin/tests/contextclick/BrowserContextMenuInSubComponent.java
new file mode 100644
index 0000000000..d3edf0ba43
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/contextclick/BrowserContextMenuInSubComponent.java
@@ -0,0 +1,84 @@
+/*
+ * 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.contextclick;
+
+import com.vaadin.annotations.Widgetset;
+import com.vaadin.event.ContextClickEvent;
+import com.vaadin.event.ContextClickEvent.ContextClickListener;
+import com.vaadin.server.AbstractExtension;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.tests.widgetset.TestingWidgetSet;
+import com.vaadin.ui.AbstractComponent;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Notification;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.TextArea;
+import com.vaadin.ui.VerticalLayout;
+
+@Widgetset(TestingWidgetSet.NAME)
+public class BrowserContextMenuInSubComponent extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Panel panel = new Panel();
+
+ VerticalLayout layout = new VerticalLayout();
+ final TextArea textArea = new TextArea();
+ // Make TextArea show regular context menu instead of firing the
+ // server-side event.
+ BrowserContextMenuExtension.extend(textArea);
+ final Button button = new Button("Submit", new Button.ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Notification.show(textArea.getValue());
+ }
+ });
+
+ layout.addComponent(textArea);
+ layout.addComponent(button);
+
+ panel.setContent(layout);
+
+ panel.addContextClickListener(new ContextClickListener() {
+
+ @Override
+ public void contextClick(ContextClickEvent event) {
+ button.click();
+ }
+ });
+
+ addComponent(panel);
+ }
+
+ /**
+ * A simple extension for making extended component stop propagation of the
+ * context click events, so the browser will handle the context click and
+ * show its own context menu.
+ */
+ public static class BrowserContextMenuExtension extends AbstractExtension {
+ private BrowserContextMenuExtension(AbstractComponent c) {
+ super(c);
+ }
+
+ public static BrowserContextMenuExtension extend(AbstractComponent c) {
+ return new BrowserContextMenuExtension(c);
+ }
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/extension/BrowserContextMenuExtensionConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/extension/BrowserContextMenuExtensionConnector.java
new file mode 100644
index 0000000000..9b05ff35d8
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/widgetset/client/extension/BrowserContextMenuExtensionConnector.java
@@ -0,0 +1,49 @@
+/*
+ * 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.widgetset.client.extension;
+
+import com.google.gwt.event.dom.client.ContextMenuEvent;
+import com.google.gwt.event.dom.client.ContextMenuHandler;
+import com.vaadin.client.ServerConnector;
+import com.vaadin.client.extensions.AbstractExtensionConnector;
+import com.vaadin.client.ui.AbstractComponentConnector;
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.tests.contextclick.BrowserContextMenuInSubComponent.BrowserContextMenuExtension;
+
+/**
+ * Client-side connector of the {@link BrowserContextMenuExtension}.
+ */
+@Connect(BrowserContextMenuExtension.class)
+public class BrowserContextMenuExtensionConnector extends
+ AbstractExtensionConnector {
+
+ @Override
+ protected void extend(ServerConnector target) {
+ getParent().getWidget().addDomHandler(new ContextMenuHandler() {
+
+ @Override
+ public void onContextMenu(ContextMenuEvent event) {
+ // Stop context click events from propagating.
+ event.stopPropagation();
+ }
+ }, ContextMenuEvent.getType());
+ }
+
+ @Override
+ public AbstractComponentConnector getParent() {
+ return (AbstractComponentConnector) super.getParent();
+ }
+}