Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright 2019 HealthPivots, all rights reserved
*
* @Created: Apr 10, 2019
*/
package com.vaadin.addon.spreadsheet.elements;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.phantomjs.PhantomJSDriver;

import com.vaadin.testbench.TestBenchDriverProxy;

/**
* ElementUtil
*/
public class ElementUtil {

/**
* Helper to work around lack of PhantomJS direct support for contextClick events.
* May need to wait for the context click to appear after calling.
*
* @param driver
* @param webElement

* @see com.vaadin.testbench.TestBenchElement#contextClick()
* @see "https://github.com/ariya/phantomjs/issues/14005"
*/
public static void phantomJSContextClick(WebDriver driver, WebElement webElement) {
WebDriver actualDriver = driver;
if (actualDriver instanceof TestBenchDriverProxy) {
actualDriver = ((TestBenchDriverProxy)actualDriver).getActualDriver();
}
if (actualDriver instanceof PhantomJSDriver) {
String script =
"var element = arguments[0];" +
"var event = document.createEvent('HTMLEvents');" +
"event.initEvent('contextmenu', true, false);" +
"element.dispatchEvent(event);";
((JavascriptExecutor)driver)
.executeScript(script, new Object[]{webElement});
}
}

private ElementUtil() {
// unused
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@

import java.util.List;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.phantomjs.PhantomJSDriver;

import com.vaadin.testbench.By;
import com.vaadin.testbench.TestBenchDriverProxy;
import com.vaadin.testbench.elementsbase.AbstractElement;

/**
Expand Down Expand Up @@ -147,4 +151,18 @@ public boolean hasCommentIndicator() {
return !indicators.isEmpty();
}

/**
* Override to allow cell context menu tests to pass for PhantomJS.
* See the linked issue below for code. PhantomJS doesn't support context
* menu directly with Selenium.
*
* @see com.vaadin.testbench.TestBenchElement#contextClick()
* @see "https://github.com/ariya/phantomjs/issues/14005"
*/
@Override
public void contextClick() {
// for PhantomJS, this won't open the context menu
super.contextClick();
ElementUtil.phantomJSContextClick(getDriver(), getWrappedElement());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,20 @@ public TestBenchElement getResizeHandle() {
findElement(By.className("header-resize-dnd-second")),
getCommandExecutor());
}


/**
* Override to allow cell context menu tests to pass for PhantomJS.
* See the linked issue below for code. PhantomJS doesn't support context
* menu directly with Selenium.
*
* @see com.vaadin.testbench.TestBenchElement#contextClick()
* @see "https://github.com/ariya/phantomjs/issues/14005"
*/
@Override
public void contextClick() {
// for PhantomJS, this won't open the context menu
super.contextClick();
ElementUtil.phantomJSContextClick(getDriver(), getWrappedElement());
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ...FirstColumnTest-overflowBasedOnFullMergedWidth_PhantomJS_mergedNarrowColumn.png
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.server.KeyMapper;
import com.vaadin.shared.Registration;

/**
* ContextMenuManager is an utility class for the Spreadsheet component. This
Expand All @@ -51,6 +52,8 @@ public class ContextMenuManager implements Serializable {

private int contextMenuHeaderIndex = -1;

private Registration contextClickRegistration;

/**
* Constructs a new ContextMenuManager and ties it to the given Spreadsheet.
*
Expand All @@ -77,6 +80,7 @@ public void addActionHandler(Handler actionHandler) {
actionHandlers.add(actionHandler);
}
}
checkContextClickHandler();
}

/**
Expand All @@ -94,6 +98,7 @@ public void removeActionHandler(Handler actionHandler) {
actionMapper = null;
}
}
checkContextClickHandler();
}

/**
Expand All @@ -106,6 +111,21 @@ public boolean hasActionHandlers() {
return actionHandlers != null && actionHandlers.size() > 0;
}

private void checkContextClickHandler() {
if (hasActionHandlers()) {
if (contextClickRegistration == null) {
contextClickRegistration = spreadsheet
.addContextClickListener(event -> {
// this is never called, only here to tell the connector to
// watch for context events
});
}
} else if (contextClickRegistration != null) {
contextClickRegistration.remove();
contextClickRegistration = null;
}
}

/**
* This method is called when a context menu event has happened on any cell
* of the target Spreadsheet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
import com.vaadin.addon.spreadsheet.shared.SpreadsheetState;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.ContextClickEvent;
import com.vaadin.server.Resource;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Component;
import com.vaadin.ui.Component.Focusable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,6 @@ public void setPosition(int col1, int col2, int row1, int row2) {
setFillMode(false);
}

if (!dragging) {
showTouchActions();
}
}

public void setPaintPosition(int col1, int col2, int row1, int row2) {
Expand All @@ -847,128 +844,6 @@ public void setPaintPosition(int col1, int col2, int row1, int row2) {
}
}

private void showTouchActions() {
if (touchMode) {
// show touch actions in popup

if (touchActions != null) {
// remove old
touchActions.hide();
}

touchActions = new VOverlay(true);
touchActions.setOwner((Widget) sheetWidget.actionHandler);
touchActions.addStyleName("v-contextmenu");

final MenuBar m = new MenuBar();
m.addItem(new SafeHtmlBuilder().appendEscaped("Fill").toSafeHtml(),
new ScheduledCommand() {

@Override
public void execute() {
setFillMode(true);
touchActions.hide();
}
});

touchActions.add(m);

Scheduler.get().scheduleDeferred(new ScheduledCommand() {

@Override
public void execute() {
touchActions
.setPopupPositionAndShow(new PositionCallback() {

@Override
public void setPosition(int offsetWidth,
int offsetHeight) {
// above top border
int top = 0;
int left = 0;
int bottom = 0;
int width = 0;
int parentTop = 0;
if (topRight != null
&& topRight.isVisible()) {
top = topRight.top.getAbsoluteTop();
left = topRight.top.getAbsoluteLeft();
width = topRight.top.getClientWidth();
bottom = topRight.bottom
.getAbsoluteBottom() + 5;
if (topLeft.isVisible()) {
width += topLeft.top
.getClientWidth();
}
if (bottomRight.isVisible()) {
bottom = bottomRight.bottom
.getAbsoluteBottom() + 5;
}
} else if (topLeft != null
&& topLeft.isVisible()) {
top = topLeft.top.getAbsoluteTop();
left = topLeft.top.getAbsoluteLeft();
width = topLeft.top.getClientWidth();
bottom = topLeft.bottom
.getAbsoluteBottom() + 5;
if (bottomLeft.isVisible()) {
bottom = bottomLeft.bottom
.getAbsoluteBottom() + 5;
}
} else if (bottomLeft != null
&& bottomLeft.isVisible()) {
top = bottomLeft.top.getAbsoluteTop();
left = bottomLeft.top.getAbsoluteLeft();
width = bottomLeft.top.getClientWidth();
bottom = bottomLeft.bottom
.getAbsoluteBottom() + 5;
if (bottomRight.isVisible()) {
width += bottomRight.top
.getClientWidth();
}
} else {
top = bottomRight.top.getAbsoluteTop();
left = bottomRight.top
.getAbsoluteLeft();
width = bottomRight.top
.getClientWidth();
bottom = bottomRight.bottom
.getAbsoluteBottom() + 5;
}
if (width > sheetWidget.getElement()
.getClientWidth()) {
width = sheetWidget.getElement()
.getClientWidth();
}

if (sheetWidget.hasFrozenRows()) {
parentTop = sheetWidget
.getTopRightPane()
.getAbsoluteTop();
} else {
parentTop = sheetWidget
.getBottomRightPane()
.getAbsoluteTop();
}

top -= offsetHeight + 5;
left += (width / 2) - (offsetWidth / 2);

if (parentTop > top) {
// put under instead
top = bottom + 5;
}
touchActions.setPopupPosition(left, top);

// TODO check for room
}
});
touchActions.show();
}
});
}
}

@Override
public void setWidth(String width) {

Expand Down Expand Up @@ -1224,7 +1099,6 @@ private void stopSelectingCells(Event event) {
sheetWidget.getSelectedCellRow(), tempRow);

dragging = false;
showTouchActions();
}

protected void setFillMode(boolean fillMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,8 @@ public void onBrowserEvent(Event event) {
}
break;
case Event.ONMOUSEUP:
if (event.getButton() == NativeEvent.BUTTON_RIGHT) {
// Context menu is displayed on mouse up to prevent
// contextmenu event on VContextMenu
widget.onSheetMouseDown(event);
}
// now that context menus are handled with the contextMenuEvent
// this should do nothing.
break;
case Event.ONDBLCLICK:
onSheetDoubleClick(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ void onScrollViewChanged(int firstRow, int lastRow, int firstColumn,
*/
void onCellRightClick(NativeEvent nativeEvent, int column, int row);

/**
* if there is a connector iOS context click timer running, cancel it
*/
void cancelContextClickTimer();

/**
* Called on right mouse button click on top of a row header
*
Expand Down
Loading