| 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 "components/constrained_window/constrained_window_views.h" | 9 #include "components/constrained_window/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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 public: | 42 public: |
| 43 NativeWebContentsModalDialogManagerViews( | 43 NativeWebContentsModalDialogManagerViews( |
| 44 NativeWebContentsModalDialog dialog, | 44 NativeWebContentsModalDialog dialog, |
| 45 SingleWebContentsDialogManagerDelegate* native_delegate) | 45 SingleWebContentsDialogManagerDelegate* native_delegate) |
| 46 : native_delegate_(native_delegate), | 46 : native_delegate_(native_delegate), |
| 47 dialog_(dialog), | 47 dialog_(dialog), |
| 48 host_(NULL) { | 48 host_(NULL) { |
| 49 ManageDialog(); | 49 ManageDialog(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 virtual ~NativeWebContentsModalDialogManagerViews() { | 52 ~NativeWebContentsModalDialogManagerViews() override { |
| 53 if (host_) | 53 if (host_) |
| 54 host_->RemoveObserver(this); | 54 host_->RemoveObserver(this); |
| 55 | 55 |
| 56 for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); | 56 for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); |
| 57 it != observed_widgets_.end(); | 57 it != observed_widgets_.end(); |
| 58 ++it) { | 58 ++it) { |
| 59 (*it)->RemoveObserver(this); | 59 (*it)->RemoveObserver(this); |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 85 parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, true); | 85 parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, true); |
| 86 } | 86 } |
| 87 | 87 |
| 88 wm::SetModalParent( | 88 wm::SetModalParent( |
| 89 widget->GetNativeWindow(), | 89 widget->GetNativeWindow(), |
| 90 platform_util::GetParent(widget->GetNativeView())); | 90 platform_util::GetParent(widget->GetNativeView())); |
| 91 #endif | 91 #endif |
| 92 } | 92 } |
| 93 | 93 |
| 94 // SingleWebContentsDialogManager overrides | 94 // SingleWebContentsDialogManager overrides |
| 95 virtual void Show() override { | 95 void Show() override { |
| 96 views::Widget* widget = GetWidget(dialog()); | 96 views::Widget* widget = GetWidget(dialog()); |
| 97 #if defined(USE_AURA) | 97 #if defined(USE_AURA) |
| 98 scoped_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; | 98 scoped_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; |
| 99 if (shown_widgets_.find(widget) != shown_widgets_.end()) { | 99 if (shown_widgets_.find(widget) != shown_widgets_.end()) { |
| 100 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( | 100 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( |
| 101 widget->GetNativeWindow()->parent())); | 101 widget->GetNativeWindow()->parent())); |
| 102 } | 102 } |
| 103 #endif | 103 #endif |
| 104 // Host may be NULL during tab drag on Views/Win32. | 104 // Host may be NULL during tab drag on Views/Win32. |
| 105 if (host_) | 105 if (host_) |
| 106 UpdateWebContentsModalDialogPosition(widget, host_); | 106 UpdateWebContentsModalDialogPosition(widget, host_); |
| 107 widget->Show(); | 107 widget->Show(); |
| 108 Focus(); | 108 Focus(); |
| 109 | 109 |
| 110 #if defined(USE_AURA) | 110 #if defined(USE_AURA) |
| 111 // TODO(pkotwicz): Control the z-order of the constrained dialog via | 111 // TODO(pkotwicz): Control the z-order of the constrained dialog via |
| 112 // views::kHostViewKey. We will need to ensure that the parent window's | 112 // views::kHostViewKey. We will need to ensure that the parent window's |
| 113 // shadows are below the constrained dialog in z-order when we do this. | 113 // shadows are below the constrained dialog in z-order when we do this. |
| 114 shown_widgets_.insert(widget); | 114 shown_widgets_.insert(widget); |
| 115 #endif | 115 #endif |
| 116 } | 116 } |
| 117 | 117 |
| 118 virtual void Hide() override { | 118 void Hide() override { |
| 119 views::Widget* widget = GetWidget(dialog()); | 119 views::Widget* widget = GetWidget(dialog()); |
| 120 #if defined(USE_AURA) | 120 #if defined(USE_AURA) |
| 121 scoped_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; | 121 scoped_ptr<wm::SuspendChildWindowVisibilityAnimations> suspend; |
| 122 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( | 122 suspend.reset(new wm::SuspendChildWindowVisibilityAnimations( |
| 123 widget->GetNativeWindow()->parent())); | 123 widget->GetNativeWindow()->parent())); |
| 124 #endif | 124 #endif |
| 125 widget->Hide(); | 125 widget->Hide(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 virtual void Close() override { | 128 void Close() override { GetWidget(dialog())->Close(); } |
| 129 GetWidget(dialog())->Close(); | |
| 130 } | |
| 131 | 129 |
| 132 virtual void Focus() override { | 130 void Focus() override { |
| 133 views::Widget* widget = GetWidget(dialog()); | 131 views::Widget* widget = GetWidget(dialog()); |
| 134 if (widget->widget_delegate() && | 132 if (widget->widget_delegate() && |
| 135 widget->widget_delegate()->GetInitiallyFocusedView()) | 133 widget->widget_delegate()->GetInitiallyFocusedView()) |
| 136 widget->widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); | 134 widget->widget_delegate()->GetInitiallyFocusedView()->RequestFocus(); |
| 137 #if defined(USE_AURA) | 135 #if defined(USE_AURA) |
| 138 // We don't necessarily have a RootWindow yet. | 136 // We don't necessarily have a RootWindow yet. |
| 139 if (widget->GetNativeView()->GetRootWindow()) | 137 if (widget->GetNativeView()->GetRootWindow()) |
| 140 widget->GetNativeView()->Focus(); | 138 widget->GetNativeView()->Focus(); |
| 141 #endif | 139 #endif |
| 142 } | 140 } |
| 143 | 141 |
| 144 virtual void Pulse() override { | 142 void Pulse() override {} |
| 145 } | |
| 146 | 143 |
| 147 // WebContentsModalDialogHostObserver overrides | 144 // WebContentsModalDialogHostObserver overrides |
| 148 virtual void OnPositionRequiresUpdate() override { | 145 void OnPositionRequiresUpdate() override { |
| 149 DCHECK(host_); | 146 DCHECK(host_); |
| 150 | 147 |
| 151 for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); | 148 for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); |
| 152 it != observed_widgets_.end(); | 149 it != observed_widgets_.end(); |
| 153 ++it) { | 150 ++it) { |
| 154 UpdateWebContentsModalDialogPosition(*it, host_); | 151 UpdateWebContentsModalDialogPosition(*it, host_); |
| 155 } | 152 } |
| 156 } | 153 } |
| 157 | 154 |
| 158 virtual void OnHostDestroying() override { | 155 void OnHostDestroying() override { |
| 159 host_->RemoveObserver(this); | 156 host_->RemoveObserver(this); |
| 160 host_ = NULL; | 157 host_ = NULL; |
| 161 } | 158 } |
| 162 | 159 |
| 163 // views::WidgetObserver overrides | 160 // views::WidgetObserver overrides |
| 164 | 161 |
| 165 // NOTE(wittman): OnWidgetClosing is overriden to ensure that, when the widget | 162 // NOTE(wittman): OnWidgetClosing is overriden to ensure that, when the widget |
| 166 // is explicitly closed, the destruction occurs within the same call | 163 // is explicitly closed, the destruction occurs within the same call |
| 167 // stack. This avoids event races that lead to non-deterministic destruction | 164 // stack. This avoids event races that lead to non-deterministic destruction |
| 168 // ordering in e.g. the print preview dialog. OnWidgetDestroying is overridden | 165 // ordering in e.g. the print preview dialog. OnWidgetDestroying is overridden |
| 169 // because OnWidgetClosing is *only* invoked on explicit close, not when the | 166 // because OnWidgetClosing is *only* invoked on explicit close, not when the |
| 170 // widget is implicitly destroyed due to its parent being closed. This | 167 // widget is implicitly destroyed due to its parent being closed. This |
| 171 // situation occurs with app windows. WidgetClosing removes the observer, so | 168 // situation occurs with app windows. WidgetClosing removes the observer, so |
| 172 // only one of these two functions is ever invoked for a given widget. | 169 // only one of these two functions is ever invoked for a given widget. |
| 173 virtual void OnWidgetClosing(views::Widget* widget) override { | 170 void OnWidgetClosing(views::Widget* widget) override { |
| 174 WidgetClosing(widget); | 171 WidgetClosing(widget); |
| 175 } | 172 } |
| 176 | 173 |
| 177 virtual void OnWidgetDestroying(views::Widget* widget) override { | 174 void OnWidgetDestroying(views::Widget* widget) override { |
| 178 WidgetClosing(widget); | 175 WidgetClosing(widget); |
| 179 } | 176 } |
| 180 | 177 |
| 181 virtual void HostChanged( | 178 void HostChanged(web_modal::WebContentsModalDialogHost* new_host) override { |
| 182 web_modal::WebContentsModalDialogHost* new_host) override { | |
| 183 if (host_) | 179 if (host_) |
| 184 host_->RemoveObserver(this); | 180 host_->RemoveObserver(this); |
| 185 | 181 |
| 186 host_ = new_host; | 182 host_ = new_host; |
| 187 | 183 |
| 188 // |host_| may be null during WebContents destruction or Win32 tab dragging. | 184 // |host_| may be null during WebContents destruction or Win32 tab dragging. |
| 189 if (host_) { | 185 if (host_) { |
| 190 host_->AddObserver(this); | 186 host_->AddObserver(this); |
| 191 | 187 |
| 192 for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); | 188 for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); |
| 193 it != observed_widgets_.end(); | 189 it != observed_widgets_.end(); |
| 194 ++it) { | 190 ++it) { |
| 195 views::Widget::ReparentNativeView((*it)->GetNativeView(), | 191 views::Widget::ReparentNativeView((*it)->GetNativeView(), |
| 196 host_->GetHostView()); | 192 host_->GetHostView()); |
| 197 } | 193 } |
| 198 | 194 |
| 199 OnPositionRequiresUpdate(); | 195 OnPositionRequiresUpdate(); |
| 200 } | 196 } |
| 201 } | 197 } |
| 202 | 198 |
| 203 virtual NativeWebContentsModalDialog dialog() override { | 199 NativeWebContentsModalDialog dialog() override { return dialog_; } |
| 204 return dialog_; | |
| 205 } | |
| 206 | 200 |
| 207 private: | 201 private: |
| 208 static views::Widget* GetWidget(NativeWebContentsModalDialog dialog) { | 202 static views::Widget* GetWidget(NativeWebContentsModalDialog dialog) { |
| 209 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog); | 203 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(dialog); |
| 210 DCHECK(widget); | 204 DCHECK(widget); |
| 211 return widget; | 205 return widget; |
| 212 } | 206 } |
| 213 | 207 |
| 214 void WidgetClosing(views::Widget* widget) { | 208 void WidgetClosing(views::Widget* widget) { |
| 215 #if defined(USE_AURA) | 209 #if defined(USE_AURA) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 243 namespace web_modal { | 237 namespace web_modal { |
| 244 | 238 |
| 245 SingleWebContentsDialogManager* WebContentsModalDialogManager:: | 239 SingleWebContentsDialogManager* WebContentsModalDialogManager:: |
| 246 CreateNativeWebModalManager( | 240 CreateNativeWebModalManager( |
| 247 NativeWebContentsModalDialog dialog, | 241 NativeWebContentsModalDialog dialog, |
| 248 SingleWebContentsDialogManagerDelegate* native_delegate) { | 242 SingleWebContentsDialogManagerDelegate* native_delegate) { |
| 249 return new NativeWebContentsModalDialogManagerViews(dialog, native_delegate); | 243 return new NativeWebContentsModalDialogManagerViews(dialog, native_delegate); |
| 250 } | 244 } |
| 251 | 245 |
| 252 } // namespace web_modal | 246 } // namespace web_modal |
| OLD | NEW |