OLD | NEW |
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 #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/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 - (void)toggleColumn:(id)sender; | 95 - (void)toggleColumn:(id)sender; |
96 - (void)adjustSelectionAndEndProcessButton; | 96 - (void)adjustSelectionAndEndProcessButton; |
97 - (void)deselectRows; | 97 - (void)deselectRows; |
98 @end | 98 @end |
99 | 99 |
100 //////////////////////////////////////////////////////////////////////////////// | 100 //////////////////////////////////////////////////////////////////////////////// |
101 // TaskManagerWindowController implementation: | 101 // TaskManagerWindowController implementation: |
102 | 102 |
103 @implementation TaskManagerWindowController | 103 @implementation TaskManagerWindowController |
104 | 104 |
105 - (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver { | 105 - (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver |
| 106 highlightBackgroundResources:(bool)highlightBackgroundResources { |
106 NSString* nibpath = [base::mac::MainAppBundle() | 107 NSString* nibpath = [base::mac::MainAppBundle() |
107 pathForResource:@"TaskManager" | 108 pathForResource:@"TaskManager" |
108 ofType:@"nib"]; | 109 ofType:@"nib"]; |
109 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 110 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
110 taskManagerObserver_ = taskManagerObserver; | 111 taskManagerObserver_ = taskManagerObserver; |
111 taskManager_ = taskManagerObserver_->task_manager(); | 112 taskManager_ = taskManagerObserver_->task_manager(); |
112 model_ = taskManager_->model(); | 113 model_ = taskManager_->model(); |
| 114 highlightBackgroundResources_ = highlightBackgroundResources; |
| 115 if (highlightBackgroundResources_) { |
| 116 // Highlight background resources with a yellow background. |
| 117 backgroundResourceColor_.reset( |
| 118 [[NSColor colorWithDeviceRed:0xff/255.0 |
| 119 green:0xfa/255.0 |
| 120 blue:0xcd/255.0 |
| 121 alpha:1.0] retain]); |
| 122 } |
113 | 123 |
114 if (g_browser_process && g_browser_process->local_state()) { | 124 if (g_browser_process && g_browser_process->local_state()) { |
115 size_saver_.reset([[WindowSizeAutosaver alloc] | 125 size_saver_.reset([[WindowSizeAutosaver alloc] |
116 initWithWindow:[self window] | 126 initWithWindow:[self window] |
117 prefService:g_browser_process->local_state() | 127 prefService:g_browser_process->local_state() |
118 path:prefs::kTaskManagerWindowPlacement]); | 128 path:prefs::kTaskManagerWindowPlacement]); |
119 } | 129 } |
120 [self showWindow:self]; | 130 [self showWindow:self]; |
121 } | 131 } |
122 return self; | 132 return self; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 - (NSTableView*)tableView { | 195 - (NSTableView*)tableView { |
186 return tableView_; | 196 return tableView_; |
187 } | 197 } |
188 | 198 |
189 - (void)awakeFromNib { | 199 - (void)awakeFromNib { |
190 [self setUpTableColumns]; | 200 [self setUpTableColumns]; |
191 [self setUpTableHeaderContextMenu]; | 201 [self setUpTableHeaderContextMenu]; |
192 [self adjustSelectionAndEndProcessButton]; | 202 [self adjustSelectionAndEndProcessButton]; |
193 | 203 |
194 [tableView_ setDoubleAction:@selector(selectDoubleClickedTab:)]; | 204 [tableView_ setDoubleAction:@selector(selectDoubleClickedTab:)]; |
| 205 [tableView_ setIntercellSpacing:NSMakeSize(0.0, 0.0)]; |
195 [tableView_ sizeToFit]; | 206 [tableView_ sizeToFit]; |
196 } | 207 } |
197 | 208 |
198 - (void)dealloc { | 209 - (void)dealloc { |
199 [tableView_ setDelegate:nil]; | 210 [tableView_ setDelegate:nil]; |
200 [tableView_ setDataSource:nil]; | 211 [tableView_ setDataSource:nil]; |
201 [super dealloc]; | 212 [super dealloc]; |
202 } | 213 } |
203 | 214 |
204 // Adds a column which has the given string id as title. |isVisible| specifies | 215 // Adds a column which has the given string id as title. |isVisible| specifies |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 } | 374 } |
364 | 375 |
365 - (void)windowWillClose:(NSNotification*)notification { | 376 - (void)windowWillClose:(NSNotification*)notification { |
366 if (taskManagerObserver_) { | 377 if (taskManagerObserver_) { |
367 taskManagerObserver_->WindowWasClosed(); | 378 taskManagerObserver_->WindowWasClosed(); |
368 taskManagerObserver_ = nil; | 379 taskManagerObserver_ = nil; |
369 } | 380 } |
370 [self autorelease]; | 381 [self autorelease]; |
371 } | 382 } |
372 | 383 |
| 384 // Delegate method invoked before each cell in the table is displayed. We |
| 385 // override this to provide highlighting of background resources. |
| 386 - (void) tableView:(NSTableView*)tableView |
| 387 willDisplayCell:(id)cell |
| 388 forTableColumn:(NSTableColumn*)tableColumn |
| 389 row:(NSInteger)row { |
| 390 if (!highlightBackgroundResources_) |
| 391 return; |
| 392 |
| 393 bool isBackground = |
| 394 taskManagerObserver_->IsBackgroundRow(viewToModelMap_[row]); |
| 395 DCHECK([cell respondsToSelector:@selector(setBackgroundColor:)]); |
| 396 if ([cell respondsToSelector:@selector(setBackgroundColor:)]) { |
| 397 if (isBackground && ![tableView isRowSelected:row]) { |
| 398 [cell setDrawsBackground:YES]; |
| 399 [cell setBackgroundColor:backgroundResourceColor_]; |
| 400 } else { |
| 401 [cell setBackgroundColor:nil]; |
| 402 [cell setDrawsBackground:NO]; |
| 403 } |
| 404 } |
| 405 } |
| 406 |
373 @end | 407 @end |
374 | 408 |
375 @implementation TaskManagerWindowController (NSTableDataSource) | 409 @implementation TaskManagerWindowController (NSTableDataSource) |
376 | 410 |
377 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { | 411 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { |
378 DCHECK(tableView == tableView_ || tableView_ == nil); | 412 DCHECK(tableView == tableView_ || tableView_ == nil); |
379 return model_->ResourceCount(); | 413 return model_->ResourceCount(); |
380 } | 414 } |
381 | 415 |
382 - (NSString*)modelTextForRow:(int)row column:(int)columnId { | 416 - (NSString*)modelTextForRow:(int)row column:(int)columnId { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 | 529 |
496 currentSortDescriptor_.reset([[newDescriptors objectAtIndex:0] retain]); | 530 currentSortDescriptor_.reset([[newDescriptors objectAtIndex:0] retain]); |
497 [self reloadData]; // Sorts. | 531 [self reloadData]; // Sorts. |
498 } | 532 } |
499 | 533 |
500 @end | 534 @end |
501 | 535 |
502 //////////////////////////////////////////////////////////////////////////////// | 536 //////////////////////////////////////////////////////////////////////////////// |
503 // TaskManagerMac implementation: | 537 // TaskManagerMac implementation: |
504 | 538 |
505 TaskManagerMac::TaskManagerMac(TaskManager* task_manager) | 539 TaskManagerMac::TaskManagerMac(TaskManager* task_manager, |
| 540 bool highlight_background_resources) |
506 : task_manager_(task_manager), | 541 : task_manager_(task_manager), |
507 model_(task_manager->model()), | 542 model_(task_manager->model()), |
508 icon_cache_(this) { | 543 icon_cache_(this), |
| 544 highlight_background_resources_(highlight_background_resources) { |
509 window_controller_ = | 545 window_controller_ = |
510 [[TaskManagerWindowController alloc] initWithTaskManagerObserver:this]; | 546 [[TaskManagerWindowController alloc] |
| 547 initWithTaskManagerObserver:this |
| 548 highlightBackgroundResources:highlight_background_resources]; |
511 model_->AddObserver(this); | 549 model_->AddObserver(this); |
512 } | 550 } |
513 | 551 |
514 // static | 552 // static |
515 TaskManagerMac* TaskManagerMac::instance_ = NULL; | 553 TaskManagerMac* TaskManagerMac::instance_ = NULL; |
516 | 554 |
517 TaskManagerMac::~TaskManagerMac() { | 555 TaskManagerMac::~TaskManagerMac() { |
518 if (this == instance_) { | 556 if (this == instance_) { |
519 // Do not do this when running in unit tests: |StartUpdating()| never got | 557 // Do not do this when running in unit tests: |StartUpdating()| never got |
520 // called in that case. | 558 // called in that case. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 } | 600 } |
563 | 601 |
564 int TaskManagerMac::RowCount() const { | 602 int TaskManagerMac::RowCount() const { |
565 return model_->ResourceCount(); | 603 return model_->ResourceCount(); |
566 } | 604 } |
567 | 605 |
568 SkBitmap TaskManagerMac::GetIcon(int r) const { | 606 SkBitmap TaskManagerMac::GetIcon(int r) const { |
569 return model_->GetResourceIcon(r); | 607 return model_->GetResourceIcon(r); |
570 } | 608 } |
571 | 609 |
| 610 bool TaskManagerMac::IsBackgroundRow(int row) const { |
| 611 return model_->IsBackgroundResource(row); |
| 612 } |
| 613 |
572 // static | 614 // static |
573 void TaskManagerMac::Show() { | 615 void TaskManagerMac::Show(bool highlight_background_resources) { |
574 if (instance_) { | 616 if (instance_) { |
575 // If there's a Task manager window open already, just activate it. | 617 if (instance_->highlight_background_resources_ == |
576 [[instance_->window_controller_ window] | 618 highlight_background_resources) { |
| 619 // There's a Task manager window open already, so just activate it. |
| 620 [[instance_->window_controller_ window] |
577 makeKeyAndOrderFront:instance_->window_controller_]; | 621 makeKeyAndOrderFront:instance_->window_controller_]; |
578 } else { | 622 return; |
579 instance_ = new TaskManagerMac(TaskManager::GetInstance()); | 623 } else { |
580 instance_->model_->StartUpdating(); | 624 // The user is switching between "View Background Pages" and |
| 625 // "Task Manager" so close the existing window and fall through to |
| 626 // open a new one. |
| 627 [[instance_->window_controller_ window] close]; |
| 628 } |
581 } | 629 } |
| 630 // Create a new instance. |
| 631 instance_ = new TaskManagerMac(TaskManager::GetInstance(), |
| 632 highlight_background_resources); |
| 633 instance_->model_->StartUpdating(); |
582 } | 634 } |
OLD | NEW |