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.
5 #ifndef ASH_WM_PANELS_PANEL_WINDOW_RESIZER_H_
6 #define ASH_WM_PANELS_PANEL_WINDOW_RESIZER_H_
8 #include "ash/wm/window_resizer.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/weak_ptr.h"
19 // PanelWindowResizer is used by ToplevelWindowEventFilter to handle dragging,
20 // moving or resizing panel window. These can be attached and detached from the
22 class ASH_EXPORT PanelWindowResizer : public WindowResizer {
24 virtual ~PanelWindowResizer();
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,
31 const gfx::Point& location,
33 aura::client::WindowMoveSource source);
36 virtual void Drag(const gfx::Point& location, int event_flags) OVERRIDE;
37 virtual void CompleteDrag(int event_flags) OVERRIDE;
38 virtual void RevertDrag() OVERRIDE;
39 virtual aura::Window* GetTarget() OVERRIDE;
40 virtual const gfx::Point& GetInitialLocation() const OVERRIDE;
43 // Creates PanelWindowResizer that adds the ability to attach / detach panel
44 // windows as well as reparenting them to the panel layer while dragging to
45 // |next_window_resizer|. This object takes ownership of
46 // |next_window_resizer|.
47 PanelWindowResizer(WindowResizer* next_window_resizer,
48 const Details& details);
50 // Checks if the provided window bounds should attach to the launcher. If true
51 // the offset gives the necessary adjustment to snap to the launcher.
52 bool AttachToLauncher(const gfx::Rect& bounds, gfx::Point* offset);
54 // Tracks the panel's initial position and attachment at the start of a drag
55 // and informs the PanelLayoutManager that a drag has started if necessary.
56 void StartedDragging();
58 // Informs the PanelLayoutManager that the drag is complete if it was informed
60 void FinishDragging();
62 // Updates the dragged panel's index in the launcher.
63 void UpdateLauncherPosition();
65 const Details details_;
67 // Last pointer location in screen coordinates.
68 gfx::Point last_location_;
70 // Wraps a window resizer and adds panel detaching / reattaching and snapping
71 // to launcher behavior during drags.
72 scoped_ptr<WindowResizer> next_window_resizer_;
74 // Panel container window.
75 aura::Window* panel_container_;
76 aura::Window* initial_panel_container_;
78 // Set to true once Drag() is invoked and the bounds of the window change.
79 bool did_move_or_resize_;
81 // True if the window started attached to the launcher.
82 const bool was_attached_;
84 // True if the window should attach to the launcher after releasing.
87 base::WeakPtrFactory<PanelWindowResizer> weak_ptr_factory_;
89 DISALLOW_COPY_AND_ASSIGN(PanelWindowResizer);
94 #endif // ASH_WM_PANELS_PANEL_WINDOW_RESIZER_H_