| 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 #include "ui/aura/window_tree_host_observer.h" |
| 16 #endif |
| 17 #include "ui/base/accelerators/accelerator.h" |
| 13 #include "ui/gfx/native_widget_types.h" | 18 #include "ui/gfx/native_widget_types.h" |
| 14 #include "ui/views/widget/widget_observer.h" | 19 #include "ui/views/widget/widget_observer.h" |
| 15 | 20 |
| 16 namespace views { | 21 namespace views { |
| 17 class Widget; | 22 class Widget; |
| 18 } | 23 } |
| 19 | 24 |
| 20 namespace constrained_window { | 25 namespace constrained_window { |
| 21 | 26 |
| 22 // Class for parenting a tab-modal views dialog off of a views browser. | 27 // Class for parenting a tab-modal views dialog off of a views browser. |
| 28 #if defined(USE_AURA) |
| 23 class NativeWebContentsModalDialogManagerViews | 29 class NativeWebContentsModalDialogManagerViews |
| 24 : public web_modal::SingleWebContentsDialogManager, | 30 : public web_modal::SingleWebContentsDialogManager, |
| 25 public web_modal::ModalDialogHostObserver, | 31 public web_modal::ModalDialogHostObserver, |
| 32 public views::WidgetObserver, |
| 33 public aura::WindowObserver, |
| 34 public aura::WindowTreeHostObserver { |
| 35 public: |
| 36 NativeWebContentsModalDialogManagerViews( |
| 37 gfx::NativeWindow dialog, |
| 38 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate, |
| 39 bool is_toplevel, ui::AcceleratorTarget* target); |
| 40 |
| 41 ~NativeWebContentsModalDialogManagerViews() override; |
| 42 |
| 43 // Sets up this object to manage the |dialog_|. Registers for closing events |
| 44 // in order to notify the delegate. If |is_toplevel| is true, the dialog will |
| 45 // be set up as a top level dialog (peer of the host's native window), with |
| 46 // the host as its transient parent. However, unlike most window modal |
| 47 // dialogs, it will not block all events to its transient parent. |
| 48 void ManageDialog(bool is_toplevel); |
| 49 |
| 50 // web_modal::SingleWebContentsDialogManager: |
| 51 void Show() override; |
| 52 void Hide() override; |
| 53 void Close() override; |
| 54 void Focus() override; |
| 55 void Pulse() override; |
| 56 |
| 57 // web_modal::ModalDialogHostObserver: |
| 58 void OnPositionRequiresUpdate() override; |
| 59 void OnHostDestroying() override; |
| 60 |
| 61 // views::WidgetObserver: |
| 62 |
| 63 // NOTE(wittman): OnWidgetClosing is overriden to ensure that, when the widget |
| 64 // is explicitly closed, the destruction occurs within the same call |
| 65 // stack. This avoids event races that lead to non-deterministic destruction |
| 66 // ordering in e.g. the print preview dialog. OnWidgetDestroying is overridden |
| 67 // because OnWidgetClosing is *only* invoked on explicit close, not when the |
| 68 // widget is implicitly destroyed due to its parent being closed. This |
| 69 // situation occurs with app windows. WidgetClosing removes the observer, so |
| 70 // only one of these two functions is ever invoked for a given widget. |
| 71 void OnWidgetClosing(views::Widget* widget) override; |
| 72 void OnWidgetDestroying(views::Widget* widget) override; |
| 73 void OnWidgetActivationChanged(views::Widget* widget, bool active) override; |
| 74 void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override; |
| 75 gfx::NativeWindow dialog() override; |
| 76 |
| 77 #if defined(USE_AURA) |
| 78 // aura::WindowObserver |
| 79 void OnWindowBoundsChanged(aura::Window* window, |
| 80 const gfx::Rect& old_bounds, |
| 81 const gfx::Rect& new_bounds) override; |
| 82 void OnWindowDestroying(aura::Window* window) override; |
| 83 void OnWindowStackingChanged(aura::Window* window) override; |
| 84 void OnWindowParentChanged(aura::Window* window, |
| 85 aura::Window* parent) override; |
| 86 |
| 87 // aura::WindowTreeHostObserver |
| 88 void OnHostMovedInPixels(const aura::WindowTreeHost* host, |
| 89 const gfx::Point& new_origin_in_pixels) override; |
| 90 |
| 91 // Helper function to stack |widget|'s native window above the modal dialog |
| 92 // host's native window. |
| 93 void StackWidgetAtTop(views::Widget* widget); |
| 94 |
| 95 #endif |
| 96 |
| 97 protected: |
| 98 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate() { |
| 99 return native_delegate_; |
| 100 } |
| 101 |
| 102 // By default just calls widget->Show() or Hide(), but allows a derived class |
| 103 // to override in order to hide an alternate way (e.g. if the default hide |
| 104 // would tear down attached dialogs too early). |
| 105 virtual void ShowWidget(views::Widget* widget); |
| 106 virtual void HideWidget(views::Widget* widget); |
| 107 void FocusInternal(views::Widget* widget); |
| 108 static views::Widget* GetWidget(gfx::NativeWindow dialog); |
| 109 |
| 110 private: |
| 111 void WidgetClosing(views::Widget* widget); |
| 112 void OnNonClippedPositionRequiresUpdate(); |
| 113 |
| 114 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate_; |
| 115 gfx::NativeWindow dialog_; |
| 116 web_modal::WebContentsModalDialogHost* host_; |
| 117 bool host_destroying_; |
| 118 |
| 119 // A target that accelerators that arrive at the host web contents widget will |
| 120 // be forwarded to. Used to enable escape = dialog close for top level |
| 121 // dialogs. |
| 122 ui::AcceleratorTarget* target_; |
| 123 |
| 124 std::set<views::Widget*> observed_widgets_; |
| 125 std::set<views::Widget*> shown_widgets_; |
| 126 |
| 127 // base::OneShotTimer timer_; |
| 128 |
| 129 // Tracks if Show() was called from within the manager or elsewhere. |
| 130 bool called_internal_ = false; |
| 131 |
| 132 // Tracks if the top level window is currently minimized. |
| 133 bool window_minimized_ = false; |
| 134 |
| 135 // Used to indicate if the call to Show() has been deferred to prevent focus |
| 136 // problems - if true, Show() should be callled when the window is next |
| 137 // re-stacked. |
| 138 bool show_on_next_stack_ = false; |
| 139 |
| 140 // Whether or not the parent widget (host window) is inactive while the |
| 141 // preview dialog is active. |
| 142 bool parent_inactive_ = false; |
| 143 |
| 144 // Used to indicate that the state is being updated for a new host. |
| 145 bool host_changing_ = false; |
| 146 |
| 147 bool need_to_show_ = false; |
| 148 |
| 149 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews); |
| 150 }; |
| 151 #else |
| 152 class NativeWebContentsModalDialogManagerViews |
| 153 : public web_modal::SingleWebContentsDialogManager, |
| 154 public web_modal::ModalDialogHostObserver, |
| 26 public views::WidgetObserver { | 155 public views::WidgetObserver { |
| 27 public: | 156 public: |
| 28 NativeWebContentsModalDialogManagerViews( | 157 NativeWebContentsModalDialogManagerViews( |
| 29 gfx::NativeWindow dialog, | 158 gfx::NativeWindow dialog, |
| 30 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate); | 159 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate, |
| 160 bool is_toplevel, ui::AcceleratorTarget* target); |
| 31 | 161 |
| 32 ~NativeWebContentsModalDialogManagerViews() override; | 162 ~NativeWebContentsModalDialogManagerViews() override; |
| 33 | 163 |
| 34 // Sets up this object to manage the |dialog_|. Registers for closing events | 164 // Sets up this object to manage the |dialog_|. Registers for closing events |
| 35 // in order to notify the delegate. | 165 // in order to notify the delegate. If |is_toplevel| is true, the dialog will |
| 36 void ManageDialog(); | 166 // be set up as a top level dialog (peer of the host's native window), with |
| 167 // the host as its transient parent. However, unlike most window modal |
| 168 // dialogs, it will not block all events to its transient parent. |
| 169 void ManageDialog(bool is_toplevel); |
| 37 | 170 |
| 38 // web_modal::SingleWebContentsDialogManager: | 171 // web_modal::SingleWebContentsDialogManager: |
| 39 void Show() override; | 172 void Show() override; |
| 40 void Hide() override; | 173 void Hide() override; |
| 41 void Close() override; | 174 void Close() override; |
| 42 void Focus() override; | 175 void Focus() override; |
| 43 void Pulse() override; | 176 void Pulse() override; |
| 44 | 177 |
| 45 // web_modal::ModalDialogHostObserver: | 178 // web_modal::ModalDialogHostObserver: |
| 46 void OnPositionRequiresUpdate() override; | 179 void OnPositionRequiresUpdate() override; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 69 // By default just calls widget->Show() or Hide(), but allows a derived class | 202 // 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 | 203 // to override in order to hide an alternate way (e.g. if the default hide |
| 71 // would tear down attached dialogs too early). | 204 // would tear down attached dialogs too early). |
| 72 virtual void ShowWidget(views::Widget* widget); | 205 virtual void ShowWidget(views::Widget* widget); |
| 73 virtual void HideWidget(views::Widget* widget); | 206 virtual void HideWidget(views::Widget* widget); |
| 74 | 207 |
| 75 static views::Widget* GetWidget(gfx::NativeWindow dialog); | 208 static views::Widget* GetWidget(gfx::NativeWindow dialog); |
| 76 | 209 |
| 77 private: | 210 private: |
| 78 void WidgetClosing(views::Widget* widget); | 211 void WidgetClosing(views::Widget* widget); |
| 79 | 212 void OnNonClippedPositionRequiresUpdate(); |
| 213 void FocusInternal(views::Widget* widget); |
| 80 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate_; | 214 web_modal::SingleWebContentsDialogManagerDelegate* native_delegate_; |
| 81 gfx::NativeWindow dialog_; | 215 gfx::NativeWindow dialog_; |
| 82 web_modal::WebContentsModalDialogHost* host_; | 216 web_modal::WebContentsModalDialogHost* host_; |
| 83 bool host_destroying_; | 217 bool host_destroying_; |
| 218 ui::AcceleratorTarget* target_; |
| 84 std::set<views::Widget*> observed_widgets_; | 219 std::set<views::Widget*> observed_widgets_; |
| 85 std::set<views::Widget*> shown_widgets_; | 220 std::set<views::Widget*> shown_widgets_; |
| 86 | 221 |
| 87 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews); | 222 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews); |
| 88 }; | 223 }; |
| 89 | 224 |
| 225 #endif // USE_AURA |
| 90 } // namespace constrained_window | 226 } // namespace constrained_window |
| 91 | 227 |
| 92 #endif // COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGE
R_VIEWS_H_ | 228 #endif // COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGE
R_VIEWS_H_ |
| OLD | NEW |