Index: ash/drag_drop/drag_drop_tracker.cc |
diff --git a/ash/drag_drop/drag_drop_tracker.cc b/ash/drag_drop/drag_drop_tracker.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..286dacfd3833c6a522b11ad8b4a02e69fabdab91 |
--- /dev/null |
+++ b/ash/drag_drop/drag_drop_tracker.cc |
@@ -0,0 +1,80 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ash/drag_drop/drag_drop_tracker.h" |
+ |
+#include "ash/shell.h" |
+#include "ash/shell_window_ids.h" |
+#include "ash/wm/coordinate_conversion.h" |
+#include "ui/aura/root_window.h" |
+#include "ui/base/event.h" |
+ |
+namespace { |
+ |
+// Creates a window for capturing drag events. |
+aura::Window* CreateCaptureWindow(aura::RootWindow* root_window) { |
+ aura::Window* window = new aura::Window(NULL); |
+ window->Init(ui::LAYER_NOT_DRAWN); |
+ aura::Window* default_container = |
+ ash::Shell::GetContainer(root_window, |
+ ash::internal::kShellWindowId_DefaultContainer); |
+ default_container->AddChild(window); |
sky
2012/08/20 15:35:18
Doesn't SetParent(NULL) do what you want instead o
mazda
2012/08/21 02:10:59
Yes, it does with some setups. I changed the code
|
+ window->Show(); |
+ return window; |
+} |
+ |
+} // namespace |
+ |
+namespace ash { |
+namespace internal { |
+ |
+DragDropTracker::DragDropTracker() |
+ : capture_window_(NULL) { |
+} |
+ |
+DragDropTracker::~DragDropTracker() { |
+ StopTracking(); |
+} |
+ |
+void DragDropTracker::StartTracking(aura::RootWindow* root_window) { |
+ StopTracking(); |
+ capture_window_ = CreateCaptureWindow(root_window); |
+ capture_window_->SetCapture(); |
+} |
+ |
+void DragDropTracker::StopTracking() { |
+ if (capture_window_) { |
+ capture_window_->ReleaseCapture(); |
+ delete capture_window_; |
+ } |
+ capture_window_ = NULL; |
+} |
+ |
+aura::Window* DragDropTracker::GetTarget(const ui::LocatedEvent& event) { |
+ std::pair<aura::RootWindow*, gfx::Point> pair = |
+ ash::wm::GetRootWindowRelativeToWindow(capture_window_->GetRootWindow(), |
+ event.location()); |
+ return pair.first->GetEventHandlerForPoint(pair.second); |
+} |
+ |
+ui::MouseEvent* DragDropTracker::ConvertMouseEvent( |
+ aura::Window* target, |
+ const ui::MouseEvent& event) { |
+ DCHECK(capture_window_); |
+ std::pair<aura::RootWindow*, gfx::Point> location_pair = |
+ ash::wm::GetRootWindowRelativeToWindow(capture_window_->GetRootWindow(), |
+ event.location()); |
+ aura::Window::ConvertPointToTarget(location_pair.first, target, |
+ &location_pair.second); |
+ std::pair<aura::RootWindow*, gfx::Point> root_location_pair = |
+ ash::wm::GetRootWindowRelativeToWindow(capture_window_->GetRootWindow(), |
+ event.root_location()); |
+ return new ui::MouseEvent(event.type(), |
+ location_pair.second, |
+ root_location_pair.second, |
+ event.flags()); |
+} |
+ |
+} // namespace internal |
+} // namespace ash |