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

Introduce Position::operator bool()

This patch introduces |operator bool()| for |PositionTemplate<T>| for writing
code like: |if (Position position = ...) { ... }|.

Change-Id: Ifb9061cb8ac95c25f7db03293c17080dba3ebc43
Reviewed-on: https://chromium-review.googlesource.com/939202Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539533}
parent f7424236
......@@ -73,6 +73,8 @@ class CORE_TEMPLATE_CLASS_EXPORT PositionTemplate {
PositionTemplate(const PositionTemplate&);
explicit operator bool() const { return IsNotNull(); }
PositionAnchorType AnchorType() const { return anchor_type_; }
bool IsAfterAnchor() const {
return anchor_type_ == PositionAnchorType::kAfterAnchor;
......
......@@ -141,6 +141,12 @@ TEST_F(PositionTest, NodeAsRangeLastNodeShadow) {
EXPECT_EQ(t1, PositionInFlatTree::AfterNode(*host).NodeAsRangeLastNode());
}
TEST_F(PositionTest, OperatorBool) {
SetBodyContent("foo");
EXPECT_FALSE(static_cast<bool>(Position()));
EXPECT_TRUE(static_cast<bool>(Position(GetDocument().body(), 0)));
}
TEST_F(PositionTest, ToPositionInFlatTreeWithActiveInsertionPoint) {
const char* body_content = "<p id='host'>00<b id='one'>11</b>22</p>";
const char* shadow_content =
......
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