1// Copyright 2014 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#ifndef CHROME_BROWSER_UI_COCOA_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_MAC_H_
6#define CHROME_BROWSER_UI_COCOA_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_MAC_H_
7
8#import <Cocoa/Cocoa.h>
9
10#include "base/mac/scoped_nsobject.h"
11#include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
12
13@class MenuController;
14
15// Mac implementation of the context menu display code. Uses a Cocoa NSMenu
16// to display the context menu. Internally uses an obj-c object as the
17// target of the NSMenu, bridging back to this C++ class.
18class RenderViewContextMenuMac : public RenderViewContextMenu {
19 public:
20  RenderViewContextMenuMac(content::RenderFrameHost* render_frame_host,
21                           const content::ContextMenuParams& params,
22                           NSView* parent_view);
23  virtual ~RenderViewContextMenuMac();
24
25  // SimpleMenuModel::Delegate implementation.
26  virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
27  virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
28  virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
29
30  void Show();
31
32 protected:
33  // RenderViewContextMenu implementation.
34  virtual bool GetAcceleratorForCommandId(
35      int command_id,
36      ui::Accelerator* accelerator) OVERRIDE;
37  virtual void AppendPlatformEditableItems() OVERRIDE;
38
39 private:
40  friend class ToolkitDelegateMac;
41
42  // Adds menu to the platform's toolkit.
43  void InitToolkitMenu();
44
45  // Cancels the menu.
46  void CancelToolkitMenu();
47
48  // Updates the status and text of the specified context-menu item.
49  void UpdateToolkitMenuItem(int command_id,
50                             bool enabled,
51                             bool hidden,
52                             const base::string16& title);
53
54  // Adds writing direction submenu.
55  void AppendBidiSubMenu();
56
57  // Handler for the "Look Up in Dictionary" menu item.
58  void LookUpInDictionary();
59
60  // Handler for the "Start Speaking" menu item.
61  void StartSpeaking();
62
63  // Handler for the "Stop Speaking" menu item.
64  void StopSpeaking();
65
66  // The Cocoa menu controller for this menu.
67  base::scoped_nsobject<MenuController> menu_controller_;
68
69  // Model for the "Speech" submenu.
70  ui::SimpleMenuModel speech_submenu_model_;
71
72  // Model for the BiDi input submenu.
73  ui::SimpleMenuModel bidi_submenu_model_;
74
75  // The Cocoa parent view.
76  NSView* parent_view_;
77
78  DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuMac);
79};
80
81#endif  // CHROME_BROWSER_UI_COCOA_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_MAC_H_
82