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