OLD | NEW |
---|---|
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_types.h" | 9 #include "ash/shelf/shelf_types.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "grit/ash_strings.h" | 11 #include "grit/ash_strings.h" |
12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
13 | 13 |
14 namespace ash { | 14 namespace ash { |
15 | 15 |
16 ShelfAlignmentMenu::ShelfAlignmentMenu(aura::Window* root) | 16 ShelfAlignmentMenu::ShelfAlignmentMenu(Shelf* shelf) |
17 : ui::SimpleMenuModel(NULL), | 17 : ui::SimpleMenuModel(nullptr), shelf_(shelf) { |
18 root_window_(root) { | 18 DCHECK(shelf_); |
19 DCHECK(root_window_); | |
20 int align_group_id = 1; | 19 int align_group_id = 1; |
21 set_delegate(this); | 20 set_delegate(this); |
22 AddRadioItemWithStringId(MENU_ALIGN_LEFT, | 21 AddRadioItemWithStringId(MENU_ALIGN_LEFT, |
23 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_LEFT, | 22 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_LEFT, |
24 align_group_id); | 23 align_group_id); |
25 AddRadioItemWithStringId(MENU_ALIGN_BOTTOM, | 24 AddRadioItemWithStringId(MENU_ALIGN_BOTTOM, |
26 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_BOTTOM, | 25 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_BOTTOM, |
27 align_group_id); | 26 align_group_id); |
28 AddRadioItemWithStringId(MENU_ALIGN_RIGHT, | 27 AddRadioItemWithStringId(MENU_ALIGN_RIGHT, |
29 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_RIGHT, | 28 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_RIGHT, |
30 align_group_id); | 29 align_group_id); |
31 } | 30 } |
32 | 31 |
33 ShelfAlignmentMenu::~ShelfAlignmentMenu() {} | 32 ShelfAlignmentMenu::~ShelfAlignmentMenu() {} |
34 | 33 |
35 bool ShelfAlignmentMenu::IsCommandIdChecked(int command_id) const { | 34 bool ShelfAlignmentMenu::IsCommandIdChecked(int command_id) const { |
36 return Shelf::ForWindow(root_window_) | 35 return shelf_->SelectValueForShelfAlignment( |
37 ->SelectValueForShelfAlignment(MENU_ALIGN_BOTTOM == command_id, | 36 MENU_ALIGN_BOTTOM == command_id, MENU_ALIGN_LEFT == command_id, |
38 MENU_ALIGN_LEFT == command_id, | 37 MENU_ALIGN_RIGHT == command_id, false); |
39 MENU_ALIGN_RIGHT == command_id, false); | |
40 } | 38 } |
41 | 39 |
42 bool ShelfAlignmentMenu::IsCommandIdEnabled(int command_id) const { | 40 bool ShelfAlignmentMenu::IsCommandIdEnabled(int command_id) const { |
43 return true; | 41 return true; |
44 } | 42 } |
45 | 43 |
46 bool ShelfAlignmentMenu::GetAcceleratorForCommandId( | 44 bool ShelfAlignmentMenu::GetAcceleratorForCommandId( |
47 int command_id, | 45 int command_id, |
48 ui::Accelerator* accelerator) { | 46 ui::Accelerator* accelerator) { |
49 return false; | 47 return false; |
50 } | 48 } |
51 | 49 |
52 void ShelfAlignmentMenu::ExecuteCommand(int command_id, int event_flags) { | 50 void ShelfAlignmentMenu::ExecuteCommand(int command_id, int event_flags) { |
51 aura::Window* root_window = | |
52 shelf_->shelf_widget()->GetNativeWindow()->GetRootWindow(); | |
53 Shell* shell = Shell::GetInstance(); | |
53 switch (static_cast<MenuItem>(command_id)) { | 54 switch (static_cast<MenuItem>(command_id)) { |
54 case MENU_ALIGN_LEFT: | 55 case MENU_ALIGN_LEFT: |
55 Shell::GetInstance()->metrics()-> | 56 shell->metrics()->RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_LEFT); |
56 RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_LEFT); | 57 shell->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, root_window); |
msw
2016/03/17 19:04:37
Shell::SetShelfAlignment triggers ShellObserver::O
| |
57 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, | |
58 root_window_); | |
59 break; | 58 break; |
60 case MENU_ALIGN_BOTTOM: | 59 case MENU_ALIGN_BOTTOM: |
61 Shell::GetInstance()->metrics()-> | 60 shell->metrics()->RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_BOTTOM); |
62 RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_BOTTOM); | 61 shell->SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM, root_window); |
63 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM, | |
64 root_window_); | |
65 break; | 62 break; |
66 case MENU_ALIGN_RIGHT: | 63 case MENU_ALIGN_RIGHT: |
67 Shell::GetInstance()->metrics()-> | 64 shell->metrics()->RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_RIGHT); |
68 RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_RIGHT); | 65 shell->SetShelfAlignment(SHELF_ALIGNMENT_RIGHT, root_window); |
69 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_RIGHT, | |
70 root_window_); | |
71 break; | 66 break; |
72 } | 67 } |
73 } | 68 } |
74 | 69 |
75 } // namespace ash | 70 } // namespace ash |
OLD | NEW |