2006-12-04 Don Gibson <dgibson77@gmail.com>
[WebKit-https.git] / WebCore / platform / ContextMenuItem.h
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 <wtf/Noncopyable.h>
30
31 #include "PlatformMenuDescription.h"
32 #include "PlatformString.h"
33
34 #if PLATFORM(MAC)
35 #include "RetainPtr.h"
36
37 #ifdef __OBJC__
38 @class NSMenuItem;
39 #else
40 class NSMenuItem;
41 #endif
42 #elif PLATFORM(WIN)
43 typedef struct tagMENUITEMINFOW* LPMENUITEMINFO;
44 #elif PLATFORM(QT)
45 #endif
46
47 namespace WebCore {
48
49     class ContextMenu;
50
51 #if PLATFORM(MAC)
52     typedef NSMenuItem* PlatformMenuItemDescription;
53 #elif PLATFORM(WIN)
54     typedef LPMENUITEMINFO PlatformMenuItemDescription;
55 #elif PLATFORM(QT)
56     typedef void* PlatformMenuItemDescription;
57 #endif
58
59     // This enum needs to be in sync with WebMenuItemTag, which is defined in WebUIDelegate.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         ContextMenuItemTagOpenFrameInNewWindow,
69         ContextMenuItemTagCopy,
70         ContextMenuItemTagGoBack,
71         ContextMenuItemTagGoForward,
72         ContextMenuItemTagStop,
73         ContextMenuItemTagReload,
74         ContextMenuItemTagCut,
75         ContextMenuItemTagPaste,
76         ContextMenuItemTagSpellingGuess,
77         ContextMenuItemTagNoGuessesFound,
78         ContextMenuItemTagIgnoreSpelling,
79         ContextMenuItemTagLearnSpelling,
80         ContextMenuItemTagOther,
81         ContextMenuItemTagSearchInSpotlight,
82         ContextMenuItemTagSearchWeb,
83         ContextMenuItemTagLookUpInDictionary,
84         ContextMenuItemTagOpenWithDefaultApplication,
85         ContextMenuItemPDFActualSize,
86         ContextMenuItemPDFZoomIn,
87         ContextMenuItemPDFZoomOut,
88         ContextMenuItemPDFAutoSize,
89         ContextMenuItemPDFSinglePage,
90         ContextMenuItemPDFFacingPages,
91         ContextMenuItemPDFContinuous,
92         ContextMenuItemPDFNextPage,
93         ContextMenuItemPDFPreviousPage,
94         // These are new tags! Not a part of API!!!!
95         ContextMenuItemTagOpenLink = 1000,
96 #ifndef BUILDING_ON_TIGER
97         ContextMenuItemTagSpellingAndGrammarMenu, // Spelling sub-menu
98         ContextMenuItemTagShowSpellingAndGrammar,
99         ContextMenuItemTagCheckDocumentNow,
100         ContextMenuItemTagCheckSpellingWhileTyping,
101         ContextMenuItemTagCheckGrammarWithSpelling,
102 #else
103         ContextMenuItemTagSpellingMenu, // Tiger Spelling sub-menu
104         ContextMenuItemTagSpellingMenuItem,
105         ContextMenuItemTagCheckSpelling,
106         ContextMenuItemTagCheckSpellingWhileTyping,
107 #endif
108         ContextMenuItemTagFontMenu, // Font sub-menu
109         ContextMenuItemTagShowFonts,
110         ContextMenuItemTagBold,
111         ContextMenuItemTagItalic,
112         ContextMenuItemTagUnderline,
113         ContextMenuItemTagOutline,
114         ContextMenuItemTagStyles,
115         ContextMenuItemTagShowColors,
116         ContextMenuItemTagSpeechMenu, // Speech sub-menu
117         ContextMenuItemTagStartSpeaking,
118         ContextMenuItemTagStopSpeaking,
119         ContextMenuItemTagWritingDirectionMenu, // Writing Direction sub-menu
120         ContextMenuItemTagDefaultDirection,
121         ContextMenuItemTagLeftToRight,
122         ContextMenuItemTagRightToLeft,
123         ContextMenuItemBaseApplicationTag = 10000
124     };
125
126     enum ContextMenuItemType {
127         ActionType,
128         SeparatorType,
129         SubmenuType
130     };
131
132     class ContextMenuItem : Noncopyable {
133     public:
134         ContextMenuItem(PlatformMenuItemDescription, ContextMenu*);
135         ContextMenuItem(ContextMenu* parentMenu = 0, ContextMenu* subMenu = 0);
136         ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* parentMenu = 0, 
137             ContextMenu* subMenu = 0);
138         ~ContextMenuItem();
139
140         ContextMenu* parentMenu() const { return m_parentMenu; }
141         PlatformMenuItemDescription platformDescription() const;
142
143         ContextMenuItemType type() const { return m_type; }
144         void setType(ContextMenuItemType type) { m_type = type; }
145
146         ContextMenuAction action() const;
147         void setAction(ContextMenuAction action);
148
149         String title() const;
150         void setTitle(String title);
151
152         PlatformMenuDescription platformSubMenu() const;
153         void setSubMenu(ContextMenu* subMenu);
154
155         // FIXME: Do we need a keyboard accelerator here?
156
157     private:
158         ContextMenu* m_parentMenu;
159 #if PLATFORM(MAC)
160         RetainPtr<NSMenuItem> m_platformDescription;
161 #else
162         PlatformMenuItemDescription m_platformDescription;
163 #endif
164         ContextMenuItemType m_type;
165     };
166
167 }
168
169 #endif // ContextMenuItem_h