/chrome/browser/ui/views/task_manager_view.h

http://github.com/chromium/chromium · C Header · 132 lines · 78 code · 33 blank · 21 comment · 0 complexity · 113b2725c5fc4f4ff215deff4005c631 MD5 · raw file

  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CHROME_BROWSER_UI_VIEWS_TASK_MANAGER_VIEW_H_
  5. #define CHROME_BROWSER_UI_VIEWS_TASK_MANAGER_VIEW_H_
  6. #include <vector>
  7. #include "base/macros.h"
  8. #include "chrome/browser/ui/task_manager/task_manager_table_model.h"
  9. #include "ui/base/models/simple_menu_model.h"
  10. #include "ui/base/models/table_model.h"
  11. #include "ui/views/context_menu_controller.h"
  12. #include "ui/views/controls/menu/menu_runner.h"
  13. #include "ui/views/controls/table/table_grouper.h"
  14. #include "ui/views/controls/table/table_view_observer.h"
  15. #include "ui/views/window/dialog_delegate.h"
  16. class Browser;
  17. namespace views {
  18. class TableView;
  19. class View;
  20. } // namespace views
  21. namespace task_manager {
  22. // The new task manager UI container.
  23. class TaskManagerView : public TableViewDelegate,
  24. public views::DialogDelegateView,
  25. public views::TableGrouper,
  26. public views::TableViewObserver,
  27. public views::ContextMenuController,
  28. public ui::SimpleMenuModel::Delegate {
  29. public:
  30. ~TaskManagerView() override;
  31. // Shows the Task Manager window, or re-activates an existing one.
  32. static task_manager::TaskManagerTableModel* Show(Browser* browser);
  33. // Hides the Task Manager if it is showing.
  34. static void Hide();
  35. // task_manager::TableViewDelegate:
  36. bool IsColumnVisible(int column_id) const override;
  37. void SetColumnVisibility(int column_id, bool new_visibility) override;
  38. bool IsTableSorted() const override;
  39. TableSortDescriptor GetSortDescriptor() const override;
  40. void SetSortDescriptor(const TableSortDescriptor& descriptor) override;
  41. // views::View:
  42. gfx::Size CalculatePreferredSize() const override;
  43. bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
  44. // views::DialogDelegateView:
  45. views::View* GetInitiallyFocusedView() override;
  46. bool CanResize() const override;
  47. bool CanMaximize() const override;
  48. bool CanMinimize() const override;
  49. bool ExecuteWindowsCommand(int command_id) override;
  50. base::string16 GetWindowTitle() const override;
  51. gfx::ImageSkia GetWindowIcon() override;
  52. std::string GetWindowName() const override;
  53. bool Accept() override;
  54. bool IsDialogButtonEnabled(ui::DialogButton button) const override;
  55. void WindowClosing() override;
  56. // views::TableGrouper:
  57. void GetGroupRange(int model_index, views::GroupRange* range) override;
  58. // views::TableViewObserver:
  59. void OnSelectionChanged() override;
  60. void OnDoubleClick() override;
  61. void OnKeyDown(ui::KeyboardCode keycode) override;
  62. // views::ContextMenuController:
  63. void ShowContextMenuForViewImpl(views::View* source,
  64. const gfx::Point& point,
  65. ui::MenuSourceType source_type) override;
  66. // ui::SimpleMenuModel::Delegate:
  67. bool IsCommandIdChecked(int id) const override;
  68. bool IsCommandIdEnabled(int id) const override;
  69. void ExecuteCommand(int id, int event_flags) override;
  70. void MenuClosed(ui::SimpleMenuModel* source) override;
  71. private:
  72. friend class TaskManagerViewTest;
  73. TaskManagerView();
  74. static TaskManagerView* GetInstanceForTests();
  75. // Creates the child controls.
  76. void Init();
  77. // Initializes the state of the always-on-top setting as the window is shown.
  78. void InitAlwaysOnTopState();
  79. // Activates the tab associated with the selected row.
  80. void ActivateSelectedTab();
  81. // Selects the active tab in the specified browser window.
  82. void SelectTaskOfActiveTab(Browser* browser);
  83. // Restores saved "always on top" state from a previous session.
  84. void RetrieveSavedAlwaysOnTopState();
  85. std::unique_ptr<TaskManagerTableModel> table_model_;
  86. std::unique_ptr<ui::SimpleMenuModel> menu_model_;
  87. std::unique_ptr<views::MenuRunner> menu_runner_;
  88. // We need to own the text of the menu, the Windows API does not copy it.
  89. base::string16 always_on_top_menu_text_;
  90. views::TableView* tab_table_;
  91. views::View* tab_table_parent_;
  92. // all possible columns, not necessarily visible
  93. std::vector<ui::TableColumn> columns_;
  94. // True when the Task Manager window should be shown on top of other windows.
  95. bool is_always_on_top_;
  96. DISALLOW_COPY_AND_ASSIGN(TaskManagerView);
  97. };
  98. } // namespace task_manager
  99. #endif // CHROME_BROWSER_UI_VIEWS_TASK_MANAGER_VIEW_H_