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