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

Side by Side Diff: ash/shelf/shelf_alignment_menu.cc

Issue 1812013003: Pass shelf instances, not root windows, for ash context menus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Call OnShelfAlignmentChanged after LayoutShelf. Created 4 years, 9 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 | « ash/shelf/shelf_alignment_menu.h ('k') | ash/shelf/shelf_layout_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/shelf/shelf_alignment_menu.h" 5 #include "ash/shelf/shelf_alignment_menu.h"
6 6
7 #include "ash/metrics/user_metrics_recorder.h" 7 #include "ash/metrics/user_metrics_recorder.h"
8 #include "ash/shelf/shelf.h" 8 #include "ash/shelf/shelf.h"
9 #include "ash/shelf/shelf_layout_manager.h"
9 #include "ash/shelf/shelf_types.h" 10 #include "ash/shelf/shelf_types.h"
11 #include "ash/shelf/shelf_widget.h"
10 #include "ash/shell.h" 12 #include "ash/shell.h"
11 #include "grit/ash_strings.h" 13 #include "grit/ash_strings.h"
12 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
13 15
14 namespace ash { 16 namespace ash {
15 17
16 ShelfAlignmentMenu::ShelfAlignmentMenu(aura::Window* root) 18 ShelfAlignmentMenu::ShelfAlignmentMenu(Shelf* shelf)
17 : ui::SimpleMenuModel(NULL), 19 : ui::SimpleMenuModel(nullptr), shelf_(shelf) {
18 root_window_(root) { 20 DCHECK(shelf_);
19 DCHECK(root_window_);
20 int align_group_id = 1; 21 int align_group_id = 1;
21 set_delegate(this); 22 set_delegate(this);
22 AddRadioItemWithStringId(MENU_ALIGN_LEFT, 23 AddRadioItemWithStringId(MENU_ALIGN_LEFT,
23 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_LEFT, 24 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_LEFT,
24 align_group_id); 25 align_group_id);
25 AddRadioItemWithStringId(MENU_ALIGN_BOTTOM, 26 AddRadioItemWithStringId(MENU_ALIGN_BOTTOM,
26 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_BOTTOM, 27 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_BOTTOM,
27 align_group_id); 28 align_group_id);
28 AddRadioItemWithStringId(MENU_ALIGN_RIGHT, 29 AddRadioItemWithStringId(MENU_ALIGN_RIGHT,
29 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_RIGHT, 30 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_RIGHT,
30 align_group_id); 31 align_group_id);
31 } 32 }
32 33
33 ShelfAlignmentMenu::~ShelfAlignmentMenu() {} 34 ShelfAlignmentMenu::~ShelfAlignmentMenu() {}
34 35
35 bool ShelfAlignmentMenu::IsCommandIdChecked(int command_id) const { 36 bool ShelfAlignmentMenu::IsCommandIdChecked(int command_id) const {
36 return Shelf::ForWindow(root_window_) 37 return shelf_->SelectValueForShelfAlignment(
37 ->SelectValueForShelfAlignment(MENU_ALIGN_BOTTOM == command_id, 38 MENU_ALIGN_BOTTOM == command_id, MENU_ALIGN_LEFT == command_id,
38 MENU_ALIGN_LEFT == command_id, 39 MENU_ALIGN_RIGHT == command_id, false);
39 MENU_ALIGN_RIGHT == command_id, false);
40 } 40 }
41 41
42 bool ShelfAlignmentMenu::IsCommandIdEnabled(int command_id) const { 42 bool ShelfAlignmentMenu::IsCommandIdEnabled(int command_id) const {
43 return true; 43 return true;
44 } 44 }
45 45
46 bool ShelfAlignmentMenu::GetAcceleratorForCommandId( 46 bool ShelfAlignmentMenu::GetAcceleratorForCommandId(
47 int command_id, 47 int command_id,
48 ui::Accelerator* accelerator) { 48 ui::Accelerator* accelerator) {
49 return false; 49 return false;
50 } 50 }
51 51
52 void ShelfAlignmentMenu::ExecuteCommand(int command_id, int event_flags) { 52 void ShelfAlignmentMenu::ExecuteCommand(int command_id, int event_flags) {
53 Shell* shell = Shell::GetInstance();
54 ShelfLayoutManager* manager = shelf_->shelf_widget()->shelf_layout_manager();
53 switch (static_cast<MenuItem>(command_id)) { 55 switch (static_cast<MenuItem>(command_id)) {
54 case MENU_ALIGN_LEFT: 56 case MENU_ALIGN_LEFT:
55 Shell::GetInstance()->metrics()-> 57 shell->metrics()->RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_LEFT);
56 RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_LEFT); 58 manager->SetAlignment(SHELF_ALIGNMENT_LEFT);
57 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
58 root_window_);
59 break; 59 break;
60 case MENU_ALIGN_BOTTOM: 60 case MENU_ALIGN_BOTTOM:
61 Shell::GetInstance()->metrics()-> 61 shell->metrics()->RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_BOTTOM);
62 RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_BOTTOM); 62 manager->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
63 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM,
64 root_window_);
65 break; 63 break;
66 case MENU_ALIGN_RIGHT: 64 case MENU_ALIGN_RIGHT:
67 Shell::GetInstance()->metrics()-> 65 shell->metrics()->RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_RIGHT);
68 RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_RIGHT); 66 manager->SetAlignment(SHELF_ALIGNMENT_RIGHT);
69 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_RIGHT,
70 root_window_);
71 break; 67 break;
72 } 68 }
73 } 69 }
74 70
75 } // namespace ash 71 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_alignment_menu.h ('k') | ash/shelf/shelf_layout_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698