OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/aura/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 private: | 229 private: |
230 gfx::Point position_; | 230 gfx::Point position_; |
231 | 231 |
232 DISALLOW_COPY_AND_ASSIGN(GestureTrackPositionDelegate); | 232 DISALLOW_COPY_AND_ASSIGN(GestureTrackPositionDelegate); |
233 }; | 233 }; |
234 | 234 |
235 base::TimeDelta getTime() { | 235 base::TimeDelta getTime() { |
236 return base::Time::NowFromSystemTime() - base::Time(); | 236 return base::Time::NowFromSystemTime() - base::Time(); |
237 } | 237 } |
238 | 238 |
| 239 class SelfEventHandlingWindowDelegate : public TestWindowDelegate { |
| 240 public: |
| 241 SelfEventHandlingWindowDelegate() {} |
| 242 |
| 243 virtual bool ShouldDescendIntoChildForEventHandling( |
| 244 Window* child, |
| 245 const gfx::Point& location) OVERRIDE { |
| 246 return false; |
| 247 } |
| 248 |
| 249 private: |
| 250 DISALLOW_COPY_AND_ASSIGN(SelfEventHandlingWindowDelegate); |
| 251 }; |
| 252 |
239 } // namespace | 253 } // namespace |
240 | 254 |
241 TEST_F(WindowTest, GetChildById) { | 255 TEST_F(WindowTest, GetChildById) { |
242 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 256 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
243 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); | 257 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); |
244 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); | 258 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); |
245 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); | 259 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); |
246 | 260 |
247 EXPECT_EQ(NULL, w1->GetChildById(57)); | 261 EXPECT_EQ(NULL, w1->GetChildById(57)); |
248 EXPECT_EQ(w12.get(), w1->GetChildById(12)); | 262 EXPECT_EQ(w12.get(), w1->GetChildById(12)); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 521 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); |
508 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); | 522 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); |
509 | 523 |
510 // We can override the hit test bounds of the parent to make the parent grab | 524 // We can override the hit test bounds of the parent to make the parent grab |
511 // events along that edge. | 525 // events along that edge. |
512 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); | 526 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); |
513 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 527 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); |
514 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); | 528 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); |
515 } | 529 } |
516 | 530 |
| 531 TEST_F(WindowTest, GetEventHandlerForPointWithOverrideDescendingOrder) { |
| 532 scoped_ptr<SelfEventHandlingWindowDelegate> parent_delegate( |
| 533 new SelfEventHandlingWindowDelegate); |
| 534 scoped_ptr<Window> parent(CreateTestWindowWithDelegate( |
| 535 parent_delegate.get(), 1, gfx::Rect(10, 20, 400, 500), NULL)); |
| 536 scoped_ptr<Window> child( |
| 537 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 390, 480), |
| 538 parent.get())); |
| 539 |
| 540 // We can override ShouldDescendIntoChildForEventHandling to make the parent |
| 541 // grab all events. |
| 542 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); |
| 543 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(50, 50))); |
| 544 } |
| 545 |
517 TEST_F(WindowTest, GetTopWindowContainingPoint) { | 546 TEST_F(WindowTest, GetTopWindowContainingPoint) { |
518 Window* root = root_window(); | 547 Window* root = root_window(); |
519 root->SetBounds(gfx::Rect(0, 0, 300, 300)); | 548 root->SetBounds(gfx::Rect(0, 0, 300, 300)); |
520 | 549 |
521 scoped_ptr<Window> w1( | 550 scoped_ptr<Window> w1( |
522 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), NULL)); | 551 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), NULL)); |
523 scoped_ptr<Window> w11( | 552 scoped_ptr<Window> w11( |
524 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); | 553 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); |
525 | 554 |
526 scoped_ptr<Window> w2( | 555 scoped_ptr<Window> w2( |
(...skipping 1980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2507 // Move |w2| to be a child of |w1|. | 2536 // Move |w2| to be a child of |w1|. |
2508 w1->AddChild(w2.get()); | 2537 w1->AddChild(w2.get()); |
2509 // Sine we moved in the same root, observer shouldn't be notified. | 2538 // Sine we moved in the same root, observer shouldn't be notified. |
2510 EXPECT_EQ("0 0", observer.CountStringAndReset()); | 2539 EXPECT_EQ("0 0", observer.CountStringAndReset()); |
2511 // |w2| should still have focus after moving. | 2540 // |w2| should still have focus after moving. |
2512 EXPECT_TRUE(w2->HasFocus()); | 2541 EXPECT_TRUE(w2->HasFocus()); |
2513 } | 2542 } |
2514 | 2543 |
2515 } // namespace test | 2544 } // namespace test |
2516 } // namespace aura | 2545 } // namespace aura |
OLD | NEW |