| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 - (void)toggleColumn:(id)sender; | 106 - (void)toggleColumn:(id)sender; |
| 107 - (void)adjustSelectionAndEndProcessButton; | 107 - (void)adjustSelectionAndEndProcessButton; |
| 108 - (void)deselectRows; | 108 - (void)deselectRows; |
| 109 @end | 109 @end |
| 110 | 110 |
| 111 //////////////////////////////////////////////////////////////////////////////// | 111 //////////////////////////////////////////////////////////////////////////////// |
| 112 // TaskManagerWindowController implementation: | 112 // TaskManagerWindowController implementation: |
| 113 | 113 |
| 114 @implementation TaskManagerWindowController | 114 @implementation TaskManagerWindowController |
| 115 | 115 |
| 116 - (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver | 116 - (id)initWithTaskManagerObserver:(TaskManagerMac*)taskManagerObserver { |
| 117 highlightBackgroundResources:(bool)highlightBackgroundResources { | |
| 118 NSString* nibpath = [base::mac::FrameworkBundle() | 117 NSString* nibpath = [base::mac::FrameworkBundle() |
| 119 pathForResource:@"TaskManager" | 118 pathForResource:@"TaskManager" |
| 120 ofType:@"nib"]; | 119 ofType:@"nib"]; |
| 121 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 120 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
| 122 taskManagerObserver_ = taskManagerObserver; | 121 taskManagerObserver_ = taskManagerObserver; |
| 123 taskManager_ = taskManagerObserver_->task_manager(); | 122 taskManager_ = taskManagerObserver_->task_manager(); |
| 124 model_ = taskManager_->model(); | 123 model_ = taskManager_->model(); |
| 125 highlightBackgroundResources_ = highlightBackgroundResources; | |
| 126 if (highlightBackgroundResources_) { | |
| 127 // Highlight background resources with a yellow background. | |
| 128 backgroundResourceColor_.reset( | |
| 129 [[NSColor colorWithDeviceRed:0xff/255.0 | |
| 130 green:0xfa/255.0 | |
| 131 blue:0xcd/255.0 | |
| 132 alpha:1.0] retain]); | |
| 133 } | |
| 134 | 124 |
| 135 if (g_browser_process && g_browser_process->local_state()) { | 125 if (g_browser_process && g_browser_process->local_state()) { |
| 136 size_saver_.reset([[WindowSizeAutosaver alloc] | 126 size_saver_.reset([[WindowSizeAutosaver alloc] |
| 137 initWithWindow:[self window] | 127 initWithWindow:[self window] |
| 138 prefService:g_browser_process->local_state() | 128 prefService:g_browser_process->local_state() |
| 139 path:prefs::kTaskManagerWindowPlacement]); | 129 path:prefs::kTaskManagerWindowPlacement]); |
| 140 } | 130 } |
| 141 [self showWindow:self]; | 131 [self showWindow:self]; |
| 142 } | 132 } |
| 143 return self; | 133 return self; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 } | 379 } |
| 390 | 380 |
| 391 - (void)windowWillClose:(NSNotification*)notification { | 381 - (void)windowWillClose:(NSNotification*)notification { |
| 392 if (taskManagerObserver_) { | 382 if (taskManagerObserver_) { |
| 393 taskManagerObserver_->WindowWasClosed(); | 383 taskManagerObserver_->WindowWasClosed(); |
| 394 taskManagerObserver_ = nil; | 384 taskManagerObserver_ = nil; |
| 395 } | 385 } |
| 396 [self autorelease]; | 386 [self autorelease]; |
| 397 } | 387 } |
| 398 | 388 |
| 399 // Delegate method invoked before each cell in the table is displayed. We | |
| 400 // override this to provide highlighting of background resources. | |
| 401 - (void) tableView:(NSTableView*)tableView | |
| 402 willDisplayCell:(id)cell | |
| 403 forTableColumn:(NSTableColumn*)tableColumn | |
| 404 row:(NSInteger)row { | |
| 405 if (!highlightBackgroundResources_) | |
| 406 return; | |
| 407 | |
| 408 DCHECK([cell respondsToSelector:@selector(setBackgroundColor:)]); | |
| 409 if ([cell respondsToSelector:@selector(setBackgroundColor:)]) { | |
| 410 NSColor* color = nil; | |
| 411 if (taskManagerObserver_->IsBackgroundRow(viewToModelMap_[row]) && | |
| 412 ![tableView isRowSelected:row]) { | |
| 413 color = backgroundResourceColor_.get(); | |
| 414 if ((row % 2) == 1 && [tableView usesAlternatingRowBackgroundColors]) { | |
| 415 color = [color blendedColorWithFraction:0.05 | |
| 416 ofColor:[NSColor blackColor]]; | |
| 417 } | |
| 418 } | |
| 419 [cell setBackgroundColor:color]; | |
| 420 | |
| 421 // The icon at the left is an |NSButtonCell|, which does not | |
| 422 // implement this method on 10.5. | |
| 423 if ([cell respondsToSelector:@selector(setDrawsBackground:)]) | |
| 424 [cell setDrawsBackground:(color != nil)]; | |
| 425 } | |
| 426 } | |
| 427 | |
| 428 @end | 389 @end |
| 429 | 390 |
| 430 @implementation TaskManagerWindowController (NSTableDataSource) | 391 @implementation TaskManagerWindowController (NSTableDataSource) |
| 431 | 392 |
| 432 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { | 393 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { |
| 433 DCHECK(tableView == tableView_ || tableView_ == nil); | 394 DCHECK(tableView == tableView_ || tableView_ == nil); |
| 434 return model_->ResourceCount(); | 395 return model_->ResourceCount(); |
| 435 } | 396 } |
| 436 | 397 |
| 437 - (NSString*)modelTextForRow:(int)row column:(int)columnId { | 398 - (NSString*)modelTextForRow:(int)row column:(int)columnId { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 | 443 |
| 483 currentSortDescriptor_.reset([[newDescriptors objectAtIndex:0] retain]); | 444 currentSortDescriptor_.reset([[newDescriptors objectAtIndex:0] retain]); |
| 484 [self reloadData]; // Sorts. | 445 [self reloadData]; // Sorts. |
| 485 } | 446 } |
| 486 | 447 |
| 487 @end | 448 @end |
| 488 | 449 |
| 489 //////////////////////////////////////////////////////////////////////////////// | 450 //////////////////////////////////////////////////////////////////////////////// |
| 490 // TaskManagerMac implementation: | 451 // TaskManagerMac implementation: |
| 491 | 452 |
| 492 TaskManagerMac::TaskManagerMac(TaskManager* task_manager, | 453 TaskManagerMac::TaskManagerMac(TaskManager* task_manager) |
| 493 bool highlight_background_resources) | |
| 494 : task_manager_(task_manager), | 454 : task_manager_(task_manager), |
| 495 model_(task_manager->model()), | 455 model_(task_manager->model()), |
| 496 icon_cache_(this), | 456 icon_cache_(this) { |
| 497 highlight_background_resources_(highlight_background_resources) { | |
| 498 window_controller_ = | 457 window_controller_ = |
| 499 [[TaskManagerWindowController alloc] | 458 [[TaskManagerWindowController alloc] initWithTaskManagerObserver:this]; |
| 500 initWithTaskManagerObserver:this | |
| 501 highlightBackgroundResources:highlight_background_resources]; | |
| 502 model_->AddObserver(this); | 459 model_->AddObserver(this); |
| 503 } | 460 } |
| 504 | 461 |
| 505 // static | 462 // static |
| 506 TaskManagerMac* TaskManagerMac::instance_ = NULL; | 463 TaskManagerMac* TaskManagerMac::instance_ = NULL; |
| 507 | 464 |
| 508 TaskManagerMac::~TaskManagerMac() { | 465 TaskManagerMac::~TaskManagerMac() { |
| 509 if (this == instance_) { | 466 if (this == instance_) { |
| 510 // Do not do this when running in unit tests: |StartUpdating()| never got | 467 // Do not do this when running in unit tests: |StartUpdating()| never got |
| 511 // called in that case. | 468 // called in that case. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 } | 510 } |
| 554 | 511 |
| 555 int TaskManagerMac::RowCount() const { | 512 int TaskManagerMac::RowCount() const { |
| 556 return model_->ResourceCount(); | 513 return model_->ResourceCount(); |
| 557 } | 514 } |
| 558 | 515 |
| 559 gfx::ImageSkia TaskManagerMac::GetIcon(int r) const { | 516 gfx::ImageSkia TaskManagerMac::GetIcon(int r) const { |
| 560 return model_->GetResourceIcon(r); | 517 return model_->GetResourceIcon(r); |
| 561 } | 518 } |
| 562 | 519 |
| 563 bool TaskManagerMac::IsBackgroundRow(int row) const { | |
| 564 return model_->IsBackgroundResource(row); | |
| 565 } | |
| 566 | |
| 567 // static | 520 // static |
| 568 void TaskManagerMac::Show(bool highlight_background_resources) { | 521 void TaskManagerMac::Show() { |
| 569 if (instance_) { | 522 if (instance_) { |
| 570 if (instance_->highlight_background_resources_ == | 523 [[instance_->window_controller_ window] |
| 571 highlight_background_resources) { | 524 makeKeyAndOrderFront:instance_->window_controller_]; |
| 572 // There's a Task manager window open already, so just activate it. | 525 return; |
| 573 [[instance_->window_controller_ window] | |
| 574 makeKeyAndOrderFront:instance_->window_controller_]; | |
| 575 return; | |
| 576 } else { | |
| 577 // The user is switching between "View Background Pages" and | |
| 578 // "Task Manager" so close the existing window and fall through to | |
| 579 // open a new one. | |
| 580 [[instance_->window_controller_ window] close]; | |
| 581 } | |
| 582 } | 526 } |
| 583 // Create a new instance. | 527 // Create a new instance. |
| 584 instance_ = new TaskManagerMac(TaskManager::GetInstance(), | 528 instance_ = new TaskManagerMac(TaskManager::GetInstance()); |
| 585 highlight_background_resources); | |
| 586 instance_->model_->StartUpdating(); | 529 instance_->model_->StartUpdating(); |
| 587 } | 530 } |
| 588 | 531 |
| 589 namespace chrome { | 532 namespace chrome { |
| 590 | 533 |
| 591 // Declared in browser_dialogs.h. | 534 // Declared in browser_dialogs.h. |
| 592 void ShowTaskManager(Browser* browser, bool highlight_background_resources) { | 535 void ShowTaskManager(Browser* browser) { |
| 593 TaskManagerMac::Show(highlight_background_resources); | 536 TaskManagerMac::Show(); |
| 594 } | 537 } |
| 595 | 538 |
| 596 } // namespace chrome | 539 } // namespace chrome |
| 597 | 540 |
| OLD | NEW |