| OLD | NEW |
| (Empty) | |
| 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_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ |
| 6 #define ASH_WM_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "ash/wm/common/ash_wm_common_export.h" |
| 11 #include "ash/wm/common/wm_display_observer.h" |
| 12 #include "ash/wm/common/wm_types.h" |
| 13 #include "base/callback.h" |
| 14 #include "base/macros.h" |
| 15 #include "ui/gfx/geometry/rect.h" |
| 16 #include "ui/wm/public/window_move_client.h" |
| 17 |
| 18 namespace ui { |
| 19 class KeyEvent; |
| 20 class LocatedEvent; |
| 21 class MouseEvent; |
| 22 class GestureEvent; |
| 23 } |
| 24 |
| 25 namespace ash { |
| 26 |
| 27 class WindowResizer; |
| 28 |
| 29 namespace wm { |
| 30 |
| 31 class WmGlobals; |
| 32 class WmWindow; |
| 33 |
| 34 // WmToplevelWindowEventHandler handles dragging and resizing of top level |
| 35 // windows. WmToplevelWindowEventHandler is forwarded events, such as from an |
| 36 // EventHandler. |
| 37 class ASH_WM_COMMON_EXPORT WmToplevelWindowEventHandler |
| 38 : public WmDisplayObserver { |
| 39 public: |
| 40 // Describes what triggered ending the drag. |
| 41 enum class DragResult { |
| 42 // The drag successfully completed. |
| 43 SUCCESS, |
| 44 |
| 45 REVERT, |
| 46 |
| 47 // The underlying window was destroyed while the drag is in process. |
| 48 WINDOW_DESTROYED |
| 49 }; |
| 50 using EndClosure = base::Callback<void(DragResult)>; |
| 51 |
| 52 explicit WmToplevelWindowEventHandler(WmGlobals* globals); |
| 53 ~WmToplevelWindowEventHandler() override; |
| 54 |
| 55 void OnKeyEvent(ui::KeyEvent* event); |
| 56 void OnMouseEvent(ui::MouseEvent* event, WmWindow* target); |
| 57 void OnGestureEvent(ui::GestureEvent* event, WmWindow* target); |
| 58 |
| 59 // Attempts to start a drag if one is not already in progress. Returns true if |
| 60 // successful. |end_closure| is run when the drag completes. |end_closure| is |
| 61 // not run if the drag does not start. |
| 62 bool AttemptToStartDrag(WmWindow* window, |
| 63 const gfx::Point& point_in_parent, |
| 64 int window_component, |
| 65 aura::client::WindowMoveSource source, |
| 66 const EndClosure& end_closure); |
| 67 |
| 68 // If there is a drag in progress it is reverted, otherwise does nothing. |
| 69 void RevertDrag(); |
| 70 |
| 71 private: |
| 72 class ScopedWindowResizer; |
| 73 |
| 74 // Completes or reverts the drag if one is in progress. Returns true if a |
| 75 // drag was completed or reverted. |
| 76 bool CompleteDrag(DragResult result); |
| 77 |
| 78 void HandleMousePressed(WmWindow* target, ui::MouseEvent* event); |
| 79 void HandleMouseReleased(WmWindow* target, ui::MouseEvent* event); |
| 80 |
| 81 // Called during a drag to resize/position the window. |
| 82 void HandleDrag(WmWindow* target, ui::LocatedEvent* event); |
| 83 |
| 84 // Called during mouse moves to update window resize shadows. |
| 85 void HandleMouseMoved(WmWindow* target, ui::LocatedEvent* event); |
| 86 |
| 87 // Called for mouse exits to hide window resize shadows. |
| 88 void HandleMouseExited(WmWindow* target, ui::LocatedEvent* event); |
| 89 |
| 90 // Called when mouse capture is lost. |
| 91 void HandleCaptureLost(ui::LocatedEvent* event); |
| 92 |
| 93 // Sets |window|'s state type to |new_state_type|. Called after the drag has |
| 94 // been completed for fling gestures. |
| 95 void SetWindowStateTypeFromGesture(WmWindow* window, |
| 96 wm::WindowStateType new_state_type); |
| 97 |
| 98 // Invoked from ScopedWindowResizer if the window is destroyed. |
| 99 void ResizerWindowDestroyed(); |
| 100 |
| 101 // WmDisplayObserver: |
| 102 void OnDisplayConfigurationChanging() override; |
| 103 |
| 104 WmGlobals* globals_; |
| 105 |
| 106 // The hittest result for the first finger at the time that it initially |
| 107 // touched the screen. |first_finger_hittest_| is one of ui/base/hit_test.h |
| 108 int first_finger_hittest_; |
| 109 |
| 110 // The window bounds when the drag was started. When a window is minimized, |
| 111 // maximized or snapped via a swipe/fling gesture, the restore bounds should |
| 112 // be set to the bounds of the window when the drag was started. |
| 113 gfx::Rect pre_drag_window_bounds_; |
| 114 |
| 115 // Is a window move/resize in progress because of gesture events? |
| 116 bool in_gesture_drag_ = false; |
| 117 |
| 118 std::unique_ptr<ScopedWindowResizer> window_resizer_; |
| 119 |
| 120 EndClosure end_closure_; |
| 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(WmToplevelWindowEventHandler); |
| 123 }; |
| 124 |
| 125 } // namespace wm |
| 126 } // namespace ash |
| 127 |
| 128 #endif // ASH_WM_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ |
| OLD | NEW |