Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chrome/browser/ui/views/new_task_manager_view.cc

Issue 1982303003: Reuse more dialog code for new task manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: simpler Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/new_task_manager_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/ui/views/new_task_manager_view.h" 5 #include "chrome/browser/ui/views/new_task_manager_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/profiles/profile_window.h" 12 #include "chrome/browser/profiles/profile_window.h"
13 #include "chrome/browser/task_management/task_manager_observer.h" 13 #include "chrome/browser/task_management/task_manager_observer.h"
14 #include "chrome/browser/task_manager/task_manager.h" 14 #include "chrome/browser/task_manager/task_manager.h"
15 #include "chrome/browser/ui/browser_navigator_params.h" 15 #include "chrome/browser/ui/browser_navigator_params.h"
16 #include "chrome/browser/ui/task_manager/task_manager_columns.h" 16 #include "chrome/browser/ui/task_manager/task_manager_columns.h"
17 #include "chrome/browser/ui/user_manager.h" 17 #include "chrome/browser/ui/user_manager.h"
18 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
19 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
20 #include "chrome/grit/chromium_strings.h" 20 #include "chrome/grit/chromium_strings.h"
21 #include "chrome/grit/generated_resources.h" 21 #include "chrome/grit/generated_resources.h"
22 #include "components/prefs/pref_service.h" 22 #include "components/prefs/pref_service.h"
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/models/table_model_observer.h" 24 #include "ui/base/models/table_model_observer.h"
25 #include "ui/views/border.h"
25 #include "ui/views/controls/label.h" 26 #include "ui/views/controls/label.h"
26 #include "ui/views/controls/table/table_view.h" 27 #include "ui/views/controls/table/table_view.h"
28 #include "ui/views/layout/fill_layout.h"
27 #include "ui/views/layout/layout_constants.h" 29 #include "ui/views/layout/layout_constants.h"
28 #include "ui/views/view.h" 30 #include "ui/views/view.h"
29 #include "ui/views/widget/widget.h" 31 #include "ui/views/widget/widget.h"
32 #include "ui/views/window/dialog_client_view.h"
30 33
31 #if defined(USE_ASH) 34 #if defined(USE_ASH)
32 #include "ash/shelf/shelf_util.h" 35 #include "ash/shelf/shelf_util.h"
33 #include "ash/wm/window_util.h" 36 #include "ash/wm/window_util.h"
34 #include "grit/ash_resources.h" 37 #include "grit/ash_resources.h"
35 #endif // defined(USE_ASH) 38 #endif // defined(USE_ASH)
36 39
37 #if defined(OS_WIN) 40 #if defined(OS_WIN)
38 #include "chrome/browser/shell_integration_win.h" 41 #include "chrome/browser/shell_integration_win.h"
39 #include "ui/base/win/shell.h" 42 #include "ui/base/win/shell.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return TableSortDescriptor(); 134 return TableSortDescriptor();
132 135
133 const auto& descriptor = tab_table_->sort_descriptors().front(); 136 const auto& descriptor = tab_table_->sort_descriptors().front();
134 return TableSortDescriptor(descriptor.column_id, descriptor.ascending); 137 return TableSortDescriptor(descriptor.column_id, descriptor.ascending);
135 } 138 }
136 139
137 void NewTaskManagerView::ToggleSortOrder(int visible_column_index) { 140 void NewTaskManagerView::ToggleSortOrder(int visible_column_index) {
138 tab_table_->ToggleSortOrder(visible_column_index); 141 tab_table_->ToggleSortOrder(visible_column_index);
139 } 142 }
140 143
141 void NewTaskManagerView::Layout() {
142 gfx::Size size = kill_button_->GetPreferredSize();
143 gfx::Rect parent_bounds = parent()->GetContentsBounds();
144 const int horizontal_margin = views::kPanelHorizMargin;
145 const int vertical_margin = views::kButtonVEdgeMargin;
146 int x = width() - size.width() - horizontal_margin;
147 int y_buttons = parent_bounds.bottom() - size.height() - vertical_margin;
148 kill_button_->SetBounds(x, y_buttons, size.width(), size.height());
149
150 gfx::Rect rect = GetLocalBounds();
151 rect.Inset(horizontal_margin, views::kPanelVertMargin);
152 rect.Inset(0, 0, 0,
153 kill_button_->height() + views::kUnrelatedControlVerticalSpacing);
154 tab_table_parent_->SetBoundsRect(rect);
155 }
156
157 gfx::Size NewTaskManagerView::GetPreferredSize() const { 144 gfx::Size NewTaskManagerView::GetPreferredSize() const {
158 return gfx::Size(460, 270); 145 return gfx::Size(460, 270);
159 } 146 }
160 147
161 bool NewTaskManagerView::AcceleratorPressed( 148 bool NewTaskManagerView::AcceleratorPressed(
162 const ui::Accelerator& accelerator) { 149 const ui::Accelerator& accelerator) {
163 DCHECK_EQ(ui::VKEY_W, accelerator.key_code()); 150 DCHECK_EQ(ui::VKEY_W, accelerator.key_code());
164 DCHECK_EQ(ui::EF_CONTROL_DOWN, accelerator.modifiers()); 151 DCHECK_EQ(ui::EF_CONTROL_DOWN, accelerator.modifiers());
165 GetWidget()->Close(); 152 GetWidget()->Close();
166 return true; 153 return true;
167 } 154 }
168 155
169 void NewTaskManagerView::ViewHierarchyChanged(
170 const ViewHierarchyChangedDetails& details) {
171 views::DialogDelegateView::ViewHierarchyChanged(details);
172 // Since we want the Kill button to show up in the same visual row as the
173 // close button, which is provided by the framework, we must add it to the
174 // non-client view, which is the parent of this view. Similarly, when we're
175 // removed from the view hierarchy, we must take care to clean up that item.
176 if (details.child == this) {
177 if (details.is_add) {
178 details.parent->AddChildView(kill_button_);
179 tab_table_parent_ = tab_table_->CreateParentIfNecessary();
180 AddChildView(tab_table_parent_);
181 } else {
182 details.parent->RemoveChildView(kill_button_);
183 }
184 }
185 }
186
187 void NewTaskManagerView::ButtonPressed(views::Button* sender,
188 const ui::Event& event) {
189 DCHECK_EQ(kill_button_, sender);
190
191 using SelectedIndices = ui::ListSelectionModel::SelectedIndices;
192 SelectedIndices selection(tab_table_->selection_model().selected_indices());
193 for (SelectedIndices::const_reverse_iterator i = selection.rbegin();
194 i != selection.rend();
195 ++i) {
196 table_model_->KillTask(*i);
197 }
198 }
199
200 bool NewTaskManagerView::CanResize() const { 156 bool NewTaskManagerView::CanResize() const {
201 return true; 157 return true;
202 } 158 }
203 159
204 bool NewTaskManagerView::CanMaximize() const { 160 bool NewTaskManagerView::CanMaximize() const {
205 return true; 161 return true;
206 } 162 }
207 163
208 bool NewTaskManagerView::CanMinimize() const { 164 bool NewTaskManagerView::CanMinimize() const {
209 return true; 165 return true;
210 } 166 }
211 167
212 bool NewTaskManagerView::ExecuteWindowsCommand(int command_id) { 168 bool NewTaskManagerView::ExecuteWindowsCommand(int command_id) {
213 return false; 169 return false;
214 } 170 }
215 171
216 base::string16 NewTaskManagerView::GetWindowTitle() const { 172 base::string16 NewTaskManagerView::GetWindowTitle() const {
217 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE); 173 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE);
218 } 174 }
219 175
220 std::string NewTaskManagerView::GetWindowName() const { 176 std::string NewTaskManagerView::GetWindowName() const {
221 return prefs::kTaskManagerWindowPlacement; 177 return prefs::kTaskManagerWindowPlacement;
222 } 178 }
223 179
180 bool NewTaskManagerView::Accept() {
181 using SelectedIndices = ui::ListSelectionModel::SelectedIndices;
182 SelectedIndices selection(tab_table_->selection_model().selected_indices());
183 for (SelectedIndices::const_reverse_iterator i = selection.rbegin();
184 i != selection.rend(); ++i) {
185 table_model_->KillTask(*i);
186 }
187
188 // Just kill the process, don't close the task manager dialog.
189 return false;
190 }
191
192 bool NewTaskManagerView::Close() {
193 return true;
194 }
195
224 int NewTaskManagerView::GetDialogButtons() const { 196 int NewTaskManagerView::GetDialogButtons() const {
225 return ui::DIALOG_BUTTON_NONE; 197 return ui::DIALOG_BUTTON_OK;
198 }
199
200 base::string16 NewTaskManagerView::GetDialogButtonLabel(
201 ui::DialogButton button) const {
202 return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL);
203 }
204
205 bool NewTaskManagerView::IsDialogButtonEnabled(ui::DialogButton button) const {
206 const ui::ListSelectionModel::SelectedIndices& selections(
207 tab_table_->selection_model().selected_indices());
208 for (const auto& selection : selections) {
209 if (table_model_->IsBrowserProcess(selection))
210 return false;
211 }
212
213 return !selections.empty() && TaskManager::IsEndProcessEnabled();
226 } 214 }
227 215
228 void NewTaskManagerView::WindowClosing() { 216 void NewTaskManagerView::WindowClosing() {
229 // Now that the window is closed, we can allow a new one to be opened. 217 // Now that the window is closed, we can allow a new one to be opened.
230 // (WindowClosing comes in asynchronously from the call to Close() and we 218 // (WindowClosing comes in asynchronously from the call to Close() and we
231 // may have already opened a new instance). 219 // may have already opened a new instance).
232 if (g_task_manager_view == this) { 220 if (g_task_manager_view == this) {
233 // We don't have to delete |g_task_manager_view| as we don't own it. It's 221 // We don't have to delete |g_task_manager_view| as we don't own it. It's
234 // owned by the Views hierarchy. 222 // owned by the Views hierarchy.
235 g_task_manager_view = nullptr; 223 g_task_manager_view = nullptr;
236 } 224 }
237 table_model_->StoreColumnsSettings(); 225 table_model_->StoreColumnsSettings();
238 } 226 }
239 227
240 bool NewTaskManagerView::UseNewStyleForThisDialog() const { 228 bool NewTaskManagerView::UseNewStyleForThisDialog() const {
241 return false; 229 return false;
242 } 230 }
243 231
244 void NewTaskManagerView::GetGroupRange(int model_index, 232 void NewTaskManagerView::GetGroupRange(int model_index,
245 views::GroupRange* range) { 233 views::GroupRange* range) {
246 table_model_->GetRowsGroupRange(model_index, &range->start, &range->length); 234 table_model_->GetRowsGroupRange(model_index, &range->start, &range->length);
247 } 235 }
248 236
249 void NewTaskManagerView::OnSelectionChanged() { 237 void NewTaskManagerView::OnSelectionChanged() {
250 const ui::ListSelectionModel::SelectedIndices& selections( 238 GetDialogClientView()->UpdateDialogButtons();
251 tab_table_->selection_model().selected_indices());
252 bool selection_contains_browser_process = false;
253 for (const auto& selection : selections) {
254 if (table_model_->IsBrowserProcess(selection)) {
255 selection_contains_browser_process = true;
256 break;
257 }
258 }
259
260 kill_button_->SetEnabled(!selection_contains_browser_process &&
261 !selections.empty() &&
262 TaskManager::IsEndProcessEnabled());
263 } 239 }
264 240
265 void NewTaskManagerView::OnDoubleClick() { 241 void NewTaskManagerView::OnDoubleClick() {
266 ActivateFocusedTab(); 242 ActivateFocusedTab();
267 } 243 }
268 244
269 void NewTaskManagerView::OnKeyDown(ui::KeyboardCode keycode) { 245 void NewTaskManagerView::OnKeyDown(ui::KeyboardCode keycode) {
270 if (keycode == ui::VKEY_RETURN) 246 if (keycode == ui::VKEY_RETURN)
271 ActivateFocusedTab(); 247 ActivateFocusedTab();
272 } 248 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 int command_id, 282 int command_id,
307 ui::Accelerator* accelerator) { 283 ui::Accelerator* accelerator) {
308 return false; 284 return false;
309 } 285 }
310 286
311 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) { 287 void NewTaskManagerView::ExecuteCommand(int id, int event_flags) {
312 table_model_->ToggleColumnVisibility(id); 288 table_model_->ToggleColumnVisibility(id);
313 } 289 }
314 290
315 NewTaskManagerView::NewTaskManagerView() 291 NewTaskManagerView::NewTaskManagerView()
316 : kill_button_(nullptr), 292 : tab_table_(nullptr),
317 tab_table_(nullptr),
318 tab_table_parent_(nullptr), 293 tab_table_parent_(nullptr),
319 is_always_on_top_(false) { 294 is_always_on_top_(false) {
320 Init(); 295 Init();
321 } 296 }
322 297
323 // static 298 // static
324 NewTaskManagerView* NewTaskManagerView::GetInstanceForTests() { 299 NewTaskManagerView* NewTaskManagerView::GetInstanceForTests() {
325 return g_task_manager_view; 300 return g_task_manager_view;
326 } 301 }
327 302
(...skipping 14 matching lines...) Expand all
342 table_model_.reset(new TaskManagerTableModel(REFRESH_TYPE_CPU | 317 table_model_.reset(new TaskManagerTableModel(REFRESH_TYPE_CPU |
343 REFRESH_TYPE_MEMORY | 318 REFRESH_TYPE_MEMORY |
344 REFRESH_TYPE_NETWORK_USAGE, 319 REFRESH_TYPE_NETWORK_USAGE,
345 this)); 320 this));
346 tab_table_->SetModel(table_model_.get()); 321 tab_table_->SetModel(table_model_.get());
347 tab_table_->SetGrouper(this); 322 tab_table_->SetGrouper(this);
348 tab_table_->SetObserver(this); 323 tab_table_->SetObserver(this);
349 tab_table_->set_context_menu_controller(this); 324 tab_table_->set_context_menu_controller(this);
350 set_context_menu_controller(this); 325 set_context_menu_controller(this);
351 326
327 tab_table_parent_ = tab_table_->CreateParentIfNecessary();
328 AddChildView(tab_table_parent_);
329
330 SetLayoutManager(new views::FillLayout());
331 SetBorder(views::Border::CreateEmptyBorder(views::kPanelVertMargin,
332 views::kButtonHEdgeMarginNew, 0,
333 views::kButtonHEdgeMarginNew));
334
352 table_model_->RetrieveSavedColumnsSettingsAndUpdateTable(); 335 table_model_->RetrieveSavedColumnsSettingsAndUpdateTable();
353 336
354 kill_button_ = new views::LabelButton(this,
355 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_KILL));
356 kill_button_->SetStyle(views::Button::STYLE_BUTTON);
357
358 // Makes sure our state is consistent.
359 OnSelectionChanged();
360
361 AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN)); 337 AddAccelerator(ui::Accelerator(ui::VKEY_W, ui::EF_CONTROL_DOWN));
362 } 338 }
363 339
364 void NewTaskManagerView::InitAlwaysOnTopState() { 340 void NewTaskManagerView::InitAlwaysOnTopState() {
365 RetriveSavedAlwaysOnTopState(); 341 RetrieveSavedAlwaysOnTopState();
afakhry 2016/05/19 00:49:43 Thanks for catching that typo.
366 GetWidget()->SetAlwaysOnTop(is_always_on_top_); 342 GetWidget()->SetAlwaysOnTop(is_always_on_top_);
367 } 343 }
368 344
369 void NewTaskManagerView::ActivateFocusedTab() { 345 void NewTaskManagerView::ActivateFocusedTab() {
370 const int active_row = tab_table_->selection_model().active(); 346 const int active_row = tab_table_->selection_model().active();
371 if (active_row != ui::ListSelectionModel::kUnselectedIndex) 347 if (active_row != ui::ListSelectionModel::kUnselectedIndex)
372 table_model_->ActivateTask(active_row); 348 table_model_->ActivateTask(active_row);
373 } 349 }
374 350
375 void NewTaskManagerView::RetriveSavedAlwaysOnTopState() { 351 void NewTaskManagerView::RetrieveSavedAlwaysOnTopState() {
376 is_always_on_top_ = false; 352 is_always_on_top_ = false;
377 353
378 if (!g_browser_process->local_state()) 354 if (!g_browser_process->local_state())
379 return; 355 return;
380 356
381 const base::DictionaryValue* dictionary = 357 const base::DictionaryValue* dictionary =
382 g_browser_process->local_state()->GetDictionary(GetWindowName()); 358 g_browser_process->local_state()->GetDictionary(GetWindowName());
383 if (dictionary) 359 if (dictionary)
384 dictionary->GetBoolean("always_on_top", &is_always_on_top_); 360 dictionary->GetBoolean("always_on_top", &is_always_on_top_);
385 } 361 }
386 362
387 } // namespace task_management 363 } // namespace task_management
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/new_task_manager_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698