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_vector.h" 10 #include "ui/gfx/rect.h" 11 #include "ui/gfx/transform.h" 12 13 namespace aura { 14 class Window; 15 } 16 17 namespace ui { 18 class Layer; 19 } 20 21 namespace views { 22 class Widget; 23 } 24 25 namespace ash { 26 27 class ScopedWindowCopy; 28 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 { 34 public: 35 // The duration of transitions used for window transforms. 36 static const int kTransitionMilliseconds; 37 38 // Returns |rect| having been shrunk to fit within |bounds| (preserving the 39 // aspect ratio). 40 static gfx::Rect ShrinkRectToFitPreservingAspectRatio( 41 const gfx::Rect& rect, 42 const gfx::Rect& bounds); 43 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); 47 48 explicit ScopedTransformOverviewWindow(aura::Window* window); 49 virtual ~ScopedTransformOverviewWindow(); 50 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; 54 55 // Returns the original bounds of all transformed windows. 56 gfx::Rect GetBoundsInScreen() const; 57 58 // Restores the window if it was minimized. 59 void RestoreWindow(); 60 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(); 64 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(); 69 70 // Prepares for overview mode by doing any necessary actions before entering. 71 virtual void PrepareForOverview(); 72 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, 78 bool animate); 79 80 aura::Window* window() const { return window_; } 81 82 private: 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); 87 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, 92 bool animate); 93 94 // A weak pointer to the real window in the overview. 95 aura::Window* window_; 96 97 // Copies of the window and transient parents for a different root window. 98 ScopedVector<ScopedWindowCopy> window_copies_; 99 100 // If true, the window was minimized and should be restored if the window 101 // was not selected. 102 bool minimized_; 103 104 // Tracks if this window was ignored by the shelf. 105 bool ignored_by_shelf_; 106 107 // True if the window has been transformed for overview mode. 108 bool overview_started_; 109 110 // The original transform of the window before entering overview mode. 111 gfx::Transform original_transform_; 112 113 DISALLOW_COPY_AND_ASSIGN(ScopedTransformOverviewWindow); 114 }; 115 116 } // namespace ash 117 118 #endif // ASH_WM_OVERVIEW_SCOPED_TRANSFORM_OVERVIEW_WINDOW_H_ 119