Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / chrome / renderer / resources / extensions / extension_options_events.js
blob1bc517c91c03284d84cabc5ed6daf581e3088575
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 = {
13 'close': {
14 evt: CreateEvent('extensionOptionsInternal.onClose'),
15 fields: []
17 'load': {
18 evt: CreateEvent('extensionOptionsInternal.onLoad'),
19 fields: []
21 'sizechanged': {
22 evt: CreateEvent('extensionOptionsInternal.onSizeChanged'),
23 customHandler: function(handler, event, extensionOptionsEvent) {
24 handler.handleSizeChangedEvent(event, extensionOptionsEvent);
26 fields:['newWidth', 'newHeight', 'oldWidth', 'oldHeight']
30 /**
31 * @constructor
33 function ExtensionOptionsEvents(extensionOptionsInternal, viewInstanceId) {
34 this.extensionOptionsInternal = extensionOptionsInternal;
35 this.viewInstanceId = viewInstanceId;
36 this.setup();
39 // Sets up events.
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) {
47 var self = this;
48 info.evt.addListener(function(e) {
49 var details = {bubbles:true};
50 if (info.cancelable)
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];
57 });
58 if (info.customHandler) {
59 info.customHandler(self, e, extensionOptionsEvent);
60 return;
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;