Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: third_party/WebKit/Source/web/ContextMenuClientImpl.cpp

Issue 2007213002: Fixing long press paste pop up bug (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nit pick Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 return false;
375 376
377 selectedWebFrame->client()->showContextMenu(data);
376 return true; 378 return true;
377 } 379 }
378 380
379 void ContextMenuClientImpl::clearContextMenu() 381 void ContextMenuClientImpl::clearContextMenu()
380 { 382 {
381 HitTestResult r = m_webView->page()->contextMenuController().hitTestResult() ; 383 HitTestResult r = m_webView->page()->contextMenuController().hitTestResult() ;
382 LocalFrame* selectedFrame = r.innerNodeFrame(); 384 LocalFrame* selectedFrame = r.innerNodeFrame();
383 if (!selectedFrame) 385 if (!selectedFrame)
384 return; 386 return;
385 387
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 outputItems[i] = subItems[i]; 426 outputItems[i] = subItems[i];
425 subMenuItems.swap(outputItems); 427 subMenuItems.swap(outputItems);
426 } 428 }
427 429
428 void ContextMenuClientImpl::populateCustomMenuItems(const ContextMenu* defaultMe nu, WebContextMenuData* data) 430 void ContextMenuClientImpl::populateCustomMenuItems(const ContextMenu* defaultMe nu, WebContextMenuData* data)
429 { 431 {
430 populateSubMenuItems(defaultMenu->items(), data->customItems); 432 populateSubMenuItems(defaultMenu->items(), data->customItems);
431 } 433 }
432 434
433 } // namespace blink 435 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/web/tests/WebViewTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698