1 // Copyright (c) 2013 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.
5 #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_H_
6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_H_
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/weak_ptr.h"
11 #include "ui/events/platform/platform_event_dispatcher.h"
12 #include "ui/gfx/image/image_skia.h"
13 #include "ui/gfx/native_widget_types.h"
14 #include "ui/gfx/vector2d_f.h"
15 #include "ui/views/widget/desktop_aura/x11_move_loop.h"
16 #include "ui/views/widget/desktop_aura/x11_move_loop_delegate.h"
18 typedef struct _XDisplay XDisplay
;
25 class ScopedEventDispatcher
;
32 // Runs a nested message loop and grabs the mouse. This is used to implement
34 class X11WholeScreenMoveLoop
: public X11MoveLoop
,
35 public ui::PlatformEventDispatcher
{
37 explicit X11WholeScreenMoveLoop(X11MoveLoopDelegate
* delegate
);
38 virtual ~X11WholeScreenMoveLoop();
40 // ui:::PlatformEventDispatcher:
41 virtual bool CanDispatchEvent(const ui::PlatformEvent
& event
) OVERRIDE
;
42 virtual uint32_t DispatchEvent(const ui::PlatformEvent
& event
) OVERRIDE
;
45 virtual bool RunMoveLoop(aura::Window
* window
,
46 gfx::NativeCursor cursor
) OVERRIDE
;
47 virtual void UpdateCursor(gfx::NativeCursor cursor
) OVERRIDE
;
48 virtual void EndMoveLoop() OVERRIDE
;
51 // Grabs the pointer and keyboard, setting the mouse cursor to |cursor|.
52 // Returns true if the grab was successful.
53 bool GrabPointerAndKeyboard(gfx::NativeCursor cursor
);
55 // Creates an input-only window to be used during the drag.
56 Window
CreateDragInputWindow(XDisplay
* display
);
58 // Dispatch mouse movement event to |delegate_| in a posted task.
59 void DispatchMouseMovement();
61 X11MoveLoopDelegate
* delegate_
;
63 // Are we running a nested message loop from RunMoveLoop()?
65 scoped_ptr
<ui::ScopedEventDispatcher
> nested_dispatcher_
;
67 bool should_reset_mouse_flags_
;
69 // An invisible InputOnly window . We create this window so we can track the
70 // cursor wherever it goes on screen during a drag, since normal windows
71 // don't receive pointer motion events outside of their bounds.
72 ::Window grab_input_window_
;
74 base::Closure quit_closure_
;
76 // Keeps track of whether the move-loop is cancled by the user (e.g. by
80 // Keeps track of whether we still have a pointer grab at the end of the loop.
83 XMotionEvent last_xmotion_
;
84 base::WeakPtrFactory
<X11WholeScreenMoveLoop
> weak_factory_
;
86 DISALLOW_COPY_AND_ASSIGN(X11WholeScreenMoveLoop
);
91 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_H_