Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PointerEvent.java 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright 2000-2013 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.event;
  17. import com.google.gwt.dom.client.NativeEvent;
  18. import com.google.gwt.event.dom.client.MouseEvent;
  19. import com.google.gwt.event.shared.EventHandler;
  20. /**
  21. * Abstract class representing Pointer events.
  22. *
  23. * @param <H>
  24. * handler type
  25. *
  26. * @since 7.2
  27. */
  28. public abstract class PointerEvent<H extends EventHandler> extends
  29. MouseEvent<H> {
  30. enum EventType {
  31. PointerDown, PointerMove, PointerOut, PointerOver, PointerUp, PointerCancel;
  32. String getNativeEventName() {
  33. return PointerEventSupport.getNativeEventName(this);
  34. }
  35. }
  36. public static final String TYPE_UNKNOWN = "";
  37. public static final String TYPE_TOUCH = "touch";
  38. public static final String TYPE_PEN = "pen";
  39. public static final String TYPE_MOUSE = "mouse";
  40. /**
  41. * Gets a unique identifier for the pointer that caused this event. The
  42. * identifiers of previously active but retired pointers may be recycled.
  43. *
  44. * @return unique pointer id
  45. */
  46. public final int getPointerId() {
  47. return getPointerId(getNativeEvent());
  48. }
  49. /**
  50. * Gets the width of the contact geometry of the pointer in CSS pixels.
  51. *
  52. * @return width in CSS pixels
  53. */
  54. public final int getWidth() {
  55. return getWidth(getNativeEvent());
  56. }
  57. /**
  58. * Gets the height of the contact geometry of the pointer in CSS pixels.
  59. *
  60. * @return height in CSS pixels.
  61. */
  62. public final int getHeight() {
  63. return getHeight(getNativeEvent());
  64. }
  65. /**
  66. * Gets the pressure of the pointer input as a value in the range of [0, 1]
  67. * where 0 and 1 represent the minimum and maximum, respectively.
  68. *
  69. * @return input pressure as a value between 0 and 1
  70. */
  71. public final double getPressure() {
  72. return getPressure(getNativeEvent());
  73. }
  74. /**
  75. * Gets the angle between the Y-Z plane and the plane containing both the
  76. * transducer and the Y axis. A positive tilt is to the right.
  77. *
  78. * @return the tilt along the X axis as degrees in the range of [-90, 90],
  79. * or 0 if the device does not support tilt
  80. */
  81. public final double getTiltX() {
  82. return getTiltX(getNativeEvent());
  83. }
  84. /**
  85. * Gets the angle between the X-Z plane and the plane containing both the
  86. * transducer and the X axis. A positive tilt is towards the user.
  87. *
  88. * @return the tilt along the Y axis as degrees in the range of [-90, 90],
  89. * or 0 if the device does not support tilt
  90. */
  91. public final double getTiltY() {
  92. return getTiltY(getNativeEvent());
  93. }
  94. /**
  95. * Gets the type of the pointer device that caused this event.
  96. *
  97. * @see PointerEvent#TYPE_UNKNOWN
  98. * @see PointerEvent#TYPE_TOUCH
  99. * @see PointerEvent#TYPE_PEN
  100. * @see PointerEvent#TYPE_MOUSE
  101. *
  102. * @return a String indicating the type of the pointer device
  103. */
  104. public final String getPointerType() {
  105. return getPointerType(getNativeEvent());
  106. }
  107. /**
  108. * Indicates whether the pointer is the primary pointer of this type.
  109. *
  110. * @return true if the pointer is the primary pointer, otherwise false
  111. */
  112. public final boolean isPrimary() {
  113. return isPrimary(getNativeEvent());
  114. }
  115. private static native final int getPointerId(NativeEvent e)
  116. /*-{
  117. return e.pointerId;
  118. }-*/;
  119. private static native final int getWidth(NativeEvent e)
  120. /*-{
  121. return e.width;
  122. }-*/;
  123. private static native final int getHeight(NativeEvent e)
  124. /*-{
  125. return e.height;
  126. }-*/;
  127. private static native final double getPressure(NativeEvent e)
  128. /*-{
  129. return e.pressure;
  130. }-*/;
  131. private static native final double getTiltX(NativeEvent e)
  132. /*-{
  133. return e.tiltX;
  134. }-*/;
  135. private static native final double getTiltY(NativeEvent e)
  136. /*-{
  137. return e.tiltY;
  138. }-*/;
  139. private static native final String getPointerType(NativeEvent e)
  140. /*-{
  141. var pointerType = e.pointerType;
  142. if (typeof pointerType === "number") {
  143. pointerType = [ , , "touch", "pen", "mouse" ][pointerType];
  144. }
  145. return pointerType || "";
  146. }-*/;
  147. private static native final boolean isPrimary(NativeEvent e)
  148. /*-{
  149. return e.isPrimary;
  150. }-*/;
  151. }