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

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: Rebased and addressed comment. Created 4 years, 7 months 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 73ef0c3d9d084f6d63db8fff506099ec1fc61bac..dff90f0df332e626be7456a7c34a16a435b21974 100644
--- a/content/browser/frame_host/frame_tree_node.cc
+++ b/content/browser/frame_host/frame_tree_node.cc
@@ -277,16 +277,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 {
@@ -494,4 +489,22 @@ void FrameTreeNode::TraceSnapshot() const {
new TracedFrameTreeNode(*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) {
+ if ((relative_offset < 0 && static_cast<size_t>(-relative_offset) > i) ||
+ i + relative_offset >= parent_->child_count()) {
+ return nullptr;
+ }
+ return parent_->child_at(i + relative_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