| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_V
IEWS_H_ | 5 #ifndef COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_V
IEWS_H_ |
| 6 #define COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_V
IEWS_H_ | 6 #define COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_V
IEWS_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "components/web_modal/modal_dialog_host.h" | 11 #include "components/web_modal/modal_dialog_host.h" |
| 12 #include "components/web_modal/single_web_contents_dialog_manager.h" | 12 #include "components/web_modal/single_web_contents_dialog_manager.h" |
| 13 #if defined(USE_AURA) |
| 14 #include "ui/aura/window_observer.h" |
| 15 #endif |
| 16 #include "ui/base/accelerators/accelerator.h" |
| 13 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
| 14 #include "ui/views/widget/widget_observer.h" | 18 #include "ui/views/widget/widget_observer.h" |
| 15 | 19 |
| 16 namespace views { | 20 namespace views { |
| 17 class Widget; | 21 class Widget; |
| 18 } | 22 } |
| 19 | 23 |
| 20 namespace constrained_window { | 24 namespace constrained_window { |
| 21 | 25 |
| 22 // Class for parenting a tab-modal views dialog off of a views browser. | 26 // Class for parenting a tab-modal views dialog off of a views browser. |
| 27 #if defined(USE_AURA) |
| 23 class NativeWebContentsModalDialogManagerViews | 28 class NativeWebContentsModalDialogManagerViews |
| 24 : public web_modal::SingleWebContentsDialogManager, | 29 : public web_modal::SingleWebContentsDialogManager, |
| 25 public web_modal::ModalDialogHostObserver, | 30 public web_modal::ModalDialogHostObserver, |
| 26 public views::WidgetObserver { | 31 public views::WidgetObserver, |
| 32 public aura::WindowObserver { |
| 27 public: | 33 public: |
| 28 NativeWebContentsModalDialogManagerViews( | 34 NativeWebContentsModalDialogManagerViews( |
| 29 gfx::NativeWindow dialog, | 35 gfx::NativeWindow dialog, |
| 30 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate); | 36 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate, |
| 37 bool is_toplevel, ui::AcceleratorTarget* target); |
| 31 | 38 |
| 32 ~NativeWebContentsModalDialogManagerViews() override; | 39 ~NativeWebContentsModalDialogManagerViews() override; |
| 33 | 40 |
| 34 // Sets up this object to manage the |dialog_|. Registers for closing events | 41 // Sets up this object to manage the |dialog_|. Registers for closing events |
| 35 // in order to notify the delegate. | 42 // in order to notify the delegate. If |is_toplevel| is true, the dialog will |
| 36 void ManageDialog(); | 43 // be set up as a top level dialog (peer of the host's native window), with |
| 44 // the host as its transient parent. However, unlike most window modal |
| 45 // dialogs, it will not block all events to its transient parent. |
| 46 void ManageDialog(bool is_toplevel); |
| 37 | 47 |
| 38 // web_modal::SingleWebContentsDialogManager: | 48 // web_modal::SingleWebContentsDialogManager: |
| 39 void Show() override; | 49 void Show() override; |
| 40 void Hide() override; | 50 void Hide() override; |
| 41 void Close() override; | 51 void Close() override; |
| 42 void Focus() override; | 52 void Focus() override; |
| 43 void Pulse() override; | 53 void Pulse() override; |
| 44 | 54 |
| 45 // web_modal::ModalDialogHostObserver: | 55 // web_modal::ModalDialogHostObserver: |
| 46 void OnPositionRequiresUpdate() override; | 56 void OnPositionRequiresUpdate() override; |
| 47 void OnHostDestroying() override; | 57 void OnHostDestroying() override; |
| 48 | 58 |
| 49 // views::WidgetObserver: | 59 // views::WidgetObserver: |
| 50 | 60 |
| 51 // NOTE(wittman): OnWidgetClosing is overriden to ensure that, when the widget | 61 // NOTE(wittman): OnWidgetClosing is overriden to ensure that, when the widget |
| 52 // is explicitly closed, the destruction occurs within the same call | 62 // is explicitly closed, the destruction occurs within the same call |
| 53 // stack. This avoids event races that lead to non-deterministic destruction | 63 // stack. This avoids event races that lead to non-deterministic destruction |
| 54 // ordering in e.g. the print preview dialog. OnWidgetDestroying is overridden | 64 // ordering in e.g. the print preview dialog. OnWidgetDestroying is overridden |
| 55 // because OnWidgetClosing is *only* invoked on explicit close, not when the | 65 // because OnWidgetClosing is *only* invoked on explicit close, not when the |
| 56 // widget is implicitly destroyed due to its parent being closed. This | 66 // widget is implicitly destroyed due to its parent being closed. This |
| 57 // situation occurs with app windows. WidgetClosing removes the observer, so | 67 // situation occurs with app windows. WidgetClosing removes the observer, so |
| 58 // only one of these two functions is ever invoked for a given widget. | 68 // only one of these two functions is ever invoked for a given widget. |
| 59 void OnWidgetClosing(views::Widget* widget) override; | 69 void OnWidgetClosing(views::Widget* widget) override; |
| 60 void OnWidgetDestroying(views::Widget* widget) override; | 70 void OnWidgetDestroying(views::Widget* widget) override; |
| 61 void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override; | 71 void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override; |
| 62 gfx::NativeWindow dialog() override; | 72 gfx::NativeWindow dialog() override; |
| 63 | 73 |
| 74 #if defined(USE_AURA) |
| 75 // aura::WindowObserver |
| 76 void OnWindowBoundsChanged(aura::Window* window, |
| 77 const gfx::Rect& old_bounds, |
| 78 const gfx::Rect& new_bounds) override; |
| 79 |
| 80 void OnWindowRemovingFromRootWindow(aura::Window* window, |
| 81 aura::Window* new_root) override; |
| 82 void OnWindowDestroying(aura::Window* window) override; |
| 83 #endif |
| 84 |
| 64 protected: | 85 protected: |
| 65 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate() { | 86 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate() { |
| 66 return native_delegate_; | 87 return native_delegate_; |
| 67 } | 88 } |
| 68 | 89 |
| 69 // By default just calls widget->Show() or Hide(), but allows a derived class | 90 // By default just calls widget->Show() or Hide(), but allows a derived class |
| 70 // to override in order to hide an alternate way (e.g. if the default hide | 91 // to override in order to hide an alternate way (e.g. if the default hide |
| 71 // would tear down attached dialogs too early). | 92 // would tear down attached dialogs too early). |
| 72 virtual void ShowWidget(views::Widget* widget); | 93 virtual void ShowWidget(views::Widget* widget); |
| 73 virtual void HideWidget(views::Widget* widget); | 94 virtual void HideWidget(views::Widget* widget); |
| 74 | 95 |
| 75 static views::Widget* GetWidget(gfx::NativeWindow dialog); | 96 static views::Widget* GetWidget(gfx::NativeWindow dialog); |
| 76 | 97 |
| 98 |
| 77 private: | 99 private: |
| 78 void WidgetClosing(views::Widget* widget); | 100 void WidgetClosing(views::Widget* widget); |
| 101 void OnNonClippedPositionRequiresUpdate(); |
| 79 | 102 |
| 80 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate_; | 103 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate_; |
| 81 gfx::NativeWindow dialog_; | 104 gfx::NativeWindow dialog_; |
| 82 web_modal::WebContentsModalDialogHost* host_; | 105 web_modal::WebContentsModalDialogHost* host_; |
| 83 bool host_destroying_; | 106 bool host_destroying_; |
| 107 ui::AcceleratorTarget* target_; |
| 84 std::set<views::Widget*> observed_widgets_; | 108 std::set<views::Widget*> observed_widgets_; |
| 85 std::set<views::Widget*> shown_widgets_; | 109 std::set<views::Widget*> shown_widgets_; |
| 86 | 110 |
| 87 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews); | 111 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews); |
| 88 }; | 112 }; |
| 113 #else |
| 114 class NativeWebContentsModalDialogManagerViews |
| 115 : public web_modal::SingleWebContentsDialogManager, |
| 116 public web_modal::ModalDialogHostObserver, |
| 117 public views::WidgetObserver { |
| 118 public: |
| 119 NativeWebContentsModalDialogManagerViews( |
| 120 gfx::NativeWindow dialog, |
| 121 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate, |
| 122 bool is_toplevel, ui::AcceleratorTarget* target); |
| 89 | 123 |
| 124 ~NativeWebContentsModalDialogManagerViews() override; |
| 125 |
| 126 // Sets up this object to manage the |dialog_|. Registers for closing events |
| 127 // in order to notify the delegate. If |is_toplevel| is true, the dialog will |
| 128 // be set up as a top level dialog (peer of the host's native window), with |
| 129 // the host as its transient parent. However, unlike most window modal |
| 130 // dialogs, it will not block all events to its transient parent. |
| 131 void ManageDialog(bool is_toplevel); |
| 132 |
| 133 // web_modal::SingleWebContentsDialogManager: |
| 134 void Show() override; |
| 135 void Hide() override; |
| 136 void Close() override; |
| 137 void Focus() override; |
| 138 void Pulse() override; |
| 139 |
| 140 // web_modal::ModalDialogHostObserver: |
| 141 void OnPositionRequiresUpdate() override; |
| 142 void OnHostDestroying() override; |
| 143 |
| 144 // views::WidgetObserver: |
| 145 |
| 146 // NOTE(wittman): OnWidgetClosing is overriden to ensure that, when the widget |
| 147 // is explicitly closed, the destruction occurs within the same call |
| 148 // stack. This avoids event races that lead to non-deterministic destruction |
| 149 // ordering in e.g. the print preview dialog. OnWidgetDestroying is overridden |
| 150 // because OnWidgetClosing is *only* invoked on explicit close, not when the |
| 151 // widget is implicitly destroyed due to its parent being closed. This |
| 152 // situation occurs with app windows. WidgetClosing removes the observer, so |
| 153 // only one of these two functions is ever invoked for a given widget. |
| 154 void OnWidgetClosing(views::Widget* widget) override; |
| 155 void OnWidgetDestroying(views::Widget* widget) override; |
| 156 void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override; |
| 157 gfx::NativeWindow dialog() override; |
| 158 |
| 159 protected: |
| 160 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate() { |
| 161 return native_delegate_; |
| 162 } |
| 163 |
| 164 // By default just calls widget->Show() or Hide(), but allows a derived class |
| 165 // to override in order to hide an alternate way (e.g. if the default hide |
| 166 // would tear down attached dialogs too early). |
| 167 virtual void ShowWidget(views::Widget* widget); |
| 168 virtual void HideWidget(views::Widget* widget); |
| 169 |
| 170 static views::Widget* GetWidget(gfx::NativeWindow dialog); |
| 171 |
| 172 |
| 173 private: |
| 174 void WidgetClosing(views::Widget* widget); |
| 175 void OnNonClippedPositionRequiresUpdate(); |
| 176 |
| 177 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate_; |
| 178 gfx::NativeWindow dialog_; |
| 179 web_modal::WebContentsModalDialogHost* host_; |
| 180 bool host_destroying_; |
| 181 ui::AcceleratorTarget* target_; |
| 182 std::set<views::Widget*> observed_widgets_; |
| 183 std::set<views::Widget*> shown_widgets_; |
| 184 |
| 185 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews); |
| 186 }; |
| 187 #endif // USE_AURA |
| 90 } // namespace constrained_window | 188 } // namespace constrained_window |
| 91 | 189 |
| 92 #endif // COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGE
R_VIEWS_H_ | 190 #endif // COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGE
R_VIEWS_H_ |
| OLD | NEW |