Commit 16938949 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Ensure clean layout before calling LayoutText::CaretMaxOffset

LayoutText::CaretMaxOffset() requires clean layout, but currently can be
called from DeleteSelectionCommand when layout is dirty. This patch adds
layout update before the call sites to fix it.

Bug: 781698
Change-Id: I17b7596e93f025d61836e39cca4bf736713d3422
Reviewed-on: https://chromium-review.googlesource.com/778050
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517778}
parent cda3240b
...@@ -618,6 +618,7 @@ void DeleteSelectionCommand::HandleGeneralDelete(EditingState* editing_state) { ...@@ -618,6 +618,7 @@ void DeleteSelectionCommand::HandleGeneralDelete(EditingState* editing_state) {
return; return;
} }
GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
if (start_offset >= CaretMaxOffset(start_node) && start_node->IsTextNode()) { if (start_offset >= CaretMaxOffset(start_node) && start_node->IsTextNode()) {
Text* text = ToText(start_node); Text* text = ToText(start_node);
if (text->length() > (unsigned)CaretMaxOffset(start_node)) if (text->length() > (unsigned)CaretMaxOffset(start_node))
...@@ -698,6 +699,7 @@ void DeleteSelectionCommand::HandleGeneralDelete(EditingState* editing_state) { ...@@ -698,6 +699,7 @@ void DeleteSelectionCommand::HandleGeneralDelete(EditingState* editing_state) {
return; return;
node = next_node; node = next_node;
} else { } else {
GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
Node& n = NodeTraversal::LastWithinOrSelf(*node); Node& n = NodeTraversal::LastWithinOrSelf(*node);
if (downstream_end_.AnchorNode() == n && if (downstream_end_.AnchorNode() == n &&
downstream_end_.ComputeEditingOffset() >= CaretMaxOffset(&n)) { downstream_end_.ComputeEditingOffset() >= CaretMaxOffset(&n)) {
......
...@@ -1962,6 +1962,9 @@ Optional<unsigned> LayoutText::CaretOffsetForPosition( ...@@ -1962,6 +1962,9 @@ Optional<unsigned> LayoutText::CaretOffsetForPosition(
} }
int LayoutText::CaretMinOffset() const { int LayoutText::CaretMinOffset() const {
// TODO(crbug.com/781698): Add the following DCHECK.
// DCHECK(!GetDocument().NeedsLayoutTreeUpdate());
if (auto* mapping = GetNGOffsetMapping()) { if (auto* mapping = GetNGOffsetMapping()) {
const Position first_position = PositionForCaretOffset(0); const Position first_position = PositionForCaretOffset(0);
if (first_position.IsNull()) if (first_position.IsNull())
...@@ -1984,6 +1987,9 @@ int LayoutText::CaretMinOffset() const { ...@@ -1984,6 +1987,9 @@ int LayoutText::CaretMinOffset() const {
} }
int LayoutText::CaretMaxOffset() const { int LayoutText::CaretMaxOffset() const {
// TODO(crbug.com/781698): Add the following DCHECK.
// DCHECK(!GetDocument().NeedsLayoutTreeUpdate());
if (auto* mapping = GetNGOffsetMapping()) { if (auto* mapping = GetNGOffsetMapping()) {
const Position last_position = PositionForCaretOffset(TextLength()); const Position last_position = PositionForCaretOffset(TextLength());
if (last_position.IsNull()) if (last_position.IsNull())
......
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