Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: chrome/browser/tab_contents/render_view_context_menu.h

Issue 7713033: Integrate the Spelling service to Chrome. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_ 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_ 6 #define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
15 #include "base/observer_list.h"
15 #include "base/string16.h" 16 #include "base/string16.h"
16 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 17 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
17 #include "chrome/browser/extensions/extension_menu_manager.h" 18 #include "chrome/browser/extensions/extension_menu_manager.h"
19 #include "chrome/browser/tab_contents/render_view_context_menu_observer.h"
18 #include "content/common/page_transition_types.h" 20 #include "content/common/page_transition_types.h"
19 #include "ui/base/models/simple_menu_model.h" 21 #include "ui/base/models/simple_menu_model.h"
20 #include "webkit/glue/context_menu.h" 22 #include "webkit/glue/context_menu.h"
21 #include "webkit/glue/window_open_disposition.h" 23 #include "webkit/glue/window_open_disposition.h"
22 24
23 class ExtensionMenuItem; 25 class ExtensionMenuItem;
24 class Profile; 26 class Profile;
27 class RenderViewHost;
25 class TabContents; 28 class TabContents;
29 class SpellingMenuObserver;
26 30
27 namespace gfx { 31 namespace gfx {
28 class Point; 32 class Point;
29 } 33 }
30 34
31 namespace WebKit { 35 namespace WebKit {
32 struct WebMediaPlayerAction; 36 struct WebMediaPlayerAction;
33 } 37 }
34 38
35 class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate { 39 // An interface that controls a RenderViewContextMenu instance from observers.
40 // This interface is designed mainly for controling the instance while showing
Avi (use Gerrit) 2011/08/23 18:38:19 typo: controlling
Hironori Bono 2011/08/25 11:18:58 Done.
41 // so we can add a context-menu item that takes long time to create its text,
42 // such as retrieving the item text from a server. The simplest usage is:
43 // 1. Adding an item with temporary text;
44 // 2. Posting a background task that creates the item text, and;
45 // 3. Calling UpdateMenuItem() in the callback function.
46 // The following snippet describes the simple usage that updates a context-menu
47 // item with this interface.
48 //
49 // class MyTask : public URLFetcher::Delegate {
50 // public:
51 // MyTask(RenderViewContextMenuDelegate* delegate, int id)
52 // : delegate_(delegate),
53 // id_(id) {
54 // }
55 // virtual ~MyTask() {
56 // }
57 // virtual void OnURLFetchComplete(const URLFetcher* source,
58 // const GURL& url,
59 // const net::URLRequestStatus& status,
60 // int response,
61 // const net::ResponseCookies& cookies,
62 // const std::string& data) {
63 // bool enabled = respose == 200;
Avi (use Gerrit) 2011/08/23 18:38:19 response
Hironori Bono 2011/08/25 11:18:58 Done.
64 // const char* text = enabled ? "OK" : "ERROR";
65 // delegate_->UpdateMenuItem(id_, enabled, ASCIIToUTF16(text));
66 // }
67 // void Start(const GURL* url, net::URLRequestContextGetter* context) {
68 // fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this));
69 // fetcher_->set_request_context(context);
70 // fetcher_->Start();
71 // }
72 //
73 // private:
74 // URLFetcher fetcher_;
75 // RenderViewContextMenuDelegate* delegate_;
76 // int id_;
77 // };
78 //
79 // void RenderViewContextMenu::AppendEditableItems() {
80 // // Add a menu item with temporary text shown while we create the final
81 // // text.
82 // menu_model_.AddItemWithStringId(IDC_MY_ITEM, IDC_MY_TEXT);
83 //
84 // // Start a task that creates the final text.
85 // my_task_ = new MyTask(this, IDC_MY_ITEM);
86 // my_task_->Start(...);
87 // }
88 //
89 class RenderViewContextMenuDelegate {
Avi (use Gerrit) 2011/08/23 18:38:19 This naming seems backwards from most usage of the
Hironori Bono 2011/08/25 11:18:58 Thank you for your description. This is just cause
Avi (use Gerrit) 2011/08/25 14:59:12 That's better. I'm struggling to come up with a go
Hironori Bono 2011/08/29 08:17:04 It is a good question. I initially tried to split
90 public:
91 // Add a menu item to a context menu.
92 virtual void AddMenuItem(int command_id, const string16& title) = 0;
93
94 // Update the stauts and text of the specified context-menu item.
Avi (use Gerrit) 2011/08/23 18:38:19 status
Hironori Bono 2011/08/25 11:18:58 Done.
95 virtual void UpdateMenuItem(int command_id,
96 bool enabled,
97 const string16& title) = 0;
98
99 // Retrieve the RenderViewHost (or Profile) instance associated with a context
100 // menu, respectively.
101 virtual RenderViewHost* GetRenderViewHost() const = 0;
102 virtual Profile* GetProfile() const = 0;
103 };
104
105 class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate,
106 public RenderViewContextMenuDelegate {
36 public: 107 public:
37 static const size_t kMaxExtensionItemTitleLength; 108 static const size_t kMaxExtensionItemTitleLength;
38 static const size_t kMaxSelectionTextLength; 109 static const size_t kMaxSelectionTextLength;
39 110
40 RenderViewContextMenu(TabContents* tab_contents, 111 RenderViewContextMenu(TabContents* tab_contents,
41 const ContextMenuParams& params); 112 const ContextMenuParams& params);
42 113
43 virtual ~RenderViewContextMenu(); 114 virtual ~RenderViewContextMenu();
44 115
45 // Initializes the context menu. 116 // Initializes the context menu.
46 void Init(); 117 void Init();
47 118
48 // Provide access to the menu model for ExternalTabContainer. 119 // Provide access to the menu model for ExternalTabContainer.
49 const ui::MenuModel& menu_model() const { return menu_model_; } 120 const ui::MenuModel& menu_model() const { return menu_model_; }
50 121
51 // SimpleMenuModel::Delegate implementation. 122 // SimpleMenuModel::Delegate implementation.
52 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 123 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
53 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 124 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
54 virtual void ExecuteCommand(int command_id) OVERRIDE; 125 virtual void ExecuteCommand(int command_id) OVERRIDE;
55 virtual void MenuWillShow(ui::SimpleMenuModel* source) OVERRIDE; 126 virtual void MenuWillShow(ui::SimpleMenuModel* source) OVERRIDE;
56 virtual void MenuClosed(ui::SimpleMenuModel* source) OVERRIDE; 127 virtual void MenuClosed(ui::SimpleMenuModel* source) OVERRIDE;
57 128
129 // RenderViewContextMenuDelegate implementation.
130 virtual void AddMenuItem(int command_id, const string16& title) OVERRIDE;
131 virtual void UpdateMenuItem(int command_id,
132 bool enabled,
133 const string16& title) OVERRIDE;
134 virtual RenderViewHost* GetRenderViewHost() const;
135 virtual Profile* GetProfile() const;
136
58 protected: 137 protected:
59 void InitMenu(); 138 void InitMenu();
60 139
61 // Platform specific functions. 140 // Platform specific functions.
62 virtual void PlatformInit() = 0; 141 virtual void PlatformInit() = 0;
63 virtual bool GetAcceleratorForCommandId( 142 virtual bool GetAcceleratorForCommandId(
64 int command_id, 143 int command_id,
65 ui::Accelerator* accelerator) = 0; 144 ui::Accelerator* accelerator) = 0;
66 virtual void LookUpInDictionary(); 145 virtual void LookUpInDictionary();
67 146
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // a text selection. 242 // a text selection.
164 GURL selection_navigation_url_; 243 GURL selection_navigation_url_;
165 244
166 ui::SimpleMenuModel spellcheck_submenu_model_; 245 ui::SimpleMenuModel spellcheck_submenu_model_;
167 ui::SimpleMenuModel speech_input_submenu_model_; 246 ui::SimpleMenuModel speech_input_submenu_model_;
168 ui::SimpleMenuModel bidi_submenu_model_; 247 ui::SimpleMenuModel bidi_submenu_model_;
169 ui::SimpleMenuModel protocol_handler_submenu_model_; 248 ui::SimpleMenuModel protocol_handler_submenu_model_;
170 ScopedVector<ui::SimpleMenuModel> extension_menu_models_; 249 ScopedVector<ui::SimpleMenuModel> extension_menu_models_;
171 scoped_refptr<ProtocolHandlerRegistry> protocol_handler_registry_; 250 scoped_refptr<ProtocolHandlerRegistry> protocol_handler_registry_;
172 251
252 // An observer that handles a spelling-menu items.
253 scoped_ptr<SpellingMenuObserver> spelling_menu_observer_;
254
255 // Our observers.
256 mutable ObserverList<RenderViewContextMenuObserver> observers_;
257
173 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu); 258 DISALLOW_COPY_AND_ASSIGN(RenderViewContextMenu);
174 }; 259 };
175 260
176 #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_ 261 #endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698