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 "ash/wm/overview/transparent_activate_window_button.h"
10 #include "ash/wm/overview/transparent_activate_window_button_delegate.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/transform.h"
16 #include "ui/views/widget/widget.h"
32 class ScopedWindowCopy
;
34 // Manages a window, and it's transient children, in the overview mode. This
35 // class allows transforming the windows with a helper to determine the best
36 // fit in certain bounds. The window's state is restored on destruction of this
38 class ScopedTransformOverviewWindow
39 : public TransparentActivateWindowButtonDelegate
{
41 typedef ScopedVector
<ScopedOverviewAnimationSettings
> ScopedAnimationSettings
;
43 // Returns |rect| having been shrunk to fit within |bounds| (preserving the
45 static gfx::Rect
ShrinkRectToFitPreservingAspectRatio(
46 const gfx::Rect
& rect
,
47 const gfx::Rect
& bounds
);
49 // Returns the transform turning |src_rect| into |dst_rect|.
50 static gfx::Transform
GetTransformForRect(const gfx::Rect
& src_rect
,
51 const gfx::Rect
& dst_rect
);
53 explicit ScopedTransformOverviewWindow(aura::Window
* window
);
54 ~ScopedTransformOverviewWindow() override
;
56 gfx::Transform
get_overview_transform() const { return overview_transform_
; }
58 void set_overview_transform(const gfx::Transform
& transform
) {
59 overview_transform_
= transform
;
62 TransparentActivateWindowButton
* activate_button() {
63 return activate_button_
.get();
67 // Starts an animation sequence which will use animation settings specified by
68 // |animation_type|. The |animation_settings| container is populated with
69 // scoped entities and the container should be destroyed at the end of the
70 // animation sequence.
73 // ScopedTransformOverviewWindow overview_window(window);
74 // ScopedTransformOverviewWindow::ScopedAnimationSettings scoped_settings;
75 // overview_window.BeginScopedAnimation(
76 // OverviewAnimationType::OVERVIEW_ANIMATION_SELECTOR_ITEM_SCROLL_CANCEL,
77 // &animation_settings);
78 // // Calls to SetTransform & SetOpacity will use the same animation settings
79 // // until scoped_settings is destroyed.
80 // overview_window.SetTransform(root_window, new_transform);
81 // overview_window.SetOpacity(1);
82 void BeginScopedAnimation(
83 OverviewAnimationType animation_type
,
84 ScopedAnimationSettings
* animation_settings
);
86 // Returns true if this window selector window contains the |target|.
87 bool Contains(const aura::Window
* target
) const;
89 // Returns the original target bounds of all transformed windows.
90 gfx::Rect
GetTargetBoundsInScreen() const;
92 // Restores the window if it was minimized.
95 // Restores this window on exit rather than returning it to a minimized state
96 // if it was minimized on entering overview mode.
97 void RestoreWindowOnExit();
99 // Informs the ScopedTransformOverviewWindow that the window being watched was
100 // destroyed. This resets the internal window pointer to avoid calling
101 // anything on the window at destruction time.
102 void OnWindowDestroyed();
104 // Prepares for overview mode by doing any necessary actions before entering.
105 void PrepareForOverview();
107 // Applies the |transform| to the overview window and all of its transient
109 void SetTransform(aura::Window
* root_window
,
110 const gfx::Transform
& transform
);
112 // Set's the opacity of the managed windows.
113 void SetOpacity(float opacity
);
115 aura::Window
* window() const { return window_
; }
117 // Closes the transient root of the window managed by |this|.
120 // ash::TransparentActivateWindowButtonDelegate:
121 void Select() override
;
124 // A weak pointer to the real window in the overview.
125 aura::Window
* window_
;
127 // The transparent overlay that captures events.
128 scoped_ptr
<TransparentActivateWindowButton
> activate_button_
;
130 // If true, the window was minimized and should be restored if the window
134 // Tracks if this window was ignored by the shelf.
135 bool ignored_by_shelf_
;
137 // True if the window has been transformed for overview mode.
138 bool overview_started_
;
140 // The original transform of the window before entering overview mode.
141 gfx::Transform original_transform_
;
143 // Keeps track of the original transform used when |this| has been positioned
144 // during SelectorItem layout.
145 gfx::Transform overview_transform_
;
147 // The original opacity of the window before entering overview mode.
148 float original_opacity_
;
150 DISALLOW_COPY_AND_ASSIGN(ScopedTransformOverviewWindow
);
155 #endif // ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_