| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/wm/overview/scoped_transform_overview_window.h" | 5 #include "ash/wm/overview/scoped_transform_overview_window.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
| 11 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
| 12 #include "ash/wm/overview/scoped_overview_animation_settings.h" | 12 #include "ash/wm/overview/scoped_overview_animation_settings.h" |
| 13 #include "ash/wm/overview/scoped_window_copy.h" | |
| 14 #include "ash/wm/overview/window_selector_item.h" | 13 #include "ash/wm/overview/window_selector_item.h" |
| 15 #include "ash/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
| 16 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 17 #include "base/macros.h" | 16 #include "base/macros.h" |
| 18 #include "ui/aura/client/aura_constants.h" | 17 #include "ui/aura/client/aura_constants.h" |
| 19 #include "ui/aura/client/screen_position_client.h" | 18 #include "ui/aura/client/screen_position_client.h" |
| 20 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 21 #include "ui/compositor/scoped_layer_animation_settings.h" | 20 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 22 #include "ui/gfx/animation/tween.h" | 21 #include "ui/gfx/animation/tween.h" |
| 23 #include "ui/gfx/transform_util.h" | 22 #include "ui/gfx/transform_util.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 aura::Window* window) | 167 aura::Window* window) |
| 169 : window_(window), | 168 : window_(window), |
| 170 activate_button_(new TransparentActivateWindowButton( | 169 activate_button_(new TransparentActivateWindowButton( |
| 171 window_->GetRootWindow(), this)), | 170 window_->GetRootWindow(), this)), |
| 172 minimized_(window->GetProperty(aura::client::kShowStateKey) == | 171 minimized_(window->GetProperty(aura::client::kShowStateKey) == |
| 173 ui::SHOW_STATE_MINIMIZED), | 172 ui::SHOW_STATE_MINIMIZED), |
| 174 ignored_by_shelf_(wm::GetWindowState(window)->ignored_by_shelf()), | 173 ignored_by_shelf_(wm::GetWindowState(window)->ignored_by_shelf()), |
| 175 overview_started_(false), | 174 overview_started_(false), |
| 176 original_transform_(window->layer()->GetTargetTransform()), | 175 original_transform_(window->layer()->GetTargetTransform()), |
| 177 original_opacity_(window->layer()->GetTargetOpacity()) { | 176 original_opacity_(window->layer()->GetTargetOpacity()) { |
| 177 DCHECK(window_); |
| 178 } | 178 } |
| 179 | 179 |
| 180 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() { | 180 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() { |
| 181 if (window_) { | 181 } |
| 182 ScopedAnimationSettings animation_settings_list; | |
| 183 BeginScopedAnimation( | |
| 184 OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, | |
| 185 &animation_settings_list); | |
| 186 SetTransform(window()->GetRootWindow(), original_transform_); | |
| 187 | 182 |
| 188 ScopedOverviewAnimationSettings animation_settings( | 183 void ScopedTransformOverviewWindow::RestoreWindow() { |
| 189 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, | 184 ScopedAnimationSettings animation_settings_list; |
| 190 window_); | 185 BeginScopedAnimation( |
| 191 gfx::Transform transform; | 186 OverviewAnimationType::OVERVIEW_ANIMATION_RESTORE_WINDOW, |
| 192 if (minimized_ && window_->GetProperty(aura::client::kShowStateKey) != | 187 &animation_settings_list); |
| 193 ui::SHOW_STATE_MINIMIZED) { | 188 SetTransform(window()->GetRootWindow(), original_transform_); |
| 194 // Setting opacity 0 and visible false ensures that the property change | 189 |
| 195 // to SHOW_STATE_MINIMIZED will not animate the window from its original | 190 ScopedOverviewAnimationSettings animation_settings( |
| 196 // bounds to the minimized position. | 191 OverviewAnimationType::OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS, |
| 197 // Hiding the window needs to be done before the target opacity is 0, | 192 window_); |
| 198 // otherwise the layer's visibility will not be updated | 193 gfx::Transform transform; |
| 199 // (See VisibilityController::UpdateLayerVisibility). | 194 if (minimized_ && window_->GetProperty(aura::client::kShowStateKey) != |
| 200 window_->Hide(); | 195 ui::SHOW_STATE_MINIMIZED) { |
| 201 window_->layer()->SetOpacity(0); | 196 // Setting opacity 0 and visible false ensures that the property change |
| 202 window_->SetProperty(aura::client::kShowStateKey, | 197 // to SHOW_STATE_MINIMIZED will not animate the window from its original |
| 203 ui::SHOW_STATE_MINIMIZED); | 198 // bounds to the minimized position. |
| 204 } | 199 // Hiding the window needs to be done before the target opacity is 0, |
| 205 wm::GetWindowState(window_)->set_ignored_by_shelf(ignored_by_shelf_); | 200 // otherwise the layer's visibility will not be updated |
| 206 SetOpacity(original_opacity_); | 201 // (See VisibilityController::UpdateLayerVisibility). |
| 202 window_->Hide(); |
| 203 window_->layer()->SetOpacity(0); |
| 204 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 207 } | 205 } |
| 206 wm::GetWindowState(window_)->set_ignored_by_shelf(ignored_by_shelf_); |
| 207 SetOpacity(original_opacity_); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void ScopedTransformOverviewWindow::BeginScopedAnimation( | 210 void ScopedTransformOverviewWindow::BeginScopedAnimation( |
| 211 OverviewAnimationType animation_type, | 211 OverviewAnimationType animation_type, |
| 212 ScopedAnimationSettings* animation_settings) { | 212 ScopedAnimationSettings* animation_settings) { |
| 213 for (const auto& window : GetTransientTreeIterator(window_)) { | 213 for (const auto& window : GetTransientTreeIterator(window_)) { |
| 214 animation_settings->push_back( | 214 animation_settings->push_back( |
| 215 new ScopedOverviewAnimationSettings(animation_type, window)); | 215 new ScopedOverviewAnimationSettings(animation_type, window)); |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 bool ScopedTransformOverviewWindow::Contains(const aura::Window* target) const { | 219 bool ScopedTransformOverviewWindow::Contains(const aura::Window* target) const { |
| 220 for (const auto& window : GetTransientTreeIterator(window_)) { | 220 for (const auto& window : GetTransientTreeIterator(window_)) { |
| 221 if (window->Contains(target)) | 221 if (window->Contains(target)) |
| 222 return true; | 222 return true; |
| 223 } | 223 } |
| 224 return false; | 224 return false; |
| 225 } | 225 } |
| 226 | 226 |
| 227 gfx::Rect ScopedTransformOverviewWindow::GetTargetBoundsInScreen() const { | 227 gfx::Rect ScopedTransformOverviewWindow::GetTargetBoundsInScreen() const { |
| 228 gfx::Rect bounds; | 228 gfx::Rect bounds; |
| 229 for (const auto& window : GetTransientTreeIterator(window_)) { | 229 for (const auto& window : GetTransientTreeIterator(window_)) { |
| 230 bounds.Union(ScreenUtil::ConvertRectToScreen(window->parent(), | 230 bounds.Union(ScreenUtil::ConvertRectToScreen(window->parent(), |
| 231 window->GetTargetBounds())); | 231 window->GetTargetBounds())); |
| 232 } | 232 } |
| 233 return bounds; | 233 return bounds; |
| 234 } | 234 } |
| 235 | 235 |
| 236 void ScopedTransformOverviewWindow::RestoreWindow() { | 236 void ScopedTransformOverviewWindow::ShowWindowIfMinimized() { |
| 237 if (minimized_ && window_->GetProperty(aura::client::kShowStateKey) == | 237 if (minimized_ && window_->GetProperty(aura::client::kShowStateKey) == |
| 238 ui::SHOW_STATE_MINIMIZED) { | 238 ui::SHOW_STATE_MINIMIZED) { |
| 239 window_->Show(); | 239 window_->Show(); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 | 242 |
| 243 void ScopedTransformOverviewWindow::RestoreWindowOnExit() { | 243 void ScopedTransformOverviewWindow::ShowWindowOnExit() { |
| 244 minimized_ = false; | 244 if (minimized_) { |
| 245 original_transform_ = gfx::Transform(); | 245 minimized_ = false; |
| 246 original_opacity_ = kRestoreWindowOpacity; | 246 original_transform_ = gfx::Transform(); |
| 247 original_opacity_ = kRestoreWindowOpacity; |
| 248 } |
| 247 } | 249 } |
| 248 | 250 |
| 249 void ScopedTransformOverviewWindow::OnWindowDestroyed() { | 251 void ScopedTransformOverviewWindow::OnWindowDestroyed() { |
| 250 window_ = nullptr; | 252 window_ = nullptr; |
| 251 } | 253 } |
| 252 | 254 |
| 253 gfx::Rect ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( | 255 gfx::Rect ScopedTransformOverviewWindow::ShrinkRectToFitPreservingAspectRatio( |
| 254 const gfx::Rect& rect, | 256 const gfx::Rect& rect, |
| 255 const gfx::Rect& bounds) { | 257 const gfx::Rect& bounds) { |
| 256 DCHECK(!rect.IsEmpty()); | 258 DCHECK(!rect.IsEmpty()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 310 |
| 309 void ScopedTransformOverviewWindow::Close() { | 311 void ScopedTransformOverviewWindow::Close() { |
| 310 aura::Window* window = GetTransientRoot(window_); | 312 aura::Window* window = GetTransientRoot(window_); |
| 311 views::Widget::GetWidgetForNativeView(window)->Close(); | 313 views::Widget::GetWidgetForNativeView(window)->Close(); |
| 312 } | 314 } |
| 313 | 315 |
| 314 void ScopedTransformOverviewWindow::PrepareForOverview() { | 316 void ScopedTransformOverviewWindow::PrepareForOverview() { |
| 315 DCHECK(!overview_started_); | 317 DCHECK(!overview_started_); |
| 316 overview_started_ = true; | 318 overview_started_ = true; |
| 317 wm::GetWindowState(window_)->set_ignored_by_shelf(true); | 319 wm::GetWindowState(window_)->set_ignored_by_shelf(true); |
| 318 RestoreWindow(); | 320 ShowWindowIfMinimized(); |
| 319 } | 321 } |
| 320 | 322 |
| 321 } // namespace ash | 323 } // namespace ash |
| OLD | NEW |