Skip to content

Commit

Permalink
Add a workaround to prevent the graph from being dragged around.
Browse files Browse the repository at this point in the history
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
tsuna committed Jan 21, 2013
1 parent 497a820 commit 6c1dda8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/tsd/client/QueryUi.java
Expand Up @@ -1080,10 +1080,14 @@ private final class ZoomBox extends HTML
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
Expand All @@ -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);
Expand Down

0 comments on commit 6c1dda8

Please sign in to comment.