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/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" 13 #include "ui/base/l10n/l10n_util.h" 14 15 namespace ash { 16 17 ShelfAlignmentMenu::ShelfAlignmentMenu(aura::Window* root) 18 : ui::SimpleMenuModel(NULL), 19 root_window_(root) { 20 DCHECK(root_window_); 21 int align_group_id = 1; 22 set_delegate(this); 23 AddRadioItemWithStringId(MENU_ALIGN_LEFT, 24 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_LEFT, 25 align_group_id); 26 AddRadioItemWithStringId(MENU_ALIGN_BOTTOM, 27 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_BOTTOM, 28 align_group_id); 29 AddRadioItemWithStringId(MENU_ALIGN_RIGHT, 30 IDS_ASH_SHELF_CONTEXT_MENU_ALIGN_RIGHT, 31 align_group_id); 32 } 33 34 ShelfAlignmentMenu::~ShelfAlignmentMenu() {} 35 36 bool ShelfAlignmentMenu::IsCommandIdChecked(int command_id) const { 37 return internal::ShelfLayoutManager::ForLauncher(root_window_)-> 38 SelectValueForShelfAlignment( 39 MENU_ALIGN_BOTTOM == command_id, 40 MENU_ALIGN_LEFT == command_id, 41 MENU_ALIGN_RIGHT == command_id, 42 false); 43 } 44 45 bool ShelfAlignmentMenu::IsCommandIdEnabled(int command_id) const { 46 return true; 47 } 48 49 bool ShelfAlignmentMenu::GetAcceleratorForCommandId( 50 int command_id, 51 ui::Accelerator* accelerator) { 52 return false; 53 } 54 55 void ShelfAlignmentMenu::ExecuteCommand(int command_id, int event_flags) { 56 switch (static_cast<MenuItem>(command_id)) { 57 case MENU_ALIGN_LEFT: 58 Shell::GetInstance()->metrics()-> 59 RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_LEFT); 60 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, 61 root_window_); 62 break; 63 case MENU_ALIGN_BOTTOM: 64 Shell::GetInstance()->metrics()-> 65 RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_BOTTOM); 66 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM, 67 root_window_); 68 break; 69 case MENU_ALIGN_RIGHT: 70 Shell::GetInstance()->metrics()-> 71 RecordUserMetricsAction(UMA_SHELF_ALIGNMENT_SET_RIGHT); 72 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_RIGHT, 73 root_window_); 74 break; 75 } 76 } 77 78 } // namespace ash 79