View Javadoc

1   /*
2    * Copyright (c) 2010 Alex Moffat
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20   * THE SOFTWARE.
21   */
22  
23  package com.google.gwt.user.client.impl;
24  
25  import com.google.gwt.user.client.Element;
26  
27  /**
28   * Add handling for touch events to standard DOM impl used by Safari.
29   *
30   * @author amoffat Alex Moffat
31   */
32  class DOMImplMobileSafari extends DOMImplSafari {
33  
34    public native int eventGetTypeInt(String eventType) /*-{
35      switch (eventType) {
36      case "blur": return 0x01000;
37      case "change": return 0x00400;
38      case "click": return 0x00001;
39      case "dblclick": return 0x00002;
40      case "focus": return 0x00800;
41      case "keydown": return 0x00080;
42      case "keypress": return 0x00100;
43      case "keyup": return 0x00200;
44      case "load": return 0x08000;
45      case "losecapture": return 0x02000;
46      case "mousedown": return 0x00004;
47      case "mousemove": return 0x00040;
48      case "mouseout": return 0x00020;
49      case "mouseover": return 0x00010;
50      case "mouseup": return 0x00008;
51      case "scroll": return 0x04000;
52      case "error": return 0x10000;
53      case "mousewheel": return 0x20000;
54      case "DOMMouseScroll": return 0x20000;
55      case "contextmenu": return 0x40000;
56      case "paste": return 0x80000;
57      case "touchstart": return 0x100000;
58      case "touchmove": return 0x200000;
59      case "touchcancel": return 0x400000;
60      case "touchend": return 0x800000;
61      }
62    }-*/;
63   
64    protected native void sinkEventsImpl(Element elem, int bits) /*-{
65      var chMask = (elem.__eventBits || 0) ^ bits;
66      elem.__eventBits = bits;
67      if (!chMask) return;
68  
69      if (chMask & 0x00001) elem.onclick       = (bits & 0x00001) ?
70          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
71      if (chMask & 0x00002) elem.ondblclick    = (bits & 0x00002) ?
72          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
73      if (chMask & 0x00004) elem.onmousedown   = (bits & 0x00004) ?
74          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
75      if (chMask & 0x00008) elem.onmouseup     = (bits & 0x00008) ?
76          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
77      if (chMask & 0x00010) elem.onmouseover   = (bits & 0x00010) ?
78          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
79      if (chMask & 0x00020) elem.onmouseout    = (bits & 0x00020) ?
80          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
81      if (chMask & 0x00040) elem.onmousemove   = (bits & 0x00040) ?
82          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
83      if (chMask & 0x00080) elem.onkeydown     = (bits & 0x00080) ?
84          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
85      if (chMask & 0x00100) elem.onkeypress    = (bits & 0x00100) ?
86          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
87      if (chMask & 0x00200) elem.onkeyup       = (bits & 0x00200) ?
88          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
89      if (chMask & 0x00400) elem.onchange      = (bits & 0x00400) ?
90          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
91      if (chMask & 0x00800) elem.onfocus       = (bits & 0x00800) ?
92          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
93      if (chMask & 0x01000) elem.onblur        = (bits & 0x01000) ?
94          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
95      if (chMask & 0x02000) elem.onlosecapture = (bits & 0x02000) ?
96          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
97      if (chMask & 0x04000) elem.onscroll      = (bits & 0x04000) ?
98          @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
99      if (chMask & 0x08000) elem.onload        = (bits & 0x08000) ?
100         @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
101     if (chMask & 0x10000) elem.onerror       = (bits & 0x10000) ?
102         @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
103     if (chMask & 0x20000) elem.onmousewheel  = (bits & 0x20000) ?
104         @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
105     if (chMask & 0x40000) elem.oncontextmenu = (bits & 0x40000) ?
106         @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
107     if (chMask & 0x80000) elem.onpaste       = (bits & 0x80000) ?
108         @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
109 
110     // Handle touch events.
111     if (chMask & 0x100000) elem.ontouchstart = (bits & 0x100000) ?
112         @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
113     if (chMask & 0x200000) elem.ontouchmove = (bits & 0x200000) ?
114         @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
115     if (chMask & 0x400000) elem.ontouchcancel = (bits & 0x400000) ?
116         @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
117     if (chMask & 0x800000) elem.ontouchend = (bits & 0x800000) ?
118         @com.google.gwt.user.client.impl.DOMImplStandard::dispatchEvent : null;
119   }-*/;
120 }