• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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/shell/context_menu.h"
6 
7 #include "ash/launcher/launcher.h"
8 #include "ash/root_window_controller.h"
9 #include "ash/shelf/shelf_types.h"
10 #include "ash/shell.h"
11 #include "grit/ash_strings.h"
12 #include "ui/base/l10n/l10n_util.h"
13 
14 namespace ash {
15 namespace shell {
16 
ContextMenu(aura::Window * root)17 ContextMenu::ContextMenu(aura::Window* root)
18     : ui::SimpleMenuModel(NULL),
19       root_window_(root),
20       alignment_menu_(root) {
21   DCHECK(root_window_);
22   set_delegate(this);
23   AddCheckItemWithStringId(MENU_AUTO_HIDE,
24                            IDS_ASH_SHELF_CONTEXT_MENU_AUTO_HIDE);
25   AddSubMenuWithStringId(MENU_ALIGNMENT_MENU,
26                          IDS_ASH_SHELF_CONTEXT_MENU_POSITION,
27                          &alignment_menu_);
28 }
29 
~ContextMenu()30 ContextMenu::~ContextMenu() {
31 }
32 
IsCommandIdChecked(int command_id) const33 bool ContextMenu::IsCommandIdChecked(int command_id) const {
34   switch (command_id) {
35     case MENU_AUTO_HIDE:
36       return Shell::GetInstance()->GetShelfAutoHideBehavior(root_window_) ==
37           ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
38     default:
39       return false;
40   }
41 }
42 
IsCommandIdEnabled(int command_id) const43 bool ContextMenu::IsCommandIdEnabled(int command_id) const {
44   return true;
45 }
46 
GetAcceleratorForCommandId(int command_id,ui::Accelerator * accelerator)47 bool ContextMenu::GetAcceleratorForCommandId(
48       int command_id,
49       ui::Accelerator* accelerator) {
50   return false;
51 }
52 
ExecuteCommand(int command_id,int event_flags)53 void ContextMenu::ExecuteCommand(int command_id, int event_flags) {
54   Shell* shell = Shell::GetInstance();
55   switch (static_cast<MenuItem>(command_id)) {
56     case MENU_AUTO_HIDE:
57       shell->SetShelfAutoHideBehavior(
58           shell->GetShelfAutoHideBehavior(root_window_) ==
59               SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ?
60                   SHELF_AUTO_HIDE_BEHAVIOR_NEVER :
61                   SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
62           root_window_);
63       break;
64     case MENU_ALIGNMENT_MENU:
65       break;
66   }
67 }
68 
69 }  // namespace shell
70 }  // namespace ash
71