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

Side by Side Diff: chrome/browser/resources/ntp/apps.js

Issue 3517004: Revert 60997 - o Add user customizable launch type for apps by adding options... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 2 months 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 | « chrome/browser/resources/new_new_tab.html ('k') | chrome/browser/resources/shared/css/menu.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 function getAppsCallback(data) { 5 function getAppsCallback(data) {
6 logEvent('received apps'); 6 logEvent('received apps');
7 var appsSection = $('apps'); 7 var appsSection = $('apps');
8 var appsSectionContent = $('apps-maxiview'); 8 var appsSectionContent = $('apps-maxiview');
9 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; 9 var appsMiniview = appsSection.getElementsByClassName('miniview')[0];
10 appsSectionContent.textContent = ''; 10 appsSectionContent.textContent = '';
(...skipping 18 matching lines...) Expand all
29 29
30 apps.loaded = true; 30 apps.loaded = true;
31 maybeDoneLoading(); 31 maybeDoneLoading();
32 32
33 if (data.apps.length > 0 && isDoneLoading()) { 33 if (data.apps.length > 0 && isDoneLoading()) {
34 updateMiniviewClipping(appsMiniview); 34 updateMiniviewClipping(appsMiniview);
35 layoutSections(); 35 layoutSections();
36 } 36 }
37 } 37 }
38 38
39 function appsPrefChangeCallback(data) {
40 // Currently the only pref that is watched is the launch type.
41 data.apps.forEach(function(app) {
42 var appLink = document.querySelector('.app a[app-id=' + app['id'] + ']');
43 if (appLink)
44 appLink.setAttribute('launch-type', app['launch_type']);
45 });
46 }
47
48 var apps = (function() { 39 var apps = (function() {
49 40
50 function createElement(app) { 41 function createElement(app) {
51 var div = document.createElement('div'); 42 var div = document.createElement('div');
52 div.className = 'app'; 43 div.className = 'app';
53 44
54 var a = div.appendChild(document.createElement('a')); 45 var a = div.appendChild(document.createElement('a'));
55 a.setAttribute('app-id', app['id']); 46 a.setAttribute('app-id', app['id']);
56 a.setAttribute('launch-type', app['launch_type']);
57 a.xtitle = a.textContent = app['name']; 47 a.xtitle = a.textContent = app['name'];
58 a.href = app['launch_url']; 48 a.href = app['launch_url'];
59 49
60 return div; 50 return div;
61 } 51 }
62 52
63 function createContextMenu(app) { 53 function createContextMenu(app) {
64 var menu = new cr.ui.Menu; 54 var menu = new cr.ui.Menu;
65 var button = document.createElement(button); 55 var button = document.createElement(button);
66 } 56 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 92
103 /** 93 /**
104 * @this {!HTMLAnchorElement} 94 * @this {!HTMLAnchorElement}
105 */ 95 */
106 function handleClick(e) { 96 function handleClick(e) {
107 var appId = e.currentTarget.getAttribute('app-id'); 97 var appId = e.currentTarget.getAttribute('app-id');
108 launchApp(appId); 98 launchApp(appId);
109 return false; 99 return false;
110 } 100 }
111 101
112 // Keep in sync with LaunchType in extension_prefs.h
113 var LaunchType = {
114 LAUNCH_PINNED: 0,
115 LAUNCH_REGULAR: 1,
116 LAUNCH_FULLSCREEN: 2
117 };
118
119 // Keep in sync with LaunchContainer in extension.h
120 var LaunchContainer = {
121 LAUNCH_WINDOW: 0,
122 LAUNCH_PANEL: 1,
123 LAUNCH_TAB: 2
124 };
125
126 var currentApp; 102 var currentApp;
127 103
128 function addContextMenu(el, app) { 104 function addContextMenu(el, app) {
129 el.addEventListener('contextmenu', cr.ui.contextMenuHandler); 105 el.addEventListener('contextmenu', cr.ui.contextMenuHandler);
130 el.addEventListener('keydown', cr.ui.contextMenuHandler); 106 el.addEventListener('keydown', cr.ui.contextMenuHandler);
131 el.addEventListener('keyup', cr.ui.contextMenuHandler); 107 el.addEventListener('keyup', cr.ui.contextMenuHandler);
132 108
133 Object.defineProperty(el, 'contextMenu', { 109 Object.defineProperty(el, 'contextMenu', {
134 get: function() { 110 get: function() {
135 currentApp = app; 111 currentApp = app;
136 112
137 $('apps-launch-command').label = app['name']; 113 $('apps-launch-command').label = app['name'];
138 $('apps-options-command').canExecuteChange(); 114 $('apps-options-command').canExecuteChange();
139 115
140 var appLinkSel = '.app a[app-id=' + app['id'] + ']';
141 var launchType =
142 el.querySelector(appLinkSel).getAttribute('launch-type');
143
144 var launchContainer = app['launch_container'];
145 var isPanel = launchContainer == LaunchContainer.LAUNCH_PANEL;
146
147 // Update the commands related to the launch type.
148 var launchTypeIds = ['apps-launch-type-pinned',
149 'apps-launch-type-regular',
150 'apps-launch-type-fullscreen'];
151 launchTypeIds.forEach(function(id) {
152 var command = $(id);
153 command.disabled = isPanel;
154 command.checked = !isPanel &&
155 launchType == command.getAttribute('launch-type');
156 });
157
158 return $('app-context-menu'); 116 return $('app-context-menu');
159 } 117 }
160 }); 118 });
161 } 119 }
162 120
163 document.addEventListener('command', function(e) { 121 document.addEventListener('command', function(e) {
164 if (!currentApp) 122 if (!currentApp)
165 return; 123 return;
166 124
167 var commandId = e.command.id; 125 switch (e.command.id) {
168 switch (commandId) {
169 case 'apps-options-command': 126 case 'apps-options-command':
170 window.location = currentApp['options_url']; 127 window.location = currentApp['options_url'];
171 break; 128 break;
172 case 'apps-launch-command': 129 case 'apps-launch-command':
173 launchApp(currentApp['id']); 130 launchApp(currentApp['id']);
174 break; 131 break;
175 case 'apps-uninstall-command': 132 case 'apps-uninstall-command':
176 chrome.send('uninstallApp', [currentApp['id']]); 133 chrome.send('uninstallApp', [currentApp['id']]);
177 break; 134 break;
178 case 'apps-launch-type-pinned':
179 case 'apps-launch-type-regular':
180 case 'apps-launch-type-fullscreen':
181 chrome.send('setLaunchType',
182 [currentApp['id'], e.command.getAttribute('launch-type')]);
183 break;
184 } 135 }
185 }); 136 });
186 137
187 document.addEventListener('canExecute', function(e) { 138 document.addEventListener('canExecute', function(e) {
188 switch (e.command.id) { 139 switch (e.command.id) {
189 case 'apps-options-command': 140 case 'apps-options-command':
190 e.canExecute = currentApp && currentApp['options_url']; 141 e.canExecute = currentApp && currentApp['options_url'];
191 break; 142 break;
192 case 'apps-launch-command': 143 case 'apps-launch-command':
193 case 'apps-uninstall-command': 144 case 'apps-uninstall-command':
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 204
254 createWebStoreElement: function() { 205 createWebStoreElement: function() {
255 return createElement({ 206 return createElement({
256 'id': 'web-store-entry', 207 'id': 'web-store-entry',
257 'name': localStrings.getString('web_store_title'), 208 'name': localStrings.getString('web_store_title'),
258 'launch_url': localStrings.getString('web_store_url') 209 'launch_url': localStrings.getString('web_store_url')
259 }); 210 });
260 } 211 }
261 }; 212 };
262 })(); 213 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/new_new_tab.html ('k') | chrome/browser/resources/shared/css/menu.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698