Skip to content

Commit

Permalink
[editing] Unify PositionIterator constructor
Browse files Browse the repository at this point in the history
This patch unifies `PositionIterator` constructor to simplify source
code for improving code health.

Bug: 1132412
Change-Id: I82cd47b3d3d8372c645c32e4c2a55535cafc6ac8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4033055
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: Koji Ishii <kojii@chromium.org>
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: Kent Tamura <tkent@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1072639}
  • Loading branch information
yosinch authored and Chromium LUCI CQ committed Nov 17, 2022
1 parent 18e8931 commit 6ade24b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
32 changes: 12 additions & 20 deletions third_party/blink/renderer/core/editing/position_iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ static constexpr int kInvalidOffset = -1;

template <typename Strategy>
PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm(
Node* anchor_node,
int offset_in_anchor)
: anchor_node_(anchor_node),
node_after_position_in_anchor_(
Strategy::ChildAt(*anchor_node, offset_in_anchor)),
offset_in_anchor_(node_after_position_in_anchor_ ? 0 : offset_in_anchor),
depth_to_anchor_node_(0),
dom_tree_version_(anchor_node->GetDocument().DomTreeVersion()) {
for (Node* node = SelectableParentOf<Strategy>(*anchor_node); node;
const PositionTemplate<Strategy>& pos) {
if (pos.IsNull())
return;
anchor_node_ = pos.AnchorNode();
const int offset_in_anchor = pos.ComputeEditingOffset();

node_after_position_in_anchor_ =
Strategy::ChildAt(*anchor_node_, offset_in_anchor);
offset_in_anchor_ = node_after_position_in_anchor_ ? 0 : offset_in_anchor;
dom_tree_version_ = anchor_node_->GetDocument().DomTreeVersion();

for (Node* node = SelectableParentOf<Strategy>(*anchor_node_); node;
node = SelectableParentOf<Strategy>(*node)) {
// Each offsets_in_anchor_node_[offset] should be an index of node in
// parent, but delay to calculate the index until it is needed for
Expand All @@ -78,17 +81,6 @@ PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm(
if (node_after_position_in_anchor_)
offsets_in_anchor_node_.push_back(offset_in_anchor);
}
template <typename Strategy>
PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm(
const PositionTemplate<Strategy>& pos)
: PositionIteratorAlgorithm(
pos.IsNull()
? PositionIteratorAlgorithm()
: PositionIteratorAlgorithm(pos.AnchorNode(),
pos.ComputeEditingOffset())) {}

template <typename Strategy>
PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm() = default;

template <typename Strategy>
PositionTemplate<Strategy>
Expand Down
3 changes: 0 additions & 3 deletions third_party/blink/renderer/core/editing/position_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ class PositionIteratorAlgorithm {
bool AtEndOfNode() const;

private:
PositionIteratorAlgorithm(Node* anchor_node, int offset_in_anchor_node);
PositionIteratorAlgorithm();

bool IsValid() const {
return !anchor_node_ ||
dom_tree_version_ == anchor_node_->GetDocument().DomTreeVersion();
Expand Down

0 comments on commit 6ade24b

Please sign in to comment.