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_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ 6 #define ASH_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ 7 8 #include <set> 9 10 #include "ash/ash_export.h" 11 #include "ash/display/display_controller.h" 12 #include "base/callback.h" 13 #include "base/compiler_specific.h" 14 #include "base/memory/scoped_ptr.h" 15 #include "ui/aura/client/window_move_client.h" 16 #include "ui/events/event_handler.h" 17 #include "ui/gfx/point.h" 18 #include "ui/gfx/rect.h" 19 20 namespace aura { 21 class Window; 22 } 23 24 namespace ui { 25 class LocatedEvent; 26 } 27 28 namespace ash { 29 30 class WindowResizer; 31 32 class ASH_EXPORT ToplevelWindowEventHandler 33 : public ui::EventHandler, 34 public aura::client::WindowMoveClient, 35 public DisplayController::Observer { 36 public: 37 explicit ToplevelWindowEventHandler(aura::Window* owner); 38 virtual ~ToplevelWindowEventHandler(); 39 40 const aura::Window* owner() const { return owner_; } 41 42 // Overridden from ui::EventHandler: 43 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; 44 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 45 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 46 47 // Overridden form aura::client::WindowMoveClient: 48 virtual aura::client::WindowMoveResult RunMoveLoop( 49 aura::Window* source, 50 const gfx::Vector2d& drag_offset, 51 aura::client::WindowMoveSource move_source) OVERRIDE; 52 virtual void EndMoveLoop() OVERRIDE; 53 54 // Overridden form ash::DisplayController::Observer: 55 virtual void OnDisplayConfigurationChanging() OVERRIDE; 56 57 private: 58 class ScopedWindowResizer; 59 60 enum DragCompletionStatus { 61 DRAG_COMPLETE, 62 DRAG_REVERT 63 }; 64 65 void CreateScopedWindowResizer(aura::Window* window, 66 const gfx::Point& point_in_parent, 67 int window_component, 68 aura::client::WindowMoveSource source); 69 70 // Finishes the drag. 71 void CompleteDrag(DragCompletionStatus status, int event_flags); 72 73 void HandleMousePressed(aura::Window* target, ui::MouseEvent* event); 74 void HandleMouseReleased(aura::Window* target, ui::MouseEvent* event); 75 76 // Called during a drag to resize/position the window. 77 // The return value is returned by OnMouseEvent() above. 78 void HandleDrag(aura::Window* target, ui::LocatedEvent* event); 79 80 // Called during mouse moves to update window resize shadows. 81 // Return value is returned by OnMouseEvent() above. 82 void HandleMouseMoved(aura::Window* target, ui::LocatedEvent* event); 83 84 // Called for mouse exits to hide window resize shadows. 85 // Return value is returned by OnMouseEvent() above. 86 void HandleMouseExited(aura::Window* target, ui::LocatedEvent* event); 87 88 // Invoked from ScopedWindowResizer if the window is destroyed. 89 void ResizerWindowDestroyed(); 90 91 // The container which this event handler is handling events on. 92 aura::Window* owner_; 93 94 // Are we running a nested message loop from RunMoveLoop(). 95 bool in_move_loop_; 96 97 // Was the move operation cancelled? Used only when the nested loop 98 // is used to move a window. 99 bool move_cancelled_; 100 101 // Is a window move/resize in progress because of gesture events? 102 bool in_gesture_drag_; 103 104 // The window bounds before it started the drag. 105 // When a window is moved using a touch gesture, and it is swiped up/down 106 // maximize/minimize, the restore bounds should be set to the bounds of the 107 // window when the drag started. 108 gfx::Rect pre_drag_window_bounds_; 109 110 scoped_ptr<ScopedWindowResizer> window_resizer_; 111 112 base::Closure quit_closure_; 113 114 // Used to track if this object is deleted while running a nested message 115 // loop. If non-null the destructor sets this to true. 116 bool* destroyed_; 117 118 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandler); 119 }; 120 121 } // namespace aura 122 123 #endif // ASH_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ 124