Chromium Code Reviews| Index: ash/wm/common/wm_toplevel_window_event_handler.h |
| diff --git a/ash/wm/common/wm_toplevel_window_event_handler.h b/ash/wm/common/wm_toplevel_window_event_handler.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..953452ae8d3aa65f58a569a3e7fc64ccf6c8244c |
| --- /dev/null |
| +++ b/ash/wm/common/wm_toplevel_window_event_handler.h |
| @@ -0,0 +1,131 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef ASH_WM_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ |
| +#define ASH_WM_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ |
| + |
| +#include <memory> |
| + |
| +#include "ash/wm/common/ash_wm_common_export.h" |
| +#include "ash/wm/common/wm_display_observer.h" |
| +#include "ash/wm/common/wm_types.h" |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "ui/gfx/geometry/rect.h" |
| +#include "ui/wm/public/window_move_client.h" |
| + |
| +namespace ui { |
| +class KeyEvent; |
| +class LocatedEvent; |
| +class MouseEvent; |
| +class GestureEvent; |
| +} |
| + |
| +namespace ash { |
| + |
| +class WindowResizer; |
| + |
| +namespace wm { |
| + |
| +class WmGlobals; |
| +class WmWindow; |
| + |
| +// WmToplevelWindowEventHandler handles dragging and resizing of top level |
| +// windows. WmToplevelWindowEventHandler is forwarded events, such as from an |
| +// EventHandler. |
|
James Cook
2016/05/21 18:28:21
Nice class comment.
|
| +class ASH_WM_COMMON_EXPORT WmToplevelWindowEventHandler |
| + : public WmDisplayObserver { |
| + public: |
| + // Describes what triggered ending the drag. |
| + 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.
|
| + // The drag successfully completed. |
| + SUCCESS, |
| + |
| + REVERT, |
| + |
| + // The underlying window was destroyed while the drag is in process. |
| + WINDOW_DESTROYED |
| + }; |
| + using EndClosure = base::Callback<void(EndReason)>; |
| + |
| + explicit WmToplevelWindowEventHandler(WmGlobals* globals); |
| + ~WmToplevelWindowEventHandler() override; |
| + |
| + void OnKeyEvent(ui::KeyEvent* event); |
| + void OnMouseEvent(ui::MouseEvent* event, WmWindow* target); |
| + void OnGestureEvent(ui::GestureEvent* event, WmWindow* target); |
| + |
| + // Attempts to start a drag if one is not already in progress. Returns true if |
| + // successful. |end_closure| is run when the drag completes. |end_closure| is |
| + // not run if the drag does not start. |
| + bool AttemptToStartDrag(WmWindow* window, |
| + const gfx::Point& point_in_parent, |
| + int window_component, |
| + aura::client::WindowMoveSource source, |
| + const EndClosure& end_closure); |
| + |
| + // If there is a drag in progress it is reverted, otherwise does nothing. |
| + void RevertDrag(); |
| + |
| + // Returns true if there is a drag in progress. |
| + 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
|
| + |
| + private: |
| + class ScopedWindowResizer; |
| + |
| + // Completes or reverts the drag if one is in progress. Returns true if a |
| + // drag was completed or reverted. |
| + bool CompleteDrag(EndReason reason); |
| + |
| + void HandleMousePressed(WmWindow* target, ui::MouseEvent* event); |
| + void HandleMouseReleased(WmWindow* target, ui::MouseEvent* event); |
| + |
| + // Called during a drag to resize/position the window. |
| + void HandleDrag(WmWindow* target, ui::LocatedEvent* event); |
| + |
| + // Called during mouse moves to update window resize shadows. |
| + void HandleMouseMoved(WmWindow* target, ui::LocatedEvent* event); |
| + |
| + // Called for mouse exits to hide window resize shadows. |
| + void HandleMouseExited(WmWindow* target, ui::LocatedEvent* event); |
| + |
| + // Called when mouse capture is lost. |
| + void HandleCaptureLost(ui::LocatedEvent* event); |
| + |
| + // Sets |window|'s state type to |new_state_type|. Called after the drag has |
| + // been completed for fling gestures. |
| + void SetWindowStateTypeFromGesture(WmWindow* window, |
| + wm::WindowStateType new_state_type); |
| + |
| + // Invoked from ScopedWindowResizer if the window is destroyed. |
| + void ResizerWindowDestroyed(); |
| + |
| + // WmDisplayObserver: |
| + void OnDisplayConfigurationChanging() override; |
| + |
| + WmGlobals* globals_; |
| + |
| + // The hittest result for the first finger at the time that it initially |
| + // touched the screen. |first_finger_hittest_| is one of ui/base/hit_test.h |
| + int first_finger_hittest_; |
| + |
| + // The window bounds when the drag was started. When a window is minimized, |
| + // maximized or snapped via a swipe/fling gesture, the restore bounds should |
| + // be set to the bounds of the window when the drag was started. |
| + gfx::Rect pre_drag_window_bounds_; |
| + |
| + // Is a window move/resize in progress because of gesture events? |
| + 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
|
| + |
| + std::unique_ptr<ScopedWindowResizer> window_resizer_; |
| + |
| + EndClosure end_closure_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WmToplevelWindowEventHandler); |
| +}; |
| + |
| +} // namespace wm |
| +} // namespace ash |
| + |
| +#endif // ASH_WM_WM_TOPLEVEL_WINDOW_EVENT_HANDLER_H_ |