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/native_web_contents_modal_dialog_manager.h" |
| 9 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 10 #include "chrome/browser/ui/web_contents_modal_dialog_manager.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 NativeWebContentsModalDialogManagerViews |
| 31 : public NativeWebContentsModalDialogManager, |
| 32 public views::WidgetObserver { |
| 33 public: |
| 34 NativeWebContentsModalDialogManagerViews( |
| 35 WebContentsModalDialogManager* manager) |
| 36 : manager_(manager) { |
| 37 } |
| 38 |
| 39 virtual ~NativeWebContentsModalDialogManagerViews() { |
| 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 // NativeWebContentsModalDialogManager overrides |
| 48 virtual void ManageDialog(gfx::NativeWindow window) OVERRIDE { |
| 49 views::Widget* widget = GetWidget(window); |
| 50 widget->AddObserver(this); |
| 51 observed_widgets_.insert(widget); |
| 52 widget->set_movement_disabled(true); |
| 53 |
| 54 #if defined(USE_AURA) |
| 55 // TODO(wittman): remove once the new visual style is complete |
| 56 widget->GetNativeWindow()->SetProperty(aura::client::kConstrainedWindowKey, |
| 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 // TODO(wittman): remove once the new visual style is complete |
| 70 widget->GetNativeWindow()->SetProperty(ash::kConstrainedWindowKey, true); |
| 71 views::corewm::SetModalParent( |
| 72 widget->GetNativeWindow(), |
| 73 platform_util::GetParent(widget->GetNativeView())); |
| 74 #endif |
| 75 } |
| 76 |
| 77 virtual void CloseDialog(gfx::NativeWindow window) OVERRIDE { |
| 78 views::Widget* widget = GetWidget(window); |
| 79 #if defined(USE_ASH) |
| 80 gfx::NativeView view = platform_util::GetParent(widget->GetNativeView()); |
| 81 // Allow the parent to animate again. |
| 82 if (view && view->parent()) |
| 83 view->parent()->ClearProperty(aura::client::kAnimationsDisabledKey); |
| 84 #endif |
| 85 widget->Close(); |
| 86 } |
| 87 |
| 88 // views::WidgetObserver overrides |
| 89 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { |
| 90 manager_->WillClose(static_cast<ConstrainedWindowViews*>(widget)); |
| 91 observed_widgets_.erase(widget); |
| 92 } |
| 93 |
| 94 private: |
| 95 static views::Widget* GetWidget(gfx::NativeWindow window) { |
| 96 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
| 97 DCHECK(widget); |
| 98 return widget; |
| 99 } |
| 100 |
| 101 WebContentsModalDialogManager* manager_; |
| 102 std::set<views::Widget*> observed_widgets_; |
| 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(NativeWebContentsModalDialogManagerViews); |
| 105 }; |
| 106 |
| 107 } // namespace |
| 108 |
| 109 NativeWebContentsModalDialogManager* WebContentsModalDialogManager:: |
| 110 CreateNativeManager(WebContentsModalDialogManager* manager) { |
| 111 return new NativeWebContentsModalDialogManagerViews(manager); |
| 112 } |
OLD | NEW |