| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 This contains an implementation of the EventTarget interface | 6 * @fileoverview This contains an implementation of the EventTarget interface |
| 7 * as defined by DOM Level 2 Events. | 7 * as defined by DOM Level 2 Events. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 * @return {boolean} Whether the default action was prevented. If someone | 69 * @return {boolean} Whether the default action was prevented. If someone |
| 70 * calls preventDefault on the event object then this returns false. | 70 * calls preventDefault on the event object then this returns false. |
| 71 */ | 71 */ |
| 72 dispatchEvent: function(event) { | 72 dispatchEvent: function(event) { |
| 73 if (!this.listeners_) | 73 if (!this.listeners_) |
| 74 return true; | 74 return true; |
| 75 | 75 |
| 76 // Since we are using DOM Event objects we need to override some of the | 76 // Since we are using DOM Event objects we need to override some of the |
| 77 // properties and methods so that we can emulate this correctly. | 77 // properties and methods so that we can emulate this correctly. |
| 78 var self = this; | 78 var self = this; |
| 79 event.__defineGetter__('target', function() { return self; }); | 79 event.__defineGetter__('target', function() { |
| 80 return self; |
| 81 }); |
| 80 | 82 |
| 81 var type = event.type; | 83 var type = event.type; |
| 82 var prevented = 0; | 84 var prevented = 0; |
| 83 if (type in this.listeners_) { | 85 if (type in this.listeners_) { |
| 84 // Clone to prevent removal during dispatch | 86 // Clone to prevent removal during dispatch |
| 85 var handlers = this.listeners_[type].concat(); | 87 var handlers = this.listeners_[type].concat(); |
| 86 for (var i = 0, handler; handler = handlers[i]; i++) { | 88 for (var i = 0, handler; handler = handlers[i]; i++) { |
| 87 if (handler.handleEvent) | 89 if (handler.handleEvent) |
| 88 prevented |= handler.handleEvent.call(handler, event) === false; | 90 prevented |= handler.handleEvent.call(handler, event) === false; |
| 89 else | 91 else |
| 90 prevented |= handler.call(this, event) === false; | 92 prevented |= handler.call(this, event) === false; |
| 91 } | 93 } |
| 92 } | 94 } |
| 93 | 95 |
| 94 return !prevented && !event.defaultPrevented; | 96 return !prevented && !event.defaultPrevented; |
| 95 } | 97 } |
| 96 }; | 98 }; |
| 97 | 99 |
| 98 // Export | 100 // Export |
| 99 return {EventTarget: EventTarget}; | 101 return {EventTarget: EventTarget}; |
| 100 }); | 102 }); |
| OLD | NEW |