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 #elif PLATFORM(HAIKU) 50 class BMenuItem; 51 #endif 52 53 namespace WebCore { 54 55 class ContextMenu; 56 57 // This enum needs to be in sync with the WebMenuItemTag enum in WebUIDelegate.h and the 58 // extra values in WebUIDelegatePrivate.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 #if PLATFORM(GTK) 76 ContextMenuItemTagDelete, 77 ContextMenuItemTagSelectAll, 78 ContextMenuItemTagInputMethods, 79 ContextMenuItemTagUnicode, 80 #endif 81 ContextMenuItemTagSpellingGuess, 82 ContextMenuItemTagNoGuessesFound, 83 ContextMenuItemTagIgnoreSpelling, 84 ContextMenuItemTagLearnSpelling, 85 ContextMenuItemTagOther, 86 ContextMenuItemTagSearchInSpotlight, 87 ContextMenuItemTagSearchWeb, 88 ContextMenuItemTagLookUpInDictionary, 89 ContextMenuItemTagOpenWithDefaultApplication, 90 ContextMenuItemPDFActualSize, 91 ContextMenuItemPDFZoomIn, 92 ContextMenuItemPDFZoomOut, 93 ContextMenuItemPDFAutoSize, 94 ContextMenuItemPDFSinglePage, 95 ContextMenuItemPDFFacingPages, 96 ContextMenuItemPDFContinuous, 97 ContextMenuItemPDFNextPage, 98 ContextMenuItemPDFPreviousPage, 99 // These are new tags! Not a part of API!!!! 100 ContextMenuItemTagOpenLink = 2000, 101 ContextMenuItemTagIgnoreGrammar, 102 ContextMenuItemTagSpellingMenu, // Spelling or Spelling/Grammar sub-menu 103 ContextMenuItemTagShowSpellingPanel, 104 ContextMenuItemTagCheckSpelling, 105 ContextMenuItemTagCheckSpellingWhileTyping, 106 ContextMenuItemTagCheckGrammarWithSpelling, 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 ContextMenuItemTagPDFSinglePageScrolling, 123 ContextMenuItemTagPDFFacingPagesScrolling, 124 #if ENABLE(INSPECTOR) 125 ContextMenuItemTagInspectElement, 126 #endif 127 ContextMenuItemTagTextDirectionMenu, // Text Direction sub-menu 128 ContextMenuItemTagTextDirectionDefault, 129 ContextMenuItemTagTextDirectionLeftToRight, 130 ContextMenuItemTagTextDirectionRightToLeft, 131 #if PLATFORM(MAC) 132 ContextMenuItemTagCorrectSpellingAutomatically, 133 ContextMenuItemTagSubstitutionsMenu, 134 ContextMenuItemTagShowSubstitutions, 135 ContextMenuItemTagSmartCopyPaste, 136 ContextMenuItemTagSmartQuotes, 137 ContextMenuItemTagSmartDashes, 138 ContextMenuItemTagSmartLinks, 139 ContextMenuItemTagTextReplacement, 140 ContextMenuItemTagTransformationsMenu, 141 ContextMenuItemTagMakeUpperCase, 142 ContextMenuItemTagMakeLowerCase, 143 ContextMenuItemTagCapitalize, 144 ContextMenuItemTagChangeBack, 145 #endif 146 ContextMenuItemBaseCustomTag = 5000, 147 ContextMenuItemBaseApplicationTag = 10000 148 }; 149 150 enum ContextMenuItemType { 151 ActionType, 152 CheckableActionType, 153 SeparatorType, 154 SubmenuType 155 }; 156 157 #if PLATFORM(MAC) 158 typedef NSMenuItem* PlatformMenuItemDescription; 159 #elif PLATFORM(WIN) 160 typedef LPMENUITEMINFO PlatformMenuItemDescription; 161 #elif PLATFORM(QT) 162 struct PlatformMenuItemDescription { PlatformMenuItemDescriptionPlatformMenuItemDescription163 PlatformMenuItemDescription() 164 : type(ActionType), 165 action(ContextMenuItemTagNoAction), 166 checked(false), 167 enabled(true) 168 {} 169 170 ContextMenuItemType type; 171 ContextMenuAction action; 172 String title; 173 QList<ContextMenuItem> subMenuItems; 174 bool checked; 175 bool enabled; 176 }; 177 #elif PLATFORM(GTK) 178 struct PlatformMenuItemDescription { PlatformMenuItemDescriptionPlatformMenuItemDescription179 PlatformMenuItemDescription() 180 : type(ActionType) 181 , action(ContextMenuItemTagNoAction) 182 , subMenu(0) 183 , checked(false) 184 , enabled(true) 185 {} 186 187 ContextMenuItemType type; 188 ContextMenuAction action; 189 String title; 190 GtkMenu* subMenu; 191 bool checked; 192 bool enabled; 193 }; 194 #elif defined ANDROID 195 typedef void* PlatformMenuItemDescription; 196 #elif PLATFORM(WX) 197 struct PlatformMenuItemDescription { PlatformMenuItemDescriptionPlatformMenuItemDescription198 PlatformMenuItemDescription() 199 : type(ActionType), 200 action(ContextMenuItemTagNoAction), 201 checked(false), 202 enabled(true) 203 {} 204 205 ContextMenuItemType type; 206 ContextMenuAction action; 207 String title; 208 wxMenu * subMenu; 209 bool checked; 210 bool enabled; 211 }; 212 #elif PLATFORM(HAIKU) 213 typedef BMenuItem* PlatformMenuItemDescription; 214 #elif PLATFORM(CHROMIUM) 215 struct PlatformMenuItemDescription { PlatformMenuItemDescriptionPlatformMenuItemDescription216 PlatformMenuItemDescription() 217 : type(ActionType) 218 , action(ContextMenuItemTagNoAction) 219 , checked(false) 220 , enabled(true) { } 221 ContextMenuItemType type; 222 ContextMenuAction action; 223 String title; 224 bool checked; 225 bool enabled; 226 }; 227 #else 228 typedef void* PlatformMenuItemDescription; 229 #endif 230 231 class ContextMenuItem : public FastAllocBase { 232 public: 233 ContextMenuItem(PlatformMenuItemDescription); 234 ContextMenuItem(ContextMenu* subMenu = 0); 235 ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu = 0); 236 #if PLATFORM(GTK) 237 ContextMenuItem(GtkMenuItem*); 238 #endif 239 ~ContextMenuItem(); 240 241 PlatformMenuItemDescription releasePlatformDescription(); 242 243 ContextMenuItemType type() const; 244 void setType(ContextMenuItemType); 245 246 ContextMenuAction action() const; 247 void setAction(ContextMenuAction); 248 249 String title() const; 250 void setTitle(const String&); 251 252 PlatformMenuDescription platformSubMenu() const; 253 void setSubMenu(ContextMenu*); 254 255 void setChecked(bool = true); 256 bool checked() const; 257 258 void setEnabled(bool = true); 259 bool enabled() const; 260 261 // FIXME: Do we need a keyboard accelerator here? 262 #if PLATFORM(GTK) 263 static GtkMenuItem* createNativeMenuItem(const PlatformMenuItemDescription&); 264 #endif 265 266 private: 267 #if PLATFORM(MAC) 268 RetainPtr<NSMenuItem> m_platformDescription; 269 #else 270 PlatformMenuItemDescription m_platformDescription; 271 #endif 272 }; 273 274 } 275 276 #endif // ContextMenuItem_h 277