| Index: components/constrained_window/native_web_contents_modal_dialog_manager_views.h
|
| diff --git a/components/constrained_window/native_web_contents_modal_dialog_manager_views.h b/components/constrained_window/native_web_contents_modal_dialog_manager_views.h
|
| index 382b9ce8cad05c93948100ca109ac8965913d206..066037f043da1beadb56803fddb558a7429d474d 100644
|
| --- a/components/constrained_window/native_web_contents_modal_dialog_manager_views.h
|
| +++ b/components/constrained_window/native_web_contents_modal_dialog_manager_views.h
|
| @@ -10,6 +10,11 @@
|
| #include "base/macros.h"
|
| #include "components/web_modal/modal_dialog_host.h"
|
| #include "components/web_modal/single_web_contents_dialog_manager.h"
|
| +#if defined(USE_AURA)
|
| +#include "ui/aura/window_observer.h"
|
| +#include "ui/aura/window_tree_host_observer.h"
|
| +#endif
|
| +#include "ui/base/accelerators/accelerator.h"
|
| #include "ui/gfx/native_widget_types.h"
|
| #include "ui/views/widget/widget_observer.h"
|
|
|
| @@ -20,6 +25,130 @@ class Widget;
|
| namespace constrained_window {
|
|
|
| // Class for parenting a tab-modal views dialog off of a views browser.
|
| +#if defined(USE_AURA)
|
| +class NativeWebContentsModalDialogManagerViews
|
| + : public web_modal::SingleWebContentsDialogManager,
|
| + public web_modal::ModalDialogHostObserver,
|
| + public views::WidgetObserver,
|
| + public aura::WindowObserver,
|
| + public aura::WindowTreeHostObserver {
|
| + public:
|
| + NativeWebContentsModalDialogManagerViews(
|
| + gfx::NativeWindow dialog,
|
| + web_modal::SingleWebContentsDialogManagerDelegate* native_delegate,
|
| + bool is_toplevel, ui::AcceleratorTarget* target);
|
| +
|
| + ~NativeWebContentsModalDialogManagerViews() override;
|
| +
|
| + // Sets up this object to manage the |dialog_|. Registers for closing events
|
| + // in order to notify the delegate. If |is_toplevel| is true, the dialog will
|
| + // be set up as a top level dialog (peer of the host's native window), with
|
| + // the host as its transient parent. However, unlike most window modal
|
| + // dialogs, it will not block all events to its transient parent.
|
| + void ManageDialog(bool is_toplevel);
|
| +
|
| + // web_modal::SingleWebContentsDialogManager:
|
| + void Show() override;
|
| + void Hide() override;
|
| + void Close() override;
|
| + void Focus() override;
|
| + void Pulse() override;
|
| +
|
| + // web_modal::ModalDialogHostObserver:
|
| + void OnPositionRequiresUpdate() override;
|
| + void OnHostDestroying() override;
|
| +
|
| + // views::WidgetObserver:
|
| +
|
| + // NOTE(wittman): OnWidgetClosing is overriden to ensure that, when the widget
|
| + // is explicitly closed, the destruction occurs within the same call
|
| + // stack. This avoids event races that lead to non-deterministic destruction
|
| + // ordering in e.g. the print preview dialog. OnWidgetDestroying is overridden
|
| + // because OnWidgetClosing is *only* invoked on explicit close, not when the
|
| + // widget is implicitly destroyed due to its parent being closed. This
|
| + // situation occurs with app windows. WidgetClosing removes the observer, so
|
| + // only one of these two functions is ever invoked for a given widget.
|
| + void OnWidgetClosing(views::Widget* widget) override;
|
| + void OnWidgetDestroying(views::Widget* widget) override;
|
| + void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
|
| + void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override;
|
| + gfx::NativeWindow dialog() override;
|
| +
|
| +#if defined(USE_AURA)
|
| + // aura::WindowObserver
|
| + void OnWindowBoundsChanged(aura::Window* window,
|
| + const gfx::Rect& old_bounds,
|
| + const gfx::Rect& new_bounds) override;
|
| + void OnWindowDestroying(aura::Window* window) override;
|
| + void OnWindowStackingChanged(aura::Window* window) override;
|
| + void OnWindowParentChanged(aura::Window* window,
|
| + aura::Window* parent) override;
|
| +
|
| + // aura::WindowTreeHostObserver
|
| + void OnHostMovedInPixels(const aura::WindowTreeHost* host,
|
| + const gfx::Point& new_origin_in_pixels) override;
|
| +
|
| + // Helper function to stack |widget|'s native window above the modal dialog
|
| + // host's native window.
|
| + void StackWidgetAtTop(views::Widget* widget);
|
| +
|
| +#endif
|
| +
|
| + protected:
|
| + web_modal::SingleWebContentsDialogManagerDelegate* native_delegate() {
|
| + return native_delegate_;
|
| + }
|
| +
|
| + // By default just calls widget->Show() or Hide(), but allows a derived class
|
| + // to override in order to hide an alternate way (e.g. if the default hide
|
| + // would tear down attached dialogs too early).
|
| + virtual void ShowWidget(views::Widget* widget);
|
| + virtual void HideWidget(views::Widget* widget);
|
| + void FocusInternal(views::Widget* widget);
|
| + static views::Widget* GetWidget(gfx::NativeWindow dialog);
|
| +
|
| + private:
|
| + void WidgetClosing(views::Widget* widget);
|
| + void OnNonClippedPositionRequiresUpdate();
|
| +
|
| + web_modal::SingleWebContentsDialogManagerDelegate* native_delegate_;
|
| + gfx::NativeWindow dialog_;
|
| + web_modal::WebContentsModalDialogHost* host_;
|
| + bool host_destroying_;
|
| +
|
| + // A target that accelerators that arrive at the host web contents widget will
|
| + // be forwarded to. Used to enable escape = dialog close for top level
|
| + // dialogs.
|
| + ui::AcceleratorTarget* target_;
|
| +
|
| + std::set<views::Widget*> observed_widgets_;
|
| + std::set<views::Widget*> shown_widgets_;
|
| +
|
| +// base::OneShotTimer timer_;
|
| +
|
| + // Tracks if Show() was called from within the manager or elsewhere.
|
| + bool called_internal_ = false;
|
| +
|
| + // Tracks if the top level window is currently minimized.
|
| + bool window_minimized_ = false;
|
| +
|
| + // Used to indicate if the call to Show() has been deferred to prevent focus
|
| + // problems - if true, Show() should be callled when the window is next
|
| + // re-stacked.
|
| + bool show_on_next_stack_ = false;
|
| +
|
| + // Whether or not the parent widget (host window) is inactive while the
|
| + // preview dialog is active.
|
| + bool parent_inactive_ = false;
|
| +
|
| + // Used to indicate that the state is being updated for a new host.
|
| + bool host_changing_ = false;
|
| +
|
| + bool need_to_show_ = false;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews);
|
| +};
|
| +#else
|
| class NativeWebContentsModalDialogManagerViews
|
| : public web_modal::SingleWebContentsDialogManager,
|
| public web_modal::ModalDialogHostObserver,
|
| @@ -27,13 +156,17 @@ class NativeWebContentsModalDialogManagerViews
|
| public:
|
| NativeWebContentsModalDialogManagerViews(
|
| gfx::NativeWindow dialog,
|
| - web_modal::SingleWebContentsDialogManagerDelegate* native_delegate);
|
| + web_modal::SingleWebContentsDialogManagerDelegate* native_delegate,
|
| + bool is_toplevel, ui::AcceleratorTarget* target);
|
|
|
| ~NativeWebContentsModalDialogManagerViews() override;
|
|
|
| // Sets up this object to manage the |dialog_|. Registers for closing events
|
| - // in order to notify the delegate.
|
| - void ManageDialog();
|
| + // in order to notify the delegate. If |is_toplevel| is true, the dialog will
|
| + // be set up as a top level dialog (peer of the host's native window), with
|
| + // the host as its transient parent. However, unlike most window modal
|
| + // dialogs, it will not block all events to its transient parent.
|
| + void ManageDialog(bool is_toplevel);
|
|
|
| // web_modal::SingleWebContentsDialogManager:
|
| void Show() override;
|
| @@ -76,17 +209,20 @@ class NativeWebContentsModalDialogManagerViews
|
|
|
| private:
|
| void WidgetClosing(views::Widget* widget);
|
| -
|
| + void OnNonClippedPositionRequiresUpdate();
|
| + void FocusInternal(views::Widget* widget);
|
| web_modal::SingleWebContentsDialogManagerDelegate* native_delegate_;
|
| gfx::NativeWindow dialog_;
|
| web_modal::WebContentsModalDialogHost* host_;
|
| bool host_destroying_;
|
| + ui::AcceleratorTarget* target_;
|
| std::set<views::Widget*> observed_widgets_;
|
| std::set<views::Widget*> shown_widgets_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews);
|
| };
|
|
|
| +#endif // USE_AURA
|
| } // namespace constrained_window
|
|
|
| #endif // COMPONENTS_CONSTRAINED_WINDOW_NATIVE_WEB_CONTENTS_MODAL_DIALOG_MANAGER_VIEWS_H_
|
|
|