OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <set> | 5 #include <set> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/platform_util.h" | 8 #include "chrome/browser/platform_util.h" |
9 #include "chrome/browser/ui/views/constrained_window_views.h" | 9 #include "chrome/browser/ui/views/constrained_window_views.h" |
10 #include "components/web_modal/single_web_contents_dialog_manager.h" | 10 #include "components/web_modal/single_web_contents_dialog_manager.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, true); | 94 parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, true); |
95 } | 95 } |
96 | 96 |
97 wm::SetModalParent( | 97 wm::SetModalParent( |
98 widget->GetNativeWindow(), | 98 widget->GetNativeWindow(), |
99 platform_util::GetParent(widget->GetNativeView())); | 99 platform_util::GetParent(widget->GetNativeView())); |
100 #endif | 100 #endif |
101 } | 101 } |
102 | 102 |
103 // SingleWebContentsDialogManager overrides | 103 // SingleWebContentsDialogManager overrides |
104 virtual void Show() OVERRIDE { | 104 virtual void Show() override { |
105 views::Widget* widget = GetWidget(dialog()); | 105 views::Widget* widget = GetWidget(dialog()); |
106 #if defined(USE_AURA) | 106 #if defined(USE_AURA) |
107 scoped_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; | 107 scoped_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; |
108 if (shown_widgets_.find(widget) != shown_widgets_.end()) { | 108 if (shown_widgets_.find(widget) != shown_widgets_.end()) { |
109 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( | 109 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( |
110 widget->GetNativeWindow()->parent())); | 110 widget->GetNativeWindow()->parent())); |
111 } | 111 } |
112 #endif | 112 #endif |
113 // Host may be NULL during tab drag on Views/Win32. | 113 // Host may be NULL during tab drag on Views/Win32. |
114 if (host_) | 114 if (host_) |
115 UpdateWebContentsModalDialogPosition(widget, host_); | 115 UpdateWebContentsModalDialogPosition(widget, host_); |
116 widget->Show(); | 116 widget->Show(); |
117 Focus(); | 117 Focus(); |
118 | 118 |
119 #if defined(USE_AURA) | 119 #if defined(USE_AURA) |
120 // TODO(pkotwicz): Control the z-order of the constrained dialog via | 120 // TODO(pkotwicz): Control the z-order of the constrained dialog via |
121 // views::kHostViewKey. We will need to ensure that the parent window's | 121 // views::kHostViewKey. We will need to ensure that the parent window's |
122 // shadows are below the constrained dialog in z-order when we do this. | 122 // shadows are below the constrained dialog in z-order when we do this. |
123 shown_widgets_.insert(widget); | 123 shown_widgets_.insert(widget); |
124 #endif | 124 #endif |
125 } | 125 } |
126 | 126 |
127 virtual void Hide() OVERRIDE { | 127 virtual void Hide() override { |
128 views::Widget* widget = GetWidget(dialog()); | 128 views::Widget* widget = GetWidget(dialog()); |
129 #if defined(USE_AURA) | 129 #if defined(USE_AURA) |
130 scoped_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; | 130 scoped_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; |
131 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( | 131 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( |
132 widget->GetNativeWindow()->parent())); | 132 widget->GetNativeWindow()->parent())); |
133 #endif | 133 #endif |
134 widget->Hide(); | 134 widget->Hide(); |
135 } | 135 } |
136 | 136 |
137 virtual void Close() OVERRIDE { | 137 virtual void Close() override { |
138 GetWidget(dialog())->Close(); | 138 GetWidget(dialog())->Close(); |
139 } | 139 } |
140 | 140 |
141 virtual void Focus() OVERRIDE { | 141 virtual void Focus() override { |
142 views::Widget* widget = GetWidget(dialog()); | 142 views::Widget* widget = GetWidget(dialog()); |
143 if (widget->widget_delegate() && | 143 if (widget->widget_delegate() && |
144 widget->widget_delegate()->GetInitiallyFocusedView()) | 144 widget->widget_delegate()->GetInitiallyFocusedView()) |
145 widget->widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); | 145 widget->widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); |
146 #if defined(USE_ASH) | 146 #if defined(USE_ASH) |
147 // We don't necessarily have a RootWindow yet. | 147 // We don't necessarily have a RootWindow yet. |
148 if (widget->GetNativeView()->GetRootWindow()) | 148 if (widget->GetNativeView()->GetRootWindow()) |
149 widget->GetNativeView()->Focus(); | 149 widget->GetNativeView()->Focus(); |
150 #endif | 150 #endif |
151 } | 151 } |
152 | 152 |
153 virtual void Pulse() OVERRIDE { | 153 virtual void Pulse() override { |
154 } | 154 } |
155 | 155 |
156 // WebContentsModalDialogHostObserver overrides | 156 // WebContentsModalDialogHostObserver overrides |
157 virtual void OnPositionRequiresUpdate() OVERRIDE { | 157 virtual void OnPositionRequiresUpdate() override { |
158 DCHECK(host_); | 158 DCHECK(host_); |
159 | 159 |
160 for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); | 160 for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); |
161 it != observed_widgets_.end(); | 161 it != observed_widgets_.end(); |
162 ++it) { | 162 ++it) { |
163 UpdateWebContentsModalDialogPosition(*it, host_); | 163 UpdateWebContentsModalDialogPosition(*it, host_); |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 virtual void OnHostDestroying() OVERRIDE { | 167 virtual void OnHostDestroying() override { |
168 host_->RemoveObserver(this); | 168 host_->RemoveObserver(this); |
169 host_ = NULL; | 169 host_ = NULL; |
170 } | 170 } |
171 | 171 |
172 // views::WidgetObserver overrides | 172 // views::WidgetObserver overrides |
173 | 173 |
174 // NOTE(wittman): OnWidgetClosing is overriden to ensure that, when the widget | 174 // NOTE(wittman): OnWidgetClosing is overriden to ensure that, when the widget |
175 // is explicitly closed, the destruction occurs within the same call | 175 // is explicitly closed, the destruction occurs within the same call |
176 // stack. This avoids event races that lead to non-deterministic destruction | 176 // stack. This avoids event races that lead to non-deterministic destruction |
177 // ordering in e.g. the print preview dialog. OnWidgetDestroying is overridden | 177 // ordering in e.g. the print preview dialog. OnWidgetDestroying is overridden |
178 // because OnWidgetClosing is *only* invoked on explicit close, not when the | 178 // because OnWidgetClosing is *only* invoked on explicit close, not when the |
179 // widget is implicitly destroyed due to its parent being closed. This | 179 // widget is implicitly destroyed due to its parent being closed. This |
180 // situation occurs with app windows. WidgetClosing removes the observer, so | 180 // situation occurs with app windows. WidgetClosing removes the observer, so |
181 // only one of these two functions is ever invoked for a given widget. | 181 // only one of these two functions is ever invoked for a given widget. |
182 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { | 182 virtual void OnWidgetClosing(views::Widget* widget) override { |
183 WidgetClosing(widget); | 183 WidgetClosing(widget); |
184 } | 184 } |
185 | 185 |
186 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE { | 186 virtual void OnWidgetDestroying(views::Widget* widget) override { |
187 WidgetClosing(widget); | 187 WidgetClosing(widget); |
188 } | 188 } |
189 | 189 |
190 virtual void HostChanged( | 190 virtual void HostChanged( |
191 web_modal::WebContentsModalDialogHost* new_host) OVERRIDE { | 191 web_modal::WebContentsModalDialogHost* new_host) override { |
192 if (host_) | 192 if (host_) |
193 host_->RemoveObserver(this); | 193 host_->RemoveObserver(this); |
194 | 194 |
195 host_ = new_host; | 195 host_ = new_host; |
196 | 196 |
197 // |host_| may be null during WebContents destruction or Win32 tab dragging. | 197 // |host_| may be null during WebContents destruction or Win32 tab dragging. |
198 if (host_) { | 198 if (host_) { |
199 host_->AddObserver(this); | 199 host_->AddObserver(this); |
200 | 200 |
201 for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); | 201 for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); |
202 it != observed_widgets_.end(); | 202 it != observed_widgets_.end(); |
203 ++it) { | 203 ++it) { |
204 views::Widget::ReparentNativeView((*it)->GetNativeView(), | 204 views::Widget::ReparentNativeView((*it)->GetNativeView(), |
205 host_->GetHostView()); | 205 host_->GetHostView()); |
206 } | 206 } |
207 | 207 |
208 OnPositionRequiresUpdate(); | 208 OnPositionRequiresUpdate(); |
209 } | 209 } |
210 } | 210 } |
211 | 211 |
212 virtual NativeWebContentsModalDialog dialog() OVERRIDE { | 212 virtual NativeWebContentsModalDialog dialog() override { |
213 return dialog_; | 213 return dialog_; |
214 } | 214 } |
215 | 215 |
216 private: | 216 private: |
217 static views::Widget* GetWidget(NativeWebContentsModalDialog dialog) { | 217 static views::Widget* GetWidget(NativeWebContentsModalDialog dialog) { |
218 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog); | 218 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog); |
219 DCHECK(widget); | 219 DCHECK(widget); |
220 return widget; | 220 return widget; |
221 } | 221 } |
222 | 222 |
(...skipping 29 matching lines...) Expand all Loading... |
252 namespace web_modal { | 252 namespace web_modal { |
253 | 253 |
254 SingleWebContentsDialogManager* WebContentsModalDialogManager:: | 254 SingleWebContentsDialogManager* WebContentsModalDialogManager:: |
255 CreateNativeWebModalManager( | 255 CreateNativeWebModalManager( |
256 NativeWebContentsModalDialog dialog, | 256 NativeWebContentsModalDialog dialog, |
257 SingleWebContentsDialogManagerDelegate* native_delegate) { | 257 SingleWebContentsDialogManagerDelegate* native_delegate) { |
258 return new NativeWebContentsModalDialogManagerViews(dialog, native_delegate); | 258 return new NativeWebContentsModalDialogManagerViews(dialog, native_delegate); |
259 } | 259 } |
260 | 260 |
261 } // namespace web_modal | 261 } // namespace web_modal |
OLD | NEW |