| 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 #include "components/constrained_window/native_web_contents_modal_dialog_manager
_views.h" | 5 #include "components/constrained_window/native_web_contents_modal_dialog_manager
_views.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "components/constrained_window/constrained_window_views.h" | 9 #include "components/constrained_window/constrained_window_views.h" |
| 10 #include "components/web_modal/web_contents_modal_dialog_host.h" | 10 #include "components/web_modal/web_contents_modal_dialog_host.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 return; | 91 return; |
| 92 | 92 |
| 93 views::Widget* widget = GetWidget(dialog()); | 93 views::Widget* widget = GetWidget(dialog()); |
| 94 #if defined(USE_AURA) | 94 #if defined(USE_AURA) |
| 95 std::unique_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; | 95 std::unique_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; |
| 96 if (shown_widgets_.find(widget) != shown_widgets_.end()) { | 96 if (shown_widgets_.find(widget) != shown_widgets_.end()) { |
| 97 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( | 97 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( |
| 98 widget->GetNativeWindow()->parent())); | 98 widget->GetNativeWindow()->parent())); |
| 99 } | 99 } |
| 100 #endif | 100 #endif |
| 101 // Host may be NULL during tab drag on Views/Win32. | 101 ShowWidget(widget); |
| 102 if (host_) | |
| 103 constrained_window::UpdateWebContentsModalDialogPosition(widget, host_); | |
| 104 widget->Show(); | |
| 105 Focus(); | 102 Focus(); |
| 106 | 103 |
| 107 #if defined(USE_AURA) | 104 #if defined(USE_AURA) |
| 108 // TODO(pkotwicz): Control the z-order of the constrained dialog via | 105 // TODO(pkotwicz): Control the z-order of the constrained dialog via |
| 109 // views::kHostViewKey. We will need to ensure that the parent window's | 106 // views::kHostViewKey. We will need to ensure that the parent window's |
| 110 // shadows are below the constrained dialog in z-order when we do this. | 107 // shadows are below the constrained dialog in z-order when we do this. |
| 111 shown_widgets_.insert(widget); | 108 shown_widgets_.insert(widget); |
| 112 #endif | 109 #endif |
| 113 } | 110 } |
| 114 | 111 |
| 115 void NativeWebContentsModalDialogManagerViews::Hide() { | 112 void NativeWebContentsModalDialogManagerViews::Hide() { |
| 116 views::Widget* widget = GetWidget(dialog()); | 113 views::Widget* widget = GetWidget(dialog()); |
| 117 #if defined(USE_AURA) | 114 #if defined(USE_AURA) |
| 118 std::unique_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; | 115 std::unique_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; |
| 119 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( | 116 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( |
| 120 widget->GetNativeWindow()->parent())); | 117 widget->GetNativeWindow()->parent())); |
| 121 #endif | 118 #endif |
| 122 widget->Hide(); | 119 HideWidget(widget); |
| 123 } | 120 } |
| 124 | 121 |
| 125 void NativeWebContentsModalDialogManagerViews::Close() { | 122 void NativeWebContentsModalDialogManagerViews::Close() { |
| 126 GetWidget(dialog())->Close(); | 123 GetWidget(dialog())->Close(); |
| 127 } | 124 } |
| 128 | 125 |
| 129 void NativeWebContentsModalDialogManagerViews::Focus() { | 126 void NativeWebContentsModalDialogManagerViews::Focus() { |
| 130 views::Widget* widget = GetWidget(dialog()); | 127 views::Widget* widget = GetWidget(dialog()); |
| 131 if (widget->widget_delegate() && | 128 if (widget->widget_delegate() && |
| 132 widget->widget_delegate()->GetInitiallyFocusedView()) | 129 widget->widget_delegate()->GetInitiallyFocusedView()) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 } | 184 } |
| 188 | 185 |
| 189 OnPositionRequiresUpdate(); | 186 OnPositionRequiresUpdate(); |
| 190 } | 187 } |
| 191 } | 188 } |
| 192 | 189 |
| 193 gfx::NativeWindow NativeWebContentsModalDialogManagerViews::dialog() { | 190 gfx::NativeWindow NativeWebContentsModalDialogManagerViews::dialog() { |
| 194 return dialog_; | 191 return dialog_; |
| 195 } | 192 } |
| 196 | 193 |
| 194 void NativeWebContentsModalDialogManagerViews::ShowWidget( |
| 195 views::Widget* widget) { |
| 196 // |host_| may be NULL during tab drag on Views/Win32. |
| 197 if (host_) |
| 198 constrained_window::UpdateWebContentsModalDialogPosition(widget, host_); |
| 199 widget->Show(); |
| 200 } |
| 201 |
| 202 void NativeWebContentsModalDialogManagerViews::HideWidget( |
| 203 views::Widget* widget) { |
| 204 widget->Hide(); |
| 205 } |
| 206 |
| 197 views::Widget* NativeWebContentsModalDialogManagerViews::GetWidget( | 207 views::Widget* NativeWebContentsModalDialogManagerViews::GetWidget( |
| 198 gfx::NativeWindow dialog) { | 208 gfx::NativeWindow dialog) { |
| 199 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog); | 209 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog); |
| 200 DCHECK(widget); | 210 DCHECK(widget); |
| 201 return widget; | 211 return widget; |
| 202 } | 212 } |
| 203 | 213 |
| 204 void NativeWebContentsModalDialogManagerViews::WidgetClosing( | 214 void NativeWebContentsModalDialogManagerViews::WidgetClosing( |
| 205 views::Widget* widget) { | 215 views::Widget* widget) { |
| 206 #if defined(USE_AURA) | 216 #if defined(USE_AURA) |
| 207 gfx::NativeView view = widget->GetNativeView()->parent(); | 217 gfx::NativeView view = widget->GetNativeView()->parent(); |
| 208 // Allow the parent to animate again. | 218 // Allow the parent to animate again. |
| 209 if (view && view->parent()) | 219 if (view && view->parent()) |
| 210 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); | 220 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); |
| 211 #endif | 221 #endif |
| 212 widget->RemoveObserver(this); | 222 widget->RemoveObserver(this); |
| 213 observed_widgets_.erase(widget); | 223 observed_widgets_.erase(widget); |
| 214 | 224 |
| 215 #if defined(USE_AURA) | 225 #if defined(USE_AURA) |
| 216 shown_widgets_.erase(widget); | 226 shown_widgets_.erase(widget); |
| 217 #endif | 227 #endif |
| 218 | 228 |
| 219 // Will cause this object to be deleted. | 229 // Will cause this object to be deleted. |
| 220 native_delegate_->WillClose(widget->GetNativeWindow()); | 230 native_delegate_->WillClose(widget->GetNativeWindow()); |
| 221 } | 231 } |
| 222 | 232 |
| 223 } // namespace constrained_window | 233 } // namespace constrained_window |
| OLD | NEW |