Commit 324dfc6a authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Introduce FlatTreeTraversal::InclusiveAncestorsOf()

This patch Introduces FlatTreeTraversal::InclusiveAncestorsOf() as
|NodeTraversal|.

This patch is a preparation of the patch[1].

[1] http://crrev.com/c/737981: Introduce TextOffsetMapping to simplify
word/paragraph selection

Change-Id: I5ec0043887b0d72816bd2b0701a3e6cbe40ff28e
Reviewed-on: https://chromium-review.googlesource.com/742770
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512783}
parent b6454acb
...@@ -129,13 +129,15 @@ class CORE_EXPORT FlatTreeTraversal { ...@@ -129,13 +129,15 @@ class CORE_EXPORT FlatTreeTraversal {
// |NodeTraversal|: // |NodeTraversal|:
// - AncestorsOf() // - AncestorsOf()
// - DescendantsOf() // - DescendantsOf()
// - InclusiveAncestorsOf()
// - InclusiveDescendantsOf() // - InclusiveDescendantsOf()
// - StartsAt() // - StartsAt()
// - StartsAfter() // - StartsAfter()
static TraversalRange<TraversalChildrenIterator<FlatTreeTraversal>> static TraversalRange<TraversalChildrenIterator<FlatTreeTraversal>>
ChildrenOf(const Node&); ChildrenOf(const Node&);
static TraversalRange<TraversalInclusiveAncestorsIterator<FlatTreeTraversal>>
InclusiveAncestorsOf(const Node&);
private: private:
enum TraversalDirection { enum TraversalDirection {
kTraversalDirectionForward, kTraversalDirectionForward,
...@@ -344,6 +346,12 @@ FlatTreeTraversal::ChildrenOf(const Node& parent) { ...@@ -344,6 +346,12 @@ FlatTreeTraversal::ChildrenOf(const Node& parent) {
return TraversalRange<TraversalChildrenIterator<FlatTreeTraversal>>(&parent); return TraversalRange<TraversalChildrenIterator<FlatTreeTraversal>>(&parent);
} }
inline TraversalRange<TraversalInclusiveAncestorsIterator<FlatTreeTraversal>>
FlatTreeTraversal::InclusiveAncestorsOf(const Node& node) {
return TraversalRange<TraversalInclusiveAncestorsIterator<FlatTreeTraversal>>(
&node);
}
} // namespace blink } // namespace blink
#endif #endif
...@@ -330,6 +330,23 @@ TEST_F(FlatTreeTraversalTest, nextSkippingChildren) { ...@@ -330,6 +330,23 @@ TEST_F(FlatTreeTraversalTest, nextSkippingChildren) {
EXPECT_EQ(*m1, FlatTreeTraversal::PreviousSkippingChildren(*m2)); EXPECT_EQ(*m1, FlatTreeTraversal::PreviousSkippingChildren(*m2));
} }
TEST_F(FlatTreeTraversalTest, InclusiveAncestorsOf) {
SetupDocumentTree("<div><div><div id=sample></div></div></div>");
Element* const sample = GetDocument().getElementById("sample");
HeapVector<Member<Node>> expected_nodes;
for (Node* parent = sample; parent;
parent = FlatTreeTraversal::Parent(*parent)) {
expected_nodes.push_back(parent);
}
HeapVector<Member<Node>> actual_nodes;
for (Node& ancestor : FlatTreeTraversal::InclusiveAncestorsOf(*sample))
actual_nodes.push_back(&ancestor);
EXPECT_EQ(expected_nodes, actual_nodes);
}
// Test case for // Test case for
// - lastWithin // - lastWithin
// - lastWithinOrSelf // - lastWithinOrSelf
......
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