OLD | NEW |
1 /** | 1 /** |
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 **/ | 5 **/ |
6 | 6 |
7 // Checking for "chrome.app.runtime" availability allows this Chrome app code to | 7 // Checking for "chrome.app.runtime" availability allows this Chrome app code to |
8 // be tested in a regular web page (like tests/manual.html). Checking for | 8 // be tested in a regular web page (like tests/manual.html). Checking for |
9 // "chrome" and "chrome.app" availability further allows this code to be tested | 9 // "chrome" and "chrome.app" availability further allows this code to be tested |
10 // in non-Chrome browsers, which is useful for example to test touch support | 10 // in non-Chrome browsers, which is useful for example to test touch support |
11 // with a non-Chrome touch device. | 11 // with a non-Chrome touch device. |
12 if (typeof chrome !== 'undefined' && chrome.app && chrome.app.runtime) { | 12 if (typeof chrome !== 'undefined' && chrome.app && chrome.app.runtime) { |
13 chrome.app.runtime.onLaunched.addListener(function() { | 13 var showCalculatorWindow = function () { |
14 chrome.app.window.create('calculator.html', { | 14 chrome.app.window.create('calculator.html', { |
15 defaultWidth: 243, minWidth: 243, maxWidth: 243, | 15 defaultWidth: 243, minWidth: 243, maxWidth: 243, |
16 defaultHeight: 380, minHeight: 380, maxHeight: 380, | 16 defaultHeight: 380, minHeight: 380, maxHeight: 380, |
17 id: 'calculator' | 17 id: 'calculator' |
18 }, function(appWindow) { | 18 }, function(appWindow) { |
19 appWindow.contentWindow.onload = function() { | 19 appWindow.contentWindow.onload = function() { |
20 new Controller(new Model(9), new View(appWindow.contentWindow)); | 20 new Controller(new Model(9), new View(appWindow.contentWindow)); |
21 }; | 21 }; |
| 22 |
| 23 chrome.storage.local.set({windowVisible: true}); |
| 24 appWindow.onClosed.addListener(function() { |
| 25 chrome.storage.local.set({windowVisible: false}); |
| 26 }); |
| 27 }); |
| 28 } |
| 29 |
| 30 chrome.app.runtime.onLaunched.addListener(showCalculatorWindow); |
| 31 chrome.app.runtime.onRestarted.addListener(function() { |
| 32 chrome.storage.local.get('windowVisible', function(data) { |
| 33 if (data.windowVisible) |
| 34 showCalculatorWindow(); |
22 }); | 35 }); |
23 }); | 36 }); |
24 } | 37 } |
25 | 38 |
26 function Controller(model, view) { | 39 function Controller(model, view) { |
27 this.inputs = this.defineInputs_(); | 40 this.inputs = this.defineInputs_(); |
28 this.model = model; | 41 this.model = model; |
29 this.view = view; | 42 this.view = view; |
30 this.view.onButton = function(button) { | 43 this.view.onButton = function(button) { |
31 this.handleInput_(this.inputs.byButton[button]); | 44 this.handleInput_(this.inputs.byButton[button]); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 operand: this.getUpdatedValue_(before, after, 'operand', !before.operator) | 106 operand: this.getUpdatedValue_(before, after, 'operand', !before.operator) |
94 }); | 107 }); |
95 return !before.accumulator; | 108 return !before.accumulator; |
96 } | 109 } |
97 | 110 |
98 /** @private */ | 111 /** @private */ |
99 Controller.prototype.getUpdatedValue_ = function(before, after, key, zero) { | 112 Controller.prototype.getUpdatedValue_ = function(before, after, key, zero) { |
100 var value = (typeof after[key] !== 'undefined') ? after[key] : before[key]; | 113 var value = (typeof after[key] !== 'undefined') ? after[key] : before[key]; |
101 return zero ? (value || '0') : value; | 114 return zero ? (value || '0') : value; |
102 } | 115 } |
OLD | NEW |