190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file. 490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_H_ 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#define UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_H_ 790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/callback.h" 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/compiler_specific.h" 10effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "base/memory/weak_ptr.h" 111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/base/cursor/cursor.h" 12c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "ui/events/platform/platform_event_dispatcher.h" 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/gfx/image/image_skia.h" 147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "ui/gfx/native_widget_types.h" 15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/gfx/vector2d_f.h" 166e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/views/widget/desktop_aura/x11_move_loop.h" 176e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "ui/views/widget/desktop_aura/x11_move_loop_delegate.h" 1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)typedef struct _XDisplay XDisplay; 20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace aura { 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class Window; 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liunamespace ui { 265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuclass ScopedEventDispatcher; 275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu} 285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace views { 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class Widget; 32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Runs a nested message loop and grabs the mouse. This is used to implement 3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// dragging. 356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class X11WholeScreenMoveLoop : public X11MoveLoop, 366e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) public ui::PlatformEventDispatcher { 3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 386e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) explicit X11WholeScreenMoveLoop(X11MoveLoopDelegate* delegate); 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~X11WholeScreenMoveLoop(); 4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 41c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // ui:::PlatformEventDispatcher: 42c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch virtual bool CanDispatchEvent(const ui::PlatformEvent& event) OVERRIDE; 43c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch virtual uint32_t DispatchEvent(const ui::PlatformEvent& event) OVERRIDE; 4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // X11MoveLoop: 466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual bool RunMoveLoop(aura::Window* window, 476e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) gfx::NativeCursor cursor) OVERRIDE; 486e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual void UpdateCursor(gfx::NativeCursor cursor) OVERRIDE; 496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual void EndMoveLoop() OVERRIDE; 50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Grabs the pointer, setting the mouse cursor to |cursor|. Returns true if 531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // successful. 541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool GrabPointer(gfx::NativeCursor cursor); 551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Grabs the keyboard. Returns true if successful. 571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool GrabKeyboard(); 587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Creates an input-only window to be used during the drag. 60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Window CreateDragInputWindow(XDisplay* display); 61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 62effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Dispatch mouse movement event to |delegate_| in a posted task. 63effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch void DispatchMouseMovement(); 64effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 656e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) X11MoveLoopDelegate* delegate_; 6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Are we running a nested message loop from RunMoveLoop()? 6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool in_move_loop_; 695c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu scoped_ptr<ui::ScopedEventDispatcher> nested_dispatcher_; 7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Cursor in use prior to the move loop starting. Restored when the move loop 721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // quits. 731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci gfx::NativeCursor initial_cursor_; 741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool should_reset_mouse_flags_; 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // An invisible InputOnly window. Keyboard grab and sometimes mouse grab 781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // are set on this window. 7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ::Window grab_input_window_; 8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Whether the pointer was grabbed on |grab_input_window_|. 821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bool grabbed_pointer_; 831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::Closure quit_closure_; 8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 86c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Keeps track of whether the move-loop is cancled by the user (e.g. by 87c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // pressing escape). 88c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch bool canceled_; 89c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 90effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch XMotionEvent last_xmotion_; 91effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch base::WeakPtrFactory<X11WholeScreenMoveLoop> weak_factory_; 92f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(X11WholeScreenMoveLoop); 9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace views 9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_H_ 99