| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/wm/core/transient_window_manager.h" | 5 #include "ui/wm/core/transient_window_manager.h" |
| 6 | 6 |
| 7 #include "ui/aura/client/visibility_client.h" | 7 #include "ui/aura/client/visibility_client.h" |
| 8 #include "ui/aura/client/window_tree_client.h" | 8 #include "ui/aura/client/window_tree_client.h" |
| 9 #include "ui/aura/layout_manager.h" | 9 #include "ui/aura/layout_manager.h" |
| 10 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
| 11 #include "ui/aura/test/test_windows.h" | 11 #include "ui/aura/test/test_windows.h" |
| 12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 13 #include "ui/wm/core/transient_window_observer.h" | 13 #include "ui/wm/core/transient_window_observer.h" |
| 14 #include "ui/wm/core/window_util.h" | 14 #include "ui/wm/core/window_util.h" |
| 15 #include "ui/wm/core/wm_state.h" | 15 #include "ui/wm/core/wm_state.h" |
| 16 | 16 |
| 17 using aura::Window; | 17 using aura::Window; |
| 18 | 18 |
| 19 using aura::test::ChildWindowIDsAsString; | 19 using aura::test::ChildWindowIDsAsString; |
| 20 using aura::test::CreateTestWindowWithId; | 20 using aura::test::CreateTestWindowWithId; |
| 21 | 21 |
| 22 namespace wm { | 22 namespace wm { |
| 23 | 23 |
| 24 class TestTransientWindowObserver : public TransientWindowObserver { | 24 class TestTransientWindowObserver : public TransientWindowObserver { |
| 25 public: | 25 public: |
| 26 TestTransientWindowObserver() : add_count_(0), remove_count_(0) { | 26 TestTransientWindowObserver() : add_count_(0), remove_count_(0) { |
| 27 } | 27 } |
| 28 | 28 |
| 29 virtual ~TestTransientWindowObserver() { | 29 ~TestTransientWindowObserver() override {} |
| 30 } | |
| 31 | 30 |
| 32 int add_count() const { return add_count_; } | 31 int add_count() const { return add_count_; } |
| 33 int remove_count() const { return remove_count_; } | 32 int remove_count() const { return remove_count_; } |
| 34 | 33 |
| 35 // TransientWindowObserver overrides: | 34 // TransientWindowObserver overrides: |
| 36 virtual void OnTransientChildAdded(Window* window, | 35 void OnTransientChildAdded(Window* window, Window* transient) override { |
| 37 Window* transient) override { | |
| 38 add_count_++; | 36 add_count_++; |
| 39 } | 37 } |
| 40 virtual void OnTransientChildRemoved(Window* window, | 38 void OnTransientChildRemoved(Window* window, Window* transient) override { |
| 41 Window* transient) override { | |
| 42 remove_count_++; | 39 remove_count_++; |
| 43 } | 40 } |
| 44 | 41 |
| 45 private: | 42 private: |
| 46 int add_count_; | 43 int add_count_; |
| 47 int remove_count_; | 44 int remove_count_; |
| 48 | 45 |
| 49 DISALLOW_COPY_AND_ASSIGN(TestTransientWindowObserver); | 46 DISALLOW_COPY_AND_ASSIGN(TestTransientWindowObserver); |
| 50 }; | 47 }; |
| 51 | 48 |
| 52 class TransientWindowManagerTest : public aura::test::AuraTestBase { | 49 class TransientWindowManagerTest : public aura::test::AuraTestBase { |
| 53 public: | 50 public: |
| 54 TransientWindowManagerTest() {} | 51 TransientWindowManagerTest() {} |
| 55 virtual ~TransientWindowManagerTest() {} | 52 ~TransientWindowManagerTest() override {} |
| 56 | 53 |
| 57 virtual void SetUp() override { | 54 void SetUp() override { |
| 58 AuraTestBase::SetUp(); | 55 AuraTestBase::SetUp(); |
| 59 wm_state_.reset(new wm::WMState); | 56 wm_state_.reset(new wm::WMState); |
| 60 } | 57 } |
| 61 | 58 |
| 62 virtual void TearDown() override { | 59 void TearDown() override { |
| 63 wm_state_.reset(); | 60 wm_state_.reset(); |
| 64 AuraTestBase::TearDown(); | 61 AuraTestBase::TearDown(); |
| 65 } | 62 } |
| 66 | 63 |
| 67 protected: | 64 protected: |
| 68 // Creates a transient window that is transient to |parent|. | 65 // Creates a transient window that is transient to |parent|. |
| 69 Window* CreateTransientChild(int id, Window* parent) { | 66 Window* CreateTransientChild(int id, Window* parent) { |
| 70 Window* window = new Window(NULL); | 67 Window* window = new Window(NULL); |
| 71 window->set_id(id); | 68 window->set_id(id); |
| 72 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 69 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 339 |
| 343 // Used by NotifyDelegateAfterDeletingTransients. Adds a string to a vector when | 340 // Used by NotifyDelegateAfterDeletingTransients. Adds a string to a vector when |
| 344 // OnWindowDestroyed() is invoked so that destruction order can be verified. | 341 // OnWindowDestroyed() is invoked so that destruction order can be verified. |
| 345 class DestroyedTrackingDelegate : public aura::test::TestWindowDelegate { | 342 class DestroyedTrackingDelegate : public aura::test::TestWindowDelegate { |
| 346 public: | 343 public: |
| 347 explicit DestroyedTrackingDelegate(const std::string& name, | 344 explicit DestroyedTrackingDelegate(const std::string& name, |
| 348 std::vector<std::string>* results) | 345 std::vector<std::string>* results) |
| 349 : name_(name), | 346 : name_(name), |
| 350 results_(results) {} | 347 results_(results) {} |
| 351 | 348 |
| 352 virtual void OnWindowDestroyed(aura::Window* window) override { | 349 void OnWindowDestroyed(aura::Window* window) override { |
| 353 results_->push_back(name_); | 350 results_->push_back(name_); |
| 354 } | 351 } |
| 355 | 352 |
| 356 private: | 353 private: |
| 357 const std::string name_; | 354 const std::string name_; |
| 358 std::vector<std::string>* results_; | 355 std::vector<std::string>* results_; |
| 359 | 356 |
| 360 DISALLOW_COPY_AND_ASSIGN(DestroyedTrackingDelegate); | 357 DISALLOW_COPY_AND_ASSIGN(DestroyedTrackingDelegate); |
| 361 }; | 358 }; |
| 362 | 359 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 root_window()->StackChildAtTop(window1.get()); | 447 root_window()->StackChildAtTop(window1.get()); |
| 451 EXPECT_EQ("2 3 1 11 12 13", ChildWindowIDsAsString(root_window())); | 448 EXPECT_EQ("2 3 1 11 12 13", ChildWindowIDsAsString(root_window())); |
| 452 } | 449 } |
| 453 | 450 |
| 454 class StackingMadrigalLayoutManager : public aura::LayoutManager { | 451 class StackingMadrigalLayoutManager : public aura::LayoutManager { |
| 455 public: | 452 public: |
| 456 explicit StackingMadrigalLayoutManager(Window* root_window) | 453 explicit StackingMadrigalLayoutManager(Window* root_window) |
| 457 : root_window_(root_window) { | 454 : root_window_(root_window) { |
| 458 root_window_->SetLayoutManager(this); | 455 root_window_->SetLayoutManager(this); |
| 459 } | 456 } |
| 460 virtual ~StackingMadrigalLayoutManager() { | 457 ~StackingMadrigalLayoutManager() override {} |
| 461 } | |
| 462 | 458 |
| 463 private: | 459 private: |
| 464 // Overridden from LayoutManager: | 460 // Overridden from LayoutManager: |
| 465 virtual void OnWindowResized() override {} | 461 void OnWindowResized() override {} |
| 466 virtual void OnWindowAddedToLayout(Window* child) override {} | 462 void OnWindowAddedToLayout(Window* child) override {} |
| 467 virtual void OnWillRemoveWindowFromLayout(Window* child) override {} | 463 void OnWillRemoveWindowFromLayout(Window* child) override {} |
| 468 virtual void OnWindowRemovedFromLayout(Window* child) override {} | 464 void OnWindowRemovedFromLayout(Window* child) override {} |
| 469 virtual void OnChildWindowVisibilityChanged(Window* child, | 465 void OnChildWindowVisibilityChanged(Window* child, bool visible) override { |
| 470 bool visible) override { | |
| 471 Window::Windows::const_iterator it = root_window_->children().begin(); | 466 Window::Windows::const_iterator it = root_window_->children().begin(); |
| 472 Window* last_window = NULL; | 467 Window* last_window = NULL; |
| 473 for (; it != root_window_->children().end(); ++it) { | 468 for (; it != root_window_->children().end(); ++it) { |
| 474 if (*it == child && last_window) { | 469 if (*it == child && last_window) { |
| 475 if (!visible) | 470 if (!visible) |
| 476 root_window_->StackChildAbove(last_window, *it); | 471 root_window_->StackChildAbove(last_window, *it); |
| 477 else | 472 else |
| 478 root_window_->StackChildAbove(*it, last_window); | 473 root_window_->StackChildAbove(*it, last_window); |
| 479 break; | 474 break; |
| 480 } | 475 } |
| 481 last_window = *it; | 476 last_window = *it; |
| 482 } | 477 } |
| 483 } | 478 } |
| 484 virtual void SetChildBounds(Window* child, | 479 void SetChildBounds(Window* child, |
| 485 const gfx::Rect& requested_bounds) override { | 480 const gfx::Rect& requested_bounds) override { |
| 486 SetChildBoundsDirect(child, requested_bounds); | 481 SetChildBoundsDirect(child, requested_bounds); |
| 487 } | 482 } |
| 488 | 483 |
| 489 Window* root_window_; | 484 Window* root_window_; |
| 490 | 485 |
| 491 DISALLOW_COPY_AND_ASSIGN(StackingMadrigalLayoutManager); | 486 DISALLOW_COPY_AND_ASSIGN(StackingMadrigalLayoutManager); |
| 492 }; | 487 }; |
| 493 | 488 |
| 494 class StackingMadrigalVisibilityClient : public aura::client::VisibilityClient { | 489 class StackingMadrigalVisibilityClient : public aura::client::VisibilityClient { |
| 495 public: | 490 public: |
| 496 explicit StackingMadrigalVisibilityClient(Window* root_window) | 491 explicit StackingMadrigalVisibilityClient(Window* root_window) |
| 497 : ignored_window_(NULL) { | 492 : ignored_window_(NULL) { |
| 498 aura::client::SetVisibilityClient(root_window, this); | 493 aura::client::SetVisibilityClient(root_window, this); |
| 499 } | 494 } |
| 500 virtual ~StackingMadrigalVisibilityClient() { | 495 ~StackingMadrigalVisibilityClient() override {} |
| 501 } | |
| 502 | 496 |
| 503 void set_ignored_window(Window* ignored_window) { | 497 void set_ignored_window(Window* ignored_window) { |
| 504 ignored_window_ = ignored_window; | 498 ignored_window_ = ignored_window; |
| 505 } | 499 } |
| 506 | 500 |
| 507 private: | 501 private: |
| 508 // Overridden from client::VisibilityClient: | 502 // Overridden from client::VisibilityClient: |
| 509 virtual void UpdateLayerVisibility(Window* window, bool visible) override { | 503 void UpdateLayerVisibility(Window* window, bool visible) override { |
| 510 if (!visible) { | 504 if (!visible) { |
| 511 if (window == ignored_window_) | 505 if (window == ignored_window_) |
| 512 window->layer()->set_delegate(NULL); | 506 window->layer()->set_delegate(NULL); |
| 513 else | 507 else |
| 514 window->layer()->SetVisible(visible); | 508 window->layer()->SetVisible(visible); |
| 515 } else { | 509 } else { |
| 516 window->layer()->SetVisible(visible); | 510 window->layer()->SetVisible(visible); |
| 517 } | 511 } |
| 518 } | 512 } |
| 519 | 513 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 EXPECT_EQ(0, test_observer.remove_count()); | 692 EXPECT_EQ(0, test_observer.remove_count()); |
| 699 | 693 |
| 700 RemoveTransientChild(parent.get(), w1.get()); | 694 RemoveTransientChild(parent.get(), w1.get()); |
| 701 EXPECT_EQ(1, test_observer.add_count()); | 695 EXPECT_EQ(1, test_observer.add_count()); |
| 702 EXPECT_EQ(1, test_observer.remove_count()); | 696 EXPECT_EQ(1, test_observer.remove_count()); |
| 703 | 697 |
| 704 TransientWindowManager::Get(parent.get())->RemoveObserver(&test_observer); | 698 TransientWindowManager::Get(parent.get())->RemoveObserver(&test_observer); |
| 705 } | 699 } |
| 706 | 700 |
| 707 } // namespace wm | 701 } // namespace wm |
| OLD | NEW |