• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
3  * Copyright (C) 2010 Igalia S.L
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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.
25  */
26 
27 #ifndef ContextMenuItem_h
28 #define ContextMenuItem_h
29 
30 #include "PlatformMenuDescription.h"
31 #include "PlatformString.h"
32 #include <wtf/OwnPtr.h>
33 
34 #if PLATFORM(MAC)
35 #include <wtf/RetainPtr.h>
36 
37 #ifdef __OBJC__
38 @class NSMenuItem;
39 #else
40 class NSMenuItem;
41 #endif
42 #elif PLATFORM(WIN)
43 typedef struct tagMENUITEMINFOW MENUITEMINFO;
44 #elif PLATFORM(GTK)
45 typedef struct _GtkMenuItem GtkMenuItem;
46 #elif PLATFORM(QT)
47 #include <QAction>
48 #elif PLATFORM(WX)
49 class wxMenuItem;
50 #elif PLATFORM(HAIKU)
51 class BMenuItem;
52 #endif
53 
54 namespace WebCore {
55 
56     class ContextMenu;
57 
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,
70 #endif
71         ContextMenuItemTagOpenFrameInNewWindow,
72         ContextMenuItemTagCopy,
73         ContextMenuItemTagGoBack,
74         ContextMenuItemTagGoForward,
75         ContextMenuItemTagStop,
76         ContextMenuItemTagReload,
77         ContextMenuItemTagCut,
78         ContextMenuItemTagPaste,
79 #if PLATFORM(GTK)
80         ContextMenuItemTagDelete,
81 #endif
82 #if PLATFORM(GTK) || PLATFORM(QT)
83         ContextMenuItemTagSelectAll,
84 #endif
85 #if PLATFORM(GTK)
86         ContextMenuItemTagInputMethods,
87         ContextMenuItemTagUnicode,
88 #endif
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,
134 #endif
135         ContextMenuItemTagTextDirectionMenu, // Text Direction sub-menu
136         ContextMenuItemTagTextDirectionDefault,
137         ContextMenuItemTagTextDirectionLeftToRight,
138         ContextMenuItemTagTextDirectionRightToLeft,
139 #if PLATFORM(MAC)
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,
153 #endif
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
165     };
166 
167     enum ContextMenuItemType {
168         ActionType,
169         CheckableActionType,
170         SeparatorType,
171         SubmenuType
172     };
173 
174 #if PLATFORM(MAC)
175     typedef NSMenuItem* PlatformMenuItemDescription;
176 #elif PLATFORM(QT)
177     struct PlatformMenuItemDescription {
PlatformMenuItemDescriptionPlatformMenuItemDescription178         PlatformMenuItemDescription()
179             : type(ActionType),
180               action(ContextMenuItemTagNoAction),
181               checked(false),
182               enabled(true)
183         {}
184 
185         ContextMenuItemType type;
186         ContextMenuAction action;
187         String title;
188         QList<ContextMenuItem> subMenuItems;
189         bool checked;
190         bool enabled;
191     };
192 #elif PLATFORM(GTK)
193     typedef GtkMenuItem* PlatformMenuItemDescription;
194 #elif PLATFORM(WX)
195     struct PlatformMenuItemDescription {
PlatformMenuItemDescriptionPlatformMenuItemDescription196         PlatformMenuItemDescription()
197             : type(ActionType),
198               action(ContextMenuItemTagNoAction),
199               checked(false),
200               enabled(true)
201         {}
202 
203         ContextMenuItemType type;
204         ContextMenuAction action;
205         String title;
206         wxMenu * subMenu;
207         bool checked;
208         bool enabled;
209     };
210 #elif PLATFORM(HAIKU)
211     typedef BMenuItem* PlatformMenuItemDescription;
212 #elif PLATFORM(CHROMIUM)
213     struct PlatformMenuItemDescription {
PlatformMenuItemDescriptionPlatformMenuItemDescription214         PlatformMenuItemDescription()
215             : type(ActionType)
216             , action(ContextMenuItemTagNoAction)
217             , checked(false)
218             , enabled(true) { }
219         ContextMenuItemType type;
220         ContextMenuAction action;
221         String title;
222         bool checked;
223         bool enabled;
224     };
225 #else
226     typedef void* PlatformMenuItemDescription;
227 #endif
228 
229     class ContextMenuItem {
230         WTF_MAKE_FAST_ALLOCATED;
231     public:
232         ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, ContextMenu* subMenu = 0);
233         ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool enabled, bool checked);
234 
235         ~ContextMenuItem();
236 
237         void setType(ContextMenuItemType);
238         ContextMenuItemType type() const;
239 
240         void setAction(ContextMenuAction);
241         ContextMenuAction action() const;
242 
243         void setChecked(bool = true);
244         bool checked() const;
245 
246         void setEnabled(bool = true);
247         bool enabled() const;
248 
249         void setSubMenu(ContextMenu*);
250 
251 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
252 #if PLATFORM(WIN)
253         typedef MENUITEMINFO NativeItem;
254 #elif PLATFORM(EFL)
255         typedef void* NativeItem;
256 #endif
257         ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, const Vector<ContextMenuItem>& subMenuItems);
258         explicit ContextMenuItem(const NativeItem&);
259 
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;
263 
setTitle(const String & title)264         void setTitle(const String& title) { m_title = title; }
title()265         const String& title() const { return m_title; }
266 
subMenuItems()267         const Vector<ContextMenuItem>& subMenuItems() const { return m_subMenuItems; }
268 #else
269     public:
270         ContextMenuItem(PlatformMenuItemDescription);
271         ContextMenuItem(ContextMenu* subMenu = 0);
272         ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, Vector<ContextMenuItem>& submenuItems);
273 
274         PlatformMenuItemDescription releasePlatformDescription();
275 
276         String title() const;
277         void setTitle(const String&);
278 
279         PlatformMenuDescription platformSubMenu() const;
280         void setSubMenu(Vector<ContextMenuItem>&);
281 
282 #endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
283     private:
284 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
285         String m_title;
286         bool m_enabled;
287         bool m_checked;
288         ContextMenuAction m_action;
289         ContextMenuItemType m_type;
290         Vector<ContextMenuItem> m_subMenuItems;
291 #else
292 #if PLATFORM(MAC)
293         RetainPtr<NSMenuItem> m_platformDescription;
294 #else
295         PlatformMenuItemDescription m_platformDescription;
296 #endif
297 #endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
298     };
299 
300 }
301 
302 #endif // ContextMenuItem_h
303