Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / wm / dock / docked_window_resizer.h
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 class DockedWindowLayoutManager;
25
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 {
29  public:
30   ~DockedWindowResizer() override;
31
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);
37
38   // WindowResizer:
39   void Drag(const gfx::Point& location, int event_flags) override;
40   void CompleteDrag() override;
41   void RevertDrag() override;
42
43  private:
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);
49
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);
53
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();
57
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
60   // reverted.
61   void FinishedDragging(aura::client::WindowMoveResult move_result);
62
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
68   // end of the drag.
69   DockedAction MaybeReparentWindowOnDragCompletion(bool is_resized,
70                                                    bool is_attached_panel);
71
72   gfx::Point last_location_;
73
74   // Wraps a window resizer and adds detaching / reattaching during drags.
75   scoped_ptr<WindowResizer> next_window_resizer_;
76
77   // Dock container window.
78   DockedWindowLayoutManager* dock_layout_;
79   DockedWindowLayoutManager* initial_dock_layout_;
80
81   // Set to true once Drag() is invoked and the bounds of the window change.
82   bool did_move_or_resize_;
83
84   // Set to true if the window that is being dragged was docked before drag.
85   bool was_docked_;
86
87   // True if the dragged window is docked during the drag.
88   bool is_docked_;
89
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_;
93
94   base::WeakPtrFactory<DockedWindowResizer> weak_ptr_factory_;
95
96   DISALLOW_COPY_AND_ASSIGN(DockedWindowResizer);
97 };
98
99 }  // namespace ash
100
101 #endif  // ASH_WM_DOCK_DOCK_WINDOW_RESIZER_H_