Chromium Code Reviews| 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/native_web_contents_modal_dialog_manager.h" | 10 #include "components/web_modal/native_web_contents_modal_dialog_manager.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 views::Widget* widget = GetWidget(dialog); | 70 views::Widget* widget = GetWidget(dialog); |
| 71 widget->AddObserver(this); | 71 widget->AddObserver(this); |
| 72 observed_widgets_.insert(widget); | 72 observed_widgets_.insert(widget); |
| 73 widget->set_movement_disabled(true); | 73 widget->set_movement_disabled(true); |
| 74 | 74 |
| 75 #if defined(USE_AURA) | 75 #if defined(USE_AURA) |
| 76 // TODO(wittman): remove once the new visual style is complete | 76 // TODO(wittman): remove once the new visual style is complete |
| 77 widget->GetNativeWindow()->SetProperty(aura::client::kConstrainedWindowKey, | 77 widget->GetNativeWindow()->SetProperty(aura::client::kConstrainedWindowKey, |
| 78 true); | 78 true); |
| 79 | 79 |
| 80 if (views::DialogDelegate::UseNewStyle()) { | 80 views::corewm::SetWindowVisibilityAnimationType( |
| 81 views::corewm::SetWindowVisibilityAnimationType( | 81 widget->GetNativeWindow(), |
| 82 widget->GetNativeWindow(), | 82 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE); |
| 83 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE); | |
| 84 } | |
| 85 #endif | 83 #endif |
| 86 | 84 |
| 87 #if defined(USE_ASH) | 85 #if defined(USE_ASH) |
| 88 gfx::NativeView parent = platform_util::GetParent(widget->GetNativeView()); | 86 gfx::NativeView parent = platform_util::GetParent(widget->GetNativeView()); |
| 89 views::corewm::SetChildWindowVisibilityChangesAnimated(parent); | 87 views::corewm::SetChildWindowVisibilityChangesAnimated(parent); |
| 90 // No animations should get performed on the window since that will re-order | 88 // No animations should get performed on the window since that will re-order |
| 91 // the window stack which will then cause many problems. | 89 // the window stack which will then cause many problems. |
| 92 if (parent && parent->parent()) { | 90 if (parent && parent->parent()) { |
| 93 parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, true); | 91 parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, true); |
| 94 } | 92 } |
| 95 | 93 |
| 96 // TODO(wittman): remove once the new visual style is complete | 94 // TODO(wittman): remove once the new visual style is complete |
| 97 widget->GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); | 95 widget->GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); |
| 98 views::corewm::SetModalParent( | 96 views::corewm::SetModalParent( |
| 99 widget->GetNativeWindow(), | 97 widget->GetNativeWindow(), |
| 100 platform_util::GetParent(widget->GetNativeView())); | 98 platform_util::GetParent(widget->GetNativeView())); |
| 101 #endif | 99 #endif |
| 102 } | 100 } |
| 103 | 101 |
| 104 virtual void ShowDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | 102 virtual void ShowDialog(NativeWebContentsModalDialog dialog) OVERRIDE { |
| 105 views::Widget* widget = GetWidget(dialog); | 103 views::Widget* widget = GetWidget(dialog); |
| 106 #if defined(USE_AURA) | 104 #if defined(USE_AURA) |
| 107 scoped_ptr<views::corewm::SuspendChildWindowVisibilityAnimations> suspend; | 105 scoped_ptr<views::corewm::SuspendChildWindowVisibilityAnimations> suspend; |
| 108 if (views::DialogDelegate::UseNewStyle() && | 106 if (shown_widgets_.find(widget) != shown_widgets_.end()) { |
| 109 shown_widgets_.find(widget) != shown_widgets_.end()) { | |
| 110 suspend.reset(new views::corewm::SuspendChildWindowVisibilityAnimations( | 107 suspend.reset(new views::corewm::SuspendChildWindowVisibilityAnimations( |
| 111 widget->GetNativeWindow()->parent())); | 108 widget->GetNativeWindow()->parent())); |
| 112 } | 109 } |
| 113 #endif | 110 #endif |
| 114 // Host may be NULL during tab drag on Views/Win32. | 111 // Host may be NULL during tab drag on Views/Win32. |
| 115 if (host_) | 112 if (host_) |
| 116 UpdateWebContentsModalDialogPosition(widget, host_); | 113 UpdateWebContentsModalDialogPosition(widget, host_); |
| 117 widget->Show(); | 114 widget->Show(); |
| 118 FocusDialog(dialog); | 115 FocusDialog(dialog); |
| 119 | 116 |
| 120 #if defined(USE_AURA) | 117 #if defined(USE_AURA) |
| 121 // TODO(pkotwicz): Control the z-order of the constrained dialog via | 118 // TODO(pkotwicz): Control the z-order of the constrained dialog via |
| 122 // views::kHostViewKey. We will need to ensure that the parent window's | 119 // views::kHostViewKey. We will need to ensure that the parent window's |
| 123 // shadows are below the constrained dialog in z-order when we do this. | 120 // shadows are below the constrained dialog in z-order when we do this. |
| 124 shown_widgets_.insert(widget); | 121 shown_widgets_.insert(widget); |
| 125 #endif | 122 #endif |
| 126 } | 123 } |
| 127 | 124 |
| 128 virtual void HideDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | 125 virtual void HideDialog(NativeWebContentsModalDialog dialog) OVERRIDE { |
| 129 views::Widget* widget = GetWidget(dialog); | 126 views::Widget* widget = GetWidget(dialog); |
| 130 #if defined(USE_AURA) | 127 #if defined(USE_AURA) |
| 131 scoped_ptr<views::corewm::SuspendChildWindowVisibilityAnimations> suspend; | 128 scoped_ptr<views::corewm::SuspendChildWindowVisibilityAnimations> suspend; |
| 132 if (views::DialogDelegate::UseNewStyle()) { | 129 suspend.reset(new views::corewm::SuspendChildWindowVisibilityAnimations( |
| 133 suspend.reset(new views::corewm::SuspendChildWindowVisibilityAnimations( | 130 widget->GetNativeWindow()->parent())); |
| 134 widget->GetNativeWindow()->parent())); | |
| 135 } | |
| 136 #endif | 131 #endif |
| 137 widget->Hide(); | 132 widget->Hide(); |
| 138 } | 133 } |
| 139 | 134 |
| 140 virtual void CloseDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | 135 virtual void CloseDialog(NativeWebContentsModalDialog dialog) OVERRIDE { |
| 141 GetWidget(dialog)->Close(); | 136 GetWidget(dialog)->Close(); |
| 142 } | 137 } |
| 143 | 138 |
| 144 virtual void FocusDialog(NativeWebContentsModalDialog dialog) OVERRIDE { | 139 virtual void FocusDialog(NativeWebContentsModalDialog dialog) OVERRIDE { |
| 145 views::Widget* widget = GetWidget(dialog); | 140 views::Widget* widget = GetWidget(dialog); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 WidgetClosing(widget); | 185 WidgetClosing(widget); |
| 191 } | 186 } |
| 192 | 187 |
| 193 virtual void HostChanged( | 188 virtual void HostChanged( |
| 194 web_modal::WebContentsModalDialogHost* new_host) OVERRIDE { | 189 web_modal::WebContentsModalDialogHost* new_host) OVERRIDE { |
| 195 if (host_) | 190 if (host_) |
| 196 host_->RemoveObserver(this); | 191 host_->RemoveObserver(this); |
| 197 | 192 |
| 198 host_ = new_host; | 193 host_ = new_host; |
| 199 | 194 |
| 200 if (host_) | 195 // |host_| may be null during WebContents destruction or Win32 tab dragging. |
| 196 if (host_) { | |
| 201 host_->AddObserver(this); | 197 host_->AddObserver(this); |
| 202 | 198 |
| 203 // Old-style dialogs are parented to the web contents view and don't need | 199 std::set<views::Widget*>::iterator it = observed_widgets_.begin(); |
|
sky
2013/11/16 03:03:16
move inside lop.
msw
2013/11/16 04:15:44
Done.
| |
| 204 // reparenting. The host_ may be null during tab drag under Views/Win32 or | 200 for (; it != observed_widgets_.end(); ++it) { |
| 205 // when destroying the WebContents. | |
| 206 if (views::DialogDelegate::UseNewStyle() && host_) { | |
| 207 for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); | |
| 208 it != observed_widgets_.end(); | |
| 209 ++it) { | |
| 210 views::Widget::ReparentNativeView((*it)->GetNativeView(), | 201 views::Widget::ReparentNativeView((*it)->GetNativeView(), |
| 211 host_->GetHostView()); | 202 host_->GetHostView()); |
| 212 } | 203 } |
| 213 | 204 |
| 214 OnPositionRequiresUpdate(); | 205 OnPositionRequiresUpdate(); |
| 215 } | 206 } |
| 216 } | 207 } |
| 217 | 208 |
| 218 private: | 209 private: |
| 219 static views::Widget* GetWidget(NativeWebContentsModalDialog dialog) { | 210 static views::Widget* GetWidget(NativeWebContentsModalDialog dialog) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 249 | 240 |
| 250 namespace web_modal { | 241 namespace web_modal { |
| 251 | 242 |
| 252 NativeWebContentsModalDialogManager* WebContentsModalDialogManager:: | 243 NativeWebContentsModalDialogManager* WebContentsModalDialogManager:: |
| 253 CreateNativeManager( | 244 CreateNativeManager( |
| 254 NativeWebContentsModalDialogManagerDelegate* native_delegate) { | 245 NativeWebContentsModalDialogManagerDelegate* native_delegate) { |
| 255 return new NativeWebContentsModalDialogManagerViews(native_delegate); | 246 return new NativeWebContentsModalDialogManagerViews(native_delegate); |
| 256 } | 247 } |
| 257 | 248 |
| 258 } // namespace web_modal | 249 } // namespace web_modal |
| OLD | NEW |