initial import
[vuplus_webkit] / Source / WebCore / platform / ContextMenuItem.h
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 typedef struct _GtkAction GtkAction;
47 #elif PLATFORM(QT)
48 #include <QAction>
49 #elif PLATFORM(WX)
50 class wxMenuItem;
51 #elif PLATFORM(HAIKU)
52 class BMenuItem;
53 #endif
54
55 namespace WebCore {
56
57     class ContextMenu;
58
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,
71 #endif
72         ContextMenuItemTagOpenFrameInNewWindow,
73         ContextMenuItemTagCopy,
74         ContextMenuItemTagGoBack,
75         ContextMenuItemTagGoForward,
76         ContextMenuItemTagStop,
77         ContextMenuItemTagReload,
78         ContextMenuItemTagCut,
79         ContextMenuItemTagPaste,
80 #if PLATFORM(GTK)
81         ContextMenuItemTagDelete,
82 #endif
83 #if PLATFORM(GTK) || PLATFORM(QT)
84         ContextMenuItemTagSelectAll,
85 #endif
86 #if PLATFORM(GTK)
87         ContextMenuItemTagInputMethods,
88         ContextMenuItemTagUnicode,
89 #endif
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,
135 #endif
136         ContextMenuItemTagTextDirectionMenu, // Text Direction sub-menu
137         ContextMenuItemTagTextDirectionDefault,
138         ContextMenuItemTagTextDirectionLeftToRight,
139         ContextMenuItemTagTextDirectionRightToLeft,
140 #if PLATFORM(MAC)
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,
154 #endif
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
166     };
167
168     enum ContextMenuItemType {
169         ActionType,
170         CheckableActionType,
171         SeparatorType,
172         SubmenuType
173     };
174
175 #if PLATFORM(MAC)
176     typedef NSMenuItem* PlatformMenuItemDescription;
177 #elif PLATFORM(QT)
178     struct PlatformMenuItemDescription {
179         PlatformMenuItemDescription()
180             : type(ActionType),
181               action(ContextMenuItemTagNoAction),
182               checked(false),
183               enabled(true)
184         {}
185
186         ContextMenuItemType type;
187         ContextMenuAction action;
188         String title;
189         QList<ContextMenuItem> subMenuItems;
190         bool checked;
191         bool enabled;
192     };
193 #elif PLATFORM(GTK)
194     typedef GtkMenuItem* PlatformMenuItemDescription;
195 #elif PLATFORM(WX)
196     struct PlatformMenuItemDescription {
197         PlatformMenuItemDescription()
198             : type(ActionType),
199               action(ContextMenuItemTagNoAction),
200               checked(false),
201               enabled(true)
202         {}
203
204         ContextMenuItemType type;
205         ContextMenuAction action;
206         String title;
207         wxMenu * subMenu;
208         bool checked;
209         bool enabled;
210     };
211 #elif PLATFORM(HAIKU)
212     typedef BMenuItem* PlatformMenuItemDescription;
213 #elif PLATFORM(CHROMIUM)
214     struct PlatformMenuItemDescription {
215         PlatformMenuItemDescription()
216             : type(ActionType)
217             , action(ContextMenuItemTagNoAction)
218             , checked(false)
219             , enabled(true) { }
220         ContextMenuItemType type;
221         ContextMenuAction action;
222         String title;
223         bool checked;
224         bool enabled;
225     };
226 #else
227     typedef void* PlatformMenuItemDescription;
228 #endif
229
230     class ContextMenuItem {
231         WTF_MAKE_FAST_ALLOCATED;
232     public:
233         ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, ContextMenu* subMenu = 0);
234         ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool enabled, bool checked);
235
236         ~ContextMenuItem();
237
238         void setType(ContextMenuItemType);
239         ContextMenuItemType type() const;
240
241         void setAction(ContextMenuAction);
242         ContextMenuAction action() const;
243
244         void setChecked(bool = true);
245         bool checked() const;
246
247         void setEnabled(bool = true);
248         bool enabled() const;
249
250         void setSubMenu(ContextMenu*);
251
252 #if PLATFORM(GTK)
253         GtkAction* gtkAction() const;
254 #endif
255
256 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
257 #if PLATFORM(WIN)
258         typedef MENUITEMINFO NativeItem;
259 #elif PLATFORM(EFL)
260         typedef void* NativeItem;
261 #endif
262         ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, const Vector<ContextMenuItem>& subMenuItems);
263         explicit ContextMenuItem(const NativeItem&);
264
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;
268
269         void setTitle(const String& title) { m_title = title; }
270         const String& title() const { return m_title; }
271
272         const Vector<ContextMenuItem>& subMenuItems() const { return m_subMenuItems; }
273 #else
274     public:
275         ContextMenuItem(PlatformMenuItemDescription);
276         ContextMenuItem(ContextMenu* subMenu = 0);
277         ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, Vector<ContextMenuItem>& submenuItems);
278
279         PlatformMenuItemDescription releasePlatformDescription();
280
281         String title() const;
282         void setTitle(const String&);
283
284         PlatformMenuDescription platformSubMenu() const;
285         void setSubMenu(Vector<ContextMenuItem>&);
286
287 #endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
288     private:
289 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
290         ContextMenuItemType m_type;
291         ContextMenuAction m_action;
292         String m_title;
293         bool m_enabled;
294         bool m_checked;
295         Vector<ContextMenuItem> m_subMenuItems;
296 #else
297 #if PLATFORM(MAC)
298         RetainPtr<NSMenuItem> m_platformDescription;
299 #else
300         PlatformMenuItemDescription m_platformDescription;
301 #endif
302 #endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
303     };
304
305 }
306
307 #endif // ContextMenuItem_h