| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview Touch Handler. Class that handles all touch events and | 6 * @fileoverview Touch Handler. Class that handles all touch events and |
| 7 * uses them to interpret higher level gestures and behaviors. TouchEvent is a | 7 * uses them to interpret higher level gestures and behaviors. TouchEvent is a |
| 8 * built in mobile safari type: | 8 * built in mobile safari type: |
| 9 * http://developer.apple.com/safari/library/documentation/UserExperience/Refere
nce/TouchEventClassReference/TouchEvent/TouchEvent.html. | 9 * http://developer.apple.com/safari/library/documentation/UserExperience/Refere
nce/TouchEventClassReference/TouchEvent/TouchEvent.html. |
| 10 * This class is intended to work with all webkit browsers, tested on Chrome and | 10 * This class is intended to work with all webkit browsers, tested on Chrome and |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * behavior will NOT perform the actual dragging (redrawing the element) | 24 * behavior will NOT perform the actual dragging (redrawing the element) |
| 25 * for you, this responsibility is left to the client code. | 25 * for you, this responsibility is left to the client code. |
| 26 * | 26 * |
| 27 * Long press: | 27 * Long press: |
| 28 * When your element is touched and held without any drag occuring, the | 28 * When your element is touched and held without any drag occuring, the |
| 29 * LONG_PRESS event will fire. | 29 * LONG_PRESS event will fire. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 // Use an anonymous function to enable strict mode just for this file (which | 32 // Use an anonymous function to enable strict mode just for this file (which |
| 33 // will be concatenated with other files when embedded in Chrome) | 33 // will be concatenated with other files when embedded in Chrome) |
| 34 var TouchHandler = (function() { | 34 cr.define('cr.ui', function() { |
| 35 'use strict'; | 35 'use strict'; |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * A TouchHandler attaches to an Element, listents for low-level touch (or | 38 * A TouchHandler attaches to an Element, listents for low-level touch (or |
| 39 * mouse) events and dispatching higher-level events on the element. | 39 * mouse) events and dispatching higher-level events on the element. |
| 40 * @param {!Element} element The element to listen on and fire events | 40 * @param {!Element} element The element to listen on and fire events |
| 41 * for. | 41 * for. |
| 42 * @constructor | 42 * @constructor |
| 43 */ | 43 */ |
| 44 function TouchHandler(element) { | 44 function TouchHandler(element) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 // Fired whenever a touch that is being tracked has been released. | 120 // Fired whenever a touch that is being tracked has been released. |
| 121 // Correlates 1:1 with a TOUCH_START. | 121 // Correlates 1:1 with a TOUCH_START. |
| 122 TOUCH_END: 'touchHandler:touch_end' | 122 TOUCH_END: 'touchHandler:touch_end' |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 | 125 |
| 126 /** | 126 /** |
| 127 * The type of event sent by TouchHandler | 127 * The type of event sent by TouchHandler |
| 128 * @constructor | 128 * @constructor |
| 129 * @param {string} type The type of event (one of Grabber.EventType). | 129 * @param {string} type The type of event (one of cr.ui.Grabber.EventType). |
| 130 * @param {boolean} bubbles Whether or not the event should bubble. | 130 * @param {boolean} bubbles Whether or not the event should bubble. |
| 131 * @param {number} clientX The X location of the touch. | 131 * @param {number} clientX The X location of the touch. |
| 132 * @param {number} clientY The Y location of the touch. | 132 * @param {number} clientY The Y location of the touch. |
| 133 * @param {!Element} touchedElement The element at the current location of the | 133 * @param {!Element} touchedElement The element at the current location of the |
| 134 * touch. | 134 * touch. |
| 135 */ | 135 */ |
| 136 TouchHandler.Event = function(type, bubbles, clientX, clientY, | 136 TouchHandler.Event = function(type, bubbles, clientX, clientY, |
| 137 touchedElement) { | 137 touchedElement) { |
| 138 var event = document.createEvent('Event'); | 138 var event = document.createEvent('Event'); |
| 139 event.initEvent(type, bubbles, true); | 139 event.initEvent(type, bubbles, true); |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 if (isDrag) { | 839 if (isDrag) { |
| 840 event.dragDeltaX = clientX - this.startTouchX_; | 840 event.dragDeltaX = clientX - this.startTouchX_; |
| 841 event.dragDeltaY = clientY - this.startTouchY_; | 841 event.dragDeltaY = clientY - this.startTouchY_; |
| 842 } | 842 } |
| 843 | 843 |
| 844 this.element_.dispatchEvent(event); | 844 this.element_.dispatchEvent(event); |
| 845 return event.enableDrag; | 845 return event.enableDrag; |
| 846 } | 846 } |
| 847 }; | 847 }; |
| 848 | 848 |
| 849 return TouchHandler; | 849 return { |
| 850 })(); | 850 TouchHandler: TouchHandler |
| 851 }; |
| 852 }); |
| OLD | NEW |