• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 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_DOCK_DOCK_WINDOW_RESIZER_H_
6 #define ASH_WM_DOCK_DOCK_WINDOW_RESIZER_H_
7 
8 #include "ash/wm/dock/dock_types.h"
9 #include "ash/wm/window_resizer.h"
10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 
14 namespace gfx {
15 class Point;
16 class Rect;
17 }
18 
19 namespace aura {
20 class RootWindow;
21 }
22 
23 namespace ash {
24 namespace internal {
25 
26 class DockedWindowLayoutManager;
27 
28 // DockWindowResizer is used by ToplevelWindowEventFilter to handle dragging,
29 // moving or resizing of a window while it is docked to the side of a screen.
30 class ASH_EXPORT DockedWindowResizer : public WindowResizer {
31  public:
32   virtual ~DockedWindowResizer();
33 
34   // Creates a new DockWindowResizer. The caller takes ownership of the
35   // returned object. The ownership of |next_window_resizer| is taken by the
36   // returned object. Returns NULL if not resizable.
37   static DockedWindowResizer* Create(WindowResizer* next_window_resizer,
38                                      aura::Window* window,
39                                      const gfx::Point& location,
40                                      int window_component,
41                                      aura::client::WindowMoveSource source);
42 
43   // WindowResizer:
44   virtual void Drag(const gfx::Point& location, int event_flags) OVERRIDE;
45   virtual void CompleteDrag(int event_flags) OVERRIDE;
46   virtual void RevertDrag() OVERRIDE;
47   virtual aura::Window* GetTarget() OVERRIDE;
48   virtual const gfx::Point& GetInitialLocation() const OVERRIDE;
49 
50  private:
51   // Creates DockWindowResizer that adds the ability to attach / detach
52   // windows to / from the dock. This object takes ownership of
53   // |next_window_resizer|.
54   DockedWindowResizer(WindowResizer* next_window_resizer,
55                       const Details& details);
56 
57   // If the provided window bounds should snap to the side of a screen,
58   // returns the offset that gives the necessary adjustment to snap.
59   void MaybeSnapToEdge(const gfx::Rect& bounds, gfx::Point* offset);
60 
61   // Tracks the window's initial position and attachment at the start of a drag
62   // and informs the DockLayoutManager that a drag has started if necessary.
63   void StartedDragging();
64 
65   // Informs the DockLayoutManager that the drag is complete if it was informed
66   // of the drag start.
67   void FinishedDragging();
68 
69   // Reparents dragged window as necessary to the docked container or back to
70   // workspace at the end of the drag. Calculates and returns action taken that
71   // can be reported in UMA stats. |is_resized| reports if the window is merely
72   // being resized rather than repositioned. |attached_panel| is necessary to
73   // avoid docking panels that have been attached to the launcher shelf at the
74   // end of the drag.
75   DockedAction MaybeReparentWindowOnDragCompletion(bool is_resized,
76                                                    bool is_attached_panel);
77 
78   const Details details_;
79 
80   gfx::Point last_location_;
81 
82   // Wraps a window resizer and adds detaching / reattaching during drags.
83   scoped_ptr<WindowResizer> next_window_resizer_;
84 
85   // Dock container window.
86   internal::DockedWindowLayoutManager* dock_layout_;
87   internal::DockedWindowLayoutManager* initial_dock_layout_;
88 
89   // Set to true once Drag() is invoked and the bounds of the window change.
90   bool did_move_or_resize_;
91 
92   // Set to true if the window that is being dragged was docked before drag.
93   bool was_docked_;
94 
95   // True if the dragged window is docked during the drag.
96   bool is_docked_;
97 
98   // True if the dragged window had |bounds_changed_by_user| before the drag.
99   // Cleared whenever the target window gets dragged outside of the docked area.
100   bool was_bounds_changed_by_user_;
101 
102   base::WeakPtrFactory<DockedWindowResizer> weak_ptr_factory_;
103 
104   DISALLOW_COPY_AND_ASSIGN(DockedWindowResizer);
105 };
106 
107 }  // namespace internal
108 }  // namespace ash
109 
110 #endif  // ASH_WM_DOCK_DOCK_WINDOW_RESIZER_H_
111