Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / drag_drop / drag_drop_controller.cc
index 1d5d636..5ce5cd5 100644 (file)
@@ -7,16 +7,14 @@
 #include "ash/drag_drop/drag_drop_tracker.h"
 #include "ash/drag_drop/drag_image_view.h"
 #include "ash/shell.h"
-#include "ash/wm/coordinate_conversion.h"
 #include "base/bind.h"
 #include "base/message_loop/message_loop.h"
 #include "base/run_loop.h"
 #include "ui/aura/client/capture_client.h"
-#include "ui/aura/client/drag_drop_delegate.h"
 #include "ui/aura/env.h"
-#include "ui/aura/root_window.h"
 #include "ui/aura/window.h"
 #include "ui/aura/window_delegate.h"
+#include "ui/aura/window_event_dispatcher.h"
 #include "ui/base/dragdrop/drag_drop_types.h"
 #include "ui/base/dragdrop/os_exchange_data.h"
 #include "ui/base/hit_test.h"
 #include "ui/gfx/rect_conversions.h"
 #include "ui/views/views_delegate.h"
 #include "ui/views/widget/native_widget_aura.h"
+#include "ui/wm/core/coordinate_conversion.h"
+#include "ui/wm/public/drag_drop_delegate.h"
 
 namespace ash {
-namespace internal {
-
 namespace {
+
 // The duration of the drag cancel animation in millisecond.
 const int kCancelAnimationDuration = 250;
 const int kTouchCancelAnimationDuration = 20;
@@ -65,14 +64,11 @@ gfx::Rect AdjustDragImageBoundsForScaleAndOffset(
 
 void DispatchGestureEndToWindow(aura::Window* window) {
   if (window && window->delegate()) {
-    ui::GestureEvent gesture_end(
-        ui::ET_GESTURE_END,
-        0,
-        0,
-        0,
-        ui::EventTimeForNow(),
-        ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0),
-        0);
+    ui::GestureEvent gesture_end(0,
+                                 0,
+                                 0,
+                                 ui::EventTimeForNow(),
+                                 ui::GestureEventDetails(ui::ET_GESTURE_END));
     window->delegate()->OnGestureEvent(&gesture_end);
   }
 }
@@ -82,49 +78,40 @@ class DragDropTrackerDelegate : public aura::WindowDelegate {
  public:
   explicit DragDropTrackerDelegate(DragDropController* controller)
       : drag_drop_controller_(controller) {}
-  virtual ~DragDropTrackerDelegate() {}
+  ~DragDropTrackerDelegate() override {}
 
   // Overridden from WindowDelegate:
-  virtual gfx::Size GetMinimumSize() const OVERRIDE {
-    return gfx::Size();
-  }
+  gfx::Size GetMinimumSize() const override { return gfx::Size(); }
 
-  virtual gfx::Size GetMaximumSize() const OVERRIDE {
-    return gfx::Size();
-  }
+  gfx::Size GetMaximumSize() const override { return gfx::Size(); }
 
-  virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
-                               const gfx::Rect& new_bounds) OVERRIDE {}
-  virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
+  void OnBoundsChanged(const gfx::Rect& old_bounds,
+                       const gfx::Rect& new_bounds) override {}
+  gfx::NativeCursor GetCursor(const gfx::Point& point) override {
     return gfx::kNullCursor;
   }
-  virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
+  int GetNonClientComponent(const gfx::Point& point) const override {
     return HTCAPTION;
   }
-  virtual bool ShouldDescendIntoChildForEventHandling(
+  bool ShouldDescendIntoChildForEventHandling(
       aura::Window* child,
-      const gfx::Point& location) OVERRIDE {
+      const gfx::Point& location) override {
     return true;
   }
-  virtual bool CanFocus() OVERRIDE { return true; }
-  virtual void OnCaptureLost() OVERRIDE {
+  bool CanFocus() override { return true; }
+  void OnCaptureLost() override {
     if (drag_drop_controller_->IsDragDropInProgress())
       drag_drop_controller_->DragCancel();
   }
-  virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
-  }
-  virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {}
-  virtual void OnWindowDestroying() OVERRIDE {}
-  virtual void OnWindowDestroyed() OVERRIDE {}
-  virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {}
-  virtual bool HasHitTestMask() const OVERRIDE {
-    return true;
-  }
-  virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {
+  void OnPaint(gfx::Canvas* canvas) override {}
+  void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
+  void OnWindowDestroying(aura::Window* window) override {}
+  void OnWindowDestroyed(aura::Window* window) override {}
+  void OnWindowTargetVisibilityChanged(bool visible) override {}
+  bool HasHitTestMask() const override { return true; }
+  void GetHitTestMask(gfx::Path* mask) const override {
     DCHECK(mask->isEmpty());
   }
-  virtual void DidRecreateLayer(ui::Layer* old_layer,
-                                ui::Layer* new_layer) OVERRIDE {}
 
  private:
   DragDropController* drag_drop_controller_;
@@ -203,7 +190,7 @@ int DragDropController::StartDragAndDrop(
     drag_image_vertical_offset = kTouchDragImageVerticalOffset;
   }
   gfx::Point start_location = root_location;
-  ash::wm::ConvertPointToScreen(root_window, &start_location);
+  ::wm::ConvertPointToScreen(root_window, &start_location);
   drag_image_final_bounds_for_cancel_animation_ = gfx::Rect(
       start_location - provider->GetDragImageOffset(),
       provider->GetDragImage().size());
@@ -228,7 +215,7 @@ int DragDropController::StartDragAndDrop(
     cancel_animation_->End();
 
   if (should_block_during_drag_drop_) {
-    base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher());
+    base::RunLoop run_loop;
     quit_closure_ = run_loop.QuitClosure();
     base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
     base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
@@ -249,11 +236,12 @@ int DragDropController::StartDragAndDrop(
 
 void DragDropController::DragUpdate(aura::Window* target,
                                     const ui::LocatedEvent& event) {
-  aura::client::DragDropDelegate* delegate = NULL;
   int op = ui::DragDropTypes::DRAG_NONE;
   if (target != drag_window_) {
     if (drag_window_) {
-      if ((delegate = aura::client::GetDragDropDelegate(drag_window_)))
+      aura::client::DragDropDelegate* delegate =
+          aura::client::GetDragDropDelegate(drag_window_);
+      if (delegate)
         delegate->OnDragExited();
       if (drag_window_ != drag_source_window_)
         drag_window_->RemoveObserver(this);
@@ -262,7 +250,9 @@ void DragDropController::DragUpdate(aura::Window* target,
     // We are already an observer of |drag_source_window_| so no need to add.
     if (drag_window_ != drag_source_window_)
       drag_window_->AddObserver(this);
-    if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) {
+    aura::client::DragDropDelegate* delegate =
+        aura::client::GetDragDropDelegate(drag_window_);
+    if (delegate) {
       ui::DropTargetEvent e(*drag_data_,
                             event.location(),
                             event.root_location(),
@@ -271,7 +261,9 @@ void DragDropController::DragUpdate(aura::Window* target,
       delegate->OnDragEntered(e);
     }
   } else {
-    if ((delegate = aura::client::GetDragDropDelegate(drag_window_))) {
+    aura::client::DragDropDelegate* delegate =
+        aura::client::GetDragDropDelegate(drag_window_);
+    if (delegate) {
       ui::DropTargetEvent e(*drag_data_,
                             event.location(),
                             event.root_location(),
@@ -292,8 +284,8 @@ void DragDropController::DragUpdate(aura::Window* target,
   DCHECK(drag_image_.get());
   if (drag_image_->visible()) {
     gfx::Point root_location_in_screen = event.root_location();
-    ash::wm::ConvertPointToScreen(target->GetRootWindow(),
-                                  &root_location_in_screen);
+    ::wm::ConvertPointToScreen(target->GetRootWindow(),
+                               &root_location_in_screen);
     drag_image_->SetScreenPosition(
         root_location_in_screen - drag_image_offset_);
     drag_image_->SetTouchDragOperation(op);
@@ -303,7 +295,6 @@ void DragDropController::DragUpdate(aura::Window* target,
 void DragDropController::Drop(aura::Window* target,
                               const ui::LocatedEvent& event) {
   ash::Shell::GetInstance()->cursor_manager()->SetCursor(ui::kCursorPointer);
-  aura::client::DragDropDelegate* delegate = NULL;
 
   // We must guarantee that a target gets a OnDragEntered before Drop. WebKit
   // depends on not getting a Drop without DragEnter. This behavior is
@@ -312,7 +303,9 @@ void DragDropController::Drop(aura::Window* target,
     DragUpdate(target, event);
   DCHECK(target == drag_window_);
 
-  if ((delegate = aura::client::GetDragDropDelegate(target))) {
+  aura::client::DragDropDelegate* delegate =
+      aura::client::GetDragDropDelegate(target);
+  if (delegate) {
     ui::DropTargetEvent e(
         *drag_data_, event.location(), event.root_location(), drag_operation_);
     e.set_flags(event.flags());
@@ -557,10 +550,9 @@ void DragDropController::Cleanup() {
     drag_window_->RemoveObserver(this);
   drag_window_ = NULL;
   drag_data_ = NULL;
-  // Cleanup can be called again while deleting DragDropTracker, so use Pass
-  // instead of reset to avoid double free.
-  drag_drop_tracker_.Pass();
+  // Cleanup can be called again while deleting DragDropTracker, so delete
+  // the pointer with a local variable to avoid double free.
+  scoped_ptr<ash::DragDropTracker> holder = drag_drop_tracker_.Pass();
 }
 
-}  // namespace internal
 }  // namespace ash