summaryrefslogtreecommitdiffstats
path: root/views/controls/menu/native_menu_views.h
blob: 75e91004ed50c778bbe1ba1a0c6a5f1d53bbca6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef VIEWS_CONTROLS_MENU_NATIVE_MENU_LINUX_H_
#define VIEWS_CONTROLS_MENU_NATIVE_MENU_LINUX_H_
#pragma once

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "views/controls/menu/menu_delegate.h"
#include "views/controls/menu/menu_wrapper.h"

namespace ui {
class MenuModel;
}

namespace views {

class MenuItemView;
class MenuRunner;

// A views implementation of MenuWrapper, used currently for touchui.
class NativeMenuViews : public MenuWrapper,
                        public MenuDelegate {
 public:
  explicit NativeMenuViews(Menu2* menu);
  virtual ~NativeMenuViews();

  // Overridden from MenuWrapper:
  virtual void RunMenuAt(const gfx::Point& point, int alignment) OVERRIDE;
  virtual void CancelMenu() OVERRIDE;
  virtual void Rebuild() OVERRIDE;
  virtual void UpdateStates() OVERRIDE;
  virtual gfx::NativeMenu GetNativeMenu() const OVERRIDE;
  virtual MenuAction GetMenuAction() const OVERRIDE;
  virtual void AddMenuListener(MenuListener* listener) OVERRIDE;
  virtual void RemoveMenuListener(MenuListener* listener) OVERRIDE;
  virtual void SetMinimumWidth(int width) OVERRIDE;

  // Overridden from MenuDelegate:
  virtual bool IsItemChecked(int id) const OVERRIDE;
  virtual bool IsCommandEnabled(int id) const OVERRIDE;
  virtual void ExecuteCommand(int id) OVERRIDE;
  virtual bool GetAccelerator(int id, views::Accelerator* accelerator) OVERRIDE;

 private:
  void AddMenuItemsFromModel(MenuItemView* parent, ui::MenuModel* model);
  void UpdateMenuFromModel(SubmenuView* menu, ui::MenuModel* model);

  // The attached model and delegate. Does not assume ownership.
  ui::MenuModel* model_;
  MenuItemView* root_;
  scoped_ptr<MenuRunner> menu_runner_;

  DISALLOW_COPY_AND_ASSIGN(NativeMenuViews);
};

}  // namespace views

#endif  // VIEWS_CONTROLS_MENU_NATIVE_MENU_LINUX_H_