Commit 1ce19971 authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

Assert user selection start/end editability.

This patch introduces DCHECK in FrameSelection::SetSelectionDeprecated
so that user's selection start/end should have same editability for
code sanity.

Bug: 789870
Change-Id: Ia01192e61a9f27e2ddeef24e385b23a62a572174
Reviewed-on: https://chromium-review.googlesource.com/c/1325286Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606739}
parent 837d8ef4
......@@ -193,6 +193,19 @@ void FrameSelection::SetSelectionAndEndTyping(
.Build());
}
static void AssertUserSelection(const SelectionInDOMTree& selection,
const SetSelectionOptions& options) {
// User's selection start/end should have same editability.
#if DCHECK_IS_ON()
if (!options.ShouldShowHandle() &&
options.GetSetSelectionBy() != SetSelectionBy::kUser)
return;
Node* base_editable_root = RootEditableElementOf(selection.Base());
Node* extent_editable_root = RootEditableElementOf(selection.Extent());
DCHECK_EQ(base_editable_root, extent_editable_root) << selection;
#endif
}
bool FrameSelection::SetSelectionDeprecated(
const SelectionInDOMTree& new_selection,
const SetSelectionOptions& passed_options) {
......@@ -200,7 +213,7 @@ bool FrameSelection::SetSelectionDeprecated(
if (ShouldAlwaysUseDirectionalSelection(frame_)) {
options_builder.SetIsDirectional(true);
}
SetSelectionOptions options = options_builder.Build();
const SetSelectionOptions options = options_builder.Build();
if (granularity_strategy_ && !options.DoNotClearStrategy())
granularity_strategy_->Clear();
......@@ -221,8 +234,10 @@ bool FrameSelection::SetSelectionDeprecated(
if (!is_changed && is_handle_visible_ == should_show_handle &&
is_directional_ == options.IsDirectional())
return false;
if (is_changed)
if (is_changed) {
AssertUserSelection(new_selection, options);
selection_editor_->SetSelectionAndEndTyping(new_selection);
}
is_directional_ = options.IsDirectional();
should_shrink_next_tap_ = options.ShouldShrinkNextTap();
is_handle_visible_ = should_show_handle;
......
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