| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ASH_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ | 5 #ifndef ASH_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ |
| 6 #define ASH_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ | 6 #define ASH_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ |
| 7 | 7 |
| 8 #include <memory> | |
| 9 #include <set> | |
| 10 | |
| 11 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 12 #include "ash/display/window_tree_host_manager.h" | 9 #include "ash/wm/common/wm_toplevel_window_event_handler.h" |
| 13 #include "ash/wm/common/wm_types.h" | 10 #include "ash/wm/common/wm_types.h" |
| 14 #include "base/callback.h" | |
| 15 #include "base/compiler_specific.h" | |
| 16 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 17 #include "ui/events/event_handler.h" | 13 #include "ui/events/event_handler.h" |
| 18 #include "ui/gfx/geometry/point.h" | |
| 19 #include "ui/gfx/geometry/rect.h" | |
| 20 #include "ui/wm/public/window_move_client.h" | 14 #include "ui/wm/public/window_move_client.h" |
| 21 | 15 |
| 22 namespace aura { | 16 namespace aura { |
| 23 class Window; | 17 class Window; |
| 24 } | 18 } |
| 25 | 19 |
| 26 namespace ui { | 20 namespace base { |
| 27 class LocatedEvent; | 21 class RunLoop; |
| 28 } | 22 } |
| 29 | 23 |
| 30 namespace ash { | 24 namespace ash { |
| 31 | 25 namespace wm { |
| 32 class WindowResizer; | 26 class WmGloblals; |
| 27 } |
| 33 | 28 |
| 34 class ASH_EXPORT ToplevelWindowEventHandler | 29 class ASH_EXPORT ToplevelWindowEventHandler |
| 35 : public ui::EventHandler, | 30 : public ui::EventHandler, |
| 36 public aura::client::WindowMoveClient, | 31 public aura::client::WindowMoveClient { |
| 37 public WindowTreeHostManager::Observer { | |
| 38 public: | 32 public: |
| 39 ToplevelWindowEventHandler(); | 33 explicit ToplevelWindowEventHandler(wm::WmGlobals* globals); |
| 40 ~ToplevelWindowEventHandler() override; | 34 ~ToplevelWindowEventHandler() override; |
| 41 | 35 |
| 42 // Overridden from ui::EventHandler: | 36 // Overridden from ui::EventHandler: |
| 43 void OnKeyEvent(ui::KeyEvent* event) override; | 37 void OnKeyEvent(ui::KeyEvent* event) override; |
| 44 void OnMouseEvent(ui::MouseEvent* event) override; | 38 void OnMouseEvent(ui::MouseEvent* event) override; |
| 45 void OnGestureEvent(ui::GestureEvent* event) override; | 39 void OnGestureEvent(ui::GestureEvent* event) override; |
| 46 | 40 |
| 47 // Overridden form aura::client::WindowMoveClient: | 41 // Overridden form aura::client::WindowMoveClient: |
| 48 aura::client::WindowMoveResult RunMoveLoop( | 42 aura::client::WindowMoveResult RunMoveLoop( |
| 49 aura::Window* source, | 43 aura::Window* source, |
| 50 const gfx::Vector2d& drag_offset, | 44 const gfx::Vector2d& drag_offset, |
| 51 aura::client::WindowMoveSource move_source) override; | 45 aura::client::WindowMoveSource move_source) override; |
| 52 void EndMoveLoop() override; | 46 void EndMoveLoop() override; |
| 53 | 47 |
| 54 // Overridden form ash::WindowTreeHostManager::Observer: | 48 private: |
| 55 void OnDisplayConfigurationChanging() override; | 49 // Callback from WmToplevelWindowEventHandler once the drag completes. |
| 50 void OnDragCompleted( |
| 51 wm::WmToplevelWindowEventHandler::DragResult* result_return_value, |
| 52 base::RunLoop* run_loop, |
| 53 wm::WmToplevelWindowEventHandler::DragResult result); |
| 56 | 54 |
| 57 private: | 55 wm::WmToplevelWindowEventHandler wm_toplevel_window_event_handler_; |
| 58 class ScopedWindowResizer; | |
| 59 | |
| 60 enum DragCompletionStatus { | |
| 61 DRAG_COMPLETE, | |
| 62 DRAG_REVERT, | |
| 63 | |
| 64 // To be used when WindowResizer::GetTarget() is destroyed. Neither | |
| 65 // completes nor reverts the drag because both access the WindowResizer's | |
| 66 // window. | |
| 67 DRAG_RESIZER_WINDOW_DESTROYED | |
| 68 }; | |
| 69 | |
| 70 // Attempts to start a drag if one is not already in progress. Returns true if | |
| 71 // successful. | |
| 72 bool AttemptToStartDrag(aura::Window* window, | |
| 73 const gfx::Point& point_in_parent, | |
| 74 int window_component, | |
| 75 aura::client::WindowMoveSource source); | |
| 76 | |
| 77 // Completes or reverts the drag if one is in progress. Returns true if a | |
| 78 // drag was completed or reverted. | |
| 79 bool CompleteDrag(DragCompletionStatus status); | |
| 80 | |
| 81 void HandleMousePressed(aura::Window* target, ui::MouseEvent* event); | |
| 82 void HandleMouseReleased(aura::Window* target, ui::MouseEvent* event); | |
| 83 | |
| 84 // Called during a drag to resize/position the window. | |
| 85 void HandleDrag(aura::Window* target, ui::LocatedEvent* event); | |
| 86 | |
| 87 // Called during mouse moves to update window resize shadows. | |
| 88 void HandleMouseMoved(aura::Window* target, ui::LocatedEvent* event); | |
| 89 | |
| 90 // Called for mouse exits to hide window resize shadows. | |
| 91 void HandleMouseExited(aura::Window* target, ui::LocatedEvent* event); | |
| 92 | |
| 93 // Called when mouse capture is lost. | |
| 94 void HandleCaptureLost(ui::LocatedEvent* event); | |
| 95 | |
| 96 // Sets |window|'s state type to |new_state_type|. Called after the drag has | |
| 97 // been completed for fling gestures. | |
| 98 void SetWindowStateTypeFromGesture(aura::Window* window, | |
| 99 wm::WindowStateType new_state_type); | |
| 100 | |
| 101 // Invoked from ScopedWindowResizer if the window is destroyed. | |
| 102 void ResizerWindowDestroyed(); | |
| 103 | |
| 104 // The hittest result for the first finger at the time that it initially | |
| 105 // touched the screen. |first_finger_hittest_| is one of ui/base/hit_test.h | |
| 106 int first_finger_hittest_; | |
| 107 | |
| 108 // The window bounds when the drag was started. When a window is minimized, | |
| 109 // maximized or snapped via a swipe/fling gesture, the restore bounds should | |
| 110 // be set to the bounds of the window when the drag was started. | |
| 111 gfx::Rect pre_drag_window_bounds_; | |
| 112 | 56 |
| 113 // Are we running a nested message loop from RunMoveLoop(). | 57 // Are we running a nested message loop from RunMoveLoop(). |
| 114 bool in_move_loop_; | 58 bool in_move_loop_ = false; |
| 115 | 59 |
| 116 // Is a window move/resize in progress because of gesture events? | 60 base::WeakPtrFactory<ToplevelWindowEventHandler> weak_factory_; |
| 117 bool in_gesture_drag_; | |
| 118 | |
| 119 // Whether the drag was reverted. Set by CompleteDrag(). | |
| 120 bool drag_reverted_; | |
| 121 | |
| 122 std::unique_ptr<ScopedWindowResizer> window_resizer_; | |
| 123 | |
| 124 base::Closure quit_closure_; | |
| 125 | |
| 126 // Used to track if this object is deleted while running a nested message | |
| 127 // loop. If non-null the destructor sets this to true. | |
| 128 bool* destroyed_; | |
| 129 | 61 |
| 130 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandler); | 62 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandler); |
| 131 }; | 63 }; |
| 132 | 64 |
| 133 } // namespace aura | 65 } // namespace ash |
| 134 | 66 |
| 135 #endif // ASH_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ | 67 #endif // ASH_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ |
| OLD | NEW |