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 #include "chrome/browser/ui/cocoa/task_manager_mac.h" | 5 #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/mac/bundle_locations.h" | 10 #include "base/mac/bundle_locations.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 209 |
210 - (void)dealloc { | 210 - (void)dealloc { |
211 [tableView_ setDelegate:nil]; | 211 [tableView_ setDelegate:nil]; |
212 [tableView_ setDataSource:nil]; | 212 [tableView_ setDataSource:nil]; |
213 [super dealloc]; | 213 [super dealloc]; |
214 } | 214 } |
215 | 215 |
216 // Adds a column which has the given string id as title. |isVisible| specifies | 216 // Adds a column which has the given string id as title. |isVisible| specifies |
217 // if the column is initially visible. | 217 // if the column is initially visible. |
218 - (NSTableColumn*)addColumnWithId:(int)columnId visible:(BOOL)isVisible { | 218 - (NSTableColumn*)addColumnWithId:(int)columnId visible:(BOOL)isVisible { |
219 scoped_nsobject<NSTableColumn> column([[NSTableColumn alloc] | 219 base::scoped_nsobject<NSTableColumn> column([[NSTableColumn alloc] |
220 initWithIdentifier:[NSString stringWithFormat:@"%d", columnId]]); | 220 initWithIdentifier:[NSString stringWithFormat:@"%d", columnId]]); |
221 | 221 |
222 NSTextAlignment textAlignment = | 222 NSTextAlignment textAlignment = |
223 (columnId == IDS_TASK_MANAGER_TASK_COLUMN || | 223 (columnId == IDS_TASK_MANAGER_TASK_COLUMN || |
224 columnId == IDS_TASK_MANAGER_PROFILE_NAME_COLUMN) ? | 224 columnId == IDS_TASK_MANAGER_PROFILE_NAME_COLUMN) ? |
225 NSLeftTextAlignment : NSRightTextAlignment; | 225 NSLeftTextAlignment : NSRightTextAlignment; |
226 | 226 |
227 [[column.get() headerCell] | 227 [[column.get() headerCell] |
228 setStringValue:l10n_util::GetNSStringWithFixup(columnId)]; | 228 setStringValue:l10n_util::GetNSStringWithFixup(columnId)]; |
229 [[column.get() headerCell] setAlignment:textAlignment]; | 229 [[column.get() headerCell] setAlignment:textAlignment]; |
230 [[column.get() dataCell] setAlignment:textAlignment]; | 230 [[column.get() dataCell] setAlignment:textAlignment]; |
231 | 231 |
232 NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; | 232 NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
233 [[column.get() dataCell] setFont:font]; | 233 [[column.get() dataCell] setFont:font]; |
234 | 234 |
235 [column.get() setHidden:!isVisible]; | 235 [column.get() setHidden:!isVisible]; |
236 [column.get() setEditable:NO]; | 236 [column.get() setEditable:NO]; |
237 | 237 |
238 // The page column should by default be sorted ascending. | 238 // The page column should by default be sorted ascending. |
239 BOOL ascending = columnId == IDS_TASK_MANAGER_TASK_COLUMN; | 239 BOOL ascending = columnId == IDS_TASK_MANAGER_TASK_COLUMN; |
240 | 240 |
241 scoped_nsobject<NSSortDescriptor> sortDescriptor([[NSSortDescriptor alloc] | 241 base::scoped_nsobject<NSSortDescriptor> sortDescriptor( |
242 initWithKey:[NSString stringWithFormat:@"%d", columnId] | 242 [[NSSortDescriptor alloc] |
243 ascending:ascending]); | 243 initWithKey:[NSString stringWithFormat:@"%d", columnId] |
| 244 ascending:ascending]); |
244 [column.get() setSortDescriptorPrototype:sortDescriptor.get()]; | 245 [column.get() setSortDescriptorPrototype:sortDescriptor.get()]; |
245 | 246 |
246 // Default values, only used in release builds if nobody notices the DCHECK | 247 // Default values, only used in release builds if nobody notices the DCHECK |
247 // during development when adding new columns. | 248 // during development when adding new columns. |
248 int minWidth = 200, maxWidth = 400; | 249 int minWidth = 200, maxWidth = 400; |
249 | 250 |
250 size_t i; | 251 size_t i; |
251 for (i = 0; i < arraysize(columnWidths); ++i) { | 252 for (i = 0; i < arraysize(columnWidths); ++i) { |
252 if (columnWidths[i].columnId == columnId) { | 253 if (columnWidths[i].columnId == columnId) { |
253 minWidth = columnWidths[i].minWidth; | 254 minWidth = columnWidths[i].minWidth; |
(...skipping 14 matching lines...) Expand all Loading... |
268 } | 269 } |
269 | 270 |
270 // Adds all the task manager's columns to the table. | 271 // Adds all the task manager's columns to the table. |
271 - (void)setUpTableColumns { | 272 - (void)setUpTableColumns { |
272 for (NSTableColumn* column in [tableView_ tableColumns]) | 273 for (NSTableColumn* column in [tableView_ tableColumns]) |
273 [tableView_ removeTableColumn:column]; | 274 [tableView_ removeTableColumn:column]; |
274 NSTableColumn* nameColumn = [self addColumnWithId:IDS_TASK_MANAGER_TASK_COLUMN | 275 NSTableColumn* nameColumn = [self addColumnWithId:IDS_TASK_MANAGER_TASK_COLUMN |
275 visible:YES]; | 276 visible:YES]; |
276 // |nameColumn| displays an icon for every row -- this is done by an | 277 // |nameColumn| displays an icon for every row -- this is done by an |
277 // NSButtonCell. | 278 // NSButtonCell. |
278 scoped_nsobject<NSButtonCell> nameCell( | 279 base::scoped_nsobject<NSButtonCell> nameCell( |
279 [[NSButtonCell alloc] initTextCell:@""]); | 280 [[NSButtonCell alloc] initTextCell:@""]); |
280 [nameCell.get() setImagePosition:NSImageLeft]; | 281 [nameCell.get() setImagePosition:NSImageLeft]; |
281 [nameCell.get() setButtonType:NSSwitchButton]; | 282 [nameCell.get() setButtonType:NSSwitchButton]; |
282 [nameCell.get() setAlignment:[[nameColumn dataCell] alignment]]; | 283 [nameCell.get() setAlignment:[[nameColumn dataCell] alignment]]; |
283 [nameCell.get() setFont:[[nameColumn dataCell] font]]; | 284 [nameCell.get() setFont:[[nameColumn dataCell] font]]; |
284 [nameColumn setDataCell:nameCell.get()]; | 285 [nameColumn setDataCell:nameCell.get()]; |
285 | 286 |
286 // Initially, sort on the tab name. | 287 // Initially, sort on the tab name. |
287 [tableView_ setSortDescriptors: | 288 [tableView_ setSortDescriptors: |
288 [NSArray arrayWithObject:[nameColumn sortDescriptorPrototype]]]; | 289 [NSArray arrayWithObject:[nameColumn sortDescriptorPrototype]]]; |
(...skipping 14 matching lines...) Expand all Loading... |
303 [self addColumnWithId:IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN visible:NO]; | 304 [self addColumnWithId:IDS_TASK_MANAGER_SQLITE_MEMORY_USED_COLUMN visible:NO]; |
304 [self addColumnWithId:IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN | 305 [self addColumnWithId:IDS_TASK_MANAGER_JAVASCRIPT_MEMORY_ALLOCATED_COLUMN |
305 visible:NO]; | 306 visible:NO]; |
306 [self addColumnWithId:IDS_TASK_MANAGER_GOATS_TELEPORTED_COLUMN visible:NO]; | 307 [self addColumnWithId:IDS_TASK_MANAGER_GOATS_TELEPORTED_COLUMN visible:NO]; |
307 } | 308 } |
308 | 309 |
309 // Creates a context menu for the table header that allows the user to toggle | 310 // Creates a context menu for the table header that allows the user to toggle |
310 // which columns should be shown and which should be hidden (like e.g. | 311 // which columns should be shown and which should be hidden (like e.g. |
311 // Task Manager.app's table header context menu). | 312 // Task Manager.app's table header context menu). |
312 - (void)setUpTableHeaderContextMenu { | 313 - (void)setUpTableHeaderContextMenu { |
313 scoped_nsobject<NSMenu> contextMenu( | 314 base::scoped_nsobject<NSMenu> contextMenu( |
314 [[NSMenu alloc] initWithTitle:@"Task Manager context menu"]); | 315 [[NSMenu alloc] initWithTitle:@"Task Manager context menu"]); |
315 for (NSTableColumn* column in [tableView_ tableColumns]) { | 316 for (NSTableColumn* column in [tableView_ tableColumns]) { |
316 NSMenuItem* item = [contextMenu.get() | 317 NSMenuItem* item = [contextMenu.get() |
317 addItemWithTitle:[[column headerCell] stringValue] | 318 addItemWithTitle:[[column headerCell] stringValue] |
318 action:@selector(toggleColumn:) | 319 action:@selector(toggleColumn:) |
319 keyEquivalent:@""]; | 320 keyEquivalent:@""]; |
320 [item setTarget:self]; | 321 [item setTarget:self]; |
321 [item setRepresentedObject:column]; | 322 [item setRepresentedObject:column]; |
322 [item setState:[column isHidden] ? NSOffState : NSOnState]; | 323 [item setState:[column isHidden] ? NSOffState : NSOnState]; |
323 } | 324 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 | 532 |
532 namespace chrome { | 533 namespace chrome { |
533 | 534 |
534 // Declared in browser_dialogs.h. | 535 // Declared in browser_dialogs.h. |
535 void ShowTaskManager(Browser* browser) { | 536 void ShowTaskManager(Browser* browser) { |
536 TaskManagerMac::Show(); | 537 TaskManagerMac::Show(); |
537 } | 538 } |
538 | 539 |
539 } // namespace chrome | 540 } // namespace chrome |
540 | 541 |
OLD | NEW |