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 "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/base/events/event_handler.h"
17 #include "ui/gfx/point.h"
18 #include "ui/gfx/rect.h"
32 class ASH_EXPORT ToplevelWindowEventHandler
33 : public ui::EventHandler
,
34 public aura::client::WindowMoveClient
,
35 public DisplayController::Observer
{
37 explicit ToplevelWindowEventHandler(aura::Window
* owner
);
38 virtual ~ToplevelWindowEventHandler();
40 const aura::Window
* owner() const { return owner_
; }
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
;
47 // Overridden form aura::client::WindowMoveClient:
48 virtual aura::client::WindowMoveResult
RunMoveLoop(
50 const gfx::Vector2d
& drag_offset
,
51 aura::client::WindowMoveSource move_source
) OVERRIDE
;
52 virtual void EndMoveLoop() OVERRIDE
;
54 // Overridden form ash::DisplayController::Observer:
55 virtual void OnDisplayConfigurationChanging() OVERRIDE
;
58 class ScopedWindowResizer
;
60 enum DragCompletionStatus
{
65 void CreateScopedWindowResizer(aura::Window
* window
,
66 const gfx::Point
& point_in_parent
,
67 int window_component
);
70 void CompleteDrag(DragCompletionStatus status
, int event_flags
);
72 void HandleMousePressed(aura::Window
* target
, ui::MouseEvent
* event
);
73 void HandleMouseReleased(aura::Window
* target
, ui::MouseEvent
* event
);
75 // Called during a drag to resize/position the window.
76 // The return value is returned by OnMouseEvent() above.
77 void HandleDrag(aura::Window
* target
, ui::LocatedEvent
* event
);
79 // Called during mouse moves to update window resize shadows.
80 // Return value is returned by OnMouseEvent() above.
81 void HandleMouseMoved(aura::Window
* target
, ui::LocatedEvent
* event
);
83 // Called for mouse exits to hide window resize shadows.
84 // Return value is returned by OnMouseEvent() above.
85 void HandleMouseExited(aura::Window
* target
, ui::LocatedEvent
* event
);
87 // Invoked from ScopedWindowResizer if the window is destroyed.
88 void ResizerWindowDestroyed();
90 // The container which this event handler is handling events on.
93 // Are we running a nested message loop from RunMoveLoop().
96 // Was the move operation cancelled? Used only when the nested loop
97 // is used to move a window.
100 // Is a window move/resize in progress because of gesture events?
101 bool in_gesture_drag_
;
103 // The window bounds before it started the drag.
104 // When a window is moved using a touch gesture, and it is swiped up/down
105 // maximize/minimize, the restore bounds should be set to the bounds of the
106 // window when the drag started.
107 gfx::Rect pre_drag_window_bounds_
;
109 scoped_ptr
<ScopedWindowResizer
> window_resizer_
;
111 base::Closure quit_closure_
;
113 // Used to track if this object is deleted while running a nested message
114 // loop. If non-null the destructor sets this to true.
117 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandler
);
122 #endif // ASH_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_