OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UI_VIEWS_NEW_TASK_MANAGER_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_NEW_TASK_MANAGER_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_NEW_TASK_MANAGER_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_NEW_TASK_MANAGER_VIEW_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "chrome/browser/ui/host_desktop.h" | 10 #include "chrome/browser/ui/host_desktop.h" |
| 11 #include "chrome/browser/ui/task_manager/task_manager_table_model.h" |
11 #include "ui/base/models/simple_menu_model.h" | 12 #include "ui/base/models/simple_menu_model.h" |
12 #include "ui/base/models/table_model.h" | 13 #include "ui/base/models/table_model.h" |
13 #include "ui/views/context_menu_controller.h" | 14 #include "ui/views/context_menu_controller.h" |
14 #include "ui/views/controls/button/label_button.h" | 15 #include "ui/views/controls/button/label_button.h" |
15 #include "ui/views/controls/link_listener.h" | 16 #include "ui/views/controls/link_listener.h" |
16 #include "ui/views/controls/menu/menu_runner.h" | 17 #include "ui/views/controls/menu/menu_runner.h" |
| 18 #include "ui/views/controls/table/table_grouper.h" |
17 #include "ui/views/controls/table/table_view_observer.h" | 19 #include "ui/views/controls/table/table_view_observer.h" |
18 #include "ui/views/window/dialog_delegate.h" | 20 #include "ui/views/window/dialog_delegate.h" |
19 | 21 |
20 namespace views { | 22 namespace views { |
21 class LabelButton; | 23 class LabelButton; |
22 class Link; | 24 class Link; |
23 class TableView; | 25 class TableView; |
24 class View; | 26 class View; |
25 } // namespace views | 27 } // namespace views |
26 | 28 |
27 namespace task_management { | 29 namespace task_management { |
28 | 30 |
29 // A collection of data to be used in the construction of a task manager table | 31 class TaskManagerTableModel; |
30 // column. | |
31 struct TableColumnData { | |
32 // The generated ID of the column. These can change from one build to another. | |
33 // Their values are controlled by the generation from generated_resources.grd. | |
34 int id; | |
35 | |
36 // The alignment of the text displayed in this column. | |
37 ui::TableColumn::Alignment align; | |
38 | |
39 // |width| and |percent| used to define the size of the column. See | |
40 // ui::TableColumn::width and ui::TableColumn::percent for details. | |
41 int width; | |
42 float percent; | |
43 | |
44 // Is the column sortable. | |
45 bool sortable; | |
46 | |
47 // Is the initial sort order ascending? | |
48 bool initial_sort_is_ascending; | |
49 | |
50 // The default visibility of this column at startup of the table if no | |
51 // visibility is stored for it in the prefs. | |
52 bool default_visibility; | |
53 }; | |
54 | |
55 // The task manager table columns and their properties. | |
56 extern const TableColumnData kColumns[]; | |
57 extern const size_t kColumnsSize; | |
58 | |
59 // Session Restore Keys. | |
60 extern const char kSortColumnIdKey[]; | |
61 extern const char kSortIsAscendingKey[]; | |
62 | |
63 // Returns the |column_id| as a string value to be used as keys in the user | |
64 // preferences. | |
65 std::string GetColumnIdAsString(int column_id); | |
66 | 32 |
67 // The new task manager UI container. | 33 // The new task manager UI container. |
68 class NewTaskManagerView | 34 class NewTaskManagerView |
69 : public views::ButtonListener, | 35 : public TableViewDelegate, |
| 36 public views::ButtonListener, |
70 public views::DialogDelegateView, | 37 public views::DialogDelegateView, |
| 38 public views::TableGrouper, |
71 public views::TableViewObserver, | 39 public views::TableViewObserver, |
72 public views::LinkListener, | 40 public views::LinkListener, |
73 public views::ContextMenuController, | 41 public views::ContextMenuController, |
74 public ui::SimpleMenuModel::Delegate { | 42 public ui::SimpleMenuModel::Delegate { |
75 public: | 43 public: |
76 ~NewTaskManagerView() override; | 44 ~NewTaskManagerView() override; |
77 | 45 |
78 // Shows the Task Manager window, or re-activates an existing one. | 46 // Shows the Task Manager window, or re-activates an existing one. |
79 static void Show(Browser* browser); | 47 static void Show(Browser* browser); |
80 | 48 |
81 // Hides the Task Manager if it is showing. | 49 // Hides the Task Manager if it is showing. |
82 static void Hide(); | 50 static void Hide(); |
83 | 51 |
| 52 // task_management::TableViewDelegate: |
| 53 bool IsColumnVisible(int column_id) const override; |
| 54 void SetColumnVisibility(int column_id, bool new_visibility) override; |
| 55 bool IsTableSorted() const override; |
| 56 TableSortDescriptor GetSortDescriptor() const override; |
| 57 void ToggleSortOrder(int visible_column_index) override; |
| 58 |
84 // views::View: | 59 // views::View: |
85 void Layout() override; | 60 void Layout() override; |
86 gfx::Size GetPreferredSize() const override; | 61 gfx::Size GetPreferredSize() const override; |
87 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 62 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
88 void ViewHierarchyChanged( | 63 void ViewHierarchyChanged( |
89 const ViewHierarchyChangedDetails& details) override; | 64 const ViewHierarchyChangedDetails& details) override; |
90 | 65 |
91 // views::ButtonListener: | 66 // views::ButtonListener: |
92 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 67 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
93 | 68 |
94 // views::DialogDelegateView: | 69 // views::DialogDelegateView: |
95 bool CanResize() const override; | 70 bool CanResize() const override; |
96 bool CanMaximize() const override; | 71 bool CanMaximize() const override; |
97 bool CanMinimize() const override; | 72 bool CanMinimize() const override; |
98 bool ExecuteWindowsCommand(int command_id) override; | 73 bool ExecuteWindowsCommand(int command_id) override; |
99 base::string16 GetWindowTitle() const override; | 74 base::string16 GetWindowTitle() const override; |
100 std::string GetWindowName() const override; | 75 std::string GetWindowName() const override; |
101 int GetDialogButtons() const override; | 76 int GetDialogButtons() const override; |
102 void WindowClosing() override; | 77 void WindowClosing() override; |
103 bool UseNewStyleForThisDialog() const override; | 78 bool UseNewStyleForThisDialog() const override; |
104 | 79 |
| 80 // views::TableGrouper: |
| 81 void GetGroupRange(int model_index, views::GroupRange* range) override; |
| 82 |
105 // views::TableViewObserver: | 83 // views::TableViewObserver: |
106 void OnSelectionChanged() override; | 84 void OnSelectionChanged() override; |
107 void OnDoubleClick() override; | 85 void OnDoubleClick() override; |
108 void OnKeyDown(ui::KeyboardCode keycode) override; | 86 void OnKeyDown(ui::KeyboardCode keycode) override; |
109 | 87 |
110 // views::LinkListener: | 88 // views::LinkListener: |
111 void LinkClicked(views::Link* source, int event_flags) override; | 89 void LinkClicked(views::Link* source, int event_flags) override; |
112 | 90 |
113 // views::ContextMenuController: | 91 // views::ContextMenuController: |
114 void ShowContextMenuForView(views::View* source, | 92 void ShowContextMenuForView(views::View* source, |
115 const gfx::Point& point, | 93 const gfx::Point& point, |
116 ui::MenuSourceType source_type) override; | 94 ui::MenuSourceType source_type) override; |
117 | 95 |
118 // ui::SimpleMenuModel::Delegate: | 96 // ui::SimpleMenuModel::Delegate: |
119 bool IsCommandIdChecked(int id) const override; | 97 bool IsCommandIdChecked(int id) const override; |
120 bool IsCommandIdEnabled(int id) const override; | 98 bool IsCommandIdEnabled(int id) const override; |
121 bool GetAcceleratorForCommandId(int command_id, | 99 bool GetAcceleratorForCommandId(int command_id, |
122 ui::Accelerator* accelerator) override; | 100 ui::Accelerator* accelerator) override; |
123 void ExecuteCommand(int id, int event_flags) override; | 101 void ExecuteCommand(int id, int event_flags) override; |
124 | 102 |
125 private: | 103 private: |
126 friend class NewTaskManagerViewTest; | 104 friend class NewTaskManagerViewTest; |
127 class TableModel; | |
128 | 105 |
129 explicit NewTaskManagerView(chrome::HostDesktopType desktop_type); | 106 explicit NewTaskManagerView(chrome::HostDesktopType desktop_type); |
130 | 107 |
131 static NewTaskManagerView* GetInstanceForTests(); | 108 static NewTaskManagerView* GetInstanceForTests(); |
132 | 109 |
133 // Creates the child controls. | 110 // Creates the child controls. |
134 void Init(); | 111 void Init(); |
135 | 112 |
136 // Initializes the state of the always-on-top setting as the window is shown. | 113 // Initializes the state of the always-on-top setting as the window is shown. |
137 void InitAlwaysOnTopState(); | 114 void InitAlwaysOnTopState(); |
138 | 115 |
139 // Activates the tab associated with the focused row. | 116 // Activates the tab associated with the focused row. |
140 void ActivateFocusedTab(); | 117 void ActivateFocusedTab(); |
141 | 118 |
142 // Restores saved "always on top" state from a previous session. | 119 // Restores saved "always on top" state from a previous session. |
143 void RetriveSavedAlwaysOnTopState(); | 120 void RetriveSavedAlwaysOnTopState(); |
144 | 121 |
145 // Restores the saved columns settings from a previous session into | 122 scoped_ptr<TaskManagerTableModel> table_model_; |
146 // |columns_settings_| and updates the table view. | |
147 void RetrieveSavedColumnsSettingsAndUpdateTable(); | |
148 | |
149 // Stores the current values in |column_settings_| to the user prefs so that | |
150 // it can be restored later next time the task manager view is opened. | |
151 void StoreColumnsSettings(); | |
152 | |
153 void ToggleColumnVisibility(int column_id); | |
154 | |
155 scoped_ptr<NewTaskManagerView::TableModel> table_model_; | |
156 | 123 |
157 scoped_ptr<views::MenuRunner> menu_runner_; | 124 scoped_ptr<views::MenuRunner> menu_runner_; |
158 | 125 |
159 // Contains either the column settings retrieved from user preferences if it | |
160 // exists, or the default column settings. | |
161 // The columns settings are the visible columns and the last sorted column | |
162 // and the direction of the sort. | |
163 scoped_ptr<base::DictionaryValue> columns_settings_; | |
164 | |
165 // We need to own the text of the menu, the Windows API does not copy it. | 126 // We need to own the text of the menu, the Windows API does not copy it. |
166 base::string16 always_on_top_menu_text_; | 127 base::string16 always_on_top_menu_text_; |
167 | 128 |
168 views::LabelButton* kill_button_; | 129 views::LabelButton* kill_button_; |
169 views::Link* about_memory_link_; | 130 views::Link* about_memory_link_; |
170 views::TableView* tab_table_; | 131 views::TableView* tab_table_; |
171 views::View* tab_table_parent_; | 132 views::View* tab_table_parent_; |
172 | 133 |
173 // all possible columns, not necessarily visible | 134 // all possible columns, not necessarily visible |
174 std::vector<ui::TableColumn> columns_; | 135 std::vector<ui::TableColumn> columns_; |
175 | 136 |
176 // The host desktop type this task manager belongs to. | 137 // The host desktop type this task manager belongs to. |
177 const chrome::HostDesktopType desktop_type_; | 138 const chrome::HostDesktopType desktop_type_; |
178 | 139 |
179 // True when the Task Manager window should be shown on top of other windows. | 140 // True when the Task Manager window should be shown on top of other windows. |
180 bool is_always_on_top_; | 141 bool is_always_on_top_; |
181 | 142 |
182 DISALLOW_COPY_AND_ASSIGN(NewTaskManagerView); | 143 DISALLOW_COPY_AND_ASSIGN(NewTaskManagerView); |
183 }; | 144 }; |
184 | 145 |
185 } // namespace task_management | 146 } // namespace task_management |
186 | 147 |
187 #endif // CHROME_BROWSER_UI_VIEWS_NEW_TASK_MANAGER_VIEW_H_ | 148 #endif // CHROME_BROWSER_UI_VIEWS_NEW_TASK_MANAGER_VIEW_H_ |
OLD | NEW |