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.
5 #ifndef ASH_WM_DOCK_DOCK_WINDOW_RESIZER_H_
6 #define ASH_WM_DOCK_DOCK_WINDOW_RESIZER_H_
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"
24 class DockedWindowLayoutManager
;
26 // DockWindowResizer is used by ToplevelWindowEventFilter to handle dragging,
27 // moving or resizing of a window while it is docked to the side of a screen.
28 class ASH_EXPORT DockedWindowResizer
: public WindowResizer
{
30 ~DockedWindowResizer() override
;
32 // Creates a new DockWindowResizer. The caller takes ownership of the
33 // returned object. The ownership of |next_window_resizer| is taken by the
34 // returned object. Returns NULL if not resizable.
35 static DockedWindowResizer
* Create(WindowResizer
* next_window_resizer
,
36 wm::WindowState
* window_state
);
39 void Drag(const gfx::Point
& location
, int event_flags
) override
;
40 void CompleteDrag() override
;
41 void RevertDrag() override
;
44 // Creates DockWindowResizer that adds the ability to attach / detach
45 // windows to / from the dock. This object takes ownership of
46 // |next_window_resizer|.
47 DockedWindowResizer(WindowResizer
* next_window_resizer
,
48 wm::WindowState
* window_state
);
50 // If the provided window bounds should snap to the side of a screen,
51 // returns the offset that gives the necessary adjustment to snap.
52 void MaybeSnapToEdge(const gfx::Rect
& bounds
, gfx::Point
* offset
);
54 // Tracks the window's initial position and attachment at the start of a drag
55 // and informs the DockLayoutManager that a drag has started if necessary.
56 void StartedDragging();
58 // Informs the DockLayoutManager that the drag is complete if it was informed
59 // of the drag start. |move_result| specifies if the drag was completed or
61 void FinishedDragging(aura::client::WindowMoveResult move_result
);
63 // Reparents dragged window as necessary to the docked container or back to
64 // workspace at the end of the drag. Calculates and returns action taken that
65 // can be reported in UMA stats. |is_resized| reports if the window is merely
66 // being resized rather than repositioned. |attached_panel| is necessary to
67 // avoid docking panels that have been attached to the launcher shelf at the
69 DockedAction
MaybeReparentWindowOnDragCompletion(bool is_resized
,
70 bool is_attached_panel
);
72 gfx::Point last_location_
;
74 // Wraps a window resizer and adds detaching / reattaching during drags.
75 scoped_ptr
<WindowResizer
> next_window_resizer_
;
77 // Dock container window.
78 DockedWindowLayoutManager
* dock_layout_
;
79 DockedWindowLayoutManager
* initial_dock_layout_
;
81 // Set to true once Drag() is invoked and the bounds of the window change.
82 bool did_move_or_resize_
;
84 // Set to true if the window that is being dragged was docked before drag.
87 // True if the dragged window is docked during the drag.
90 // True if the dragged window had |bounds_changed_by_user| before the drag.
91 // Cleared whenever the target window gets dragged outside of the docked area.
92 bool was_bounds_changed_by_user_
;
94 base::WeakPtrFactory
<DockedWindowResizer
> weak_ptr_factory_
;
96 DISALLOW_COPY_AND_ASSIGN(DockedWindowResizer
);
101 #endif // ASH_WM_DOCK_DOCK_WINDOW_RESIZER_H_