2015-07-22 02:36:08 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2017-10-28 02:10:06 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2015-07-22 02:36:08 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_layers_TreeTraversal_h
|
|
|
|
#define mozilla_layers_TreeTraversal_h
|
|
|
|
|
2015-11-16 21:54:12 +03:00
|
|
|
#include <queue>
|
|
|
|
|
2015-07-22 02:36:08 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
|
Bug 1199798 - Use more generic tree traversal algorithms in APZCTreeManager. r=botond
Extend the tree traversal algorithms in TreeTraversal.h, and use them
instead of manual loops in APZCTreeManager.
- Create function ForEachNode(), which calls a function on each node
of a tree. The function must return a TraversalFlag to indicate
whether the node's children should be visited or skipped.
- Modify DepthFirstSearch() and BreadthFirstSearch() to operate on
pointers that are not (necessarily) const. This makes them more
general.
- Refactor functions in APZCTreeManager: Collect, FlushRepaints,
FlushRepaintsRecursively, FlushPendingRepaint,
FlushPendingRepaintRecursively, UpdateZoomConstraints,
UpdateZoomConstraintsRecursively, ClearTree, FindScrollNode.
--HG--
extra : rebase_source : e7a740a9833ba49b1d41849bb43ce9077d42bc07
extra : source : ef6f195f2259e103f0c1979a5f4ebb5a8601b15d
2015-11-06 20:31:36 +03:00
|
|
|
/*
|
2016-01-25 15:04:13 +03:00
|
|
|
* Returned by |aPostAction| and |aPreAction| in ForEachNode, indicates
|
|
|
|
* the behavior to follow either action:
|
|
|
|
*
|
|
|
|
* TraversalFlag::Skip - the node's children are not traversed. If this
|
|
|
|
* flag is returned by |aPreAction|, |aPostAction| is skipped for the
|
|
|
|
* current node, as well.
|
|
|
|
* TraversalFlag::Continue - traversal continues normally.
|
|
|
|
* TraversalFlag::Abort - traversal stops immediately.
|
Bug 1199798 - Use more generic tree traversal algorithms in APZCTreeManager. r=botond
Extend the tree traversal algorithms in TreeTraversal.h, and use them
instead of manual loops in APZCTreeManager.
- Create function ForEachNode(), which calls a function on each node
of a tree. The function must return a TraversalFlag to indicate
whether the node's children should be visited or skipped.
- Modify DepthFirstSearch() and BreadthFirstSearch() to operate on
pointers that are not (necessarily) const. This makes them more
general.
- Refactor functions in APZCTreeManager: Collect, FlushRepaints,
FlushRepaintsRecursively, FlushPendingRepaint,
FlushPendingRepaintRecursively, UpdateZoomConstraints,
UpdateZoomConstraintsRecursively, ClearTree, FindScrollNode.
--HG--
extra : rebase_source : e7a740a9833ba49b1d41849bb43ce9077d42bc07
extra : source : ef6f195f2259e103f0c1979a5f4ebb5a8601b15d
2015-11-06 20:31:36 +03:00
|
|
|
*/
|
2016-01-25 15:04:13 +03:00
|
|
|
enum class TraversalFlag { Skip, Continue, Abort };
|
Bug 1199798 - Use more generic tree traversal algorithms in APZCTreeManager. r=botond
Extend the tree traversal algorithms in TreeTraversal.h, and use them
instead of manual loops in APZCTreeManager.
- Create function ForEachNode(), which calls a function on each node
of a tree. The function must return a TraversalFlag to indicate
whether the node's children should be visited or skipped.
- Modify DepthFirstSearch() and BreadthFirstSearch() to operate on
pointers that are not (necessarily) const. This makes them more
general.
- Refactor functions in APZCTreeManager: Collect, FlushRepaints,
FlushRepaintsRecursively, FlushPendingRepaint,
FlushPendingRepaintRecursively, UpdateZoomConstraints,
UpdateZoomConstraintsRecursively, ClearTree, FindScrollNode.
--HG--
extra : rebase_source : e7a740a9833ba49b1d41849bb43ce9077d42bc07
extra : source : ef6f195f2259e103f0c1979a5f4ebb5a8601b15d
2015-11-06 20:31:36 +03:00
|
|
|
|
2016-03-10 12:20:40 +03:00
|
|
|
/*
|
|
|
|
* Iterator types to be specified in traversal function calls:
|
|
|
|
*
|
|
|
|
* ForwardIterator - for nodes using GetFirstChild() and GetNextSibling()
|
|
|
|
* ReverseIterator - for nodes using GetLastChild() and GetPrevSibling()
|
|
|
|
*/
|
|
|
|
class ForwardIterator
|
|
|
|
{
|
|
|
|
public:
|
2016-09-22 19:31:26 +03:00
|
|
|
template <typename Node>
|
|
|
|
static Node* FirstChild(Node* n) {
|
|
|
|
return n->GetFirstChild();
|
|
|
|
}
|
2016-03-10 12:20:40 +03:00
|
|
|
template <typename Node>
|
|
|
|
static Node* NextSibling(Node* n) {
|
|
|
|
return n->GetNextSibling();
|
|
|
|
}
|
|
|
|
template <typename Node>
|
2016-09-22 19:31:26 +03:00
|
|
|
static Node FirstChild(Node n) {
|
|
|
|
return n.GetFirstChild();
|
|
|
|
}
|
|
|
|
template <typename Node>
|
|
|
|
static Node NextSibling(Node n) {
|
|
|
|
return n.GetNextSibling();
|
2016-03-10 12:20:40 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
class ReverseIterator
|
|
|
|
{
|
|
|
|
public:
|
2016-09-22 19:31:26 +03:00
|
|
|
template <typename Node>
|
|
|
|
static Node* FirstChild(Node* n) {
|
|
|
|
return n->GetLastChild();
|
|
|
|
}
|
2016-03-10 12:20:40 +03:00
|
|
|
template <typename Node>
|
|
|
|
static Node* NextSibling(Node* n) {
|
|
|
|
return n->GetPrevSibling();
|
|
|
|
}
|
|
|
|
template <typename Node>
|
2016-09-22 19:31:26 +03:00
|
|
|
static Node FirstChild(Node n) {
|
|
|
|
return n.GetLastChild();
|
|
|
|
}
|
|
|
|
template <typename Node>
|
|
|
|
static Node NextSibling(Node n) {
|
|
|
|
return n.GetPrevSibling();
|
2016-03-10 12:20:40 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-22 02:36:08 +03:00
|
|
|
/*
|
2016-01-25 15:04:13 +03:00
|
|
|
* Do a depth-first traversal of the tree rooted at |aRoot|, performing
|
|
|
|
* |aPreAction| before traversal of children and |aPostAction| after.
|
2015-07-22 02:36:08 +03:00
|
|
|
*
|
2016-01-25 15:04:13 +03:00
|
|
|
* Returns true if traversal aborted, false if continued normally. If
|
|
|
|
* TraversalFlag::Skip is returned in |aPreAction|, then |aPostAction|
|
|
|
|
* is not performed.
|
2016-03-10 12:20:40 +03:00
|
|
|
*
|
|
|
|
* |Iterator| should have static methods named NextSibling() and FirstChild()
|
2016-09-22 19:31:26 +03:00
|
|
|
* that accept an argument of type Node. For convenience, classes
|
2016-03-10 12:20:40 +03:00
|
|
|
* |ForwardIterator| and |ReverseIterator| are provided which implement these
|
|
|
|
* methods as GetNextSibling()/GetFirstChild() and GetPrevSibling()/GetLastChild(),
|
|
|
|
* respectively.
|
2015-07-22 02:36:08 +03:00
|
|
|
*/
|
2016-03-10 12:20:40 +03:00
|
|
|
template <typename Iterator, typename Node, typename PreAction, typename PostAction>
|
2016-09-22 19:31:26 +03:00
|
|
|
static auto ForEachNode(Node aRoot, const PreAction& aPreAction, const PostAction& aPostAction) ->
|
2016-01-25 15:04:13 +03:00
|
|
|
typename EnableIf<IsSame<decltype(aPreAction(aRoot)), TraversalFlag>::value &&
|
|
|
|
IsSame<decltype(aPostAction(aRoot)),TraversalFlag>::value, bool>::Type
|
2015-07-22 02:36:08 +03:00
|
|
|
{
|
|
|
|
if (!aRoot) {
|
2016-01-25 15:04:13 +03:00
|
|
|
return false;
|
2015-07-22 02:36:08 +03:00
|
|
|
}
|
|
|
|
|
2016-01-25 15:04:13 +03:00
|
|
|
TraversalFlag result = aPreAction(aRoot);
|
2015-07-22 02:36:08 +03:00
|
|
|
|
2016-01-25 15:04:13 +03:00
|
|
|
if (result == TraversalFlag::Abort) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-07-22 02:36:08 +03:00
|
|
|
|
2016-01-25 15:04:13 +03:00
|
|
|
if (result == TraversalFlag::Continue) {
|
2016-09-22 19:31:26 +03:00
|
|
|
for (Node child = Iterator::FirstChild(aRoot);
|
2015-07-22 02:36:08 +03:00
|
|
|
child;
|
2016-03-10 12:20:40 +03:00
|
|
|
child = Iterator::NextSibling(child)) {
|
|
|
|
bool abort = ForEachNode<Iterator>(child, aPreAction, aPostAction);
|
2016-01-25 15:04:13 +03:00
|
|
|
if (abort) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = aPostAction(aRoot);
|
|
|
|
|
|
|
|
if (result == TraversalFlag::Abort) {
|
|
|
|
return true;
|
2015-07-22 02:36:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-25 15:04:13 +03:00
|
|
|
return false;
|
2015-07-22 02:36:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-01-25 15:04:13 +03:00
|
|
|
* Do a depth-first traversal of the tree rooted at |aRoot|, performing
|
|
|
|
* |aPreAction| before traversal of children and |aPostAction| after.
|
|
|
|
*/
|
2016-03-10 12:20:40 +03:00
|
|
|
template <typename Iterator, typename Node, typename PreAction, typename PostAction>
|
2016-09-22 19:31:26 +03:00
|
|
|
static auto ForEachNode(Node aRoot, const PreAction& aPreAction, const PostAction& aPostAction) ->
|
2016-01-25 15:04:13 +03:00
|
|
|
typename EnableIf<IsSame<decltype(aPreAction(aRoot)), void>::value &&
|
|
|
|
IsSame<decltype(aPostAction(aRoot)),void>::value, void>::Type
|
|
|
|
{
|
|
|
|
if (!aRoot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aPreAction(aRoot);
|
|
|
|
|
2016-09-22 19:31:26 +03:00
|
|
|
for (Node child = Iterator::FirstChild(aRoot);
|
2016-01-25 15:04:13 +03:00
|
|
|
child;
|
2016-03-10 12:20:40 +03:00
|
|
|
child = Iterator::NextSibling(child)) {
|
|
|
|
ForEachNode<Iterator>(child, aPreAction, aPostAction);
|
2016-01-25 15:04:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
aPostAction(aRoot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ForEachNode pre-order traversal, using TraversalFlag.
|
|
|
|
*/
|
2016-03-10 12:20:40 +03:00
|
|
|
template <typename Iterator, typename Node, typename PreAction>
|
2016-09-22 19:31:26 +03:00
|
|
|
auto ForEachNode(Node aRoot, const PreAction& aPreAction) ->
|
2016-01-25 15:04:13 +03:00
|
|
|
typename EnableIf<IsSame<decltype(aPreAction(aRoot)), TraversalFlag>::value, bool>::Type
|
|
|
|
{
|
2016-09-22 19:31:26 +03:00
|
|
|
return ForEachNode<Iterator>(aRoot, aPreAction, [](Node aNode){ return TraversalFlag::Continue; });
|
2016-01-25 15:04:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ForEachNode pre-order, not using TraversalFlag.
|
|
|
|
*/
|
2016-03-10 12:20:40 +03:00
|
|
|
template <typename Iterator, typename Node, typename PreAction>
|
2016-09-22 19:31:26 +03:00
|
|
|
auto ForEachNode(Node aRoot, const PreAction& aPreAction) ->
|
2016-01-25 15:04:13 +03:00
|
|
|
typename EnableIf<IsSame<decltype(aPreAction(aRoot)), void>::value, void>::Type
|
|
|
|
{
|
2016-09-22 19:31:26 +03:00
|
|
|
ForEachNode<Iterator>(aRoot, aPreAction, [](Node aNode){});
|
2016-01-25 15:04:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ForEachNode post-order traversal, using TraversalFlag.
|
|
|
|
*/
|
2016-03-10 12:20:40 +03:00
|
|
|
template <typename Iterator, typename Node, typename PostAction>
|
2016-09-22 19:31:26 +03:00
|
|
|
auto ForEachNodePostOrder(Node aRoot, const PostAction& aPostAction) ->
|
2016-01-25 15:04:13 +03:00
|
|
|
typename EnableIf<IsSame<decltype(aPostAction(aRoot)), TraversalFlag>::value, bool>::Type
|
|
|
|
{
|
2016-09-22 19:31:26 +03:00
|
|
|
return ForEachNode<Iterator>(aRoot, [](Node aNode){ return TraversalFlag::Continue; }, aPostAction);
|
2016-01-25 15:04:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ForEachNode post-order, not using TraversalFlag.
|
|
|
|
*/
|
2016-03-10 12:20:40 +03:00
|
|
|
template <typename Iterator, typename Node, typename PostAction>
|
2016-09-22 19:31:26 +03:00
|
|
|
auto ForEachNodePostOrder(Node aRoot, const PostAction& aPostAction) ->
|
2016-01-25 15:04:13 +03:00
|
|
|
typename EnableIf<IsSame<decltype(aPostAction(aRoot)), void>::value, void>::Type
|
|
|
|
{
|
2016-09-22 19:31:26 +03:00
|
|
|
ForEachNode<Iterator>(aRoot, [](Node aNode){}, aPostAction);
|
2016-01-25 15:04:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do a breadth-first search of the tree rooted at |aRoot|, and return the
|
2015-07-22 02:36:08 +03:00
|
|
|
* first visited node that satisfies |aCondition|, or nullptr if no such node
|
|
|
|
* was found.
|
|
|
|
*
|
2016-09-22 19:31:26 +03:00
|
|
|
* |Iterator| and |Node| have all the same requirements seen in ForEachNode()'s
|
|
|
|
* definition, but in addition to those, |Node| must be able to express a null
|
|
|
|
* value, returned from Node()
|
2015-07-22 02:36:08 +03:00
|
|
|
*/
|
2016-03-10 12:20:40 +03:00
|
|
|
template <typename Iterator, typename Node, typename Condition>
|
2016-09-22 19:31:26 +03:00
|
|
|
Node BreadthFirstSearch(Node aRoot, const Condition& aCondition)
|
2015-07-22 02:36:08 +03:00
|
|
|
{
|
|
|
|
if (!aRoot) {
|
2016-09-22 19:31:26 +03:00
|
|
|
return Node();
|
2015-07-22 02:36:08 +03:00
|
|
|
}
|
|
|
|
|
2016-09-22 19:31:26 +03:00
|
|
|
std::queue<Node> queue;
|
2016-01-25 15:04:13 +03:00
|
|
|
queue.push(aRoot);
|
|
|
|
while (!queue.empty()) {
|
2016-09-22 19:31:26 +03:00
|
|
|
Node node = queue.front();
|
2016-01-25 15:04:13 +03:00
|
|
|
queue.pop();
|
2015-07-22 02:36:08 +03:00
|
|
|
|
|
|
|
if (aCondition(node)) {
|
2016-01-25 15:04:13 +03:00
|
|
|
return node;
|
2015-07-22 02:36:08 +03:00
|
|
|
}
|
|
|
|
|
2016-09-22 19:31:26 +03:00
|
|
|
for (Node child = Iterator::FirstChild(node);
|
2015-07-22 02:36:08 +03:00
|
|
|
child;
|
2016-03-10 12:20:40 +03:00
|
|
|
child = Iterator::NextSibling(child)) {
|
2016-01-25 15:04:13 +03:00
|
|
|
queue.push(child);
|
2015-07-22 02:36:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-22 19:31:26 +03:00
|
|
|
return Node();
|
2015-07-22 02:36:08 +03:00
|
|
|
}
|
|
|
|
|
Bug 1199798 - Use more generic tree traversal algorithms in APZCTreeManager. r=botond
Extend the tree traversal algorithms in TreeTraversal.h, and use them
instead of manual loops in APZCTreeManager.
- Create function ForEachNode(), which calls a function on each node
of a tree. The function must return a TraversalFlag to indicate
whether the node's children should be visited or skipped.
- Modify DepthFirstSearch() and BreadthFirstSearch() to operate on
pointers that are not (necessarily) const. This makes them more
general.
- Refactor functions in APZCTreeManager: Collect, FlushRepaints,
FlushRepaintsRecursively, FlushPendingRepaint,
FlushPendingRepaintRecursively, UpdateZoomConstraints,
UpdateZoomConstraintsRecursively, ClearTree, FindScrollNode.
--HG--
extra : rebase_source : e7a740a9833ba49b1d41849bb43ce9077d42bc07
extra : source : ef6f195f2259e103f0c1979a5f4ebb5a8601b15d
2015-11-06 20:31:36 +03:00
|
|
|
/*
|
2016-01-25 15:04:13 +03:00
|
|
|
* Do a pre-order, depth-first search of the tree rooted at |aRoot|, and
|
|
|
|
* return the first visited node that satisfies |aCondition|, or nullptr
|
|
|
|
* if no such node was found.
|
Bug 1199798 - Use more generic tree traversal algorithms in APZCTreeManager. r=botond
Extend the tree traversal algorithms in TreeTraversal.h, and use them
instead of manual loops in APZCTreeManager.
- Create function ForEachNode(), which calls a function on each node
of a tree. The function must return a TraversalFlag to indicate
whether the node's children should be visited or skipped.
- Modify DepthFirstSearch() and BreadthFirstSearch() to operate on
pointers that are not (necessarily) const. This makes them more
general.
- Refactor functions in APZCTreeManager: Collect, FlushRepaints,
FlushRepaintsRecursively, FlushPendingRepaint,
FlushPendingRepaintRecursively, UpdateZoomConstraints,
UpdateZoomConstraintsRecursively, ClearTree, FindScrollNode.
--HG--
extra : rebase_source : e7a740a9833ba49b1d41849bb43ce9077d42bc07
extra : source : ef6f195f2259e103f0c1979a5f4ebb5a8601b15d
2015-11-06 20:31:36 +03:00
|
|
|
*
|
2016-09-22 19:31:26 +03:00
|
|
|
* |Iterator| and |Node| have all the same requirements seen in ForEachNode()'s
|
|
|
|
* definition, but in addition to those, |Node| must be able to express a null
|
|
|
|
* value, returned from Node().
|
Bug 1199798 - Use more generic tree traversal algorithms in APZCTreeManager. r=botond
Extend the tree traversal algorithms in TreeTraversal.h, and use them
instead of manual loops in APZCTreeManager.
- Create function ForEachNode(), which calls a function on each node
of a tree. The function must return a TraversalFlag to indicate
whether the node's children should be visited or skipped.
- Modify DepthFirstSearch() and BreadthFirstSearch() to operate on
pointers that are not (necessarily) const. This makes them more
general.
- Refactor functions in APZCTreeManager: Collect, FlushRepaints,
FlushRepaintsRecursively, FlushPendingRepaint,
FlushPendingRepaintRecursively, UpdateZoomConstraints,
UpdateZoomConstraintsRecursively, ClearTree, FindScrollNode.
--HG--
extra : rebase_source : e7a740a9833ba49b1d41849bb43ce9077d42bc07
extra : source : ef6f195f2259e103f0c1979a5f4ebb5a8601b15d
2015-11-06 20:31:36 +03:00
|
|
|
*/
|
2016-03-10 12:20:40 +03:00
|
|
|
template <typename Iterator, typename Node, typename Condition>
|
2016-09-22 19:31:26 +03:00
|
|
|
Node DepthFirstSearch(Node aRoot, const Condition& aCondition)
|
Bug 1199798 - Use more generic tree traversal algorithms in APZCTreeManager. r=botond
Extend the tree traversal algorithms in TreeTraversal.h, and use them
instead of manual loops in APZCTreeManager.
- Create function ForEachNode(), which calls a function on each node
of a tree. The function must return a TraversalFlag to indicate
whether the node's children should be visited or skipped.
- Modify DepthFirstSearch() and BreadthFirstSearch() to operate on
pointers that are not (necessarily) const. This makes them more
general.
- Refactor functions in APZCTreeManager: Collect, FlushRepaints,
FlushRepaintsRecursively, FlushPendingRepaint,
FlushPendingRepaintRecursively, UpdateZoomConstraints,
UpdateZoomConstraintsRecursively, ClearTree, FindScrollNode.
--HG--
extra : rebase_source : e7a740a9833ba49b1d41849bb43ce9077d42bc07
extra : source : ef6f195f2259e103f0c1979a5f4ebb5a8601b15d
2015-11-06 20:31:36 +03:00
|
|
|
{
|
2016-09-22 19:31:26 +03:00
|
|
|
Node result = Node();
|
Bug 1199798 - Use more generic tree traversal algorithms in APZCTreeManager. r=botond
Extend the tree traversal algorithms in TreeTraversal.h, and use them
instead of manual loops in APZCTreeManager.
- Create function ForEachNode(), which calls a function on each node
of a tree. The function must return a TraversalFlag to indicate
whether the node's children should be visited or skipped.
- Modify DepthFirstSearch() and BreadthFirstSearch() to operate on
pointers that are not (necessarily) const. This makes them more
general.
- Refactor functions in APZCTreeManager: Collect, FlushRepaints,
FlushRepaintsRecursively, FlushPendingRepaint,
FlushPendingRepaintRecursively, UpdateZoomConstraints,
UpdateZoomConstraintsRecursively, ClearTree, FindScrollNode.
--HG--
extra : rebase_source : e7a740a9833ba49b1d41849bb43ce9077d42bc07
extra : source : ef6f195f2259e103f0c1979a5f4ebb5a8601b15d
2015-11-06 20:31:36 +03:00
|
|
|
|
2016-03-10 12:20:40 +03:00
|
|
|
ForEachNode<Iterator>(aRoot,
|
2016-09-22 19:31:26 +03:00
|
|
|
[&aCondition, &result](Node aNode)
|
2016-01-25 15:04:13 +03:00
|
|
|
{
|
|
|
|
if (aCondition(aNode)) {
|
|
|
|
result = aNode;
|
|
|
|
return TraversalFlag::Abort;
|
|
|
|
}
|
Bug 1199798 - Use more generic tree traversal algorithms in APZCTreeManager. r=botond
Extend the tree traversal algorithms in TreeTraversal.h, and use them
instead of manual loops in APZCTreeManager.
- Create function ForEachNode(), which calls a function on each node
of a tree. The function must return a TraversalFlag to indicate
whether the node's children should be visited or skipped.
- Modify DepthFirstSearch() and BreadthFirstSearch() to operate on
pointers that are not (necessarily) const. This makes them more
general.
- Refactor functions in APZCTreeManager: Collect, FlushRepaints,
FlushRepaintsRecursively, FlushPendingRepaint,
FlushPendingRepaintRecursively, UpdateZoomConstraints,
UpdateZoomConstraintsRecursively, ClearTree, FindScrollNode.
--HG--
extra : rebase_source : e7a740a9833ba49b1d41849bb43ce9077d42bc07
extra : source : ef6f195f2259e103f0c1979a5f4ebb5a8601b15d
2015-11-06 20:31:36 +03:00
|
|
|
|
2016-01-25 15:04:13 +03:00
|
|
|
return TraversalFlag::Continue;
|
|
|
|
});
|
Bug 1199798 - Use more generic tree traversal algorithms in APZCTreeManager. r=botond
Extend the tree traversal algorithms in TreeTraversal.h, and use them
instead of manual loops in APZCTreeManager.
- Create function ForEachNode(), which calls a function on each node
of a tree. The function must return a TraversalFlag to indicate
whether the node's children should be visited or skipped.
- Modify DepthFirstSearch() and BreadthFirstSearch() to operate on
pointers that are not (necessarily) const. This makes them more
general.
- Refactor functions in APZCTreeManager: Collect, FlushRepaints,
FlushRepaintsRecursively, FlushPendingRepaint,
FlushPendingRepaintRecursively, UpdateZoomConstraints,
UpdateZoomConstraintsRecursively, ClearTree, FindScrollNode.
--HG--
extra : rebase_source : e7a740a9833ba49b1d41849bb43ce9077d42bc07
extra : source : ef6f195f2259e103f0c1979a5f4ebb5a8601b15d
2015-11-06 20:31:36 +03:00
|
|
|
|
2016-01-25 15:04:13 +03:00
|
|
|
return result;
|
Bug 1199798 - Use more generic tree traversal algorithms in APZCTreeManager. r=botond
Extend the tree traversal algorithms in TreeTraversal.h, and use them
instead of manual loops in APZCTreeManager.
- Create function ForEachNode(), which calls a function on each node
of a tree. The function must return a TraversalFlag to indicate
whether the node's children should be visited or skipped.
- Modify DepthFirstSearch() and BreadthFirstSearch() to operate on
pointers that are not (necessarily) const. This makes them more
general.
- Refactor functions in APZCTreeManager: Collect, FlushRepaints,
FlushRepaintsRecursively, FlushPendingRepaint,
FlushPendingRepaintRecursively, UpdateZoomConstraints,
UpdateZoomConstraintsRecursively, ClearTree, FindScrollNode.
--HG--
extra : rebase_source : e7a740a9833ba49b1d41849bb43ce9077d42bc07
extra : source : ef6f195f2259e103f0c1979a5f4ebb5a8601b15d
2015-11-06 20:31:36 +03:00
|
|
|
}
|
|
|
|
|
2016-01-25 15:04:13 +03:00
|
|
|
/*
|
|
|
|
* Perform a post-order, depth-first search starting at aRoot.
|
2016-03-10 12:20:40 +03:00
|
|
|
*
|
2016-09-22 19:31:26 +03:00
|
|
|
* |Iterator| and |Node| have all the same requirements seen in ForEachNode()'s
|
|
|
|
* definition, but in addition to those, |Node| must be able to express a null
|
|
|
|
* value, returned from Node().
|
2016-01-25 15:04:13 +03:00
|
|
|
*/
|
2016-03-10 12:20:40 +03:00
|
|
|
template <typename Iterator, typename Node, typename Condition>
|
2016-09-22 19:31:26 +03:00
|
|
|
Node DepthFirstSearchPostOrder(Node aRoot, const Condition& aCondition)
|
2015-11-23 21:06:01 +03:00
|
|
|
{
|
2016-09-22 19:31:26 +03:00
|
|
|
Node result = Node();
|
2015-11-23 21:06:01 +03:00
|
|
|
|
2016-03-10 12:20:40 +03:00
|
|
|
ForEachNodePostOrder<Iterator>(aRoot,
|
2016-09-22 19:31:26 +03:00
|
|
|
[&aCondition, &result](Node aNode)
|
2016-01-25 15:04:13 +03:00
|
|
|
{
|
|
|
|
if (aCondition(aNode)) {
|
|
|
|
result = aNode;
|
|
|
|
return TraversalFlag::Abort;
|
|
|
|
}
|
2015-11-23 21:06:01 +03:00
|
|
|
|
2016-01-25 15:04:13 +03:00
|
|
|
return TraversalFlag::Continue;
|
|
|
|
});
|
2015-11-23 21:06:01 +03:00
|
|
|
|
2016-01-25 15:04:13 +03:00
|
|
|
return result;
|
2015-11-23 21:06:01 +03:00
|
|
|
}
|
|
|
|
|
2015-07-22 02:36:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // mozilla_layers_TreeTraversal_h
|