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_PANELS_PANEL_WINDOW_RESIZER_H_
6#define ASH_WM_PANELS_PANEL_WINDOW_RESIZER_H_
7
8#include "ash/wm/window_resizer.h"
9#include "base/compiler_specific.h"
10#include "base/memory/weak_ptr.h"
11
12namespace gfx {
13class Rect;
14class Point;
15}
16
17namespace ash {
18
19// PanelWindowResizer is used by ToplevelWindowEventFilter to handle dragging,
20// moving or resizing panel window. These can be attached and detached from the
21// launcher.
22class ASH_EXPORT PanelWindowResizer : public WindowResizer {
23 public:
24  virtual ~PanelWindowResizer();
25
26  // Creates a new PanelWindowResizer. The caller takes ownership of the
27  // returned object. The ownership of |next_window_resizer| is taken by the
28  // returned object. Returns NULL if not resizable.
29  static PanelWindowResizer* Create(WindowResizer* next_window_resizer,
30                                    wm::WindowState* window_state);
31
32  // WindowResizer:
33  virtual void Drag(const gfx::Point& location, int event_flags) OVERRIDE;
34  virtual void CompleteDrag() OVERRIDE;
35  virtual void RevertDrag() OVERRIDE;
36
37 private:
38  // Creates PanelWindowResizer that adds the ability to attach / detach panel
39  // windows as well as reparenting them to the panel layer while dragging to
40  // |next_window_resizer|. This object takes ownership of
41  // |next_window_resizer|.
42  PanelWindowResizer(WindowResizer* next_window_resizer,
43                     wm::WindowState* window_state);
44
45  // Checks if the provided window bounds should attach to the launcher. If true
46  // the offset gives the necessary adjustment to snap to the launcher.
47  bool AttachToLauncher(const gfx::Rect& bounds, gfx::Point* offset);
48
49  // Tracks the panel's initial position and attachment at the start of a drag
50  // and informs the PanelLayoutManager that a drag has started if necessary.
51  void StartedDragging();
52
53  // Informs the PanelLayoutManager that the drag is complete if it was informed
54  // of the drag start.
55  void FinishDragging();
56
57  // Updates the dragged panel's index in the launcher.
58  void UpdateLauncherPosition();
59
60  // Last pointer location in screen coordinates.
61  gfx::Point last_location_;
62
63  // Wraps a window resizer and adds panel detaching / reattaching and snapping
64  // to launcher behavior during drags.
65  scoped_ptr<WindowResizer> next_window_resizer_;
66
67  // Panel container window.
68  aura::Window* panel_container_;
69  aura::Window* initial_panel_container_;
70
71  // Set to true once Drag() is invoked and the bounds of the window change.
72  bool did_move_or_resize_;
73
74  // True if the window started attached to the launcher.
75  const bool was_attached_;
76
77  base::WeakPtrFactory<PanelWindowResizer> weak_ptr_factory_;
78
79  DISALLOW_COPY_AND_ASSIGN(PanelWindowResizer);
80};
81
82}  // namespace ash
83
84#endif  // ASH_WM_PANELS_PANEL_WINDOW_RESIZER_H_
85