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

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

Issue 2785853002: Selection Action mode triggered like a context menu (Closed)
Patch Set: fix tests Created 3 years, 7 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
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 22 matching lines...) Expand all
33 #include "bindings/core/v8/ExceptionState.h" 33 #include "bindings/core/v8/ExceptionState.h"
34 #include "core/CSSPropertyNames.h" 34 #include "core/CSSPropertyNames.h"
35 #include "core/HTMLNames.h" 35 #include "core/HTMLNames.h"
36 #include "core/InputTypeNames.h" 36 #include "core/InputTypeNames.h"
37 #include "core/css/CSSStyleDeclaration.h" 37 #include "core/css/CSSStyleDeclaration.h"
38 #include "core/dom/Document.h" 38 #include "core/dom/Document.h"
39 #include "core/dom/ElementTraversal.h" 39 #include "core/dom/ElementTraversal.h"
40 #include "core/editing/Editor.h" 40 #include "core/editing/Editor.h"
41 #include "core/editing/markers/DocumentMarkerController.h" 41 #include "core/editing/markers/DocumentMarkerController.h"
42 #include "core/editing/spellcheck/SpellChecker.h" 42 #include "core/editing/spellcheck/SpellChecker.h"
43 #include "core/events/MouseEvent.h"
43 #include "core/exported/WebDataSourceImpl.h" 44 #include "core/exported/WebDataSourceImpl.h"
44 #include "core/exported/WebPluginContainerBase.h" 45 #include "core/exported/WebPluginContainerBase.h"
45 #include "core/exported/WebViewBase.h" 46 #include "core/exported/WebViewBase.h"
46 #include "core/frame/FrameView.h" 47 #include "core/frame/FrameView.h"
47 #include "core/frame/Settings.h" 48 #include "core/frame/Settings.h"
48 #include "core/frame/VisualViewport.h" 49 #include "core/frame/VisualViewport.h"
49 #include "core/frame/WebLocalFrameBase.h" 50 #include "core/frame/WebLocalFrameBase.h"
50 #include "core/html/HTMLAnchorElement.h" 51 #include "core/html/HTMLAnchorElement.h"
51 #include "core/html/HTMLFormElement.h" 52 #include "core/html/HTMLFormElement.h"
52 #include "core/html/HTMLFrameElementBase.h" 53 #include "core/html/HTMLFrameElementBase.h"
53 #include "core/html/HTMLImageElement.h" 54 #include "core/html/HTMLImageElement.h"
54 #include "core/html/HTMLInputElement.h" 55 #include "core/html/HTMLInputElement.h"
55 #include "core/html/HTMLMediaElement.h" 56 #include "core/html/HTMLMediaElement.h"
56 #include "core/html/HTMLPlugInElement.h" 57 #include "core/html/HTMLPlugInElement.h"
58 #include "core/input/ContextMenuAllowedScope.h"
57 #include "core/input/EventHandler.h" 59 #include "core/input/EventHandler.h"
58 #include "core/layout/HitTestResult.h" 60 #include "core/layout/HitTestResult.h"
59 #include "core/layout/LayoutPart.h" 61 #include "core/layout/LayoutPart.h"
60 #include "core/loader/DocumentLoader.h" 62 #include "core/loader/DocumentLoader.h"
61 #include "core/loader/FrameLoader.h" 63 #include "core/loader/FrameLoader.h"
62 #include "core/loader/HistoryItem.h" 64 #include "core/loader/HistoryItem.h"
63 #include "core/page/ContextMenuController.h" 65 #include "core/page/ContextMenuController.h"
64 #include "core/page/Page.h" 66 #include "core/page/Page.h"
65 #include "platform/ContextMenu.h" 67 #include "platform/ContextMenu.h"
66 #include "platform/exported/WrappedResourceResponse.h" 68 #include "platform/exported/WrappedResourceResponse.h"
67 #include "platform/text/TextBreakIterator.h" 69 #include "platform/text/TextBreakIterator.h"
68 #include "platform/weborigin/KURL.h" 70 #include "platform/weborigin/KURL.h"
69 #include "platform/wtf/text/WTFString.h" 71 #include "platform/wtf/text/WTFString.h"
70 #include "public/platform/WebPoint.h" 72 #include "public/platform/WebPoint.h"
71 #include "public/platform/WebString.h" 73 #include "public/platform/WebString.h"
72 #include "public/platform/WebURL.h" 74 #include "public/platform/WebURL.h"
73 #include "public/platform/WebURLResponse.h" 75 #include "public/platform/WebURLResponse.h"
74 #include "public/platform/WebVector.h" 76 #include "public/platform/WebVector.h"
75 #include "public/web/WebContextMenuData.h" 77 #include "public/web/WebContextMenuData.h"
76 #include "public/web/WebFormElement.h" 78 #include "public/web/WebFormElement.h"
77 #include "public/web/WebFrameClient.h" 79 #include "public/web/WebFrameClient.h"
78 #include "public/web/WebMenuItemInfo.h" 80 #include "public/web/WebMenuItemInfo.h"
79 #include "public/web/WebPlugin.h" 81 #include "public/web/WebPlugin.h"
80 #include "public/web/WebSearchableFormData.h" 82 #include "public/web/WebSearchableFormData.h"
81 #include "public/web/WebTextCheckClient.h" 83 #include "public/web/WebTextCheckClient.h"
82 #include "public/web/WebViewClient.h" 84 #include "public/web/WebViewClient.h"
83 #include "web/ContextMenuAllowedScope.h"
84 85
85 namespace blink { 86 namespace blink {
86 87
87 // Figure out the URL of a page or subframe. Returns |page_type| as the type, 88 // Figure out the URL of a page or subframe. Returns |page_type| as the type,
88 // which indicates page or subframe, or ContextNodeType::kNone if the URL could 89 // which indicates page or subframe, or ContextNodeType::kNone if the URL could
89 // not be determined for some reason. 90 // not be determined for some reason.
90 static WebURL UrlFromFrame(LocalFrame* frame) { 91 static WebURL UrlFromFrame(LocalFrame* frame) {
91 if (frame) { 92 if (frame) {
92 DocumentLoader* dl = frame->Loader().GetDocumentLoader(); 93 DocumentLoader* dl = frame->Loader().GetDocumentLoader();
93 if (dl) { 94 if (dl) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 191 }
191 192
192 bool ContextMenuClientImpl::ShouldShowContextMenuFromTouch( 193 bool ContextMenuClientImpl::ShouldShowContextMenuFromTouch(
193 const WebContextMenuData& data) { 194 const WebContextMenuData& data) {
194 return web_view_->GetPage() 195 return web_view_->GetPage()
195 ->GetSettings() 196 ->GetSettings()
196 .GetAlwaysShowContextMenuOnTouch() || 197 .GetAlwaysShowContextMenuOnTouch() ||
197 !data.link_url.IsEmpty() || 198 !data.link_url.IsEmpty() ||
198 data.media_type == WebContextMenuData::kMediaTypeImage || 199 data.media_type == WebContextMenuData::kMediaTypeImage ||
199 data.media_type == WebContextMenuData::kMediaTypeVideo || 200 data.media_type == WebContextMenuData::kMediaTypeVideo ||
200 data.is_editable; 201 data.is_editable || !data.selected_text.IsEmpty();
201 } 202 }
202 203
203 static HTMLFormElement* AssociatedFormElement(HTMLElement& element) { 204 static HTMLFormElement* AssociatedFormElement(HTMLElement& element) {
204 if (isHTMLFormElement(element)) 205 if (isHTMLFormElement(element))
205 return &toHTMLFormElement(element); 206 return &toHTMLFormElement(element);
206 return element.formOwner(); 207 return element.formOwner();
207 } 208 }
208 209
209 // Scans logically forward from "start", including any child frames. 210 // Scans logically forward from "start", including any child frames.
210 static HTMLFormElement* ScanForForm(const Node* start) { 211 static HTMLFormElement* ScanForForm(const Node* start) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 break; 247 break;
247 HTMLElement& element = ToHTMLElement(node); 248 HTMLElement& element = ToHTMLElement(node);
248 if (HTMLFormElement* form = AssociatedFormElement(element)) 249 if (HTMLFormElement* form = AssociatedFormElement(element))
249 return form; 250 return form;
250 } 251 }
251 252
252 // Try walking forward in the node tree to find a form element. 253 // Try walking forward in the node tree to find a form element.
253 return ScanForForm(start); 254 return ScanForForm(start);
254 } 255 }
255 256
256 bool ContextMenuClientImpl::ShowContextMenu(const ContextMenu* default_menu, 257 bool ContextMenuClientImpl::ShowContextMenu(
257 bool from_touch) { 258 const ContextMenu* default_menu,
259 MouseEvent::SyntheticEventType synthetic_event_type) {
258 // Displaying the context menu in this function is a big hack as we don't 260 // Displaying the context menu in this function is a big hack as we don't
259 // have context, i.e. whether this is being invoked via a script or in 261 // have context, i.e. whether this is being invoked via a script or in
260 // response to user input (Mouse event WM_RBUTTONDOWN, 262 // response to user input (Mouse event WM_RBUTTONDOWN,
261 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked 263 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked
262 // in response to the above input events before popping up the context menu. 264 // in response to the above input events before popping up the context menu.
263 if (!ContextMenuAllowedScope::IsContextMenuAllowed()) 265 if (!ContextMenuAllowedScope::IsContextMenuAllowed())
264 return false; 266 return false;
265 267
266 HitTestResult r = 268 HitTestResult r =
267 web_view_->GetPage()->GetContextMenuController().GetHitTestResult(); 269 web_view_->GetPage()->GetContextMenuController().GetHitTestResult();
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 490
489 int left = std::min(focus_webrect.x, anchor_webrect.x); 491 int left = std::min(focus_webrect.x, anchor_webrect.x);
490 int top = std::min(focus_webrect.y, anchor_webrect.y); 492 int top = std::min(focus_webrect.y, anchor_webrect.y);
491 int right = std::max(focus_webrect.x + focus_webrect.width, 493 int right = std::max(focus_webrect.x + focus_webrect.width,
492 anchor_webrect.x + anchor_webrect.width); 494 anchor_webrect.x + anchor_webrect.width);
493 int bottom = std::max(focus_webrect.y + focus_webrect.height, 495 int bottom = std::max(focus_webrect.y + focus_webrect.height,
494 anchor_webrect.y + anchor_webrect.height); 496 anchor_webrect.y + anchor_webrect.height);
495 497
496 data.selection_rect = WebRect(left, top, right - left, bottom - top); 498 data.selection_rect = WebRect(left, top, right - left, bottom - top);
497 499
498 if (from_touch && !ShouldShowContextMenuFromTouch(data)) 500 data.from_select_all = synthetic_event_type == MouseEvent::kFromSelectAll;
501 if (synthetic_event_type == MouseEvent::kFromTouch &&
502 !ShouldShowContextMenuFromTouch(data))
499 return false; 503 return false;
500 504
501 selected_web_frame->SetContextMenuNode(r.InnerNodeOrImageMapImage()); 505 selected_web_frame->SetContextMenuNode(r.InnerNodeOrImageMapImage());
502 if (!selected_web_frame->Client()) 506 if (!selected_web_frame->Client())
503 return false; 507 return false;
504 508
505 selected_web_frame->Client()->ShowContextMenu(data); 509 selected_web_frame->Client()->ShowContextMenu(data);
506 return true; 510 return true;
507 } 511 }
508 512
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 sub_menu_items.Swap(output_items); 563 sub_menu_items.Swap(output_items);
560 } 564 }
561 565
562 void ContextMenuClientImpl::PopulateCustomMenuItems( 566 void ContextMenuClientImpl::PopulateCustomMenuItems(
563 const ContextMenu* default_menu, 567 const ContextMenu* default_menu,
564 WebContextMenuData* data) { 568 WebContextMenuData* data) {
565 PopulateSubMenuItems(default_menu->Items(), data->custom_items); 569 PopulateSubMenuItems(default_menu->Items(), data->custom_items);
566 } 570 }
567 571
568 } // namespace blink 572 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698