summaryrefslogtreecommitdiffstats
path: root/ash/drag_drop
diff options
context:
space:
mode:
authorvarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-04 00:31:02 +0000
committervarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-04 00:31:02 +0000
commit5eae7160b229cfd54b1f1d5463f4edacb79033d5 (patch)
treeea0f69cfd3cd4229c21ae4f8203e308db61c8fc8 /ash/drag_drop
parent15c16be96c04ab9fa99ee36bddb83616ec923390 (diff)
downloadchromium_src-5eae7160b229cfd54b1f1d5463f4edacb79033d5.zip
chromium_src-5eae7160b229cfd54b1f1d5463f4edacb79033d5.tar.gz
chromium_src-5eae7160b229cfd54b1f1d5463f4edacb79033d5.tar.bz2
Beginning of drag/drop should copy the drag data to clipboard.
BUG=97845 TEST=added new test Review URL: http://codereview.chromium.org/8994012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116236 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/drag_drop')
-rw-r--r--ash/drag_drop/drag_drop_controller.cc5
-rw-r--r--ash/drag_drop/drag_drop_controller_unittest.cc57
2 files changed, 44 insertions, 18 deletions
diff --git a/ash/drag_drop/drag_drop_controller.cc b/ash/drag_drop/drag_drop_controller.cc
index 48e43d0..c1539b6 100644
--- a/ash/drag_drop/drag_drop_controller.cc
+++ b/ash/drag_drop/drag_drop_controller.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -14,6 +14,7 @@
#include "ui/base/dragdrop/os_exchange_data_provider_aura.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
+#include "ui/views/views_delegate.h"
#include "ui/views/widget/native_widget_aura.h"
namespace ash {
@@ -58,6 +59,8 @@ int DragDropController::StartDragAndDrop(const ui::OSExchangeData& data,
gfx::Point location = RootWindow::GetInstance()->last_mouse_location();
const ui::OSExchangeDataProviderAura& provider =
static_cast<const ui::OSExchangeDataProviderAura&>(data.provider());
+ provider.WriteDataToClipboard(
+ views::ViewsDelegate::views_delegate->GetClipboard());
drag_image_.reset(new DragImageView);
drag_image_->SetImage(provider.drag_image());
diff --git a/ash/drag_drop/drag_drop_controller_unittest.cc b/ash/drag_drop/drag_drop_controller_unittest.cc
index bea60aa..35fa1d9 100644
--- a/ash/drag_drop/drag_drop_controller_unittest.cc
+++ b/ash/drag_drop/drag_drop_controller_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -10,10 +10,13 @@
#include "base/utf_string_conversions.h"
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
+#include "ui/base/clipboard/clipboard.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/dragdrop/os_exchange_data.h"
#include "ui/views/events/event.h"
+#include "ui/views/test/test_views_delegate.h"
#include "ui/views/view.h"
+#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
namespace ash {
@@ -179,6 +182,7 @@ class DragDropControllerTest : public AuraShellTestBase {
drag_drop_controller_.reset(new TestDragDropController);
drag_drop_controller_->set_should_block_during_drag_drop(false);
aura::client::SetDragDropClient(drag_drop_controller_.get());
+ views_delegate_.reset(new views::TestViewsDelegate);
}
void TearDown() OVERRIDE {
@@ -193,15 +197,16 @@ class DragDropControllerTest : public AuraShellTestBase {
protected:
scoped_ptr<TestDragDropController> drag_drop_controller_;
+ scoped_ptr<views::TestViewsDelegate> views_delegate_;
private:
DISALLOW_COPY_AND_ASSIGN(DragDropControllerTest);
};
TEST_F(DragDropControllerTest, DragDropInSingleViewTest) {
- views::Widget* widget = CreateNewWidget();
+ scoped_ptr<views::Widget> widget(CreateNewWidget());
DragTestView* drag_view = new DragTestView;
- AddViewToWidgetAndResize(widget, drag_view);
+ AddViewToWidgetAndResize(widget.get(), drag_view);
gfx::Point point = gfx::Rect(drag_view->bounds()).CenterPoint();
ui::OSExchangeData data;
data.SetString(UTF8ToUTF16("I am being dragged"));
@@ -242,16 +247,15 @@ TEST_F(DragDropControllerTest, DragDropInSingleViewTest) {
EXPECT_EQ(1, drag_view->num_drops_);
EXPECT_EQ(0, drag_view->num_drag_exits_);
EXPECT_TRUE(drag_view->drag_done_received_);
- delete widget;
}
TEST_F(DragDropControllerTest, DragDropInMultipleViewsSingleWidgetTest) {
- views::Widget* widget = CreateNewWidget();
+ scoped_ptr<views::Widget> widget(CreateNewWidget());
DragTestView* drag_view1 = new DragTestView;
- AddViewToWidgetAndResize(widget, drag_view1);
+ AddViewToWidgetAndResize(widget.get(), drag_view1);
gfx::Point point = drag_view1->bounds().CenterPoint();
DragTestView* drag_view2 = new DragTestView;
- AddViewToWidgetAndResize(widget, drag_view2);
+ AddViewToWidgetAndResize(widget.get(), drag_view2);
ui::OSExchangeData data;
data.SetString(UTF8ToUTF16("I am being dragged"));
@@ -301,17 +305,16 @@ TEST_F(DragDropControllerTest, DragDropInMultipleViewsSingleWidgetTest) {
EXPECT_EQ(1, drag_view2->num_drops_);
EXPECT_EQ(0, drag_view2->num_drag_exits_);
EXPECT_FALSE(drag_view2->drag_done_received_);
- delete widget;
}
TEST_F(DragDropControllerTest, DragDropInMultipleViewsMultipleWidgetsTest) {
- views::Widget* widget1 = CreateNewWidget();
+ scoped_ptr<views::Widget> widget1(CreateNewWidget());
DragTestView* drag_view1 = new DragTestView;
- AddViewToWidgetAndResize(widget1, drag_view1);
+ AddViewToWidgetAndResize(widget1.get(), drag_view1);
gfx::Point point = drag_view1->bounds().CenterPoint();
- views::Widget* widget2 = CreateNewWidget();
+ scoped_ptr<views::Widget> widget2(CreateNewWidget());
DragTestView* drag_view2 = new DragTestView;
- AddViewToWidgetAndResize(widget2, drag_view2);
+ AddViewToWidgetAndResize(widget2.get(), drag_view2);
gfx::Rect widget1_bounds = widget1->GetClientAreaScreenBounds();
gfx::Rect widget2_bounds = widget2->GetClientAreaScreenBounds();
widget2->SetBounds(gfx::Rect(widget1_bounds.width(), 0,
@@ -365,14 +368,12 @@ TEST_F(DragDropControllerTest, DragDropInMultipleViewsMultipleWidgetsTest) {
EXPECT_EQ(1, drag_view2->num_drops_);
EXPECT_EQ(0, drag_view2->num_drag_exits_);
EXPECT_FALSE(drag_view2->drag_done_received_);
- delete widget1;
- delete widget2;
}
TEST_F(DragDropControllerTest, ViewRemovedWhileInDragDropTest) {
- views::Widget* widget = CreateNewWidget();
+ scoped_ptr<views::Widget> widget(CreateNewWidget());
DragTestView* drag_view = new DragTestView;
- AddViewToWidgetAndResize(widget, drag_view);
+ AddViewToWidgetAndResize(widget.get(), drag_view);
gfx::Point point = gfx::Rect(drag_view->bounds()).CenterPoint();
ui::OSExchangeData data;
data.SetString(UTF8ToUTF16("I am being dragged"));
@@ -425,7 +426,29 @@ TEST_F(DragDropControllerTest, ViewRemovedWhileInDragDropTest) {
EXPECT_EQ(0, drag_view->num_drops_);
EXPECT_EQ(0, drag_view->num_drag_exits_);
EXPECT_TRUE(drag_view->drag_done_received_);
- delete widget;
+}
+
+TEST_F(DragDropControllerTest, DragCopiesDataToClipboardTest) {
+ scoped_ptr<views::Widget> widget(CreateNewWidget());
+ DragTestView* drag_view = new DragTestView;
+ AddViewToWidgetAndResize(widget.get(), drag_view);
+ gfx::Point point = gfx::Rect(drag_view->bounds()).CenterPoint();
+ ui::OSExchangeData data;
+ std::string data_str("I am being dragged");
+ data.SetString(ASCIIToUTF16(data_str));
+
+ aura::MouseEvent event(ui::ET_MOUSE_PRESSED, point, ui::EF_LEFT_MOUSE_BUTTON);
+ aura::RootWindow::GetInstance()->DispatchMouseEvent(&event);
+ aura::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, point,
+ ui::EF_LEFT_MOUSE_BUTTON);
+ aura::RootWindow::GetInstance()->DispatchMouseEvent(&drag_event);
+
+ ui::Clipboard* cb = views::ViewsDelegate::views_delegate->GetClipboard();
+ EXPECT_TRUE(cb->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(),
+ ui::Clipboard::BUFFER_STANDARD));
+ std::string result;
+ cb->ReadAsciiText(ui::Clipboard::BUFFER_STANDARD, &result);
+ EXPECT_EQ(data_str, result);
}
} // namespace test