Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: ash/common/wm/overview/scoped_transform_overview_window.cc

Issue 2101843003: [ash-md] Animates a window closed while in overview mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [ash-md] Animates a window closed while in overview mode (comments) Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/wm/overview/scoped_transform_overview_window.h" 5 #include "ash/common/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/common/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
11 #include "ash/common/wm/overview/scoped_overview_animation_settings.h" 11 #include "ash/common/wm/overview/scoped_overview_animation_settings.h"
12 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h" 12 #include "ash/common/wm/overview/scoped_overview_animation_settings_factory.h"
13 #include "ash/common/wm/overview/window_selector_item.h" 13 #include "ash/common/wm/overview/window_selector_item.h"
14 #include "ash/common/wm/window_state.h" 14 #include "ash/common/wm/window_state.h"
15 #include "ash/common/wm_window.h" 15 #include "ash/common/wm_window.h"
16 #include "ash/common/wm_window_property.h" 16 #include "ash/common/wm_window_property.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/single_thread_task_runner.h"
19 #include "base/threading/thread_task_runner_handle.h"
18 #include "third_party/skia/include/core/SkPaint.h" 20 #include "third_party/skia/include/core/SkPaint.h"
19 #include "third_party/skia/include/core/SkPath.h" 21 #include "third_party/skia/include/core/SkPath.h"
20 #include "third_party/skia/include/core/SkRect.h" 22 #include "third_party/skia/include/core/SkRect.h"
21 #include "ui/compositor/layer.h" 23 #include "ui/compositor/layer.h"
22 #include "ui/compositor/layer_delegate.h" 24 #include "ui/compositor/layer_delegate.h"
23 #include "ui/compositor/paint_recorder.h" 25 #include "ui/compositor/paint_recorder.h"
24 #include "ui/gfx/geometry/rect.h" 26 #include "ui/gfx/geometry/rect.h"
25 #include "ui/gfx/geometry/safe_integer_conversions.h" 27 #include "ui/gfx/geometry/safe_integer_conversions.h"
26 #include "ui/gfx/transform_util.h" 28 #include "ui/gfx/transform_util.h"
27 29
28 using WmWindows = std::vector<ash::WmWindow*>; 30 using WmWindows = std::vector<ash::WmWindow*>;
29 31
30 namespace ash { 32 namespace ash {
31 33
32 namespace { 34 namespace {
33 35
36 // When set to true by tests makes closing the widget synchronous.
37 bool immediate_close_for_tests = false;
38
34 // The opacity level that windows will be set to when they are restored. 39 // The opacity level that windows will be set to when they are restored.
35 const float kRestoreWindowOpacity = 1.0f; 40 const float kRestoreWindowOpacity = 1.0f;
36 41
37 // Alpha value used to paint mask layer that masks the original window header. 42 // Alpha value used to paint mask layer that masks the original window header.
38 const int kOverviewContentMaskAlpha = 255; 43 const int kOverviewContentMaskAlpha = 255;
39 44
45 // Delay closing window with Material Design to allow it to shrink and fade out.
46 const int kCloseWindowDelayInMilliseconds = 150;
47
40 WmWindow* GetTransientRoot(WmWindow* window) { 48 WmWindow* GetTransientRoot(WmWindow* window) {
41 while (window->GetTransientParent()) 49 while (window && window->GetTransientParent())
42 window = window->GetTransientParent(); 50 window = window->GetTransientParent();
43 return window; 51 return window;
44 } 52 }
45 53
46 std::unique_ptr<ScopedOverviewAnimationSettings> 54 std::unique_ptr<ScopedOverviewAnimationSettings>
47 CreateScopedOverviewAnimationSettings(OverviewAnimationType animation_type, 55 CreateScopedOverviewAnimationSettings(OverviewAnimationType animation_type,
48 WmWindow* window) { 56 WmWindow* window) {
49 return ScopedOverviewAnimationSettingsFactory::Get() 57 return ScopedOverviewAnimationSettingsFactory::Get()
50 ->CreateOverviewAnimationSettings(animation_type, window); 58 ->CreateOverviewAnimationSettings(animation_type, window);
51 } 59 }
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 PrepareForLayerBoundsChange() { 247 PrepareForLayerBoundsChange() {
240 return base::Closure(); 248 return base::Closure();
241 } 249 }
242 250
243 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow(WmWindow* window) 251 ScopedTransformOverviewWindow::ScopedTransformOverviewWindow(WmWindow* window)
244 : window_(window), 252 : window_(window),
245 minimized_(window->GetShowState() == ui::SHOW_STATE_MINIMIZED), 253 minimized_(window->GetShowState() == ui::SHOW_STATE_MINIMIZED),
246 ignored_by_shelf_(window->GetWindowState()->ignored_by_shelf()), 254 ignored_by_shelf_(window->GetWindowState()->ignored_by_shelf()),
247 overview_started_(false), 255 overview_started_(false),
248 original_transform_(window->GetTargetTransform()), 256 original_transform_(window->GetTargetTransform()),
249 original_opacity_(window->GetTargetOpacity()) {} 257 original_opacity_(window->GetTargetOpacity()),
258 weak_ptr_factory_(this) {}
250 259
251 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {} 260 ScopedTransformOverviewWindow::~ScopedTransformOverviewWindow() {}
252 261
253 void ScopedTransformOverviewWindow::RestoreWindow() { 262 void ScopedTransformOverviewWindow::RestoreWindow() {
254 if (ash::MaterialDesignController::IsOverviewMaterial()) { 263 if (ash::MaterialDesignController::IsOverviewMaterial()) {
255 window()->GetLayer()->SetMaskLayer(nullptr); 264 window()->GetLayer()->SetMaskLayer(nullptr);
256 mask_.reset(); 265 mask_.reset();
257 } 266 }
258 267
259 ScopedAnimationSettings animation_settings_list; 268 ScopedAnimationSettings animation_settings_list;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 static_cast<float>(dst_rect.height()) / src_rect.height()); 390 static_cast<float>(dst_rect.height()) / src_rect.height());
382 return transform; 391 return transform;
383 } 392 }
384 393
385 void ScopedTransformOverviewWindow::SetTransform( 394 void ScopedTransformOverviewWindow::SetTransform(
386 WmWindow* root_window, 395 WmWindow* root_window,
387 const gfx::Transform& transform, 396 const gfx::Transform& transform,
388 int radius) { 397 int radius) {
389 DCHECK(overview_started_); 398 DCHECK(overview_started_);
390 399
391 if (ash::MaterialDesignController::IsOverviewMaterial()) { 400 if (ash::MaterialDesignController::IsOverviewMaterial() && !mask_) {
392 mask_.reset(new OverviewContentMask( 401 mask_.reset(new OverviewContentMask(
393 window()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET), radius)); 402 window()->GetIntProperty(WmWindowProperty::TOP_VIEW_INSET), radius));
394 mask_->layer()->SetBounds(GetTargetBoundsInScreen()); 403 mask_->layer()->SetBounds(GetTargetBoundsInScreen());
395 window()->GetLayer()->SetMaskLayer(mask_->layer()); 404 window()->GetLayer()->SetMaskLayer(mask_->layer());
396 } 405 }
397 406
398 gfx::Point target_origin(GetTargetBoundsInScreen().origin()); 407 gfx::Point target_origin(GetTargetBoundsInScreen().origin());
399 408
400 for (const auto& window : GetTransientTreeIterator(window_)) { 409 for (const auto& window : GetTransientTreeIterator(window_)) {
401 WmWindow* parent_window = window->GetParent(); 410 WmWindow* parent_window = window->GetParent();
402 gfx::Point original_origin = 411 gfx::Point original_origin =
403 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin(); 412 parent_window->ConvertRectToScreen(window->GetTargetBounds()).origin();
404 gfx::Transform new_transform = 413 gfx::Transform new_transform =
405 TransformAboutPivot(gfx::Point(target_origin.x() - original_origin.x(), 414 TransformAboutPivot(gfx::Point(target_origin.x() - original_origin.x(),
406 target_origin.y() - original_origin.y()), 415 target_origin.y() - original_origin.y()),
407 transform); 416 transform);
408 window->SetTransform(new_transform); 417 window->SetTransform(new_transform);
409 } 418 }
410 } 419 }
411 420
412 void ScopedTransformOverviewWindow::SetOpacity(float opacity) { 421 void ScopedTransformOverviewWindow::SetOpacity(float opacity) {
413 for (const auto& window : GetTransientTreeIterator(window_)) { 422 for (const auto& window : GetTransientTreeIterator(window_)) {
414 window->SetOpacity(opacity); 423 window->SetOpacity(opacity);
415 } 424 }
416 } 425 }
417 426
418 void ScopedTransformOverviewWindow::Close() { 427 void ScopedTransformOverviewWindow::Close() {
419 GetTransientRoot(window_)->CloseWidget(); 428 if (immediate_close_for_tests ||
429 !ash::MaterialDesignController::IsOverviewMaterial()) {
430 CloseWidget();
431 return;
432 }
433 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
434 FROM_HERE, base::Bind(&ScopedTransformOverviewWindow::CloseWidget,
435 weak_ptr_factory_.GetWeakPtr()),
436 base::TimeDelta::FromMilliseconds(kCloseWindowDelayInMilliseconds));
420 } 437 }
421 438
422 void ScopedTransformOverviewWindow::PrepareForOverview() { 439 void ScopedTransformOverviewWindow::PrepareForOverview() {
423 DCHECK(!overview_started_); 440 DCHECK(!overview_started_);
424 overview_started_ = true; 441 overview_started_ = true;
425 window_->GetWindowState()->set_ignored_by_shelf(true); 442 window_->GetWindowState()->set_ignored_by_shelf(true);
426 ShowWindowIfMinimized(); 443 ShowWindowIfMinimized();
427 } 444 }
428 445
446 void ScopedTransformOverviewWindow::CloseWidget() {
447 WmWindow* parent_window = GetTransientRoot(window_);
448 if (parent_window)
449 parent_window->CloseWidget();
450 }
451
452 // static
453 void ScopedTransformOverviewWindow::SetImmediateCloseForTests() {
454 immediate_close_for_tests = true;
455 }
456
429 } // namespace ash 457 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698