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

Side by Side Diff: chrome/browser/resources/task_manager/main.js

Issue 7326044: WebUI TaskManager: Column Customization (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 5 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 /** @constructor */ 5 /** @constructor */
6 function TaskManager() { } 6 function TaskManager() { }
7 7
8 cr.addSingletonGetter(TaskManager); 8 cr.addSingletonGetter(TaskManager);
9 9
10 /* 10 /*
11 * Default columns (column_id, label, width) 11 * Default columns (column_id, label_id, width, is_default)
12 * @const 12 * @const
13 */ 13 */
14 var DEFAULT_COLUMNS = [['title', 'page_column', 300], 14 var DEFAULT_COLUMNS = [['title', 'page_column', 300, true],
15 ['networkUsage', 'network_column', 85], 15 ['networkUsage', 'network_column', 85, true],
16 ['cpuUsage', 'cpu_column', 80], 16 ['cpuUsage', 'cpu_column', 80, true],
17 ['privateMemory', 'private_memory_column', 80]]; 17 ['privateMemory', 'private_memory_column', 80, true],
18 ['processId', 'process_id_column', 120, false]];
18 19
19 var localStrings = new LocalStrings(); 20 var localStrings = new LocalStrings();
20 21
21 TaskManager.prototype = { 22 TaskManager.prototype = {
22 /** 23 /**
23 * Handle window close. 24 * Handle window close.
24 * @public 25 * @public
25 */ 26 */
26 onClose: function () { 27 onClose: function () {
27 if (!this.disabled_) { 28 if (!this.disabled_) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 this.enableTaskManager(); 87 this.enableTaskManager();
87 88
88 this.dialogDom_ = dialogDom; 89 this.dialogDom_ = dialogDom;
89 this.document_ = dialogDom.ownerDocument; 90 this.document_ = dialogDom.ownerDocument;
90 91
91 $('close-window').addEventListener('click', this.close.bind(this)); 92 $('close-window').addEventListener('click', this.close.bind(this));
92 $('kill-process').addEventListener('click', this.killProcess.bind(this)); 93 $('kill-process').addEventListener('click', this.killProcess.bind(this));
93 $('about-memory-link').addEventListener('click', 94 $('about-memory-link').addEventListener('click',
94 this.openAboutMemory.bind(this)); 95 this.openAboutMemory.bind(this));
95 96
97 this.is_column_shown_ = [];
98 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
99 this.is_column_shown_[i] = DEFAULT_COLUMNS[i][3];
100 }
101
102 this.localized_column_ = [];
103 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
104 var column_label_id = DEFAULT_COLUMNS[i][1];
105 var localized_label = localStrings.getString(column_label_id);
106 // Falls back to raw column_label_id if localized string is not defined.
107 if (localized_label == "")
108 localized_label = column_label_id;
109
110 this.localized_column_[i] = localized_label;
111 }
112
96 this.initColumnModel_(); 113 this.initColumnModel_();
97 this.selectionModel_ = new cr.ui.ListSelectionModel(); 114 this.selectionModel_ = new cr.ui.ListSelectionModel();
98 this.dataModel_ = new cr.ui.ArrayDataModel([]); 115 this.dataModel_ = new cr.ui.ArrayDataModel([]);
99 116
100 // Initializes compare functions for column sort. 117 // Initializes compare functions for column sort.
101 var dm = this.dataModel_; 118 var dm = this.dataModel_;
102 dm.setCompareFunction('networkUsage', function(a, b) { 119 dm.setCompareFunction('networkUsage', function(a, b) {
103 var value_id = 'networkUsageValue'; 120 var value_id = 'networkUsageValue';
104 return dm.defaultValuesCompareFunction(a[value_id][0], b[value_id][0]); 121 return dm.defaultValuesCompareFunction(a[value_id][0], b[value_id][0]);
105 }); 122 });
106 dm.setCompareFunction('cpuUsage', function(a, b) { 123 dm.setCompareFunction('cpuUsage', function(a, b) {
107 var value_id = 'cpuUsageValue'; 124 var value_id = 'cpuUsageValue';
108 return dm.defaultValuesCompareFunction(a[value_id][0], b[value_id][0]); 125 return dm.defaultValuesCompareFunction(a[value_id][0], b[value_id][0]);
109 }); 126 });
110 dm.setCompareFunction('privateMemory', function(a, b) { 127 dm.setCompareFunction('privateMemory', function(a, b) {
111 var value_id = 'privateMemoryValue'; 128 var value_id = 'privateMemoryValue';
112 return dm.defaultValuesCompareFunction(a[value_id][0], b[value_id][0]); 129 return dm.defaultValuesCompareFunction(a[value_id][0], b[value_id][0]);
113 }); 130 });
114 131
115 this.initTable_(); 132 this.initTable_();
133 this.initColumnMenu_();
116 this.table_.redraw(); 134 this.table_.redraw();
117 }, 135 },
118 136
119 initColumnModel_: function () { 137 initColumnModel_: function () {
120 var table_columns = new Array(); 138 var table_columns = new Array();
121 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) { 139 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
122 var localized_label = localStrings.getString(DEFAULT_COLUMNS[i][1]); 140 if (!this.is_column_shown_[i])
123 table_columns.push(new cr.ui.table.TableColumn(DEFAULT_COLUMNS[i][0], 141 continue;
124 localized_label, 142
125 DEFAULT_COLUMNS[i][2])); 143 var column = DEFAULT_COLUMNS[i];
144 table_columns.push(new cr.ui.table.TableColumn(column[0],
145 this.localized_column_[i],
146 column[2]));
126 } 147 }
127 148
128 for (var i = 0; i < table_columns.length; i++) { 149 for (var i = 0; i < table_columns.length; i++) {
129 table_columns[i].renderFunction = this.renderText_.bind(this); 150 table_columns[i].renderFunction = this.renderText_.bind(this);
130 } 151 }
131 152
132 this.columnModel_ = new cr.ui.table.TableColumnModel(table_columns); 153 this.columnModel_ = new cr.ui.table.TableColumnModel(table_columns);
133 }, 154 },
134 155
156 initColumnMenu_: function () {
157 this.column_menu_commands_ = [];
158
159 this.commandsElement_ = this.document_.createElement('commands');
160 this.document_.body.appendChild(this.commandsElement_);
161
162 this.columnSelectContextMenu_ = this.document_.createElement('menu');
163 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
164 var column = DEFAULT_COLUMNS[i];
165
166 // Creates command element to receive event.
167 var command = this.document_.createElement('command');
168 command.id = 'columnContextMenu-' + column[0];
169 cr.ui.Command.decorate(command);
170 this.column_menu_commands_[command.id] = command;
171 this.commandsElement_.appendChild(command);
172
173 // Creates menuitem element.
174 var item = this.document_.createElement('menuitem');
175 item.command = command;
176 command.menuitem = item;
177 item.textContent = this.localized_column_[i];
178 if (this.is_column_shown_[i])
179 item.setAttributeNode(this.document_.createAttribute("checked"));
180 this.columnSelectContextMenu_.appendChild(item);
181 }
182
183 this.document_.body.appendChild(this.columnSelectContextMenu_);
184 cr.ui.Menu.decorate(this.columnSelectContextMenu_);
185
186 cr.ui.contextMenuHandler.addContextMenuProperty(this.table_.header);
187 this.table_.header.contextMenu = this.columnSelectContextMenu_;
188
189 this.document_.addEventListener('command', this.onCommand_.bind(this));
190 this.document_.addEventListener('canExecute',
191 this.onCommandCanExecute_.bind(this));
192
193 },
194
135 initTable_: function () { 195 initTable_: function () {
136 if (!this.dataModel_ || !this.selectionModel_ || !this.columnModel_) { 196 if (!this.dataModel_ || !this.selectionModel_ || !this.columnModel_) {
137 console.log('ERROR: some models are not defined.'); 197 console.log('ERROR: some models are not defined.');
138 return; 198 return;
139 } 199 }
140 200
141 this.table_ = this.dialogDom_.querySelector('.detail-table'); 201 this.table_ = this.dialogDom_.querySelector('.detail-table');
142 cr.ui.Table.decorate(this.table_); 202 cr.ui.Table.decorate(this.table_);
143 203
144 this.table_.dataModel = this.dataModel_; 204 this.table_.dataModel = this.dataModel_;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 262
203 dm.splice.apply(dm, args); 263 dm.splice.apply(dm, args);
204 }, 264 },
205 265
206 onTaskRemove: function (start, length, tasks) { 266 onTaskRemove: function (start, length, tasks) {
207 var dm = this.dataModel_; 267 var dm = this.dataModel_;
208 if (!dm) 268 if (!dm)
209 return; 269 return;
210 dm.splice(start, length); 270 dm.splice(start, length);
211 }, 271 },
272
273 /**
274 * Respond to a command being executed.
275 */
276 onCommand_: function(event) {
277 var command = event.command;
278 if (command.id.substr(0, 18) == 'columnContextMenu-') {
279 console.log(command.id.substr(18));
280 this.onColumnContextMenu_(command.id.substr(18), command);
281 }
282 },
283
284 onCommandCanExecute_: function(event) {
285 event.canExecute = true;
286 },
287
288 onColumnContextMenu_: function(id, command) {
289 var menuitem = command.menuitem;
290 var checked_item_count = 0;
291 var is_uncheck = 0;
292
293 // Leaves a item visible when user tries making invisible but it is the
294 // last one.
295 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
296 var column = DEFAULT_COLUMNS[i];
297 if (column[0] == id && this.is_column_shown_[i]) {
298 is_uncheck = 1;
299 }
300 if (this.is_column_shown_[i])
301 checked_item_count++;
302 }
303 if (checked_item_count == 1 && is_uncheck) {
304 return;
305 }
306
307 // Toggles the visibility of the column.
308 for (var i = 0; i < DEFAULT_COLUMNS.length; i++) {
309 var column = DEFAULT_COLUMNS[i];
310 if (column[0] == id) {
311 this.is_column_shown_[i] = !this.is_column_shown_[i];
312 menuitem.checked = this.is_column_shown_[i];
313 this.initColumnModel_()
314 this.table_.columnModel = this.columnModel_;
315 this.table_.redraw();
316 return;
317 }
318 }
319 },
212 }; 320 };
213 321
214 var taskmanager = TaskManager.getInstance(); 322 var taskmanager = TaskManager.getInstance();
215 323
216 function init() { 324 function init() {
217 taskmanager.initialize(document.body); 325 taskmanager.initialize(document.body);
218 } 326 }
219 327
220 function onClose() { 328 function onClose() {
221 return taskmanager.onClose(); 329 return taskmanager.onClose();
(...skipping 16 matching lines...) Expand all
238 taskmanager.onTaskChange(start, length, tasks); 346 taskmanager.onTaskChange(start, length, tasks);
239 } 347 }
240 348
241 function taskRemoved(start, length) { 349 function taskRemoved(start, length) {
242 // Sometimes this can get called too early. 350 // Sometimes this can get called too early.
243 if (!taskmanager) 351 if (!taskmanager)
244 return; 352 return;
245 taskmanager.onTaskRemove(start, length); 353 taskmanager.onTaskRemove(start, length);
246 } 354 }
247 355
OLDNEW
« no previous file with comments | « chrome/browser/resources/task_manager/main.html ('k') | chrome/browser/ui/webui/task_manager_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698