1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var EventBindings
= require('event_bindings');
7 var CreateEvent = function(name
) {
8 var eventOpts
= {supportsListeners
: true, supportsFilters
: true};
9 return new EventBindings
.Event(name
, undefined, eventOpts
);
12 var EXTENSION_OPTIONS_EVENTS
= {
14 evt
: CreateEvent('extensionOptionsInternal.onClose'),
18 evt
: CreateEvent('extensionOptionsInternal.onLoad'),
22 evt
: CreateEvent('extensionOptionsInternal.onSizeChanged'),
23 customHandler: function(handler
, event
, extensionOptionsEvent
) {
24 handler
.handleSizeChangedEvent(event
, extensionOptionsEvent
);
26 fields
:['newWidth', 'newHeight', 'oldWidth', 'oldHeight']
33 function ExtensionOptionsEvents(extensionOptionsInternal
, viewInstanceId
) {
34 this.extensionOptionsInternal
= extensionOptionsInternal
;
35 this.viewInstanceId
= viewInstanceId
;
40 ExtensionOptionsEvents
.prototype.setup = function() {
41 for (var eventName
in EXTENSION_OPTIONS_EVENTS
) {
42 this.setupEvent(eventName
, EXTENSION_OPTIONS_EVENTS
[eventName
]);
46 ExtensionOptionsEvents
.prototype.setupEvent = function(name
, info
) {
48 info
.evt
.addListener(function(e
) {
49 var details
= {bubbles
:true};
51 details
.cancelable
= true;
52 var extensionOptionsEvent
= new Event(name
, details
);
53 $Array
.forEach(info
.fields
, function(field
) {
54 if (e
.hasOwnProperty(field
)) {
55 extensionOptionsEvent
[field
] = e
[field
];
58 if (info
.customHandler
) {
59 info
.customHandler(self
, e
, extensionOptionsEvent
);
62 self
.extensionOptionsInternal
.dispatchEvent(extensionOptionsEvent
);
63 }, {instanceId
: self
.viewInstanceId
});
65 this.extensionOptionsInternal
.setupEventProperty(name
);
68 ExtensionOptionsEvents
.prototype.handleSizeChangedEvent = function(
69 event
, extensionOptionsEvent
) {
70 this.extensionOptionsInternal
.onSizeChanged(extensionOptionsEvent
.newWidth
,
71 extensionOptionsEvent
.newHeight
,
72 extensionOptionsEvent
.oldWidth
,
73 extensionOptionsEvent
.oldHeight
);
74 this.extensionOptionsInternal
.dispatchEvent(extensionOptionsEvent
);
77 exports
.ExtensionOptionsEvents
= ExtensionOptionsEvents
;
78 exports
.CreateEvent
= CreateEvent
;