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 12 namespace gfx { 13 class Rect; 14 class Point; 15 } 16 17 namespace 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. 22 class 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 aura::Window* window, 31 const gfx::Point& location, 32 int window_component, 33 aura::client::WindowMoveSource source); 34 35 // WindowResizer: 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; 41 42 private: 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); 49 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); 53 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(); 57 58 // Informs the PanelLayoutManager that the drag is complete if it was informed 59 // of the drag start. 60 void FinishDragging(); 61 62 // Updates the dragged panel's index in the launcher. 63 void UpdateLauncherPosition(); 64 65 const Details details_; 66 67 // Last pointer location in screen coordinates. 68 gfx::Point last_location_; 69 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_; 73 74 // Panel container window. 75 aura::Window* panel_container_; 76 aura::Window* initial_panel_container_; 77 78 // Set to true once Drag() is invoked and the bounds of the window change. 79 bool did_move_or_resize_; 80 81 // True if the window started attached to the launcher. 82 const bool was_attached_; 83 84 // True if the window should attach to the launcher after releasing. 85 bool should_attach_; 86 87 base::WeakPtrFactory<PanelWindowResizer> weak_ptr_factory_; 88 89 DISALLOW_COPY_AND_ASSIGN(PanelWindowResizer); 90 }; 91 92 } // namespace ash 93 94 #endif // ASH_WM_PANELS_PANEL_WINDOW_RESIZER_H_ 95