| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_DESKTOP_DRAG_DROP_CLIENT_AURAX11_H_ | 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_ | 6 #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_DRAG_DROP_CLIENT_AURAX11_H_ |
| 7 | 7 |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 |
| 10 #include <memory> |
| 9 #include <set> | 11 #include <set> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" | 15 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
| 17 #include "ui/aura/window_observer.h" | 18 #include "ui/aura/window_observer.h" |
| 18 #include "ui/base/cursor/cursor.h" | 19 #include "ui/base/cursor/cursor.h" |
| 19 #include "ui/base/dragdrop/drag_drop_types.h" | 20 #include "ui/base/dragdrop/drag_drop_types.h" |
| 20 #include "ui/gfx/geometry/point.h" | 21 #include "ui/gfx/geometry/point.h" |
| 21 #include "ui/gfx/x/x11_atom_cache.h" | 22 #include "ui/gfx/x/x11_atom_cache.h" |
| 22 #include "ui/views/views_export.h" | 23 #include "ui/views/views_export.h" |
| 23 #include "ui/views/widget/desktop_aura/x11_move_loop_delegate.h" | 24 #include "ui/views/widget/desktop_aura/x11_move_loop_delegate.h" |
| 24 #include "ui/wm/public/drag_drop_client.h" | 25 #include "ui/wm/public/drag_drop_client.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void OnMouseMovement(const gfx::Point& screen_point, | 100 void OnMouseMovement(const gfx::Point& screen_point, |
| 100 int flags, | 101 int flags, |
| 101 base::TimeDelta event_time) override; | 102 base::TimeDelta event_time) override; |
| 102 void OnMouseReleased() override; | 103 void OnMouseReleased() override; |
| 103 void OnMoveLoopEnded() override; | 104 void OnMoveLoopEnded() override; |
| 104 | 105 |
| 105 protected: | 106 protected: |
| 106 // The following methods are virtual for the sake of testing. | 107 // The following methods are virtual for the sake of testing. |
| 107 | 108 |
| 108 // Creates a move loop. | 109 // Creates a move loop. |
| 109 virtual scoped_ptr<X11MoveLoop> CreateMoveLoop( | 110 virtual std::unique_ptr<X11MoveLoop> CreateMoveLoop( |
| 110 X11MoveLoopDelegate* delegate); | 111 X11MoveLoopDelegate* delegate); |
| 111 | 112 |
| 112 // Finds the topmost X11 window at |screen_point| and returns it if it is | 113 // Finds the topmost X11 window at |screen_point| and returns it if it is |
| 113 // Xdnd aware. Returns NULL otherwise. | 114 // Xdnd aware. Returns NULL otherwise. |
| 114 virtual ::Window FindWindowFor(const gfx::Point& screen_point); | 115 virtual ::Window FindWindowFor(const gfx::Point& screen_point); |
| 115 | 116 |
| 116 // Sends |xev| to |xid|, optionally short circuiting the round trip to the X | 117 // Sends |xev| to |xid|, optionally short circuiting the round trip to the X |
| 117 // server. | 118 // server. |
| 118 virtual void SendXClientEvent(::Window xid, XEvent* xev); | 119 virtual void SendXClientEvent(::Window xid, XEvent* xev); |
| 119 | 120 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 141 // the mouse is released. | 142 // the mouse is released. |
| 142 void StartEndMoveLoopTimer(); | 143 void StartEndMoveLoopTimer(); |
| 143 | 144 |
| 144 // Ends the move loop. | 145 // Ends the move loop. |
| 145 void EndMoveLoop(); | 146 void EndMoveLoop(); |
| 146 | 147 |
| 147 // When we receive an position x11 message, we need to translate that into | 148 // When we receive an position x11 message, we need to translate that into |
| 148 // the underlying aura::Window representation, as moves internal to the X11 | 149 // the underlying aura::Window representation, as moves internal to the X11 |
| 149 // window can cause internal drag leave and enter messages. | 150 // window can cause internal drag leave and enter messages. |
| 150 void DragTranslate(const gfx::Point& root_window_location, | 151 void DragTranslate(const gfx::Point& root_window_location, |
| 151 scoped_ptr<ui::OSExchangeData>* data, | 152 std::unique_ptr<ui::OSExchangeData>* data, |
| 152 scoped_ptr<ui::DropTargetEvent>* event, | 153 std::unique_ptr<ui::DropTargetEvent>* event, |
| 153 aura::client::DragDropDelegate** delegate); | 154 aura::client::DragDropDelegate** delegate); |
| 154 | 155 |
| 155 // Called when we need to notify the current aura::Window that we're no | 156 // Called when we need to notify the current aura::Window that we're no |
| 156 // longer dragging over it. | 157 // longer dragging over it. |
| 157 void NotifyDragLeave(); | 158 void NotifyDragLeave(); |
| 158 | 159 |
| 159 // Converts our bitfield of actions into an Atom that represents what action | 160 // Converts our bitfield of actions into an Atom that represents what action |
| 160 // we're most likely to take on drop. | 161 // we're most likely to take on drop. |
| 161 ::Atom DragOperationToAtom(int drag_operation); | 162 ::Atom DragOperationToAtom(int drag_operation); |
| 162 | 163 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 195 |
| 195 // Creates a widget for the user to drag around. | 196 // Creates a widget for the user to drag around. |
| 196 void CreateDragWidget(const gfx::ImageSkia& image); | 197 void CreateDragWidget(const gfx::ImageSkia& image); |
| 197 | 198 |
| 198 // Returns true if |image| has any visible regions (defined as having a pixel | 199 // Returns true if |image| has any visible regions (defined as having a pixel |
| 199 // with alpha > 32). | 200 // with alpha > 32). |
| 200 bool IsValidDragImage(const gfx::ImageSkia& image); | 201 bool IsValidDragImage(const gfx::ImageSkia& image); |
| 201 | 202 |
| 202 // A nested message loop that notifies this object of events through the | 203 // A nested message loop that notifies this object of events through the |
| 203 // X11MoveLoopDelegate interface. | 204 // X11MoveLoopDelegate interface. |
| 204 scoped_ptr<X11MoveLoop> move_loop_; | 205 std::unique_ptr<X11MoveLoop> move_loop_; |
| 205 | 206 |
| 206 aura::Window* root_window_; | 207 aura::Window* root_window_; |
| 207 | 208 |
| 208 DesktopNativeCursorManager* cursor_manager_; | 209 DesktopNativeCursorManager* cursor_manager_; |
| 209 | 210 |
| 210 Display* xdisplay_; | 211 Display* xdisplay_; |
| 211 ::Window xwindow_; | 212 ::Window xwindow_; |
| 212 | 213 |
| 213 ui::X11AtomCache atom_cache_; | 214 ui::X11AtomCache atom_cache_; |
| 214 | 215 |
| 215 // Target side information. | 216 // Target side information. |
| 216 class X11DragContext; | 217 class X11DragContext; |
| 217 scoped_ptr<X11DragContext> target_current_context_; | 218 std::unique_ptr<X11DragContext> target_current_context_; |
| 218 | 219 |
| 219 // The modifier state for the most recent mouse move. | 220 // The modifier state for the most recent mouse move. |
| 220 int current_modifier_state_; | 221 int current_modifier_state_; |
| 221 | 222 |
| 222 // The Aura window that is currently under the cursor. We need to manually | 223 // The Aura window that is currently under the cursor. We need to manually |
| 223 // keep track of this because Windows will only call our drag enter method | 224 // keep track of this because Windows will only call our drag enter method |
| 224 // once when the user enters the associated X Window. But inside that X | 225 // once when the user enters the associated X Window. But inside that X |
| 225 // Window there could be multiple aura windows, so we need to generate drag | 226 // Window there could be multiple aura windows, so we need to generate drag |
| 226 // enter events for them. | 227 // enter events for them. |
| 227 aura::Window* target_window_; | 228 aura::Window* target_window_; |
| 228 | 229 |
| 229 // Because Xdnd messages don't contain the position in messages other than | 230 // Because Xdnd messages don't contain the position in messages other than |
| 230 // the XdndPosition message, we must manually keep track of the last position | 231 // the XdndPosition message, we must manually keep track of the last position |
| 231 // change. | 232 // change. |
| 232 gfx::Point target_window_location_; | 233 gfx::Point target_window_location_; |
| 233 gfx::Point target_window_root_location_; | 234 gfx::Point target_window_root_location_; |
| 234 | 235 |
| 235 // In the Xdnd protocol, we aren't supposed to send another XdndPosition | 236 // In the Xdnd protocol, we aren't supposed to send another XdndPosition |
| 236 // message until we have received a confirming XdndStatus message. | 237 // message until we have received a confirming XdndStatus message. |
| 237 bool waiting_on_status_; | 238 bool waiting_on_status_; |
| 238 | 239 |
| 239 // If we would send an XdndPosition message while we're waiting for an | 240 // If we would send an XdndPosition message while we're waiting for an |
| 240 // XdndStatus response, we need to cache the latest details we'd send. | 241 // XdndStatus response, we need to cache the latest details we'd send. |
| 241 scoped_ptr<std::pair<gfx::Point, unsigned long> > next_position_message_; | 242 std::unique_ptr<std::pair<gfx::Point, unsigned long>> next_position_message_; |
| 242 | 243 |
| 243 // Reprocesses the most recent mouse move event if the mouse has not moved | 244 // Reprocesses the most recent mouse move event if the mouse has not moved |
| 244 // in a while in case the window stacking order has changed and | 245 // in a while in case the window stacking order has changed and |
| 245 // |source_current_window_| needs to be updated. | 246 // |source_current_window_| needs to be updated. |
| 246 base::OneShotTimer repeat_mouse_move_timer_; | 247 base::OneShotTimer repeat_mouse_move_timer_; |
| 247 | 248 |
| 248 // When the mouse is released, we need to wait for the last XdndStatus message | 249 // When the mouse is released, we need to wait for the last XdndStatus message |
| 249 // only if we have previously received a status message from | 250 // only if we have previously received a status message from |
| 250 // |source_current_window_|. | 251 // |source_current_window_|. |
| 251 bool status_received_since_enter_; | 252 bool status_received_since_enter_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 268 // is DRAG_NONE if we haven't sent out an XdndPosition message yet, haven't | 269 // is DRAG_NONE if we haven't sent out an XdndPosition message yet, haven't |
| 269 // yet received an XdndStatus or if the other window has told us that there's | 270 // yet received an XdndStatus or if the other window has told us that there's |
| 270 // no action that we can agree on. | 271 // no action that we can agree on. |
| 271 ui::DragDropTypes::DragOperation negotiated_operation_; | 272 ui::DragDropTypes::DragOperation negotiated_operation_; |
| 272 | 273 |
| 273 // Ends the move loop if the target is too slow to respond after the mouse is | 274 // Ends the move loop if the target is too slow to respond after the mouse is |
| 274 // released. | 275 // released. |
| 275 base::OneShotTimer end_move_loop_timer_; | 276 base::OneShotTimer end_move_loop_timer_; |
| 276 | 277 |
| 277 // Widget that the user drags around. May be NULL. | 278 // Widget that the user drags around. May be NULL. |
| 278 scoped_ptr<Widget> drag_widget_; | 279 std::unique_ptr<Widget> drag_widget_; |
| 279 | 280 |
| 280 // The offset of |drag_widget_| relative to the mouse position. | 281 // The offset of |drag_widget_| relative to the mouse position. |
| 281 gfx::Vector2d drag_widget_offset_; | 282 gfx::Vector2d drag_widget_offset_; |
| 282 | 283 |
| 283 base::WeakPtrFactory<DesktopDragDropClientAuraX11> weak_ptr_factory_; | 284 base::WeakPtrFactory<DesktopDragDropClientAuraX11> weak_ptr_factory_; |
| 284 | 285 |
| 285 DISALLOW_COPY_AND_ASSIGN(DesktopDragDropClientAuraX11); | 286 DISALLOW_COPY_AND_ASSIGN(DesktopDragDropClientAuraX11); |
| 286 }; | 287 }; |
| 287 | 288 |
| 288 } // namespace views | 289 } // namespace views |
| 289 | 290 |
| 290 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_DRAG_DROP_CLIENT_AURAX11_H_ | 291 #endif // UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_DRAG_DROP_CLIENT_AURAX11_H_ |
| OLD | NEW |