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
3 // found in the LICENSE file.
5 #ifndef ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_
6 #define ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_
8 #include "ash/wm/overview/scoped_overview_animation_settings.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/scoped_vector.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/transform.h"
14 #include "ui/views/widget/widget.h"
30 class ScopedWindowCopy
;
32 // Manages a window, and it's transient children, in the overview mode. This
33 // class allows transforming the windows with a helper to determine the best
34 // fit in certain bounds. The window's state is restored on destruction of this
36 class ScopedTransformOverviewWindow
{
38 typedef ScopedVector
<ScopedOverviewAnimationSettings
> ScopedAnimationSettings
;
40 // Returns |rect| having been shrunk to fit within |bounds| (preserving the
42 static gfx::Rect
ShrinkRectToFitPreservingAspectRatio(
43 const gfx::Rect
& rect
,
44 const gfx::Rect
& bounds
);
46 // Returns the transform turning |src_rect| into |dst_rect|.
47 static gfx::Transform
GetTransformForRect(const gfx::Rect
& src_rect
,
48 const gfx::Rect
& dst_rect
);
50 explicit ScopedTransformOverviewWindow(aura::Window
* window
);
51 ~ScopedTransformOverviewWindow();
53 gfx::Transform
get_overview_transform() const { return overview_transform_
; }
55 void set_overview_transform(const gfx::Transform
& transform
) {
56 overview_transform_
= transform
;
59 // Starts an animation sequence which will use animation settings specified by
60 // |animation_type|. The |animation_settings| container is populated with
61 // scoped entities and the container should be destroyed at the end of the
62 // animation sequence.
65 // ScopedTransformOverviewWindow overview_window(window);
66 // ScopedTransformOverviewWindow::ScopedAnimationSettings scoped_settings;
67 // overview_window.BeginScopedAnimation(
68 // OverviewAnimationType::OVERVIEW_ANIMATION_SELECTOR_ITEM_SCROLL_CANCEL,
69 // &animation_settings);
70 // // Calls to SetTransform & SetOpacity will use the same animation settings
71 // // until scoped_settings is destroyed.
72 // overview_window.SetTransform(root_window, new_transform);
73 // overview_window.SetOpacity(1);
74 void BeginScopedAnimation(
75 OverviewAnimationType animation_type
,
76 ScopedAnimationSettings
* animation_settings
);
78 // Returns true if this window selector window contains the |target|.
79 bool Contains(const aura::Window
* target
) const;
81 // Returns the original target bounds of all transformed windows.
82 gfx::Rect
GetTargetBoundsInScreen() const;
84 // Restores and animates the managed window to it's non overview mode state.
87 // Forces the managed window to be shown (ie not hidden or minimized) when
88 // calling RestoreWindow().
89 void ShowWindowOnExit();
91 // Informs the ScopedTransformOverviewWindow that the window being watched was
92 // destroyed. This resets the internal window pointer.
93 void OnWindowDestroyed();
95 // Prepares for overview mode by doing any necessary actions before entering.
96 void PrepareForOverview();
98 // Applies the |transform| to the overview window and all of its transient
100 void SetTransform(aura::Window
* root_window
,
101 const gfx::Transform
& transform
);
103 // Set's the opacity of the managed windows.
104 void SetOpacity(float opacity
);
106 aura::Window
* window() const { return window_
; }
108 // Closes the transient root of the window managed by |this|.
112 // Shows the window if it was minimized.
113 void ShowWindowIfMinimized();
115 // A weak pointer to the real window in the overview.
116 aura::Window
* window_
;
118 // If true, the window was minimized and should be restored if the window
122 // Tracks if this window was ignored by the shelf.
123 bool ignored_by_shelf_
;
125 // True if the window has been transformed for overview mode.
126 bool overview_started_
;
128 // The original transform of the window before entering overview mode.
129 gfx::Transform original_transform_
;
131 // Keeps track of the original transform used when |this| has been positioned
132 // during SelectorItem layout.
133 gfx::Transform overview_transform_
;
135 // The original opacity of the window before entering overview mode.
136 float original_opacity_
;
138 DISALLOW_COPY_AND_ASSIGN(ScopedTransformOverviewWindow
);
143 #endif // ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_