Commit b6aea068 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Change NGInlineNodeEditor::SetTextWithOffset() to use character diff instead of offsets

This patch changes |NGInlineNodeEditor| to reuse |ShapeResult| before
and after changed region by equality of substring instead of calculating
it from offsets to handle generated line break markers, e.g. leading
spaces in pre-wrap, and increase chance to reuse, e.g. replacing
"abc" with "abX", before this patch we reuse nothing but after this
patch we reuse "ab".

This patch also gets rid of |NGInlineNodeData::can_use_flag_editing_|
because we don't use it.

Bug: 1131315
Change-Id: Ic4471340245522ced6b2a4d3d8bf43b23a2ff077
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2437831
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812062}
parent 376b2999
......@@ -249,8 +249,11 @@ TEST_F(LayoutNGTextTest, SetTextWithOffsetDeleteWithGeneratedBreakOpportunity) {
Text& text = To<Text>(*GetElementById("target")->firstChild());
text.deleteData(2, 1, ASSERT_NO_EXCEPTION); // remove "\n"
EXPECT_EQ("LayoutText has NeedsCollectInlines",
GetItemsAsString(*text.GetLayoutObject()));
EXPECT_EQ(
"*{'ab', ShapeResult=0+2}\n"
"{''}\n"
"{''}\n",
GetItemsAsString(*text.GetLayoutObject()));
}
// http://crbug.com/1123251
......
......@@ -563,7 +563,6 @@ void NGInlineItemsBuilderTemplate<
// after a forced break.
if (item->Type() != NGInlineItem::kControl ||
text_[item->StartOffset()] != kNewlineCharacter) {
can_use_fast_editing_ = false;
AppendGeneratedBreakOpportunity(layout_object);
}
}
......@@ -1236,7 +1235,6 @@ void NGInlineItemsBuilderTemplate<
// |SegmentText()| will analyze the text and reset |is_bidi_enabled_| if it
// doesn't contain any RTL characters.
data->is_bidi_enabled_ = MayBeBidiEnabled();
data->can_use_fast_editing_ = CanUseFastEditing();
// Note: Even if |IsEmptyInline()| is true, |text_| isn't empty, e.g. it
// holds U+FFFC(ORC) for float or abspos.
data->has_line_even_if_empty_ =
......
......@@ -56,9 +56,6 @@ class NGInlineItemsBuilderTemplate {
// Returns whether the items contain any Bidi controls.
bool HasBidiControls() const { return has_bidi_controls_; }
// Returns whether the items contain any generated break opportunity.
bool CanUseFastEditing() const { return can_use_fast_editing_; }
// Returns if the inline node has no content. For example:
// <span></span> or <span><float></float></span>.
bool IsEmptyInline() const { return is_empty_inline_; }
......@@ -185,7 +182,6 @@ class NGInlineItemsBuilderTemplate {
bool has_bidi_controls_ = false;
bool has_ruby_ = false;
bool can_use_fast_editing_ = true;
bool is_empty_inline_ = true;
bool is_block_level_ = true;
bool changes_may_affect_earlier_lines_ = false;
......
......@@ -22,7 +22,6 @@ struct CORE_EXPORT NGInlineNodeData : NGInlineItemsData {
return static_cast<TextDirection>(base_direction_);
}
bool CanUseFastEditing() const { return can_use_fast_editing_; }
bool HasLineEvenIfEmpty() const { return has_line_even_if_empty_; }
bool HasRuby() const { return has_ruby_; }
bool IsEmptyInline() const { return is_empty_inline_; }
......@@ -59,9 +58,6 @@ struct CORE_EXPORT NGInlineNodeData : NGInlineItemsData {
unsigned is_bidi_enabled_ : 1;
unsigned base_direction_ : 1; // TextDirection
// True if we can use fast editing path.
unsigned can_use_fast_editing_ : 1;
// True if there are no inline item items and the associated block is root
// editable element or having "-internal-empty-line-height:fabricated",
// e.g. <div contenteditable></div>, <input type=button value="">
......
<!doctype html>
<script src="../../resources/ahem.js"></script>
<style>
.sample {
border: solid 1px; green;
font: 20px monospace;
padding: 5px;
white-space: pre-wrap;
}
</style>
<div class="sample" id="target">XYZ bc</div>
<br>
<div class="sample">XYZ bc</div>
<!doctype html>
<script src="../../resources/ahem.js"></script>
<style>
.sample {
border: solid 1px; green;
font: 20px monospace;
padding: 5px;
white-space: pre-wrap;
}
</style>
<div class="sample" id="target"> bc</div>
<br>
<div class="sample">XYZ bc</div>
<script>
const target = document.getElementById('target');
const text = target.firstChild;
document.body.offsetHeight;
text.insertData(0, 'XYZ');
</script>
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