Home | History | Annotate | Download | only in wm
      1 // Copyright (c) 2012 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_DRAG_WINDOW_CONTROLLER_H_
      6 #define ASH_WM_DRAG_WINDOW_CONTROLLER_H_
      7 
      8 #include "ash/ash_export.h"
      9 #include "base/basictypes.h"
     10 #include "base/gtest_prod_util.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "ui/gfx/display.h"
     13 #include "ui/gfx/rect.h"
     14 
     15 namespace aura {
     16 class Window;
     17 }
     18 
     19 namespace ui {
     20 class Layer;
     21 class LayerTreeOwner;
     22 }
     23 
     24 namespace views {
     25 class Widget;
     26 }
     27 
     28 namespace ash {
     29 
     30 // DragWindowController is responsible for showing a semi-transparent window
     31 // while dragging a window across displays.
     32 class ASH_EXPORT DragWindowController {
     33  public:
     34   explicit DragWindowController(aura::Window* window);
     35   virtual ~DragWindowController();
     36 
     37   // Sets the display where the window is placed after the window is dropped.
     38   void SetDestinationDisplay(const gfx::Display& dst_display);
     39 
     40   // Shows the drag window at the specified location (coordinates of the
     41   // parent). If |layer| is non-NULL, it is shown on top of the drag window.
     42   // |layer| is owned by the caller.
     43   // This does not immediately show the window.
     44   void Show();
     45 
     46   // Hides the drag window.
     47   void Hide();
     48 
     49   // This is used to set bounds for the drag window immediately. This should
     50   // be called only when the drag window is already visible.
     51   void SetBounds(const gfx::Rect& bounds);
     52 
     53   // Sets the opacity of the drag window.
     54   void SetOpacity(float opacity);
     55 
     56  private:
     57   FRIEND_TEST_ALL_PREFIXES(DragWindowResizerTest, DragWindowController);
     58 
     59   // Creates and shows the |drag_widget_| at |bounds|.
     60   // |layer| is shown on top of the drag window if it is non-NULL.
     61   // |layer| is not owned by this object.
     62   void CreateDragWidget(const gfx::Rect& bounds);
     63 
     64   // Sets bounds of the drag window. The window is shown on |dst_display_|
     65   // if its id() is valid. Otherwise, a display nearest to |bounds| is chosen.
     66   void SetBoundsInternal(const gfx::Rect& bounds);
     67 
     68   // Recreates a fresh layer for |window_| and all its child windows.
     69   void RecreateWindowLayers();
     70 
     71   // Window the drag window is placed beneath.
     72   aura::Window* window_;
     73 
     74   // The display where the drag is placed. When dst_display_.id() is
     75   // kInvalidDisplayID (i.e. the default), a display nearest to the current
     76   // |bounds_| is automatically used.
     77   gfx::Display dst_display_;
     78 
     79   // Initially the bounds of |window_|. Each time Show() is invoked
     80   // |start_bounds_| is then reset to the bounds of |drag_widget_| and
     81   // |bounds_| is set to the value passed into Show(). The animation animates
     82   // between these two values.
     83   gfx::Rect bounds_;
     84 
     85   views::Widget* drag_widget_;
     86 
     87   // The copy of window_->layer() and its descendants.
     88   scoped_ptr<ui::LayerTreeOwner> layer_owner_;
     89 
     90   DISALLOW_COPY_AND_ASSIGN(DragWindowController);
     91 };
     92 
     93 }  // namespace ash
     94 
     95 #endif  // ASH_WM_DRAG_WINDOW_CONTROLLER_H_
     96