| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 | 8 |
| 9 MSVC_PUSH_WARNING_LEVEL(0); | 9 MSVC_PUSH_WARNING_LEVEL(0); |
| 10 #include "ContextMenu.h" | 10 #include "ContextMenu.h" |
| 11 #include "Document.h" | 11 #include "Document.h" |
| 12 #include "DocumentLoader.h" | 12 #include "DocumentLoader.h" |
| 13 #include "Editor.h" | 13 #include "Editor.h" |
| 14 #include "EventHandler.h" | 14 #include "EventHandler.h" |
| 15 #include "FrameLoader.h" | 15 #include "FrameLoader.h" |
| 16 #include "FrameView.h" | 16 #include "FrameView.h" |
| 17 #include "HitTestResult.h" | 17 #include "HitTestResult.h" |
| 18 #include "HTMLMediaElement.h" |
| 19 #include "HTMLNames.h" |
| 18 #include "KURL.h" | 20 #include "KURL.h" |
| 19 #include "Widget.h" | 21 #include "Widget.h" |
| 20 MSVC_POP_WARNING(); | 22 MSVC_POP_WARNING(); |
| 21 #undef LOG | 23 #undef LOG |
| 22 | 24 |
| 23 #include "webkit/glue/context_menu_client_impl.h" | 25 #include "webkit/glue/context_menu_client_impl.h" |
| 24 | 26 |
| 25 #include "base/string_util.h" | 27 #include "base/string_util.h" |
| 26 #include "webkit/api/public/WebURL.h" | 28 #include "webkit/api/public/WebURL.h" |
| 27 #include "webkit/api/public/WebURLResponse.h" | 29 #include "webkit/api/public/WebURLResponse.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 return NULL; | 156 return NULL; |
| 155 | 157 |
| 156 WebCore::HitTestResult r = default_menu->hitTestResult(); | 158 WebCore::HitTestResult r = default_menu->hitTestResult(); |
| 157 WebCore::Frame* selected_frame = r.innerNonSharedNode()->document()->frame(); | 159 WebCore::Frame* selected_frame = r.innerNonSharedNode()->document()->frame(); |
| 158 | 160 |
| 159 WebCore::IntPoint menu_point = | 161 WebCore::IntPoint menu_point = |
| 160 selected_frame->view()->contentsToWindow(r.point()); | 162 selected_frame->view()->contentsToWindow(r.point()); |
| 161 | 163 |
| 162 ContextNode node; | 164 ContextNode node; |
| 163 | 165 |
| 164 // Links, Images and Image-Links take preference over all else. | 166 // Links, Images, Media tags, and Image/Media-Links take preference over |
| 167 // all else. |
| 165 WebCore::KURL link_url = r.absoluteLinkURL(); | 168 WebCore::KURL link_url = r.absoluteLinkURL(); |
| 166 if (!link_url.isEmpty()) { | 169 if (!link_url.isEmpty()) { |
| 167 node.type |= ContextNode::LINK; | 170 node.type |= ContextNode::LINK; |
| 168 } | 171 } |
| 169 WebCore::KURL image_url = r.absoluteImageURL(); | 172 |
| 170 if (!image_url.isEmpty()) { | 173 WebCore::KURL src_url; |
| 174 |
| 175 ContextMenuMediaParams media_params; |
| 176 |
| 177 if (!r.absoluteImageURL().isEmpty()) { |
| 178 src_url = r.absoluteImageURL(); |
| 171 node.type |= ContextNode::IMAGE; | 179 node.type |= ContextNode::IMAGE; |
| 180 } else if (!r.absoluteMediaURL().isEmpty()) { |
| 181 src_url = r.absoluteMediaURL(); |
| 182 |
| 183 // We know that if absoluteMediaURL() is not empty, then this is a media |
| 184 // element. |
| 185 WebCore::HTMLMediaElement* media_element = |
| 186 static_cast<WebCore::HTMLMediaElement*>(r.innerNonSharedNode()); |
| 187 if (media_element->hasTagName(WebCore::HTMLNames::videoTag)) { |
| 188 node.type |= ContextNode::VIDEO; |
| 189 } else if (media_element->hasTagName(WebCore::HTMLNames::audioTag)) { |
| 190 node.type |= ContextNode::AUDIO; |
| 191 } |
| 192 |
| 193 media_params.playback_rate = media_element->playbackRate(); |
| 194 |
| 195 if (media_element->paused()) { |
| 196 media_params.player_state |= ContextMenuMediaParams::PLAYER_PAUSED; |
| 197 } |
| 198 if (media_element->muted()) { |
| 199 media_params.player_state |= ContextMenuMediaParams::PLAYER_MUTED; |
| 200 } |
| 201 if (media_element->loop()) { |
| 202 media_params.player_state |= ContextMenuMediaParams::PLAYER_LOOP; |
| 203 } |
| 204 if (media_element->supportsSave()) { |
| 205 media_params.player_state |= ContextMenuMediaParams::PLAYER_CAN_SAVE; |
| 206 } |
| 172 } | 207 } |
| 173 | 208 |
| 174 // If it's not a link, an image or an image link, show a selection menu or a | 209 // If it's not a link, an image, a media element, or an image/media link, |
| 175 // more generic page menu. | 210 // show a selection menu or a more generic page menu. |
| 176 std::wstring selection_text_string; | 211 std::wstring selection_text_string; |
| 177 std::wstring misspelled_word_string; | 212 std::wstring misspelled_word_string; |
| 178 GURL frame_url; | 213 GURL frame_url; |
| 179 GURL page_url; | 214 GURL page_url; |
| 180 std::string security_info; | 215 std::string security_info; |
| 181 | 216 |
| 182 std::string frame_charset = WideToASCII( | 217 std::string frame_charset = WideToASCII( |
| 183 webkit_glue::StringToStdWString(selected_frame->loader()->encoding())); | 218 webkit_glue::StringToStdWString(selected_frame->loader()->encoding())); |
| 184 // Send the frame and page URLs in any case. | 219 // Send the frame and page URLs in any case. |
| 185 ContextNode frame_node = ContextNode(ContextNode::NONE); | 220 ContextNode frame_node = ContextNode(ContextNode::NONE); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // We can always select all... | 274 // We can always select all... |
| 240 edit_flags |= ContextNode::CAN_SELECT_ALL; | 275 edit_flags |= ContextNode::CAN_SELECT_ALL; |
| 241 | 276 |
| 242 WebViewDelegate* d = webview_->delegate(); | 277 WebViewDelegate* d = webview_->delegate(); |
| 243 if (d) { | 278 if (d) { |
| 244 d->ShowContextMenu(webview_, | 279 d->ShowContextMenu(webview_, |
| 245 node, | 280 node, |
| 246 menu_point.x(), | 281 menu_point.x(), |
| 247 menu_point.y(), | 282 menu_point.y(), |
| 248 webkit_glue::KURLToGURL(link_url), | 283 webkit_glue::KURLToGURL(link_url), |
| 249 webkit_glue::KURLToGURL(image_url), | 284 webkit_glue::KURLToGURL(src_url), |
| 250 page_url, | 285 page_url, |
| 251 frame_url, | 286 frame_url, |
| 287 media_params, |
| 252 selection_text_string, | 288 selection_text_string, |
| 253 misspelled_word_string, | 289 misspelled_word_string, |
| 254 edit_flags, | 290 edit_flags, |
| 255 security_info, | 291 security_info, |
| 256 frame_charset); | 292 frame_charset); |
| 257 } | 293 } |
| 258 return NULL; | 294 return NULL; |
| 259 } | 295 } |
| 260 | 296 |
| 261 void ContextMenuClientImpl::contextMenuItemSelected( | 297 void ContextMenuClientImpl::contextMenuItemSelected( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 286 | 322 |
| 287 bool ContextMenuClientImpl::shouldIncludeInspectElementItem() { | 323 bool ContextMenuClientImpl::shouldIncludeInspectElementItem() { |
| 288 return false; // TODO(jackson): Eventually include the inspector context me
nu item | 324 return false; // TODO(jackson): Eventually include the inspector context me
nu item |
| 289 } | 325 } |
| 290 | 326 |
| 291 #if defined(OS_MACOSX) | 327 #if defined(OS_MACOSX) |
| 292 void ContextMenuClientImpl::searchWithSpotlight() { | 328 void ContextMenuClientImpl::searchWithSpotlight() { |
| 293 // TODO(pinkerton): write this | 329 // TODO(pinkerton): write this |
| 294 } | 330 } |
| 295 #endif | 331 #endif |
| OLD | NEW |