Commit 63b1a036 authored by xiaochengh's avatar xiaochengh Committed by Commit bot

Prune layout update calls from Editor::*appliedEditing

Editor used to update layout after applying commands for setting
frame selection. Now that setting frame selection no longer requires
clean layout, this patch removes these layout update calls.

BUG=590369
TEST=n/a; no behavior change

Review-Url: https://codereview.chromium.org/2729313002
Cr-Commit-Position: refs/heads/master@{#467890}
parent ea02813b
......@@ -916,13 +916,16 @@ static void DispatchEditableContentChangedEvents(Element* start_root,
Event::Create(EventTypeNames::webkitEditableContentChanged));
}
static VisibleSelection CorrectedVisibleSelection(
const VisibleSelection& passed_selection) {
static SelectionInDOMTree CorrectedSelectionAfterCommand(
const VisibleSelection& passed_selection,
Document* document) {
if (!passed_selection.Base().IsConnected() ||
!passed_selection.Extent().IsConnected())
return VisibleSelection();
DCHECK(!passed_selection.Base().GetDocument()->NeedsLayoutTreeUpdate());
return CreateVisibleSelection(passed_selection.AsSelection());
!passed_selection.Extent().IsConnected() ||
passed_selection.Base().GetDocument() != document ||
passed_selection.Base().GetDocument() !=
passed_selection.Extent().GetDocument())
return SelectionInDOMTree();
return passed_selection.AsSelection();
}
void Editor::AppliedEditing(CompositeEditCommand* cmd) {
......@@ -942,19 +945,12 @@ void Editor::AppliedEditing(CompositeEditCommand* cmd) {
undo_step->EndingRootEditableElement(), cmd->GetInputType(),
cmd->TextDataForInputEvent(), IsComposingFromCommand(cmd));
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details.
// The clean layout is consumed by |mostBackwardCaretPosition|, called through
// |changeSelectionAfterCommand|. In the long term, we should postpone visible
// selection canonicalization so that selection update does not need layout.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
const VisibleSelection& new_selection =
CorrectedVisibleSelection(cmd->EndingSelection());
const SelectionInDOMTree& new_selection = CorrectedSelectionAfterCommand(
cmd->EndingSelection(), GetFrame().GetDocument());
// Don't clear the typing style with this selection change. We do those things
// elsewhere if necessary.
ChangeSelectionAfterCommand(new_selection.AsSelection(), 0);
ChangeSelectionAfterCommand(new_selection, 0);
if (!cmd->PreservesTypingStyle())
ClearTypingStyle();
......@@ -976,7 +972,7 @@ void Editor::AppliedEditing(CompositeEditCommand* cmd) {
undo_stack_->RegisterUndoStep(last_edit_command_->EnsureUndoStep());
}
RespondToChangedContents(new_selection.Start());
RespondToChangedContents(new_selection.Base());
}
void Editor::UnappliedEditing(UndoStep* cmd) {
......@@ -989,22 +985,15 @@ void Editor::UnappliedEditing(UndoStep* cmd) {
InputEvent::InputType::kHistoryUndo, g_null_atom,
InputEvent::EventIsComposing::kNotComposing);
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details.
// In the long term, we should stop editing commands from storing
// VisibleSelections as starting and ending selections.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
const VisibleSelection& new_selection =
CorrectedVisibleSelection(cmd->StartingSelection());
DCHECK(new_selection.IsValidFor(*GetFrame().GetDocument())) << new_selection;
const SelectionInDOMTree& new_selection = CorrectedSelectionAfterCommand(
cmd->StartingSelection(), GetFrame().GetDocument());
ChangeSelectionAfterCommand(
new_selection.AsSelection(),
new_selection,
FrameSelection::kCloseTyping | FrameSelection::kClearTypingStyle);
last_edit_command_ = nullptr;
undo_stack_->RegisterRedoStep(cmd);
RespondToChangedContents(new_selection.Start());
RespondToChangedContents(new_selection.Base());
}
void Editor::ReappliedEditing(UndoStep* cmd) {
......@@ -1017,21 +1006,15 @@ void Editor::ReappliedEditing(UndoStep* cmd) {
InputEvent::InputType::kHistoryRedo, g_null_atom,
InputEvent::EventIsComposing::kNotComposing);
// TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
// needs to be audited. See http://crbug.com/590369 for more details.
// In the long term, we should stop editing commands from storing
// VisibleSelections as starting and ending selections.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
const VisibleSelection& new_selection =
CorrectedVisibleSelection(cmd->EndingSelection());
DCHECK(new_selection.IsValidFor(*GetFrame().GetDocument())) << new_selection;
const SelectionInDOMTree& new_selection = CorrectedSelectionAfterCommand(
cmd->EndingSelection(), GetFrame().GetDocument());
ChangeSelectionAfterCommand(
new_selection.AsSelection(),
new_selection,
FrameSelection::kCloseTyping | FrameSelection::kClearTypingStyle);
last_edit_command_ = nullptr;
undo_stack_->RegisterUndoStep(cmd);
RespondToChangedContents(new_selection.Start());
RespondToChangedContents(new_selection.Base());
}
Editor* Editor::Create(LocalFrame& frame) {
......
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