2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2010 Igalia S.L
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef ContextMenuItem_h
28 #define ContextMenuItem_h
30 #include "PlatformMenuDescription.h"
31 #include "PlatformString.h"
32 #include <wtf/OwnPtr.h>
35 #include <wtf/RetainPtr.h>
43 typedef struct tagMENUITEMINFOW MENUITEMINFO;
45 typedef struct _GtkMenuItem GtkMenuItem;
46 typedef struct _GtkAction GtkAction;
59 // This enum needs to be in sync with the WebMenuItemTag enum in WebUIDelegate.h and the
60 // extra values in WebUIDelegatePrivate.h
61 enum ContextMenuAction {
62 ContextMenuItemTagNoAction=0, // This item is not actually in WebUIDelegate.h
63 ContextMenuItemTagOpenLinkInNewWindow=1,
64 ContextMenuItemTagDownloadLinkToDisk,
65 ContextMenuItemTagCopyLinkToClipboard,
66 ContextMenuItemTagOpenImageInNewWindow,
67 ContextMenuItemTagDownloadImageToDisk,
68 ContextMenuItemTagCopyImageToClipboard,
69 #if PLATFORM(QT) || PLATFORM(GTK)
70 ContextMenuItemTagCopyImageUrlToClipboard,
72 ContextMenuItemTagOpenFrameInNewWindow,
73 ContextMenuItemTagCopy,
74 ContextMenuItemTagGoBack,
75 ContextMenuItemTagGoForward,
76 ContextMenuItemTagStop,
77 ContextMenuItemTagReload,
78 ContextMenuItemTagCut,
79 ContextMenuItemTagPaste,
81 ContextMenuItemTagDelete,
83 #if PLATFORM(GTK) || PLATFORM(QT)
84 ContextMenuItemTagSelectAll,
87 ContextMenuItemTagInputMethods,
88 ContextMenuItemTagUnicode,
90 ContextMenuItemTagSpellingGuess,
91 ContextMenuItemTagNoGuessesFound,
92 ContextMenuItemTagIgnoreSpelling,
93 ContextMenuItemTagLearnSpelling,
94 ContextMenuItemTagOther,
95 ContextMenuItemTagSearchInSpotlight,
96 ContextMenuItemTagSearchWeb,
97 ContextMenuItemTagLookUpInDictionary,
98 ContextMenuItemTagOpenWithDefaultApplication,
99 ContextMenuItemPDFActualSize,
100 ContextMenuItemPDFZoomIn,
101 ContextMenuItemPDFZoomOut,
102 ContextMenuItemPDFAutoSize,
103 ContextMenuItemPDFSinglePage,
104 ContextMenuItemPDFFacingPages,
105 ContextMenuItemPDFContinuous,
106 ContextMenuItemPDFNextPage,
107 ContextMenuItemPDFPreviousPage,
108 // These are new tags! Not a part of API!!!!
109 ContextMenuItemTagOpenLink = 2000,
110 ContextMenuItemTagIgnoreGrammar,
111 ContextMenuItemTagSpellingMenu, // Spelling or Spelling/Grammar sub-menu
112 ContextMenuItemTagShowSpellingPanel,
113 ContextMenuItemTagCheckSpelling,
114 ContextMenuItemTagCheckSpellingWhileTyping,
115 ContextMenuItemTagCheckGrammarWithSpelling,
116 ContextMenuItemTagFontMenu, // Font sub-menu
117 ContextMenuItemTagShowFonts,
118 ContextMenuItemTagBold,
119 ContextMenuItemTagItalic,
120 ContextMenuItemTagUnderline,
121 ContextMenuItemTagOutline,
122 ContextMenuItemTagStyles,
123 ContextMenuItemTagShowColors,
124 ContextMenuItemTagSpeechMenu, // Speech sub-menu
125 ContextMenuItemTagStartSpeaking,
126 ContextMenuItemTagStopSpeaking,
127 ContextMenuItemTagWritingDirectionMenu, // Writing Direction sub-menu
128 ContextMenuItemTagDefaultDirection,
129 ContextMenuItemTagLeftToRight,
130 ContextMenuItemTagRightToLeft,
131 ContextMenuItemTagPDFSinglePageScrolling,
132 ContextMenuItemTagPDFFacingPagesScrolling,
133 #if ENABLE(INSPECTOR)
134 ContextMenuItemTagInspectElement,
136 ContextMenuItemTagTextDirectionMenu, // Text Direction sub-menu
137 ContextMenuItemTagTextDirectionDefault,
138 ContextMenuItemTagTextDirectionLeftToRight,
139 ContextMenuItemTagTextDirectionRightToLeft,
141 ContextMenuItemTagCorrectSpellingAutomatically,
142 ContextMenuItemTagSubstitutionsMenu,
143 ContextMenuItemTagShowSubstitutions,
144 ContextMenuItemTagSmartCopyPaste,
145 ContextMenuItemTagSmartQuotes,
146 ContextMenuItemTagSmartDashes,
147 ContextMenuItemTagSmartLinks,
148 ContextMenuItemTagTextReplacement,
149 ContextMenuItemTagTransformationsMenu,
150 ContextMenuItemTagMakeUpperCase,
151 ContextMenuItemTagMakeLowerCase,
152 ContextMenuItemTagCapitalize,
153 ContextMenuItemTagChangeBack,
155 ContextMenuItemTagOpenMediaInNewWindow,
156 ContextMenuItemTagCopyMediaLinkToClipboard,
157 ContextMenuItemTagToggleMediaControls,
158 ContextMenuItemTagToggleMediaLoop,
159 ContextMenuItemTagEnterVideoFullscreen,
160 ContextMenuItemTagMediaPlayPause,
161 ContextMenuItemTagMediaMute,
162 ContextMenuItemBaseCustomTag = 5000,
163 ContextMenuItemCustomTagNoAction = 5998,
164 ContextMenuItemLastCustomTag = 5999,
165 ContextMenuItemBaseApplicationTag = 10000
168 enum ContextMenuItemType {
176 typedef NSMenuItem* PlatformMenuItemDescription;
178 struct PlatformMenuItemDescription {
179 PlatformMenuItemDescription()
181 action(ContextMenuItemTagNoAction),
186 ContextMenuItemType type;
187 ContextMenuAction action;
189 QList<ContextMenuItem> subMenuItems;
194 typedef GtkMenuItem* PlatformMenuItemDescription;
196 struct PlatformMenuItemDescription {
197 PlatformMenuItemDescription()
199 action(ContextMenuItemTagNoAction),
204 ContextMenuItemType type;
205 ContextMenuAction action;
211 #elif PLATFORM(HAIKU)
212 typedef BMenuItem* PlatformMenuItemDescription;
213 #elif PLATFORM(CHROMIUM)
214 struct PlatformMenuItemDescription {
215 PlatformMenuItemDescription()
217 , action(ContextMenuItemTagNoAction)
220 ContextMenuItemType type;
221 ContextMenuAction action;
227 typedef void* PlatformMenuItemDescription;
230 class ContextMenuItem {
231 WTF_MAKE_FAST_ALLOCATED;
233 ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, ContextMenu* subMenu = 0);
234 ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool enabled, bool checked);
238 void setType(ContextMenuItemType);
239 ContextMenuItemType type() const;
241 void setAction(ContextMenuAction);
242 ContextMenuAction action() const;
244 void setChecked(bool = true);
245 bool checked() const;
247 void setEnabled(bool = true);
248 bool enabled() const;
250 void setSubMenu(ContextMenu*);
253 GtkAction* gtkAction() const;
256 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
258 typedef MENUITEMINFO NativeItem;
260 typedef void* NativeItem;
262 ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, const Vector<ContextMenuItem>& subMenuItems);
263 explicit ContextMenuItem(const NativeItem&);
265 // On Windows, the title (dwTypeData of the MENUITEMINFO) is not set in this function. Callers can set the title themselves,
266 // and handle the lifetime of the title, if they need it.
267 NativeItem nativeMenuItem() const;
269 void setTitle(const String& title) { m_title = title; }
270 const String& title() const { return m_title; }
272 const Vector<ContextMenuItem>& subMenuItems() const { return m_subMenuItems; }
275 ContextMenuItem(PlatformMenuItemDescription);
276 ContextMenuItem(ContextMenu* subMenu = 0);
277 ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, Vector<ContextMenuItem>& submenuItems);
279 PlatformMenuItemDescription releasePlatformDescription();
281 String title() const;
282 void setTitle(const String&);
284 PlatformMenuDescription platformSubMenu() const;
285 void setSubMenu(Vector<ContextMenuItem>&);
287 #endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
289 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
290 ContextMenuItemType m_type;
291 ContextMenuAction m_action;
295 Vector<ContextMenuItem> m_subMenuItems;
298 RetainPtr<NSMenuItem> m_platformDescription;
300 PlatformMenuItemDescription m_platformDescription;
302 #endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
307 #endif // ContextMenuItem_h