Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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" |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 12 | #include "ash/wm/wm_types.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | #include "base/callback.h" |
| 14 | #include "base/compiler_specific.h" |
| 15 | #include "base/memory/scoped_ptr.h" |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 16 | #include "ui/events/event_handler.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 17 | #include "ui/gfx/point.h" |
| 18 | #include "ui/gfx/rect.h" |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 19 | #include "ui/wm/public/window_move_client.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 20 | |
| 21 | namespace aura { |
| 22 | class Window; |
| 23 | } |
| 24 | |
| 25 | namespace ui { |
| 26 | class LocatedEvent; |
| 27 | } |
| 28 | |
| 29 | namespace ash { |
| 30 | |
| 31 | class WindowResizer; |
| 32 | |
| 33 | class ASH_EXPORT ToplevelWindowEventHandler |
| 34 | : public ui::EventHandler, |
| 35 | public aura::client::WindowMoveClient, |
| 36 | public DisplayController::Observer { |
| 37 | public: |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 38 | ToplevelWindowEventHandler(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 39 | virtual ~ToplevelWindowEventHandler(); |
| 40 | |
| 41 | // Overridden from ui::EventHandler: |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 42 | virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
| 43 | virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
| 44 | virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 45 | |
| 46 | // Overridden form aura::client::WindowMoveClient: |
| 47 | virtual aura::client::WindowMoveResult RunMoveLoop( |
| 48 | aura::Window* source, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 49 | const gfx::Vector2d& drag_offset, |
| 50 | aura::client::WindowMoveSource move_source) OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 51 | virtual void EndMoveLoop() OVERRIDE; |
| 52 | |
| 53 | // Overridden form ash::DisplayController::Observer: |
| 54 | virtual void OnDisplayConfigurationChanging() OVERRIDE; |
| 55 | |
| 56 | private: |
| 57 | class ScopedWindowResizer; |
| 58 | |
| 59 | enum DragCompletionStatus { |
| 60 | DRAG_COMPLETE, |
| 61 | DRAG_REVERT |
| 62 | }; |
| 63 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 64 | // Attempts to start a drag if one is not already in progress. Returns true if |
| 65 | // successful. |
| 66 | bool AttemptToStartDrag(aura::Window* window, |
| 67 | const gfx::Point& point_in_parent, |
| 68 | int window_component, |
| 69 | aura::client::WindowMoveSource source); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 70 | |
| 71 | // Finishes the drag. |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 72 | void CompleteDrag(DragCompletionStatus status); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 73 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 74 | void HandleMousePressed(aura::Window* target, ui::MouseEvent* event); |
| 75 | void HandleMouseReleased(aura::Window* target, ui::MouseEvent* event); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 76 | |
| 77 | // Called during a drag to resize/position the window. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 78 | void HandleDrag(aura::Window* target, ui::LocatedEvent* event); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 79 | |
| 80 | // Called during mouse moves to update window resize shadows. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 81 | void HandleMouseMoved(aura::Window* target, ui::LocatedEvent* event); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 82 | |
| 83 | // Called for mouse exits to hide window resize shadows. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 84 | void HandleMouseExited(aura::Window* target, ui::LocatedEvent* event); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 85 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 86 | // Sets |window|'s state type to |new_state_type|. Called after the drag has |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 87 | // been completed for fling gestures. |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 88 | void SetWindowStateTypeFromGesture(aura::Window* window, |
| 89 | wm::WindowStateType new_state_type); |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 90 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 91 | // Invoked from ScopedWindowResizer if the window is destroyed. |
| 92 | void ResizerWindowDestroyed(); |
| 93 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 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_; |
| 97 | |
| 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_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 102 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 103 | // Are we running a nested message loop from RunMoveLoop(). |
| 104 | bool in_move_loop_; |
| 105 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 106 | // Is a window move/resize in progress because of gesture events? |
| 107 | bool in_gesture_drag_; |
| 108 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 109 | // Whether the drag was reverted. Set by CompleteDrag(). |
| 110 | bool drag_reverted_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 111 | |
| 112 | scoped_ptr<ScopedWindowResizer> window_resizer_; |
| 113 | |
| 114 | base::Closure quit_closure_; |
| 115 | |
| 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. |
| 118 | bool* destroyed_; |
| 119 | |
| 120 | DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandler); |
| 121 | }; |
| 122 | |
| 123 | } // namespace aura |
| 124 | |
| 125 | #endif // ASH_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ |