Commit 2e91966d authored by xiaochengh's avatar xiaochengh Committed by Commit bot

Make EnabledInEditableText return false for user-triggered command and unfocused selection

Certain editing commands shouldn't be enabled when they are user-triggered and
the selection doesn't have focus. This patch adds checking of
FrameSelection::SelectionHasFocus() in EnabledInEditableText to fix
the behavior of these commands:

BackwardDelete
DeleteBackward
DeleteBackwardByDecomposingPreviousCharacter
DeleteForward
DeleteToBeginningOfLine
DeleteToBeginningOfParagraph
DeleteToEndOfLine
DeleteToEndOfParagraph
DeleteToMark
DeleteWordBackward
DeleteWordForward
ForwardDelete
IgnoreSpelling
InsertBacktab
InsertHTML
InsertLineBreak
InsertNewline
InsertParagraph
InsertTab
InsertText
MoveBackward
MoveDown
MoveForward
MoveLeft
MovePageDown
MovePageUp
MoveParagraphBackward
MoveParagraphForward
MoveRight
MoveToBeginningOfDocument
MoveToBeginningOfLine
MoveToBeginningOfParagraph
MoveToBeginningOfSentence
MoveToEndOfDocument
MoveToEndOfLine
MoveToEndOfParagraph
MoveToEndOfSentence
MoveToLeftEndOfLine
MoveToLeftEndOfLineAndModifySelection
MoveToRightEndOfLine
MoveToRightEndOfLineAndModifySelection
MoveUp
MoveWordBackward
MoveWordForward
MoveWordLeft
MoveWordRight
Yank
YankAndSelect

BUG=713607, 722925
TEST=editing/selection/arrow_key_with_unfocused_selection.html

Review-Url: https://codereview.chromium.org/2886933002
Cr-Commit-Position: refs/heads/master@{#472284}
parent be588080
<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
// Regression tests for crbug.com/713607.
test(() => {
assert_exists(window, 'eventSender', 'This test requires eventSender');
assert_selection(
[
'<textarea>^text|</textarea>',
'<a href="http://www.example.com/">link</a>'
].join(''),
selection => {
const link = selection.document.querySelector('a');
link.focus();
eventSender.keyDown('ArrowLeft');
assert_equals(selection.document.activeElement, link);
},
[
'|<textarea>text</textarea>',
'<a href="http://www.example.com/">link</a>'
].join(''));
}, 'Press left arrow key with unfocused selection in text control');
test(() => {
assert_exists(window, 'eventSender', 'This test requires eventSender');
assert_selection(
[
'<div contenteditable>^text|</div>',
'<a href="http://www.example.com/">link</a>'
].join(''),
selection => {
const link = selection.document.querySelector('a');
link.focus();
eventSender.keyDown('ArrowLeft');
assert_equals(selection.document.activeElement, link);
},
[
'<div contenteditable>^text|</div>',
'<a href="http://www.example.com/">link</a>'
].join(''));
}, 'Press left arrow key with unfocused selection in contenteditable div');
</script>
......@@ -2051,8 +2051,11 @@ static bool EnabledCut(LocalFrame& frame, Event*, EditorCommandSource source) {
static bool EnabledInEditableText(LocalFrame& frame,
Event* event,
EditorCommandSource) {
EditorCommandSource source) {
frame.GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
if (source == kCommandFromMenuOrKeyBinding &&
!frame.Selection().SelectionHasFocus())
return false;
return frame.GetEditor().SelectionForCommand(event).RootEditableElement();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment