| 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 Binding = require('binding').Binding; | 9 var Binding = require('binding').Binding; |
| 10 var Event = require('event_bindings').Event; | 10 var Event = require('event_bindings').Event; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 forEach(currentWindowInternal, function(key, value) { | 215 forEach(currentWindowInternal, function(key, value) { |
| 216 // Do not add internal functions that should not appear in the AppWindow | 216 // Do not add internal functions that should not appear in the AppWindow |
| 217 // interface. They are called by Bounds mutators. | 217 // interface. They are called by Bounds mutators. |
| 218 if (key !== kSetBoundsFunction && key !== kSetSizeConstraintsFunction) | 218 if (key !== kSetBoundsFunction && key !== kSetSizeConstraintsFunction) |
| 219 AppWindow.prototype[key] = value; | 219 AppWindow.prototype[key] = value; |
| 220 }); | 220 }); |
| 221 AppWindow.prototype.moveTo = $Function.bind(window.moveTo, window); | 221 AppWindow.prototype.moveTo = $Function.bind(window.moveTo, window); |
| 222 AppWindow.prototype.resizeTo = $Function.bind(window.resizeTo, window); | 222 AppWindow.prototype.resizeTo = $Function.bind(window.resizeTo, window); |
| 223 AppWindow.prototype.contentWindow = window; | 223 AppWindow.prototype.contentWindow = window; |
| 224 AppWindow.prototype.onClosed = new Event(); | 224 AppWindow.prototype.onClosed = new Event(); |
| 225 AppWindow.prototype.onWindowFirstShownForTests = new Event(); | |
| 226 AppWindow.prototype.close = function() { | 225 AppWindow.prototype.close = function() { |
| 227 this.contentWindow.close(); | 226 this.contentWindow.close(); |
| 228 }; | 227 }; |
| 229 AppWindow.prototype.getBounds = function() { | 228 AppWindow.prototype.getBounds = function() { |
| 230 // This is to maintain backcompatibility with a bug on Windows and | 229 // This is to maintain backcompatibility with a bug on Windows and |
| 231 // ChromeOS, which returns the position of the window but the size of | 230 // ChromeOS, which returns the position of the window but the size of |
| 232 // the content. | 231 // the content. |
| 233 var innerBounds = appWindowData.innerBounds; | 232 var innerBounds = appWindowData.innerBounds; |
| 234 var outerBounds = appWindowData.outerBounds; | 233 var outerBounds = appWindowData.outerBounds; |
| 235 return { left: outerBounds.left, top: outerBounds.top, | 234 return { left: outerBounds.left, top: outerBounds.top, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 246 }; | 245 }; |
| 247 AppWindow.prototype.isMaximized = function() { | 246 AppWindow.prototype.isMaximized = function() { |
| 248 return appWindowData.maximized; | 247 return appWindowData.maximized; |
| 249 }; | 248 }; |
| 250 AppWindow.prototype.isAlwaysOnTop = function() { | 249 AppWindow.prototype.isAlwaysOnTop = function() { |
| 251 return appWindowData.alwaysOnTop; | 250 return appWindowData.alwaysOnTop; |
| 252 }; | 251 }; |
| 253 AppWindow.prototype.alphaEnabled = function() { | 252 AppWindow.prototype.alphaEnabled = function() { |
| 254 return appWindowData.alphaEnabled; | 253 return appWindowData.alphaEnabled; |
| 255 }; | 254 }; |
| 256 AppWindow.prototype.handleWindowFirstShownForTests = function(callback) { | |
| 257 // This allows test apps to get have their callback run even if they | |
| 258 // call this after the first show has happened. | |
| 259 if (this.firstShowHasHappened) { | |
| 260 callback(); | |
| 261 return; | |
| 262 } | |
| 263 this.onWindowFirstShownForTests.addListener(callback); | |
| 264 } | |
| 265 | 255 |
| 266 Object.defineProperty(AppWindow.prototype, 'id', {get: function() { | 256 Object.defineProperty(AppWindow.prototype, 'id', {get: function() { |
| 267 return appWindowData.id; | 257 return appWindowData.id; |
| 268 }}); | 258 }}); |
| 269 | 259 |
| 270 // These properties are for testing. | 260 // These properties are for testing. |
| 271 Object.defineProperty( | 261 Object.defineProperty( |
| 272 AppWindow.prototype, 'hasFrameColor', {get: function() { | 262 AppWindow.prototype, 'hasFrameColor', {get: function() { |
| 273 return appWindowData.hasFrameColor; | 263 return appWindowData.hasFrameColor; |
| 274 }}); | 264 }}); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 349 |
| 360 if ((oldData.fullscreen && !update.fullscreen) || | 350 if ((oldData.fullscreen && !update.fullscreen) || |
| 361 (oldData.minimized && !update.minimized) || | 351 (oldData.minimized && !update.minimized) || |
| 362 (oldData.maximized && !update.maximized)) | 352 (oldData.maximized && !update.maximized)) |
| 363 dispatchEventIfExists(currentWindow, "onRestored"); | 353 dispatchEventIfExists(currentWindow, "onRestored"); |
| 364 | 354 |
| 365 if (oldData.alphaEnabled !== update.alphaEnabled) | 355 if (oldData.alphaEnabled !== update.alphaEnabled) |
| 366 dispatchEventIfExists(currentWindow, "onAlphaEnabledChanged"); | 356 dispatchEventIfExists(currentWindow, "onAlphaEnabledChanged"); |
| 367 }; | 357 }; |
| 368 | 358 |
| 369 function onAppWindowShownForTests() { | |
| 370 if (!currentAppWindow) | |
| 371 return; | |
| 372 | |
| 373 if (!currentAppWindow.firstShowHasHappened) | |
| 374 dispatchEventIfExists(currentAppWindow, "onWindowFirstShownForTests"); | |
| 375 | |
| 376 currentAppWindow.firstShowHasHappened = true; | |
| 377 } | |
| 378 | |
| 379 function onAppWindowClosed() { | 359 function onAppWindowClosed() { |
| 380 if (!currentAppWindow) | 360 if (!currentAppWindow) |
| 381 return; | 361 return; |
| 382 dispatchEventIfExists(currentAppWindow, "onClosed"); | 362 dispatchEventIfExists(currentAppWindow, "onClosed"); |
| 383 } | 363 } |
| 384 | 364 |
| 385 function updateBounds(boundsType, bounds) { | 365 function updateBounds(boundsType, bounds) { |
| 386 if (!currentWindowInternal) | 366 if (!currentWindowInternal) |
| 387 return; | 367 return; |
| 388 | 368 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 400 if (value === null) | 380 if (value === null) |
| 401 constraints[key] = 0; | 381 constraints[key] = 0; |
| 402 }); | 382 }); |
| 403 | 383 |
| 404 currentWindowInternal.setSizeConstraints(boundsType, constraints); | 384 currentWindowInternal.setSizeConstraints(boundsType, constraints); |
| 405 } | 385 } |
| 406 | 386 |
| 407 exports.$set('binding', appWindow.generate()); | 387 exports.$set('binding', appWindow.generate()); |
| 408 exports.$set('onAppWindowClosed', onAppWindowClosed); | 388 exports.$set('onAppWindowClosed', onAppWindowClosed); |
| 409 exports.$set('updateAppWindowProperties', updateAppWindowProperties); | 389 exports.$set('updateAppWindowProperties', updateAppWindowProperties); |
| 410 exports.$set('appWindowShownForTests', onAppWindowShownForTests); | |
| OLD | NEW |