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 "base/compiler_specific.h"
9 #include "base/memory/scoped_vector.h"
10 #include "ui/gfx/rect.h"
11 #include "ui/gfx/transform.h"
27 class ScopedWindowCopy;
29 // Manages a window in the overview mode. This class allows transforming the
30 // window with a helper to determine the best fit in certain bounds and
31 // copies the window if being moved to another display. The window's state is
32 // restored on destruction of this object.
33 class ScopedTransformOverviewWindow {
35 // The duration of transitions used for window transforms.
36 static const int kTransitionMilliseconds;
38 // Returns |rect| having been shrunk to fit within |bounds| (preserving the
40 static gfx::Rect ShrinkRectToFitPreservingAspectRatio(
41 const gfx::Rect& rect,
42 const gfx::Rect& bounds);
44 // Returns the transform turning |src_rect| into |dst_rect|.
45 static gfx::Transform GetTransformForRect(const gfx::Rect& src_rect,
46 const gfx::Rect& dst_rect);
48 explicit ScopedTransformOverviewWindow(aura::Window* window);
49 virtual ~ScopedTransformOverviewWindow();
51 // Returns true if this window selector window contains the |target|. This is
52 // used to determine if an event targetted this window.
53 bool Contains(const aura::Window* target) const;
55 // Returns the original bounds of all transformed windows.
56 gfx::Rect GetBoundsInScreen() const;
58 // Restores the window if it was minimized.
61 // Restores this window on exit rather than returning it to a minimized state
62 // if it was minimized on entering overview mode.
63 void RestoreWindowOnExit();
65 // Informs the ScopedTransformOverviewWindow that the window being watched was
66 // destroyed. This resets the internal window pointer to avoid calling
67 // anything on the window at destruction time.
68 void OnWindowDestroyed();
70 // Prepares for overview mode by doing any necessary actions before entering.
71 virtual void PrepareForOverview();
73 // Sets |transform| on the window and a copy of the window if the target
74 // |root_window| is not the window's root window. If |animate| the transform
75 // is animated in, otherwise it is immediately applied.
76 void SetTransform(aura::Window* root_window,
77 const gfx::Transform& transform,
80 aura::Window* window() const { return window_; }
83 // Creates copies of |window| and all of its modal transient parents on the
84 // root window |target_root|.
85 void CopyWindowAndTransientParents(aura::Window* target_root,
86 aura::Window* window);
88 // Applies the |transform| to the overview window and all of its transient
89 // children using animations. If |animate| the transform is animated in,
90 // otherwise it is applied immediately.
91 void SetTransformOnWindowAndTransientChildren(const gfx::Transform& transform,
94 // A weak pointer to the real window in the overview.
95 aura::Window* window_;
97 // Copies of the window and transient parents for a different root window.
98 ScopedVector<ScopedWindowCopy> window_copies_;
100 // If true, the window was minimized and should be restored if the window
104 // Tracks if this window was ignored by the shelf.
105 bool ignored_by_shelf_;
107 // True if the window has been transformed for overview mode.
108 bool overview_started_;
110 // The original transform of the window before entering overview mode.
111 gfx::Transform original_transform_;
113 DISALLOW_COPY_AND_ASSIGN(ScopedTransformOverviewWindow);
118 #endif // ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_