Title: [143576] trunk/Source/WebCore
- Revision
- 143576
- Author
- [email protected]
- Date
- 2013-02-21 02:16:32 -0800 (Thu, 21 Feb 2013)
Log Message
Add event dispatch class for the new calendar picker
https://bugs.webkit.org/show_bug.cgi?id=110131
Reviewed by Kent Tamura.
Adding event dispatcher class as part of the new calendar picker patch at Bug 109439.
No new tests. Code is not yet used.
* Resources/pagepopups/calendarPicker.js:
(EventEmitter):
(EventEmitter.prototype.on): Adds a callback for an event.
(EventEmitter.prototype.hasListener): Returns true if more than one listeners exist for an event type.
(EventEmitter.prototype.removeListener): Removes an event listener.
(EventEmitter.prototype.dispatchEvent): Dispatches an event to all callbacks. Takes variable number of arguments.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (143575 => 143576)
--- trunk/Source/WebCore/ChangeLog 2013-02-21 10:09:15 UTC (rev 143575)
+++ trunk/Source/WebCore/ChangeLog 2013-02-21 10:16:32 UTC (rev 143576)
@@ -1,3 +1,21 @@
+2013-02-21 Keishi Hattori <[email protected]>
+
+ Add event dispatch class for the new calendar picker
+ https://bugs.webkit.org/show_bug.cgi?id=110131
+
+ Reviewed by Kent Tamura.
+
+ Adding event dispatcher class as part of the new calendar picker patch at Bug 109439.
+
+ No new tests. Code is not yet used.
+
+ * Resources/pagepopups/calendarPicker.js:
+ (EventEmitter):
+ (EventEmitter.prototype.on): Adds a callback for an event.
+ (EventEmitter.prototype.hasListener): Returns true if more than one listeners exist for an event type.
+ (EventEmitter.prototype.removeListener): Removes an event listener.
+ (EventEmitter.prototype.dispatchEvent): Dispatches an event to all callbacks. Takes variable number of arguments.
+
2013-02-21 Ken Kania <[email protected]>
Web Inspector: Add command for selecting files for file input element
Modified: trunk/Source/WebCore/Resources/pagepopups/calendarPicker.js (143575 => 143576)
--- trunk/Source/WebCore/Resources/pagepopups/calendarPicker.js 2013-02-21 10:09:15 UTC (rev 143575)
+++ trunk/Source/WebCore/Resources/pagepopups/calendarPicker.js 2013-02-21 10:16:32 UTC (rev 143576)
@@ -652,6 +652,64 @@
/**
* @constructor
+ */
+function EventEmitter() {
+};
+
+/**
+ * @param {!string} type
+ * @param {!function({...*})} callback
+ */
+EventEmitter.prototype.on = function(type, callback) {
+ console.assert(callback instanceof Function);
+ if (!this._callbacks)
+ this._callbacks = {};
+ if (!this._callbacks[type])
+ this._callbacks[type] = [];
+ this._callbacks[type].push(callback);
+};
+
+EventEmitter.prototype.hasListener = function(type) {
+ if (!this._callbacks)
+ return false;
+ var callbacksForType = this._callbacks[type];
+ if (!callbacksForType)
+ return false;
+ return callbacksForType.length > 0;
+};
+
+/**
+ * @param {!string} type
+ * @param {!function(Object)} callback
+ */
+EventEmitter.prototype.removeListener = function(type, callback) {
+ if (!this._callbacks)
+ return;
+ var callbacksForType = this._callbacks[type];
+ if (!callbacksForType)
+ return;
+ callbacksForType.splice(callbacksForType.indexOf(callback), 1);
+ if (callbacksForType.length === 0)
+ delete this._callbacks[type];
+};
+
+/**
+ * @param {!string} type
+ * @param {...*} var_args
+ */
+EventEmitter.prototype.dispatchEvent = function(type) {
+ if (!this._callbacks)
+ return;
+ var callbacksForType = this._callbacks[type];
+ if (!callbacksForType)
+ return;
+ for (var i = 0; i < callbacksForType.length; ++i) {
+ callbacksForType[i].apply(this, Array.prototype.slice.call(arguments, 1));
+ }
+};
+
+/**
+ * @constructor
* @param {!Element} element
* @param {!Object} config
*/
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes