[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 1 | // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 4 | |
| 5 | #include "config.h" |
| 6 | |
[email protected] | fa41969 | 2008-10-16 21:46:14 | [diff] [blame] | 7 | #include "base/compiler_specific.h" |
| 8 | |
| 9 | MSVC_PUSH_WARNING_LEVEL(0); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 10 | #include "ContextMenu.h" |
| 11 | #include "Document.h" |
| 12 | #include "DocumentLoader.h" |
| 13 | #include "Editor.h" |
[email protected] | 985f0e6 | 2008-10-29 01:05:08 | [diff] [blame] | 14 | #include "EventHandler.h" |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 15 | #include "FrameLoader.h" |
| 16 | #include "FrameView.h" |
| 17 | #include "HitTestResult.h" |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 18 | #include "HTMLMediaElement.h" |
| 19 | #include "HTMLNames.h" |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 20 | #include "KURL.h" |
[email protected] | c67b2c0 | 2009-08-20 19:23:36 | [diff] [blame] | 21 | #include "MediaError.h" |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 22 | #include "Widget.h" |
[email protected] | fa41969 | 2008-10-16 21:46:14 | [diff] [blame] | 23 | MSVC_POP_WARNING(); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 24 | #undef LOG |
| 25 | |
| 26 | #include "webkit/glue/context_menu_client_impl.h" |
| 27 | |
| 28 | #include "base/string_util.h" |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 29 | #include "webkit/api/public/WebURL.h" |
| 30 | #include "webkit/api/public/WebURLResponse.h" |
[email protected] | 31f4c7e | 2009-08-27 20:43:29 | [diff] [blame] | 31 | #include "webkit/api/src/WebDataSourceImpl.h" |
[email protected] | e09ba55 | 2009-02-05 03:26:29 | [diff] [blame] | 32 | #include "webkit/glue/context_menu.h" |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 33 | #include "webkit/glue/glue_util.h" |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 34 | #include "webkit/glue/webview_impl.h" |
| 35 | |
| 36 | #include "base/word_iterator.h" |
| 37 | |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 38 | using WebKit::WebDataSource; |
[email protected] | 31f4c7e | 2009-08-27 20:43:29 | [diff] [blame] | 39 | using WebKit::WebDataSourceImpl; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 40 | |
[email protected] | 985f0e6 | 2008-10-29 01:05:08 | [diff] [blame] | 41 | namespace { |
| 42 | |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 43 | // Helper function to determine whether text is a single word or a sentence. |
[email protected] | 985f0e6 | 2008-10-29 01:05:08 | [diff] [blame] | 44 | bool IsASingleWord(const std::wstring& text) { |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 45 | WordIterator iter(text, WordIterator::BREAK_WORD); |
| 46 | int word_count = 0; |
| 47 | if (!iter.Init()) return false; |
| 48 | while (iter.Advance()) { |
| 49 | if (iter.IsWord()) { |
| 50 | word_count++; |
| 51 | if (word_count > 1) // More than one word. |
| 52 | return false; |
| 53 | } |
| 54 | } |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 55 | |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 56 | // Check for 0 words. |
| 57 | if (!word_count) |
| 58 | return false; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 59 | |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 60 | // Has a single word. |
| 61 | return true; |
| 62 | } |
| 63 | |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 64 | // Helper function to get misspelled word on which context menu |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 65 | // is to be evolked. This function also sets the word on which context menu |
[email protected] | 442a3a1 | 2009-04-23 18:14:06 | [diff] [blame] | 66 | // has been evoked to be the selected word, as required. This function changes |
| 67 | // the selection only when there were no selected characters. |
[email protected] | 985f0e6 | 2008-10-29 01:05:08 | [diff] [blame] | 68 | std::wstring GetMisspelledWord(const WebCore::ContextMenu* default_menu, |
| 69 | WebCore::Frame* selected_frame) { |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 70 | std::wstring misspelled_word_string; |
| 71 | |
| 72 | // First select from selectedText to check for multiple word selection. |
| 73 | misspelled_word_string = CollapseWhitespace( |
| 74 | webkit_glue::StringToStdWString(selected_frame->selectedText()), |
| 75 | false); |
| 76 | |
[email protected] | 442a3a1 | 2009-04-23 18:14:06 | [diff] [blame] | 77 | // If some texts were already selected, we don't change the selection. |
| 78 | if (!misspelled_word_string.empty()) { |
| 79 | // Don't provide suggestions for multiple words. |
| 80 | if (!IsASingleWord(misspelled_word_string)) |
| 81 | return L""; |
| 82 | else |
| 83 | return misspelled_word_string; |
| 84 | } |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 85 | |
[email protected] | 3a500b35 | 2008-10-31 17:10:21 | [diff] [blame] | 86 | WebCore::HitTestResult hit_test_result = selected_frame->eventHandler()-> |
| 87 | hitTestResultAtPoint(default_menu->hitTestResult().point(), true); |
| 88 | WebCore::Node* inner_node = hit_test_result.innerNode(); |
| 89 | WebCore::VisiblePosition pos(inner_node->renderer()->positionForPoint( |
| 90 | hit_test_result.localPoint())); |
[email protected] | 985f0e6 | 2008-10-29 01:05:08 | [diff] [blame] | 91 | |
[email protected] | 0f0981d | 2009-02-12 23:09:35 | [diff] [blame] | 92 | WebCore::VisibleSelection selection; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 93 | if (pos.isNotNull()) { |
[email protected] | 0f0981d | 2009-02-12 23:09:35 | [diff] [blame] | 94 | selection = WebCore::VisibleSelection(pos); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 95 | selection.expandUsingGranularity(WebCore::WordGranularity); |
| 96 | } |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 97 | |
| 98 | if (selection.isRange()) { |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 99 | selected_frame->setSelectionGranularity(WebCore::WordGranularity); |
| 100 | } |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 101 | |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 102 | if (selected_frame->shouldChangeSelection(selection)) |
[email protected] | de56f378 | 2008-10-01 22:31:35 | [diff] [blame] | 103 | selected_frame->selection()->setSelection(selection); |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 104 | |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 105 | misspelled_word_string = CollapseWhitespace( |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 106 | webkit_glue::StringToStdWString(selected_frame->selectedText()), |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 107 | false); |
[email protected] | 6d886b7 | 2009-02-11 23:30:11 | [diff] [blame] | 108 | |
| 109 | // If misspelled word is empty, then that portion should not be selected. |
| 110 | // Set the selection to that position only, and do not expand. |
| 111 | if (misspelled_word_string.empty()) { |
[email protected] | 0f0981d | 2009-02-12 23:09:35 | [diff] [blame] | 112 | selection = WebCore::VisibleSelection(pos); |
[email protected] | 6d886b7 | 2009-02-11 23:30:11 | [diff] [blame] | 113 | selected_frame->selection()->setSelection(selection); |
| 114 | } |
| 115 | |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 116 | return misspelled_word_string; |
| 117 | } |
| 118 | |
[email protected] | 985f0e6 | 2008-10-29 01:05:08 | [diff] [blame] | 119 | } // namespace |
| 120 | |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 121 | ContextMenuClientImpl::~ContextMenuClientImpl() { |
| 122 | } |
| 123 | |
| 124 | void ContextMenuClientImpl::contextMenuDestroyed() { |
| 125 | delete this; |
| 126 | } |
| 127 | |
| 128 | // Figure out the URL of a page or subframe. Returns |page_type| as the type, |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 129 | // which indicates page or subframe, or ContextNodeType::NONE if the URL could not |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 130 | // be determined for some reason. |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 131 | static ContextNodeType GetTypeAndURLFromFrame( |
| 132 | WebCore::Frame* frame, |
| 133 | GURL* url, |
| 134 | ContextNodeType page_node_type) { |
| 135 | ContextNodeType node_type; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 136 | if (frame) { |
| 137 | WebCore::DocumentLoader* dl = frame->loader()->documentLoader(); |
| 138 | if (dl) { |
[email protected] | 31f4c7e | 2009-08-27 20:43:29 | [diff] [blame] | 139 | WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 140 | if (ds) { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 141 | node_type = page_node_type; |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 142 | *url = ds->hasUnreachableURL() ? ds->unreachableURL() |
| 143 | : ds->request().url(); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | } |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 147 | return node_type; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | WebCore::PlatformMenuDescription |
| 151 | ContextMenuClientImpl::getCustomMenuFromDefaultItems( |
| 152 | WebCore::ContextMenu* default_menu) { |
| 153 | // Displaying the context menu in this function is a big hack as we don't |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 154 | // have context, i.e. whether this is being invoked via a script or in |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 155 | // response to user input (Mouse event WM_RBUTTONDOWN, |
| 156 | // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked |
| 157 | // in response to the above input events before popping up the context menu. |
| 158 | if (!webview_->context_menu_allowed()) |
| 159 | return NULL; |
| 160 | |
| 161 | WebCore::HitTestResult r = default_menu->hitTestResult(); |
| 162 | WebCore::Frame* selected_frame = r.innerNonSharedNode()->document()->frame(); |
| 163 | |
| 164 | WebCore::IntPoint menu_point = |
| 165 | selected_frame->view()->contentsToWindow(r.point()); |
| 166 | |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 167 | ContextNodeType node_type; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 168 | |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 169 | // Links, Images, Media tags, and Image/Media-Links take preference over |
| 170 | // all else. |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 171 | WebCore::KURL link_url = r.absoluteLinkURL(); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 172 | if (!link_url.isEmpty()) { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 173 | node_type.type |= ContextNodeType::LINK; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 174 | } |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 175 | |
| 176 | WebCore::KURL src_url; |
| 177 | |
| 178 | ContextMenuMediaParams media_params; |
| 179 | |
| 180 | if (!r.absoluteImageURL().isEmpty()) { |
| 181 | src_url = r.absoluteImageURL(); |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 182 | node_type.type |= ContextNodeType::IMAGE; |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 183 | } else if (!r.absoluteMediaURL().isEmpty()) { |
| 184 | src_url = r.absoluteMediaURL(); |
[email protected] | e626d7f | 2009-08-12 19:52:44 | [diff] [blame] | 185 | |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 186 | // We know that if absoluteMediaURL() is not empty, then this is a media |
| 187 | // element. |
| 188 | WebCore::HTMLMediaElement* media_element = |
| 189 | static_cast<WebCore::HTMLMediaElement*>(r.innerNonSharedNode()); |
| 190 | if (media_element->hasTagName(WebCore::HTMLNames::videoTag)) { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 191 | node_type.type |= ContextNodeType::VIDEO; |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 192 | } else if (media_element->hasTagName(WebCore::HTMLNames::audioTag)) { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 193 | node_type.type |= ContextNodeType::AUDIO; |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 194 | } |
| 195 | |
[email protected] | c67b2c0 | 2009-08-20 19:23:36 | [diff] [blame] | 196 | if (media_element->error()) { |
| 197 | media_params.player_state |= ContextMenuMediaParams::IN_ERROR; |
| 198 | } |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 199 | if (media_element->paused()) { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 200 | media_params.player_state |= ContextMenuMediaParams::PAUSED; |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 201 | } |
| 202 | if (media_element->muted()) { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 203 | media_params.player_state |= ContextMenuMediaParams::MUTED; |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 204 | } |
| 205 | if (media_element->loop()) { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 206 | media_params.player_state |= ContextMenuMediaParams::LOOP; |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 207 | } |
| 208 | if (media_element->supportsSave()) { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 209 | media_params.player_state |= ContextMenuMediaParams::CAN_SAVE; |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 210 | } |
[email protected] | bdaa1b75 | 2009-08-20 21:28:17 | [diff] [blame] | 211 | |
| 212 | media_params.has_audio = media_element->hasAudio(); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 213 | } |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 214 | |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 215 | // If it's not a link, an image, a media element, or an image/media link, |
| 216 | // show a selection menu or a more generic page menu. |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 217 | std::wstring selection_text_string; |
| 218 | std::wstring misspelled_word_string; |
| 219 | GURL frame_url; |
| 220 | GURL page_url; |
[email protected] | 6aa376b | 2008-09-23 18:49:52 | [diff] [blame] | 221 | std::string security_info; |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 222 | |
[email protected] | c9825a4 | 2009-05-01 22:51:50 | [diff] [blame] | 223 | std::string frame_charset = WideToASCII( |
| 224 | webkit_glue::StringToStdWString(selected_frame->loader()->encoding())); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 225 | // Send the frame and page URLs in any case. |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 226 | ContextNodeType frame_node = ContextNodeType(ContextNodeType::NONE); |
| 227 | ContextNodeType page_node = |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 228 | GetTypeAndURLFromFrame(webview_->main_frame()->frame(), |
| 229 | &page_url, |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 230 | ContextNodeType(ContextNodeType::PAGE)); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 231 | if (selected_frame != webview_->main_frame()->frame()) { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 232 | frame_node = |
| 233 | GetTypeAndURLFromFrame(selected_frame, |
| 234 | &frame_url, |
| 235 | ContextNodeType(ContextNodeType::FRAME)); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 236 | } |
[email protected] | 12464693 | 2009-01-28 18:39:02 | [diff] [blame] | 237 | |
| 238 | if (r.isSelected()) { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 239 | node_type.type |= ContextNodeType::SELECTION; |
[email protected] | 12464693 | 2009-01-28 18:39:02 | [diff] [blame] | 240 | selection_text_string = CollapseWhitespace( |
| 241 | webkit_glue::StringToStdWString(selected_frame->selectedText()), |
| 242 | false); |
| 243 | } |
| 244 | |
| 245 | if (r.isContentEditable()) { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 246 | node_type.type |= ContextNodeType::EDITABLE; |
[email protected] | 12464693 | 2009-01-28 18:39:02 | [diff] [blame] | 247 | if (webview_->GetFocusedWebCoreFrame()->editor()-> |
| 248 | isContinuousSpellCheckingEnabled()) { |
| 249 | misspelled_word_string = GetMisspelledWord(default_menu, |
| 250 | selected_frame); |
| 251 | } |
| 252 | } |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 253 | |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 254 | if (node_type.type == ContextNodeType::NONE) { |
[email protected] | 12464693 | 2009-01-28 18:39:02 | [diff] [blame] | 255 | if (selected_frame != webview_->main_frame()->frame()) { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 256 | node_type = frame_node; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 257 | } else { |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 258 | node_type = page_node; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
[email protected] | 6aa376b | 2008-09-23 18:49:52 | [diff] [blame] | 262 | // Now retrieve the security info. |
| 263 | WebCore::DocumentLoader* dl = selected_frame->loader()->documentLoader(); |
[email protected] | 31f4c7e | 2009-08-27 20:43:29 | [diff] [blame] | 264 | WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl); |
[email protected] | 726985e2 | 2009-06-18 21:09:28 | [diff] [blame] | 265 | if (ds) |
| 266 | security_info = ds->response().securityInfo(); |
[email protected] | 6aa376b | 2008-09-23 18:49:52 | [diff] [blame] | 267 | |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 268 | int edit_flags = ContextNodeType::CAN_DO_NONE; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 269 | if (webview_->GetFocusedWebCoreFrame()->editor()->canUndo()) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 270 | edit_flags |= ContextNodeType::CAN_UNDO; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 271 | if (webview_->GetFocusedWebCoreFrame()->editor()->canRedo()) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 272 | edit_flags |= ContextNodeType::CAN_REDO; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 273 | if (webview_->GetFocusedWebCoreFrame()->editor()->canCut()) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 274 | edit_flags |= ContextNodeType::CAN_CUT; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 275 | if (webview_->GetFocusedWebCoreFrame()->editor()->canCopy()) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 276 | edit_flags |= ContextNodeType::CAN_COPY; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 277 | if (webview_->GetFocusedWebCoreFrame()->editor()->canPaste()) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 278 | edit_flags |= ContextNodeType::CAN_PASTE; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 279 | if (webview_->GetFocusedWebCoreFrame()->editor()->canDelete()) |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 280 | edit_flags |= ContextNodeType::CAN_DELETE; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 281 | // We can always select all... |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 282 | edit_flags |= ContextNodeType::CAN_SELECT_ALL; |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 283 | |
| 284 | WebViewDelegate* d = webview_->delegate(); |
| 285 | if (d) { |
| 286 | d->ShowContextMenu(webview_, |
[email protected] | 581b87eb | 2009-07-23 23:06:56 | [diff] [blame] | 287 | node_type, |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 288 | menu_point.x(), |
| 289 | menu_point.y(), |
| 290 | webkit_glue::KURLToGURL(link_url), |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 291 | webkit_glue::KURLToGURL(src_url), |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 292 | page_url, |
| 293 | frame_url, |
[email protected] | 574a1d6 | 2009-07-17 03:23:46 | [diff] [blame] | 294 | media_params, |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 295 | selection_text_string, |
| 296 | misspelled_word_string, |
[email protected] | 6aa376b | 2008-09-23 18:49:52 | [diff] [blame] | 297 | edit_flags, |
[email protected] | c9825a4 | 2009-05-01 22:51:50 | [diff] [blame] | 298 | security_info, |
| 299 | frame_charset); |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 300 | } |
| 301 | return NULL; |
| 302 | } |
| 303 | |
| 304 | void ContextMenuClientImpl::contextMenuItemSelected( |
| 305 | WebCore::ContextMenuItem*, const WebCore::ContextMenu*) { |
| 306 | } |
| 307 | |
| 308 | void ContextMenuClientImpl::downloadURL(const WebCore::KURL&) { |
| 309 | } |
| 310 | |
| 311 | void ContextMenuClientImpl::copyImageToClipboard(const WebCore::HitTestResult&) { |
| 312 | } |
| 313 | |
| 314 | void ContextMenuClientImpl::searchWithGoogle(const WebCore::Frame*) { |
| 315 | } |
| 316 | |
| 317 | void ContextMenuClientImpl::lookUpInDictionary(WebCore::Frame*) { |
| 318 | } |
| 319 | |
| 320 | void ContextMenuClientImpl::speak(const WebCore::String&) { |
| 321 | } |
| 322 | |
[email protected] | f3d3105 | 2009-06-29 20:49:29 | [diff] [blame] | 323 | bool ContextMenuClientImpl::isSpeaking() { |
| 324 | return false; |
| 325 | } |
| 326 | |
initial.commit | f5b16fe | 2008-07-27 00:20:51 | [diff] [blame] | 327 | void ContextMenuClientImpl::stopSpeaking() { |
| 328 | } |
| 329 | |
| 330 | bool ContextMenuClientImpl::shouldIncludeInspectElementItem() { |
| 331 | return false; // TODO(jackson): Eventually include the inspector context menu item |
| 332 | } |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 333 | |
[email protected] | 7284c650 | 2008-09-09 20:27:26 | [diff] [blame] | 334 | #if defined(OS_MACOSX) |
| 335 | void ContextMenuClientImpl::searchWithSpotlight() { |
| 336 | // TODO(pinkerton): write this |
| 337 | } |
| 338 | #endif |