090534c9db50a93f7fc400d9baa2bb4903556a44
[WebKit-https.git] / Source / WebCore / platform / ContextMenuItem.h
1 /*
2  * Copyright (C) 2006 Apple 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 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 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 #if ENABLE(CONTEXT_MENUS)
31
32 #include "PlatformMenuDescription.h"
33 #include <wtf/OwnPtr.h>
34 #include <wtf/text/WTFString.h>
35
36 #if PLATFORM(COCOA)
37 #include <wtf/RetainPtr.h>
38 OBJC_CLASS NSMenuItem;
39 #elif PLATFORM(GTK)
40 typedef struct _GtkMenuItem GtkMenuItem;
41 typedef struct _GtkAction GtkAction;
42 #endif
43 #endif // ENABLE(CONTEXT_MENUS)
44
45 namespace WebCore {
46
47     class ContextMenu;
48
49     // This enum needs to be in sync with the WebMenuItemTag enum in WebUIDelegate.h and the
50     // extra values in WebUIDelegatePrivate.h
51     enum ContextMenuAction {
52         ContextMenuItemTagNoAction=0, // This item is not actually in WebUIDelegate.h
53         ContextMenuItemTagOpenLinkInNewWindow=1,
54         ContextMenuItemTagDownloadLinkToDisk,
55         ContextMenuItemTagCopyLinkToClipboard,
56         ContextMenuItemTagOpenImageInNewWindow,
57         ContextMenuItemTagDownloadImageToDisk,
58         ContextMenuItemTagCopyImageToClipboard,
59 #if PLATFORM(GTK) || PLATFORM(EFL)
60         ContextMenuItemTagCopyImageUrlToClipboard,
61 #endif
62         ContextMenuItemTagOpenFrameInNewWindow,
63         ContextMenuItemTagCopy,
64         ContextMenuItemTagGoBack,
65         ContextMenuItemTagGoForward,
66         ContextMenuItemTagStop,
67         ContextMenuItemTagReload,
68         ContextMenuItemTagCut,
69         ContextMenuItemTagPaste,
70 #if PLATFORM(GTK)
71         ContextMenuItemTagDelete,
72 #endif
73 #if PLATFORM(GTK) || PLATFORM (EFL)
74         ContextMenuItemTagSelectAll,
75 #endif
76 #if PLATFORM(GTK)
77         ContextMenuItemTagInputMethods,
78         ContextMenuItemTagUnicode,
79         ContextMenuItemTagUnicodeInsertLRMMark,
80         ContextMenuItemTagUnicodeInsertRLMMark,
81         ContextMenuItemTagUnicodeInsertLREMark,
82         ContextMenuItemTagUnicodeInsertRLEMark,
83         ContextMenuItemTagUnicodeInsertLROMark,
84         ContextMenuItemTagUnicodeInsertRLOMark,
85         ContextMenuItemTagUnicodeInsertPDFMark,
86         ContextMenuItemTagUnicodeInsertZWSMark,
87         ContextMenuItemTagUnicodeInsertZWJMark,
88         ContextMenuItemTagUnicodeInsertZWNJMark,
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         ContextMenuItemTagInspectElement,
134         ContextMenuItemTagTextDirectionMenu, // Text Direction sub-menu
135         ContextMenuItemTagTextDirectionDefault,
136         ContextMenuItemTagTextDirectionLeftToRight,
137         ContextMenuItemTagTextDirectionRightToLeft,
138 #if PLATFORM(COCOA)
139         ContextMenuItemTagCorrectSpellingAutomatically,
140         ContextMenuItemTagSubstitutionsMenu,
141         ContextMenuItemTagShowSubstitutions,
142         ContextMenuItemTagSmartCopyPaste,
143         ContextMenuItemTagSmartQuotes,
144         ContextMenuItemTagSmartDashes,
145         ContextMenuItemTagSmartLinks,
146         ContextMenuItemTagTextReplacement,
147         ContextMenuItemTagTransformationsMenu,
148         ContextMenuItemTagMakeUpperCase,
149         ContextMenuItemTagMakeLowerCase,
150         ContextMenuItemTagCapitalize,
151         ContextMenuItemTagChangeBack,
152 #endif
153         ContextMenuItemTagOpenMediaInNewWindow,
154         ContextMenuItemTagDownloadMediaToDisk,
155         ContextMenuItemTagCopyMediaLinkToClipboard,
156         ContextMenuItemTagToggleMediaControls,
157         ContextMenuItemTagToggleMediaLoop,
158         ContextMenuItemTagEnterVideoFullscreen,
159         ContextMenuItemTagMediaPlayPause,
160         ContextMenuItemTagMediaMute,
161         ContextMenuItemTagDictationAlternative,
162         ContextMenuItemTagOpenLinkInThisWindow,
163         ContextMenuItemTagToggleVideoFullscreen,
164         ContextMenuItemTagShareMenu, 
165         ContextMenuItemBaseCustomTag = 5000,
166         ContextMenuItemCustomTagNoAction = 5998,
167         ContextMenuItemLastCustomTag = 5999,
168         ContextMenuItemBaseApplicationTag = 10000
169     };
170
171     enum ContextMenuItemType {
172         ActionType,
173         CheckableActionType,
174         SeparatorType,
175         SubmenuType
176     };
177
178 #if ENABLE(CONTEXT_MENUS)
179 #if PLATFORM(COCOA)
180     typedef NSMenuItem* PlatformMenuItemDescription;
181 #elif PLATFORM(GTK)
182     typedef GtkMenuItem* PlatformMenuItemDescription;
183 #else
184     typedef void* PlatformMenuItemDescription;
185 #endif
186
187     class ContextMenuItem {
188         WTF_MAKE_FAST_ALLOCATED;
189     public:
190         WEBCORE_EXPORT ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, ContextMenu* subMenu = 0);
191         WEBCORE_EXPORT ContextMenuItem(ContextMenuItemType, ContextMenuAction, const String&, bool enabled, bool checked);
192
193         WEBCORE_EXPORT ~ContextMenuItem();
194
195         void setType(ContextMenuItemType);
196         WEBCORE_EXPORT ContextMenuItemType type() const;
197
198         void setAction(ContextMenuAction);
199         WEBCORE_EXPORT ContextMenuAction action() const;
200
201         void setChecked(bool = true);
202         WEBCORE_EXPORT bool checked() const;
203
204         void setEnabled(bool = true);
205         WEBCORE_EXPORT bool enabled() const;
206
207         void setSubMenu(ContextMenu*);
208
209         static bool supportsShareMenu();
210         WEBCORE_EXPORT static ContextMenuItem shareSelectedTextMenuItem(const String&);
211
212 #if PLATFORM(GTK)
213         GtkAction* gtkAction() const;
214 #endif
215
216 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
217         ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, const Vector<ContextMenuItem>& subMenuItems);
218         explicit ContextMenuItem(const PlatformContextMenuItem&);
219
220         // On Windows, the title (dwTypeData of the MENUITEMINFO) is not set in this function. Callers can set the title themselves,
221         // and handle the lifetime of the title, if they need it.
222         PlatformContextMenuItem platformContextMenuItem() const;
223
224         void setTitle(const String& title) { m_title = title; }
225         const String& title() const { return m_title; }
226
227         const Vector<ContextMenuItem>& subMenuItems() const { return m_subMenuItems; }
228 #else
229     public:
230         WEBCORE_EXPORT explicit ContextMenuItem(PlatformMenuItemDescription);
231         explicit ContextMenuItem(ContextMenu* subMenu);
232         ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, Vector<ContextMenuItem>& submenuItems);
233         ContextMenuItem();
234
235         bool isNull() const { return !m_platformDescription; }
236
237 #if PLATFORM(GTK)
238         WEBCORE_EXPORT PlatformMenuItemDescription releasePlatformDescription();
239 #endif
240
241         WEBCORE_EXPORT PlatformMenuItemDescription platformDescription() const;
242
243         WEBCORE_EXPORT String title() const;
244         void setTitle(const String&);
245
246         WEBCORE_EXPORT PlatformMenuDescription platformSubMenu() const;
247         void setSubMenu(Vector<ContextMenuItem>&);
248
249 #endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
250     private:
251 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
252         ContextMenuItemType m_type;
253         ContextMenuAction m_action;
254         String m_title;
255         bool m_enabled;
256         bool m_checked;
257         Vector<ContextMenuItem> m_subMenuItems;
258 #else
259 #if PLATFORM(COCOA)
260         RetainPtr<NSMenuItem> m_platformDescription;
261 #else
262         PlatformMenuItemDescription m_platformDescription;
263 #endif
264 #endif // USE(CROSS_PLATFORM_CONTEXT_MENUS)
265     };
266
267 #endif // ENABLE(CONTEXT_MENUS)
268 }
269
270 #endif // ContextMenuItem_h