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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 static bool shouldShowContextMenuFromTouch(const WebContextMenuData& data) | 134 static bool shouldShowContextMenuFromTouch(const WebContextMenuData& data) |
| 135 { | 135 { |
| 136 return !data.linkURL.isEmpty() | 136 return !data.linkURL.isEmpty() |
| 137 || data.mediaType == WebContextMenuData::MediaTypeImage | 137 || data.mediaType == WebContextMenuData::MediaTypeImage |
| 138 || data.mediaType == WebContextMenuData::MediaTypeVideo; | 138 || data.mediaType == WebContextMenuData::MediaTypeVideo |
| 139 || data.isEditable; | |
| 139 } | 140 } |
| 140 | 141 |
| 141 bool ContextMenuClientImpl::showContextMenu(const ContextMenu* defaultMenu, bool fromTouch) | 142 bool ContextMenuClientImpl::showContextMenu(const ContextMenu* defaultMenu, bool fromTouch) |
| 142 { | 143 { |
| 143 // Displaying the context menu in this function is a big hack as we don't | 144 // Displaying the context menu in this function is a big hack as we don't |
| 144 // have context, i.e. whether this is being invoked via a script or in | 145 // have context, i.e. whether this is being invoked via a script or in |
| 145 // response to user input (Mouse event WM_RBUTTONDOWN, | 146 // response to user input (Mouse event WM_RBUTTONDOWN, |
| 146 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked | 147 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked |
| 147 // in response to the above input events before popping up the context menu. | 148 // in response to the above input events before popping up the context menu. |
| 148 if (!ContextMenuAllowedScope::isContextMenuAllowed()) | 149 if (!ContextMenuAllowedScope::isContextMenuAllowed()) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 data.srcURL = pluginElement->document().completeURL(pluginElemen t->url()); | 257 data.srcURL = pluginElement->document().completeURL(pluginElemen t->url()); |
| 257 data.mediaFlags |= WebContextMenuData::MediaCanSave; | 258 data.mediaFlags |= WebContextMenuData::MediaCanSave; |
| 258 | 259 |
| 259 // Add context menu commands that are supported by the plugin. | 260 // Add context menu commands that are supported by the plugin. |
| 260 if (plugin->plugin()->canRotateView()) | 261 if (plugin->plugin()->canRotateView()) |
| 261 data.mediaFlags |= WebContextMenuData::MediaCanRotate; | 262 data.mediaFlags |= WebContextMenuData::MediaCanRotate; |
| 262 } | 263 } |
| 263 } | 264 } |
| 264 } | 265 } |
| 265 | 266 |
| 266 if (fromTouch && !shouldShowContextMenuFromTouch(data)) | |
| 267 return false; | |
| 268 | |
| 269 // If it's not a link, an image, a media element, or an image/media link, | 267 // If it's not a link, an image, a media element, or an image/media link, |
| 270 // show a selection menu or a more generic page menu. | 268 // show a selection menu or a more generic page menu. |
| 271 if (selectedFrame->document()->loader()) | 269 if (selectedFrame->document()->loader()) |
| 272 data.frameEncoding = selectedFrame->document()->encodingName(); | 270 data.frameEncoding = selectedFrame->document()->encodingName(); |
| 273 | 271 |
| 274 // Send the frame and page URLs in any case. | 272 // Send the frame and page URLs in any case. |
| 275 if (!m_webView->page()->mainFrame()->isLocalFrame()) { | 273 if (!m_webView->page()->mainFrame()->isLocalFrame()) { |
| 276 // TODO(kenrb): This works around the problem of URLs not being | 274 // TODO(kenrb): This works around the problem of URLs not being |
| 277 // available for top-level frames that are in a different process. | 275 // available for top-level frames that are in a different process. |
| 278 // It mostly works to convert the security origin to a URL, but | 276 // It mostly works to convert the security origin to a URL, but |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 if (element->type() == InputTypeNames::password) | 359 if (element->type() == InputTypeNames::password) |
| 362 data.inputFieldType = WebContextMenuData::InputFieldTypePassword; | 360 data.inputFieldType = WebContextMenuData::InputFieldTypePassword; |
| 363 else if (element->isTextField()) | 361 else if (element->isTextField()) |
| 364 data.inputFieldType = WebContextMenuData::InputFieldTypePlainText; | 362 data.inputFieldType = WebContextMenuData::InputFieldTypePlainText; |
| 365 else | 363 else |
| 366 data.inputFieldType = WebContextMenuData::InputFieldTypeOther; | 364 data.inputFieldType = WebContextMenuData::InputFieldTypeOther; |
| 367 } else { | 365 } else { |
| 368 data.inputFieldType = WebContextMenuData::InputFieldTypeNone; | 366 data.inputFieldType = WebContextMenuData::InputFieldTypeNone; |
| 369 } | 367 } |
| 370 | 368 |
| 369 if (fromTouch && !shouldShowContextMenuFromTouch(data)) | |
| 370 return false; | |
| 371 | |
| 371 WebLocalFrameImpl* selectedWebFrame = WebLocalFrameImpl::fromFrame(selectedF rame); | 372 WebLocalFrameImpl* selectedWebFrame = WebLocalFrameImpl::fromFrame(selectedF rame); |
| 372 selectedWebFrame->setContextMenuNode(r.innerNodeOrImageMapImage()); | 373 selectedWebFrame->setContextMenuNode(r.innerNodeOrImageMapImage()); |
| 373 if (selectedWebFrame->client()) | 374 if (selectedWebFrame->client()) { |
| 374 selectedWebFrame->client()->showContextMenu(data); | 375 selectedWebFrame->client()->showContextMenu(data); |
| 376 return true; | |
|
aelias_OOO_until_Jul13
2016/05/25 01:08:32
Nit: in Blink style, it's generally preferred for
| |
| 377 } | |
| 375 | 378 |
| 376 return true; | 379 return false; |
| 377 } | 380 } |
| 378 | 381 |
| 379 void ContextMenuClientImpl::clearContextMenu() | 382 void ContextMenuClientImpl::clearContextMenu() |
| 380 { | 383 { |
| 381 HitTestResult r = m_webView->page()->contextMenuController().hitTestResult() ; | 384 HitTestResult r = m_webView->page()->contextMenuController().hitTestResult() ; |
| 382 LocalFrame* selectedFrame = r.innerNodeFrame(); | 385 LocalFrame* selectedFrame = r.innerNodeFrame(); |
| 383 if (!selectedFrame) | 386 if (!selectedFrame) |
| 384 return; | 387 return; |
| 385 | 388 |
| 386 WebLocalFrameImpl* selectedWebFrame = WebLocalFrameImpl::fromFrame(selectedF rame); | 389 WebLocalFrameImpl* selectedWebFrame = WebLocalFrameImpl::fromFrame(selectedF rame); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 outputItems[i] = subItems[i]; | 427 outputItems[i] = subItems[i]; |
| 425 subMenuItems.swap(outputItems); | 428 subMenuItems.swap(outputItems); |
| 426 } | 429 } |
| 427 | 430 |
| 428 void ContextMenuClientImpl::populateCustomMenuItems(const ContextMenu* defaultMe nu, WebContextMenuData* data) | 431 void ContextMenuClientImpl::populateCustomMenuItems(const ContextMenu* defaultMe nu, WebContextMenuData* data) |
| 429 { | 432 { |
| 430 populateSubMenuItems(defaultMenu->items(), data->customItems); | 433 populateSubMenuItems(defaultMenu->items(), data->customItems); |
| 431 } | 434 } |
| 432 | 435 |
| 433 } // namespace blink | 436 } // namespace blink |
| OLD | NEW |