OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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. |
| 4 |
| 5 #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_DRAG_DROP_CLIENT_AURAX11_H_ |
| 6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_DRAG_DROP_CLIENT_AURAX11_H_ |
| 7 |
| 8 #include <X11/Xlib.h> |
| 9 |
| 10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. |
| 11 #undef RootWindow |
| 12 |
| 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "ui/aura/client/drag_drop_client.h" |
| 17 #include "ui/aura/window_observer.h" |
| 18 #include "ui/base/x/x11_atom_cache.h" |
| 19 #include "ui/gfx/point.h" |
| 20 #include "ui/views/views_export.h" |
| 21 |
| 22 namespace aura { |
| 23 class RootWindow; |
| 24 namespace client { |
| 25 class DragDropDelegate; |
| 26 } |
| 27 } |
| 28 |
| 29 namespace gfx { |
| 30 class Point; |
| 31 } |
| 32 |
| 33 namespace ui { |
| 34 class DragSource; |
| 35 class DropTargetEvent; |
| 36 class OSExchangeData; |
| 37 class RootWindow; |
| 38 } |
| 39 |
| 40 namespace views { |
| 41 class DesktopRootWindowHostX11; |
| 42 |
| 43 // Implements drag and drop on X11 for aura. On one side, this class takes raw |
| 44 // X11 events forwarded from DesktopRootWindowHostLinux, while on the other, it |
| 45 // handles the views drag events. |
| 46 class VIEWS_EXPORT DesktopDragDropClientAuraX11 |
| 47 : public aura::client::DragDropClient, |
| 48 public aura::WindowObserver { |
| 49 public: |
| 50 DesktopDragDropClientAuraX11( |
| 51 views::DesktopRootWindowHostX11* root_window_host, |
| 52 aura::RootWindow* root_window, |
| 53 Display* xdisplay, |
| 54 ::Window xwindow); |
| 55 virtual ~DesktopDragDropClientAuraX11(); |
| 56 |
| 57 // These methods handle the various X11 client messages from the platform. |
| 58 void OnXdndEnter(const XClientMessageEvent& event); |
| 59 void OnXdndLeave(const XClientMessageEvent& event); |
| 60 void OnXdndPosition(const XClientMessageEvent& event); |
| 61 void OnXdndStatus(const XClientMessageEvent& event); |
| 62 void OnXdndFinished(const XClientMessageEvent& event); |
| 63 void OnXdndDrop(const XClientMessageEvent& event); |
| 64 |
| 65 // Overridden from aura::client::DragDropClient: |
| 66 virtual int StartDragAndDrop( |
| 67 const ui::OSExchangeData& data, |
| 68 aura::RootWindow* root_window, |
| 69 aura::Window* source_window, |
| 70 const gfx::Point& root_location, |
| 71 int operation, |
| 72 ui::DragDropTypes::DragEventSource source) OVERRIDE; |
| 73 virtual void DragUpdate(aura::Window* target, |
| 74 const ui::LocatedEvent& event) OVERRIDE; |
| 75 virtual void Drop(aura::Window* target, |
| 76 const ui::LocatedEvent& event) OVERRIDE; |
| 77 virtual void DragCancel() OVERRIDE; |
| 78 virtual bool IsDragDropInProgress() OVERRIDE; |
| 79 |
| 80 // aura::WindowObserver implementation: |
| 81 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; |
| 82 |
| 83 private: |
| 84 // When we receive an position x11 message, we need to translate that into |
| 85 // the underlying aura::Window representation, as moves internal to the X11 |
| 86 // window can cause internal drag leave and enter messages. |
| 87 void DragTranslate(const gfx::Point& root_window_location, |
| 88 scoped_ptr<ui::OSExchangeData>* data, |
| 89 scoped_ptr<ui::DropTargetEvent>* event, |
| 90 aura::client::DragDropDelegate** delegate); |
| 91 |
| 92 // Called when we need to notify the current aura::Window that we're no |
| 93 // longer dragging over it. |
| 94 void NotifyDragLeave(); |
| 95 |
| 96 // Converts our bitfield of actions into an Atom that represents what action |
| 97 // we're most likely to take on drop. |
| 98 unsigned long DragOperationToAtom(int drag_operation); |
| 99 |
| 100 // Sends |xev| to |xid|, optionally short circuiting the round trip to the X |
| 101 // server. |
| 102 void SendXClientEvent(unsigned long xid, XEvent* xev); |
| 103 |
| 104 views::DesktopRootWindowHostX11* root_window_host_; |
| 105 aura::RootWindow* root_window_; |
| 106 |
| 107 Display* xdisplay_; |
| 108 ::Window xwindow_; |
| 109 |
| 110 ui::X11AtomCache atom_cache_; |
| 111 |
| 112 // Target side information. |
| 113 |
| 114 class X11DragContext; |
| 115 scoped_ptr<X11DragContext> current_context_; |
| 116 |
| 117 // The Aura window that is currently under the cursor. We need to manually |
| 118 // keep track of this because Windows will only call our drag enter method |
| 119 // once when the user enters the associated X Window. But inside that X |
| 120 // Window there could be multiple aura windows, so we need to generate drag |
| 121 // enter events for them. |
| 122 aura::Window* target_window_; |
| 123 |
| 124 // Because Xdnd messages don't contain the position in messages other than |
| 125 // the XdndPosition message, we must manually keep track of the last position |
| 126 // change. |
| 127 gfx::Point target_window_location_; |
| 128 gfx::Point target_window_root_location_; |
| 129 |
| 130 bool drag_drop_in_progress_; |
| 131 |
| 132 int drag_operation_; |
| 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(DesktopDragDropClientAuraX11); |
| 135 }; |
| 136 |
| 137 } // namespace views |
| 138 |
| 139 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_DRAG_DROP_CLIENT_AURAX11_H_ |
OLD | NEW |