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

Don't create VisiblePosition and VisibleSelection in...

Don't create VisiblePosition and VisibleSelection in FrameSelection::SelectFrameElementInParentIfFullySelected()

This patch refactors the function's selection setting and validation
part, so that:

- It stops the problematic pattern of creating VisibleSelection before
  focusing parent frame, which may invalidate the VS

- It no longer creates VisiblePosition and VisibleSelection for creating
  the selection. This is because for a frame owner element, the range
  [before_node, after_node] is already a canonicalized range, on which
  creating VP or VS is unnecessary.

Bug: 657237, 897983
Change-Id: I5b046047071a4af7454cc1bfef52a457fe49d9c2
Reviewed-on: https://chromium-review.googlesource.com/c/1298179Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603169}
parent edede786
......@@ -652,33 +652,19 @@ void FrameSelection::SelectFrameElementInParentIfFullySelected() {
if (!blink::HasEditableStyle(*owner_element_parent))
return;
// Create compute positions before and after the element.
unsigned owner_element_node_index = owner_element->NodeIndex();
VisiblePosition before_owner_element = CreateVisiblePosition(
Position(owner_element_parent, owner_element_node_index));
VisiblePosition after_owner_element = CreateVisiblePosition(
Position(owner_element_parent, owner_element_node_index + 1),
TextAffinity::kUpstreamIfPossible);
SelectionInDOMTree::Builder builder;
builder
.SetBaseAndExtentDeprecated(before_owner_element.DeepEquivalent(),
after_owner_element.DeepEquivalent())
.SetAffinity(before_owner_element.Affinity());
// Focus on the parent frame, and then select from before this element to
// after.
VisibleSelection new_selection = CreateVisibleSelection(builder.Build());
// TODO(yosin): We should call |FocusController::setFocusedFrame()| before
// |createVisibleSelection()|.
page->GetFocusController().SetFocusedFrame(parent);
// setFocusedFrame can dispatch synchronous focus/blur events. The document
// SetFocusedFrame can dispatch synchronous focus/blur events. The document
// tree might be modified.
if (!new_selection.IsNone() &&
new_selection.IsValidFor(*(ToLocalFrame(parent)->GetDocument()))) {
ToLocalFrame(parent)->Selection().SetSelectionAndEndTyping(
new_selection.AsSelection());
}
if (!owner_element->isConnected() ||
owner_element->GetDocument() != ToLocalFrame(parent)->GetDocument())
return;
ToLocalFrame(parent)->Selection().SetSelectionAndEndTyping(
SelectionInDOMTree::Builder()
.SetBaseAndExtent(Position::BeforeNode(*owner_element),
Position::AfterNode(*owner_element))
.Build());
}
// Returns a shadow tree node for legacy shadow trees, a child of the
......
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