test_child_modal_parent.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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
  3. // found in the LICENSE file.
  4. #ifndef ASH_WM_TEST_CHILD_MODAL_PARENT_H_
  5. #define ASH_WM_TEST_CHILD_MODAL_PARENT_H_
  6. #include <memory>
  7. #include "ui/views/controls/button/button.h"
  8. #include "ui/views/widget/widget_delegate.h"
  9. #include "ui/views/widget/widget_observer.h"
  10. namespace views {
  11. class NativeViewHost;
  12. class Textfield;
  13. class View;
  14. class Widget;
  15. } // namespace views
  16. namespace ash {
  17. // Test window that can act as a parent for modal child windows.
  18. class TestChildModalParent : public views::WidgetDelegateView,
  19. public views::WidgetObserver {
  20. public:
  21. // Create and show a top-level window that hosts a modal parent. Returns the
  22. // widget delegate, which is owned by the widget and deleted on window close.
  23. static TestChildModalParent* Show(aura::Window* context);
  24. explicit TestChildModalParent(aura::Window* context);
  25. TestChildModalParent(const TestChildModalParent&) = delete;
  26. TestChildModalParent& operator=(const TestChildModalParent&) = delete;
  27. ~TestChildModalParent() override;
  28. // Returns the modal parent window hosted within the top-level window.
  29. aura::Window* GetModalParent() const;
  30. // Create, show, and returns a child-modal window.
  31. aura::Window* ShowModalChild();
  32. private:
  33. // Overridden from views::View:
  34. void Layout() override;
  35. void AddedToWidget() override;
  36. // Overridden from WidgetObserver:
  37. void OnWidgetDestroying(views::Widget* widget) override;
  38. void ButtonPressed();
  39. // The widget for the modal parent, a child of TestChildModalParent's Widget.
  40. std::unique_ptr<views::Widget> modal_parent_;
  41. // The button to toggle showing and hiding the child window. The child window
  42. // does not block input to this button.
  43. views::Button* button_;
  44. // The text field to indicate the keyboard focus.
  45. views::Textfield* textfield_;
  46. // The host for the modal parent.
  47. views::NativeViewHost* host_;
  48. // The modal child widget.
  49. views::Widget* modal_child_ = nullptr;
  50. };
  51. } // namespace ash
  52. #endif // ASH_WM_TEST_CHILD_MODAL_PARENT_H_