| 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 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_HOST_H_ | 5 #ifndef UI_VIEWS_CONTROLS_MENU_MENU_HOST_H_ |
| 6 #define UI_VIEWS_CONTROLS_MENU_MENU_HOST_H_ | 6 #define UI_VIEWS_CONTROLS_MENU_MENU_HOST_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 14 #include "ui/views/widget/widget_observer.h" |
| 14 | 15 |
| 15 namespace views { | 16 namespace views { |
| 16 | 17 |
| 17 class SubmenuView; | 18 class SubmenuView; |
| 18 class View; | 19 class View; |
| 19 class Widget; | 20 class Widget; |
| 20 | 21 |
| 21 namespace internal { | 22 namespace internal { |
| 22 | 23 |
| 23 // This class is internal to views. | 24 // This class is internal to views. |
| 24 class PreMenuEventDispatchHandler; | 25 class PreMenuEventDispatchHandler; |
| 25 | 26 |
| 26 } // internal | 27 } // internal |
| 27 | 28 |
| 28 namespace test { | 29 namespace test { |
| 29 class MenuControllerTest; | 30 class MenuControllerTest; |
| 30 } // test | 31 } // test |
| 31 | 32 |
| 32 // SubmenuView uses a MenuHost to house the SubmenuView. | 33 // SubmenuView uses a MenuHost to house the SubmenuView. |
| 33 // | 34 // |
| 34 // SubmenuView owns the MenuHost. When SubmenuView is done with the MenuHost | 35 // SubmenuView owns the MenuHost. When SubmenuView is done with the MenuHost |
| 35 // |DestroyMenuHost| is invoked. The one exception to this is if the native | 36 // |DestroyMenuHost| is invoked. The one exception to this is if the native |
| 36 // OS destroys the widget out from under us, in which case |MenuHostDestroyed| | 37 // OS destroys the widget out from under us, in which case |MenuHostDestroyed| |
| 37 // is invoked back on the SubmenuView and the SubmenuView then drops references | 38 // is invoked back on the SubmenuView and the SubmenuView then drops references |
| 38 // to the MenuHost. | 39 // to the MenuHost. |
| 39 class MenuHost : public Widget { | 40 class MenuHost : public Widget, public WidgetObserver { |
| 40 public: | 41 public: |
| 41 explicit MenuHost(SubmenuView* submenu); | 42 explicit MenuHost(SubmenuView* submenu); |
| 42 ~MenuHost() override; | 43 ~MenuHost() override; |
| 43 | 44 |
| 44 // Initializes and shows the MenuHost. | 45 // Initializes and shows the MenuHost. |
| 45 // WARNING: |parent| may be NULL. | 46 // WARNING: |parent| may be NULL. |
| 46 void InitMenuHost(Widget* parent, | 47 void InitMenuHost(Widget* parent, |
| 47 const gfx::Rect& bounds, | 48 const gfx::Rect& bounds, |
| 48 View* contents_view, | 49 View* contents_view, |
| 49 bool do_capture); | 50 bool do_capture); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 63 | 64 |
| 64 // Sets the bounds of the menu host. | 65 // Sets the bounds of the menu host. |
| 65 void SetMenuHostBounds(const gfx::Rect& bounds); | 66 void SetMenuHostBounds(const gfx::Rect& bounds); |
| 66 | 67 |
| 67 // Releases a mouse grab installed by |ShowMenuHost|. | 68 // Releases a mouse grab installed by |ShowMenuHost|. |
| 68 void ReleaseMenuHostCapture(); | 69 void ReleaseMenuHostCapture(); |
| 69 | 70 |
| 70 private: | 71 private: |
| 71 friend class test::MenuControllerTest; | 72 friend class test::MenuControllerTest; |
| 72 | 73 |
| 73 // Overridden from Widget: | 74 // Widget: |
| 74 internal::RootView* CreateRootView() override; | 75 internal::RootView* CreateRootView() override; |
| 75 void OnMouseCaptureLost() override; | 76 void OnMouseCaptureLost() override; |
| 76 void OnNativeWidgetDestroyed() override; | 77 void OnNativeWidgetDestroyed() override; |
| 77 void OnOwnerClosing() override; | 78 void OnOwnerClosing() override; |
| 78 void OnDragWillStart() override; | 79 void OnDragWillStart() override; |
| 79 void OnDragComplete() override; | 80 void OnDragComplete() override; |
| 80 | 81 |
| 82 // WidgetObserver: |
| 83 void OnWidgetDestroying(Widget* widget) override; |
| 84 |
| 85 // Parent of the MenuHost widget. |
| 86 Widget* owner_ = nullptr; |
| 87 |
| 81 // The view we contain. | 88 // The view we contain. |
| 82 SubmenuView* submenu_; | 89 SubmenuView* submenu_; |
| 83 | 90 |
| 84 // If true, DestroyMenuHost has been invoked. | 91 // If true, DestroyMenuHost has been invoked. |
| 85 bool destroying_; | 92 bool destroying_; |
| 86 | 93 |
| 87 // If true and capture is lost we don't notify the delegate. | 94 // If true and capture is lost we don't notify the delegate. |
| 88 bool ignore_capture_lost_; | 95 bool ignore_capture_lost_; |
| 89 | 96 |
| 90 #if !defined(OS_MACOSX) | 97 #if !defined(OS_MACOSX) |
| 91 // Handles raw touch events at the moment. | 98 // Handles raw touch events at the moment. |
| 92 std::unique_ptr<internal::PreMenuEventDispatchHandler> pre_dispatch_handler_; | 99 std::unique_ptr<internal::PreMenuEventDispatchHandler> pre_dispatch_handler_; |
| 93 #endif | 100 #endif |
| 94 | 101 |
| 95 DISALLOW_COPY_AND_ASSIGN(MenuHost); | 102 DISALLOW_COPY_AND_ASSIGN(MenuHost); |
| 96 }; | 103 }; |
| 97 | 104 |
| 98 } // namespace views | 105 } // namespace views |
| 99 | 106 |
| 100 #endif // UI_VIEWS_CONTROLS_MENU_MENU_HOST_H_ | 107 #endif // UI_VIEWS_CONTROLS_MENU_MENU_HOST_H_ |
| OLD | NEW |