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 COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ | 5 #ifndef COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ |
6 #define COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ | 6 #define COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ |
7 | 7 |
8 namespace content { | 8 namespace content { |
9 struct ContextMenuParams; | 9 struct ContextMenuParams; |
10 } | 10 } |
11 | 11 |
12 // The interface used for implementing context-menu items. The following | 12 // The interface used for implementing context-menu items. The following |
13 // instruction describe how to implement a context-menu item with this | 13 // instruction describe how to implement a context-menu item with this |
14 // interface. | 14 // interface. |
15 // | 15 // |
16 // 1. Add command IDs for the context-menu items to 'chrome_command_ids.h'. | 16 // 1. Add command IDs for the context-menu items to 'chrome_command_ids.h'. |
17 // | 17 // |
18 // #define IDC_MY_COMMAND 99999 | 18 // #define IDC_MY_COMMAND 99999 |
19 // | 19 // |
20 // 2. Add strings for the context-menu items to 'generated_sources.grd'. | 20 // 2. Add strings for the context-menu items to 'generated_sources.grd'. |
21 // | 21 // |
22 // <message name="IDS_MY_COMMAND" desc="..."> | 22 // <message name="IDS_MY_COMMAND" desc="..."> |
23 // My command | 23 // My command |
24 // </message> | 24 // </message> |
25 // | 25 // |
26 // 3. Create a class that implements this interface. (It is a good idea to use | 26 // 3. Create a class that implements this interface. (It is a good idea to use |
27 // the RenderViewContextMenuDelegate interface to avoid accessing the | 27 // the RenderViewContextMenuProxy interface to avoid accessing the |
28 // RenderViewContextMenu class directly.) | 28 // RenderViewContextMenu class directly.) |
29 // | 29 // |
30 // class MyMenuObserver : public RenderViewContextMenuObserver { | 30 // class MyMenuObserver : public RenderViewContextMenuObserver { |
31 // public: | 31 // public: |
32 // MyMenuObserver(RenderViewContextMenuDelegate* d); | 32 // MyMenuObserver(RenderViewContextMenuProxy* p); |
33 // ~MyMenuObserver(); | 33 // ~MyMenuObserver(); |
34 // | 34 // |
35 // virtual void InitMenu(const content::ContextMenuParams& params) OVERRIDE; | 35 // virtual void InitMenu(const content::ContextMenuParams& params) OVERRIDE; |
36 // virtual bool IsCommandIdSupported(int command_id) OVERRIDE; | 36 // virtual bool IsCommandIdSupported(int command_id) OVERRIDE; |
37 // virtual bool IsCommandIdEnabled(int command_id) OVERRIDE; | 37 // virtual bool IsCommandIdEnabled(int command_id) OVERRIDE; |
38 // virtual void ExecuteCommand(int command_id) OVERRIDE; | 38 // virtual void ExecuteCommand(int command_id) OVERRIDE; |
39 // | 39 // |
40 // private: | 40 // private: |
41 // RenderViewContextMenuDelgate* delegate_; | 41 // RenderViewContextMenuProxy* proxy_; |
42 // } | 42 // } |
43 // | 43 // |
44 // void MyMenuObserver::InitMenu(const content::ContextMenuParams& params) { | 44 // void MyMenuObserver::InitMenu(const content::ContextMenuParams& params) { |
45 // delegate_->AddMenuItem(IDC_MY_COMMAND,...); | 45 // proxy_->AddMenuItem(IDC_MY_COMMAND,...); |
46 // } | 46 // } |
47 // | 47 // |
48 // bool MyMenuObserver::IsCommandIdSupported(int command_id) { | 48 // bool MyMenuObserver::IsCommandIdSupported(int command_id) { |
49 // return command_id == IDC_MY_COMMAND; | 49 // return command_id == IDC_MY_COMMAND; |
50 // } | 50 // } |
51 // | 51 // |
52 // bool MyMenuObserver::IsCommandIdEnabled(int command_id) { | 52 // bool MyMenuObserver::IsCommandIdEnabled(int command_id) { |
53 // DCHECK(command_id == IDC_MY_COMMAND); | 53 // DCHECK(command_id == IDC_MY_COMMAND); |
54 // return true; | 54 // return true; |
55 // } | 55 // } |
(...skipping 19 matching lines...) Expand all Loading... |
75 // my_menu_observer_.reset(new MyMenuObserver(this)); | 75 // my_menu_observer_.reset(new MyMenuObserver(this)); |
76 // observers_.AddObserver(my_menu_observer_.get()); | 76 // observers_.AddObserver(my_menu_observer_.get()); |
77 // } | 77 // } |
78 // | 78 // |
79 // | 79 // |
80 class RenderViewContextMenuObserver { | 80 class RenderViewContextMenuObserver { |
81 public: | 81 public: |
82 virtual ~RenderViewContextMenuObserver() {} | 82 virtual ~RenderViewContextMenuObserver() {} |
83 | 83 |
84 // Called when the RenderViewContextMenu class initializes a context menu. We | 84 // Called when the RenderViewContextMenu class initializes a context menu. We |
85 // usually call RenderViewContextMenuDelegate::AddMenuItem() to add menu items | 85 // usually call RenderViewContextMenuProxy::AddMenuItem() to add menu items |
86 // in this function. | 86 // in this function. |
87 virtual void InitMenu(const content::ContextMenuParams& params) {} | 87 virtual void InitMenu(const content::ContextMenuParams& params) {} |
88 | 88 |
89 // Called when the RenderViewContextMenu class asks whether an observer | 89 // Called when the RenderViewContextMenu class asks whether an observer |
90 // listens for the specified command ID. If this function returns true, the | 90 // listens for the specified command ID. If this function returns true, the |
91 // RenderViewContextMenu class calls IsCommandIdEnabled() or ExecuteCommand(). | 91 // RenderViewContextMenu class calls IsCommandIdEnabled() or ExecuteCommand(). |
92 virtual bool IsCommandIdSupported(int command_id); | 92 virtual bool IsCommandIdSupported(int command_id); |
93 | 93 |
94 // Called when the RenderViewContextMenu class sets the initial status of the | 94 // Called when the RenderViewContextMenu class sets the initial status of the |
95 // specified context-menu item. If we need to enable or disable a context-menu | 95 // specified context-menu item. If we need to enable or disable a context-menu |
96 // item while showing, use RenderViewContextMenuDelegate::UpdateMenuItem(). | 96 // item while showing, use RenderViewContextMenuProxy::UpdateMenuItem(). |
97 virtual bool IsCommandIdChecked(int command_id); | 97 virtual bool IsCommandIdChecked(int command_id); |
98 virtual bool IsCommandIdEnabled(int command_id); | 98 virtual bool IsCommandIdEnabled(int command_id); |
99 | 99 |
100 // Called when a user selects the specified context-menu item. | 100 // Called when a user selects the specified context-menu item. |
101 virtual void ExecuteCommand(int command_id) {} | 101 virtual void ExecuteCommand(int command_id) {} |
102 | 102 |
103 // Called when a user closes the context menu without selecting any items. | 103 // Called when a user closes the context menu without selecting any items. |
104 virtual void OnMenuCancel() {} | 104 virtual void OnMenuCancel() {} |
105 }; | 105 }; |
106 | 106 |
107 #endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ | 107 #endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ |
OLD | NEW |