Chromium Code Reviews| Index: chrome/browser/ui/views/web_contents_modal_dialog_manager_views.cc |
| diff --git a/chrome/browser/ui/views/web_contents_modal_dialog_manager_views.cc b/chrome/browser/ui/views/web_contents_modal_dialog_manager_views.cc |
| index be58bd1b72aab75c874d3e27db51e5f4f8513720..5e860f98a091a482788cb01392e026fc47e26a62 100644 |
| --- a/chrome/browser/ui/views/web_contents_modal_dialog_manager_views.cc |
| +++ b/chrome/browser/ui/views/web_contents_modal_dialog_manager_views.cc |
| @@ -2,6 +2,8 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "chrome/browser/ui/views/web_contents_modal_dialog_manager_views.h" |
| + |
| #include <memory> |
| #include <set> |
|
tapted
2016/05/04 03:29:25
move to header
Patti Lor
2016/05/11 01:35:19
Done.
|
| @@ -33,223 +35,203 @@ using web_modal::SingleWebContentsDialogManagerDelegate; |
| using web_modal::WebContentsModalDialogHost; |
| using web_modal::ModalDialogHostObserver; |
| -namespace { |
| - |
| -class NativeWebContentsModalDialogManagerViews |
| - : public SingleWebContentsDialogManager, |
| - public ModalDialogHostObserver, |
| - public views::WidgetObserver { |
| - public: |
| +NativeWebContentsModalDialogManagerViews:: |
| NativeWebContentsModalDialogManagerViews( |
| gfx::NativeWindow dialog, |
| SingleWebContentsDialogManagerDelegate* native_delegate) |
| - : native_delegate_(native_delegate), |
| - dialog_(dialog), |
| - host_(NULL), |
| - host_destroying_(false) { |
| - ManageDialog(); |
| - } |
| + : native_delegate_(native_delegate), |
| + dialog_(dialog), |
| + host_(NULL), |
| + host_destroying_(false) { |
| + ManageDialog(); |
| +} |
| - ~NativeWebContentsModalDialogManagerViews() override { |
| - if (host_) |
| - host_->RemoveObserver(this); |
| +NativeWebContentsModalDialogManagerViews:: |
| + ~NativeWebContentsModalDialogManagerViews() { |
| + if (host_) |
| + host_->RemoveObserver(this); |
| - for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); |
| - it != observed_widgets_.end(); |
| - ++it) { |
| - (*it)->RemoveObserver(this); |
| - } |
| + for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); |
| + it != observed_widgets_.end(); |
| + ++it) { |
| + (*it)->RemoveObserver(this); |
| } |
| +} |
| - // Sets up this object to manage the dialog_. Registers for closing events |
| - // in order to notify the delegate. |
| - virtual void ManageDialog() { |
| - views::Widget* widget = GetWidget(dialog()); |
| - widget->AddObserver(this); |
| - observed_widgets_.insert(widget); |
| - widget->set_movement_disabled(true); |
| +void NativeWebContentsModalDialogManagerViews::ManageDialog() { |
| + views::Widget* widget = GetWidget(dialog()); |
| + widget->AddObserver(this); |
| + observed_widgets_.insert(widget); |
| + widget->set_movement_disabled(true); |
| #if defined(USE_AURA) |
| - // TODO(wittman): remove once the new visual style is complete |
| - widget->GetNativeWindow()->SetProperty(aura::client::kConstrainedWindowKey, |
| - true); |
| - |
| - wm::SetWindowVisibilityAnimationType( |
| - widget->GetNativeWindow(), |
| - wm::WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE); |
| - |
| - gfx::NativeView parent = platform_util::GetParent(widget->GetNativeView()); |
| - wm::SetChildWindowVisibilityChangesAnimated(parent); |
| - // No animations should get performed on the window since that will re-order |
| - // the window stack which will then cause many problems. |
| - if (parent && parent->parent()) { |
| - parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, true); |
| - } |
| + // TODO(wittman): remove once the new visual style is complete |
| + widget->GetNativeWindow()->SetProperty(aura::client::kConstrainedWindowKey, |
| + true); |
| + |
| + wm::SetWindowVisibilityAnimationType( |
| + widget->GetNativeWindow(), |
| + wm::WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE); |
| + |
| + gfx::NativeView parent = platform_util::GetParent(widget->GetNativeView()); |
| + wm::SetChildWindowVisibilityChangesAnimated(parent); |
| + // No animations should get performed on the window since that will re-order |
| + // the window stack which will then cause many problems. |
| + if (parent && parent->parent()) { |
| + parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, true); |
| + } |
| - wm::SetModalParent( |
| - widget->GetNativeWindow(), |
| - native_delegate_->GetWebContents()->GetNativeView()); |
| + wm::SetModalParent( |
| + widget->GetNativeWindow(), |
| + native_delegate_->GetWebContents()->GetNativeView()); |
| #endif |
| - } |
| +} |
| + |
| +// SingleWebContentsDialogManager: |
| - // SingleWebContentsDialogManager overrides |
| - void Show() override { |
| - // The host destroying means the dialogs will be destroyed in short order. |
| - // Avoid showing dialogs at this point as the necessary native window |
| - // services may not be present. |
| - if (host_destroying_) |
| - return; |
| +void NativeWebContentsModalDialogManagerViews::Show() { |
| + // The host destroying means the dialogs will be destroyed in short order. |
| + // Avoid showing dialogs at this point as the necessary native window |
| + // services may not be present. |
| + if (host_destroying_) |
| + return; |
| - views::Widget* widget = GetWidget(dialog()); |
| + views::Widget* widget = GetWidget(dialog()); |
| #if defined(USE_AURA) |
| - std::unique_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; |
| - if (shown_widgets_.find(widget) != shown_widgets_.end()) { |
| - suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( |
| - widget->GetNativeWindow()->parent())); |
| - } |
| + std::unique_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; |
| + if (shown_widgets_.find(widget) != shown_widgets_.end()) { |
| + suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( |
| + widget->GetNativeWindow()->parent())); |
| + } |
| #endif |
| - // Host may be NULL during tab drag on Views/Win32. |
| - if (host_) |
| - constrained_window::UpdateWebContentsModalDialogPosition(widget, host_); |
| - widget->Show(); |
| - Focus(); |
| + ShowWidget(widget); |
| + Focus(); |
| #if defined(USE_AURA) |
| - // TODO(pkotwicz): Control the z-order of the constrained dialog via |
| - // views::kHostViewKey. We will need to ensure that the parent window's |
| - // shadows are below the constrained dialog in z-order when we do this. |
| - shown_widgets_.insert(widget); |
| + // TODO(pkotwicz): Control the z-order of the constrained dialog via |
| + // views::kHostViewKey. We will need to ensure that the parent window's |
| + // shadows are below the constrained dialog in z-order when we do this. |
| + shown_widgets_.insert(widget); |
| #endif |
| - } |
| +} |
| - void Hide() override { |
| - views::Widget* widget = GetWidget(dialog()); |
| +void NativeWebContentsModalDialogManagerViews::Hide() { |
| + views::Widget* widget = GetWidget(dialog()); |
| #if defined(USE_AURA) |
| - std::unique_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; |
| - suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( |
| - widget->GetNativeWindow()->parent())); |
| + std::unique_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; |
| + suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( |
| + widget->GetNativeWindow()->parent())); |
| #endif |
| - widget->Hide(); |
| - } |
| + HideWidget(widget); |
| +} |
| - void Close() override { GetWidget(dialog())->Close(); } |
| +void NativeWebContentsModalDialogManagerViews::Close() { |
| + GetWidget(dialog())->Close(); |
| +} |
| - void Focus() override { |
| - views::Widget* widget = GetWidget(dialog()); |
| - if (widget->widget_delegate() && |
| - widget->widget_delegate()->GetInitiallyFocusedView()) |
| - widget->widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); |
| +void NativeWebContentsModalDialogManagerViews::Focus() { |
| + views::Widget* widget = GetWidget(dialog()); |
| + if (widget->widget_delegate() && |
| + widget->widget_delegate()->GetInitiallyFocusedView()) |
| + widget->widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); |
| #if defined(USE_AURA) |
| - // We don't necessarily have a RootWindow yet. |
| - if (widget->GetNativeView()->GetRootWindow()) |
| - widget->GetNativeView()->Focus(); |
| + // We don't necessarily have a RootWindow yet. |
| + if (widget->GetNativeView()->GetRootWindow()) |
| + widget->GetNativeView()->Focus(); |
| #endif |
| - } |
| +} |
| - void Pulse() override {} |
| +// WebContentsModalDialogHostObserver: |
|
tapted
2016/05/04 03:29:25
nit: this comment isn't needed
Patti Lor
2016/05/11 01:35:19
Really? I've updated it to web_modal::ModalDialogH
|
| - // WebContentsModalDialogHostObserver overrides |
| - void OnPositionRequiresUpdate() override { |
| - DCHECK(host_); |
| +void NativeWebContentsModalDialogManagerViews::OnPositionRequiresUpdate() { |
| + DCHECK(host_); |
| - for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); |
| - it != observed_widgets_.end(); |
| - ++it) { |
| - constrained_window::UpdateWebContentsModalDialogPosition(*it, host_); |
| - } |
| + for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); |
| + it != observed_widgets_.end(); |
| + ++it) { |
| + constrained_window::UpdateWebContentsModalDialogPosition(*it, host_); |
| } |
| +} |
| - void OnHostDestroying() override { |
| - host_->RemoveObserver(this); |
| - host_ = NULL; |
| - host_destroying_ = true; |
| - } |
| +void NativeWebContentsModalDialogManagerViews::OnHostDestroying() { |
| + host_->RemoveObserver(this); |
| + host_ = NULL; |
| + host_destroying_ = true; |
| +} |
| - // views::WidgetObserver overrides |
| - |
| - // 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 { |
| - WidgetClosing(widget); |
| - } |
| +// views::WidgetObserver: |
| - void OnWidgetDestroying(views::Widget* widget) override { |
| - WidgetClosing(widget); |
| - } |
| +void NativeWebContentsModalDialogManagerViews::OnWidgetClosing( |
| + views::Widget* widget) { |
| + WidgetClosing(widget); |
| +} |
| - void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override { |
| - if (host_) |
| - host_->RemoveObserver(this); |
| +void NativeWebContentsModalDialogManagerViews::OnWidgetDestroying( |
| + views::Widget* widget) { |
| + WidgetClosing(widget); |
| +} |
| - host_ = new_host; |
| +void NativeWebContentsModalDialogManagerViews::HostChanged( |
| + WebContentsModalDialogHost* new_host) { |
| + if (host_) |
| + host_->RemoveObserver(this); |
| - // |host_| may be null during WebContents destruction or Win32 tab dragging. |
| - if (host_) { |
| - host_->AddObserver(this); |
| + host_ = new_host; |
| - for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); |
| - it != observed_widgets_.end(); |
| - ++it) { |
| - views::Widget::ReparentNativeView((*it)->GetNativeView(), |
| - host_->GetHostView()); |
| - } |
| + // |host_| may be null during WebContents destruction or Win32 tab dragging. |
| + if (host_) { |
| + host_->AddObserver(this); |
| - OnPositionRequiresUpdate(); |
| + for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); |
| + it != observed_widgets_.end(); |
| + ++it) { |
| + views::Widget::ReparentNativeView((*it)->GetNativeView(), |
| + host_->GetHostView()); |
| } |
| + |
| + OnPositionRequiresUpdate(); |
| } |
| +} |
| - gfx::NativeWindow dialog() override { return dialog_; } |
| +gfx::NativeWindow NativeWebContentsModalDialogManagerViews::dialog() { |
| + return dialog_; |
| +} |
| - private: |
| - static views::Widget* GetWidget(gfx::NativeWindow dialog) { |
| - views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog); |
| - DCHECK(widget); |
| - return widget; |
| - } |
| +void NativeWebContentsModalDialogManagerViews::ShowWidget( |
| + views::Widget* widget) { |
| + // Host may be NULL during tab drag on Views/Win32. |
| + if (host_) |
| + constrained_window::UpdateWebContentsModalDialogPosition(widget, host_); |
| + widget->Show(); |
| +} |
| + |
| +void NativeWebContentsModalDialogManagerViews::HideWidget( |
| + views::Widget* widget) { |
| + widget->Hide(); |
| +} |
| - void WidgetClosing(views::Widget* widget) { |
| +views::Widget* NativeWebContentsModalDialogManagerViews::GetWidget( |
| + gfx::NativeWindow dialog) { |
| + views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog); |
| + DCHECK(widget); |
| + return widget; |
| +} |
| + |
| +void NativeWebContentsModalDialogManagerViews::WidgetClosing( |
| + views::Widget* widget) { |
| #if defined(USE_AURA) |
| - gfx::NativeView view = platform_util::GetParent(widget->GetNativeView()); |
| - // Allow the parent to animate again. |
| - if (view && view->parent()) |
| - view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); |
| + gfx::NativeView view = platform_util::GetParent(widget->GetNativeView()); |
| + // Allow the parent to animate again. |
| + if (view && view->parent()) |
| + view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); |
| #endif |
| - widget->RemoveObserver(this); |
| - observed_widgets_.erase(widget); |
| + widget->RemoveObserver(this); |
| + observed_widgets_.erase(widget); |
| #if defined(USE_AURA) |
| - shown_widgets_.erase(widget); |
| + shown_widgets_.erase(widget); |
| #endif |
| - // Will cause this object to be deleted. |
| - native_delegate_->WillClose(widget->GetNativeWindow()); |
| - } |
| - |
| - SingleWebContentsDialogManagerDelegate* native_delegate_; |
| - gfx::NativeWindow dialog_; |
| - WebContentsModalDialogHost* host_; |
| - bool host_destroying_; |
| - std::set<views::Widget*> observed_widgets_; |
| - std::set<views::Widget*> shown_widgets_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews); |
| -}; |
| - |
| -} // namespace |
| - |
| -namespace web_modal { |
| - |
| -SingleWebContentsDialogManager* |
| -WebContentsModalDialogManager::CreateNativeWebModalManager( |
| - gfx::NativeWindow dialog, |
| - SingleWebContentsDialogManagerDelegate* native_delegate) { |
| - return new NativeWebContentsModalDialogManagerViews(dialog, native_delegate); |
| + // Will cause this object to be deleted. |
| + native_delegate_->WillClose(widget->GetNativeWindow()); |
| } |
| - |
| -} // namespace web_modal |