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 ASH_DRAG_DROP_DRAG_DROP_TRACKER_H_ 6 #define ASH_DRAG_DROP_DRAG_DROP_TRACKER_H_ 7 8 #include <memory> 9 10 #include "ash/ash_export.h" 11 #include "base/macros.h" 12 #include "ui/events/event.h" 13 14 namespace aura { 15 class Window; 16 class WindowDelegate; 17 } 18 19 namespace ash { 20 21 // Provides functions for handling drag events inside and outside the root 22 // window where drag is started. This internally sets up a capture window for 23 // tracking drag events outside the root window where drag is initiated. 24 // Only X11 environment is supported for now. 25 class ASH_EXPORT DragDropTracker { 26 public: 27 DragDropTracker(aura::Window* context_root, aura::WindowDelegate* delegate); 28 ~DragDropTracker(); 29 capture_window()30 aura::Window* capture_window() { return capture_window_.get(); } 31 32 // Tells our |capture_window_| to take capture. This is not done right at 33 // creation to give the caller a chance to perform any operations needed 34 // before the capture is transferred. 35 void TakeCapture(); 36 37 // Gets the target located at |event| in the coordinates of the active root 38 // window. 39 aura::Window* GetTarget(const ui::LocatedEvent& event); 40 41 // Converts the locations of |event| in the coordinates of the active root 42 // window to the ones in |target|'s coordinates. 43 // Caller takes ownership of the returned object. 44 ui::LocatedEvent* ConvertEvent(aura::Window* target, 45 const ui::LocatedEvent& event); 46 47 private: 48 // A window for capturing drag events while dragging. 49 std::unique_ptr<aura::Window> capture_window_; 50 51 DISALLOW_COPY_AND_ASSIGN(DragDropTracker); 52 }; 53 54 } // namespace ash 55 56 #endif // ASH_DRAG_DROP_DRAG_DROP_TRACKER_H_ 57