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;
58 // This enum needs to be in sync with the WebMenuItemTag enum in WebUIDelegate.h and the
59 // extra values in WebUIDelegatePrivate.h
60 enum ContextMenuAction {
61 ContextMenuItemTagNoAction=0, // This item is not actually in WebUIDelegate.h
62 ContextMenuItemTagOpenLinkInNewWindow=1,
63 ContextMenuItemTagDownloadLinkToDisk,
64 ContextMenuItemTagCopyLinkToClipboard,
65 ContextMenuItemTagOpenImageInNewWindow,
66 ContextMenuItemTagDownloadImageToDisk,
67 ContextMenuItemTagCopyImageToClipboard,
68 #if PLATFORM(QT) || PLATFORM(GTK)
69 ContextMenuItemTagCopyImageUrlToClipboard,
71 ContextMenuItemTagOpenFrameInNewWindow,
72 ContextMenuItemTagCopy,
73 ContextMenuItemTagGoBack,
74 ContextMenuItemTagGoForward,
75 ContextMenuItemTagStop,
76 ContextMenuItemTagReload,
77 ContextMenuItemTagCut,
78 ContextMenuItemTagPaste,
80 ContextMenuItemTagDelete,
82 #if PLATFORM(GTK) || PLATFORM(QT)
83 ContextMenuItemTagSelectAll,
86 ContextMenuItemTagInputMethods,
87 ContextMenuItemTagUnicode,
89 ContextMenuItemTagSpellingGuess,
90 ContextMenuItemTagNoGuessesFound,
91 ContextMenuItemTagIgnoreSpelling,
92 ContextMenuItemTagLearnSpelling,
93 ContextMenuItemTagOther,
94 ContextMenuItemTagSearchInSpotlight,
95 ContextMenuItemTagSearchWeb,
96 ContextMenuItemTagLookUpInDictionary,
97 ContextMenuItemTagOpenWithDefaultApplication,
98 ContextMenuItemPDFActualSize,
99 ContextMenuItemPDFZoomIn,
100 ContextMenuItemPDFZoomOut,
101 ContextMenuItemPDFAutoSize,
102 ContextMenuItemPDFSinglePage,
103 ContextMenuItemPDFFacingPages,
104 ContextMenuItemPDFContinuous,
105 ContextMenuItemPDFNextPage,
106 ContextMenuItemPDFPreviousPage,
107 // These are new tags! Not a part of API!!!!
108 ContextMenuItemTagOpenLink = 2000,
109 ContextMenuItemTagIgnoreGrammar,
110 ContextMenuItemTagSpellingMenu, // Spelling or Spelling/Grammar sub-menu
111 ContextMenuItemTagShowSpellingPanel,
112 ContextMenuItemTagCheckSpelling,
113 ContextMenuItemTagCheckSpellingWhileTyping,
114 ContextMenuItemTagCheckGrammarWithSpelling,
115 ContextMenuItemTagFontMenu, // Font sub-menu
116 ContextMenuItemTagShowFonts,
117 ContextMenuItemTagBold,
118 ContextMenuItemTagItalic,
119 ContextMenuItemTagUnderline,
120 ContextMenuItemTagOutline,
121 ContextMenuItemTagStyles,
122 ContextMenuItemTagShowColors,
123 ContextMenuItemTagSpeechMenu, // Speech sub-menu
124 ContextMenuItemTagStartSpeaking,
125 ContextMenuItemTagStopSpeaking,
126 ContextMenuItemTagWritingDirectionMenu, // Writing Direction sub-menu
127 ContextMenuItemTagDefaultDirection,
128 ContextMenuItemTagLeftToRight,
129 ContextMenuItemTagRightToLeft,
130 ContextMenuItemTagPDFSinglePageScrolling,
131 ContextMenuItemTagPDFFacingPagesScrolling,
132 #if ENABLE(INSPECTOR)
133 ContextMenuItemTagInspectElement,
135 ContextMenuItemTagTextDirectionMenu, // Text Direction sub-menu
136 ContextMenuItemTagTextDirectionDefault,
137 ContextMenuItemTagTextDirectionLeftToRight,
138 ContextMenuItemTagTextDirectionRightToLeft,
140 ContextMenuItemTagCorrectSpellingAutomatically,
141 ContextMenuItemTagSubstitutionsMenu,
142 ContextMenuItemTagShowSubstitutions,
143 ContextMenuItemTagSmartCopyPaste,
144 ContextMenuItemTagSmartQuotes,
145 ContextMenuItemTagSmartDashes,
146 ContextMenuItemTagSmartLinks,
147 ContextMenuItemTagTextReplacement,
148 ContextMenuItemTagTransformationsMenu,
149 ContextMenuItemTagMakeUpperCase,
150 ContextMenuItemTagMakeLowerCase,
151 ContextMenuItemTagCapitalize,
152 ContextMenuItemTagChangeBack,
154 ContextMenuItemTagOpenMediaInNewWindow,
155 ContextMenuItemTagCopyMediaLinkToClipboard,
156 ContextMenuItemTagToggleMediaControls,
157 ContextMenuItemTagToggleMediaLoop,
158 ContextMenuItemTagEnterVideoFullscreen,
159 ContextMenuItemTagMediaPlayPause,
160 ContextMenuItemTagMediaMute,
161 ContextMenuItemBaseCustomTag = 5000,
162 ContextMenuItemCustomTagNoAction = 5998,
163 ContextMenuItemLastCustomTag = 5999,
164 ContextMenuItemBaseApplicationTag = 10000
167 enum ContextMenuItemType {
175 typedef NSMenuItem* PlatformMenuItemDescription;
177 struct PlatformMenuItemDescription {
178 PlatformMenuItemDescription()
180 action(ContextMenuItemTagNoAction),
185 ContextMenuItemType type;
186 ContextMenuAction action;
188 QList<ContextMenuItem> subMenuItems;
193 typedef GtkMenuItem* PlatformMenuItemDescription;
195 struct PlatformMenuItemDescription {
196 PlatformMenuItemDescription()
198 action(ContextMenuItemTagNoAction),
203 ContextMenuItemType type;
204 ContextMenuAction action;
210 #elif PLATFORM(HAIKU)
211 typedef BMenuItem* PlatformMenuItemDescription;
212 #elif PLATFORM(CHROMIUM)
213 struct PlatformMenuItemDescription {
214 PlatformMenuItemDescription()
216 , action(ContextMenuItemTagNoAction)
219 ContextMenuItemType type;
220 ContextMenuAction action;
226 typedef void* PlatformMenuItemDescription;
229 class ContextMenuItem {
230 WTF_MAKE_FAST_ALLOCATED;
232 ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, ContextMenu* subMenu = 0);
233 ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool enabled, bool checked);
237 void setType(ContextMenuItemType);
238 ContextMenuItemType type() const;
240 void setAction(ContextMenuAction);
241 ContextMenuAction action() const;
243 void setChecked(bool = true);
244 bool checked() const;
246 void setEnabled(bool = true);
247 bool enabled() const;
249 void setSubMenu(ContextMenu*);
251 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
253 typedef MENUITEMINFO NativeItem;
255 typedef void* NativeItem;
257 ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, const Vector<ContextMenuItem>& subMenuItems);
258 explicit ContextMenuItem(const NativeItem&);
260 // On Windows, the title (dwTypeData of the MENUITEMINFO) is not set in this function. Callers can set the title themselves,
261 // and handle the lifetime of the title, if they need it.
262 NativeItem nativeMenuItem() const;
264 void setTitle(const String& title) { m_title = title; }
265 const String& title() const { return m_title; }
267 const Vector<ContextMenuItem>& subMenuItems() const { return m_subMenuItems; }
270 ContextMenuItem(PlatformMenuItemDescription);
271 ContextMenuItem(ContextMenu* subMenu = 0);
272 ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, Vector<ContextMenuItem>& submenuItems);
274 PlatformMenuItemDescription releasePlatformDescription();
276 String title() const;
277 void setTitle(const String&);
279 PlatformMenuDescription platformSubMenu() const;
280 void setSubMenu(Vector<ContextMenuItem>&);
282 #endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
284 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
288 ContextMenuAction m_action;
289 ContextMenuItemType m_type;
290 Vector<ContextMenuItem> m_subMenuItems;
293 RetainPtr<NSMenuItem> m_platformDescription;
295 PlatformMenuItemDescription m_platformDescription;
297 #endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
302 #endif // ContextMenuItem_h