|
@@ -1,62 +1,62 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.client.widgets.nonpublic.external; |
3 |
|
- |
|
4 |
|
- |
import com.google.gwt.user.client.*; |
5 |
|
- |
import com.google.gwt.user.client.ui.*; |
6 |
|
- |
|
7 |
|
- |
/** |
8 |
|
- |
* A controller which interprets drag events and delegates the mouse drag |
9 |
|
- |
* operation to a delegate. |
10 |
|
- |
* <p/> |
11 |
|
- |
* see asquare.gwt.tk.client.ui.behavior.DragGesture |
12 |
|
- |
*/ |
13 |
|
- |
public class DragController extends MouseController { |
14 |
|
- |
private MouseEvent m_previousEvent; |
15 |
|
- |
|
16 |
|
- |
/** |
17 |
|
- |
* Creates a new DragController which delegates to the specified |
18 |
|
- |
* handler. |
19 |
|
- |
* |
20 |
|
- |
* @param handler a delegate object, or <code>null</code> |
21 |
|
- |
*/ |
22 |
|
- |
public DragController( MouseHandler handler ) { |
23 |
|
- |
super( Event.ONMOUSEDOWN | Event.ONMOUSEMOVE | Event.ONMOUSEUP | Event.ONLOSECAPTURE, DragController.class, handler ); |
24 |
|
- |
} |
25 |
|
- |
|
26 |
|
- |
@Override |
27 |
|
- |
public void onBrowserEvent( Widget widget, Event event ) { |
28 |
|
- |
super.onBrowserEvent( widget, event ); |
29 |
|
- |
if ( DOM.eventGetType( event ) == Event.ONLOSECAPTURE ) { |
30 |
|
- |
/* |
31 |
|
- |
* Firefox loses the mouseup if released outside the client area. |
32 |
|
- |
* But we do get an onlosecapture event. Not ideal, but it prevents |
33 |
|
- |
* a invalid state (dragging while mouse is released). |
34 |
|
- |
* http://code.google.com/p/google-web-toolkit/issues/detail?id=243 |
35 |
|
- |
*/ |
36 |
|
- |
onMouseUp( m_previousEvent ); |
37 |
|
- |
} |
38 |
|
- |
} |
39 |
|
- |
|
40 |
|
- |
@Override |
41 |
|
- |
protected void onMouseDown( MouseEvent e ) { |
42 |
|
- |
DOM.setCapture( e.getReceiver().getElement() ); |
43 |
|
- |
m_previousEvent = e; |
44 |
|
- |
super.onMouseDown( e ); |
45 |
|
- |
} |
46 |
|
- |
|
47 |
|
- |
@Override |
48 |
|
- |
protected void onMouseMove( MouseEvent e ) { |
49 |
|
- |
m_previousEvent = e; |
50 |
|
- |
super.onMouseMove( e ); |
51 |
|
- |
} |
52 |
|
- |
|
53 |
|
- |
@Override |
54 |
|
- |
protected void onMouseUp( MouseEvent e ) { |
55 |
|
- |
if ( m_previousEvent != null ) { |
56 |
|
- |
// do last to prevent reentrancy via ONLOSECAPTURE |
57 |
|
- |
DOM.releaseCapture( e.getReceiver().getElement() ); |
58 |
|
- |
} |
59 |
|
- |
super.onMouseUp( e ); |
60 |
|
- |
m_previousEvent = null; |
61 |
|
- |
} |
62 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.client.widgets.nonpublic.external; |
|
3 |
+ |
|
|
4 |
+ |
import com.google.gwt.user.client.*; |
|
5 |
+ |
import com.google.gwt.user.client.ui.*; |
|
6 |
+ |
|
|
7 |
+ |
/** |
|
8 |
+ |
* A controller which interprets drag events and delegates the mouse drag |
|
9 |
+ |
* operation to a delegate. |
|
10 |
+ |
* <p/> |
|
11 |
+ |
* see asquare.gwt.tk.client.ui.behavior.DragGesture |
|
12 |
+ |
*/ |
|
13 |
+ |
public class DragController extends MouseController { |
|
14 |
+ |
private MouseEvent m_previousEvent; |
|
15 |
+ |
|
|
16 |
+ |
/** |
|
17 |
+ |
* Creates a new DragController which delegates to the specified |
|
18 |
+ |
* handler. |
|
19 |
+ |
* |
|
20 |
+ |
* @param handler a delegate object, or <code>null</code> |
|
21 |
+ |
*/ |
|
22 |
+ |
public DragController( MouseHandler handler ) { |
|
23 |
+ |
super( Event.ONMOUSEDOWN | Event.ONMOUSEMOVE | Event.ONMOUSEUP | Event.ONLOSECAPTURE, DragController.class, handler ); |
|
24 |
+ |
} |
|
25 |
+ |
|
|
26 |
+ |
@Override |
|
27 |
+ |
public void onBrowserEvent( Widget widget, Event event ) { |
|
28 |
+ |
super.onBrowserEvent( widget, event ); |
|
29 |
+ |
if ( DOM.eventGetType( event ) == Event.ONLOSECAPTURE ) { |
|
30 |
+ |
/* |
|
31 |
+ |
* Firefox loses the mouseup if released outside the client area. |
|
32 |
+ |
* But we do get an onlosecapture event. Not ideal, but it prevents |
|
33 |
+ |
* a invalid state (dragging while mouse is released). |
|
34 |
+ |
* http://code.google.com/p/google-web-toolkit/issues/detail?id=243 |
|
35 |
+ |
*/ |
|
36 |
+ |
onMouseUp( m_previousEvent ); |
|
37 |
+ |
} |
|
38 |
+ |
} |
|
39 |
+ |
|
|
40 |
+ |
@Override |
|
41 |
+ |
protected void onMouseDown( MouseEvent e ) { |
|
42 |
+ |
DOM.setCapture( e.getReceiver().getElement() ); |
|
43 |
+ |
m_previousEvent = e; |
|
44 |
+ |
super.onMouseDown( e ); |
|
45 |
+ |
} |
|
46 |
+ |
|
|
47 |
+ |
@Override |
|
48 |
+ |
protected void onMouseMove( MouseEvent e ) { |
|
49 |
+ |
m_previousEvent = e; |
|
50 |
+ |
super.onMouseMove( e ); |
|
51 |
+ |
} |
|
52 |
+ |
|
|
53 |
+ |
@Override |
|
54 |
+ |
protected void onMouseUp( MouseEvent e ) { |
|
55 |
+ |
if ( m_previousEvent != null ) { |
|
56 |
+ |
// do last to prevent reentrancy via ONLOSECAPTURE |
|
57 |
+ |
DOM.releaseCapture( e.getReceiver().getElement() ); |
|
58 |
+ |
} |
|
59 |
+ |
super.onMouseUp( e ); |
|
60 |
+ |
m_previousEvent = null; |
|
61 |
+ |
} |
|
62 |
+ |
} |