1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
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
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.
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.
30 // ---------------------------------------------------------------------------
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.
37 #ifndef CEF_INCLUDE_CEF_CONTEXT_MENU_HANDLER_H_
38 #define CEF_INCLUDE_CEF_CONTEXT_MENU_HANDLER_H_
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"
46 class CefContextMenuParams;
49 // Implement this interface to handle context menu events. The methods of this
50 // class will be called on the UI thread.
52 /*--cef(source=client)--*/
53 class CefContextMenuHandler : public virtual CefBase {
55 typedef cef_event_flags_t EventFlags;
58 // Called before a context menu is displayed. |params| provides information
59 // about the context menu state. |model| initially contains the default
60 // context menu. The |model| can be cleared to show no context menu or
61 // modified to show a custom menu. Do not keep references to |params| or
62 // |model| outside of this callback.
65 virtual void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
66 CefRefPtr<CefFrame> frame,
67 CefRefPtr<CefContextMenuParams> params,
68 CefRefPtr<CefMenuModel> model) {}
71 // Called to execute a command selected from the context menu. Return true if
72 // the command was handled or false for the default implementation. See
73 // cef_menu_id_t for the command ids that have default implementations. All
74 // user-defined command ids should be between MENU_ID_USER_FIRST and
75 // MENU_ID_USER_LAST. |params| will have the same values as what was passed to
76 // OnBeforeContextMenu(). Do not keep a reference to |params| outside of this
80 virtual bool OnContextMenuCommand(CefRefPtr<CefBrowser> browser,
81 CefRefPtr<CefFrame> frame,
82 CefRefPtr<CefContextMenuParams> params,
84 EventFlags event_flags) { return false; }
87 // Called when the context menu is dismissed irregardless of whether the menu
88 // was empty or a command was selected.
91 virtual void OnContextMenuDismissed(CefRefPtr<CefBrowser> browser,
92 CefRefPtr<CefFrame> frame) {}
97 // Provides information about the context menu state. The ethods of this class
98 // can only be accessed on browser process the UI thread.
100 /*--cef(source=library)--*/
101 class CefContextMenuParams : public virtual CefBase {
103 typedef cef_context_menu_type_flags_t TypeFlags;
104 typedef cef_context_menu_media_type_t MediaType;
105 typedef cef_context_menu_media_state_flags_t MediaStateFlags;
106 typedef cef_context_menu_edit_state_flags_t EditStateFlags;
109 // Returns the X coordinate of the mouse where the context menu was invoked.
110 // Coords are relative to the associated RenderView's origin.
113 virtual int GetXCoord() =0;
116 // Returns the Y coordinate of the mouse where the context menu was invoked.
117 // Coords are relative to the associated RenderView's origin.
120 virtual int GetYCoord() =0;
123 // Returns flags representing the type of node that the context menu was
126 /*--cef(default_retval=CM_TYPEFLAG_NONE)--*/
127 virtual TypeFlags GetTypeFlags() =0;
130 // Returns the URL of the link, if any, that encloses the node that the
131 // context menu was invoked on.
134 virtual CefString GetLinkUrl() =0;
137 // Returns the link URL, if any, to be used ONLY for "copy link address". We
138 // don't validate this field in the frontend process.
141 virtual CefString GetUnfilteredLinkUrl() =0;
144 // Returns the source URL, if any, for the element that the context menu was
145 // invoked on. Example of elements with source URLs are img, audio, and video.
148 virtual CefString GetSourceUrl() =0;
151 // Returns true if the context menu was invoked on an image which has
152 // non-empty contents.
155 virtual bool HasImageContents() =0;
158 // Returns the URL of the top level page that the context menu was invoked on.
161 virtual CefString GetPageUrl() =0;
164 // Returns the URL of the subframe that the context menu was invoked on.
167 virtual CefString GetFrameUrl() =0;
170 // Returns the character encoding of the subframe that the context menu was
174 virtual CefString GetFrameCharset() =0;
177 // Returns the type of context node that the context menu was invoked on.
179 /*--cef(default_retval=CM_MEDIATYPE_NONE)--*/
180 virtual MediaType GetMediaType() =0;
183 // Returns flags representing the actions supported by the media element, if
184 // any, that the context menu was invoked on.
186 /*--cef(default_retval=CM_MEDIAFLAG_NONE)--*/
187 virtual MediaStateFlags GetMediaStateFlags() =0;
190 // Returns the text of the selection, if any, that the context menu was
194 virtual CefString GetSelectionText() =0;
197 // Returns the text of the misspelled word, if any, that the context menu was
201 virtual CefString GetMisspelledWord() =0;
204 // Returns true if suggestions exist, false otherwise. Fills in |suggestions|
205 // from the spell check service for the misspelled word if there is one.
208 virtual bool GetDictionarySuggestions(std::vector<CefString>& suggestions) =0;
211 // Returns true if the context menu was invoked on an editable node.
214 virtual bool IsEditable() =0;
217 // Returns true if the context menu was invoked on an editable node where
218 // spell-check is enabled.
221 virtual bool IsSpellCheckEnabled() =0;
224 // Returns flags representing the actions supported by the editable node, if
225 // any, that the context menu was invoked on.
227 /*--cef(default_retval=CM_EDITFLAG_NONE)--*/
228 virtual EditStateFlags GetEditStateFlags() =0;
231 #endif // CEF_INCLUDE_CEF_CONTEXT_MENU_HANDLER_H_