|
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 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_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ | |
6 #define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ | |
7 #pragma once | |
8 | |
9 struct ContextMenuParams; | |
10 | |
11 // The interface used for implementing context-menu items. The following | |
12 // instruction describe how to implement a context-menu item with this | |
13 // interface. | |
14 // | |
15 // 1. Add command IDs for the context-menu items to 'chrome_command_ids.h'. | |
16 // | |
17 // #define IDC_MY_COMMAND 99999 | |
18 // | |
19 // 2. Add strings for the context-menu items to 'generated_sources.grd'. | |
20 // | |
21 // <message name="IDS_MY_COMMAND" desc="..."> | |
22 // My command | |
23 // </message> | |
24 // | |
25 // 3. Create a class that implements this interface. (It is a good idea to use | |
26 // the RenderViewContextMenuDelegate interface to avoid accessing the | |
27 // RenderViewContetMenu class directly.) | |
Avi (use Gerrit)
2011/08/23 18:38:19
typo in class name
Hironori Bono
2011/08/25 11:18:58
Done.
| |
28 // | |
29 // class MyMenuObserver : public RenderViewContextMenuObserver { | |
30 // public: | |
31 // MyMenuObserver(RenderViewContextMenuDelegate* d); | |
32 // ~MyMenuObserver(); | |
33 // | |
34 // virtual void InitMenu(const ContextMenuParams& params) OVERRIDE; | |
35 // virtual bool IsCommandIdSupported(int command_id) OVERRIDE; | |
36 // virtual bool IsCommandIdEnabled(int command_id) OVERRIDE; | |
37 // virtual void ExecuteCommand(int command_id) OVERRIDE; | |
38 // | |
39 // private: | |
40 // RenderViewContextMenuDelgate* delegate_; | |
41 // } | |
42 // | |
43 // void MyMenuObserver::InitMenu(const ContextMenuParams& params) { | |
44 // delegate_->AddMenuItem(IDC_MY_COMMAND,...); | |
45 // } | |
46 // | |
47 // bool MyMenuObserver::IsCommandIdSupported(int command_id) { | |
48 // return command_id == IDC_MY_COMMAND; | |
49 // } | |
50 // | |
51 // bool MyMenuObserver::IsCommandIdEnabled(int command_id) { | |
52 // DCHECK(command_id == IDC_MY_COMMAND); | |
53 // return true; | |
54 // } | |
55 // | |
56 // void MyMenuObserver::ExecuteCommand(int command_id) { | |
57 // DCHECK(command_id == IDC_MY_COMMAND); | |
58 // } | |
59 // | |
60 // 4. Add this observer class to the RenderViewContextMenu class. (It is good | |
61 // to use scoped_ptr<> so Chrome can create its instances only when it needs.) | |
62 // | |
63 // class RenderViewContextMenu { | |
64 // ... | |
65 // private: | |
66 // scoped_ptr<MyMenuObserver> my_menu_observer_; | |
67 // }; | |
68 // | |
69 // 5. Create its instance in InitMenu() and add it to the observer list of the | |
70 // RenderViewContextMenu class. | |
71 // | |
72 // void RenderViewContextMenu::InitMenu() { | |
73 // ... | |
74 // my_menu_observer_.reset(new MyMenuObserver(this)); | |
75 // observers_.AddObserver(my_menu_observer_.get()); | |
76 // } | |
77 // | |
78 // | |
79 class RenderViewContextMenuObserver { | |
80 public: | |
81 virtual ~RenderViewContextMenuObserver() {} | |
82 | |
83 // Called when the RenderViewContextMenu class initializes a context menu. We | |
84 // usually call RenderViewContextMenuDelegate::AddMenuItem() to add menu items | |
85 // in this function. | |
86 virtual void InitMenu(const ContextMenuParams& params); | |
87 | |
88 // Called when the RenderViewContextMenu class asks whether an observer | |
89 // listens the specified command ID. If this function returns true, the | |
Avi (use Gerrit)
2011/08/23 18:38:19
listens for the specified...
Hironori Bono
2011/08/25 11:18:58
Done.
| |
90 // RenderViewContextMenu class calls IsCommandIdEnabled() or ExecuteCommand(). | |
91 virtual bool IsCommandIdSupported(int command_id); | |
92 | |
93 // Called when the RenderViewContextMenu class sets the initial status of the | |
94 // specified context-menu item. If we need to enable or disable a context-menu | |
95 // item while showing, use RenderViewContextMenuDelegate::UpdateMenuItem(). | |
96 virtual bool IsCommandIdEnabled(int command_id); | |
97 | |
98 // Called when a user selects the specified context-menu item. | |
99 virtual void ExecuteCommand(int command_id); | |
100 }; | |
101 | |
102 #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ | |
OLD | NEW |