Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Unified Diff: content/browser/frame_host/frame_tree_node.cc

Issue 1500973002: This patch adds NextSibling() to FrameTreeNode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/frame_host/frame_tree_node.h ('k') | content/browser/frame_host/frame_tree_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « content/browser/frame_host/frame_tree_node.h ('k') | content/browser/frame_host/frame_tree_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698