Unsinking mouse over/out/move events for a CellList/Tree/Table

111 views
Skip to first unread message

Paul Schwarz

unread,
Jun 23, 2010, 4:51:50 AM6/23/10
to Google Web Toolkit
Summary: in a CellList I want to sink the ONCLICK and ONCONTEXTMENU
events to be handled by my Cell's onBrowserEvent method, but I don't
want any mouse over/out/move events, but cannot seem to unsink them.

In 2.1 M1 we have CellList. If you look at the constructor of CellList
you'll see on line 139
sinkEvents(Event.ONCLICK | Event.ONCHANGE | Event.MOUSEEVENTS);

So the CellList is presuming that these are the events that we're
interested in. Now I have created my own concrete implementation of an
AbstractCell.
Other implementations are TextCell, ButtonCell, CheckboxCell, etc. So
I have followed those as examples, but have created my own Cell
implementation.

One of the methods that can be implemented is:
public abstract Object onBrowserEvent(Element parent, C value, Object
viewData, NativeEvent event, ValueUpdater<C> valueUpdater);

... and in that method I am interested in a Click event and a Context
menu event. I notice that my CPU usage peaks at 50ish% when I move my
mouse around. Sure enough GWT is picking up all the mouse over, mouse
out, mouse move events as well. AND I'm not getting my Context menu
event (because I haven't explicitly sunk it yet).

So in my UI class that keeps an instance of this CellList, in the
constructor I have:
myCellList.sinkEvents(Event.ONCONTEXTMENU);
myCellList.unsinkEvents(Event.MOUSEEVENTS);

... so now I am getting my Context menu event, but I am still getting
a flood of mouse events as I wiggle my mouse over the Cells in the
CellList. I have tried explicitly unsinking Event.ONMOUSEOVER et al.
but that has no effect either.

Either this is a bug, or more likely I am unsinking the event on the
wrong element or unsinking in the wrong order, or I am missing
something altogether.

Any ideas?

Thomas Broyer

unread,
Jun 23, 2010, 6:57:41 AM6/23/10
to Google Web Toolkit
Widget#sinkEvents defers the call to DOM.sinkEvents until the widget
is attached, but unsinkEvents doesn't, and don't update the
"eventsToSink" private variable (this could be seen as a bug in
Widget, which should override unsinkEvents too).
The workaround seems to be (not tested) to call unsinkEvents from an
onLoad override.

Paul Schwarz

unread,
Jun 23, 2010, 7:12:55 AM6/23/10
to Google Web Toolkit
Thanks Thomas,

Test and works as suggested. The class owning my CellList extends
Composite and I now have overridden the onLoad method like this:
@Override
protected void onLoad() {
myCellListView.unsinkEvents(Event.MOUSEEVENTS);
}

... and no longer are the mouse over/out/move events flooding into my
console. Interesting I still get a CPU spike when I wiggle my mouse,
but I am in hosted mode, could this have something to do with it?
Could it be that when I compile to javascript these mouse events are
genuinely ignored and have no processing overhead?

It's not a biggie, it's just that I am rendering a non-trivial view of
data in my CellList and performance is essential.
Reply all
Reply to author
Forward
0 new messages