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.
5 #include "ash/shelf/shelf_alignment_menu.h"
7 #include "ash/metrics/user_metrics_recorder.h"
8 #include "ash/shelf/shelf_layout_manager.h"
9 #include "ash/shelf/shelf_types.h"
10 #include "ash/shell.h"
11 #include "grit/ash_strings.h"
12 #include "ui/aura/window.h"
16 ShelfAlignmentMenu::ShelfAlignmentMenu(aura::Window
* root
)
17 : ui::SimpleMenuModel(NULL
),
20 int align_group_id
= 1;
22 AddRadioItemWithStringId(MENU_ALIGN_LEFT
,
23 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_LEFT
,
25 AddRadioItemWithStringId(MENU_ALIGN_BOTTOM
,
26 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_BOTTOM
,
28 AddRadioItemWithStringId(MENU_ALIGN_RIGHT
,
29 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_RIGHT
,
33 ShelfAlignmentMenu::~ShelfAlignmentMenu() {}
35 bool ShelfAlignmentMenu::IsCommandIdChecked(int command_id
) const {
36 return ShelfLayoutManager::ForShelf(root_window_
)
37 ->SelectValueForShelfAlignment(MENU_ALIGN_BOTTOM
== command_id
,
38 MENU_ALIGN_LEFT
== command_id
,
39 MENU_ALIGN_RIGHT
== command_id
,
43 bool ShelfAlignmentMenu::IsCommandIdEnabled(int command_id
) const {
47 bool ShelfAlignmentMenu::GetAcceleratorForCommandId(
49 ui::Accelerator
* accelerator
) {
53 void ShelfAlignmentMenu::ExecuteCommand(int command_id
, int event_flags
) {
54 switch (static_cast<MenuItem
>(command_id
)) {
56 Shell::GetInstance()->metrics()->
57 RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_LEFT
);
58 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT
,
61 case MENU_ALIGN_BOTTOM
:
62 Shell::GetInstance()->metrics()->
63 RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_BOTTOM
);
64 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM
,
67 case MENU_ALIGN_RIGHT
:
68 Shell::GetInstance()->metrics()->
69 RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_RIGHT
);
70 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_RIGHT
,