1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.utgenome.gwt.ipad.client;
24
25 import org.utgenome.gwt.ipad.event.HasTouchHandlers;
26 import org.utgenome.gwt.ipad.event.TouchCancelEvent;
27 import org.utgenome.gwt.ipad.event.TouchCancelHandler;
28 import org.utgenome.gwt.ipad.event.TouchEndEvent;
29 import org.utgenome.gwt.ipad.event.TouchEndHandler;
30 import org.utgenome.gwt.ipad.event.TouchMoveEvent;
31 import org.utgenome.gwt.ipad.event.TouchMoveHandler;
32 import org.utgenome.gwt.ipad.event.TouchStartEvent;
33 import org.utgenome.gwt.ipad.event.TouchStartHandler;
34 import org.utgenome.gwt.utgb.client.util.BrowserInfo;
35
36 import com.google.gwt.event.shared.HandlerRegistration;
37 import com.google.gwt.user.client.ui.Composite;
38
39
40
41
42
43
44
45 public class TouchableComposite extends Composite implements HasTouchHandlers {
46
47 private static interface Registrer {
48 public HandlerRegistration addTouchStartHandler(TouchStartHandler handler);
49 public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler);
50 public HandlerRegistration addTouchEndHandler(TouchEndHandler handler);
51 public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler);
52 }
53
54
55 private class DefaultRegistrerImpl implements Registrer {
56 public HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
57 return addDomHandler(handler, TouchStartEvent.getType());
58 }
59
60 public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
61 return addDomHandler(handler, TouchMoveEvent.getType());
62 }
63
64 public HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
65 return addDomHandler(handler, TouchEndEvent.getType());
66 }
67
68 public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
69 return addDomHandler(handler, TouchCancelEvent.getType());
70 }
71 }
72
73 private class NonIPadRegistrerImpl implements Registrer {
74 public HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
75 return null;
76 }
77
78 public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
79 return null;
80 }
81
82 public HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
83 return null;
84 }
85
86 public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
87 return null;
88 }
89 }
90
91 private Registrer impl;
92
93 {
94 if(BrowserInfo.isMobileSafari())
95 impl = new DefaultRegistrerImpl();
96 else
97 impl = new NonIPadRegistrerImpl();
98 }
99
100 public HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
101 return impl.addTouchStartHandler(handler);
102 }
103
104 public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
105 return impl.addTouchMoveHandler(handler);
106 }
107
108 public HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
109 return impl.addTouchEndHandler(handler);
110 }
111
112 public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
113 return impl.addTouchCancelHandler(handler);
114 }
115 }