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.BrowserService;
35 import org.utgenome.gwt.utgb.client.util.BrowserInfo;
36
37 import com.google.gwt.event.shared.HandlerRegistration;
38 import com.google.gwt.user.client.ui.FocusPanel;
39
40
41
42
43
44
45
46 public class TouchableFocusPanel extends FocusPanel implements HasTouchHandlers {
47
48 private static interface Registrer {
49 public HandlerRegistration addTouchStartHandler(TouchStartHandler handler);
50 public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler);
51 public HandlerRegistration addTouchEndHandler(TouchEndHandler handler);
52 public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler);
53 }
54
55
56 private class DefaultRegistrerImpl implements Registrer {
57 public HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
58 return addDomHandler(handler, TouchStartEvent.getType());
59 }
60
61 public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
62 return addDomHandler(handler, TouchMoveEvent.getType());
63 }
64
65 public HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
66 return addDomHandler(handler, TouchEndEvent.getType());
67 }
68
69 public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
70 return addDomHandler(handler, TouchCancelEvent.getType());
71 }
72 }
73
74 private class NonIPadRegistrerImpl implements Registrer {
75 public HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
76 return null;
77 }
78
79 public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
80 return null;
81 }
82
83 public HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
84 return null;
85 }
86
87 public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
88 return null;
89 }
90 }
91
92 private Registrer impl;
93
94 {
95 if(BrowserInfo.isMobileSafari())
96 impl = new DefaultRegistrerImpl();
97 else
98 impl = new NonIPadRegistrerImpl();
99 }
100
101 public HandlerRegistration addTouchStartHandler(TouchStartHandler handler) {
102 return impl.addTouchStartHandler(handler);
103 }
104
105 public HandlerRegistration addTouchMoveHandler(TouchMoveHandler handler) {
106 return impl.addTouchMoveHandler(handler);
107 }
108
109 public HandlerRegistration addTouchEndHandler(TouchEndHandler handler) {
110 return impl.addTouchEndHandler(handler);
111 }
112
113 public HandlerRegistration addTouchCancelHandler(TouchCancelHandler handler) {
114 return impl.addTouchCancelHandler(handler);
115 }
116 }