• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_
6 #define ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_
7 
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/gfx/transform.h"
13 #include "ui/views/widget/widget.h"
14 
15 namespace aura {
16 class Window;
17 }
18 
19 namespace ui {
20 class Layer;
21 }
22 
23 namespace views {
24 class Widget;
25 }
26 
27 namespace ash {
28 
29 class ScopedWindowCopy;
30 
31 // Manages a window in the overview mode. This class allows transforming the
32 // window with a helper to determine the best fit in certain bounds and
33 // copies the window if being moved to another display. The window's state is
34 // restored on destruction of this object.
35 class ScopedTransformOverviewWindow {
36  public:
37   // The duration of transitions used for window transforms.
38   static const int kTransitionMilliseconds;
39 
40   // Returns |rect| having been shrunk to fit within |bounds| (preserving the
41   // aspect ratio).
42   static gfx::Rect ShrinkRectToFitPreservingAspectRatio(
43       const gfx::Rect& rect,
44       const gfx::Rect& bounds);
45 
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);
49 
50   explicit ScopedTransformOverviewWindow(aura::Window* window);
51   virtual ~ScopedTransformOverviewWindow();
52 
53   // Returns true if this window selector window contains the |target|. This is
54   // used to determine if an event targeted this window.
55   bool Contains(const aura::Window* target) const;
56 
57   // Returns the original bounds of all transformed windows.
58   gfx::Rect GetBoundsInScreen() const;
59 
60   // Restores the window if it was minimized.
61   void RestoreWindow();
62 
63   // Restores this window on exit rather than returning it to a minimized state
64   // if it was minimized on entering overview mode.
65   void RestoreWindowOnExit();
66 
67   // Informs the ScopedTransformOverviewWindow that the window being watched was
68   // destroyed. This resets the internal window pointer to avoid calling
69   // anything on the window at destruction time.
70   void OnWindowDestroyed();
71 
72   // Prepares for overview mode by doing any necessary actions before entering.
73   virtual void PrepareForOverview();
74 
75   // Sets |transform| on the window and a copy of the window if the target
76   // |root_window| is not the window's root window. If |animate| the transform
77   // is animated in, otherwise it is immediately applied.
78   virtual void SetTransform(aura::Window* root_window,
79                             const gfx::Transform& transform,
80                             bool animate);
81 
window()82   aura::Window* window() const { return window_; }
83 
84  private:
85   // Creates copies of |window| and all of its modal transient parents on the
86   // root window |target_root|.
87   void CopyWindowAndTransientParents(aura::Window* target_root,
88                                      aura::Window* window);
89 
90   // Applies the |transform| to the overview window and all of its transient
91   // children using animations. If |animate| the transform is animated in,
92   // otherwise it is applied immediately.
93   void SetTransformOnWindowAndTransientChildren(const gfx::Transform& transform,
94                                                 bool animate);
95 
96   // A weak pointer to the real window in the overview.
97   aura::Window* window_;
98 
99   // Copies of the window and transient parents for a different root window.
100   ScopedVector<ScopedWindowCopy> window_copies_;
101 
102   // If true, the window was minimized and should be restored if the window
103   // was not selected.
104   bool minimized_;
105 
106   // Tracks if this window was ignored by the shelf.
107   bool ignored_by_shelf_;
108 
109   // True if the window has been transformed for overview mode.
110   bool overview_started_;
111 
112   // The original transform of the window before entering overview mode.
113   gfx::Transform original_transform_;
114 
115   // The original opacity of the window before entering overview mode.
116   float opacity_;
117 
118   DISALLOW_COPY_AND_ASSIGN(ScopedTransformOverviewWindow);
119 };
120 
121 }  // namespace ash
122 
123 #endif  // ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_
124