aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2008-10-03 07:59:54 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2008-10-03 07:59:54 +0000
commit934588b7b8f9c0c581766b78553b55b701e80cde (patch)
tree10dabb7fc2074ced8c753c5044e1195351d89d67
parent8c0c39470d895eb90c345563ad814d17f3cff013 (diff)
downloadvaadin-framework-934588b7b8f9c0c581766b78553b55b701e80cde.tar.gz
vaadin-framework-934588b7b8f9c0c581766b78553b55b701e80cde.zip
fixes #2133, context menu event from gwt 1.5 + some other gwt 1.5 dependent cleaning
svn changeset:5589/svn branch:trunk
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java51
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java45
2 files changed, 25 insertions, 71 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
index 2aa7743d98..82a80c7b54 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
@@ -30,7 +30,6 @@ import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.MouseEventDetails;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
-import com.itmill.toolkit.terminal.gwt.client.Util;
import com.itmill.toolkit.terminal.gwt.client.ui.IScrollTable.IScrollTableBody.IScrollTableRow;
/**
@@ -986,9 +985,7 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
*/
public void onBrowserEvent(Event event) {
if (enabled) {
- if (isResizing
- || DOM.compare(DOM.eventGetTarget(event),
- colResizeWidget)) {
+ if (isResizing || event.getTarget() == colResizeWidget) {
onResizeEvent(event);
} else {
handleCaptionEvent(event);
@@ -1465,7 +1462,7 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
public void onBrowserEvent(Event event) {
if (enabled) {
- if (DOM.compare(DOM.eventGetTarget(event), columnSelector)) {
+ if (event.getTarget() == columnSelector) {
final int left = DOM.getAbsoluteLeft(columnSelector);
final int top = DOM.getAbsoluteTop(columnSelector)
+ DOM.getElementPropertyInt(columnSelector,
@@ -1927,33 +1924,10 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
private IScrollTableRow(int rowKey) {
this.rowKey = rowKey;
setElement(DOM.createElement("tr"));
- DOM.sinkEvents(getElement(), Event.ONCLICK | Event.ONDBLCLICK);
- attachContextMenuEvent(getElement());
+ DOM.sinkEvents(getElement(), Event.ONCLICK | Event.ONDBLCLICK
+ | Event.ONCONTEXTMENU);
}
- protected void onDetach() {
- Util.removeContextMenuEvent(getElement());
- super.onDetach();
- }
-
- /**
- * Attaches context menu event handler to given element. Attached
- * handler fires showContextMenu function.
- *
- * @param el
- * element where to attach contenxt menu event
- */
- private native void attachContextMenuEvent(Element el)
- /*-{
- var row = this;
- el.oncontextmenu = function(e) {
- if(!e)
- e = $wnd.event;
- row.@com.itmill.toolkit.terminal.gwt.client.ui.IScrollTable.IScrollTableBody.IScrollTableRow::showContextMenu(Lcom/google/gwt/user/client/Event;)(e);
- return false;
- };
- }-*/;
-
public String getKey() {
return String.valueOf(rowKey);
}
@@ -2088,7 +2062,7 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
.eventGetTarget(event));
client.updateVariable(paintableId, "clickedKey", ""
+ rowKey, false);
- if (DOM.compare(getElement(), DOM.getParent(tdOrTr))) {
+ if (getElement() == tdOrTr.getParentElement()) {
int childIndex = DOM
.getChildIndex(getElement(), tdOrTr);
String colKey = null;
@@ -2117,8 +2091,8 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
*/
public void onBrowserEvent(Event event) {
final Element tdOrTr = DOM.getParent(DOM.eventGetTarget(event));
- if (DOM.compare(getElement(), tdOrTr)
- || DOM.compare(getElement(), DOM.getParent(tdOrTr))) {
+ if (getElement() == tdOrTr
+ || getElement() == tdOrTr.getParentElement()) {
switch (DOM.eventGetType(event)) {
case Event.ONCLICK:
handleClickEvent(event);
@@ -2134,7 +2108,9 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
case Event.ONDBLCLICK:
handleClickEvent(event);
break;
-
+ case Event.ONCONTEXTMENU:
+ showContextMenu(event);
+ break;
default:
break;
}
@@ -2143,14 +2119,15 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
}
public void showContextMenu(Event event) {
- ApplicationConnection.getConsole().log("Context menu");
if (enabled && actionKeys != null) {
- int left = DOM.eventGetClientX(event);
- int top = DOM.eventGetClientY(event);
+ int left = event.getClientX();
+ int top = event.getClientY();
top += Window.getScrollTop();
left += Window.getScrollLeft();
client.getContextMenu().showAt(this, left, top);
}
+ event.cancelBubble(true);
+ event.preventDefault();
}
public boolean isSelected() {
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java
index dda4bdb8ec..4269b4984d 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java
@@ -19,7 +19,6 @@ import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.MouseEventDetails;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
-import com.itmill.toolkit.terminal.gwt.client.Util;
/**
*
@@ -193,7 +192,8 @@ public class ITree extends FlowPanel implements Paintable {
public TreeNode() {
constructDom();
- sinkEvents(Event.ONCLICK | Event.ONDBLCLICK | Event.ONMOUSEUP);
+ sinkEvents(Event.ONCLICK | Event.ONDBLCLICK | Event.ONMOUSEUP
+ | Event.ONCONTEXTMENU);
}
@Override
@@ -204,20 +204,21 @@ public class ITree extends FlowPanel implements Paintable {
}
final int type = DOM.eventGetType(event);
final Element target = DOM.eventGetTarget(event);
- if (emitClickEvents && DOM.compare(target, nodeCaptionSpan)
+ if (emitClickEvents && target == nodeCaptionSpan
&& (type == Event.ONDBLCLICK || type == Event.ONMOUSEUP)) {
fireClick(event);
}
if (type == Event.ONCLICK) {
- if (DOM.compare(getElement(), target)
- || DOM.compare(ie6compatnode, target)) {
+ if (getElement() == target || ie6compatnode == target) {
// state change
toggleState();
- } else if (!readonly && DOM.compare(target, nodeCaptionSpan)) {
+ } else if (!readonly && target == nodeCaptionSpan) {
// caption click = selection change && possible click event
toggleSelection();
}
DOM.eventCancelBubble(event, true);
+ } else if (type == Event.ONCONTEXTMENU) {
+ showContextMenu(event);
}
}
@@ -266,18 +267,6 @@ public class ITree extends FlowPanel implements Paintable {
setWidget(childNodeContainer);
}
- @Override
- public void onDetach() {
- Util.removeContextMenuEvent(nodeCaptionSpan);
- super.onDetach();
- }
-
- @Override
- public void onAttach() {
- attachContextMenuEvent(nodeCaptionSpan);
- super.onAttach();
- }
-
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
setText(uidl.getStringAttribute("caption"));
key = uidl.getStringAttribute("key");
@@ -423,27 +412,15 @@ public class ITree extends FlowPanel implements Paintable {
public void showContextMenu(Event event) {
if (!readonly && !disabled) {
if (actionKeys != null) {
- int left = DOM.eventGetClientX(event);
- int top = DOM.eventGetClientY(event);
+ int left = event.getClientX();
+ int top = event.getClientY();
top += Window.getScrollTop();
left += Window.getScrollLeft();
client.getContextMenu().showAt(this, left, top);
}
- DOM.eventCancelBubble(event, true);
+ event.cancelBubble(true);
+ event.preventDefault();
}
-
}
-
- private native void attachContextMenuEvent(Element el)
- /*-{
- var node = this;
- el.oncontextmenu = function(e) {
- if(!e)
- e = $wnd.event;
- node.@com.itmill.toolkit.terminal.gwt.client.ui.ITree.TreeNode::showContextMenu(Lcom/google/gwt/user/client/Event;)(e);
- return false;
- };
- }-*/;
-
}
}