summaryrefslogtreecommitdiffstats
path: root/views/widget
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-11 14:04:00 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-11 14:04:00 +0000
commitc476652ae760b3dd16d26f4375d9f28fee42238d (patch)
tree46882f8a7b13e61052918b6dfbaac827cd515187 /views/widget
parent73704c8719ee45cbf0a92c16d2450952799dccac (diff)
downloadchromium_src-c476652ae760b3dd16d26f4375d9f28fee42238d.zip
chromium_src-c476652ae760b3dd16d26f4375d9f28fee42238d.tar.gz
chromium_src-c476652ae760b3dd16d26f4375d9f28fee42238d.tar.bz2
Refactors RootViewDropTarget into a platform independent part,
DropHelper, and the platform specific part DropTarget. I've also moved ownership/creation of the DropTarget to Widget. This makes it alot easier for the windows side, in which DropTarget must implement IDataObject. BUG=none TEST=none Review URL: http://codereview.chromium.org/165155 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23020 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r--views/widget/drop_helper.cc135
-rw-r--r--views/widget/drop_helper.h104
-rw-r--r--views/widget/drop_target_win.cc59
-rw-r--r--views/widget/drop_target_win.h53
-rw-r--r--views/widget/root_view.cc35
-rw-r--r--views/widget/root_view.h14
-rw-r--r--views/widget/root_view_drop_target.cc118
-rw-r--r--views/widget/root_view_drop_target.h71
-rw-r--r--views/widget/root_view_win.cc1
-rw-r--r--views/widget/widget.h4
-rw-r--r--views/widget/widget_gtk.cc6
-rw-r--r--views/widget/widget_gtk.h2
-rw-r--r--views/widget/widget_win.cc14
-rw-r--r--views/widget/widget_win.h5
14 files changed, 382 insertions, 239 deletions
diff --git a/views/widget/drop_helper.cc b/views/widget/drop_helper.cc
new file mode 100644
index 0000000..35dcbd0
--- /dev/null
+++ b/views/widget/drop_helper.cc
@@ -0,0 +1,135 @@
+// Copyright (c) 2006-2008 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 "views/widget/drop_helper.h"
+
+#include "app/drag_drop_types.h"
+#include "views/view.h"
+#include "views/widget/root_view.h"
+
+namespace views {
+
+DropHelper::DropHelper(RootView* root_view)
+ : root_view_(root_view),
+ target_view_(NULL),
+ deepest_view_(NULL) {
+}
+
+DropHelper::~DropHelper() {
+}
+
+void DropHelper::ResetTargetViewIfEquals(View* view) {
+ if (target_view_ == view)
+ target_view_ = NULL;
+ if (deepest_view_ == view)
+ deepest_view_ = NULL;
+}
+
+int DropHelper::OnDragOver(const OSExchangeData& data,
+ const gfx::Point& root_view_location,
+ int drag_operation) {
+ View* view = CalculateTargetViewImpl(root_view_location, data, true,
+ &deepest_view_);
+
+ if (view != target_view_) {
+ // Target changed notify old drag exited, then new drag entered.
+ NotifyDragExit();
+ target_view_ = view;
+ NotifyDragEntered(data, root_view_location, drag_operation);
+ }
+
+ return NotifyDragOver(data, root_view_location, drag_operation);
+}
+
+void DropHelper::OnDragExit() {
+ NotifyDragExit();
+ deepest_view_ = target_view_ = NULL;
+}
+
+int DropHelper::OnDrop(const OSExchangeData& data,
+ const gfx::Point& root_view_location,
+ int drag_operation) {
+ View* drop_view = target_view_;
+ deepest_view_ = target_view_ = NULL;
+ if (!drop_view)
+ return DragDropTypes::DRAG_NONE;
+
+ if (drag_operation == DragDropTypes::DRAG_NONE) {
+ drop_view->OnDragExited();
+ return DragDropTypes::DRAG_NONE;
+ }
+
+ gfx::Point view_location(root_view_location);
+ View::ConvertPointToView(NULL, drop_view, &view_location);
+ DropTargetEvent drop_event(data, view_location.x(), view_location.y(),
+ drag_operation);
+ return drop_view->OnPerformDrop(drop_event);
+}
+
+View* DropHelper::CalculateTargetView(
+ const gfx::Point& root_view_location,
+ const OSExchangeData& data,
+ bool check_can_drop) {
+ return CalculateTargetViewImpl(root_view_location, data, check_can_drop,
+ NULL);
+}
+
+View* DropHelper::CalculateTargetViewImpl(
+ const gfx::Point& root_view_location,
+ const OSExchangeData& data,
+ bool check_can_drop,
+ View** deepest_view) {
+ View* view = root_view_->GetViewForPoint(root_view_location);
+ if (view == deepest_view_) {
+ // The view the mouse is over hasn't changed; reuse the target.
+ return target_view_;
+ }
+ if (deepest_view)
+ *deepest_view = view;
+ // View under mouse changed, which means a new view may want the drop.
+ // Walk the tree, stopping at target_view_ as we know it'll accept the
+ // drop.
+ while (view && view != target_view_ &&
+ (!view->IsEnabled() || !view->CanDrop(data))) {
+ view = view->GetParent();
+ }
+ return view;
+}
+
+void DropHelper::NotifyDragEntered(const OSExchangeData& data,
+ const gfx::Point& root_view_location,
+ int drag_operation) {
+ if (!target_view_)
+ return;
+
+ gfx::Point target_view_location(root_view_location);
+ View::ConvertPointToView(root_view_, target_view_, &target_view_location);
+ DropTargetEvent enter_event(data,
+ target_view_location.x(),
+ target_view_location.y(),
+ drag_operation);
+ target_view_->OnDragEntered(enter_event);
+}
+
+int DropHelper::NotifyDragOver(const OSExchangeData& data,
+ const gfx::Point& root_view_location,
+ int drag_operation) {
+ if (!target_view_)
+ return DragDropTypes::DRAG_NONE;
+
+ gfx::Point target_view_location(root_view_location);
+ View::ConvertPointToView(root_view_, target_view_, &target_view_location);
+ DropTargetEvent enter_event(data,
+ target_view_location.x(),
+ target_view_location.y(),
+ drag_operation);
+ return target_view_->OnDragUpdated(enter_event);
+}
+
+void DropHelper::NotifyDragExit() {
+ if (target_view_)
+ target_view_->OnDragExited();
+}
+
+} // namespace views
diff --git a/views/widget/drop_helper.h b/views/widget/drop_helper.h
new file mode 100644
index 0000000..63bfa27
--- /dev/null
+++ b/views/widget/drop_helper.h
@@ -0,0 +1,104 @@
+// Copyright (c) 2006-2008 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.
+
+#ifndef VIEWS_WIDGET_DROP_HELPER_H_
+#define VIEWS_WIDGET_DROP_HELPER_H_
+
+#include "base/basictypes.h"
+
+class OSExchangeData;
+
+namespace gfx {
+class Point;
+} // namespace gfx
+
+namespace views {
+
+class RootView;
+class View;
+
+// DropHelper provides support for managing the view a drop is going to occur
+// at during dnd as well as sending the view the appropriate dnd methods.
+// DropHelper is intended to be used by a class that interacts with the system
+// drag and drop. The system class invokes OnDragOver as the mouse moves,
+// then either OnDragExit or OnDrop when the drop is done.
+class DropHelper {
+ public:
+ explicit DropHelper(RootView* root_view);
+ ~DropHelper();
+
+ // Current view drop events are targeted at, may be NULL.
+ View* target_view() const { return target_view_; }
+
+ // Returns the RootView the DropHelper was created with.
+ RootView* root_view() const { return root_view_; }
+
+ // Resets the target_view_ to NULL if it equals view.
+ //
+ // This is invoked when a View is removed from the RootView to make sure
+ // we don't target a view that was removed during dnd.
+ void ResetTargetViewIfEquals(View* view);
+
+ // Invoked when a the mouse is dragged over the root view during a drag and
+ // drop operation. This method returns a bitmask of the types in DragDropTypes
+ // for the target view. If no view wants the drop, DRAG_NONE is returned.
+ int OnDragOver(const OSExchangeData& data,
+ const gfx::Point& root_view_location,
+ int drag_operation);
+
+ // Invoked when a the mouse is dragged out of the root view during a drag and
+ // drop operation.
+ void OnDragExit();
+
+ // Invoked when the user drops data on the root view during a drag and drop
+ // operation. See OnDragOver for details on return type.
+ //
+ // NOTE: implementations must invoke OnDragOver before invoking this,
+ // supplying the return value from OnDragOver as the drag_operation.
+ int OnDrop(const OSExchangeData& data,
+ const gfx::Point& root_view_location,
+ int drag_operation);
+
+ // Calculates the target view for a drop given the specified location in
+ // the coordinate system of the rootview. This tries to avoid continually
+ // querying CanDrop by returning target_view_ if the mouse is still over
+ // target_view_.
+ View* CalculateTargetView(const gfx::Point& root_view_location,
+ const OSExchangeData& data,
+ bool check_can_drop);
+
+ private:
+ // Implementation of CalculateTargetView. If |deepest_view| is non-NULL it is
+ // set to the deepest descendant of the RootView that contains the point
+ // |root_view_location|
+ View* CalculateTargetViewImpl(const gfx::Point& root_view_location,
+ const OSExchangeData& data,
+ bool check_can_drop,
+ View** deepest_view);
+
+ // Methods to send the appropriate drop notification to the targeted view.
+ // These do nothing if the target view is NULL.
+ void NotifyDragEntered(const OSExchangeData& data,
+ const gfx::Point& root_view_location,
+ int drag_operation);
+ int NotifyDragOver(const OSExchangeData& data,
+ const gfx::Point& root_view_location,
+ int drag_operation);
+ void NotifyDragExit();
+
+ // RootView we were created for.
+ RootView* root_view_;
+
+ // View we're targeting events at.
+ View* target_view_;
+
+ // The deepest view under the current drop coordinate.
+ View* deepest_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(DropHelper);
+};
+
+} // namespace views
+
+#endif // VIEWS_WIDGET_DROP_HELPER_H_
diff --git a/views/widget/drop_target_win.cc b/views/widget/drop_target_win.cc
new file mode 100644
index 0000000..69800ca
--- /dev/null
+++ b/views/widget/drop_target_win.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2009 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 "views/widget/drop_target_win.h"
+
+#include "app/drag_drop_types.h"
+#include "app/os_exchange_data.h"
+#include "base/gfx/point.h"
+#include "views/widget/root_view.h"
+#include "views/widget/widget.h"
+
+namespace views {
+
+DropTargetWin::DropTargetWin(RootView* root_view)
+ : BaseDropTarget(root_view->GetWidget()->GetNativeView()),
+ helper_(root_view) {
+}
+
+DropTargetWin::~DropTargetWin() {
+}
+
+void DropTargetWin::ResetTargetViewIfEquals(View* view) {
+ helper_.ResetTargetViewIfEquals(view);
+}
+
+DWORD DropTargetWin::OnDragOver(IDataObject* data_object,
+ DWORD key_state,
+ POINT cursor_position,
+ DWORD effect) {
+ gfx::Point root_view_location(cursor_position.x, cursor_position.y);
+ View::ConvertPointToView(NULL, helper_.root_view(), &root_view_location);
+ int drop_operation =
+ helper_.OnDragOver(OSExchangeData(data_object),
+ root_view_location,
+ DragDropTypes::DropEffectToDragOperation(effect));
+ return DragDropTypes::DragOperationToDropEffect(drop_operation);
+}
+
+void DropTargetWin::OnDragLeave(IDataObject* data_object) {
+ helper_.OnDragExit();
+}
+
+DWORD DropTargetWin::OnDrop(IDataObject* data_object,
+ DWORD key_state,
+ POINT cursor_position,
+ DWORD effect) {
+ gfx::Point root_view_location(cursor_position.x, cursor_position.y);
+ View::ConvertPointToView(NULL, helper_.root_view(), &root_view_location);
+
+ OSExchangeData data(data_object);
+ int drop_operation = DragDropTypes::DropEffectToDragOperation(effect);
+ drop_operation = helper_.OnDragOver(data, root_view_location,
+ drop_operation);
+ drop_operation = helper_.OnDrop(data, root_view_location, drop_operation);
+ return DragDropTypes::DragOperationToDropEffect(drop_operation);
+}
+
+} // namespace views
diff --git a/views/widget/drop_target_win.h b/views/widget/drop_target_win.h
new file mode 100644
index 0000000..d771c07
--- /dev/null
+++ b/views/widget/drop_target_win.h
@@ -0,0 +1,53 @@
+// Copyright (c) 2009 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.
+
+#ifndef VIEWS_WIDGET_DROP_TARGET_WIN_H_
+#define VIEWS_WIDGET_DROP_TARGET_WIN_H_
+
+#include "base/base_drop_target.h"
+#include "views/widget/drop_helper.h"
+
+namespace views {
+
+class RootView;
+class View;
+
+// DropTargetWin takes care of managing drag and drop for WidgetWin. It
+// converts Windows OLE drop messages into Views drop messages.
+//
+// DropTargetWin uses DropHelper to manage the appropriate view to target
+// drop messages at.
+class DropTargetWin : public BaseDropTarget {
+ public:
+ explicit DropTargetWin(RootView* root_view);
+ virtual ~DropTargetWin();
+
+ // If a drag and drop is underway and view is the current drop target, the
+ // drop target is set to null.
+ // This is invoked when a View is removed from the RootView to make sure
+ // we don't target a view that was removed during dnd.
+ void ResetTargetViewIfEquals(View* view);
+
+ protected:
+ virtual DWORD OnDragOver(IDataObject* data_object,
+ DWORD key_state,
+ POINT cursor_position,
+ DWORD effect);
+
+ virtual void OnDragLeave(IDataObject* data_object);
+
+ virtual DWORD OnDrop(IDataObject* data_object,
+ DWORD key_state,
+ POINT cursor_position,
+ DWORD effect);
+
+ private:
+ views::DropHelper helper_;
+
+ DISALLOW_COPY_AND_ASSIGN(DropTargetWin);
+};
+
+} // namespace views
+
+#endif // VIEWS_WIDGET_DROP_TARGET_WIN_H_
diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc
index 145de92..526e6d1 100644
--- a/views/widget/root_view.cc
+++ b/views/widget/root_view.cc
@@ -15,11 +15,6 @@
#include "views/widget/widget.h"
#include "views/window/window.h"
-#if defined(OS_WIN)
-#include "base/base_drag_source.h"
-#include "views/widget/root_view_drop_target.h"
-#endif
-
namespace views {
/////////////////////////////////////////////////////////////////////////////
@@ -257,12 +252,8 @@ void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
mouse_pressed_handler_ = NULL;
}
-#if defined(OS_WIN)
- if (drop_target_.get())
- drop_target_->ResetTargetViewIfEquals(child);
-#else
- NOTIMPLEMENTED();
-#endif
+ if (widget_)
+ widget_->ViewHierarchyChanged(is_add, parent, child);
if (mouse_move_handler_ == child) {
mouse_move_handler_ = NULL;
@@ -507,28 +498,6 @@ void RootView::SetMouseHandler(View *new_mh) {
mouse_pressed_handler_ = new_mh;
}
-void RootView::OnWidgetCreated() {
-#if defined(OS_WIN)
- DCHECK(!drop_target_.get());
- drop_target_ = new RootViewDropTarget(this);
-#else
- // TODO(port): Port RootViewDropTarget and this goes away.
- NOTIMPLEMENTED();
-#endif
-}
-
-void RootView::OnWidgetDestroyed() {
-#if defined(OS_WIN)
- if (drop_target_.get()) {
- RevokeDragDrop(GetWidget()->GetNativeView());
- drop_target_ = NULL;
- }
-#else
- // TODO(port): Port RootViewDropTarget and this goes away.
- NOTIMPLEMENTED();
-#endif
-}
-
void RootView::ProcessMouseDragCanceled() {
if (mouse_pressed_handler_) {
// Synthesize a release event.
diff --git a/views/widget/root_view.h b/views/widget/root_view.h
index 8e8d467..b3c43d8 100644
--- a/views/widget/root_view.h
+++ b/views/widget/root_view.h
@@ -18,7 +18,6 @@ typedef struct _GdkEventExpose GdkEventExpose;
namespace views {
class PaintTask;
-class RootViewDropTarget;
class Widget;
/////////////////////////////////////////////////////////////////////////////
@@ -92,14 +91,6 @@ class RootView : public View,
virtual void OnMouseMoved(const MouseEvent& e);
virtual void SetMouseHandler(View* new_mouse_handler);
- // Invoked when the Widget has been fully initialized.
- // At the time the constructor is invoked the Widget may not be completely
- // initialized, when this method is invoked, it is.
- void OnWidgetCreated();
-
- // Invoked prior to the Widget being destroyed.
- void OnWidgetDestroyed();
-
// Invoked By the Widget if the mouse drag is interrupted by
// the system. Invokes OnMouseReleased with a value of true for canceled.
void ProcessMouseDragCanceled();
@@ -326,11 +317,6 @@ class RootView : public View,
// wrapped inside native components, and is used for the focus traversal.
View* focus_traversable_parent_view_;
-#if defined(OS_WIN)
- // Handles dnd for us.
- scoped_refptr<RootViewDropTarget> drop_target_;
-#endif
-
// Storage of strings needed for accessibility.
std::wstring accessible_name_;
diff --git a/views/widget/root_view_drop_target.cc b/views/widget/root_view_drop_target.cc
deleted file mode 100644
index 9c1f087..0000000
--- a/views/widget/root_view_drop_target.cc
+++ /dev/null
@@ -1,118 +0,0 @@
-// Copyright (c) 2006-2008 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 "views/widget/root_view_drop_target.h"
-
-#include "app/drag_drop_types.h"
-#include "base/gfx/point.h"
-#include "views/widget/root_view.h"
-#include "views/widget/widget.h"
-
-namespace views {
-
-RootViewDropTarget::RootViewDropTarget(RootView* root_view)
- : BaseDropTarget(root_view->GetWidget()->GetNativeView()),
- root_view_(root_view),
- target_view_(NULL),
- deepest_view_(NULL) {
-}
-
-RootViewDropTarget::~RootViewDropTarget() {
-}
-
-void RootViewDropTarget::ResetTargetViewIfEquals(View* view) {
- if (target_view_ == view)
- target_view_ = NULL;
- if (deepest_view_ == view)
- deepest_view_ = NULL;
-}
-
-DWORD RootViewDropTarget::OnDragOver(IDataObject* data_object,
- DWORD key_state,
- POINT cursor_position,
- DWORD effect) {
- const OSExchangeData data(data_object);
- gfx::Point root_view_location(cursor_position.x, cursor_position.y);
- View::ConvertPointToView(NULL, root_view_, &root_view_location);
- View* view = CalculateTargetView(root_view_location, data);
-
- if (view != target_view_) {
- // Target changed notify old drag exited, then new drag entered.
- if (target_view_)
- target_view_->OnDragExited();
- target_view_ = view;
- if (target_view_) {
- gfx::Point target_view_location(root_view_location);
- View::ConvertPointToView(root_view_, target_view_, &target_view_location);
- DropTargetEvent enter_event(data,
- target_view_location.x(),
- target_view_location.y(),
- DragDropTypes::DropEffectToDragOperation(effect));
- target_view_->OnDragEntered(enter_event);
- }
- }
-
- if (target_view_) {
- gfx::Point target_view_location(root_view_location);
- View::ConvertPointToView(root_view_, target_view_, &target_view_location);
- DropTargetEvent enter_event(data,
- target_view_location.x(),
- target_view_location.y(),
- DragDropTypes::DropEffectToDragOperation(effect));
- int result_operation = target_view_->OnDragUpdated(enter_event);
- return DragDropTypes::DragOperationToDropEffect(result_operation);
- } else {
- return DROPEFFECT_NONE;
- }
-}
-
-void RootViewDropTarget::OnDragLeave(IDataObject* data_object) {
- if (target_view_)
- target_view_->OnDragExited();
- deepest_view_ = target_view_ = NULL;
-}
-
-DWORD RootViewDropTarget::OnDrop(IDataObject* data_object,
- DWORD key_state,
- POINT cursor_position,
- DWORD effect) {
- const OSExchangeData data(data_object);
- DWORD drop_effect = OnDragOver(data_object, key_state, cursor_position,
- effect);
- View* drop_view = target_view_;
- deepest_view_ = target_view_ = NULL;
- if (drop_effect != DROPEFFECT_NONE) {
- gfx::Point view_location(cursor_position.x, cursor_position.y);
- View::ConvertPointToView(NULL, drop_view, &view_location);
- DropTargetEvent drop_event(data, view_location.x(), view_location.y(),
- DragDropTypes::DropEffectToDragOperation(effect));
- return DragDropTypes::DragOperationToDropEffect(
- drop_view->OnPerformDrop(drop_event));
- } else {
- if (drop_view)
- drop_view->OnDragExited();
- return DROPEFFECT_NONE;
- }
-}
-
-View* RootViewDropTarget::CalculateTargetView(
- const gfx::Point& root_view_location,
- const OSExchangeData& data) {
- View* view = root_view_->GetViewForPoint(root_view_location);
- if (view == deepest_view_) {
- // The view the mouse is over hasn't changed; reuse the target.
- return target_view_;
- }
- // View under mouse changed, which means a new view may want the drop.
- // Walk the tree, stopping at target_view_ as we know it'll accept the
- // drop.
- deepest_view_ = view;
- while (view && view != target_view_ &&
- (!view->IsEnabled() || !view->CanDrop(data))) {
- view = view->GetParent();
- }
- return view;
-}
-
-} // namespace views
diff --git a/views/widget/root_view_drop_target.h b/views/widget/root_view_drop_target.h
deleted file mode 100644
index 32cb14b..0000000
--- a/views/widget/root_view_drop_target.h
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (c) 2006-2008 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.
-
-#ifndef VIEWS_WIDGET_ROOT_VIEW_DROP_TARGET_H_
-#define VIEWS_WIDGET_ROOT_VIEW_DROP_TARGET_H_
-
-#include "app/os_exchange_data.h"
-#include "base/base_drop_target.h"
-
-namespace gfx {
-class Point;
-}
-
-namespace views {
-
-class RootView;
-class View;
-
-// RootViewDropTarget takes care of managing drag and drop for the RootView and
-// converts Windows OLE drop messages into Views drop messages.
-//
-// RootViewDropTarget is responsible for determining the appropriate View to
-// use during a drag and drop session, and forwarding events to it.
-class RootViewDropTarget : public BaseDropTarget {
- public:
- explicit RootViewDropTarget(RootView* root_view);
- virtual ~RootViewDropTarget();
-
- // If a drag and drop is underway and view is the current drop target, the
- // drop target is set to null.
- // This is invoked when a View is removed from the RootView to make sure
- // we don't target a view that was removed during dnd.
- void ResetTargetViewIfEquals(View* view);
-
- protected:
- virtual DWORD OnDragOver(IDataObject* data_object,
- DWORD key_state,
- POINT cursor_position,
- DWORD effect);
-
- virtual void OnDragLeave(IDataObject* data_object);
-
- virtual DWORD OnDrop(IDataObject* data_object,
- DWORD key_state,
- POINT cursor_position,
- DWORD effect);
-
- private:
- // Calculates the target view for a drop given the specified location in
- // the coordinate system of the rootview. This tries to avoid continually
- // querying CanDrop by returning target_view_ if the mouse is still over
- // target_view_.
- View* CalculateTargetView(const gfx::Point& root_view_location,
- const OSExchangeData& data);
-
- // RootView we were created for.
- RootView* root_view_;
-
- // View we're targeting events at.
- View* target_view_;
-
- // The deepest view under the current drop coordinate.
- View* deepest_view_;
-
- DISALLOW_EVIL_CONSTRUCTORS(RootViewDropTarget);
-};
-
-} // namespace views
-
-#endif // VIEWS_WIDGET_ROOT_VIEW_DROP_TARGET_H_
diff --git a/views/widget/root_view_win.cc b/views/widget/root_view_win.cc
index eddbb6e..fedb40d 100644
--- a/views/widget/root_view_win.cc
+++ b/views/widget/root_view_win.cc
@@ -8,7 +8,6 @@
#include "app/gfx/canvas_paint.h"
#include "base/base_drag_source.h"
#include "base/logging.h"
-#include "views/widget/root_view_drop_target.h"
namespace views {
diff --git a/views/widget/widget.h b/views/widget/widget.h
index f9e961d..829a9d0f 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -143,6 +143,10 @@ class Widget {
// Returns the FocusManager for this widget.
// Note that all widgets in a widget hierarchy share the same focus manager.
virtual FocusManager* GetFocusManager() { return NULL; }
+
+ // Forwarded from the RootView so that the widget can do any cleanup.
+ virtual void ViewHierarchyChanged(bool is_add, View *parent,
+ View *child) = 0;
};
} // namespace views
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index 76abe93..82af746 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -388,6 +388,12 @@ FocusManager* WidgetGtk::GetFocusManager() {
return focus_manager_.get();
}
+void WidgetGtk::ViewHierarchyChanged(bool is_add, View *parent,
+ View *child) {
+ // Needs dnd support (see WidgetWin::ViewHierarchyChanged).
+ NOTIMPLEMENTED();
+}
+
////////////////////////////////////////////////////////////////////////////////
// WidgetGtk, MessageLoopForUI::Observer implementation:
diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h
index 42ea283..b3308c4 100644
--- a/views/widget/widget_gtk.h
+++ b/views/widget/widget_gtk.h
@@ -96,6 +96,8 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer {
virtual const Window* GetWindow() const;
virtual ThemeProvider* GetThemeProvider() const;
virtual FocusManager* GetFocusManager();
+ virtual void ViewHierarchyChanged(bool is_add, View *parent,
+ View *child);
// MessageLoopForUI::Observer.
virtual void WillProcessEvent(GdkEvent* event);
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index 6a7b787..f431fc7 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -17,6 +17,7 @@
#include "views/views_delegate.h"
#include "views/widget/aero_tooltip_manager.h"
#include "views/widget/default_theme_provider.h"
+#include "views/widget/drop_target_win.h"
#include "views/widget/root_view.h"
#include "views/window/window_win.h"
@@ -78,7 +79,7 @@ void WidgetWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) {
SetWindowSupportsRerouteMouseWheel(GetNativeView());
- root_view_->OnWidgetCreated();
+ drop_target_ = new DropTargetWin(root_view_.get());
if ((window_style() & WS_CHILD) == 0) {
// Top-level widgets get a FocusManager.
@@ -320,6 +321,12 @@ FocusManager* WidgetWin::GetFocusManager() {
return NULL;
}
+void WidgetWin::ViewHierarchyChanged(bool is_add, View *parent,
+ View *child) {
+ if (drop_target_.get())
+ drop_target_->ResetTargetViewIfEquals(child);
+}
+
void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) {
if (use_layered_buffer_ == use_layered_buffer)
return;
@@ -432,7 +439,10 @@ void WidgetWin::OnClose() {
}
void WidgetWin::OnDestroy() {
- root_view_->OnWidgetDestroyed();
+ if (drop_target_.get()) {
+ RevokeDragDrop(GetNativeView());
+ drop_target_ = NULL;
+ }
RemoveProp(GetNativeView(), kRootViewWindowProperty);
}
diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h
index 49be8ea..3fbcc93 100644
--- a/views/widget/widget_win.h
+++ b/views/widget/widget_win.h
@@ -24,6 +24,7 @@ class Rect;
namespace views {
+class DropTargetWin;
class RootView;
class TooltipManagerWin;
class DefaultThemeProvider;
@@ -201,6 +202,8 @@ class WidgetWin : public base::WindowImpl,
virtual Window* GetWindow();
virtual const Window* GetWindow() const;
virtual FocusManager* GetFocusManager();
+ virtual void ViewHierarchyChanged(bool is_add, View *parent,
+ View *child);
// Overridden from MessageLoop::Observer:
void WillProcessMessage(const MSG& msg);
@@ -485,6 +488,8 @@ class WidgetWin : public base::WindowImpl,
// must be destroyed AFTER root_view_.
scoped_ptr<TooltipManagerWin> tooltip_manager_;
+ scoped_refptr<DropTargetWin> drop_target_;
+
// The focus manager keeping track of focus for this Widget and any of its
// children. NULL for non top-level widgets.
// WARNING: RootView's destructor calls into the FocusManager. As such, this