| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 "ui/aura_shell/modal_container_layout_manager.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "ui/aura/client/aura_constants.h" | |
| 9 #include "ui/aura/event.h" | |
| 10 #include "ui/aura/root_window.h" | |
| 11 #include "ui/aura/window.h" | |
| 12 #include "ui/aura_shell/modality_event_filter.h" | |
| 13 #include "ui/aura_shell/shell.h" | |
| 14 #include "ui/aura_shell/window_util.h" | |
| 15 #include "ui/gfx/canvas.h" | |
| 16 #include "ui/gfx/compositor/layer.h" | |
| 17 #include "ui/gfx/compositor/layer_animator.h" | |
| 18 #include "ui/views/view.h" | |
| 19 #include "ui/views/widget/widget.h" | |
| 20 | |
| 21 namespace aura_shell { | |
| 22 namespace internal { | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 class ScreenView : public views::View { | |
| 27 public: | |
| 28 ScreenView() {} | |
| 29 virtual ~ScreenView() {} | |
| 30 | |
| 31 // Overridden from views::View: | |
| 32 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
| 33 canvas->FillRect(SK_ColorBLACK, GetLocalBounds()); | |
| 34 } | |
| 35 | |
| 36 private: | |
| 37 DISALLOW_COPY_AND_ASSIGN(ScreenView); | |
| 38 }; | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 //////////////////////////////////////////////////////////////////////////////// | |
| 43 // ModalContainerLayoutManager, public: | |
| 44 | |
| 45 ModalContainerLayoutManager::ModalContainerLayoutManager( | |
| 46 aura::Window* container) | |
| 47 : container_(container), | |
| 48 modal_screen_(NULL), | |
| 49 ALLOW_THIS_IN_INITIALIZER_LIST( | |
| 50 modality_filter_(new ModalityEventFilter(container, this))) { | |
| 51 } | |
| 52 | |
| 53 ModalContainerLayoutManager::~ModalContainerLayoutManager() { | |
| 54 } | |
| 55 | |
| 56 //////////////////////////////////////////////////////////////////////////////// | |
| 57 // ModalContainerLayoutManager, aura::LayoutManager implementation: | |
| 58 | |
| 59 void ModalContainerLayoutManager::OnWindowResized() { | |
| 60 if (modal_screen_) { | |
| 61 modal_screen_->SetBounds(gfx::Rect(0, 0, container_->bounds().width(), | |
| 62 container_->bounds().height())); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 void ModalContainerLayoutManager::OnWindowAddedToLayout( | |
| 67 aura::Window* child) { | |
| 68 child->AddObserver(this); | |
| 69 if (child->GetIntProperty(aura::client::kModalKey)) | |
| 70 AddModalWindow(child); | |
| 71 } | |
| 72 | |
| 73 void ModalContainerLayoutManager::OnWillRemoveWindowFromLayout( | |
| 74 aura::Window* child) { | |
| 75 child->RemoveObserver(this); | |
| 76 if (child->GetIntProperty(aura::client::kModalKey)) | |
| 77 RemoveModalWindow(child); | |
| 78 } | |
| 79 | |
| 80 void ModalContainerLayoutManager::OnChildWindowVisibilityChanged( | |
| 81 aura::Window* child, | |
| 82 bool visible) { | |
| 83 } | |
| 84 | |
| 85 void ModalContainerLayoutManager::SetChildBounds( | |
| 86 aura::Window* child, | |
| 87 const gfx::Rect& requested_bounds) { | |
| 88 SetChildBoundsDirect(child, requested_bounds); | |
| 89 } | |
| 90 | |
| 91 //////////////////////////////////////////////////////////////////////////////// | |
| 92 // ModalContainerLayoutManager, aura::WindowObserver implementation: | |
| 93 | |
| 94 void ModalContainerLayoutManager::OnWindowPropertyChanged(aura::Window* window, | |
| 95 const char* key, | |
| 96 void* old) { | |
| 97 if (key != aura::client::kModalKey) | |
| 98 return; | |
| 99 | |
| 100 if (window->GetIntProperty(aura::client::kModalKey)) { | |
| 101 AddModalWindow(window); | |
| 102 } else if (static_cast<int>(reinterpret_cast<intptr_t>(old))) { | |
| 103 RemoveModalWindow(window); | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 //////////////////////////////////////////////////////////////////////////////// | |
| 108 // ModalContainerLayoutManager, ui::LayerAnimationObserver implementation: | |
| 109 | |
| 110 void ModalContainerLayoutManager::OnLayerAnimationEnded( | |
| 111 const ui::LayerAnimationSequence* sequence) { | |
| 112 if (modal_screen_ && !modal_screen_->GetNativeView()->layer()->ShouldDraw()) | |
| 113 DestroyModalScreen(); | |
| 114 } | |
| 115 | |
| 116 void ModalContainerLayoutManager::OnLayerAnimationAborted( | |
| 117 const ui::LayerAnimationSequence* sequence) { | |
| 118 } | |
| 119 | |
| 120 void ModalContainerLayoutManager::OnLayerAnimationScheduled( | |
| 121 const ui::LayerAnimationSequence* sequence) { | |
| 122 } | |
| 123 | |
| 124 //////////////////////////////////////////////////////////////////////////////// | |
| 125 // ModalContainerLayoutManager, ModalityEventFilter::Delegate implementation: | |
| 126 | |
| 127 bool ModalContainerLayoutManager::CanWindowReceiveEvents( | |
| 128 aura::Window* window) { | |
| 129 return GetActivatableWindow(window) == modal_window(); | |
| 130 } | |
| 131 | |
| 132 //////////////////////////////////////////////////////////////////////////////// | |
| 133 // ModalContainerLayoutManager, private: | |
| 134 | |
| 135 void ModalContainerLayoutManager::AddModalWindow(aura::Window* window) { | |
| 136 modal_windows_.push_back(window); | |
| 137 CreateModalScreen(); | |
| 138 } | |
| 139 | |
| 140 void ModalContainerLayoutManager::RemoveModalWindow(aura::Window* window) { | |
| 141 aura::Window::Windows::iterator it = | |
| 142 std::find(modal_windows_.begin(), modal_windows_.end(), window); | |
| 143 if (it != modal_windows_.end()) | |
| 144 modal_windows_.erase(it); | |
| 145 | |
| 146 if (modal_windows_.empty()) | |
| 147 HideModalScreen(); | |
| 148 else | |
| 149 aura_shell::ActivateWindow(modal_window()); | |
| 150 } | |
| 151 | |
| 152 void ModalContainerLayoutManager::CreateModalScreen() { | |
| 153 if (modal_screen_) | |
| 154 return; | |
| 155 modal_screen_ = new views::Widget; | |
| 156 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | |
| 157 params.parent = container_; | |
| 158 params.bounds = gfx::Rect(0, 0, container_->bounds().width(), | |
| 159 container_->bounds().height()); | |
| 160 modal_screen_->Init(params); | |
| 161 modal_screen_->GetNativeView()->SetName( | |
| 162 "ModalContainerLayoutManager.ModalScreen"); | |
| 163 modal_screen_->SetContentsView(new ScreenView); | |
| 164 modal_screen_->GetNativeView()->layer()->SetOpacity(0.0f); | |
| 165 modal_screen_->GetNativeView()->layer()->GetAnimator()->AddObserver(this); | |
| 166 | |
| 167 Shell::GetInstance()->AddRootWindowEventFilter(modality_filter_.get()); | |
| 168 | |
| 169 ui::LayerAnimator::ScopedSettings settings( | |
| 170 modal_screen_->GetNativeView()->layer()->GetAnimator()); | |
| 171 modal_screen_->Show(); | |
| 172 modal_screen_->GetNativeView()->layer()->SetOpacity(0.5f); | |
| 173 container_->StackChildAtTop(modal_screen_->GetNativeView()); | |
| 174 } | |
| 175 | |
| 176 void ModalContainerLayoutManager::DestroyModalScreen() { | |
| 177 modal_screen_->GetNativeView()->layer()->GetAnimator()->RemoveObserver(this); | |
| 178 modal_screen_->Close(); | |
| 179 modal_screen_ = NULL; | |
| 180 } | |
| 181 | |
| 182 void ModalContainerLayoutManager::HideModalScreen() { | |
| 183 Shell::GetInstance()->RemoveRootWindowEventFilter(modality_filter_.get()); | |
| 184 ui::LayerAnimator::ScopedSettings settings( | |
| 185 modal_screen_->GetNativeView()->layer()->GetAnimator()); | |
| 186 modal_screen_->GetNativeView()->layer()->SetOpacity(0.0f); | |
| 187 } | |
| 188 | |
| 189 } // namespace internal | |
| 190 } // namespace aura_shell | |
| OLD | NEW |