OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/shelf/shelf_alignment_menu.h" | |
6 | |
7 #include "ash/common/shelf/shelf_types.h" | |
8 #include "ash/common/shelf/wm_shelf.h" | |
9 #include "ash/common/wm/wm_user_metrics_action.h" | |
10 #include "ash/common/wm_shell.h" | |
11 #include "grit/ash_strings.h" | |
12 | |
13 namespace ash { | |
14 | |
15 ShelfAlignmentMenu::ShelfAlignmentMenu(WmShelf* wm_shelf) | |
16 : ui::SimpleMenuModel(nullptr), wm_shelf_(wm_shelf) { | |
17 DCHECK(wm_shelf_); | |
18 const int align_group_id = 1; | |
19 set_delegate(this); | |
20 AddRadioItemWithStringId(MENU_ALIGN_LEFT, | |
21 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_LEFT, | |
22 align_group_id); | |
23 AddRadioItemWithStringId(MENU_ALIGN_BOTTOM, | |
24 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_BOTTOM, | |
25 align_group_id); | |
26 AddRadioItemWithStringId(MENU_ALIGN_RIGHT, | |
27 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_RIGHT, | |
28 align_group_id); | |
29 } | |
30 | |
31 ShelfAlignmentMenu::~ShelfAlignmentMenu() {} | |
32 | |
33 bool ShelfAlignmentMenu::IsCommandIdChecked(int command_id) const { | |
34 switch (wm_shelf_->GetAlignment()) { | |
35 case SHELF_ALIGNMENT_BOTTOM: | |
36 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | |
37 return command_id == MENU_ALIGN_BOTTOM; | |
38 case SHELF_ALIGNMENT_LEFT: | |
39 return command_id == MENU_ALIGN_LEFT; | |
40 case SHELF_ALIGNMENT_RIGHT: | |
41 return command_id == MENU_ALIGN_RIGHT; | |
42 } | |
43 return false; | |
44 } | |
45 | |
46 bool ShelfAlignmentMenu::IsCommandIdEnabled(int command_id) const { | |
47 return true; | |
48 } | |
49 | |
50 bool ShelfAlignmentMenu::GetAcceleratorForCommandId( | |
51 int command_id, | |
52 ui::Accelerator* accelerator) { | |
53 return false; | |
54 } | |
55 | |
56 void ShelfAlignmentMenu::ExecuteCommand(int command_id, int event_flags) { | |
57 WmShell* shell = WmShell::Get(); | |
58 switch (static_cast<MenuItem>(command_id)) { | |
59 case MENU_ALIGN_LEFT: | |
60 shell->RecordUserMetricsAction( | |
61 wm::WmUserMetricsAction::SHELF_ALIGNMENT_SET_LEFT); | |
62 wm_shelf_->SetAlignment(SHELF_ALIGNMENT_LEFT); | |
63 break; | |
64 case MENU_ALIGN_BOTTOM: | |
65 shell->RecordUserMetricsAction( | |
66 wm::WmUserMetricsAction::SHELF_ALIGNMENT_SET_BOTTOM); | |
67 wm_shelf_->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | |
68 break; | |
69 case MENU_ALIGN_RIGHT: | |
70 shell->RecordUserMetricsAction( | |
71 wm::WmUserMetricsAction::SHELF_ALIGNMENT_SET_RIGHT); | |
72 wm_shelf_->SetAlignment(SHELF_ALIGNMENT_RIGHT); | |
73 break; | |
74 } | |
75 } | |
76 | |
77 } // namespace ash | |
OLD | NEW |