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 - (void)tableView:(NSTableView*)tableView | |
pink (ping after 24hrs)
2011/02/07 15:59:09
comment for method?
| |
385 willDisplayCell:(id)cell | |
pink (ping after 24hrs)
2011/02/07 15:59:09
minimum indent 4 spaces. That wins over lining up
| |
386 forTableColumn:(NSTableColumn*)tableColumn | |
387 row:(NSInteger)row { | |
388 if (!highlightBackgroundResources_) | |
389 return; | |
390 | |
391 bool isBackground = | |
392 taskManagerObserver_->IsBackgroundRow(viewToModelMap_[row]); | |
393 DCHECK([cell respondsToSelector:@selector(setBackgroundColor:)]); | |
394 if ([cell respondsToSelector:@selector(setBackgroundColor:)]) { | |
395 if (isBackground && ![tableView isRowSelected:row]) { | |
396 [cell setDrawsBackground:YES]; | |
397 [cell setBackgroundColor:backgroundResourceColor_]; | |
398 } else { | |
399 [cell setBackgroundColor:nil]; | |
400 [cell setDrawsBackground:NO]; | |
401 } | |
402 } | |
403 } | |
404 | |
373 @end | 405 @end |
374 | 406 |
375 @implementation TaskManagerWindowController (NSTableDataSource) | 407 @implementation TaskManagerWindowController (NSTableDataSource) |
376 | 408 |
377 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { | 409 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { |
378 DCHECK(tableView == tableView_ || tableView_ == nil); | 410 DCHECK(tableView == tableView_ || tableView_ == nil); |
379 return model_->ResourceCount(); | 411 return model_->ResourceCount(); |
380 } | 412 } |
381 | 413 |
382 - (NSString*)modelTextForRow:(int)row column:(int)columnId { | 414 - (NSString*)modelTextForRow:(int)row column:(int)columnId { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
495 | 527 |
496 currentSortDescriptor_.reset([[newDescriptors objectAtIndex:0] retain]); | 528 currentSortDescriptor_.reset([[newDescriptors objectAtIndex:0] retain]); |
497 [self reloadData]; // Sorts. | 529 [self reloadData]; // Sorts. |
498 } | 530 } |
499 | 531 |
500 @end | 532 @end |
501 | 533 |
502 //////////////////////////////////////////////////////////////////////////////// | 534 //////////////////////////////////////////////////////////////////////////////// |
503 // TaskManagerMac implementation: | 535 // TaskManagerMac implementation: |
504 | 536 |
505 TaskManagerMac::TaskManagerMac(TaskManager* task_manager) | 537 TaskManagerMac::TaskManagerMac(TaskManager* task_manager, |
538 bool highlight_background_resources) | |
506 : task_manager_(task_manager), | 539 : task_manager_(task_manager), |
507 model_(task_manager->model()), | 540 model_(task_manager->model()), |
508 icon_cache_(this) { | 541 icon_cache_(this), |
542 highlight_background_resources_(highlight_background_resources) { | |
509 window_controller_ = | 543 window_controller_ = |
510 [[TaskManagerWindowController alloc] initWithTaskManagerObserver:this]; | 544 [[TaskManagerWindowController alloc] |
545 initWithTaskManagerObserver:this | |
546 highlightBackgroundResources:highlight_background_resources]; | |
511 model_->AddObserver(this); | 547 model_->AddObserver(this); |
512 } | 548 } |
513 | 549 |
514 // static | 550 // static |
515 TaskManagerMac* TaskManagerMac::instance_ = NULL; | 551 TaskManagerMac* TaskManagerMac::instance_ = NULL; |
516 | 552 |
517 TaskManagerMac::~TaskManagerMac() { | 553 TaskManagerMac::~TaskManagerMac() { |
518 if (this == instance_) { | 554 if (this == instance_) { |
519 // Do not do this when running in unit tests: |StartUpdating()| never got | 555 // Do not do this when running in unit tests: |StartUpdating()| never got |
520 // called in that case. | 556 // called in that case. |
(...skipping 30 matching lines...) Expand all Loading... | |
551 | 587 |
552 NSImage* TaskManagerMac::GetImageForRow(int row) { | 588 NSImage* TaskManagerMac::GetImageForRow(int row) { |
553 return icon_cache_.GetImageForRow(row); | 589 return icon_cache_.GetImageForRow(row); |
554 } | 590 } |
555 | 591 |
556 //////////////////////////////////////////////////////////////////////////////// | 592 //////////////////////////////////////////////////////////////////////////////// |
557 // TaskManagerMac, public: | 593 // TaskManagerMac, public: |
558 | 594 |
559 void TaskManagerMac::WindowWasClosed() { | 595 void TaskManagerMac::WindowWasClosed() { |
560 delete this; | 596 delete this; |
561 instance_ = NULL; | 597 if (instance_ == this) |
pink (ping after 24hrs)
2011/02/07 15:59:09
when would this be not true? comment perhaps?
| |
598 instance_ = NULL; | |
562 } | 599 } |
563 | 600 |
564 int TaskManagerMac::RowCount() const { | 601 int TaskManagerMac::RowCount() const { |
565 return model_->ResourceCount(); | 602 return model_->ResourceCount(); |
566 } | 603 } |
567 | 604 |
568 SkBitmap TaskManagerMac::GetIcon(int r) const { | 605 SkBitmap TaskManagerMac::GetIcon(int r) const { |
569 return model_->GetResourceIcon(r); | 606 return model_->GetResourceIcon(r); |
570 } | 607 } |
571 | 608 |
609 bool TaskManagerMac::IsBackgroundRow(int row) const { | |
610 return model_->IsBackgroundResource(row); | |
611 } | |
612 | |
572 // static | 613 // static |
573 void TaskManagerMac::Show() { | 614 void TaskManagerMac::Show(bool highlight_background_resources) { |
574 if (instance_) { | 615 if (instance_) { |
575 // If there's a Task manager window open already, just activate it. | 616 if (instance_->highlight_background_resources_ == |
576 [[instance_->window_controller_ window] | 617 highlight_background_resources) { |
618 // There's a Task manager window open already, so just activate it. | |
619 [[instance_->window_controller_ window] | |
577 makeKeyAndOrderFront:instance_->window_controller_]; | 620 makeKeyAndOrderFront:instance_->window_controller_]; |
578 } else { | 621 return; |
579 instance_ = new TaskManagerMac(TaskManager::GetInstance()); | 622 } else { |
580 instance_->model_->StartUpdating(); | 623 // The user is switching between "View Background Pages" and |
624 // "Task Manager" so close the existing window and fall through to | |
625 // open a new one. | |
626 [[instance_->window_controller_ window] close]; | |
627 } | |
581 } | 628 } |
629 // Create a new instance. | |
630 instance_ = new TaskManagerMac(TaskManager::GetInstance(), | |
631 highlight_background_resources); | |
632 instance_->model_->StartUpdating(); | |
582 } | 633 } |
OLD | NEW |