• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef ContextMenuItem_h
27 #define ContextMenuItem_h
28 
29 #include "PlatformMenuDescription.h"
30 #include "PlatformString.h"
31 #include <wtf/OwnPtr.h>
32 
33 #if PLATFORM(MAC)
34 #include <wtf/RetainPtr.h>
35 
36 #ifdef __OBJC__
37 @class NSMenuItem;
38 #else
39 class NSMenuItem;
40 #endif
41 #elif PLATFORM(WIN)
42 typedef struct tagMENUITEMINFOW* LPMENUITEMINFO;
43 #elif PLATFORM(GTK)
44 typedef struct _GtkMenuItem GtkMenuItem;
45 #elif PLATFORM(QT)
46 #include <QAction>
47 #elif PLATFORM(WX)
48 class wxMenuItem;
49 #endif
50 
51 namespace WebCore {
52 
53     class ContextMenu;
54 
55     // This enum needs to be in sync with the WebMenuItemTag enum in WebUIDelegate.h and the
56     // extra values in WebUIDelegatePrivate.h
57     enum ContextMenuAction {
58         ContextMenuItemTagNoAction=0, // This item is not actually in WebUIDelegate.h
59         ContextMenuItemTagOpenLinkInNewWindow=1,
60         ContextMenuItemTagDownloadLinkToDisk,
61         ContextMenuItemTagCopyLinkToClipboard,
62         ContextMenuItemTagOpenImageInNewWindow,
63         ContextMenuItemTagDownloadImageToDisk,
64         ContextMenuItemTagCopyImageToClipboard,
65         ContextMenuItemTagOpenFrameInNewWindow,
66         ContextMenuItemTagCopy,
67         ContextMenuItemTagGoBack,
68         ContextMenuItemTagGoForward,
69         ContextMenuItemTagStop,
70         ContextMenuItemTagReload,
71         ContextMenuItemTagCut,
72         ContextMenuItemTagPaste,
73 #if PLATFORM(GTK)
74         ContextMenuItemTagDelete,
75         ContextMenuItemTagSelectAll,
76         ContextMenuItemTagInputMethods,
77         ContextMenuItemTagUnicode,
78 #endif
79         ContextMenuItemTagSpellingGuess,
80         ContextMenuItemTagNoGuessesFound,
81         ContextMenuItemTagIgnoreSpelling,
82         ContextMenuItemTagLearnSpelling,
83         ContextMenuItemTagOther,
84         ContextMenuItemTagSearchInSpotlight,
85         ContextMenuItemTagSearchWeb,
86         ContextMenuItemTagLookUpInDictionary,
87         ContextMenuItemTagOpenWithDefaultApplication,
88         ContextMenuItemPDFActualSize,
89         ContextMenuItemPDFZoomIn,
90         ContextMenuItemPDFZoomOut,
91         ContextMenuItemPDFAutoSize,
92         ContextMenuItemPDFSinglePage,
93         ContextMenuItemPDFFacingPages,
94         ContextMenuItemPDFContinuous,
95         ContextMenuItemPDFNextPage,
96         ContextMenuItemPDFPreviousPage,
97         // These are new tags! Not a part of API!!!!
98         ContextMenuItemTagOpenLink = 2000,
99         ContextMenuItemTagIgnoreGrammar,
100         ContextMenuItemTagSpellingMenu, // Spelling or Spelling/Grammar sub-menu
101         ContextMenuItemTagShowSpellingPanel,
102         ContextMenuItemTagCheckSpelling,
103         ContextMenuItemTagCheckSpellingWhileTyping,
104         ContextMenuItemTagCheckGrammarWithSpelling,
105         ContextMenuItemTagFontMenu, // Font sub-menu
106         ContextMenuItemTagShowFonts,
107         ContextMenuItemTagBold,
108         ContextMenuItemTagItalic,
109         ContextMenuItemTagUnderline,
110         ContextMenuItemTagOutline,
111         ContextMenuItemTagStyles,
112         ContextMenuItemTagShowColors,
113         ContextMenuItemTagSpeechMenu, // Speech sub-menu
114         ContextMenuItemTagStartSpeaking,
115         ContextMenuItemTagStopSpeaking,
116         ContextMenuItemTagWritingDirectionMenu, // Writing Direction sub-menu
117         ContextMenuItemTagDefaultDirection,
118         ContextMenuItemTagLeftToRight,
119         ContextMenuItemTagRightToLeft,
120         ContextMenuItemTagPDFSinglePageScrolling,
121         ContextMenuItemTagPDFFacingPagesScrolling,
122         ContextMenuItemTagInspectElement,
123         ContextMenuItemTagTextDirectionMenu, // Text Direction sub-menu
124         ContextMenuItemTagTextDirectionDefault,
125         ContextMenuItemTagTextDirectionLeftToRight,
126         ContextMenuItemTagTextDirectionRightToLeft,
127 #if PLATFORM(MAC)
128         ContextMenuItemTagCorrectSpellingAutomatically,
129         ContextMenuItemTagSubstitutionsMenu,
130         ContextMenuItemTagShowSubstitutions,
131         ContextMenuItemTagSmartCopyPaste,
132         ContextMenuItemTagSmartQuotes,
133         ContextMenuItemTagSmartDashes,
134         ContextMenuItemTagSmartLinks,
135         ContextMenuItemTagTextReplacement,
136         ContextMenuItemTagTransformationsMenu,
137         ContextMenuItemTagMakeUpperCase,
138         ContextMenuItemTagMakeLowerCase,
139         ContextMenuItemTagCapitalize,
140         ContextMenuItemTagChangeBack,
141 #endif
142         ContextMenuItemBaseApplicationTag = 10000
143     };
144 
145     enum ContextMenuItemType {
146         ActionType,
147         CheckableActionType,
148         SeparatorType,
149         SubmenuType
150     };
151 
152 #if PLATFORM(MAC)
153     typedef NSMenuItem* PlatformMenuItemDescription;
154 #elif PLATFORM(WIN)
155     typedef LPMENUITEMINFO PlatformMenuItemDescription;
156 #elif PLATFORM(QT)
157     struct PlatformMenuItemDescription {
PlatformMenuItemDescriptionPlatformMenuItemDescription158         PlatformMenuItemDescription()
159             : type(ActionType),
160               action(ContextMenuItemTagNoAction),
161               checked(false),
162               enabled(true)
163         {}
164 
165         ContextMenuItemType type;
166         ContextMenuAction action;
167         String title;
168         QList<ContextMenuItem> subMenuItems;
169         bool checked;
170         bool enabled;
171     };
172 #elif PLATFORM(GTK)
173     struct PlatformMenuItemDescription {
PlatformMenuItemDescriptionPlatformMenuItemDescription174         PlatformMenuItemDescription()
175             : type(ActionType)
176             , action(ContextMenuItemTagNoAction)
177             , subMenu(0)
178             , checked(false)
179             , enabled(true)
180         {}
181 
182         ContextMenuItemType type;
183         ContextMenuAction action;
184         String title;
185         GtkMenu* subMenu;
186         bool checked;
187         bool enabled;
188     };
189 #elif defined ANDROID
190     typedef void* PlatformMenuItemDescription;
191 #elif PLATFORM(WX)
192     struct PlatformMenuItemDescription {
PlatformMenuItemDescriptionPlatformMenuItemDescription193         PlatformMenuItemDescription()
194             : type(ActionType),
195               action(ContextMenuItemTagNoAction),
196               checked(false),
197               enabled(true)
198         {}
199 
200         ContextMenuItemType type;
201         ContextMenuAction action;
202         String title;
203         wxMenu * subMenu;
204         bool checked;
205         bool enabled;
206     };
207 #else
208     typedef void* PlatformMenuItemDescription;
209 #endif
210 
211     class ContextMenuItem {
212     public:
213         ContextMenuItem(PlatformMenuItemDescription);
214         ContextMenuItem(ContextMenu* subMenu = 0);
215         ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu = 0);
216 #if PLATFORM(GTK)
217         ContextMenuItem(GtkMenuItem*);
218 #endif
219         ~ContextMenuItem();
220 
221         PlatformMenuItemDescription releasePlatformDescription();
222 
223         ContextMenuItemType type() const;
224         void setType(ContextMenuItemType);
225 
226         ContextMenuAction action() const;
227         void setAction(ContextMenuAction);
228 
229         String title() const;
230         void setTitle(const String&);
231 
232         PlatformMenuDescription platformSubMenu() const;
233         void setSubMenu(ContextMenu*);
234 
235         void setChecked(bool = true);
236 
237         void setEnabled(bool = true);
238         bool enabled() const;
239 
240         // FIXME: Do we need a keyboard accelerator here?
241 #if PLATFORM(GTK)
242         static GtkMenuItem* createNativeMenuItem(const PlatformMenuItemDescription&);
243 #endif
244 
245     private:
246 #if PLATFORM(MAC)
247         RetainPtr<NSMenuItem> m_platformDescription;
248 #else
249         PlatformMenuItemDescription m_platformDescription;
250 #endif
251     };
252 
253 }
254 
255 #endif // ContextMenuItem_h
256