Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 Range* markerRange = selectionRange->cloneRange(); | 124 Range* markerRange = selectionRange->cloneRange(); |
| 125 markerRange->setStart(markerRange->startContainer(), markers[0]->startOffset ()); | 125 markerRange->setStart(markerRange->startContainer(), markers[0]->startOffset ()); |
| 126 markerRange->setEnd(markerRange->endContainer(), markers[0]->endOffset()); | 126 markerRange->setEnd(markerRange->endContainer(), markers[0]->endOffset()); |
| 127 | 127 |
| 128 if (markerRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation) != selec tionRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation)) | 128 if (markerRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation) != selec tionRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation)) |
| 129 return String(); | 129 return String(); |
| 130 | 130 |
| 131 return markerRange->text(); | 131 return markerRange->text(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void ContextMenuClientImpl::showContextMenu(const ContextMenu* defaultMenu) | 134 static bool shouldShowContextMenuFromTouch(const WebContextMenuData& data) |
| 135 { | |
| 136 return !data.linkURL.isEmpty() | |
| 137 || data.mediaType == WebContextMenuData::MediaTypeImage | |
| 138 || data.mediaType == WebContextMenuData::MediaTypeVideo; | |
| 139 } | |
| 140 | |
| 141 bool ContextMenuClientImpl::showContextMenu(const ContextMenu* defaultMenu, bool fromTouch) | |
| 135 { | 142 { |
| 136 // Displaying the context menu in this function is a big hack as we don't | 143 // Displaying the context menu in this function is a big hack as we don't |
| 137 // have context, i.e. whether this is being invoked via a script or in | 144 // have context, i.e. whether this is being invoked via a script or in |
| 138 // response to user input (Mouse event WM_RBUTTONDOWN, | 145 // response to user input (Mouse event WM_RBUTTONDOWN, |
| 139 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked | 146 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked |
| 140 // in response to the above input events before popping up the context menu. | 147 // in response to the above input events before popping up the context menu. |
| 141 if (!ContextMenuAllowedScope::isContextMenuAllowed()) | 148 if (!ContextMenuAllowedScope::isContextMenuAllowed()) |
| 142 return; | 149 return false; |
| 143 | 150 |
| 144 HitTestResult r = m_webView->page()->contextMenuController().hitTestResult() ; | 151 HitTestResult r = m_webView->page()->contextMenuController().hitTestResult() ; |
| 145 | 152 |
| 146 r.setToShadowHostIfInUserAgentShadowRoot(); | 153 r.setToShadowHostIfInUserAgentShadowRoot(); |
| 147 | 154 |
| 148 LocalFrame* selectedFrame = r.innerNodeFrame(); | 155 LocalFrame* selectedFrame = r.innerNodeFrame(); |
| 149 | 156 |
| 150 WebContextMenuData data; | 157 WebContextMenuData data; |
| 151 data.mousePosition = selectedFrame->view()->contentsToViewport(r.roundedPoin tInInnerNodeFrame()); | 158 data.mousePosition = selectedFrame->view()->contentsToViewport(r.roundedPoin tInInnerNodeFrame()); |
| 152 | 159 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 data.srcURL = pluginElement->document().completeURL(pluginElemen t->url()); | 256 data.srcURL = pluginElement->document().completeURL(pluginElemen t->url()); |
| 250 data.mediaFlags |= WebContextMenuData::MediaCanSave; | 257 data.mediaFlags |= WebContextMenuData::MediaCanSave; |
| 251 | 258 |
| 252 // Add context menu commands that are supported by the plugin. | 259 // Add context menu commands that are supported by the plugin. |
| 253 if (plugin->plugin()->canRotateView()) | 260 if (plugin->plugin()->canRotateView()) |
| 254 data.mediaFlags |= WebContextMenuData::MediaCanRotate; | 261 data.mediaFlags |= WebContextMenuData::MediaCanRotate; |
| 255 } | 262 } |
| 256 } | 263 } |
| 257 } | 264 } |
| 258 | 265 |
| 266 if (fromTouch && !shouldShowContextMenuFromTouch(data)) { | |
| 267 return false; | |
| 268 } | |
|
aelias_OOO_until_Jul13
2016/05/19 02:25:21
Nit: Blink style is that one-line control clauses
amaralp
2016/05/19 18:21:09
Done.
| |
| 269 | |
| 259 // If it's not a link, an image, a media element, or an image/media link, | 270 // If it's not a link, an image, a media element, or an image/media link, |
| 260 // show a selection menu or a more generic page menu. | 271 // show a selection menu or a more generic page menu. |
| 261 if (selectedFrame->document()->loader()) | 272 if (selectedFrame->document()->loader()) |
| 262 data.frameEncoding = selectedFrame->document()->encodingName(); | 273 data.frameEncoding = selectedFrame->document()->encodingName(); |
| 263 | 274 |
| 264 // Send the frame and page URLs in any case. | 275 // Send the frame and page URLs in any case. |
| 265 if (!m_webView->page()->mainFrame()->isLocalFrame()) { | 276 if (!m_webView->page()->mainFrame()->isLocalFrame()) { |
| 266 // TODO(kenrb): This works around the problem of URLs not being | 277 // TODO(kenrb): This works around the problem of URLs not being |
| 267 // available for top-level frames that are in a different process. | 278 // available for top-level frames that are in a different process. |
| 268 // It mostly works to convert the security origin to a URL, but | 279 // It mostly works to convert the security origin to a URL, but |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 else | 366 else |
| 356 data.inputFieldType = WebContextMenuData::InputFieldTypeOther; | 367 data.inputFieldType = WebContextMenuData::InputFieldTypeOther; |
| 357 } else { | 368 } else { |
| 358 data.inputFieldType = WebContextMenuData::InputFieldTypeNone; | 369 data.inputFieldType = WebContextMenuData::InputFieldTypeNone; |
| 359 } | 370 } |
| 360 | 371 |
| 361 WebLocalFrameImpl* selectedWebFrame = WebLocalFrameImpl::fromFrame(selectedF rame); | 372 WebLocalFrameImpl* selectedWebFrame = WebLocalFrameImpl::fromFrame(selectedF rame); |
| 362 selectedWebFrame->setContextMenuNode(r.innerNodeOrImageMapImage()); | 373 selectedWebFrame->setContextMenuNode(r.innerNodeOrImageMapImage()); |
| 363 if (selectedWebFrame->client()) | 374 if (selectedWebFrame->client()) |
| 364 selectedWebFrame->client()->showContextMenu(data); | 375 selectedWebFrame->client()->showContextMenu(data); |
| 376 | |
| 377 return true; | |
| 365 } | 378 } |
| 366 | 379 |
| 367 void ContextMenuClientImpl::clearContextMenu() | 380 void ContextMenuClientImpl::clearContextMenu() |
| 368 { | 381 { |
| 369 HitTestResult r = m_webView->page()->contextMenuController().hitTestResult() ; | 382 HitTestResult r = m_webView->page()->contextMenuController().hitTestResult() ; |
| 370 LocalFrame* selectedFrame = r.innerNodeFrame(); | 383 LocalFrame* selectedFrame = r.innerNodeFrame(); |
| 371 if (!selectedFrame) | 384 if (!selectedFrame) |
| 372 return; | 385 return; |
| 373 | 386 |
| 374 WebLocalFrameImpl* selectedWebFrame = WebLocalFrameImpl::fromFrame(selectedF rame); | 387 WebLocalFrameImpl* selectedWebFrame = WebLocalFrameImpl::fromFrame(selectedF rame); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 outputItems[i] = subItems[i]; | 425 outputItems[i] = subItems[i]; |
| 413 subMenuItems.swap(outputItems); | 426 subMenuItems.swap(outputItems); |
| 414 } | 427 } |
| 415 | 428 |
| 416 void ContextMenuClientImpl::populateCustomMenuItems(const ContextMenu* defaultMe nu, WebContextMenuData* data) | 429 void ContextMenuClientImpl::populateCustomMenuItems(const ContextMenu* defaultMe nu, WebContextMenuData* data) |
| 417 { | 430 { |
| 418 populateSubMenuItems(defaultMenu->items(), data->customItems); | 431 populateSubMenuItems(defaultMenu->items(), data->customItems); |
| 419 } | 432 } |
| 420 | 433 |
| 421 } // namespace blink | 434 } // namespace blink |
| OLD | NEW |