Chromium Code Reviews| Index: content/browser/frame_host/frame_tree_node.cc |
| diff --git a/content/browser/frame_host/frame_tree_node.cc b/content/browser/frame_host/frame_tree_node.cc |
| index 8270ea291ebeba66061c299557f320713113dd34..144fbd6c894dd5f929254152b64d7e64ad8eea7a 100644 |
| --- a/content/browser/frame_host/frame_tree_node.cc |
| +++ b/content/browser/frame_host/frame_tree_node.cc |
| @@ -217,16 +217,11 @@ bool FrameTreeNode::IsDescendantOf(FrameTreeNode* other) const { |
| } |
| FrameTreeNode* FrameTreeNode::PreviousSibling() const { |
| - if (!parent_) |
| - return nullptr; |
| - |
| - for (size_t i = 0; i < parent_->child_count(); ++i) { |
| - if (parent_->child_at(i) == this) |
| - return (i == 0) ? nullptr : parent_->child_at(i - 1); |
| - } |
| + return GetSibling(-1); |
| +} |
| - NOTREACHED() << "FrameTreeNode not found in its parent's children."; |
| - return nullptr; |
| +FrameTreeNode* FrameTreeNode::NextSibling() const { |
| + return GetSibling(1); |
| } |
| bool FrameTreeNode::IsLoading() const { |
| @@ -386,4 +381,20 @@ void FrameTreeNode::DidFocus() { |
| FOR_EACH_OBSERVER(Observer, observers_, OnFrameTreeNodeFocused(this)); |
| } |
| +FrameTreeNode* FrameTreeNode::GetSibling(int relative_offset) const { |
| + if (!parent_) |
| + return nullptr; |
| + |
| + for (size_t i = 0; i < parent_->child_count(); ++i) { |
| + if (parent_->child_at(i) == this) { |
| + size_t offset = i + relative_offset; |
| + return offset >= parent_->child_count() ? nullptr |
|
Charlie Reis
2015/12/09 22:29:15
Don't we need to check for less than 0 as well? S
paulmeyer
2015/12/09 22:38:43
I wasn't checking for less than zero specifically
Charlie Reis
2015/12/09 23:49:48
That would preclude any analyses which check for r
paulmeyer
2016/05/13 13:44:15
Okay, done.
|
| + : parent_->child_at(offset); |
| + } |
| + } |
| + |
| + NOTREACHED() << "FrameTreeNode not found in its parent's children."; |
| + return nullptr; |
| +} |
| + |
| } // namespace content |