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 "components/constrained_window/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" | |
10 #include "components/constrained_window/constrained_window_views.h" | 9 #include "components/constrained_window/constrained_window_views.h" |
11 #include "components/web_modal/web_contents_modal_dialog_host.h" | 10 #include "components/web_modal/web_contents_modal_dialog_host.h" |
12 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 11 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
13 #include "ui/gfx/geometry/point.h" | 12 #include "ui/gfx/geometry/point.h" |
14 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
15 #include "ui/views/border.h" | 14 #include "ui/views/border.h" |
16 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
17 #include "ui/views/widget/widget_delegate.h" | 16 #include "ui/views/widget/widget_delegate.h" |
18 #include "ui/views/window/dialog_delegate.h" | 17 #include "ui/views/window/dialog_delegate.h" |
19 #include "ui/views/window/non_client_view.h" | 18 #include "ui/views/window/non_client_view.h" |
20 | 19 |
21 #if defined(USE_AURA) | 20 #if defined(USE_AURA) |
22 #include "ui/aura/client/aura_constants.h" | 21 #include "ui/aura/client/aura_constants.h" |
23 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
24 #include "ui/wm/core/visibility_controller.h" | 23 #include "ui/wm/core/visibility_controller.h" |
25 #include "ui/wm/core/window_animations.h" | 24 #include "ui/wm/core/window_animations.h" |
26 #include "ui/wm/core/window_modality_controller.h" | 25 #include "ui/wm/core/window_modality_controller.h" |
27 #endif | 26 #endif |
28 | 27 |
29 using web_modal::SingleWebContentsDialogManager; | 28 using web_modal::SingleWebContentsDialogManager; |
30 using web_modal::SingleWebContentsDialogManagerDelegate; | 29 using web_modal::SingleWebContentsDialogManagerDelegate; |
31 using web_modal::WebContentsModalDialogHost; | 30 using web_modal::WebContentsModalDialogHost; |
32 using web_modal::ModalDialogHostObserver; | 31 using web_modal::ModalDialogHostObserver; |
33 | 32 |
| 33 namespace constrained_window { |
| 34 |
34 NativeWebContentsModalDialogManagerViews:: | 35 NativeWebContentsModalDialogManagerViews:: |
35 NativeWebContentsModalDialogManagerViews( | 36 NativeWebContentsModalDialogManagerViews( |
36 gfx::NativeWindow dialog, | 37 gfx::NativeWindow dialog, |
37 SingleWebContentsDialogManagerDelegate* native_delegate) | 38 SingleWebContentsDialogManagerDelegate* native_delegate) |
38 : native_delegate_(native_delegate), | 39 : native_delegate_(native_delegate), |
39 dialog_(dialog), | 40 dialog_(dialog), |
40 host_(NULL), | 41 host_(NULL), |
41 host_destroying_(false) { | 42 host_destroying_(false) { |
42 ManageDialog(); | 43 ManageDialog(); |
43 } | 44 } |
(...skipping 16 matching lines...) Expand all Loading... |
60 widget->set_movement_disabled(true); | 61 widget->set_movement_disabled(true); |
61 | 62 |
62 #if defined(USE_AURA) | 63 #if defined(USE_AURA) |
63 // TODO(wittman): remove once the new visual style is complete | 64 // TODO(wittman): remove once the new visual style is complete |
64 widget->GetNativeWindow()->SetProperty(aura::client::kConstrainedWindowKey, | 65 widget->GetNativeWindow()->SetProperty(aura::client::kConstrainedWindowKey, |
65 true); | 66 true); |
66 | 67 |
67 wm::SetWindowVisibilityAnimationType( | 68 wm::SetWindowVisibilityAnimationType( |
68 widget->GetNativeWindow(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE); | 69 widget->GetNativeWindow(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE); |
69 | 70 |
70 gfx::NativeView parent = platform_util::GetParent(widget->GetNativeView()); | 71 gfx::NativeView parent = widget->GetNativeView()->parent(); |
71 wm::SetChildWindowVisibilityChangesAnimated(parent); | 72 wm::SetChildWindowVisibilityChangesAnimated(parent); |
72 // No animations should get performed on the window since that will re-order | 73 // No animations should get performed on the window since that will re-order |
73 // the window stack which will then cause many problems. | 74 // the window stack which will then cause many problems. |
74 if (parent && parent->parent()) { | 75 if (parent && parent->parent()) { |
75 parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, true); | 76 parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, true); |
76 } | 77 } |
77 | 78 |
78 wm::SetModalParent(widget->GetNativeWindow(), | 79 wm::SetModalParent(widget->GetNativeWindow(), |
79 native_delegate_->GetWebContents()->GetNativeView()); | 80 native_delegate_->GetWebContents()->GetNativeView()); |
80 #endif | 81 #endif |
81 } | 82 } |
82 | 83 |
83 // SingleWebContentsDialogManager: | 84 // SingleWebContentsDialogManager: |
84 | 85 |
85 void NativeWebContentsModalDialogManagerViews::Show() { | 86 void NativeWebContentsModalDialogManagerViews::Show() { |
86 // The host destroying means the dialogs will be destroyed in short order. | 87 // The host destroying means the dialogs will be destroyed in short order. |
87 // Avoid showing dialogs at this point as the necessary native window | 88 // Avoid showing dialogs at this point as the necessary native window |
88 // services may not be present. | 89 // services may not be present. |
89 if (host_destroying_) | 90 if (host_destroying_) |
90 return; | 91 return; |
91 | 92 |
92 views::Widget* widget = GetWidget(dialog()); | 93 views::Widget* widget = GetWidget(dialog()); |
93 #if defined(USE_AURA) | 94 #if defined(USE_AURA) |
94 std::unique_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; | 95 std::unique_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; |
95 if (shown_widgets_.find(widget) != shown_widgets_.end()) { | 96 if (shown_widgets_.find(widget) != shown_widgets_.end()) { |
96 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( | 97 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( |
97 widget->GetNativeWindow()->parent())); | 98 widget->GetNativeWindow()->parent())); |
98 } | 99 } |
99 #endif | 100 #endif |
100 // Host may be NULL during tab drag on Views/Win32. | 101 ShowWidget(widget); |
101 if (host_) | |
102 constrained_window::UpdateWebContentsModalDialogPosition(widget, host_); | |
103 widget->Show(); | |
104 Focus(); | 102 Focus(); |
105 | 103 |
106 #if defined(USE_AURA) | 104 #if defined(USE_AURA) |
107 // TODO(pkotwicz): Control the z-order of the constrained dialog via | 105 // TODO(pkotwicz): Control the z-order of the constrained dialog via |
108 // 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 |
109 // 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. |
110 shown_widgets_.insert(widget); | 108 shown_widgets_.insert(widget); |
111 #endif | 109 #endif |
112 } | 110 } |
113 | 111 |
114 void NativeWebContentsModalDialogManagerViews::Hide() { | 112 void NativeWebContentsModalDialogManagerViews::Hide() { |
115 views::Widget* widget = GetWidget(dialog()); | 113 views::Widget* widget = GetWidget(dialog()); |
116 #if defined(USE_AURA) | 114 #if defined(USE_AURA) |
117 std::unique_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; | 115 std::unique_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; |
118 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( | 116 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( |
119 widget->GetNativeWindow()->parent())); | 117 widget->GetNativeWindow()->parent())); |
120 #endif | 118 #endif |
121 widget->Hide(); | 119 HideWidget(widget); |
122 } | 120 } |
123 | 121 |
124 void NativeWebContentsModalDialogManagerViews::Close() { | 122 void NativeWebContentsModalDialogManagerViews::Close() { |
125 GetWidget(dialog())->Close(); | 123 GetWidget(dialog())->Close(); |
126 } | 124 } |
127 | 125 |
128 void NativeWebContentsModalDialogManagerViews::Focus() { | 126 void NativeWebContentsModalDialogManagerViews::Focus() { |
129 views::Widget* widget = GetWidget(dialog()); | 127 views::Widget* widget = GetWidget(dialog()); |
130 if (widget->widget_delegate() && | 128 if (widget->widget_delegate() && |
131 widget->widget_delegate()->GetInitiallyFocusedView()) | 129 widget->widget_delegate()->GetInitiallyFocusedView()) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 184 } |
187 | 185 |
188 OnPositionRequiresUpdate(); | 186 OnPositionRequiresUpdate(); |
189 } | 187 } |
190 } | 188 } |
191 | 189 |
192 gfx::NativeWindow NativeWebContentsModalDialogManagerViews::dialog() { | 190 gfx::NativeWindow NativeWebContentsModalDialogManagerViews::dialog() { |
193 return dialog_; | 191 return dialog_; |
194 } | 192 } |
195 | 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 |
196 views::Widget* NativeWebContentsModalDialogManagerViews::GetWidget( | 207 views::Widget* NativeWebContentsModalDialogManagerViews::GetWidget( |
197 gfx::NativeWindow dialog) { | 208 gfx::NativeWindow dialog) { |
198 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog); | 209 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog); |
199 DCHECK(widget); | 210 DCHECK(widget); |
200 return widget; | 211 return widget; |
201 } | 212 } |
202 | 213 |
203 void NativeWebContentsModalDialogManagerViews::WidgetClosing( | 214 void NativeWebContentsModalDialogManagerViews::WidgetClosing( |
204 views::Widget* widget) { | 215 views::Widget* widget) { |
205 #if defined(USE_AURA) | 216 #if defined(USE_AURA) |
206 gfx::NativeView view = platform_util::GetParent(widget->GetNativeView()); | 217 gfx::NativeView view = widget->GetNativeView()->parent(); |
207 // Allow the parent to animate again. | 218 // Allow the parent to animate again. |
208 if (view && view->parent()) | 219 if (view && view->parent()) |
209 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); | 220 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); |
210 #endif | 221 #endif |
211 widget->RemoveObserver(this); | 222 widget->RemoveObserver(this); |
212 observed_widgets_.erase(widget); | 223 observed_widgets_.erase(widget); |
213 | 224 |
214 #if defined(USE_AURA) | 225 #if defined(USE_AURA) |
215 shown_widgets_.erase(widget); | 226 shown_widgets_.erase(widget); |
216 #endif | 227 #endif |
217 | 228 |
218 // Will cause this object to be deleted. | 229 // Will cause this object to be deleted. |
219 native_delegate_->WillClose(widget->GetNativeWindow()); | 230 native_delegate_->WillClose(widget->GetNativeWindow()); |
220 } | 231 } |
| 232 |
| 233 } // namespace constrained_window |
OLD | NEW |