| 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 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // } |
| 56 // | 56 // |
| 57 // void MyMenuObserver::ExecuteCommand(int command_id) { | 57 // void MyMenuObserver::ExecuteCommand(int command_id) { |
| 58 // DCHECK(command_id == IDC_MY_COMMAND); | 58 // DCHECK(command_id == IDC_MY_COMMAND); |
| 59 // } | 59 // } |
| 60 // | 60 // |
| 61 // 4. Add this observer class to the RenderViewContextMenu class. (It is good | 61 // 4. Add this observer class to the RenderViewContextMenu class. (It is good |
| 62 // to use scoped_ptr<> so Chrome can create its instances only when it needs.) | 62 // to use std::unique_ptr<> so Chrome can create its instances only when it |
| 63 // needs.) |
| 63 // | 64 // |
| 64 // class RenderViewContextMenu { | 65 // class RenderViewContextMenu { |
| 65 // ... | 66 // ... |
| 66 // private: | 67 // private: |
| 67 // scoped_ptr<MyMenuObserver> my_menu_observer_; | 68 // std::unique_ptr<MyMenuObserver> my_menu_observer_; |
| 68 // }; | 69 // }; |
| 69 // | 70 // |
| 70 // 5. Create its instance in InitMenu() and add it to the observer list of the | 71 // 5. Create its instance in InitMenu() and add it to the observer list of the |
| 71 // RenderViewContextMenu class. | 72 // RenderViewContextMenu class. |
| 72 // | 73 // |
| 73 // void RenderViewContextMenu::InitMenu() { | 74 // void RenderViewContextMenu::InitMenu() { |
| 74 // ... | 75 // ... |
| 75 // my_menu_observer_.reset(new MyMenuObserver(this)); | 76 // my_menu_observer_.reset(new MyMenuObserver(this)); |
| 76 // observers_.AddObserver(my_menu_observer_.get()); | 77 // observers_.AddObserver(my_menu_observer_.get()); |
| 77 // } | 78 // } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 98 virtual bool IsCommandIdEnabled(int command_id); | 99 virtual bool IsCommandIdEnabled(int command_id); |
| 99 | 100 |
| 100 // Called when a user selects the specified context-menu item. | 101 // Called when a user selects the specified context-menu item. |
| 101 virtual void ExecuteCommand(int command_id) {} | 102 virtual void ExecuteCommand(int command_id) {} |
| 102 | 103 |
| 103 // Called when a user closes the context menu without selecting any items. | 104 // Called when a user closes the context menu without selecting any items. |
| 104 virtual void OnMenuCancel() {} | 105 virtual void OnMenuCancel() {} |
| 105 }; | 106 }; |
| 106 | 107 |
| 107 #endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ | 108 #endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ |
| OLD | NEW |