Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <set> | |
| 6 | |
| 7 #include "chrome/browser/platform_util.h" | |
| 8 #include "chrome/browser/ui/views/constrained_window_views.h" | |
| 9 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h" | |
| 10 #include "chrome/browser/ui/web_contents_modal_dialog_manager_ui_delegate.h" | |
| 11 #include "ui/views/widget/widget.h" | |
| 12 #include "ui/views/widget/widget_observer.h" | |
| 13 | |
| 14 #if defined(USE_AURA) | |
| 15 #include "ui/aura/client/aura_constants.h" | |
| 16 #include "ui/aura/window.h" | |
| 17 #include "ui/views/corewm/visibility_controller.h" | |
| 18 #include "ui/views/corewm/window_animations.h" | |
| 19 #include "ui/views/corewm/window_modality_controller.h" | |
| 20 #endif | |
| 21 | |
| 22 #if defined(USE_ASH) | |
| 23 #include "ash/ash_constants.h" | |
| 24 #include "ash/shell.h" | |
| 25 #include "ash/wm/custom_frame_view_ash.h" | |
| 26 #endif | |
| 27 | |
| 28 namespace { | |
| 29 | |
| 30 class WebContentsModalDialogManagerUIDelegateViews | |
| 31 : public WebContentsModalDialogManagerUIDelegate, | |
| 32 public views::WidgetObserver { | |
| 33 public: | |
| 34 WebContentsModalDialogManagerUIDelegateViews( | |
| 35 WebContentsModalDialogManager* manager) | |
| 36 : manager_(manager) { | |
| 37 } | |
| 38 | |
| 39 virtual ~WebContentsModalDialogManagerUIDelegateViews() { | |
| 40 for (std::set<views::Widget*>::iterator it = observed_widgets_.begin(); | |
| 41 it != observed_widgets_.end(); | |
| 42 ++it) { | |
| 43 (*it)->RemoveObserver(this); | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 // WebContentsModalDialogManagerUIDelegateViews overrides | |
| 48 | |
|
Ben Goodger (Google)
2013/01/23 19:10:46
nit: remove line
Mike Wittman
2013/01/23 21:52:31
Done.
| |
| 49 virtual void ManageDialog(gfx::NativeWindow window) OVERRIDE { | |
| 50 views::Widget* widget = GetWidget(window); | |
| 51 widget->AddObserver(this); | |
| 52 observed_widgets_.insert(widget); | |
| 53 widget->set_movement_disabled(true); | |
| 54 | |
| 55 #if defined(USE_AURA) | |
| 56 widget->GetNativeWindow()->SetProperty(aura::client::kConstrainedWindowKey, | |
|
Ben Goodger (Google)
2013/01/23 19:10:46
Add a
// TODO: remove once the new visual style
Mike Wittman
2013/01/23 21:52:31
Done.
| |
| 57 true); | |
| 58 #endif | |
| 59 | |
| 60 #if defined(USE_ASH) | |
| 61 gfx::NativeView parent = platform_util::GetParent(widget->GetNativeView()); | |
| 62 views::corewm::SetChildWindowVisibilityChangesAnimated(parent); | |
| 63 // No animations should get performed on the window since that will re-order | |
| 64 // the window stack which will then cause many problems. | |
| 65 if (parent && parent->parent()) { | |
| 66 parent->parent()->SetProperty(aura::client::kAnimationsDisabledKey, true); | |
| 67 } | |
| 68 | |
| 69 widget->GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); | |
|
Ben Goodger (Google)
2013/01/23 19:10:46
this line seems redundant with above?
Mike Wittman
2013/01/23 21:52:31
For whatever reason, there are separate keys for A
| |
| 70 views::corewm::SetModalParent( | |
| 71 widget->GetNativeWindow(), | |
| 72 platform_util::GetParent(widget->GetNativeView())); | |
| 73 #endif | |
| 74 } | |
| 75 | |
| 76 virtual void CloseDialog(gfx::NativeWindow window) OVERRIDE { | |
| 77 views::Widget* widget = GetWidget(window); | |
| 78 #if defined(USE_ASH) | |
| 79 gfx::NativeView view = platform_util::GetParent(widget->GetNativeView()); | |
| 80 // Allow the parent to animate again. | |
| 81 if (view && view->parent()) | |
| 82 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); | |
| 83 #endif | |
| 84 widget->Close(); | |
| 85 } | |
| 86 | |
| 87 // views::WidgetObserver overrides | |
| 88 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { | |
| 89 manager_->WillClose(static_cast<ConstrainedWindowViews*>(widget)); | |
| 90 observed_widgets_.erase(widget); | |
| 91 } | |
| 92 | |
| 93 private: | |
| 94 static views::Widget* GetWidget(gfx::NativeWindow window) { | |
| 95 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | |
| 96 DCHECK(widget); | |
| 97 return widget; | |
| 98 } | |
| 99 | |
| 100 WebContentsModalDialogManager* manager_; | |
| 101 std::set<views::Widget*> observed_widgets_; | |
| 102 | |
| 103 DISALLOW_COPY_AND_ASSIGN(WebContentsModalDialogManagerUIDelegateViews); | |
| 104 }; | |
| 105 | |
| 106 } // namespace | |
| 107 | |
| 108 WebContentsModalDialogManagerUIDelegate* WebContentsModalDialogManager:: | |
| 109 CreateUIDelegate(WebContentsModalDialogManager* manager) { | |
| 110 return new WebContentsModalDialogManagerUIDelegateViews(manager); | |
| 111 } | |
| OLD | NEW |