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 "ui/base/models/simple_menu_model.h" | 11 #include "ui/base/models/simple_menu_model.h" |
12 #include "ui/base/models/table_model.h" | 12 #include "ui/base/models/table_model.h" |
13 #include "ui/views/context_menu_controller.h" | 13 #include "ui/views/context_menu_controller.h" |
14 #include "ui/views/controls/button/label_button.h" | 14 #include "ui/views/controls/button/label_button.h" |
15 #include "ui/views/controls/link_listener.h" | 15 #include "ui/views/controls/link_listener.h" |
16 #include "ui/views/controls/menu/menu_runner.h" | 16 #include "ui/views/controls/menu/menu_runner.h" |
17 #include "ui/views/controls/table/table_view_observer.h" | 17 #include "ui/views/controls/table/table_view_observer.h" |
18 #include "ui/views/window/dialog_delegate.h" | 18 #include "ui/views/window/dialog_delegate.h" |
19 | 19 |
20 namespace views { | 20 namespace views { |
21 class LabelButton; | 21 class LabelButton; |
22 class Link; | 22 class Link; |
23 class TableView; | 23 class TableView; |
24 class View; | 24 class View; |
25 } // namespace views | 25 } // namespace views |
26 | 26 |
27 namespace task_management { | 27 namespace task_management { |
28 | 28 |
| 29 // A collection of data to be used in the construction of a task manager table |
| 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 |
29 // The new task manager UI container. | 67 // The new task manager UI container. |
30 class NewTaskManagerView | 68 class NewTaskManagerView |
31 : public views::ButtonListener, | 69 : public views::ButtonListener, |
32 public views::DialogDelegateView, | 70 public views::DialogDelegateView, |
33 public views::TableViewObserver, | 71 public views::TableViewObserver, |
34 public views::LinkListener, | 72 public views::LinkListener, |
35 public views::ContextMenuController, | 73 public views::ContextMenuController, |
36 public ui::SimpleMenuModel::Delegate { | 74 public ui::SimpleMenuModel::Delegate { |
37 public: | 75 public: |
38 ~NewTaskManagerView() override; | 76 ~NewTaskManagerView() override; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 ui::MenuSourceType source_type) override; | 116 ui::MenuSourceType source_type) override; |
79 | 117 |
80 // ui::SimpleMenuModel::Delegate: | 118 // ui::SimpleMenuModel::Delegate: |
81 bool IsCommandIdChecked(int id) const override; | 119 bool IsCommandIdChecked(int id) const override; |
82 bool IsCommandIdEnabled(int id) const override; | 120 bool IsCommandIdEnabled(int id) const override; |
83 bool GetAcceleratorForCommandId(int command_id, | 121 bool GetAcceleratorForCommandId(int command_id, |
84 ui::Accelerator* accelerator) override; | 122 ui::Accelerator* accelerator) override; |
85 void ExecuteCommand(int id, int event_flags) override; | 123 void ExecuteCommand(int id, int event_flags) override; |
86 | 124 |
87 private: | 125 private: |
| 126 friend class NewTaskManagerViewTest; |
88 class TableModel; | 127 class TableModel; |
89 | 128 |
90 explicit NewTaskManagerView(chrome::HostDesktopType desktop_type); | 129 explicit NewTaskManagerView(chrome::HostDesktopType desktop_type); |
91 | 130 |
| 131 static NewTaskManagerView* GetInstanceForTests(); |
| 132 |
92 // Creates the child controls. | 133 // Creates the child controls. |
93 void Init(); | 134 void Init(); |
94 | 135 |
95 // Initializes the state of the always-on-top setting as the window is shown. | 136 // Initializes the state of the always-on-top setting as the window is shown. |
96 void InitAlwaysOnTopState(); | 137 void InitAlwaysOnTopState(); |
97 | 138 |
98 // Activates the tab associated with the focused row. | 139 // Activates the tab associated with the focused row. |
99 void ActivateFocusedTab(); | 140 void ActivateFocusedTab(); |
100 | 141 |
101 // Restores saved "always on top" state from a previous session. | 142 // Restores saved "always on top" state from a previous session. |
102 void RetriveSavedAlwaysOnTopState(); | 143 void RetriveSavedAlwaysOnTopState(); |
103 | 144 |
| 145 // Restores the saved columns settings from a previous session into |
| 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 |
104 scoped_ptr<NewTaskManagerView::TableModel> table_model_; | 155 scoped_ptr<NewTaskManagerView::TableModel> table_model_; |
105 | 156 |
106 scoped_ptr<views::MenuRunner> menu_runner_; | 157 scoped_ptr<views::MenuRunner> menu_runner_; |
107 | 158 |
| 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 |
108 // We need to own the text of the menu, the Windows API does not copy it. | 165 // We need to own the text of the menu, the Windows API does not copy it. |
109 base::string16 always_on_top_menu_text_; | 166 base::string16 always_on_top_menu_text_; |
110 | 167 |
111 views::LabelButton* kill_button_; | 168 views::LabelButton* kill_button_; |
112 views::Link* about_memory_link_; | 169 views::Link* about_memory_link_; |
113 views::TableView* tab_table_; | 170 views::TableView* tab_table_; |
114 views::View* tab_table_parent_; | 171 views::View* tab_table_parent_; |
115 | 172 |
116 // all possible columns, not necessarily visible | 173 // all possible columns, not necessarily visible |
117 std::vector<ui::TableColumn> columns_; | 174 std::vector<ui::TableColumn> columns_; |
118 | 175 |
119 // The host desktop type this task manager belongs to. | 176 // The host desktop type this task manager belongs to. |
120 const chrome::HostDesktopType desktop_type_; | 177 const chrome::HostDesktopType desktop_type_; |
121 | 178 |
122 // True when the Task Manager window should be shown on top of other windows. | 179 // True when the Task Manager window should be shown on top of other windows. |
123 bool is_always_on_top_; | 180 bool is_always_on_top_; |
124 | 181 |
125 DISALLOW_COPY_AND_ASSIGN(NewTaskManagerView); | 182 DISALLOW_COPY_AND_ASSIGN(NewTaskManagerView); |
126 }; | 183 }; |
127 | 184 |
128 } // namespace task_management | 185 } // namespace task_management |
129 | 186 |
130 #endif // CHROME_BROWSER_UI_VIEWS_NEW_TASK_MANAGER_VIEW_H_ | 187 #endif // CHROME_BROWSER_UI_VIEWS_NEW_TASK_MANAGER_VIEW_H_ |
OLD | NEW |