BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / views / new_task_manager_view.h
blob2291d8af02e06293993967e8a0d560c02d20c6e4
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.
5 #ifndef CHROME_BROWSER_UI_VIEWS_NEW_TASK_MANAGER_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_NEW_TASK_MANAGER_VIEW_H_
8 #include <vector>
10 #include "chrome/browser/ui/host_desktop.h"
11 #include "ui/base/models/simple_menu_model.h"
12 #include "ui/base/models/table_model.h"
13 #include "ui/views/context_menu_controller.h"
14 #include "ui/views/controls/button/label_button.h"
15 #include "ui/views/controls/link_listener.h"
16 #include "ui/views/controls/menu/menu_runner.h"
17 #include "ui/views/controls/table/table_view_observer.h"
18 #include "ui/views/window/dialog_delegate.h"
20 namespace views {
21 class LabelButton;
22 class Link;
23 class TableView;
24 class View;
25 } // namespace views
27 namespace task_management {
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;
36 // The alignment of the text displayed in this column.
37 ui::TableColumn::Alignment align;
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;
44 // Is the column sortable.
45 bool sortable;
47 // Is the initial sort order ascending?
48 bool initial_sort_is_ascending;
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;
55 // The task manager table columns and their properties.
56 extern const TableColumnData kColumns[];
57 extern const size_t kColumnsSize;
59 // Session Restore Keys.
60 extern const char kSortColumnIdKey[];
61 extern const char kSortIsAscendingKey[];
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);
67 // The new task manager UI container.
68 class NewTaskManagerView
69 : public views::ButtonListener,
70 public views::DialogDelegateView,
71 public views::TableViewObserver,
72 public views::LinkListener,
73 public views::ContextMenuController,
74 public ui::SimpleMenuModel::Delegate {
75 public:
76 ~NewTaskManagerView() override;
78 // Shows the Task Manager window, or re-activates an existing one.
79 static void Show(Browser* browser);
81 // Hides the Task Manager if it is showing.
82 static void Hide();
84 // views::View:
85 void Layout() override;
86 gfx::Size GetPreferredSize() const override;
87 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
88 void ViewHierarchyChanged(
89 const ViewHierarchyChangedDetails& details) override;
91 // views::ButtonListener:
92 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
94 // views::DialogDelegateView:
95 bool CanResize() const override;
96 bool CanMaximize() const override;
97 bool CanMinimize() const override;
98 bool ExecuteWindowsCommand(int command_id) override;
99 base::string16 GetWindowTitle() const override;
100 std::string GetWindowName() const override;
101 int GetDialogButtons() const override;
102 void WindowClosing() override;
103 bool UseNewStyleForThisDialog() const override;
105 // views::TableViewObserver:
106 void OnSelectionChanged() override;
107 void OnDoubleClick() override;
108 void OnKeyDown(ui::KeyboardCode keycode) override;
110 // views::LinkListener:
111 void LinkClicked(views::Link* source, int event_flags) override;
113 // views::ContextMenuController:
114 void ShowContextMenuForView(views::View* source,
115 const gfx::Point& point,
116 ui::MenuSourceType source_type) override;
118 // ui::SimpleMenuModel::Delegate:
119 bool IsCommandIdChecked(int id) const override;
120 bool IsCommandIdEnabled(int id) const override;
121 bool GetAcceleratorForCommandId(int command_id,
122 ui::Accelerator* accelerator) override;
123 void ExecuteCommand(int id, int event_flags) override;
125 private:
126 friend class NewTaskManagerViewTest;
127 class TableModel;
129 explicit NewTaskManagerView(chrome::HostDesktopType desktop_type);
131 static NewTaskManagerView* GetInstanceForTests();
133 // Creates the child controls.
134 void Init();
136 // Initializes the state of the always-on-top setting as the window is shown.
137 void InitAlwaysOnTopState();
139 // Activates the tab associated with the focused row.
140 void ActivateFocusedTab();
142 // Restores saved "always on top" state from a previous session.
143 void RetriveSavedAlwaysOnTopState();
145 // Restores the saved columns settings from a previous session into
146 // |columns_settings_| and updates the table view.
147 void RetrieveSavedColumnsSettingsAndUpdateTable();
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();
153 void ToggleColumnVisibility(int column_id);
155 scoped_ptr<NewTaskManagerView::TableModel> table_model_;
157 scoped_ptr<views::MenuRunner> menu_runner_;
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_;
165 // We need to own the text of the menu, the Windows API does not copy it.
166 base::string16 always_on_top_menu_text_;
168 views::LabelButton* kill_button_;
169 views::Link* about_memory_link_;
170 views::TableView* tab_table_;
171 views::View* tab_table_parent_;
173 // all possible columns, not necessarily visible
174 std::vector<ui::TableColumn> columns_;
176 // The host desktop type this task manager belongs to.
177 const chrome::HostDesktopType desktop_type_;
179 // True when the Task Manager window should be shown on top of other windows.
180 bool is_always_on_top_;
182 DISALLOW_COPY_AND_ASSIGN(NewTaskManagerView);
185 } // namespace task_management
187 #endif // CHROME_BROWSER_UI_VIEWS_NEW_TASK_MANAGER_VIEW_H_