Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: ash/wm/common/wm_toplevel_window_event_handler.h

Issue 2001623003: Splits ToplevelWindowEventHandler into two (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.
James Cook 2016/05/21 18:28:21 Nice class comment.
37 class ASH_WM_COMMON_EXPORT WmToplevelWindowEventHandler
38 : public WmDisplayObserver {
39 public:
40 // Describes what triggered ending the drag.
41 enum class EndReason {
James Cook 2016/05/21 18:28:21 I would call this DragEndReason or DragResult or s
sky 2016/05/23 15:48:52 I went with 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(EndReason)>;
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 // Returns true if there is a drag in progress.
72 bool is_drag_in_progress() const { return window_resizer_.get() != nullptr; }
James Cook 2016/05/21 18:28:21 I don't think this is used. (Man, I wish we had se
sky 2016/05/23 15:48:52 I use it in a subsequent patch. But I'll add it th
73
74 private:
75 class ScopedWindowResizer;
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(EndReason reason);
80
81 void HandleMousePressed(WmWindow* target, ui::MouseEvent* event);
82 void HandleMouseReleased(WmWindow* target, ui::MouseEvent* event);
83
84 // Called during a drag to resize/position the window.
85 void HandleDrag(WmWindow* target, ui::LocatedEvent* event);
86
87 // Called during mouse moves to update window resize shadows.
88 void HandleMouseMoved(WmWindow* target, ui::LocatedEvent* event);
89
90 // Called for mouse exits to hide window resize shadows.
91 void HandleMouseExited(WmWindow* 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(WmWindow* window,
99 wm::WindowStateType new_state_type);
100
101 // Invoked from ScopedWindowResizer if the window is destroyed.
102 void ResizerWindowDestroyed();
103
104 // WmDisplayObserver:
105 void OnDisplayConfigurationChanging() override;
106
107 WmGlobals* globals_;
108
109 // The hittest result for the first finger at the time that it initially
110 // touched the screen. |first_finger_hittest_| is one of ui/base/hit_test.h
111 int first_finger_hittest_;
112
113 // The window bounds when the drag was started. When a window is minimized,
114 // maximized or snapped via a swipe/fling gesture, the restore bounds should
115 // be set to the bounds of the window when the drag was started.
116 gfx::Rect pre_drag_window_bounds_;
117
118 // Is a window move/resize in progress because of gesture events?
119 bool in_gesture_drag_ = false;
James Cook 2016/05/21 18:28:21 optional nit: Consider initializing this in the .c
sky 2016/05/23 15:48:52 I agree with you, but I think it's just something
120
121 std::unique_ptr<ScopedWindowResizer> window_resizer_;
122
123 EndClosure end_closure_;
124
125 DISALLOW_COPY_AND_ASSIGN(WmToplevelWindowEventHandler);
126 };
127
128 } // namespace wm
129 } // namespace ash
130
131 #endif // ASH_WM_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698