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..91502e446b72e043fa73879768d4794c52bb3ff6 |
--- /dev/null |
+++ b/ash/drag_drop/drag_drop_tracker.cc |
@@ -0,0 +1,140 @@ |
+// 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/aura/window_delegate.h" |
+#include "ui/base/event.h" |
+#include "ui/gfx/path.h" |
+ |
+namespace { |
+ |
+// WindowDelegate for capturing drag events in DragDropTracker. This basically |
+// does nothing. |
+class DragDropTrackerWindowDelegate : public aura::WindowDelegate { |
+ public: |
+ DragDropTrackerWindowDelegate() {} |
+ virtual ~DragDropTrackerWindowDelegate() {}; |
+ |
+ private: |
+ // Overridden from WindowDelegate: |
+ virtual gfx::Size GetMinimumSize() const OVERRIDE { |
+ return gfx::Size(); |
+ } |
+ virtual void OnBoundsChanged(const gfx::Rect& old_bounds, |
+ const gfx::Rect& new_bounds) OVERRIDE { |
+ } |
+ virtual void OnFocus(aura::Window* old_focused_window) OVERRIDE { |
+ } |
+ virtual void OnBlur() OVERRIDE { |
+ } |
+ virtual bool OnKeyEvent(ui::KeyEvent* event) OVERRIDE { |
+ return false; |
+ } |
+ virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { |
+ return gfx::kNullCursor; |
+ } |
+ virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { |
+ return 0; |
+ } |
+ virtual bool ShouldDescendIntoChildForEventHandling( |
+ aura::Window* child, |
+ const gfx::Point& location) OVERRIDE { |
+ return true; |
+ } |
+ virtual bool OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
+ return true; |
+ } |
+ virtual ui::TouchStatus OnTouchEvent(ui::TouchEvent* event) OVERRIDE { |
+ return ui::TOUCH_STATUS_END; |
+ } |
+ virtual ui::GestureStatus OnGestureEvent(ui::GestureEvent* event) OVERRIDE { |
+ return ui::GESTURE_STATUS_UNKNOWN; |
+ } |
+ virtual bool CanFocus() OVERRIDE { return true; } |
+ virtual void OnCaptureLost() OVERRIDE {} |
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
+ } |
+ virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} |
+ virtual void OnWindowDestroying() OVERRIDE {} |
+ virtual void OnWindowDestroyed() OVERRIDE { delete this; } |
+ virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} |
+ virtual bool HasHitTestMask() const OVERRIDE { return false; } |
+ virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DragDropTrackerWindowDelegate); |
+}; |
+ |
+// Creates a window for capturing drag events. |
+aura::Window* CreateCaptureWindow(aura::RootWindow* root_window) { |
+ aura::Window* window = new aura::Window(new DragDropTrackerWindowDelegate); |
+ window->Init(ui::LAYER_NOT_DRAWN); |
+ aura::Window* default_container = |
+ ash::Shell::GetContainer(root_window, |
+ ash::internal::kShellWindowId_DefaultContainer); |
+ default_container->AddChild(window); |
+ 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()); |
+ aura::Window::ConvertPointToTarget(root_location_pair.first, target, |
+ &root_location_pair.second); |
+ return new ui::MouseEvent(event.type(), |
+ location_pair.second, |
+ root_location_pair.second, |
+ event.flags()); |
+} |
+ |
+} // namespace internal |
+} // namespace ash |