| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Custom binding for the app_window API. | 5 // Custom binding for the app_window API. |
| 6 | 6 |
| 7 var appWindowNatives = requireNative('app_window_natives'); | 7 var appWindowNatives = requireNative('app_window_natives'); |
| 8 var runtimeNatives = requireNative('runtime'); | 8 var runtimeNatives = requireNative('runtime'); |
| 9 var Event = require('event_bindings').Event; | |
| 10 var forEach = require('utils').forEach; | 9 var forEach = require('utils').forEach; |
| 11 var renderFrameObserverNatives = requireNative('renderFrameObserverNatives'); | 10 var renderFrameObserverNatives = requireNative('renderFrameObserverNatives'); |
| 12 | 11 |
| 13 var appWindowData = null; | 12 var appWindowData = null; |
| 14 var currentAppWindow = null; | 13 var currentAppWindow = null; |
| 15 var currentWindowInternal = null; | 14 var currentWindowInternal = null; |
| 16 | 15 |
| 17 var kSetBoundsFunction = 'setBounds'; | 16 var kSetBoundsFunction = 'setBounds'; |
| 18 var kSetSizeConstraintsFunction = 'setSizeConstraints'; | 17 var kSetSizeConstraintsFunction = 'setSizeConstraints'; |
| 19 | 18 |
| 20 if (!apiBridge) | 19 if (!apiBridge) |
| 21 var binding = require('binding').Binding; | 20 var binding = require('binding').Binding; |
| 22 | 21 |
| 22 var jsEvent; |
| 23 function createAnonymousEvent() { |
| 24 if (bindingUtil) { |
| 25 // Native custom events ignore schema. |
| 26 return bindingUtil.createCustomEvent(undefined, undefined, false); |
| 27 } |
| 28 if (!jsEvent) |
| 29 jsEvent = require('event_bindings').Event; |
| 30 return new jsEvent(); |
| 31 } |
| 32 |
| 23 // Bounds class definition. | 33 // Bounds class definition. |
| 24 var Bounds = function(boundsKey) { | 34 var Bounds = function(boundsKey) { |
| 25 privates(this).boundsKey_ = boundsKey; | 35 privates(this).boundsKey_ = boundsKey; |
| 26 }; | 36 }; |
| 27 Object.defineProperty(Bounds.prototype, 'left', { | 37 Object.defineProperty(Bounds.prototype, 'left', { |
| 28 get: function() { | 38 get: function() { |
| 29 return appWindowData[privates(this).boundsKey_].left; | 39 return appWindowData[privates(this).boundsKey_].left; |
| 30 }, | 40 }, |
| 31 set: function(left) { | 41 set: function(left) { |
| 32 this.setPosition(left, null); | 42 this.setPosition(left, null); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 return /Mac/.test(navigator.platform) || /Linux/.test(navigator.userAgent); | 214 return /Mac/.test(navigator.platform) || /Linux/.test(navigator.userAgent); |
| 205 }); | 215 }); |
| 206 | 216 |
| 207 // This is an internal function, but needs to be bound into a closure | 217 // This is an internal function, but needs to be bound into a closure |
| 208 // so the correct JS context is used for global variables such as | 218 // so the correct JS context is used for global variables such as |
| 209 // currentWindowInternal, appWindowData, etc. | 219 // currentWindowInternal, appWindowData, etc. |
| 210 apiFunctions.setHandleRequest('initializeAppWindow', function(params) { | 220 apiFunctions.setHandleRequest('initializeAppWindow', function(params) { |
| 211 currentWindowInternal = | 221 currentWindowInternal = |
| 212 getInternalApi ? | 222 getInternalApi ? |
| 213 getInternalApi('app.currentWindowInternal') : | 223 getInternalApi('app.currentWindowInternal') : |
| 214 binding.create('app.currentWindowInternal').generate(); | 224 binding.create('app.currentWindowInternal').generate(); |
| 215 var AppWindow = function() { | 225 var AppWindow = function() { |
| 216 this.innerBounds = new Bounds('innerBounds'); | 226 this.innerBounds = new Bounds('innerBounds'); |
| 217 this.outerBounds = new Bounds('outerBounds'); | 227 this.outerBounds = new Bounds('outerBounds'); |
| 218 }; | 228 }; |
| 219 forEach(currentWindowInternal, function(key, value) { | 229 forEach(currentWindowInternal, function(key, value) { |
| 220 // Do not add internal functions that should not appear in the AppWindow | 230 // Do not add internal functions that should not appear in the AppWindow |
| 221 // interface. They are called by Bounds mutators. | 231 // interface. They are called by Bounds mutators. |
| 222 if (key !== kSetBoundsFunction && key !== kSetSizeConstraintsFunction) | 232 if (key !== kSetBoundsFunction && key !== kSetSizeConstraintsFunction) |
| 223 AppWindow.prototype[key] = value; | 233 AppWindow.prototype[key] = value; |
| 224 }); | 234 }); |
| 225 AppWindow.prototype.moveTo = $Function.bind(window.moveTo, window); | 235 AppWindow.prototype.moveTo = $Function.bind(window.moveTo, window); |
| 226 AppWindow.prototype.resizeTo = $Function.bind(window.resizeTo, window); | 236 AppWindow.prototype.resizeTo = $Function.bind(window.resizeTo, window); |
| 227 AppWindow.prototype.contentWindow = window; | 237 AppWindow.prototype.contentWindow = window; |
| 228 AppWindow.prototype.onClosed = new Event(); | 238 AppWindow.prototype.onClosed = createAnonymousEvent(); |
| 229 AppWindow.prototype.close = function() { | 239 AppWindow.prototype.close = function() { |
| 230 this.contentWindow.close(); | 240 this.contentWindow.close(); |
| 231 }; | 241 }; |
| 232 AppWindow.prototype.getBounds = function() { | 242 AppWindow.prototype.getBounds = function() { |
| 233 // This is to maintain backcompatibility with a bug on Windows and | 243 // This is to maintain backcompatibility with a bug on Windows and |
| 234 // ChromeOS, which returns the position of the window but the size of | 244 // ChromeOS, which returns the position of the window but the size of |
| 235 // the content. | 245 // the content. |
| 236 var innerBounds = appWindowData.innerBounds; | 246 var innerBounds = appWindowData.innerBounds; |
| 237 var outerBounds = appWindowData.outerBounds; | 247 var outerBounds = appWindowData.outerBounds; |
| 238 return { left: outerBounds.left, top: outerBounds.top, | 248 return { left: outerBounds.left, top: outerBounds.top, |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 constraints[key] = 0; | 395 constraints[key] = 0; |
| 386 }); | 396 }); |
| 387 | 397 |
| 388 currentWindowInternal.setSizeConstraints(boundsType, constraints); | 398 currentWindowInternal.setSizeConstraints(boundsType, constraints); |
| 389 } | 399 } |
| 390 | 400 |
| 391 if (!apiBridge) | 401 if (!apiBridge) |
| 392 exports.$set('binding', appWindow.generate()); | 402 exports.$set('binding', appWindow.generate()); |
| 393 exports.$set('onAppWindowClosed', onAppWindowClosed); | 403 exports.$set('onAppWindowClosed', onAppWindowClosed); |
| 394 exports.$set('updateAppWindowProperties', updateAppWindowProperties); | 404 exports.$set('updateAppWindowProperties', updateAppWindowProperties); |
| OLD | NEW |