OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_H_ | 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_ | 6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "ui/events/platform/platform_event_dispatcher.h" | 11 #include "ui/events/platform/platform_event_dispatcher.h" |
12 #include "ui/gfx/image/image_skia.h" | 12 #include "ui/gfx/image/image_skia.h" |
13 #include "ui/gfx/native_widget_types.h" | 13 #include "ui/gfx/native_widget_types.h" |
14 #include "ui/gfx/vector2d_f.h" | 14 #include "ui/gfx/vector2d_f.h" |
15 #include "ui/views/widget/desktop_aura/x11_move_loop.h" | 15 #include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop_delegate.h" |
16 #include "ui/views/widget/desktop_aura/x11_move_loop_delegate.h" | |
17 | 16 |
18 typedef struct _XDisplay XDisplay; | 17 typedef struct _XDisplay XDisplay; |
19 | 18 |
20 namespace aura { | 19 namespace aura { |
21 class Window; | 20 class Window; |
22 } | 21 } |
23 | 22 |
24 namespace ui { | 23 namespace ui { |
25 class ScopedEventDispatcher; | 24 class ScopedEventDispatcher; |
26 } | 25 } |
27 | 26 |
28 namespace views { | 27 namespace views { |
29 | 28 |
30 class Widget; | 29 class Widget; |
31 | 30 |
32 // Runs a nested message loop and grabs the mouse. This is used to implement | 31 // Runs a nested message loop and grabs the mouse. This is used to implement |
33 // dragging. | 32 // dragging. |
34 class X11WholeScreenMoveLoop : public X11MoveLoop, | 33 class X11WholeScreenMoveLoop : public ui::PlatformEventDispatcher { |
35 public ui::PlatformEventDispatcher { | |
36 public: | 34 public: |
37 explicit X11WholeScreenMoveLoop(X11MoveLoopDelegate* delegate); | 35 explicit X11WholeScreenMoveLoop(X11WholeScreenMoveLoopDelegate* delegate); |
38 virtual ~X11WholeScreenMoveLoop(); | 36 virtual ~X11WholeScreenMoveLoop(); |
39 | 37 |
40 // ui:::PlatformEventDispatcher: | 38 // ui:::PlatformEventDispatcher: |
41 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE; | 39 virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE; |
42 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE; | 40 virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE; |
43 | 41 |
44 // X11MoveLoop: | 42 // Runs the nested message loop. While the mouse is grabbed, use |cursor| as |
45 virtual bool RunMoveLoop(aura::Window* window, | 43 // the mouse cursor. Returns true if the move-loop is completed successfully. |
46 gfx::NativeCursor cursor) OVERRIDE; | 44 // If the pointer-grab fails, or the move-loop is canceled by the user (e.g. |
47 virtual void UpdateCursor(gfx::NativeCursor cursor) OVERRIDE; | 45 // by pressing escape), then returns false. |
48 virtual void EndMoveLoop() OVERRIDE; | 46 bool RunMoveLoop(aura::Window* window, gfx::NativeCursor cursor); |
49 virtual void SetDragImage(const gfx::ImageSkia& image, | 47 |
50 const gfx::Vector2dF& offset) OVERRIDE; | 48 // Updates the cursor while the move loop is running. |
| 49 void UpdateCursor(gfx::NativeCursor cursor); |
| 50 |
| 51 // Ends the RunMoveLoop() that's currently in progress. |
| 52 void EndMoveLoop(); |
| 53 |
| 54 // Sets an image to be used during the drag. |
| 55 void SetDragImage(const gfx::ImageSkia& image, gfx::Vector2dF offset); |
51 | 56 |
52 private: | 57 private: |
53 // Grabs the pointer and keyboard, setting the mouse cursor to |cursor|. | 58 // Grabs the pointer and keyboard, setting the mouse cursor to |cursor|. |
54 // Returns true if the grab was successful. | 59 // Returns true if the grab was successful. |
55 bool GrabPointerAndKeyboard(gfx::NativeCursor cursor); | 60 bool GrabPointerAndKeyboard(gfx::NativeCursor cursor); |
56 | 61 |
57 // Creates an input-only window to be used during the drag. | 62 // Creates an input-only window to be used during the drag. |
58 Window CreateDragInputWindow(XDisplay* display); | 63 Window CreateDragInputWindow(XDisplay* display); |
59 | 64 |
60 // Creates a window to show the drag image during the drag. | 65 // Creates a window to show the drag image during the drag. |
61 void CreateDragImageWindow(); | 66 void CreateDragImageWindow(); |
62 | 67 |
63 // Checks to see if |in_image| is an image that has any visible regions | 68 // Checks to see if |in_image| is an image that has any visible regions |
64 // (defined as having a pixel with alpha > 32). If so, return true. | 69 // (defined as having a pixel with alpha > 32). If so, return true. |
65 bool CheckIfIconValid(); | 70 bool CheckIfIconValid(); |
66 | 71 |
67 // Dispatch mouse movement event to |delegate_| in a posted task. | 72 // Dispatch mouse movement event to |delegate_| in a posted task. |
68 void DispatchMouseMovement(); | 73 void DispatchMouseMovement(); |
69 | 74 |
70 X11MoveLoopDelegate* delegate_; | 75 X11WholeScreenMoveLoopDelegate* delegate_; |
71 | 76 |
72 // Are we running a nested message loop from RunMoveLoop()? | 77 // Are we running a nested message loop from RunMoveLoop()? |
73 bool in_move_loop_; | 78 bool in_move_loop_; |
74 scoped_ptr<ui::ScopedEventDispatcher> nested_dispatcher_; | 79 scoped_ptr<ui::ScopedEventDispatcher> nested_dispatcher_; |
75 | 80 |
76 bool should_reset_mouse_flags_; | 81 bool should_reset_mouse_flags_; |
77 | 82 |
78 // An invisible InputOnly window . We create this window so we can track the | 83 // An invisible InputOnly window . We create this window so we can track the |
79 // cursor wherever it goes on screen during a drag, since normal windows | 84 // cursor wherever it goes on screen during a drag, since normal windows |
80 // don't receive pointer motion events outside of their bounds. | 85 // don't receive pointer motion events outside of their bounds. |
(...skipping 15 matching lines...) Expand all Loading... |
96 gfx::Vector2dF drag_offset_; | 101 gfx::Vector2dF drag_offset_; |
97 XMotionEvent last_xmotion_; | 102 XMotionEvent last_xmotion_; |
98 base::WeakPtrFactory<X11WholeScreenMoveLoop> weak_factory_; | 103 base::WeakPtrFactory<X11WholeScreenMoveLoop> weak_factory_; |
99 | 104 |
100 DISALLOW_COPY_AND_ASSIGN(X11WholeScreenMoveLoop); | 105 DISALLOW_COPY_AND_ASSIGN(X11WholeScreenMoveLoop); |
101 }; | 106 }; |
102 | 107 |
103 } // namespace views | 108 } // namespace views |
104 | 109 |
105 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_H_ | 110 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_H_ |
OLD | NEW |