| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_COCOA_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_M
AC_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_M
AC_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_M
AC_H_ | 6 #define CHROME_BROWSER_UI_COCOA_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_M
AC_H_ |
| 7 | 7 |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 12 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| 13 #include "ui/base/cocoa/text_services_context_menu.h" |
| 13 | 14 |
| 14 @class MenuController; | 15 @class MenuController; |
| 15 | 16 |
| 16 // Mac implementation of the context menu display code. Uses a Cocoa NSMenu | 17 // Mac implementation of the context menu display code. Uses a Cocoa NSMenu |
| 17 // to display the context menu. Internally uses an obj-c object as the | 18 // to display the context menu. Internally uses an obj-c object as the |
| 18 // target of the NSMenu, bridging back to this C++ class. | 19 // target of the NSMenu, bridging back to this C++ class. |
| 19 class RenderViewContextMenuMac : public RenderViewContextMenu { | 20 class RenderViewContextMenuMac : public RenderViewContextMenu, |
| 21 public ui::TextServicesContextMenu::Delegate { |
| 20 public: | 22 public: |
| 21 RenderViewContextMenuMac(content::RenderFrameHost* render_frame_host, | 23 RenderViewContextMenuMac(content::RenderFrameHost* render_frame_host, |
| 22 const content::ContextMenuParams& params, | 24 const content::ContextMenuParams& params, |
| 23 NSView* parent_view); | 25 NSView* parent_view); |
| 24 ~RenderViewContextMenuMac() override; | 26 ~RenderViewContextMenuMac() override; |
| 25 | 27 |
| 26 // SimpleMenuModel::Delegate implementation. | 28 // SimpleMenuModel::Delegate implementation. |
| 27 void ExecuteCommand(int command_id, int event_flags) override; | 29 void ExecuteCommand(int command_id, int event_flags) override; |
| 28 bool IsCommandIdChecked(int command_id) const override; | 30 bool IsCommandIdChecked(int command_id) const override; |
| 29 bool IsCommandIdEnabled(int command_id) const override; | 31 bool IsCommandIdEnabled(int command_id) const override; |
| 30 | 32 |
| 33 // TextServicesContextMenu::Delegate: |
| 34 base::string16 GetSelectedText() const override; |
| 35 void OnSpeakRequested() override; |
| 36 bool IsTextDirectionEnabled( |
| 37 base::i18n::TextDirection direction) const override; |
| 38 bool IsTextDirectionChecked( |
| 39 base::i18n::TextDirection direction) const override; |
| 40 void UpdateTextDirection(base::i18n::TextDirection direction) override; |
| 41 |
| 31 // RenderViewContextMenuBase implementation. | 42 // RenderViewContextMenuBase implementation. |
| 32 void Show() override; | 43 void Show() override; |
| 33 | 44 |
| 34 protected: | |
| 35 // RenderViewContextMenu implementation. | |
| 36 void AppendPlatformEditableItems() override; | |
| 37 | |
| 38 private: | 45 private: |
| 39 friend class ToolkitDelegateMac; | 46 friend class ToolkitDelegateMac; |
| 40 | 47 |
| 41 // Adds menu to the platform's toolkit. | 48 // Adds menu to the platform's toolkit. |
| 42 void InitToolkitMenu(); | 49 void InitToolkitMenu(); |
| 43 | 50 |
| 44 // Cancels the menu. | 51 // Cancels the menu. |
| 45 void CancelToolkitMenu(); | 52 void CancelToolkitMenu(); |
| 46 | 53 |
| 47 // Updates the status and text of the specified context-menu item. | 54 // Updates the status and text of the specified context-menu item. |
| 48 void UpdateToolkitMenuItem(int command_id, | 55 void UpdateToolkitMenuItem(int command_id, |
| 49 bool enabled, | 56 bool enabled, |
| 50 bool hidden, | 57 bool hidden, |
| 51 const base::string16& title); | 58 const base::string16& title); |
| 52 | 59 |
| 53 // Adds writing direction submenu. | 60 // Handler for the "Look Up" menu item. |
| 54 void AppendBidiSubMenu(); | |
| 55 | |
| 56 // Handler for the "Look Up in Dictionary" menu item. | |
| 57 void LookUpInDictionary(); | 61 void LookUpInDictionary(); |
| 58 | 62 |
| 59 // Handler for the "Start Speaking" menu item. | |
| 60 void StartSpeaking(); | |
| 61 | |
| 62 // Handler for the "Stop Speaking" menu item. | |
| 63 void StopSpeaking(); | |
| 64 | |
| 65 // The Cocoa menu controller for this menu. | 63 // The Cocoa menu controller for this menu. |
| 66 base::scoped_nsobject<MenuController> menu_controller_; | 64 base::scoped_nsobject<MenuController> menu_controller_; |
| 67 | 65 |
| 68 // Model for the "Speech" submenu. | |
| 69 ui::SimpleMenuModel speech_submenu_model_; | |
| 70 | |
| 71 // Model for the BiDi input submenu. | |
| 72 ui::SimpleMenuModel bidi_submenu_model_; | |
| 73 | |
| 74 // The Cocoa parent view. | 66 // The Cocoa parent view. |
| 75 NSView* parent_view_; | 67 NSView* parent_view_; |
| 76 | 68 |
| 69 // The context menu that adds and handles Speech, Lookup and BiDi. |
| 70 ui::TextServicesContextMenu text_services_context_menu_; |
| 71 |
| 77 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuMac); | 72 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenuMac); |
| 78 }; | 73 }; |
| 79 | 74 |
| 80 // The ChromeSwizzleServicesMenuUpdater filters Services menu items in the | 75 // The ChromeSwizzleServicesMenuUpdater filters Services menu items in the |
| 81 // contextual menus and elsewhere using swizzling. | 76 // contextual menus and elsewhere using swizzling. |
| 82 @interface ChromeSwizzleServicesMenuUpdater : NSObject | 77 @interface ChromeSwizzleServicesMenuUpdater : NSObject |
| 83 // Return filtered entries, for testing. | 78 // Return filtered entries, for testing. |
| 84 + (void)storeFilteredEntriesForTestingInArray:(NSMutableArray*)array; | 79 + (void)storeFilteredEntriesForTestingInArray:(NSMutableArray*)array; |
| 85 @end | 80 @end |
| 86 | 81 |
| 87 #endif // CHROME_BROWSER_UI_COCOA_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MEN
U_MAC_H_ | 82 #endif // CHROME_BROWSER_UI_COCOA_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MEN
U_MAC_H_ |
| OLD | NEW |