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

Unified Diff: third_party/WebKit/Source/core/input/EventHandler.cpp

Issue 2880313002: Correct logic "Should ContextMenu target the selection?" (Closed)
Patch Set: Add a const 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/events/contextmenu-follows-focus.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/input/EventHandler.cpp
diff --git a/third_party/WebKit/Source/core/input/EventHandler.cpp b/third_party/WebKit/Source/core/input/EventHandler.cpp
index dc72afdad9c6949bd47ce1ce91fbc5316c683ffc..502b435461eb0f3cec894715916cc420310d9bd4 100644
--- a/third_party/WebKit/Source/core/input/EventHandler.cpp
+++ b/third_party/WebKit/Source/core/input/EventHandler.cpp
@@ -1802,6 +1802,14 @@ WebInputEventResult EventHandler::SendContextMenuEvent(
event, mev.GetHitTestResult().CanvasRegionId(), 0);
}
+static bool ShouldShowContextMenuAtSelection(const FrameSelection& selection) {
+ const VisibleSelection& visible_selection =
+ selection.ComputeVisibleSelectionInDOMTreeDeprecated();
+ if (!visible_selection.IsRange() && !visible_selection.RootEditableElement())
+ return false;
+ return selection.SelectionHasFocus();
+}
+
WebInputEventResult EventHandler::SendContextMenuEventForKey(
Element* override_target_element) {
FrameView* view = frame_->View();
@@ -1824,14 +1832,9 @@ WebInputEventResult EventHandler::SendContextMenuEventForKey(
Element* focused_element =
override_target_element ? override_target_element : doc->FocusedElement();
FrameSelection& selection = frame_->Selection();
- Position start =
- selection.ComputeVisibleSelectionInDOMTreeDeprecated().Start();
VisualViewport& visual_viewport = frame_->GetPage()->GetVisualViewport();
- if (!override_target_element && start.AnchorNode() && !selection.IsHidden() &&
- (selection.ComputeVisibleSelectionInDOMTreeDeprecated()
- .RootEditableElement() ||
- selection.ComputeVisibleSelectionInDOMTreeDeprecated().IsRange())) {
+ if (!override_target_element && ShouldShowContextMenuAtSelection(selection)) {
// TODO(editing-dev): Use of updateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details.
doc->UpdateStyleAndLayoutIgnorePendingStylesheets();
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/events/contextmenu-follows-focus.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698