2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "ContextMenu.h"
29 #include "ContextMenuController.h"
32 #include "FrameLoader.h"
36 #include "SelectionController.h"
40 #define MENU_ACTION_ITEM(action, title) static ContextMenuItem action##Item(ActionType, WebMenuItemTag##action, String(title))
42 void ContextMenu::populate()
44 MENU_ACTION_ITEM(OpenLinkInNewWindow, "Open Link in New Window");
45 MENU_ACTION_ITEM(DownloadLinkToDisk, "Download Linked File");
46 MENU_ACTION_ITEM(CopyLinkToClipboard, "Copy Link");
47 MENU_ACTION_ITEM(OpenImageInNewWindow, "Open Image in New Window");
48 MENU_ACTION_ITEM(DownloadImageToDisk, "Download Image");
49 MENU_ACTION_ITEM(CopyImageToClipboard, "Copy Image");
50 MENU_ACTION_ITEM(OpenFrameInNewWindow, "Open Frame in New Window");
51 MENU_ACTION_ITEM(Copy, "Copy");
52 MENU_ACTION_ITEM(GoBack, "Back");
53 MENU_ACTION_ITEM(GoForward, "Forward");
54 MENU_ACTION_ITEM(Stop, "Stop");
55 MENU_ACTION_ITEM(Reload, "Reload");
56 MENU_ACTION_ITEM(Cut, "Cut");
57 MENU_ACTION_ITEM(Paste, "Paste");
58 MENU_ACTION_ITEM(SpellingGuess, "");
59 MENU_ACTION_ITEM(NoGuessesFound, "No Guesses Found");
60 MENU_ACTION_ITEM(IgnoreSpelling, "Ignore Spelling");
61 MENU_ACTION_ITEM(LearnSpelling, "Learn Spelling");
63 MENU_ACTION_ITEM(SearchInSpotlight, "Search in Spotlight");
65 MENU_ACTION_ITEM(SearchWeb, "Search in Google");
66 MENU_ACTION_ITEM(LookUpInDictionary, "Look Up in Dictionary");
67 // FIXME: Add PDF action items
69 ContextMenuItem SeparatorItem(SeparatorType, WebMenuItemTagNoAction, String());
70 HitTestResult result = hitTestResult();
72 if (!result.isContentEditable()) {
73 KURL linkURL = result.absoluteLinkURL();
74 if (!linkURL.isEmpty()) {
75 if (true) { // FIXME: if FrameLoaderClient can handle the request
76 appendItem(OpenLinkInNewWindowItem);
77 appendItem(DownloadLinkToDiskItem);
79 appendItem(CopyLinkToClipboardItem);
82 KURL imageURL = result.absoluteImageURL();
83 if (!imageURL.isEmpty()) {
84 if (!linkURL.isEmpty())
85 appendItem(SeparatorItem);
87 appendItem(OpenImageInNewWindowItem);
88 appendItem(DownloadImageToDiskItem);
89 if (imageURL.isLocalFile())
90 appendItem(CopyImageToClipboardItem);
93 if (imageURL.isEmpty() && linkURL.isEmpty()) {
94 if (result.isSelected()) {
96 appendItem(SearchInSpotlightItem);
98 appendItem(SearchWebItem);
99 appendItem(SeparatorItem);
100 appendItem(LookUpInDictionaryItem);
101 appendItem(SeparatorItem);
102 appendItem(CopyItem);
104 FrameLoader* loader = result.innerNonSharedNode()->document()->frame()->loader();
105 if (loader->canGoBackOrForward(-1))
106 appendItem(GoBackItem);
108 if (loader->canGoBackOrForward(1))
109 appendItem(GoForwardItem);
111 if (loader->isLoading())
112 appendItem(StopItem);
114 appendItem(ReloadItem);
116 if (result.innerNonSharedNode()->document()->frame() != result.innerNonSharedNode()->document()->frame()->page()->mainFrame())
117 appendItem(OpenFrameInNewWindowItem);
120 } else { // Make an editing context menu
121 SelectionController* selectionController = result.innerNonSharedNode()->document()->frame()->selectionController();
122 bool inPasswordField = selectionController->isInPasswordField();
124 // Add spelling-related context menu items.
125 if (true) { // FIXME: Should be (selectionController->isSelectionMisspelled() && !inPasswordField)
126 // FIXME: Add spelling guesses here
127 appendItem(NoGuessesFoundItem);
129 appendItem(SeparatorItem);
130 appendItem(IgnoreSpellingItem);
131 appendItem(LearnSpellingItem);
132 appendItem(SeparatorItem);
135 if (result.isSelected() && !inPasswordField) {
137 appendItem(SearchInSpotlightItem);
139 appendItem(SearchWebItem);
140 appendItem(SeparatorItem);
142 appendItem(LookUpInDictionaryItem);
143 appendItem(SeparatorItem);
147 appendItem(CopyItem);
148 appendItem(PasteItem);
149 appendItem(SeparatorItem);
151 // FIXME: Add "Spelling [and Grammar, on Leopard]", "Font", "Speech", "Writing Direction" submenus here.