| 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 16 matching lines...) Expand all Loading... |
| 27 #include "ui/base/accelerators/accelerator.h" | 27 #include "ui/base/accelerators/accelerator.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "ui/base/models/simple_menu_model.h" | 29 #include "ui/base/models/simple_menu_model.h" |
| 30 #include "ui/base/models/table_model.h" | 30 #include "ui/base/models/table_model.h" |
| 31 #include "ui/base/models/table_model_observer.h" | 31 #include "ui/base/models/table_model_observer.h" |
| 32 #include "ui/events/event_constants.h" | 32 #include "ui/events/event_constants.h" |
| 33 #include "ui/events/keycodes/keyboard_codes.h" | 33 #include "ui/events/keycodes/keyboard_codes.h" |
| 34 #include "ui/gfx/canvas.h" | 34 #include "ui/gfx/canvas.h" |
| 35 #include "ui/views/context_menu_controller.h" | 35 #include "ui/views/context_menu_controller.h" |
| 36 #include "ui/views/controls/button/label_button.h" | 36 #include "ui/views/controls/button/label_button.h" |
| 37 #include "ui/views/controls/link.h" | |
| 38 #include "ui/views/controls/link_listener.h" | |
| 39 #include "ui/views/controls/menu/menu_runner.h" | 37 #include "ui/views/controls/menu/menu_runner.h" |
| 40 #include "ui/views/controls/table/table_grouper.h" | 38 #include "ui/views/controls/table/table_grouper.h" |
| 41 #include "ui/views/controls/table/table_view.h" | 39 #include "ui/views/controls/table/table_view.h" |
| 42 #include "ui/views/controls/table/table_view_observer.h" | 40 #include "ui/views/controls/table/table_view_observer.h" |
| 43 #include "ui/views/layout/layout_constants.h" | 41 #include "ui/views/layout/layout_constants.h" |
| 44 #include "ui/views/widget/widget.h" | 42 #include "ui/views/widget/widget.h" |
| 45 #include "ui/views/window/dialog_delegate.h" | 43 #include "ui/views/window/dialog_delegate.h" |
| 46 | 44 |
| 47 #if defined(USE_ASH) | 45 #if defined(USE_ASH) |
| 48 #include "ash/shelf/shelf_util.h" | 46 #include "ash/shelf/shelf_util.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 141 |
| 144 void TaskManagerTableModel::OnItemsRemoved(int start, int length) { | 142 void TaskManagerTableModel::OnItemsRemoved(int start, int length) { |
| 145 if (observer_) | 143 if (observer_) |
| 146 observer_->OnItemsRemoved(start, length); | 144 observer_->OnItemsRemoved(start, length); |
| 147 } | 145 } |
| 148 | 146 |
| 149 // The Task Manager UI container. | 147 // The Task Manager UI container. |
| 150 class TaskManagerView : public views::ButtonListener, | 148 class TaskManagerView : public views::ButtonListener, |
| 151 public views::DialogDelegateView, | 149 public views::DialogDelegateView, |
| 152 public views::TableViewObserver, | 150 public views::TableViewObserver, |
| 153 public views::LinkListener, | |
| 154 public views::ContextMenuController, | 151 public views::ContextMenuController, |
| 155 public ui::SimpleMenuModel::Delegate { | 152 public ui::SimpleMenuModel::Delegate { |
| 156 public: | 153 public: |
| 157 TaskManagerView(); | 154 TaskManagerView(); |
| 158 ~TaskManagerView() override; | 155 ~TaskManagerView() override; |
| 159 | 156 |
| 160 // Shows the Task Manager window, or re-activates an existing one. | 157 // Shows the Task Manager window, or re-activates an existing one. |
| 161 static void Show(Browser* browser); | 158 static void Show(Browser* browser); |
| 162 | 159 |
| 163 // Hides the Task Manager if it is showing. | 160 // Hides the Task Manager if it is showing. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 182 std::string GetWindowName() const override; | 179 std::string GetWindowName() const override; |
| 183 int GetDialogButtons() const override; | 180 int GetDialogButtons() const override; |
| 184 void WindowClosing() override; | 181 void WindowClosing() override; |
| 185 bool UseNewStyleForThisDialog() const override; | 182 bool UseNewStyleForThisDialog() const override; |
| 186 | 183 |
| 187 // views::TableViewObserver: | 184 // views::TableViewObserver: |
| 188 void OnSelectionChanged() override; | 185 void OnSelectionChanged() override; |
| 189 void OnDoubleClick() override; | 186 void OnDoubleClick() override; |
| 190 void OnKeyDown(ui::KeyboardCode keycode) override; | 187 void OnKeyDown(ui::KeyboardCode keycode) override; |
| 191 | 188 |
| 192 // views::LinkListener: | |
| 193 void LinkClicked(views::Link* source, int event_flags) override; | |
| 194 | |
| 195 // views::ContextMenuController: | 189 // views::ContextMenuController: |
| 196 void ShowContextMenuForView(views::View* source, | 190 void ShowContextMenuForView(views::View* source, |
| 197 const gfx::Point& point, | 191 const gfx::Point& point, |
| 198 ui::MenuSourceType source_type) override; | 192 ui::MenuSourceType source_type) override; |
| 199 | 193 |
| 200 // ui::SimpleMenuModel::Delegate: | 194 // ui::SimpleMenuModel::Delegate: |
| 201 bool IsCommandIdChecked(int id) const override; | 195 bool IsCommandIdChecked(int id) const override; |
| 202 bool IsCommandIdEnabled(int id) const override; | 196 bool IsCommandIdEnabled(int id) const override; |
| 203 bool GetAcceleratorForCommandId(int command_id, | 197 bool GetAcceleratorForCommandId(int command_id, |
| 204 ui::Accelerator* accelerator) override; | 198 ui::Accelerator* accelerator) override; |
| 205 void ExecuteCommand(int id, int event_flags) override; | 199 void ExecuteCommand(int id, int event_flags) override; |
| 206 | 200 |
| 207 private: | 201 private: |
| 208 // Creates the child controls. | 202 // Creates the child controls. |
| 209 void Init(); | 203 void Init(); |
| 210 | 204 |
| 211 // Initializes the state of the always-on-top setting as the window is shown. | 205 // Initializes the state of the always-on-top setting as the window is shown. |
| 212 void InitAlwaysOnTopState(); | 206 void InitAlwaysOnTopState(); |
| 213 | 207 |
| 214 // Activates the tab associated with the focused row. | 208 // Activates the tab associated with the focused row. |
| 215 void ActivateFocusedTab(); | 209 void ActivateFocusedTab(); |
| 216 | 210 |
| 217 // Restores saved always on top state from a previous session. | 211 // Restores saved always on top state from a previous session. |
| 218 bool GetSavedAlwaysOnTopState(bool* always_on_top) const; | 212 bool GetSavedAlwaysOnTopState(bool* always_on_top) const; |
| 219 | 213 |
| 220 views::LabelButton* kill_button_; | 214 views::LabelButton* kill_button_; |
| 221 views::Link* about_memory_link_; | |
| 222 views::TableView* tab_table_; | 215 views::TableView* tab_table_; |
| 223 views::View* tab_table_parent_; | 216 views::View* tab_table_parent_; |
| 224 | 217 |
| 225 TaskManager* task_manager_; | 218 TaskManager* task_manager_; |
| 226 | 219 |
| 227 TaskManagerModel* model_; | 220 TaskManagerModel* model_; |
| 228 | 221 |
| 229 // all possible columns, not necessarily visible | 222 // all possible columns, not necessarily visible |
| 230 std::vector<ui::TableColumn> columns_; | 223 std::vector<ui::TableColumn> columns_; |
| 231 | 224 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 244 scoped_ptr<views::MenuRunner> menu_runner_; | 237 scoped_ptr<views::MenuRunner> menu_runner_; |
| 245 | 238 |
| 246 DISALLOW_COPY_AND_ASSIGN(TaskManagerView); | 239 DISALLOW_COPY_AND_ASSIGN(TaskManagerView); |
| 247 }; | 240 }; |
| 248 | 241 |
| 249 // static | 242 // static |
| 250 TaskManagerView* TaskManagerView::instance_ = NULL; | 243 TaskManagerView* TaskManagerView::instance_ = NULL; |
| 251 | 244 |
| 252 TaskManagerView::TaskManagerView() | 245 TaskManagerView::TaskManagerView() |
| 253 : kill_button_(NULL), | 246 : kill_button_(NULL), |
| 254 about_memory_link_(NULL), | |
| 255 tab_table_(NULL), | 247 tab_table_(NULL), |
| 256 tab_table_parent_(NULL), | 248 tab_table_parent_(NULL), |
| 257 task_manager_(TaskManager::GetInstance()), | 249 task_manager_(TaskManager::GetInstance()), |
| 258 model_(TaskManager::GetInstance()->model()), | 250 model_(TaskManager::GetInstance()->model()), |
| 259 is_always_on_top_(false) { | 251 is_always_on_top_(false) { |
| 260 Init(); | 252 Init(); |
| 261 } | 253 } |
| 262 | 254 |
| 263 TaskManagerView::~TaskManagerView() { | 255 TaskManagerView::~TaskManagerView() { |
| 264 // Delete child views now, while our table model still exists. | 256 // Delete child views now, while our table model still exists. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN, false); | 364 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_GDI_HANDLES_COLUMN, false); |
| 373 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_USER_HANDLES_COLUMN, false); | 365 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_USER_HANDLES_COLUMN, false); |
| 374 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN, false); | 366 tab_table_->SetColumnVisibility(IDS_TASK_MANAGER_IDLE_WAKEUPS_COLUMN, false); |
| 375 | 367 |
| 376 tab_table_->SetObserver(this); | 368 tab_table_->SetObserver(this); |
| 377 tab_table_->set_context_menu_controller(this); | 369 tab_table_->set_context_menu_controller(this); |
| 378 set_context_menu_controller(this); | 370 set_context_menu_controller(this); |
| 379 kill_button_ = new views::LabelButton(this, | 371 kill_button_ = new views::LabelButton(this, |
| 380 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL)); | 372 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL)); |
| 381 kill_button_->SetStyle(views::Button::STYLE_BUTTON); | 373 kill_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 382 about_memory_link_ = new views::Link( | |
| 383 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_ABOUT_MEMORY_LINK)); | |
| 384 about_memory_link_->set_listener(this); | |
| 385 | 374 |
| 386 // Makes sure our state is consistent. | 375 // Makes sure our state is consistent. |
| 387 OnSelectionChanged(); | 376 OnSelectionChanged(); |
| 388 | 377 |
| 389 ui::Accelerator ctrl_w(ui::VKEY_W, ui::EF_CONTROL_DOWN); | 378 ui::Accelerator ctrl_w(ui::VKEY_W, ui::EF_CONTROL_DOWN); |
| 390 AddAccelerator(ctrl_w); | 379 AddAccelerator(ctrl_w); |
| 391 } | 380 } |
| 392 | 381 |
| 393 void TaskManagerView::ViewHierarchyChanged( | 382 void TaskManagerView::ViewHierarchyChanged( |
| 394 const ViewHierarchyChangedDetails& details) { | 383 const ViewHierarchyChangedDetails& details) { |
| 395 views::DialogDelegateView::ViewHierarchyChanged(details); | 384 views::DialogDelegateView::ViewHierarchyChanged(details); |
| 396 // Since we want the Kill button and the Memory Details link to show up in | 385 // Since we want the Kill button to show up in the same visual row as the |
| 397 // the same visual row as the close button, which is provided by the | 386 // close button, which is provided by the framework, we must add it to the |
| 398 // framework, we must add the buttons to the non-client view, which is the | 387 // non-client view, which is the parent of this view. Similarly, when we're |
| 399 // parent of this view. Similarly, when we're removed from the view | 388 // removed from the view hierarchy, we must take care to clean up that item. |
| 400 // hierarchy, we must take care to clean up those items as well. | |
| 401 if (details.child == this) { | 389 if (details.child == this) { |
| 402 if (details.is_add) { | 390 if (details.is_add) { |
| 403 details.parent->AddChildView(about_memory_link_); | |
| 404 details.parent->AddChildView(kill_button_); | 391 details.parent->AddChildView(kill_button_); |
| 405 tab_table_parent_ = tab_table_->CreateParentIfNecessary(); | 392 tab_table_parent_ = tab_table_->CreateParentIfNecessary(); |
| 406 AddChildView(tab_table_parent_); | 393 AddChildView(tab_table_parent_); |
| 407 } else { | 394 } else { |
| 408 details.parent->RemoveChildView(kill_button_); | 395 details.parent->RemoveChildView(kill_button_); |
| 409 details.parent->RemoveChildView(about_memory_link_); | |
| 410 } | 396 } |
| 411 } | 397 } |
| 412 } | 398 } |
| 413 | 399 |
| 414 void TaskManagerView::Layout() { | 400 void TaskManagerView::Layout() { |
| 415 gfx::Size size = kill_button_->GetPreferredSize(); | 401 gfx::Size size = kill_button_->GetPreferredSize(); |
| 416 gfx::Rect parent_bounds = parent()->GetContentsBounds(); | 402 gfx::Rect parent_bounds = parent()->GetContentsBounds(); |
| 417 const int horizontal_margin = views::kPanelHorizMargin; | 403 const int horizontal_margin = views::kPanelHorizMargin; |
| 418 const int vertical_margin = views::kButtonVEdgeMargin; | 404 const int vertical_margin = views::kButtonVEdgeMargin; |
| 419 int x = width() - size.width() - horizontal_margin; | 405 int x = width() - size.width() - horizontal_margin; |
| 420 int y_buttons = parent_bounds.bottom() - size.height() - vertical_margin; | 406 int y_buttons = parent_bounds.bottom() - size.height() - vertical_margin; |
| 421 kill_button_->SetBounds(x, y_buttons, size.width(), size.height()); | 407 kill_button_->SetBounds(x, y_buttons, size.width(), size.height()); |
| 422 | 408 |
| 423 size = about_memory_link_->GetPreferredSize(); | |
| 424 about_memory_link_->SetBounds( | |
| 425 horizontal_margin, | |
| 426 y_buttons + (kill_button_->height() - size.height()) / 2, | |
| 427 size.width(), size.height()); | |
| 428 | |
| 429 gfx::Rect rect = GetLocalBounds(); | 409 gfx::Rect rect = GetLocalBounds(); |
| 430 rect.Inset(horizontal_margin, views::kPanelVertMargin); | 410 rect.Inset(horizontal_margin, views::kPanelVertMargin); |
| 431 rect.Inset(0, 0, 0, | 411 rect.Inset(0, 0, 0, |
| 432 kill_button_->height() + views::kUnrelatedControlVerticalSpacing); | 412 kill_button_->height() + views::kUnrelatedControlVerticalSpacing); |
| 433 tab_table_parent_->SetBoundsRect(rect); | 413 tab_table_parent_->SetBoundsRect(rect); |
| 434 } | 414 } |
| 435 | 415 |
| 436 gfx::Size TaskManagerView::GetPreferredSize() const { | 416 gfx::Size TaskManagerView::GetPreferredSize() const { |
| 437 return gfx::Size(460, 270); | 417 return gfx::Size(460, 270); |
| 438 } | 418 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 | 543 |
| 564 void TaskManagerView::OnDoubleClick() { | 544 void TaskManagerView::OnDoubleClick() { |
| 565 ActivateFocusedTab(); | 545 ActivateFocusedTab(); |
| 566 } | 546 } |
| 567 | 547 |
| 568 void TaskManagerView::OnKeyDown(ui::KeyboardCode keycode) { | 548 void TaskManagerView::OnKeyDown(ui::KeyboardCode keycode) { |
| 569 if (keycode == ui::VKEY_RETURN) | 549 if (keycode == ui::VKEY_RETURN) |
| 570 ActivateFocusedTab(); | 550 ActivateFocusedTab(); |
| 571 } | 551 } |
| 572 | 552 |
| 573 void TaskManagerView::LinkClicked(views::Link* source, int event_flags) { | |
| 574 DCHECK_EQ(about_memory_link_, source); | |
| 575 task_manager_->OpenAboutMemory(); | |
| 576 } | |
| 577 | |
| 578 void TaskManagerView::ShowContextMenuForView(views::View* source, | 553 void TaskManagerView::ShowContextMenuForView(views::View* source, |
| 579 const gfx::Point& point, | 554 const gfx::Point& point, |
| 580 ui::MenuSourceType source_type) { | 555 ui::MenuSourceType source_type) { |
| 581 ui::SimpleMenuModel menu_model(this); | 556 ui::SimpleMenuModel menu_model(this); |
| 582 for (std::vector<ui::TableColumn>::iterator i(columns_.begin()); | 557 for (std::vector<ui::TableColumn>::iterator i(columns_.begin()); |
| 583 i != columns_.end(); ++i) { | 558 i != columns_.end(); ++i) { |
| 584 menu_model.AddCheckItem(i->id, l10n_util::GetStringUTF16(i->id)); | 559 menu_model.AddCheckItem(i->id, l10n_util::GetStringUTF16(i->id)); |
| 585 } | 560 } |
| 586 menu_runner_.reset( | 561 menu_runner_.reset( |
| 587 new views::MenuRunner(&menu_model, views::MenuRunner::CONTEXT_MENU)); | 562 new views::MenuRunner(&menu_model, views::MenuRunner::CONTEXT_MENU)); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 void HideTaskManager() { | 626 void HideTaskManager() { |
| 652 if (switches::NewTaskManagerEnabled()) { | 627 if (switches::NewTaskManagerEnabled()) { |
| 653 task_management::NewTaskManagerView::Hide(); | 628 task_management::NewTaskManagerView::Hide(); |
| 654 return; | 629 return; |
| 655 } | 630 } |
| 656 | 631 |
| 657 TaskManagerView::Hide(); | 632 TaskManagerView::Hide(); |
| 658 } | 633 } |
| 659 | 634 |
| 660 } // namespace chrome | 635 } // namespace chrome |
| OLD | NEW |