| 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/task_manager/task_manager.h" | 5 #include "chrome/browser/task_manager/task_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 147 } |
| 148 | 148 |
| 149 // The Task Manager UI container. | 149 // The Task Manager UI container. |
| 150 class TaskManagerView : public views::ButtonListener, | 150 class TaskManagerView : public views::ButtonListener, |
| 151 public views::DialogDelegateView, | 151 public views::DialogDelegateView, |
| 152 public views::TableViewObserver, | 152 public views::TableViewObserver, |
| 153 public views::LinkListener, | 153 public views::LinkListener, |
| 154 public views::ContextMenuController, | 154 public views::ContextMenuController, |
| 155 public ui::SimpleMenuModel::Delegate { | 155 public ui::SimpleMenuModel::Delegate { |
| 156 public: | 156 public: |
| 157 explicit TaskManagerView(chrome::HostDesktopType desktop_type); | 157 TaskManagerView(); |
| 158 ~TaskManagerView() override; | 158 ~TaskManagerView() override; |
| 159 | 159 |
| 160 // Shows the Task Manager window, or re-activates an existing one. | 160 // Shows the Task Manager window, or re-activates an existing one. |
| 161 static void Show(Browser* browser); | 161 static void Show(Browser* browser); |
| 162 | 162 |
| 163 // Hides the Task Manager if it is showing. | 163 // Hides the Task Manager if it is showing. |
| 164 static void Hide(); | 164 static void Hide(); |
| 165 | 165 |
| 166 // views::View: | 166 // views::View: |
| 167 void Layout() override; | 167 void Layout() override; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 TaskManagerModel* model_; | 227 TaskManagerModel* model_; |
| 228 | 228 |
| 229 // all possible columns, not necessarily visible | 229 // all possible columns, not necessarily visible |
| 230 std::vector<ui::TableColumn> columns_; | 230 std::vector<ui::TableColumn> columns_; |
| 231 | 231 |
| 232 scoped_ptr<TaskManagerTableModel> table_model_; | 232 scoped_ptr<TaskManagerTableModel> table_model_; |
| 233 | 233 |
| 234 // True when the Task Manager window should be shown on top of other windows. | 234 // True when the Task Manager window should be shown on top of other windows. |
| 235 bool is_always_on_top_; | 235 bool is_always_on_top_; |
| 236 | 236 |
| 237 // The host desktop type this task manager belongs to. | |
| 238 const chrome::HostDesktopType desktop_type_; | |
| 239 | |
| 240 // We need to own the text of the menu, the Windows API does not copy it. | 237 // We need to own the text of the menu, the Windows API does not copy it. |
| 241 base::string16 always_on_top_menu_text_; | 238 base::string16 always_on_top_menu_text_; |
| 242 | 239 |
| 243 // An open Task manager window. There can only be one open at a time. This | 240 // An open Task manager window. There can only be one open at a time. This |
| 244 // is reset to NULL when the window is closed. | 241 // is reset to NULL when the window is closed. |
| 245 static TaskManagerView* instance_; | 242 static TaskManagerView* instance_; |
| 246 | 243 |
| 247 scoped_ptr<views::MenuRunner> menu_runner_; | 244 scoped_ptr<views::MenuRunner> menu_runner_; |
| 248 | 245 |
| 249 DISALLOW_COPY_AND_ASSIGN(TaskManagerView); | 246 DISALLOW_COPY_AND_ASSIGN(TaskManagerView); |
| 250 }; | 247 }; |
| 251 | 248 |
| 252 // static | 249 // static |
| 253 TaskManagerView* TaskManagerView::instance_ = NULL; | 250 TaskManagerView* TaskManagerView::instance_ = NULL; |
| 254 | 251 |
| 255 | 252 TaskManagerView::TaskManagerView() |
| 256 TaskManagerView::TaskManagerView(chrome::HostDesktopType desktop_type) | |
| 257 : kill_button_(NULL), | 253 : kill_button_(NULL), |
| 258 about_memory_link_(NULL), | 254 about_memory_link_(NULL), |
| 259 tab_table_(NULL), | 255 tab_table_(NULL), |
| 260 tab_table_parent_(NULL), | 256 tab_table_parent_(NULL), |
| 261 task_manager_(TaskManager::GetInstance()), | 257 task_manager_(TaskManager::GetInstance()), |
| 262 model_(TaskManager::GetInstance()->model()), | 258 model_(TaskManager::GetInstance()->model()), |
| 263 is_always_on_top_(false), | 259 is_always_on_top_(false) { |
| 264 desktop_type_(desktop_type) { | |
| 265 Init(); | 260 Init(); |
| 266 } | 261 } |
| 267 | 262 |
| 268 TaskManagerView::~TaskManagerView() { | 263 TaskManagerView::~TaskManagerView() { |
| 269 // Delete child views now, while our table model still exists. | 264 // Delete child views now, while our table model still exists. |
| 270 RemoveAllChildViews(true); | 265 RemoveAllChildViews(true); |
| 271 } | 266 } |
| 272 | 267 |
| 273 void TaskManagerView::Init() { | 268 void TaskManagerView::Init() { |
| 274 table_model_.reset(new TaskManagerTableModel(model_)); | 269 table_model_.reset(new TaskManagerTableModel(model_)); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 | 439 |
| 445 bool TaskManagerView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 440 bool TaskManagerView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 446 DCHECK_EQ(ui::VKEY_W, accelerator.key_code()); | 441 DCHECK_EQ(ui::VKEY_W, accelerator.key_code()); |
| 447 DCHECK_EQ(ui::EF_CONTROL_DOWN, accelerator.modifiers()); | 442 DCHECK_EQ(ui::EF_CONTROL_DOWN, accelerator.modifiers()); |
| 448 GetWidget()->Close(); | 443 GetWidget()->Close(); |
| 449 return true; | 444 return true; |
| 450 } | 445 } |
| 451 | 446 |
| 452 // static | 447 // static |
| 453 void TaskManagerView::Show(Browser* browser) { | 448 void TaskManagerView::Show(Browser* browser) { |
| 454 // In ash we can come here through the ChromeShellDelegate. If there is no | |
| 455 // browser window at that time of the call, browser could be passed as NULL. | |
| 456 const chrome::HostDesktopType desktop_type = | |
| 457 browser ? browser->host_desktop_type() : chrome::HOST_DESKTOP_TYPE_ASH; | |
| 458 | |
| 459 if (instance_) { | 449 if (instance_) { |
| 460 // If there's a Task manager window open already, just activate it. | 450 // If there's a Task manager window open already, just activate it. |
| 461 instance_->GetWidget()->Activate(); | 451 instance_->GetWidget()->Activate(); |
| 462 return; | 452 return; |
| 463 } | 453 } |
| 464 instance_ = new TaskManagerView(desktop_type); | 454 instance_ = new TaskManagerView(); |
| 465 gfx::NativeWindow window = | 455 gfx::NativeWindow window = |
| 466 browser ? browser->window()->GetNativeWindow() : NULL; | 456 browser ? browser->window()->GetNativeWindow() : NULL; |
| 467 #if defined(USE_ASH) | 457 #if defined(USE_ASH) |
| 468 if (!window) | 458 if (!window) |
| 469 window = ash::wm::GetActiveWindow(); | 459 window = ash::wm::GetActiveWindow(); |
| 470 #endif | 460 #endif |
| 471 DialogDelegate::CreateDialogWidget(instance_, window, NULL); | 461 DialogDelegate::CreateDialogWidget(instance_, window, NULL); |
| 472 instance_->InitAlwaysOnTopState(); | 462 instance_->InitAlwaysOnTopState(); |
| 473 instance_->model_->StartUpdating(); | 463 instance_->model_->StartUpdating(); |
| 474 #if defined(OS_WIN) | 464 #if defined(OS_WIN) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 ActivateFocusedTab(); | 565 ActivateFocusedTab(); |
| 576 } | 566 } |
| 577 | 567 |
| 578 void TaskManagerView::OnKeyDown(ui::KeyboardCode keycode) { | 568 void TaskManagerView::OnKeyDown(ui::KeyboardCode keycode) { |
| 579 if (keycode == ui::VKEY_RETURN) | 569 if (keycode == ui::VKEY_RETURN) |
| 580 ActivateFocusedTab(); | 570 ActivateFocusedTab(); |
| 581 } | 571 } |
| 582 | 572 |
| 583 void TaskManagerView::LinkClicked(views::Link* source, int event_flags) { | 573 void TaskManagerView::LinkClicked(views::Link* source, int event_flags) { |
| 584 DCHECK_EQ(about_memory_link_, source); | 574 DCHECK_EQ(about_memory_link_, source); |
| 585 task_manager_->OpenAboutMemory(desktop_type_); | 575 task_manager_->OpenAboutMemory(); |
| 586 } | 576 } |
| 587 | 577 |
| 588 void TaskManagerView::ShowContextMenuForView(views::View* source, | 578 void TaskManagerView::ShowContextMenuForView(views::View* source, |
| 589 const gfx::Point& point, | 579 const gfx::Point& point, |
| 590 ui::MenuSourceType source_type) { | 580 ui::MenuSourceType source_type) { |
| 591 ui::SimpleMenuModel menu_model(this); | 581 ui::SimpleMenuModel menu_model(this); |
| 592 for (std::vector<ui::TableColumn>::iterator i(columns_.begin()); | 582 for (std::vector<ui::TableColumn>::iterator i(columns_.begin()); |
| 593 i != columns_.end(); ++i) { | 583 i != columns_.end(); ++i) { |
| 594 menu_model.AddCheckItem(i->id, l10n_util::GetStringUTF16(i->id)); | 584 menu_model.AddCheckItem(i->id, l10n_util::GetStringUTF16(i->id)); |
| 595 } | 585 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 void HideTaskManager() { | 651 void HideTaskManager() { |
| 662 if (switches::NewTaskManagerEnabled()) { | 652 if (switches::NewTaskManagerEnabled()) { |
| 663 task_management::NewTaskManagerView::Hide(); | 653 task_management::NewTaskManagerView::Hide(); |
| 664 return; | 654 return; |
| 665 } | 655 } |
| 666 | 656 |
| 667 TaskManagerView::Hide(); | 657 TaskManagerView::Hide(); |
| 668 } | 658 } |
| 669 | 659 |
| 670 } // namespace chrome | 660 } // namespace chrome |
| OLD | NEW |