x11_whole_screen_move_loop.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/message_loop/message_pump_dispatcher.h"
12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/gfx/image/image_skia.h"
137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "ui/gfx/native_widget_types.h"
14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "ui/gfx/vector2d_f.h"
1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ui/views/widget/desktop_aura/x11_whole_screen_move_loop_delegate.h"
1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)typedef struct _XDisplay XDisplay;
18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace aura {
2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class Window;
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace views {
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class Widget;
26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Runs a nested message loop and grabs the mouse. This is used to implement
2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// dragging.
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class X11WholeScreenMoveLoop : public base::MessagePumpDispatcher {
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public:
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  explicit X11WholeScreenMoveLoop(X11WholeScreenMoveLoopDelegate* delegate);
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual ~X11WholeScreenMoveLoop();
3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Overridden from base::MessagePumpDispatcher:
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual uint32_t Dispatch(const base::NativeEvent& event) OVERRIDE;
3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Runs the nested message loop. While the mouse is grabbed, use |cursor| as
387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // the mouse cursor. Returns true if there we were able to grab the pointer
397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // and run the move loop.
407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bool RunMoveLoop(aura::Window* window, gfx::NativeCursor cursor);
417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Updates the cursor while the move loop is running.
437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void UpdateCursor(gfx::NativeCursor cursor);
4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Ends the RunMoveLoop() that's currently in progress.
4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  void EndMoveLoop();
4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Sets an image to be used during the drag.
49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void SetDragImage(const gfx::ImageSkia& image, gfx::Vector2dF offset);
50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private:
52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Grabs the pointer and keyboard, setting the mouse cursor to |cursor|.
53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Returns true if the grab was successful.
54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool GrabPointerAndKeyboard(gfx::NativeCursor cursor);
557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Creates an input-only window to be used during the drag.
57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  Window CreateDragInputWindow(XDisplay* display);
58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Creates a window to show the drag image during the drag.
60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  void CreateDragImageWindow();
61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Checks to see if |in_image| is an image that has any visible regions
63a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // (defined as having a pixel with alpha > 32). If so, return true.
64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool CheckIfIconValid();
65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
66effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Dispatch mouse movement event to |delegate_| in a posted task.
67effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  void DispatchMouseMovement();
68effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  X11WholeScreenMoveLoopDelegate* delegate_;
7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Are we running a nested message loop from RunMoveLoop()?
7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool in_move_loop_;
7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool should_reset_mouse_flags_;
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // An invisible InputOnly window . We create this window so we can track the
7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // cursor wherever it goes on screen during a drag, since normal windows
7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // don't receive pointer motion events outside of their bounds.
7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ::Window grab_input_window_;
8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::Closure quit_closure_;
8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // A Widget is created during the drag if there is an image available to be
84f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // used during the drag.
85f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  scoped_ptr<Widget> drag_widget_;
86f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::ImageSkia drag_image_;
87f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  gfx::Vector2dF drag_offset_;
88effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  XMotionEvent last_xmotion_;
89effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  base::WeakPtrFactory<X11WholeScreenMoveLoop> weak_factory_;
90f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(X11WholeScreenMoveLoop);
9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace views
9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif  // UI_VIEWS_WIDGET_DESKTOP_AURA_X11_WHOLE_SCREEN_MOVE_LOOP_H_
97