Change-Id: Id7ec7013bcff446cdf3ce0f2088cb20b0708a56btags/7.6.0.rc1
@@ -1332,6 +1332,18 @@ public class WidgetUtil { | |||
} | |||
}-*/; | |||
/** | |||
* JavaScript hack to clear text selection in various browsers. | |||
* | |||
* @since 7.6 | |||
*/ | |||
public native static void clearTextSelection() | |||
/*-{ | |||
if ($wnd.getSelection) { | |||
$wnd.getSelection().removeAllRanges(); | |||
} | |||
}-*/; | |||
/** | |||
* The allowed value inaccuracy when comparing two double-typed pixel | |||
* values. |
@@ -43,6 +43,7 @@ import com.vaadin.client.DeferredWorker; | |||
import com.vaadin.client.MouseEventDetailsBuilder; | |||
import com.vaadin.client.ServerConnector; | |||
import com.vaadin.client.TooltipInfo; | |||
import com.vaadin.client.WidgetUtil; | |||
import com.vaadin.client.communication.StateChangeEvent; | |||
import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler; | |||
import com.vaadin.client.connectors.RpcDataSourceConnector.DetailsListener; | |||
@@ -1197,6 +1198,8 @@ public class GridConnector extends AbstractHasComponentsConnector implements | |||
getRpcProxy(GridServerRpc.class).contextClick(eventCell.getRowIndex(), | |||
rowKey, columnId, section, details); | |||
WidgetUtil.clearTextSelection(); | |||
} | |||
/** |
@@ -45,6 +45,7 @@ import com.vaadin.client.TooltipInfo; | |||
import com.vaadin.client.UIDL; | |||
import com.vaadin.client.Util; | |||
import com.vaadin.client.VConsole; | |||
import com.vaadin.client.WidgetUtil; | |||
import com.vaadin.client.annotations.OnStateChange; | |||
import com.vaadin.client.communication.StateChangeEvent; | |||
import com.vaadin.client.metadata.NoDataException; | |||
@@ -132,7 +133,6 @@ public abstract class AbstractComponentConnector extends AbstractConnector | |||
// remove the touch handlers as well | |||
unregisterTouchHandlers(); | |||
} | |||
} | |||
@@ -324,6 +324,8 @@ public abstract class AbstractComponentConnector extends AbstractConnector | |||
// The default context click implementation only provides the mouse | |||
// coordinates relative to root element of widget. | |||
getRpcProxy(ContextClickRpc.class).contextClick(details); | |||
WidgetUtil.clearTextSelection(); | |||
} | |||
/** |
@@ -28,11 +28,11 @@ import com.google.gwt.event.shared.HandlerRegistration; | |||
import com.google.gwt.user.client.ui.Widget; | |||
import com.vaadin.client.ApplicationConnection; | |||
import com.vaadin.client.BrowserInfo; | |||
import com.vaadin.client.HasChildMeasurementHintConnector; | |||
import com.vaadin.client.ComponentConnector; | |||
import com.vaadin.client.ConnectorHierarchyChangeEvent; | |||
import com.vaadin.client.ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler; | |||
import com.vaadin.client.DirectionalManagedLayout; | |||
import com.vaadin.client.HasChildMeasurementHintConnector; | |||
import com.vaadin.client.HasComponentsConnector; | |||
import com.vaadin.client.Paintable; | |||
import com.vaadin.client.ServerConnector; | |||
@@ -56,7 +56,8 @@ import com.vaadin.shared.ui.table.TableState; | |||
@Connect(com.vaadin.ui.Table.class) | |||
public class TableConnector extends AbstractFieldConnector implements | |||
HasComponentsConnector, ConnectorHierarchyChangeHandler, Paintable, | |||
DirectionalManagedLayout, PostLayoutListener, HasChildMeasurementHintConnector { | |||
DirectionalManagedLayout, PostLayoutListener, | |||
HasChildMeasurementHintConnector { | |||
private List<ComponentConnector> childComponents; | |||
@@ -120,6 +121,8 @@ public class TableConnector extends AbstractFieldConnector implements | |||
getRpcProxy(TableServerRpc.class).contextClick(rowKey, colKey, section, | |||
details); | |||
WidgetUtil.clearTextSelection(); | |||
} | |||
protected VScrollTableRow getScrollTableRow(Element e) { |
@@ -394,5 +394,7 @@ public class TreeConnector extends AbstractComponentConnector implements | |||
} | |||
getRpcProxy(TreeServerRpc.class).contextClick(key, details); | |||
WidgetUtil.clearTextSelection(); | |||
} | |||
} |
@@ -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); | |||
} | |||
} | |||
} |
@@ -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(); | |||
} | |||
} |