Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / views / widget / desktop_aura / x11_whole_screen_move_loop.h
blob742d5f45169c4af7a384fefc8e43705d83071dc2
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/base/cursor/cursor.h"
12 #include "ui/events/platform/platform_event_dispatcher.h"
13 #include "ui/gfx/geometry/vector2d_f.h"
14 #include "ui/gfx/image/image_skia.h"
15 #include "ui/gfx/native_widget_types.h"
16 #include "ui/gfx/x/x11_types.h"
17 #include "ui/views/widget/desktop_aura/x11_move_loop.h"
18 #include "ui/views/widget/desktop_aura/x11_move_loop_delegate.h"
20 namespace aura {
21 class Window;
24 namespace ui {
25 class MouseEvent;
26 class ScopedEventDispatcher;
29 namespace views {
31 class Widget;
33 // Runs a nested message loop and grabs the mouse. This is used to implement
34 // dragging.
35 class X11WholeScreenMoveLoop : public X11MoveLoop,
36 public ui::PlatformEventDispatcher {
37 public:
38 explicit X11WholeScreenMoveLoop(X11MoveLoopDelegate* delegate);
39 ~X11WholeScreenMoveLoop() override;
41 // ui:::PlatformEventDispatcher:
42 bool CanDispatchEvent(const ui::PlatformEvent& event) override;
43 uint32_t DispatchEvent(const ui::PlatformEvent& event) override;
45 // X11MoveLoop:
46 bool RunMoveLoop(aura::Window* window, gfx::NativeCursor cursor) override;
47 void UpdateCursor(gfx::NativeCursor cursor) override;
48 void EndMoveLoop() override;
50 private:
51 // Grabs the pointer, setting the mouse cursor to |cursor|. Returns true if
52 // successful.
53 bool GrabPointer(gfx::NativeCursor cursor);
55 void GrabEscKey();
57 // Creates an input-only window to be used during the drag.
58 XID CreateDragInputWindow(XDisplay* display);
60 // Dispatch mouse movement event to |delegate_| in a posted task.
61 void DispatchMouseMovement();
63 X11MoveLoopDelegate* delegate_;
65 // Are we running a nested message loop from RunMoveLoop()?
66 bool in_move_loop_;
67 scoped_ptr<ui::ScopedEventDispatcher> nested_dispatcher_;
69 // Cursor in use prior to the move loop starting. Restored when the move loop
70 // quits.
71 gfx::NativeCursor initial_cursor_;
73 bool should_reset_mouse_flags_;
75 // An invisible InputOnly window. Keyboard grab and sometimes mouse grab
76 // are set on this window.
77 XID grab_input_window_;
79 // Whether the pointer was grabbed on |grab_input_window_|.
80 bool grabbed_pointer_;
82 base::Closure quit_closure_;
84 // Keeps track of whether the move-loop is cancled by the user (e.g. by
85 // pressing escape).
86 bool canceled_;
88 scoped_ptr<ui::MouseEvent> last_motion_in_screen_;
89 base::WeakPtrFactory<X11WholeScreenMoveLoop> weak_factory_;
91 DISALLOW_COPY_AND_ASSIGN(X11WholeScreenMoveLoop);
94 } // namespace views
96 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_H_