@@ -28,7 +28,9 @@ goog.require('bot.Error');
28
28
goog . require ( 'bot.ErrorCode' ) ;
29
29
goog . require ( 'bot.dom' ) ;
30
30
goog . require ( 'bot.events.EventType' ) ;
31
+ goog . require ( 'goog.dom.TagName' ) ;
31
32
goog . require ( 'goog.math.Coordinate' ) ;
33
+ goog . require ( 'goog.userAgent.product' ) ;
32
34
33
35
34
36
@@ -55,7 +57,7 @@ goog.inherits(bot.Touchscreen, bot.Device);
55
57
56
58
57
59
/** @private {boolean} */
58
- bot . Touchscreen . prototype . hasMovedAfterPress_ = false ;
60
+ bot . Touchscreen . prototype . fireMouseEventsOnRelease_ = true ;
59
61
60
62
61
63
/** @private {boolean} */
@@ -88,16 +90,17 @@ bot.Touchscreen.prototype.press = function(opt_press2) {
88
90
'Cannot press touchscreen when already pressed.' ) ;
89
91
}
90
92
91
- this . hasMovedAfterPress_ = false ;
92
93
this . touchIdentifier_ = this . touchCounter_ ++ ;
93
94
if ( opt_press2 ) {
94
95
this . touchIdentifier2_ = this . touchCounter_ ++ ;
95
96
}
96
97
97
98
if ( bot . userAgent . IE_DOC_10 ) {
99
+ this . fireMouseEventsOnRelease_ = true ;
98
100
this . firePointerEvents_ ( bot . Touchscreen . fireSinglePressPointer_ ) ;
99
101
} else {
100
- this . fireTouchEvent_ ( bot . events . EventType . TOUCHSTART ) ;
102
+ this . fireMouseEventsOnRelease_ = this . fireTouchEvent_ (
103
+ bot . events . EventType . TOUCHSTART ) ;
101
104
}
102
105
} ;
103
106
@@ -153,11 +156,11 @@ bot.Touchscreen.prototype.move = function(element, coords, opt_coords2) {
153
156
154
157
if ( this . isPressed ( ) ) {
155
158
if ( ! bot . userAgent . IE_DOC_10 ) {
156
- this . hasMovedAfterPress_ = true ;
159
+ this . fireMouseEventsOnRelease_ = false ;
157
160
this . fireTouchEvent_ ( bot . events . EventType . TOUCHMOVE ) ;
158
161
} else if ( ! this . cancelled_ ) {
159
162
if ( element != originalElement ) {
160
- this . hasMovedAfterPress_ = true ;
163
+ this . fireMouseEventsOnRelease_ = false ;
161
164
}
162
165
if ( bot . Touchscreen . hasMsTouchActionsEnabled_ ( element ) ) {
163
166
this . firePointerEvents_ ( bot . Touchscreen . fireSingleMovePointer_ ) ;
@@ -189,6 +192,7 @@ bot.Touchscreen.prototype.isPressed = function() {
189
192
* A helper function to fire touch events.
190
193
*
191
194
* @param {bot.events.EventType } type Event type.
195
+ * @return {boolean } Whether the event fired successfully or was cancelled.
192
196
* @private
193
197
*/
194
198
bot . Touchscreen . prototype . fireTouchEvent_ = function ( type ) {
@@ -202,8 +206,8 @@ bot.Touchscreen.prototype.fireTouchEvent_ = function(type) {
202
206
touchIdentifier2 = this . touchIdentifier2_ ;
203
207
coords2 = this . clientXY2_ ;
204
208
}
205
- this . fireTouchEvent ( type , this . touchIdentifier_ , this . clientXY_ ,
206
- touchIdentifier2 , coords2 ) ;
209
+ return this . fireTouchEvent ( type , this . touchIdentifier_ , this . clientXY_ ,
210
+ touchIdentifier2 , coords2 ) ;
207
211
} ;
208
212
209
213
@@ -213,13 +217,22 @@ bot.Touchscreen.prototype.fireTouchEvent_ = function(type) {
213
217
* @private
214
218
*/
215
219
bot . Touchscreen . prototype . fireTouchReleaseEvents_ = function ( ) {
216
- this . fireTouchEvent_ ( bot . events . EventType . TOUCHEND ) ;
217
-
218
- // If no movement occurred since press, TouchScreen.Release will fire the
219
- // legacy mouse events: mousemove, mousedown, mouseup, and click
220
- // after the touch events have been fired. The click button should be zero
221
- // and only one mousemove should fire.
222
- if ( ! this . hasMovedAfterPress_ ) {
220
+ var touchendSuccess = this . fireTouchEvent_ ( bot . events . EventType . TOUCHEND ) ;
221
+
222
+ // In general, TouchScreen.Release will fire the legacy mouse events:
223
+ // mousemove, mousedown, mouseup, and click after the touch events have been
224
+ // fired. The click button should be zero and only one mousemove should fire.
225
+ // Under the following cases, mouse events should not be fired:
226
+ // 1. Movement has occurred since press.
227
+ // 2. Any event handler for touchstart has called preventDefault().
228
+ // 3. Any event handler for touchend has called preventDefault(), and browser
229
+ // is Mobile Safari or Chrome.
230
+ var fireMouseEvents =
231
+ this . fireMouseEventsOnRelease_ &&
232
+ ( touchendSuccess || ! ( bot . userAgent . IOS ||
233
+ goog . userAgent . product . CHROME ) ) ;
234
+
235
+ if ( fireMouseEvents ) {
223
236
this . fireMouseEvent ( bot . events . EventType . MOUSEMOVE , this . clientXY_ , 0 ) ;
224
237
var performFocus = this . fireMouseEvent ( bot . events . EventType . MOUSEDOWN ,
225
238
this . clientXY_ , 0 ) ;
@@ -331,7 +344,7 @@ bot.Touchscreen.fireSingleReleasePointer_ = function(ts, element, coords, id,
331
344
id ) ;
332
345
333
346
// Fire a click.
334
- if ( ! ts . hasMovedAfterPress_ ) {
347
+ if ( ts . fireMouseEventsOnRelease_ ) {
335
348
ts . maybeToggleOption ( ) ;
336
349
if ( ! ( bot . userAgent . WINDOWS_PHONE &&
337
350
bot . dom . isElement ( element , goog . dom . TagName . OPTION ) ) ) {
0 commit comments