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