Commit a018bf65 authored by Anupam Snigdha's avatar Anupam Snigdha Committed by Chromium LUCI CQ

Reduce usage of VisiblePosition in TypingCommand.

This CL is a continuation of crrev.com/c/2619002. We are planning to
remove |VisiblePosition| usages in editing commands and selection
because it leads to issues related to positions being snapped to
incorrect location.

Bug: 669811
Change-Id: I2f1f668033d3e1bc2d4209c9610878beaefd2c0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2643708
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845964}
parent ca4d94f4
...@@ -144,9 +144,13 @@ SelectionInDOMTree CreateSelection(const wtf_size_t start, ...@@ -144,9 +144,13 @@ SelectionInDOMTree CreateSelection(const wtf_size_t start,
return selection; return selection;
} }
bool CanAppendNewLineFeedToSelection(const VisibleSelection& selection, bool CanAppendNewLineFeedToSelection(const SelectionInDOMTree& selection,
EditingState* editing_state) { EditingState* editing_state) {
Element* element = selection.RootEditableElement(); // We use SelectionForUndoStep because it is resilient to DOM
// mutation.
const SelectionForUndoStep& selection_as_undo_step =
SelectionForUndoStep::From(selection);
Element* element = selection_as_undo_step.RootEditableElement();
if (!element) if (!element)
return false; return false;
...@@ -154,7 +158,7 @@ bool CanAppendNewLineFeedToSelection(const VisibleSelection& selection, ...@@ -154,7 +158,7 @@ bool CanAppendNewLineFeedToSelection(const VisibleSelection& selection,
auto* event = MakeGarbageCollected<BeforeTextInsertedEvent>(String("\n")); auto* event = MakeGarbageCollected<BeforeTextInsertedEvent>(String("\n"));
element->DispatchEvent(*event); element->DispatchEvent(*event);
// event may invalidate frame or selection // event may invalidate frame or selection
if (IsValidDocument(document) && selection.IsValidFor(document)) if (IsValidDocument(document) && selection_as_undo_step.IsValidFor(document))
return event->GetText().length(); return event->GetText().length();
// editing/inserting/webkitBeforeTextInserted-removes-frame.html // editing/inserting/webkitBeforeTextInserted-removes-frame.html
// and // and
...@@ -723,7 +727,8 @@ void TypingCommand::InsertTextRunWithoutNewlines(const String& text, ...@@ -723,7 +727,8 @@ void TypingCommand::InsertTextRunWithoutNewlines(const String& text,
} }
void TypingCommand::InsertLineBreak(EditingState* editing_state) { void TypingCommand::InsertLineBreak(EditingState* editing_state) {
if (!CanAppendNewLineFeedToSelection(EndingVisibleSelection(), editing_state)) if (!CanAppendNewLineFeedToSelection(EndingSelection().AsSelection(),
editing_state))
return; return;
ApplyCommandToComposite( ApplyCommandToComposite(
...@@ -735,7 +740,8 @@ void TypingCommand::InsertLineBreak(EditingState* editing_state) { ...@@ -735,7 +740,8 @@ void TypingCommand::InsertLineBreak(EditingState* editing_state) {
} }
void TypingCommand::InsertParagraphSeparator(EditingState* editing_state) { void TypingCommand::InsertParagraphSeparator(EditingState* editing_state) {
if (!CanAppendNewLineFeedToSelection(EndingVisibleSelection(), editing_state)) if (!CanAppendNewLineFeedToSelection(EndingSelection().AsSelection(),
editing_state))
return; return;
ApplyCommandToComposite( ApplyCommandToComposite(
......
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