| 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 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 // Some of the strings below have spaces at the end or are missing letters, to | 25 // Some of the strings below have spaces at the end or are missing letters, to |
| 26 // make the columns look nicer, and to take potentially longer localized strings | 26 // make the columns look nicer, and to take potentially longer localized strings |
| 27 // into account. | 27 // into account. |
| 28 const struct ColumnWidth { | 28 const struct ColumnWidth { |
| 29 int columnId; | 29 int columnId; |
| 30 int minWidth; | 30 int minWidth; |
| 31 int maxWidth; // If this is -1, 1.5*minColumWidth is used as max width. | 31 int maxWidth; // If this is -1, 1.5*minColumWidth is used as max width. |
| 32 } columnWidths[] = { | 32 } columnWidths[] = { |
| 33 // Note that arraysize includes the trailing \0. That's intended. | 33 // Note that arraysize includes the trailing \0. That's intended. |
| 34 { IDS_TASK_MANAGER_PAGE_COLUMN, 120, 600 }, | 34 { IDS_TASK_MANAGER_TASK_COLUMN, 120, 600 }, |
| 35 { IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, 60, 200 }, | 35 { IDS_TASK_MANAGER_PROFILE_NAME_COLUMN, 60, 200 }, |
| 36 { IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, | 36 { IDS_TASK_MANAGER_PHYSICAL_MEM_COLUMN, |
| 37 arraysize("800 MiB") * kCharWidth, -1 }, | 37 arraysize("800 MiB") * kCharWidth, -1 }, |
| 38 { IDS_TASK_MANAGER_SHARED_MEM_COLUMN, | 38 { IDS_TASK_MANAGER_SHARED_MEM_COLUMN, |
| 39 arraysize("800 MiB") * kCharWidth, -1 }, | 39 arraysize("800 MiB") * kCharWidth, -1 }, |
| 40 { IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, | 40 { IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN, |
| 41 arraysize("800 MiB") * kCharWidth, -1 }, | 41 arraysize("800 MiB") * kCharWidth, -1 }, |
| 42 { IDS_TASK_MANAGER_CPU_COLUMN, | 42 { IDS_TASK_MANAGER_CPU_COLUMN, |
| 43 arraysize("99.9") * kCharWidth, -1 }, | 43 arraysize("99.9") * kCharWidth, -1 }, |
| 44 { IDS_TASK_MANAGER_NET_COLUMN, | 44 { IDS_TASK_MANAGER_NET_COLUMN, |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 [super dealloc]; | 218 [super dealloc]; |
| 219 } | 219 } |
| 220 | 220 |
| 221 // Adds a column which has the given string id as title. |isVisible| specifies | 221 // Adds a column which has the given string id as title. |isVisible| specifies |
| 222 // if the column is initially visible. | 222 // if the column is initially visible. |
| 223 - (NSTableColumn*)addColumnWithId:(int)columnId visible:(BOOL)isVisible { | 223 - (NSTableColumn*)addColumnWithId:(int)columnId visible:(BOOL)isVisible { |
| 224 scoped_nsobject<NSTableColumn> column([[NSTableColumn alloc] | 224 scoped_nsobject<NSTableColumn> column([[NSTableColumn alloc] |
| 225 initWithIdentifier:[NSNumber numberWithInt:columnId]]); | 225 initWithIdentifier:[NSNumber numberWithInt:columnId]]); |
| 226 | 226 |
| 227 NSTextAlignment textAlignment = | 227 NSTextAlignment textAlignment = |
| 228 (columnId == IDS_TASK_MANAGER_PAGE_COLUMN || | 228 (columnId == IDS_TASK_MANAGER_TASK_COLUMN || |
| 229 columnId == IDS_TASK_MANAGER_PROFILE_NAME_COLUMN) ? | 229 columnId == IDS_TASK_MANAGER_PROFILE_NAME_COLUMN) ? |
| 230 NSLeftTextAlignment : NSRightTextAlignment; | 230 NSLeftTextAlignment : NSRightTextAlignment; |
| 231 | 231 |
| 232 [[column.get() headerCell] | 232 [[column.get() headerCell] |
| 233 setStringValue:l10n_util::GetNSStringWithFixup(columnId)]; | 233 setStringValue:l10n_util::GetNSStringWithFixup(columnId)]; |
| 234 [[column.get() headerCell] setAlignment:textAlignment]; | 234 [[column.get() headerCell] setAlignment:textAlignment]; |
| 235 [[column.get() dataCell] setAlignment:textAlignment]; | 235 [[column.get() dataCell] setAlignment:textAlignment]; |
| 236 | 236 |
| 237 NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; | 237 NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
| 238 [[column.get() dataCell] setFont:font]; | 238 [[column.get() dataCell] setFont:font]; |
| 239 | 239 |
| 240 [column.get() setHidden:!isVisible]; | 240 [column.get() setHidden:!isVisible]; |
| 241 [column.get() setEditable:NO]; | 241 [column.get() setEditable:NO]; |
| 242 | 242 |
| 243 // The page column should by default be sorted ascending. | 243 // The page column should by default be sorted ascending. |
| 244 BOOL ascending = columnId == IDS_TASK_MANAGER_PAGE_COLUMN; | 244 BOOL ascending = columnId == IDS_TASK_MANAGER_TASK_COLUMN; |
| 245 | 245 |
| 246 scoped_nsobject<NSSortDescriptor> sortDescriptor([[NSSortDescriptor alloc] | 246 scoped_nsobject<NSSortDescriptor> sortDescriptor([[NSSortDescriptor alloc] |
| 247 initWithKey:[NSString stringWithFormat:@"%d", columnId] | 247 initWithKey:[NSString stringWithFormat:@"%d", columnId] |
| 248 ascending:ascending]); | 248 ascending:ascending]); |
| 249 [column.get() setSortDescriptorPrototype:sortDescriptor.get()]; | 249 [column.get() setSortDescriptorPrototype:sortDescriptor.get()]; |
| 250 | 250 |
| 251 // Default values, only used in release builds if nobody notices the DCHECK | 251 // Default values, only used in release builds if nobody notices the DCHECK |
| 252 // during development when adding new columns. | 252 // during development when adding new columns. |
| 253 int minWidth = 200, maxWidth = 400; | 253 int minWidth = 200, maxWidth = 400; |
| 254 | 254 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 269 NSTableColumnUserResizingMask]; | 269 NSTableColumnUserResizingMask]; |
| 270 | 270 |
| 271 [tableView_ addTableColumn:column.get()]; | 271 [tableView_ addTableColumn:column.get()]; |
| 272 return column.get(); // Now retained by |tableView_|. | 272 return column.get(); // Now retained by |tableView_|. |
| 273 } | 273 } |
| 274 | 274 |
| 275 // Adds all the task manager's columns to the table. | 275 // Adds all the task manager's columns to the table. |
| 276 - (void)setUpTableColumns { | 276 - (void)setUpTableColumns { |
| 277 for (NSTableColumn* column in [tableView_ tableColumns]) | 277 for (NSTableColumn* column in [tableView_ tableColumns]) |
| 278 [tableView_ removeTableColumn:column]; | 278 [tableView_ removeTableColumn:column]; |
| 279 NSTableColumn* nameColumn = [self addColumnWithId:IDS_TASK_MANAGER_PAGE_COLUMN | 279 NSTableColumn* nameColumn = [self addColumnWithId:IDS_TASK_MANAGER_TASK_COLUMN |
| 280 visible:YES]; | 280 visible:YES]; |
| 281 // |nameColumn| displays an icon for every row -- this is done by an | 281 // |nameColumn| displays an icon for every row -- this is done by an |
| 282 // NSButtonCell. | 282 // NSButtonCell. |
| 283 scoped_nsobject<NSButtonCell> nameCell( | 283 scoped_nsobject<NSButtonCell> nameCell( |
| 284 [[NSButtonCell alloc] initTextCell:@""]); | 284 [[NSButtonCell alloc] initTextCell:@""]); |
| 285 [nameCell.get() setImagePosition:NSImageLeft]; | 285 [nameCell.get() setImagePosition:NSImageLeft]; |
| 286 [nameCell.get() setButtonType:NSSwitchButton]; | 286 [nameCell.get() setButtonType:NSSwitchButton]; |
| 287 [nameCell.get() setAlignment:[[nameColumn dataCell] alignment]]; | 287 [nameCell.get() setAlignment:[[nameColumn dataCell] alignment]]; |
| 288 [nameCell.get() setFont:[[nameColumn dataCell] font]]; | 288 [nameCell.get() setFont:[[nameColumn dataCell] font]]; |
| 289 [nameColumn setDataCell:nameCell.get()]; | 289 [nameColumn setDataCell:nameCell.get()]; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 | 425 |
| 426 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { | 426 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { |
| 427 DCHECK(tableView == tableView_ || tableView_ == nil); | 427 DCHECK(tableView == tableView_ || tableView_ == nil); |
| 428 return model_->ResourceCount(); | 428 return model_->ResourceCount(); |
| 429 } | 429 } |
| 430 | 430 |
| 431 - (NSString*)modelTextForRow:(int)row column:(int)columnId { | 431 - (NSString*)modelTextForRow:(int)row column:(int)columnId { |
| 432 DCHECK_LT(static_cast<size_t>(row), viewToModelMap_.size()); | 432 DCHECK_LT(static_cast<size_t>(row), viewToModelMap_.size()); |
| 433 row = viewToModelMap_[row]; | 433 row = viewToModelMap_[row]; |
| 434 switch (columnId) { | 434 switch (columnId) { |
| 435 case IDS_TASK_MANAGER_PAGE_COLUMN: // Process | 435 case IDS_TASK_MANAGER_TASK_COLUMN: // Process |
| 436 return base::SysUTF16ToNSString(model_->GetResourceTitle(row)); | 436 return base::SysUTF16ToNSString(model_->GetResourceTitle(row)); |
| 437 | 437 |
| 438 case IDS_TASK_MANAGER_PROFILE_NAME_COLUMN: // Profile Name | 438 case IDS_TASK_MANAGER_PROFILE_NAME_COLUMN: // Profile Name |
| 439 return base::SysUTF16ToNSString(model_->GetResourceProfileName(row)); | 439 return base::SysUTF16ToNSString(model_->GetResourceProfileName(row)); |
| 440 | 440 |
| 441 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: // Memory | 441 case IDS_TASK_MANAGER_PRIVATE_MEM_COLUMN: // Memory |
| 442 if (!model_->IsResourceFirstInGroup(row)) | 442 if (!model_->IsResourceFirstInGroup(row)) |
| 443 return @""; | 443 return @""; |
| 444 return base::SysUTF16ToNSString(model_->GetResourcePrivateMemory(row)); | 444 return base::SysUTF16ToNSString(model_->GetResourcePrivateMemory(row)); |
| 445 | 445 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 NOTREACHED(); | 506 NOTREACHED(); |
| 507 return @""; | 507 return @""; |
| 508 } | 508 } |
| 509 } | 509 } |
| 510 | 510 |
| 511 - (id)tableView:(NSTableView*)tableView | 511 - (id)tableView:(NSTableView*)tableView |
| 512 objectValueForTableColumn:(NSTableColumn*)tableColumn | 512 objectValueForTableColumn:(NSTableColumn*)tableColumn |
| 513 row:(NSInteger)rowIndex { | 513 row:(NSInteger)rowIndex { |
| 514 // NSButtonCells expect an on/off state as objectValue. Their title is set | 514 // NSButtonCells expect an on/off state as objectValue. Their title is set |
| 515 // in |tableView:dataCellForTableColumn:row:| below. | 515 // in |tableView:dataCellForTableColumn:row:| below. |
| 516 if ([[tableColumn identifier] intValue] == IDS_TASK_MANAGER_PAGE_COLUMN) { | 516 if ([[tableColumn identifier] intValue] == IDS_TASK_MANAGER_TASK_COLUMN) { |
| 517 return [NSNumber numberWithInt:NSOffState]; | 517 return [NSNumber numberWithInt:NSOffState]; |
| 518 } | 518 } |
| 519 | 519 |
| 520 return [self modelTextForRow:rowIndex | 520 return [self modelTextForRow:rowIndex |
| 521 column:[[tableColumn identifier] intValue]]; | 521 column:[[tableColumn identifier] intValue]]; |
| 522 } | 522 } |
| 523 | 523 |
| 524 - (NSCell*)tableView:(NSTableView*)tableView | 524 - (NSCell*)tableView:(NSTableView*)tableView |
| 525 dataCellForTableColumn:(NSTableColumn*)tableColumn | 525 dataCellForTableColumn:(NSTableColumn*)tableColumn |
| 526 row:(NSInteger)rowIndex { | 526 row:(NSInteger)rowIndex { |
| 527 NSCell* cell = [tableColumn dataCellForRow:rowIndex]; | 527 NSCell* cell = [tableColumn dataCellForRow:rowIndex]; |
| 528 | 528 |
| 529 // Set the favicon and title for the task in the name column. | 529 // Set the favicon and title for the task in the name column. |
| 530 if ([[tableColumn identifier] intValue] == IDS_TASK_MANAGER_PAGE_COLUMN) { | 530 if ([[tableColumn identifier] intValue] == IDS_TASK_MANAGER_TASK_COLUMN) { |
| 531 DCHECK([cell isKindOfClass:[NSButtonCell class]]); | 531 DCHECK([cell isKindOfClass:[NSButtonCell class]]); |
| 532 NSButtonCell* buttonCell = static_cast<NSButtonCell*>(cell); | 532 NSButtonCell* buttonCell = static_cast<NSButtonCell*>(cell); |
| 533 NSString* title = [self modelTextForRow:rowIndex | 533 NSString* title = [self modelTextForRow:rowIndex |
| 534 column:[[tableColumn identifier] intValue]]; | 534 column:[[tableColumn identifier] intValue]]; |
| 535 [buttonCell setTitle:title]; | 535 [buttonCell setTitle:title]; |
| 536 [buttonCell setImage: | 536 [buttonCell setImage: |
| 537 taskManagerObserver_->GetImageForRow(viewToModelMap_[rowIndex])]; | 537 taskManagerObserver_->GetImageForRow(viewToModelMap_[rowIndex])]; |
| 538 [buttonCell setRefusesFirstResponder:YES]; // Don't push in like a button. | 538 [buttonCell setRefusesFirstResponder:YES]; // Don't push in like a button. |
| 539 [buttonCell setHighlightsBy:NSNoCellMask]; | 539 [buttonCell setHighlightsBy:NSNoCellMask]; |
| 540 } | 540 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 // "Task Manager" so close the existing window and fall through to | 646 // "Task Manager" so close the existing window and fall through to |
| 647 // open a new one. | 647 // open a new one. |
| 648 [[instance_->window_controller_ window] close]; | 648 [[instance_->window_controller_ window] close]; |
| 649 } | 649 } |
| 650 } | 650 } |
| 651 // Create a new instance. | 651 // Create a new instance. |
| 652 instance_ = new TaskManagerMac(TaskManager::GetInstance(), | 652 instance_ = new TaskManagerMac(TaskManager::GetInstance(), |
| 653 highlight_background_resources); | 653 highlight_background_resources); |
| 654 instance_->model_->StartUpdating(); | 654 instance_->model_->StartUpdating(); |
| 655 } | 655 } |
| OLD | NEW |