Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: chrome/common/extensions/docs/examples/apps/calculator/app/controller.js

Issue 11316346: Make calculator app handle onRestarted events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update variable names Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/common/extensions/docs/examples/apps/calculator/app/manifest.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/docs/examples/apps/calculator/app/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698