diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-17 01:00:46 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-17 01:00:46 +0000 |
commit | 280cddd18639a2d14a218f32d1e32dc71addad52 (patch) | |
tree | 76fae4ac578f8f2900e9b30beedcdde6650d753c /views | |
parent | 2e236570c4122247027f934f309fcd276171cfc7 (diff) | |
download | chromium_src-280cddd18639a2d14a218f32d1e32dc71addad52.zip chromium_src-280cddd18639a2d14a218f32d1e32dc71addad52.tar.gz chromium_src-280cddd18639a2d14a218f32d1e32dc71addad52.tar.bz2 |
views: Convert while loop to for loop on View::Contains().
BUG=None
TEST=out/Debug/views_unittests --gtest_filter=ViewTest.Contains
R=sky@chromium.org
Review URL: http://codereview.chromium.org/6973069
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85572 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/view.cc | 6 | ||||
-rw-r--r-- | views/view_unittest.cc | 22 |
2 files changed, 24 insertions, 4 deletions
diff --git a/views/view.cc b/views/view.cc index 820800a..67ac560 100644 --- a/views/view.cc +++ b/views/view.cc @@ -199,11 +199,9 @@ View* View::GetChildViewAt(int index) { } bool View::Contains(const View* view) const { - const View* child = view; - while (child) { - if (child == this) + for (const View* v = view; v; v = v->parent_) { + if (v == this) return true; - child = child->parent(); } return false; } diff --git a/views/view_unittest.cc b/views/view_unittest.cc index 5a1bf4d..97d32fa 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -1875,4 +1875,26 @@ TEST_F(ViewTest, SetBoundsPaint) { EXPECT_EQ(gfx::Rect(10, 10, 40, 40), paint_rect); } +TEST_F(ViewTest, Contains) { + TestView v1; + TestView* v2 = new TestView(); + TestView* v3 = new TestView(); + + v1.AddChildView(v2); + v2->AddChildView(v3); + + EXPECT_FALSE(v1.Contains(NULL)); + EXPECT_TRUE(v1.Contains(&v1)); + EXPECT_TRUE(v1.Contains(v2)); + EXPECT_TRUE(v1.Contains(v3)); + EXPECT_FALSE(v2->Contains(NULL)); + EXPECT_TRUE(v2->Contains(v2)); + EXPECT_FALSE(v2->Contains(&v1)); + EXPECT_TRUE(v2->Contains(v3)); + EXPECT_FALSE(v3->Contains(NULL)); + EXPECT_TRUE(v3->Contains(v3)); + EXPECT_FALSE(v3->Contains(&v1)); + EXPECT_FALSE(v3->Contains(v2)); +} + } // namespace views |