Commit f7459040 authored by Ryan Landay's avatar Ryan Landay Committed by Commit Bot

Add SelectionTemplate::ComputeRange()

We have several call sites that construct an EphemeralRange from a
SelectionTemplate by calling EphemeralRange(selection.ComputeStartPosition(),
selection.ComputeEndPosition()). This CL adds a helper method so these callsites
can just do selection.ComputeRange().

Change-Id: Iaf9a8d1fa461e45f3070204bc4fd28b2b5793169
Reviewed-on: https://chromium-review.googlesource.com/806439
Commit-Queue: Ryan Landay <rlanday@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avataryosin (OOO Dec 11 to Jan 8) <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521994}
parent b9ddd92d
......@@ -155,6 +155,13 @@ PositionTemplate<Strategy> SelectionTemplate<Strategy>::ComputeStartPosition()
return IsBaseFirst() ? base_ : extent_;
}
template <typename Strategy>
EphemeralRangeTemplate<Strategy> SelectionTemplate<Strategy>::ComputeRange()
const {
return EphemeralRangeTemplate<Strategy>(ComputeStartPosition(),
ComputeEndPosition());
}
template <typename Strategy>
bool SelectionTemplate<Strategy>::IsBaseFirst() const {
DCHECK(AssertValid());
......
......@@ -118,6 +118,7 @@ class CORE_EXPORT SelectionTemplate final {
PositionTemplate<Strategy> ComputeEndPosition() const;
PositionTemplate<Strategy> ComputeStartPosition() const;
EphemeralRangeTemplate<Strategy> ComputeRange() const;
// Returns |SelectionType| for |this| based on |base_| and |extent_|.
SelectionType Type() const;
......
......@@ -21,6 +21,7 @@ TEST_F(SelectionTest, defaultConstructor) {
EXPECT_TRUE(selection.IsNone());
EXPECT_EQ(Position(), selection.Base());
EXPECT_EQ(Position(), selection.Extent());
EXPECT_EQ(EphemeralRange(), selection.ComputeRange());
}
TEST_F(SelectionTest, IsBaseFirst) {
......@@ -100,6 +101,9 @@ TEST_F(SelectionTest, SetAsBacwardAndForward) {
EXPECT_FALSE(backward_selection.IsNone());
EXPECT_EQ(end, backward_selection.Base());
EXPECT_EQ(start, backward_selection.Extent());
EXPECT_EQ(start, backward_selection.ComputeStartPosition());
EXPECT_EQ(end, backward_selection.ComputeEndPosition());
EXPECT_EQ(range, backward_selection.ComputeRange());
EXPECT_EQ(TextAffinity::kDownstream, forward_selection.Affinity());
EXPECT_TRUE(forward_selection.IsBaseFirst());
......@@ -107,6 +111,9 @@ TEST_F(SelectionTest, SetAsBacwardAndForward) {
EXPECT_FALSE(forward_selection.IsNone());
EXPECT_EQ(start, forward_selection.Base());
EXPECT_EQ(end, forward_selection.Extent());
EXPECT_EQ(start, forward_selection.ComputeStartPosition());
EXPECT_EQ(end, forward_selection.ComputeEndPosition());
EXPECT_EQ(range, forward_selection.ComputeRange());
EXPECT_EQ(TextAffinity::kDownstream, collapsed_selection.Affinity());
EXPECT_TRUE(collapsed_selection.IsBaseFirst());
......@@ -114,6 +121,9 @@ TEST_F(SelectionTest, SetAsBacwardAndForward) {
EXPECT_FALSE(collapsed_selection.IsNone());
EXPECT_EQ(start, collapsed_selection.Base());
EXPECT_EQ(start, collapsed_selection.Extent());
EXPECT_EQ(start, collapsed_selection.ComputeStartPosition());
EXPECT_EQ(start, collapsed_selection.ComputeEndPosition());
EXPECT_EQ(EphemeralRange(start, start), collapsed_selection.ComputeRange());
}
} // namespace blink
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