Permalink
Browse files

Add a workaround to prevent the graph from being dragged around.

On mouse-down events we need to prevent the event's default behavior as
it may make the browser start dragging the image around.  We don't want,
we want to handle the dragging ourselves for the drag-to-zoom box.

However preventing the event's default behavior has another obnoxious
consequence: it doesn't remove the focus from whatever had it previously,
which may cause the image to not get reloaded if a text field was being
changed and the user simply "clicked away" on the image.
  • Loading branch information...
1 parent 497a820 commit 6c1dda8b27a94f00f516ebd4218e85133ff929c8 @tsuna tsuna committed Jan 21, 2013
Showing with 7 additions and 0 deletions.
  1. +7 −0 src/tsd/client/QueryUi.java
@@ -1080,10 +1080,14 @@ static void setTextAlignCenter(final Element element) {
style.setProperty("background", "red");
style.setProperty("filter", "alpha(opacity=50)");
style.setProperty("opacity", "0.4");
+ // Needed to make this object focusable.
+ super.getElement().setAttribute("tabindex", "-1");
}
@Override
public void onMouseDown(final MouseDownEvent event) {
+ event.preventDefault();
+
// Check if the zoom selection is active, if so, it's possible that the
// mouse left the browser mid-selection and got stuck enabled even
// though the mouse isn't still pressed. If that's the case, do a similar
@@ -1104,6 +1108,9 @@ public void onMouseDown(final MouseDownEvent event) {
super.setWidth("0px");
super.setHeight("0px");
super.setVisible(true);
+ // Workaround to steal the focus from whatever had it previously,
+ // which may cause the graph to reload as a side effect.
+ super.getElement().focus();
graph_move_handler = graph.addMouseMoveHandler(this);
box_move_handler = super.addMouseMoveHandler(this);

0 comments on commit 6c1dda8

Please sign in to comment.