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_TOPLEVEL_WINDOW_EVENT_HANDLER_H_
6 #define ASH_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_
10 #include "ash/ash_export.h"
11 #include "ash/display/display_controller.h"
12 #include "ash/wm/wm_types.h"
13 #include "base/callback.h"
14 #include "base/compiler_specific.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "ui/aura/client/window_move_client.h"
17 #include "ui/events/event_handler.h"
18 #include "ui/gfx/point.h"
19 #include "ui/gfx/rect.h"
33 class ASH_EXPORT ToplevelWindowEventHandler
34 : public ui::EventHandler
,
35 public aura::client::WindowMoveClient
,
36 public DisplayController::Observer
{
38 ToplevelWindowEventHandler();
39 virtual ~ToplevelWindowEventHandler();
41 // Overridden from ui::EventHandler:
42 virtual void OnKeyEvent(ui::KeyEvent
* event
) OVERRIDE
;
43 virtual void OnMouseEvent(ui::MouseEvent
* event
) OVERRIDE
;
44 virtual void OnGestureEvent(ui::GestureEvent
* event
) OVERRIDE
;
46 // Overridden form aura::client::WindowMoveClient:
47 virtual aura::client::WindowMoveResult
RunMoveLoop(
49 const gfx::Vector2d
& drag_offset
,
50 aura::client::WindowMoveSource move_source
) OVERRIDE
;
51 virtual void EndMoveLoop() OVERRIDE
;
53 // Overridden form ash::DisplayController::Observer:
54 virtual void OnDisplayConfigurationChanging() OVERRIDE
;
57 class ScopedWindowResizer
;
59 enum DragCompletionStatus
{
64 // Attempts to start a drag if one is not already in progress. Returns true if
66 bool AttemptToStartDrag(aura::Window
* window
,
67 const gfx::Point
& point_in_parent
,
69 aura::client::WindowMoveSource source
);
72 void CompleteDrag(DragCompletionStatus status
);
74 void HandleMousePressed(aura::Window
* target
, ui::MouseEvent
* event
);
75 void HandleMouseReleased(aura::Window
* target
, ui::MouseEvent
* event
);
77 // Called during a drag to resize/position the window.
78 void HandleDrag(aura::Window
* target
, ui::LocatedEvent
* event
);
80 // Called during mouse moves to update window resize shadows.
81 void HandleMouseMoved(aura::Window
* target
, ui::LocatedEvent
* event
);
83 // Called for mouse exits to hide window resize shadows.
84 void HandleMouseExited(aura::Window
* target
, ui::LocatedEvent
* event
);
86 // Sets |window|'s show type to |new_show_type|. Called after the drag has
87 // been completed for fling gestures.
88 void SetWindowShowTypeFromGesture(aura::Window
* window
,
89 wm::WindowShowType new_show_type
);
91 // Invoked from ScopedWindowResizer if the window is destroyed.
92 void ResizerWindowDestroyed();
94 // The hittest result for the first finger at the time that it initially
95 // touched the screen. |first_finger_hittest_| is one of ui/base/hit_test.h
96 int first_finger_hittest_
;
98 // The window bounds when the drag was started. When a window is minimized,
99 // maximized or snapped via a swipe/fling gesture, the restore bounds should
100 // be set to the bounds of the window when the drag was started.
101 gfx::Rect pre_drag_window_bounds_
;
103 // Are we running a nested message loop from RunMoveLoop().
106 // Is a window move/resize in progress because of gesture events?
107 bool in_gesture_drag_
;
109 // Whether the drag was reverted. Set by CompleteDrag().
112 scoped_ptr
<ScopedWindowResizer
> window_resizer_
;
114 base::Closure quit_closure_
;
116 // Used to track if this object is deleted while running a nested message
117 // loop. If non-null the destructor sets this to true.
120 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandler
);
125 #endif // ASH_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_