Commit 166d7ffb authored by jam@chromium.org's avatar jam@chromium.org

Get drag and drop working on Win Ash.

BUG=154081
Review URL: https://codereview.chromium.org/11787005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175494 0039d316-1c4b-4281-b951-d872f2087c98
parent e9e27e4a
...@@ -623,8 +623,6 @@ ...@@ -623,8 +623,6 @@
}], }],
['OS=="win"', { ['OS=="win"', {
'sources/': [ 'sources/': [
# TODO(win_ash): implement DragDropController::StartDragAndDrop
['exclude', 'drag_drop/drag_drop_controller_unittest.cc'],
# TODO(zork): fix this test to build on Windows. See: crosbug.com/26906 # TODO(zork): fix this test to build on Windows. See: crosbug.com/26906
['exclude', 'focus_cycler_unittest.cc'], ['exclude', 'focus_cycler_unittest.cc'],
# All tests for multiple displays: not supported on Windows Ash. # All tests for multiple displays: not supported on Windows Ash.
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/animation/linear_animation.h" #include "ui/base/animation/linear_animation.h"
#include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data_provider_aura.h" #include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/events/event.h" #include "ui/base/events/event.h"
#include "ui/base/events/event_utils.h" #include "ui/base/events/event_utils.h"
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
...@@ -112,22 +112,10 @@ int DragDropController::StartDragAndDrop( ...@@ -112,22 +112,10 @@ int DragDropController::StartDragAndDrop(
if (IsDragDropInProgress()) if (IsDragDropInProgress())
return 0; return 0;
#if defined(OS_WIN) const ui::OSExchangeData::Provider* provider = &data.provider();
// TODO(win_ash): need to figure out how this will work in Metro, since
// OSExchangeDataProviderAura isn't used in Windows builds. Two alternatives:
// 1) Use OSExchangeDataProviderAura in Ash and OSExchangeDataProviderWin
// elsewhere. This will complicate creating an ui::OSExchangeData to pass
// in more context.
// 2) Add methods to get the image and offset in the base interface of these
// implementations to get to this data here.
NOTIMPLEMENTED();
return 0;
#else
const ui::OSExchangeDataProviderAura& provider =
static_cast<const ui::OSExchangeDataProviderAura&>(data.provider());
// We do not support touch drag/drop without a drag image. // We do not support touch drag/drop without a drag image.
if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH && if (source == ui::DragDropTypes::DRAG_EVENT_SOURCE_TOUCH &&
provider.drag_image().size().IsEmpty()) provider->GetDragImage().size().IsEmpty())
return 0; return 0;
current_drag_event_source_ = source; current_drag_event_source_ = source;
...@@ -162,11 +150,11 @@ int DragDropController::StartDragAndDrop( ...@@ -162,11 +150,11 @@ int DragDropController::StartDragAndDrop(
gfx::Point start_location = root_location; gfx::Point start_location = root_location;
ash::wm::ConvertPointToScreen(root_window, &start_location); ash::wm::ConvertPointToScreen(root_window, &start_location);
drag_image_final_bounds_for_cancel_animation_ = gfx::Rect( drag_image_final_bounds_for_cancel_animation_ = gfx::Rect(
start_location - provider.drag_image_offset(), start_location - provider->GetDragImageOffset(),
provider.drag_image().size()); provider->GetDragImage().size());
drag_image_.reset(new DragImageView); drag_image_.reset(new DragImageView);
drag_image_->SetImage(provider.drag_image()); drag_image_->SetImage(provider->GetDragImage());
drag_image_offset_ = provider.drag_image_offset(); drag_image_offset_ = provider->GetDragImageOffset();
gfx::Rect drag_image_bounds(start_location, drag_image_->GetPreferredSize()); gfx::Rect drag_image_bounds(start_location, drag_image_->GetPreferredSize());
drag_image_bounds = AdjustDragImageBoundsForScaleAndOffset(drag_image_bounds, drag_image_bounds = AdjustDragImageBoundsForScaleAndOffset(drag_image_bounds,
drag_image_vertical_offset, drag_image_scale, &drag_image_offset_); drag_image_vertical_offset, drag_image_scale, &drag_image_offset_);
...@@ -197,7 +185,6 @@ int DragDropController::StartDragAndDrop( ...@@ -197,7 +185,6 @@ int DragDropController::StartDragAndDrop(
drag_source_window_->RemoveObserver(this); drag_source_window_->RemoveObserver(this);
drag_source_window_ = NULL; drag_source_window_ = NULL;
} }
#endif
return drag_operation_; return drag_operation_;
} }
......
...@@ -233,8 +233,12 @@ class TestNativeWidgetAura : public views::NativeWidgetAura { ...@@ -233,8 +233,12 @@ class TestNativeWidgetAura : public views::NativeWidgetAura {
// TODO(sky): this is for debugging, remove when track down failure. // TODO(sky): this is for debugging, remove when track down failure.
void SetCheckIfCaptureLost(views::Widget* widget, bool value) { void SetCheckIfCaptureLost(views::Widget* widget, bool value) {
// On Windows, the DCHECK triggers when running on bot or locally through RDP,
// but not when logged in locally.
#if !defined(OS_WIN)
static_cast<TestNativeWidgetAura*>(widget->native_widget())-> static_cast<TestNativeWidgetAura*>(widget->native_widget())->
set_check_if_capture_lost(value); set_check_if_capture_lost(value);
#endif
} }
views::Widget* CreateNewWidget() { views::Widget* CreateNewWidget() {
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/dragdrop/os_exchange_data_provider_aura.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/size.h" #include "ui/gfx/size.h"
...@@ -18,10 +17,8 @@ void SetDragImageOnDataObject(const gfx::ImageSkia& image, ...@@ -18,10 +17,8 @@ void SetDragImageOnDataObject(const gfx::ImageSkia& image,
const gfx::Size& size, const gfx::Size& size,
const gfx::Vector2d& cursor_offset, const gfx::Vector2d& cursor_offset,
ui::OSExchangeData* data_object) { ui::OSExchangeData* data_object) {
ui::OSExchangeDataProviderAura& provider(
static_cast<ui::OSExchangeDataProviderAura&>(data_object->provider())); data_object->provider().SetDragImage(image, cursor_offset);
provider.set_drag_image(image);
provider.set_drag_image_offset(cursor_offset);
} }
} // namespace drag_utils } // namespace drag_utils
...@@ -68,6 +68,14 @@ void SetDragImageOnDataObject(const gfx::ImageSkia& image_skia, ...@@ -68,6 +68,14 @@ void SetDragImageOnDataObject(const gfx::ImageSkia& image_skia,
// Attach 'bitmap' to the data_object. // Attach 'bitmap' to the data_object.
SetDragImageOnDataObject(bitmap, size, cursor_offset, SetDragImageOnDataObject(bitmap, size, cursor_offset,
ui::OSExchangeDataProviderWin::GetIDataObject(*data_object)); ui::OSExchangeDataProviderWin::GetIDataObject(*data_object));
#if defined(USE_AURA)
// TODO: the above code is used in non-Ash, while below is used in Ash. If we
// could figure this context out then we wouldn't do unnecessary work. However
// as it stands getting this information in ui/base would be a layering
// violation.
data_object->provider().SetDragImage(image_skia, cursor_offset);
#endif
} }
} // namespace drag_utils } // namespace drag_utils
...@@ -29,6 +29,11 @@ ...@@ -29,6 +29,11 @@
class GURL; class GURL;
class Pickle; class Pickle;
namespace gfx {
class ImageSkia;
class Vector2d;
}
namespace ui { namespace ui {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -137,6 +142,13 @@ class UI_EXPORT OSExchangeData { ...@@ -137,6 +142,13 @@ class UI_EXPORT OSExchangeData {
virtual bool GetHtml(string16* html, GURL* base_url) const = 0; virtual bool GetHtml(string16* html, GURL* base_url) const = 0;
virtual bool HasHtml() const = 0; virtual bool HasHtml() const = 0;
#endif #endif
#if defined(USE_AURA)
virtual void SetDragImage(const gfx::ImageSkia& image,
const gfx::Vector2d& cursor_offset) = 0;
virtual const gfx::ImageSkia& GetDragImage() const = 0;
virtual const gfx::Vector2d& GetDragImageOffset() const = 0;
#endif
}; };
// Creates the platform specific Provider. // Creates the platform specific Provider.
......
...@@ -162,6 +162,21 @@ bool OSExchangeDataProviderAura::HasHtml() const { ...@@ -162,6 +162,21 @@ bool OSExchangeDataProviderAura::HasHtml() const {
return ((formats_ & OSExchangeData::HTML) != 0); return ((formats_ & OSExchangeData::HTML) != 0);
} }
void OSExchangeDataProviderAura::SetDragImage(
const gfx::ImageSkia& image,
const gfx::Vector2d& cursor_offset) {
drag_image_ = image;
drag_image_offset_ = cursor_offset;
}
const gfx::ImageSkia& OSExchangeDataProviderAura::GetDragImage() const {
return drag_image_;
}
const gfx::Vector2d& OSExchangeDataProviderAura::GetDragImageOffset() const {
return drag_image_offset_;
}
bool OSExchangeDataProviderAura::GetPlainTextURL(GURL* url) const { bool OSExchangeDataProviderAura::GetPlainTextURL(GURL* url) const {
if ((formats_ & OSExchangeData::STRING) == 0) if ((formats_ & OSExchangeData::STRING) == 0)
return false; return false;
......
...@@ -57,16 +57,10 @@ class UI_EXPORT OSExchangeDataProviderAura : public OSExchangeData::Provider { ...@@ -57,16 +57,10 @@ class UI_EXPORT OSExchangeDataProviderAura : public OSExchangeData::Provider {
virtual void SetHtml(const string16& html, const GURL& base_url) OVERRIDE; virtual void SetHtml(const string16& html, const GURL& base_url) OVERRIDE;
virtual bool GetHtml(string16* html, GURL* base_url) const OVERRIDE; virtual bool GetHtml(string16* html, GURL* base_url) const OVERRIDE;
virtual bool HasHtml() const OVERRIDE; virtual bool HasHtml() const OVERRIDE;
virtual void SetDragImage(const gfx::ImageSkia& image,
void set_drag_image(const gfx::ImageSkia& drag_image) { const gfx::Vector2d& cursor_offset) OVERRIDE;
drag_image_ = drag_image; virtual const gfx::ImageSkia& GetDragImage() const OVERRIDE;
} virtual const gfx::Vector2d& GetDragImageOffset() const OVERRIDE;
const gfx::ImageSkia& drag_image() const { return drag_image_; }
void set_drag_image_offset(const gfx::Vector2d& drag_image_offset) {
drag_image_offset_ = drag_image_offset;
}
const gfx::Vector2d& drag_image_offset() const { return drag_image_offset_; }
private: private:
typedef std::map<OSExchangeData::CustomFormat, Pickle> PickleData; typedef std::map<OSExchangeData::CustomFormat, Pickle> PickleData;
......
...@@ -499,6 +499,25 @@ void OSExchangeDataProviderWin::SetDownloadFileInfo( ...@@ -499,6 +499,25 @@ void OSExchangeDataProviderWin::SetDownloadFileInfo(
data_->contents_.push_back(info); data_->contents_.push_back(info);
} }
#if defined(USE_AURA)
void OSExchangeDataProviderWin::SetDragImage(
const gfx::ImageSkia& image,
const gfx::Vector2d& cursor_offset) {
drag_image_ = image;
drag_image_offset_ = cursor_offset;
}
const gfx::ImageSkia& OSExchangeDataProviderWin::GetDragImage() const {
return drag_image_;
}
const gfx::Vector2d& OSExchangeDataProviderWin::GetDragImageOffset() const {
return drag_image_offset_;
}
#endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// DataObjectImpl, IDataObject implementation: // DataObjectImpl, IDataObject implementation:
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "base/win/scoped_comptr.h" #include "base/win/scoped_comptr.h"
#include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/base/ui_export.h" #include "ui/base/ui_export.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/vector2d.h"
namespace ui { namespace ui {
...@@ -186,11 +188,23 @@ class UI_EXPORT OSExchangeDataProviderWin : public OSExchangeData::Provider { ...@@ -186,11 +188,23 @@ class UI_EXPORT OSExchangeDataProviderWin : public OSExchangeData::Provider {
virtual bool HasCustomFormat(OSExchangeData::CustomFormat format) const; virtual bool HasCustomFormat(OSExchangeData::CustomFormat format) const;
virtual void SetDownloadFileInfo( virtual void SetDownloadFileInfo(
const OSExchangeData::DownloadFileInfo& download_info); const OSExchangeData::DownloadFileInfo& download_info);
#if defined(USE_AURA)
virtual void SetDragImage(const gfx::ImageSkia& image,
const gfx::Vector2d& cursor_offset) OVERRIDE;
virtual const gfx::ImageSkia& GetDragImage() const OVERRIDE;
virtual const gfx::Vector2d& GetDragImageOffset() const OVERRIDE;
#endif
private: private:
scoped_refptr<DataObjectImpl> data_; scoped_refptr<DataObjectImpl> data_;
base::win::ScopedComPtr<IDataObject> source_object_; base::win::ScopedComPtr<IDataObject> source_object_;
#if defined(USE_AURA)
// Drag image and offset data. Only used for Ash.
gfx::ImageSkia drag_image_;
gfx::Vector2d drag_image_offset_;
#endif
DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderWin); DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderWin);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment