• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // ---------------------------------------------------------------------------
31 //
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_CONTEXT_MENU_HANDLER_H_
38 #define CEF_INCLUDE_CEF_CONTEXT_MENU_HANDLER_H_
39 #pragma once
40 
41 #include "include/cef_base.h"
42 #include "include/cef_browser.h"
43 #include "include/cef_frame.h"
44 #include "include/cef_menu_model.h"
45 
46 class CefContextMenuParams;
47 
48 ///
49 // Callback interface used for continuation of custom context menu display.
50 ///
51 /*--cef(source=library)--*/
52 class CefRunContextMenuCallback : public virtual CefBaseRefCounted {
53  public:
54   typedef cef_event_flags_t EventFlags;
55 
56   ///
57   // Complete context menu display by selecting the specified |command_id| and
58   // |event_flags|.
59   ///
60   /*--cef(capi_name=cont)--*/
61   virtual void Continue(int command_id, EventFlags event_flags) = 0;
62 
63   ///
64   // Cancel context menu display.
65   ///
66   /*--cef()--*/
67   virtual void Cancel() = 0;
68 };
69 
70 ///
71 // Implement this interface to handle context menu events. The methods of this
72 // class will be called on the UI thread.
73 ///
74 /*--cef(source=client)--*/
75 class CefContextMenuHandler : public virtual CefBaseRefCounted {
76  public:
77   typedef cef_event_flags_t EventFlags;
78 
79   ///
80   // Called before a context menu is displayed. |params| provides information
81   // about the context menu state. |model| initially contains the default
82   // context menu. The |model| can be cleared to show no context menu or
83   // modified to show a custom menu. Do not keep references to |params| or
84   // |model| outside of this callback.
85   ///
86   /*--cef()--*/
OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefContextMenuParams> params,CefRefPtr<CefMenuModel> model)87   virtual void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
88                                    CefRefPtr<CefFrame> frame,
89                                    CefRefPtr<CefContextMenuParams> params,
90                                    CefRefPtr<CefMenuModel> model) {}
91 
92   ///
93   // Called to allow custom display of the context menu. |params| provides
94   // information about the context menu state. |model| contains the context menu
95   // model resulting from OnBeforeContextMenu. For custom display return true
96   // and execute |callback| either synchronously or asynchronously with the
97   // selected command ID. For default display return false. Do not keep
98   // references to |params| or |model| outside of this callback.
99   ///
100   /*--cef()--*/
RunContextMenu(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefContextMenuParams> params,CefRefPtr<CefMenuModel> model,CefRefPtr<CefRunContextMenuCallback> callback)101   virtual bool RunContextMenu(CefRefPtr<CefBrowser> browser,
102                               CefRefPtr<CefFrame> frame,
103                               CefRefPtr<CefContextMenuParams> params,
104                               CefRefPtr<CefMenuModel> model,
105                               CefRefPtr<CefRunContextMenuCallback> callback) {
106     return false;
107   }
108 
109   ///
110   // Called to execute a command selected from the context menu. Return true if
111   // the command was handled or false for the default implementation. See
112   // cef_menu_id_t for the command ids that have default implementations. All
113   // user-defined command ids should be between MENU_ID_USER_FIRST and
114   // MENU_ID_USER_LAST. |params| will have the same values as what was passed to
115   // OnBeforeContextMenu(). Do not keep a reference to |params| outside of this
116   // callback.
117   ///
118   /*--cef()--*/
OnContextMenuCommand(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,CefRefPtr<CefContextMenuParams> params,int command_id,EventFlags event_flags)119   virtual bool OnContextMenuCommand(CefRefPtr<CefBrowser> browser,
120                                     CefRefPtr<CefFrame> frame,
121                                     CefRefPtr<CefContextMenuParams> params,
122                                     int command_id,
123                                     EventFlags event_flags) {
124     return false;
125   }
126 
127   ///
128   // Called when the context menu is dismissed irregardless of whether the menu
129   // was empty or a command was selected.
130   ///
131   /*--cef()--*/
OnContextMenuDismissed(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame)132   virtual void OnContextMenuDismissed(CefRefPtr<CefBrowser> browser,
133                                       CefRefPtr<CefFrame> frame) {}
134 };
135 
136 ///
137 // Provides information about the context menu state. The ethods of this class
138 // can only be accessed on browser process the UI thread.
139 ///
140 /*--cef(source=library)--*/
141 class CefContextMenuParams : public virtual CefBaseRefCounted {
142  public:
143   typedef cef_context_menu_type_flags_t TypeFlags;
144   typedef cef_context_menu_media_type_t MediaType;
145   typedef cef_context_menu_media_state_flags_t MediaStateFlags;
146   typedef cef_context_menu_edit_state_flags_t EditStateFlags;
147 
148   ///
149   // Returns the X coordinate of the mouse where the context menu was invoked.
150   // Coords are relative to the associated RenderView's origin.
151   ///
152   /*--cef()--*/
153   virtual int GetXCoord() = 0;
154 
155   ///
156   // Returns the Y coordinate of the mouse where the context menu was invoked.
157   // Coords are relative to the associated RenderView's origin.
158   ///
159   /*--cef()--*/
160   virtual int GetYCoord() = 0;
161 
162   ///
163   // Returns flags representing the type of node that the context menu was
164   // invoked on.
165   ///
166   /*--cef(default_retval=CM_TYPEFLAG_NONE)--*/
167   virtual TypeFlags GetTypeFlags() = 0;
168 
169   ///
170   // Returns the URL of the link, if any, that encloses the node that the
171   // context menu was invoked on.
172   ///
173   /*--cef()--*/
174   virtual CefString GetLinkUrl() = 0;
175 
176   ///
177   // Returns the link URL, if any, to be used ONLY for "copy link address". We
178   // don't validate this field in the frontend process.
179   ///
180   /*--cef()--*/
181   virtual CefString GetUnfilteredLinkUrl() = 0;
182 
183   ///
184   // Returns the source URL, if any, for the element that the context menu was
185   // invoked on. Example of elements with source URLs are img, audio, and video.
186   ///
187   /*--cef()--*/
188   virtual CefString GetSourceUrl() = 0;
189 
190   ///
191   // Returns true if the context menu was invoked on an image which has
192   // non-empty contents.
193   ///
194   /*--cef()--*/
195   virtual bool HasImageContents() = 0;
196 
197   ///
198   // Returns the title text or the alt text if the context menu was invoked on
199   // an image.
200   ///
201   /*--cef()--*/
202   virtual CefString GetTitleText() = 0;
203 
204   ///
205   // Returns the URL of the top level page that the context menu was invoked on.
206   ///
207   /*--cef()--*/
208   virtual CefString GetPageUrl() = 0;
209 
210   ///
211   // Returns the URL of the subframe that the context menu was invoked on.
212   ///
213   /*--cef()--*/
214   virtual CefString GetFrameUrl() = 0;
215 
216   ///
217   // Returns the character encoding of the subframe that the context menu was
218   // invoked on.
219   ///
220   /*--cef()--*/
221   virtual CefString GetFrameCharset() = 0;
222 
223   ///
224   // Returns the type of context node that the context menu was invoked on.
225   ///
226   /*--cef(default_retval=CM_MEDIATYPE_NONE)--*/
227   virtual MediaType GetMediaType() = 0;
228 
229   ///
230   // Returns flags representing the actions supported by the media element, if
231   // any, that the context menu was invoked on.
232   ///
233   /*--cef(default_retval=CM_MEDIAFLAG_NONE)--*/
234   virtual MediaStateFlags GetMediaStateFlags() = 0;
235 
236   ///
237   // Returns the text of the selection, if any, that the context menu was
238   // invoked on.
239   ///
240   /*--cef()--*/
241   virtual CefString GetSelectionText() = 0;
242 
243   ///
244   // Returns the text of the misspelled word, if any, that the context menu was
245   // invoked on.
246   ///
247   /*--cef()--*/
248   virtual CefString GetMisspelledWord() = 0;
249 
250   ///
251   // Returns true if suggestions exist, false otherwise. Fills in |suggestions|
252   // from the spell check service for the misspelled word if there is one.
253   ///
254   /*--cef()--*/
255   virtual bool GetDictionarySuggestions(
256       std::vector<CefString>& suggestions) = 0;
257 
258   ///
259   // Returns true if the context menu was invoked on an editable node.
260   ///
261   /*--cef()--*/
262   virtual bool IsEditable() = 0;
263 
264   ///
265   // Returns true if the context menu was invoked on an editable node where
266   // spell-check is enabled.
267   ///
268   /*--cef()--*/
269   virtual bool IsSpellCheckEnabled() = 0;
270 
271   ///
272   // Returns flags representing the actions supported by the editable node, if
273   // any, that the context menu was invoked on.
274   ///
275   /*--cef(default_retval=CM_EDITFLAG_NONE)--*/
276   virtual EditStateFlags GetEditStateFlags() = 0;
277 
278   ///
279   // Returns true if the context menu contains items specified by the renderer
280   // process (for example, plugin placeholder or pepper plugin menu items).
281   ///
282   /*--cef()--*/
283   virtual bool IsCustomMenu() = 0;
284 };
285 
286 #endif  // CEF_INCLUDE_CEF_CONTEXT_MENU_HANDLER_H_
287