From d7b970da622e72582ae69a515c249355607fe7a5 Mon Sep 17 00:00:00 2001 From: Henrique Ferreiro Date: Fri, 16 Apr 2021 19:36:44 +0000 Subject: [PATCH] Reland "Change DragDropController::StartDragAndDrop return type" This is a reland of f062e108c5538e5d5a7bfa4159ba4aeb04226e76 Original change's description: > Change DragDropController::StartDragAndDrop return type > > This CL changes the return type of > ash::DragDropController::StartDragAndDrop from integer to DragOperation, > to improve type safety. > > Bug: 1093536 > Change-Id: I4099dd80cf07a07e481358a96ee6a12c0060e5c5 > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2764362 > Commit-Queue: Henrique Ferreiro > Reviewed-by: Nick Yamane > Reviewed-by: Avi Drissman > Reviewed-by: Mitsuru Oshima (Slow - Gardening) > Reviewed-by: Scott Violet > Cr-Commit-Position: refs/heads/master@{#871936} Bug: 1093536 Change-Id: I58789f4a32a81dfbe29e1b059b45a03f2c36fa61 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2825429 Reviewed-by: Scott Violet Reviewed-by: Nick Yamane Reviewed-by: Mitsuru Oshima (Slow - Gardening) Reviewed-by: Camille Lamy Commit-Queue: Henrique Ferreiro Cr-Commit-Position: refs/heads/master@{#873425} --- ash/drag_drop/drag_drop_controller.cc | 38 ++++----- ash/drag_drop/drag_drop_controller.h | 16 ++-- .../drag_drop_controller_unittest.cc | 22 ++--- ash/drag_drop/toplevel_window_drag_delegate.h | 4 +- .../views/drag_and_drop_interactive_uitest.cc | 22 ++--- chrome/test/BUILD.gn | 1 + components/exo/drag_drop_operation.cc | 16 ++-- components/exo/extended_drag_source.cc | 8 +- components/exo/extended_drag_source.h | 2 +- .../web_contents/web_contents_view_aura.cc | 27 +++--- .../web_contents_view_aura_unittest.cc | 19 +++-- content/test/BUILD.gn | 1 + ui/aura/client/drag_drop_client.h | 13 +-- ui/base/dragdrop/BUILD.gn | 5 +- ui/base/dragdrop/drag_drop_types.cc | 10 +++ ui/base/dragdrop/drag_drop_types.h | 4 + ui/base/x/BUILD.gn | 6 +- ui/base/x/x11_drag_drop_client.cc | 82 ++++++++++--------- ui/base/x/x11_drag_drop_client.h | 25 +++--- ui/ozone/platform/wayland/BUILD.gn | 2 + ui/ozone/platform/wayland/DEPS | 1 + .../host/wayland_data_drag_controller.cc | 24 +++++- .../wayland_data_drag_controller_unittest.cc | 18 ++-- .../platform/wayland/host/wayland_window.cc | 9 +- .../platform/wayland/host/wayland_window.h | 2 +- ui/platform_window/wm/BUILD.gn | 2 +- ui/platform_window/wm/wm_drag_handler.h | 7 +- ui/platform_window/x11/BUILD.gn | 1 + ui/platform_window/x11/x11_window.cc | 26 +++--- ui/platform_window/x11/x11_window.h | 8 +- ui/views/BUILD.gn | 1 + .../controls/button/menu_button_unittest.cc | 25 +++--- .../controls/menu/menu_controller_unittest.cc | 21 ++--- .../desktop_drag_drop_client_ozone.cc | 33 ++++---- .../desktop_drag_drop_client_ozone.h | 23 +++--- ...desktop_drag_drop_client_ozone_unittest.cc | 22 ++--- .../desktop_drag_drop_client_win.cc | 13 ++- .../desktop_drag_drop_client_win.h | 15 ++-- .../x11_drag_drop_client_unittest.cc | 58 ++++++------- 39 files changed, 348 insertions(+), 284 deletions(-) diff --git a/ash/drag_drop/drag_drop_controller.cc b/ash/drag_drop/drag_drop_controller.cc index d30850bcf1e82f..7e2af7fb2268c4 100644 --- a/ash/drag_drop/drag_drop_controller.cc +++ b/ash/drag_drop/drag_drop_controller.cc @@ -26,6 +26,7 @@ #include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "ui/base/data_transfer_policy/data_transfer_policy_controller.h" #include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data_provider.h" #include "ui/base/hit_test.h" @@ -43,6 +44,8 @@ namespace ash { namespace { +using ::ui::mojom::DragOperation; + // The duration of the drag cancel animation in millisecond. constexpr base::TimeDelta kCancelAnimationDuration = base::TimeDelta::FromMilliseconds(250); @@ -158,22 +161,23 @@ DragDropController::~DragDropController() { drag_image_widget_.reset(); } -int DragDropController::StartDragAndDrop( +DragOperation DragDropController::StartDragAndDrop( std::unique_ptr data, aura::Window* root_window, aura::Window* source_window, const gfx::Point& screen_location, - int operation, + int allowed_operations, ui::mojom::DragEventSource source) { if (!enabled_ || IsDragDropInProgress()) - return 0; + return DragOperation::kNone; const ui::OSExchangeDataProvider* provider = &data->provider(); // We do not support touch drag/drop without a drag image. if (source == ui::mojom::DragEventSource::kTouch && provider->GetDragImage().size().IsEmpty()) - return 0; + return DragOperation::kNone; + operation_ = DragOperation::kNone; current_drag_event_source_ = source; DragDropTracker* tracker = new DragDropTracker(root_window, drag_drop_window_delegate_.get()); @@ -197,7 +201,7 @@ int DragDropController::StartDragAndDrop( pending_long_tap_.reset(); drag_data_ = std::move(data); - drag_operation_ = operation; + allowed_operations_ = allowed_operations; current_drag_info_ = aura::client::DragUpdateInfo(); start_location_ = screen_location; @@ -242,7 +246,7 @@ int DragDropController::StartDragAndDrop( drag_source_window_ = nullptr; } - return drag_operation_; + return operation_; } void DragDropController::SetDragImage(const gfx::ImageSkia& image, @@ -446,7 +450,7 @@ gfx::LinearAnimation* DragDropController::CreateCancelAnimation( void DragDropController::DragUpdate(aura::Window* target, const ui::LocatedEvent& event) { ui::DropTargetEvent e(*drag_data_.get(), event.location_f(), - event.root_location_f(), drag_operation_); + event.root_location_f(), allowed_operations_); e.set_flags(event.flags()); ui::Event::DispatcherApi(&e).set_target(target); @@ -542,14 +546,13 @@ void DragDropController::Drop(aura::Window* target, aura::client::GetDragDropDelegate(target); if (delegate) { ui::DropTargetEvent e(*drag_data_.get(), event.location_f(), - event.root_location_f(), drag_operation_); + event.root_location_f(), allowed_operations_); e.set_flags(event.flags()); ui::Event::DispatcherApi(&e).set_target(target); ui::OSExchangeData copied_data(drag_data_->provider().Clone()); - drag_operation_ = - static_cast(delegate->OnPerformDrop(e, std::move(drag_data_))); - if (drag_operation_ == 0 && tab_drag_drop_delegate_) { + operation_ = delegate->OnPerformDrop(e, std::move(drag_data_)); + if (operation_ == DragOperation::kNone && tab_drag_drop_delegate_) { gfx::Point location_in_screen = event.root_location(); ::wm::ConvertPointToScreen(target->GetRootWindow(), &location_in_screen); tab_drag_drop_delegate_->Drop(location_in_screen, copied_data); @@ -557,9 +560,9 @@ void DragDropController::Drop(aura::Window* target, // that the tab or group was moved. Otherwise, the WebUI tab strip does // not know that a drop resulted in a tab being moved and will temporarily // visually return the tab to its original position. (crbug.com/1081905) - drag_operation_ = ui::DragDropTypes::DragOperation::DRAG_MOVE; + operation_ = DragOperation::kMove; StartCanceledAnimation(kCancelAnimationDuration); - } else if (drag_operation_ == 0) { + } else if (operation_ == DragOperation::kNone) { StartCanceledAnimation(kCancelAnimationDuration); } else { drag_image_widget_.reset(); @@ -568,10 +571,8 @@ void DragDropController::Drop(aura::Window* target, drag_image_widget_.reset(); } - if (toplevel_window_drag_delegate_) { - drag_operation_ = - toplevel_window_drag_delegate_->OnToplevelWindowDragDropped(); - } + if (toplevel_window_drag_delegate_) + operation_ = toplevel_window_drag_delegate_->OnToplevelWindowDragDropped(); Cleanup(); if (should_block_during_drag_drop_) @@ -618,7 +619,6 @@ void DragDropController::DoDragCancel( toplevel_window_drag_delegate_->OnToplevelWindowDragCancelled(); Cleanup(); - drag_operation_ = 0; StartCanceledAnimation(drag_cancel_animation_duration); if (should_block_during_drag_drop_) std::move(quit_closure_).Run(); @@ -678,7 +678,7 @@ void DragDropController::Cleanup() { drag_window_->RemoveObserver(this); drag_window_ = nullptr; drag_data_.reset(); - + allowed_operations_ = 0; tab_drag_drop_delegate_.reset(); // Cleanup can be called again while deleting DragDropTracker, so delete diff --git a/ash/drag_drop/drag_drop_controller.h b/ash/drag_drop/drag_drop_controller.h index a57d64fba3a0ec..ccc1d708fe2bc9 100644 --- a/ash/drag_drop/drag_drop_controller.h +++ b/ash/drag_drop/drag_drop_controller.h @@ -60,12 +60,13 @@ class ASH_EXPORT DragDropController : public aura::client::DragDropClient, } // Overridden from aura::client::DragDropClient: - int StartDragAndDrop(std::unique_ptr data, - aura::Window* root_window, - aura::Window* source_window, - const gfx::Point& screen_location, - int operation, - ui::mojom::DragEventSource source) override; + ui::mojom::DragOperation StartDragAndDrop( + std::unique_ptr data, + aura::Window* root_window, + aura::Window* source_window, + const gfx::Point& screen_location, + int allowed_operations, + ui::mojom::DragEventSource source) override; void DragCancel() override; bool IsDragDropInProgress() override; void AddObserver(aura::client::DragDropClientObserver* observer) override; @@ -124,7 +125,8 @@ class ASH_EXPORT DragDropController : public aura::client::DragDropClient, views::UniqueWidgetPtr drag_image_widget_; gfx::Vector2d drag_image_offset_; std::unique_ptr drag_data_; - int drag_operation_ = 0; + int allowed_operations_ = 0; + ui::mojom::DragOperation operation_ = ui::mojom::DragOperation::kNone; aura::client::DragUpdateInfo current_drag_info_; // Used when processing a Chrome tab drag from a WebUI tab strip. diff --git a/ash/drag_drop/drag_drop_controller_unittest.cc b/ash/drag_drop/drag_drop_controller_unittest.cc index 21cdb422430071..703405641c03ab 100644 --- a/ash/drag_drop/drag_drop_controller_unittest.cc +++ b/ash/drag_drop/drag_drop_controller_unittest.cc @@ -166,17 +166,17 @@ class TestDragDropController : public DragDropController { drag_string_.clear(); } - int StartDragAndDrop(std::unique_ptr data, - aura::Window* root_window, - aura::Window* source_window, - const gfx::Point& location, - int operation, - ui::mojom::DragEventSource source) override { + DragOperation StartDragAndDrop(std::unique_ptr data, + aura::Window* root_window, + aura::Window* source_window, + const gfx::Point& location, + int allowed_operations, + ui::mojom::DragEventSource source) override { drag_start_received_ = true; data->GetString(&drag_string_); return DragDropController::StartDragAndDrop(std::move(data), root_window, source_window, location, - operation, source); + allowed_operations, source); } void DragUpdate(aura::Window* target, @@ -367,10 +367,10 @@ class TestToplevelWindowDragDelegate : public ToplevelWindowDragDelegate { source_ = source; } - int OnToplevelWindowDragDropped() override { + DragOperation OnToplevelWindowDragDropped() override { EXPECT_EQ(State::kDragStartedInvoked, state_); state_ = State::kDragDroppedInvoked; - return ui::DragDropTypes::DRAG_MOVE; + return DragOperation::kMove; } void OnToplevelWindowDragCancelled() override { @@ -1421,12 +1421,12 @@ TEST_F(DragDropControllerTest, DragTabChangesDragOperationToMove) { base::Unretained(&generator))); drag_drop_controller_->set_should_block_during_drag_drop(true); - int operation = drag_drop_controller_->StartDragAndDrop( + DragOperation operation = drag_drop_controller_->StartDragAndDrop( std::make_unique(), window->GetRootWindow(), window, gfx::Point(5, 5), ui::DragDropTypes::DRAG_NONE, ui::mojom::DragEventSource::kMouse); - EXPECT_EQ(operation, ui::DragDropTypes::DRAG_MOVE); + EXPECT_EQ(operation, DragOperation::kMove); } TEST_F(DragDropControllerTest, ToplevelWindowDragDelegate) { diff --git a/ash/drag_drop/toplevel_window_drag_delegate.h b/ash/drag_drop/toplevel_window_drag_delegate.h index 175e6e6b5348e1..52434dea5c7d6e 100644 --- a/ash/drag_drop/toplevel_window_drag_delegate.h +++ b/ash/drag_drop/toplevel_window_drag_delegate.h @@ -5,7 +5,7 @@ #ifndef ASH_DRAG_DROP_TOPLEVEL_WINDOW_DRAG_DELEGATE_H_ #define ASH_DRAG_DROP_TOPLEVEL_WINDOW_DRAG_DELEGATE_H_ -#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-shared.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-forward.h" namespace gfx { class PointF; @@ -25,7 +25,7 @@ class ToplevelWindowDragDelegate { const gfx::PointF& start_location, ui::mojom::DragEventSource source) = 0; - virtual int OnToplevelWindowDragDropped() = 0; + virtual ui::mojom::DragOperation OnToplevelWindowDragDropped() = 0; virtual void OnToplevelWindowDragCancelled() = 0; diff --git a/chrome/browser/ui/views/drag_and_drop_interactive_uitest.cc b/chrome/browser/ui/views/drag_and_drop_interactive_uitest.cc index 7ebadd8a4165cf..2d2fe2b52ff59d 100644 --- a/chrome/browser/ui/views/drag_and_drop_interactive_uitest.cc +++ b/chrome/browser/ui/views/drag_and_drop_interactive_uitest.cc @@ -55,15 +55,17 @@ #include "ui/aura/window.h" #include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/dragdrop/drop_target_event.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/rect.h" #include "url/gurl.h" namespace chrome { - namespace { +using ::ui::mojom::DragOperation; + // TODO(lukasza): Support testing on non-Aura platforms (i.e. Android + Mac?). // // Notes for the TODO above: @@ -274,12 +276,12 @@ class DragStartWaiter : public aura::client::DragDropClient { } // aura::client::DragDropClient overrides: - int StartDragAndDrop(std::unique_ptr data, - aura::Window* root_window, - aura::Window* source_window, - const gfx::Point& screen_location, - int operation, - ui::mojom::DragEventSource source) override { + DragOperation StartDragAndDrop(std::unique_ptr data, + aura::Window* root_window, + aura::Window* source_window, + const gfx::Point& screen_location, + int allowed_operations, + ui::mojom::DragEventSource source) override { DCHECK(!drag_started_); if (!drag_started_) { drag_started_ = true; @@ -303,7 +305,7 @@ class DragStartWaiter : public aura::client::DragDropClient { location_inside_web_contents_ = screen_location - gfx::Vector2d(bounds.x(), bounds.y()); - operation_ = operation; + operation_ = allowed_operations; } if (!callback_to_run_inside_drag_and_drop_message_loop_.is_null()) { @@ -314,12 +316,12 @@ class DragStartWaiter : public aura::client::DragDropClient { } if (suppress_passing_of_start_drag_further_) - return 0; + return DragOperation::kNone; // Start a nested drag-and-drop loop (might not return for a long time). return old_client_->StartDragAndDrop(std::move(data), root_window, source_window, screen_location, - operation, source); + allowed_operations, source); } void DragCancel() override { diff --git a/chrome/test/BUILD.gn b/chrome/test/BUILD.gn index b7d74487f9336a..55944804a7358b 100644 --- a/chrome/test/BUILD.gn +++ b/chrome/test/BUILD.gn @@ -6754,6 +6754,7 @@ if (!is_android) { deps += [ "//ui/aura:aura_interactive_ui_tests", "//ui/base/dragdrop:types", + "//ui/base/dragdrop/mojom", ] } else { sources -= [ diff --git a/components/exo/drag_drop_operation.cc b/components/exo/drag_drop_operation.cc index c862d62c0c4ac5..c89c3aa83ae098 100644 --- a/components/exo/drag_drop_operation.cc +++ b/components/exo/drag_drop_operation.cc @@ -21,6 +21,7 @@ #include "ui/base/clipboard/file_info.h" #include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/display/display.h" #include "ui/display/screen.h" @@ -37,9 +38,10 @@ #endif // BUILDFLAG(IS_CHROMEOS_ASH) namespace exo { - namespace { +using ::ui::mojom::DragOperation; + uint32_t DndActionsToDragOperations(const base::flat_set& actions) { uint32_t dnd_operations = 0; for (const DndAction action : actions) { @@ -72,13 +74,13 @@ DndAction DragOperationsToPreferredDndAction(int op) { } #endif -DndAction DragOperationToDndAction(int op) { +DndAction DragOperationToDndAction(DragOperation op) { switch (op) { - case ui::DragDropTypes::DragOperation::DRAG_NONE: + case DragOperation::kNone: return DndAction::kNone; - case ui::DragDropTypes::DragOperation::DRAG_MOVE: + case DragOperation::kMove: return DndAction::kMove; - case ui::DragDropTypes::DragOperation::DRAG_COPY: + case DragOperation::kCopy: return DndAction::kCopy; default: NOTREACHED(); @@ -318,7 +320,7 @@ void DragDropOperation::StartDragDropOperation() { // This triggers a nested run loop that terminates when the drag and drop // operation is completed. - int op = drag_drop_controller_->StartDragAndDrop( + DragOperation op = drag_drop_controller_->StartDragAndDrop( std::move(os_exchange_data_), origin_->get()->window()->GetRootWindow(), origin_->get()->window(), drag_start_point, dnd_operations, event_source_); @@ -327,7 +329,7 @@ void DragDropOperation::StartDragDropOperation() { if (!weak_ptr) return; - if (op) { + if (op != DragOperation::kNone) { // Success // TODO(crbug.com/994065) This is currently not the actual mime type used by diff --git a/components/exo/extended_drag_source.cc b/components/exo/extended_drag_source.cc index 69a50fb41b0683..2b5ee450247f4d 100644 --- a/components/exo/extended_drag_source.cc +++ b/components/exo/extended_drag_source.cc @@ -33,6 +33,8 @@ namespace exo { +using ::ui::mojom::DragOperation; + // static ExtendedDragSource* ExtendedDragSource::instance_ = nullptr; @@ -177,11 +179,11 @@ void ExtendedDragSource::OnToplevelWindowDragStarted( StartDrag(dragged_window_holder_->toplevel_window(), start_location); } -int ExtendedDragSource::OnToplevelWindowDragDropped() { +DragOperation ExtendedDragSource::OnToplevelWindowDragDropped() { DVLOG(1) << "OnDragDropped()"; Cleanup(); - return delegate_->ShouldAllowDropAnywhere() ? ui::DragDropTypes::DRAG_MOVE - : ui::DragDropTypes::DRAG_NONE; + return delegate_->ShouldAllowDropAnywhere() ? DragOperation::kMove + : DragOperation::kNone; } void ExtendedDragSource::OnToplevelWindowDragCancelled() { diff --git a/components/exo/extended_drag_source.h b/components/exo/extended_drag_source.h index 3aed93f9ee7498..5f4ae1785379a0 100644 --- a/components/exo/extended_drag_source.h +++ b/components/exo/extended_drag_source.h @@ -76,7 +76,7 @@ class ExtendedDragSource : public DataSourceObserver, // ash::ToplevelWindowDragDelegate: void OnToplevelWindowDragStarted(const gfx::PointF& start_location, ui::mojom::DragEventSource source) override; - int OnToplevelWindowDragDropped() override; + ui::mojom::DragOperation OnToplevelWindowDragDropped() override; void OnToplevelWindowDragCancelled() override; void OnToplevelWindowDragEvent(ui::LocatedEvent* event) override; diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc index 1ff49e30c03f92..6a91156e661685 100644 --- a/content/browser/web_contents/web_contents_view_aura.cc +++ b/content/browser/web_contents/web_contents_view_aura.cc @@ -104,6 +104,8 @@ WebContentsView* CreateWebContentsView( namespace { +using ::ui::mojom::DragOperation; + WebContentsViewAura::RenderWidgetHostViewCreateFunction g_create_render_widget_host_view = nullptr; @@ -375,15 +377,6 @@ blink::DragOperationsMask ConvertToDragOperationsMask(int drag_op) { return static_cast(web_drag_op); } -ui::mojom::DragOperation ConvertToDragOperation(int drag_ops) { - int op_mask = ConvertToDragOperationsMask(drag_ops); - DCHECK(op_mask == blink::kDragOperationNone || - op_mask == blink::kDragOperationCopy || - op_mask == blink::kDragOperationLink || - op_mask == blink::kDragOperationMove); - return static_cast(op_mask); -} - GlobalRoutingID GetRenderViewHostID(RenderViewHost* rvh) { return GlobalRoutingID(rvh->GetProcess()->GetID(), rvh->GetRoutingID()); } @@ -692,7 +685,7 @@ WebContentsViewAura::WebContentsViewAura(WebContentsImpl* web_contents, WebContentsViewDelegate* delegate) : web_contents_(web_contents), delegate_(delegate), - current_drag_op_(ui::mojom::DragOperation::kNone), + current_drag_op_(DragOperation::kNone), drag_dest_delegate_(nullptr), current_rvh_for_drag_(ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE), @@ -722,7 +715,7 @@ WebContentsViewAura::~WebContentsViewAura() { void WebContentsViewAura::EndDrag( base::WeakPtr source_rwh_weak_ptr, - ui::mojom::DragOperation op) { + DragOperation op) { drag_start_process_id_ = ChildProcessHost::kInvalidUniqueID; drag_start_view_id_ = GlobalRoutingID(ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE); @@ -1058,7 +1051,7 @@ void WebContentsViewAura::StartDragging( // We need to enable recursive tasks on the message loop so we can get // updates while in the system DoDragDrop loop. - int result_op = 0; + DragOperation result_op; { gfx::NativeView content_native_view = GetContentNativeView(); base::CurrentThread::ScopedNestableTaskAllower allow; @@ -1084,15 +1077,15 @@ void WebContentsViewAura::StartDragging( // callback yet. So we have to make sure to delay calling EndDrag until drop // is done. if (!drag_in_progress_) { - EndDrag(std::move(source_rwh_weak_ptr), ConvertToDragOperation(result_op)); + EndDrag(std::move(source_rwh_weak_ptr), result_op); } else { end_drag_runner_.ReplaceClosure(base::BindOnce( &WebContentsViewAura::EndDrag, weak_ptr_factory_.GetWeakPtr(), - std::move(source_rwh_weak_ptr), ConvertToDragOperation(result_op))); + std::move(source_rwh_weak_ptr), result_op)); } } -void WebContentsViewAura::UpdateDragCursor(ui::mojom::DragOperation operation) { +void WebContentsViewAura::UpdateDragCursor(DragOperation operation) { current_drag_op_ = operation; } @@ -1514,11 +1507,11 @@ void WebContentsViewAura::FinishOnPerformDropCallback( current_drop_data_.reset(); } -ui::mojom::DragOperation WebContentsViewAura::OnPerformDrop( +DragOperation WebContentsViewAura::OnPerformDrop( const ui::DropTargetEvent& event, std::unique_ptr data) { if (web_contents_->ShouldIgnoreInputEvents()) - return ui::mojom::DragOperation::kNone; + return DragOperation::kNone; web_contents_->GetInputEventRouter() ->GetRenderWidgetHostAtPointAsynchronously( diff --git a/content/browser/web_contents/web_contents_view_aura_unittest.cc b/content/browser/web_contents/web_contents_view_aura_unittest.cc index db657fd5f39597..9e967dd8e82482 100644 --- a/content/browser/web_contents/web_contents_view_aura_unittest.cc +++ b/content/browser/web_contents/web_contents_view_aura_unittest.cc @@ -30,6 +30,7 @@ #include "ui/base/data_transfer_policy/data_transfer_endpoint.h" #include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/dragdrop/drop_target_event.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/display/display_switches.h" #include "ui/events/base_event_utils.h" @@ -40,8 +41,10 @@ #endif namespace content { - namespace { + +using ::ui::mojom::DragOperation; + constexpr gfx::Rect kBounds = gfx::Rect(0, 0, 20, 20); constexpr gfx::PointF kClientPt = {5, 10}; @@ -73,15 +76,15 @@ class RunCallbackOnActivation : public WebContentsDelegate { class TestDragDropClient : public aura::client::DragDropClient { public: // aura::client::DragDropClient: - int StartDragAndDrop(std::unique_ptr data, - aura::Window* root_window, - aura::Window* source_window, - const gfx::Point& screen_location, - int operation, - ui::mojom::DragEventSource source) override { + DragOperation StartDragAndDrop(std::unique_ptr data, + aura::Window* root_window, + aura::Window* source_window, + const gfx::Point& screen_location, + int allowed_operations, + ui::mojom::DragEventSource source) override { drag_in_progress_ = true; drag_drop_data_ = std::move(data); - return 1; + return DragOperation::kCopy; } void DragCancel() override { drag_in_progress_ = false; } bool IsDragDropInProgress() override { return drag_in_progress_; } diff --git a/content/test/BUILD.gn b/content/test/BUILD.gn index 76cded58211b04..ee7153360c21a9 100644 --- a/content/test/BUILD.gn +++ b/content/test/BUILD.gn @@ -2590,6 +2590,7 @@ test("content_unittests") { "//ui/aura:test_support", "//ui/aura_extra", "//ui/base/dragdrop:types", + "//ui/base/dragdrop/mojom", "//ui/wm", ] } else { diff --git a/ui/aura/client/drag_drop_client.h b/ui/aura/client/drag_drop_client.h index a6fa5efeb1d647..14f959b948b7a8 100644 --- a/ui/aura/client/drag_drop_client.h +++ b/ui/aura/client/drag_drop_client.h @@ -34,12 +34,13 @@ class AURA_EXPORT DragDropClient { // applied at the end of the drag drop session. |screen_location| is in // screen coordinates. At most one drag and drop operation is allowed. // It must not start drag operation while |IsDragDropInProgress| returns true. - virtual int StartDragAndDrop(std::unique_ptr data, - aura::Window* root_window, - aura::Window* source_window, - const gfx::Point& screen_location, - int operation, - ui::mojom::DragEventSource source) = 0; + virtual ui::mojom::DragOperation StartDragAndDrop( + std::unique_ptr data, + aura::Window* root_window, + aura::Window* source_window, + const gfx::Point& screen_location, + int allowed_operations, + ui::mojom::DragEventSource source) = 0; // Called when a drag and drop session is cancelled. virtual void DragCancel() = 0; diff --git a/ui/base/dragdrop/BUILD.gn b/ui/base/dragdrop/BUILD.gn index 82c9295dbcdd18..9c7c90b14566b5 100644 --- a/ui/base/dragdrop/BUILD.gn +++ b/ui/base/dragdrop/BUILD.gn @@ -9,7 +9,10 @@ component("types") { "drag_drop_types.h", ] defines = [ "IS_UI_BASE_DRAGDROP_TYPES_IMPL" ] - public_deps = [ "//base" ] + public_deps = [ + "//base", + "//ui/base/dragdrop/mojom:mojom_headers", + ] deps = [ "//ui/base/dragdrop/mojom" ] if (is_mac) { diff --git a/ui/base/dragdrop/drag_drop_types.cc b/ui/base/dragdrop/drag_drop_types.cc index 96ea4c33e2fb49..693316ad61b5e8 100644 --- a/ui/base/dragdrop/drag_drop_types.cc +++ b/ui/base/dragdrop/drag_drop_types.cc @@ -20,4 +20,14 @@ STATIC_ASSERT_ENUM(DragDropTypes::DRAG_COPY, DragOperation::kCopy); STATIC_ASSERT_ENUM(DragDropTypes::DRAG_LINK, DragOperation::kLink); STATIC_ASSERT_ENUM(DragDropTypes::DRAG_MOVE, DragOperation::kMove); +DragOperation PreferredDragOperation(int operations) { + if (operations & DragDropTypes::DRAG_COPY) + return DragOperation::kCopy; + if (operations & DragDropTypes::DRAG_MOVE) + return DragOperation::kMove; + if (operations & DragDropTypes::DRAG_LINK) + return DragOperation::kLink; + return DragOperation::kNone; +} + } // namespace ui diff --git a/ui/base/dragdrop/drag_drop_types.h b/ui/base/dragdrop/drag_drop_types.h index 8f7fbbaccc43f4..e84d5468848f19 100644 --- a/ui/base/dragdrop/drag_drop_types.h +++ b/ui/base/dragdrop/drag_drop_types.h @@ -9,6 +9,7 @@ #include "base/component_export.h" #include "build/build_config.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-forward.h" namespace ui { @@ -36,6 +37,9 @@ class COMPONENT_EXPORT(UI_BASE_DRAGDROP_TYPES) DragDropTypes { #endif }; +COMPONENT_EXPORT(UI_BASE_DRAGDROP_TYPES) +ui::mojom::DragOperation PreferredDragOperation(int operations); + } // namespace ui #endif // UI_BASE_DRAGDROP_DRAG_DROP_TYPES_H_ diff --git a/ui/base/x/BUILD.gn b/ui/base/x/BUILD.gn index 448ce3955dec91..2fd1b90bf1a81f 100644 --- a/ui/base/x/BUILD.gn +++ b/ui/base/x/BUILD.gn @@ -106,7 +106,11 @@ component("x") { "x11_os_exchange_data_provider.cc", "x11_os_exchange_data_provider.h", ] - public_deps += [ "//ui/base/dragdrop:types" ] + public_deps += [ "//ui/base/dragdrop/mojom:mojom_shared" ] + deps += [ + "//ui/base/dragdrop:types", + "//ui/base/dragdrop/mojom", + ] } } diff --git a/ui/base/x/x11_drag_drop_client.cc b/ui/base/x/x11_drag_drop_client.cc index 91dba2f20d949c..c96e99425d5c3c 100644 --- a/ui/base/x/x11_drag_drop_client.cc +++ b/ui/base/x/x11_drag_drop_client.cc @@ -6,8 +6,10 @@ #include "base/lazy_instance.h" #include "base/logging.h" +#include "base/notreached.h" #include "ui/base/clipboard/clipboard_constants.h" #include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/x/x11_os_exchange_data_provider.h" #include "ui/base/x/x11_util.h" @@ -28,9 +30,10 @@ // All the readings are freely available online. namespace ui { - namespace { +using mojom::DragOperation; + constexpr int kWillAcceptDrop = 1; constexpr int kWantFurtherPosEvents = 2; @@ -120,29 +123,29 @@ const char kXdndStatus[] = "XdndStatus"; static base::LazyInstance>::Leaky g_live_client_map = LAZY_INSTANCE_INITIALIZER; -// Converts a bitfield of actions into an Atom that represents what action -// we're most likely to take on drop. -x11::Atom XDragOperationToAtom(int drag_operation) { - if (drag_operation & DragDropTypes::DRAG_COPY) - return x11::GetAtom(kXdndActionCopy); - if (drag_operation & DragDropTypes::DRAG_MOVE) - return x11::GetAtom(kXdndActionMove); - if (drag_operation & DragDropTypes::DRAG_LINK) - return x11::GetAtom(kXdndActionLink); - +x11::Atom DragOperationToAtom(DragOperation operation) { + switch (operation) { + case DragOperation::kNone: + return x11::Atom::None; + case DragOperation::kCopy: + return x11::GetAtom(kXdndActionCopy); + case DragOperation::kMove: + return x11::GetAtom(kXdndActionMove); + case DragOperation::kLink: + return x11::GetAtom(kXdndActionLink); + } + NOTREACHED(); return x11::Atom::None; } -// Converts a single action atom to a drag operation. -DragDropTypes::DragOperation AtomToDragOperation(x11::Atom atom) { +DragOperation AtomToDragOperation(x11::Atom atom) { if (atom == x11::GetAtom(kXdndActionCopy)) - return DragDropTypes::DRAG_COPY; + return DragOperation::kCopy; if (atom == x11::GetAtom(kXdndActionMove)) - return DragDropTypes::DRAG_MOVE; + return DragOperation::kMove; if (atom == x11::GetAtom(kXdndActionLink)) - return DragDropTypes::DRAG_LINK; - - return DragDropTypes::DRAG_NONE; + return DragOperation::kLink; + return DragOperation::kNone; } } // namespace @@ -203,18 +206,19 @@ XDragDropClient::~XDragDropClient() { std::vector XDragDropClient::GetOfferedDragOperations() const { std::vector operations; - if (drag_operation_ & DragDropTypes::DRAG_COPY) + if (allowed_operations_ & DragDropTypes::DRAG_COPY) operations.push_back(x11::GetAtom(kXdndActionCopy)); - if (drag_operation_ & DragDropTypes::DRAG_MOVE) + if (allowed_operations_ & DragDropTypes::DRAG_MOVE) operations.push_back(x11::GetAtom(kXdndActionMove)); - if (drag_operation_ & DragDropTypes::DRAG_LINK) + if (allowed_operations_ & DragDropTypes::DRAG_LINK) operations.push_back(x11::GetAtom(kXdndActionLink)); return operations; } void XDragDropClient::CompleteXdndPosition(x11::Window source_window, const gfx::Point& screen_point) { - int drag_operation = delegate_->UpdateDrag(screen_point); + DragOperation drag_operation = + PreferredDragOperation(delegate_->UpdateDrag(screen_point)); // Sends an XdndStatus message back to the source_window. l[2,3] // theoretically represent an area in the window where the current action is @@ -223,10 +227,11 @@ void XDragDropClient::CompleteXdndPosition(x11::Window source_window, // first bit of l[1] to disable the feature, and it appears that gtk neither // sets this nor respects it if set. auto xev = PrepareXdndClientMessage(kXdndStatus, source_window); - xev.data.data32[1] = - (drag_operation != 0) ? (kWantFurtherPosEvents | kWillAcceptDrop) : 0; + xev.data.data32[1] = (drag_operation != DragOperation::kNone) + ? (kWantFurtherPosEvents | kWillAcceptDrop) + : 0; xev.data.data32[4] = - static_cast(XDragOperationToAtom(drag_operation)); + static_cast(DragOperationToAtom(drag_operation)); SendXClientEvent(source_window, xev); } @@ -246,7 +251,7 @@ void XDragDropClient::ProcessMouseMove(const gfx::Point& screen_point, waiting_on_status_ = false; next_position_message_.reset(); status_received_since_enter_ = false; - negotiated_operation_ = DragDropTypes::DRAG_NONE; + negotiated_operation_ = DragOperation::kNone; if (target_current_window_ != x11::Window::None) { std::vector targets; @@ -367,12 +372,12 @@ void XDragDropClient::OnXdndStatus(const x11::ClientMessageEvent& event) { x11::Atom atom_operation = static_cast(event.data.data32[4]); negotiated_operation_ = AtomToDragOperation(atom_operation); } else { - negotiated_operation_ = DragDropTypes::DRAG_NONE; + negotiated_operation_ = DragOperation::kNone; } if (source_state_ == SourceState::kPendingDrop) { // We were waiting on the status message so we could send the XdndDrop. - if (negotiated_operation_ == DragDropTypes::DRAG_NONE) { + if (negotiated_operation_ == DragOperation::kNone) { EndMoveLoop(); return; } @@ -411,12 +416,12 @@ void XDragDropClient::OnXdndDrop(const x11::ClientMessageEvent& event) { auto source_window = static_cast(event.data.data32[0]); - int drag_operation = delegate_->PerformDrop(); + DragOperation drag_operation = delegate_->PerformDrop(); auto xev = PrepareXdndClientMessage(kXdndFinished, source_window); - xev.data.data32[1] = (drag_operation != 0) ? 1 : 0; + xev.data.data32[1] = (drag_operation != DragOperation::kNone) ? 1 : 0; xev.data.data32[2] = - static_cast(XDragOperationToAtom(drag_operation)); + static_cast(DragOperationToAtom(drag_operation)); SendXClientEvent(source_window, xev); } @@ -428,7 +433,7 @@ void XDragDropClient::OnXdndFinished(const x11::ClientMessageEvent& event) { // Clear |negotiated_operation_| if the drag was rejected. if ((event.data.data32[1] & 1) == 0) - negotiated_operation_ = DragDropTypes::DRAG_NONE; + negotiated_operation_ = DragOperation::kNone; // Clear |target_current_window_| to avoid sending XdndLeave upon ending the // move loop. @@ -447,14 +452,15 @@ void XDragDropClient::OnSelectionNotify( x11::DeleteProperty(xwindow_, xselection.property); } -void XDragDropClient::InitDrag(int operation, const OSExchangeData* data) { +void XDragDropClient::InitDrag(int allowed_operations, + const OSExchangeData* data) { target_current_window_ = x11::Window::None; source_state_ = SourceState::kOther; waiting_on_status_ = false; next_position_message_.reset(); status_received_since_enter_ = false; - drag_operation_ = operation; - negotiated_operation_ = DragDropTypes::DRAG_NONE; + allowed_operations_ = allowed_operations; + negotiated_operation_ = DragOperation::kNone; source_provider_ = static_cast(&data->provider()); @@ -544,7 +550,7 @@ void XDragDropClient::HandleMouseReleased() { return; } - if (negotiated_operation() != DragDropTypes::DRAG_NONE) { + if (negotiated_operation() != DragOperation::kNone) { // Start timer to end the move loop if the target takes too long to send // an XdndFinished message. It is important that StartEndMoveLoopTimer() // is called before SendXdndDrop() because SendXdndDrop() @@ -657,8 +663,8 @@ void XDragDropClient::SendXdndPosition(x11::Window dest_window, auto xev = PrepareXdndClientMessage(kXdndPosition, dest_window); xev.data.data32[2] = (screen_point.x() << 16) | screen_point.y(); xev.data.data32[3] = event_time; - xev.data.data32[4] = - static_cast(XDragOperationToAtom(drag_operation_)); + xev.data.data32[4] = static_cast( + DragOperationToAtom(PreferredDragOperation(allowed_operations_))); SendXClientEvent(dest_window, xev); // http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html and diff --git a/ui/base/x/x11_drag_drop_client.h b/ui/base/x/x11_drag_drop_client.h index e32e73185ce27e..b5eff05fab55b4 100644 --- a/ui/base/x/x11_drag_drop_client.h +++ b/ui/base/x/x11_drag_drop_client.h @@ -9,7 +9,7 @@ #include "base/component_export.h" #include "base/timer/timer.h" -#include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-shared.h" #include "ui/base/x/selection_utils.h" #include "ui/base/x/x11_drag_context.h" #include "ui/base/x/x11_topmost_window_finder.h" @@ -40,7 +40,7 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient { // Creates the window finder. virtual std::unique_ptr CreateWindowFinder() = 0; - // Updates the drag status by the new position. Returns the drag operation + // Updates the drag status by the new position. Returns the drag operations // possible at that position. // // Handling XdndPosition can be paused while waiting for more data; this is @@ -49,8 +49,7 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient { virtual int UpdateDrag(const gfx::Point& screen_point) = 0; // Updates the mouse cursor shape. - virtual void UpdateCursor( - DragDropTypes::DragOperation negotiated_operation) = 0; + virtual void UpdateCursor(mojom::DragOperation negotiated_operation) = 0; // Called when data from another application (not Chrome) enters the window. virtual void OnBeginForeignDrag(x11::Window window) = 0; @@ -63,7 +62,7 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient { virtual void OnBeforeDragLeave() = 0; // Drops data at the current location and returns the resulting operation. - virtual int PerformDrop() = 0; + virtual mojom::DragOperation PerformDrop() = 0; // Called to end the drag loop that is maintained by the subclass. virtual void EndDragLoop() = 0; @@ -148,7 +147,7 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient { kOther, }; - DragDropTypes::DragOperation negotiated_operation() const { + mojom::DragOperation negotiated_operation() const { return negotiated_operation_; } @@ -214,18 +213,18 @@ class COMPONENT_EXPORT(UI_BASE_X) XDragDropClient { const XOSExchangeDataProvider* source_provider_ = nullptr; // The operation bitfield as requested by StartDragAndDrop. - int drag_operation_ = 0; + int allowed_operations_ = 0; // The modifier state for the most recent mouse move. Used to bypass an // asynchronous roundtrip through the X11 server. int current_modifier_state_ = 0; - // We offer the other window a list of possible operations, - // XdndActionsList. This is the requested action from the other window. This - // is DRAG_NONE if we haven't sent out an XdndPosition message yet, haven't - // yet received an XdndStatus or if the other window has told us that there's - // no action that we can agree on. - DragDropTypes::DragOperation negotiated_operation_ = DragDropTypes::DRAG_NONE; + // We offer the other window a list of possible operations, XdndActionsList. + // This is the requested action from the other window. This is + // DragOperation::kNone if we haven't sent out an XdndPosition message yet, + // haven't yet received an XdndStatus or if the other window has told us that + // there's no action that we can agree on. + mojom::DragOperation negotiated_operation_ = mojom::DragOperation::kNone; // In the Xdnd protocol, we aren't supposed to send another XdndPosition // message until we have received a confirming XdndStatus message. diff --git a/ui/ozone/platform/wayland/BUILD.gn b/ui/ozone/platform/wayland/BUILD.gn index 578e7a50ab6787..10c1b6574c030b 100644 --- a/ui/ozone/platform/wayland/BUILD.gn +++ b/ui/ozone/platform/wayland/BUILD.gn @@ -197,6 +197,7 @@ source_set("wayland") { "//ui/base/cursor:theme_manager", "//ui/base/cursor/mojom:cursor_type", "//ui/base/dragdrop:types", + "//ui/base/dragdrop/mojom", "//ui/base/ime/linux", "//ui/events", "//ui/events:dom_keycode_converter", @@ -419,6 +420,7 @@ source_set("wayland_unittests") { "//ui/base:buildflags", "//ui/base/cursor", "//ui/base/dragdrop:types", + "//ui/base/dragdrop/mojom", "//ui/base/ime/linux", "//ui/events/ozone/layout", "//ui/gfx/linux:test_support", diff --git a/ui/ozone/platform/wayland/DEPS b/ui/ozone/platform/wayland/DEPS index a035c9180a4572..6d659e7a12dd62 100644 --- a/ui/ozone/platform/wayland/DEPS +++ b/ui/ozone/platform/wayland/DEPS @@ -8,6 +8,7 @@ include_rules = [ "+third_party/wayland", "+ui/base/clipboard/clipboard_constants.h", "+ui/base/dragdrop/drag_drop_types.h", + "+ui/base/dragdrop/mojom", "+ui/base/clipboard/file_info.h", "+ui/base/dragdrop/os_exchange_data.h", "+ui/base/dragdrop/os_exchange_data_provider_non_backed.h", diff --git a/ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc b/ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc index 56400fa70709e4..a6699db7dfd447 100644 --- a/ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc +++ b/ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc @@ -4,6 +4,7 @@ #include "ui/ozone/platform/wayland/host/wayland_data_drag_controller.h" +#include #include #include "base/check.h" @@ -13,6 +14,7 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_constants.h" #include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data_provider_non_backed.h" #include "ui/ozone/platform/wayland/common/data_util.h" @@ -26,9 +28,26 @@ #include "ui/ozone/platform/wayland/host/wayland_window_manager.h" namespace ui { - namespace { +using mojom::DragOperation; + +DragOperation DndActionToDragOperation(uint32_t action) { + // Prevent the usage of this function for an operation mask. + DCHECK_LE(std::bitset<32>(action).count(), 1u); + switch (action) { + case WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY: + return DragOperation::kCopy; + case WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE: + return DragOperation::kMove; + case WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK: + // Unsupported in the browser. + FALLTHROUGH; + default: + return DragOperation::kNone; + } +} + int DndActionsToDragOperations(uint32_t actions) { int operations = DragDropTypes::DRAG_NONE; if (actions & WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY) @@ -220,7 +239,8 @@ void WaylandDataDragController::OnDataSourceFinish(bool completed) { DCHECK(data_source_); if (origin_window_) { - origin_window_->OnDragSessionClose(data_source_->dnd_action()); + origin_window_->OnDragSessionClose( + DndActionToDragOperation(data_source_->dnd_action())); // DnD handlers expect DragLeave to be sent for drag sessions that end up // with no data transfer (wl_data_source::cancelled event). if (!completed) diff --git a/ui/ozone/platform/wayland/host/wayland_data_drag_controller_unittest.cc b/ui/ozone/platform/wayland/host/wayland_data_drag_controller_unittest.cc index cabd7bb976b6ad..23a0aed9b70373 100644 --- a/ui/ozone/platform/wayland/host/wayland_data_drag_controller_unittest.cc +++ b/ui/ozone/platform/wayland/host/wayland_data_drag_controller_unittest.cc @@ -16,6 +16,7 @@ #include "ui/base/clipboard/file_info.h" #include "ui/base/cursor/cursor.h" #include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/events/base_event_utils.h" #include "ui/gfx/geometry/point.h" @@ -40,13 +41,13 @@ #include "ui/platform_window/wm/wm_drop_handler.h" #include "url/gurl.h" -using testing::_; -using testing::Mock; - namespace ui { - namespace { +using mojom::DragOperation; +using ::testing::_; +using ::testing::Mock; + constexpr char kSampleTextForDragAndDrop[] = "This is a sample text for drag-and-drop."; @@ -69,9 +70,8 @@ PlatformClipboard::Data ToClipboardData(const StringType& data_string) { class MockDragHandlerDelegate : public WmDragHandler::Delegate { public: MOCK_METHOD1(OnDragLocationChanged, void(const gfx::Point& location)); - MOCK_METHOD1(OnDragOperationChanged, - void(DragDropTypes::DragOperation operation)); - MOCK_METHOD1(OnDragFinished, void(int operation)); + MOCK_METHOD1(OnDragOperationChanged, void(DragOperation operation)); + MOCK_METHOD1(OnDragFinished, void(DragOperation operation)); }; class MockDropHandler : public WmDropHandler { @@ -206,7 +206,9 @@ class WaylandDataDragControllerTest : public WaylandDragDropTest { // If DnD was cancelled, or data was dropped where it was not // accepted, the operation result must be None (0). // Regression test for https://crbug.com/1136751. - EXPECT_CALL(*self->drag_handler(), OnDragFinished(0)).Times(1); + EXPECT_CALL(*self->drag_handler(), + OnDragFinished(DragOperation::kNone)) + .Times(1); self->Sync(); }, diff --git a/ui/ozone/platform/wayland/host/wayland_window.cc b/ui/ozone/platform/wayland/host/wayland_window.cc index 813ad8e7c76125..8b689c59aae473 100644 --- a/ui/ozone/platform/wayland/host/wayland_window.cc +++ b/ui/ozone/platform/wayland/host/wayland_window.cc @@ -14,7 +14,7 @@ #include "build/chromeos_buildflags.h" #include "ui/base/cursor/mojom/cursor_type.mojom.h" #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" -#include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/events/event.h" #include "ui/events/event_utils.h" @@ -43,6 +43,7 @@ namespace ui { namespace { using mojom::CursorType; +using mojom::DragOperation; bool OverlayStackOrderCompare( const ui::ozone::mojom::WaylandOverlayConfigPtr& i, @@ -226,7 +227,7 @@ bool WaylandWindow::IsVisible() const { void WaylandWindow::PrepareForShutdown() { if (drag_handler_delegate_) - OnDragSessionClose(DragDropTypes::DRAG_NONE); + OnDragSessionClose(DragOperation::kNone); } void WaylandWindow::SetBounds(const gfx::Rect& bounds_px) { @@ -535,9 +536,9 @@ void WaylandWindow::OnDragLeave() { drop_handler->OnDragLeave(); } -void WaylandWindow::OnDragSessionClose(uint32_t dnd_action) { +void WaylandWindow::OnDragSessionClose(DragOperation operation) { DCHECK(drag_handler_delegate_); - drag_handler_delegate_->OnDragFinished(dnd_action); + drag_handler_delegate_->OnDragFinished(operation); drag_handler_delegate_ = nullptr; connection()->event_source()->ResetPointerFlags(); std::move(drag_loop_quit_closure_).Run(); diff --git a/ui/ozone/platform/wayland/host/wayland_window.h b/ui/ozone/platform/wayland/host/wayland_window.h index 3c810edca97991..cafe7042248e81 100644 --- a/ui/ozone/platform/wayland/host/wayland_window.h +++ b/ui/ozone/platform/wayland/host/wayland_window.h @@ -193,7 +193,7 @@ class WaylandWindow : public PlatformWindow, virtual int OnDragMotion(const gfx::PointF& point, int operation); virtual void OnDragDrop(); virtual void OnDragLeave(); - virtual void OnDragSessionClose(uint32_t dnd_action); + virtual void OnDragSessionClose(ui::mojom::DragOperation operation); virtual base::Optional> GetWindowShape() const; diff --git a/ui/platform_window/wm/BUILD.gn b/ui/platform_window/wm/BUILD.gn index 7f060579821794..bd8b4b4fa1290b 100644 --- a/ui/platform_window/wm/BUILD.gn +++ b/ui/platform_window/wm/BUILD.gn @@ -18,7 +18,7 @@ component("wm") { defines = [ "IS_WM_IMPL" ] - public_deps = [ "//ui/base/dragdrop:types" ] + public_deps = [ "//ui/base/dragdrop/mojom:mojom_headers" ] deps = [ "//ui/base", "//ui/platform_window", diff --git a/ui/platform_window/wm/wm_drag_handler.h b/ui/platform_window/wm/wm_drag_handler.h index 769554c400571d..f9fb0057fc3817 100644 --- a/ui/platform_window/wm/wm_drag_handler.h +++ b/ui/platform_window/wm/wm_drag_handler.h @@ -6,7 +6,7 @@ #define UI_PLATFORM_WINDOW_WM_WM_DRAG_HANDLER_H_ #include "base/component_export.h" -#include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-forward.h" #include "ui/gfx/native_widget_types.h" namespace gfx { @@ -25,10 +25,9 @@ class COMPONENT_EXPORT(WM) WmDragHandler { // Called every time when the drag location has changed. virtual void OnDragLocationChanged(const gfx::Point& screen_point_px) = 0; // Called when the currently negotiated operation has changed. - virtual void OnDragOperationChanged( - DragDropTypes::DragOperation operation) = 0; + virtual void OnDragOperationChanged(mojom::DragOperation operation) = 0; // Called once when the operation has finished. - virtual void OnDragFinished(int operation) = 0; + virtual void OnDragFinished(mojom::DragOperation operation) = 0; protected: virtual ~Delegate(); diff --git a/ui/platform_window/x11/BUILD.gn b/ui/platform_window/x11/BUILD.gn index dc65dc7a733019..0eaa528878fb11 100644 --- a/ui/platform_window/x11/BUILD.gn +++ b/ui/platform_window/x11/BUILD.gn @@ -20,6 +20,7 @@ component("x11") { "//ui/base:hit_test", "//ui/base:wm_role_names", "//ui/base/dragdrop:types", + "//ui/base/dragdrop/mojom", "//ui/base/x", "//ui/events", "//ui/events/devices", diff --git a/ui/platform_window/x11/x11_window.cc b/ui/platform_window/x11/x11_window.cc index 37649f7f332fcd..542546ad5a3357 100644 --- a/ui/platform_window/x11/x11_window.cc +++ b/ui/platform_window/x11/x11_window.cc @@ -13,6 +13,7 @@ #include "ui/base/buildflags.h" #include "ui/base/cursor/cursor.h" #include "ui/base/dragdrop/drag_drop_types.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/hit_test_x11.h" #include "ui/base/ui_base_features.h" @@ -50,9 +51,10 @@ #endif namespace ui { - namespace { +using mojom::DragOperation; + // Opacity for drag widget windows. constexpr float kDragWidgetOpacity = .75f; @@ -1328,7 +1330,7 @@ bool X11Window::StartDrag(const OSExchangeData& data, drag_handler_delegate_ = delegate; drag_drop_client_->InitDrag(operation, &data); - drag_operation_ = 0; + allowed_drag_operations_ = 0; notified_enter_ = false; drag_loop_ = std::make_unique(this); @@ -1385,14 +1387,13 @@ int X11Window::UpdateDrag(const gfx::Point& screen_point) { GetKeyModifiers(source_client)); notified_enter_ = true; } - drag_operation_ = drop_handler->OnDragMotion(gfx::PointF(screen_point), - suggested_operations, - GetKeyModifiers(source_client)); - return drag_operation_; + allowed_drag_operations_ = drop_handler->OnDragMotion( + gfx::PointF(screen_point), suggested_operations, + GetKeyModifiers(source_client)); + return allowed_drag_operations_; } -void X11Window::UpdateCursor( - DragDropTypes::DragOperation negotiated_operation) { +void X11Window::UpdateCursor(DragOperation negotiated_operation) { DCHECK(drag_handler_delegate_); drag_handler_delegate_->OnDragOperationChanged(negotiated_operation); } @@ -1415,10 +1416,10 @@ void X11Window::OnBeforeDragLeave() { notified_enter_ = false; } -int X11Window::PerformDrop() { +DragOperation X11Window::PerformDrop() { WmDropHandler* drop_handler = GetWmDropHandler(*this); if (!drop_handler || !notified_enter_) - return DragDropTypes::DRAG_NONE; + return DragOperation::kNone; // The drop data has been supplied on entering the window. The drop handler // should have it since then. @@ -1427,13 +1428,14 @@ int X11Window::PerformDrop() { drop_handler->OnDragDrop({}, GetKeyModifiers(XDragDropClient::GetForWindow( target_current_context->source_window()))); notified_enter_ = false; - return drag_operation_; + return PreferredDragOperation(allowed_drag_operations_); } void X11Window::EndDragLoop() { DCHECK(drag_handler_delegate_); - drag_handler_delegate_->OnDragFinished(drag_operation_); + drag_handler_delegate_->OnDragFinished( + PreferredDragOperation(allowed_drag_operations_)); drag_loop_->EndMoveLoop(); } diff --git a/ui/platform_window/x11/x11_window.h b/ui/platform_window/x11/x11_window.h index 3a78032d8467cc..5bc3079a3f583f 100644 --- a/ui/platform_window/x11/x11_window.h +++ b/ui/platform_window/x11/x11_window.h @@ -180,11 +180,11 @@ class X11_WINDOW_EXPORT X11Window // XDragDropClient::Delegate std::unique_ptr CreateWindowFinder() override; int UpdateDrag(const gfx::Point& screen_point) override; - void UpdateCursor(DragDropTypes::DragOperation negotiated_operation) override; + void UpdateCursor(mojom::DragOperation negotiated_operation) override; void OnBeginForeignDrag(x11::Window window) override; void OnEndForeignDrag() override; void OnBeforeDragLeave() override; - int PerformDrop() override; + mojom::DragOperation PerformDrop() override; void EndDragLoop() override; // X11MoveLoopDelegate @@ -327,8 +327,8 @@ class X11_WINDOW_EXPORT X11Window // Whether the drop handler has notified that the drag has entered. bool notified_enter_ = false; - // Keeps the last negotiated operation returned by the drop handler. - int drag_operation_ = 0; + // Keeps the last negotiated operations returned by the drop handler. + int allowed_drag_operations_ = 0; // Handles XDND events going through this window. std::unique_ptr drag_drop_client_; diff --git a/ui/views/BUILD.gn b/ui/views/BUILD.gn index d2b12c79e285bd..8b76846502100c 100644 --- a/ui/views/BUILD.gn +++ b/ui/views/BUILD.gn @@ -852,6 +852,7 @@ component("views") { "widget/desktop_aura/window_shape_updater.cc", "widget/desktop_aura/window_shape_updater.h", ] + public_deps += [ "//ui/base/dragdrop/mojom:mojom_shared" ] } if (use_atk) { sources += [ diff --git a/ui/views/controls/button/menu_button_unittest.cc b/ui/views/controls/button/menu_button_unittest.cc index 1b0383dbf26d2d..a98c99b9ca8092 100644 --- a/ui/views/controls/button/menu_button_unittest.cc +++ b/ui/views/controls/button/menu_button_unittest.cc @@ -30,10 +30,11 @@ #include "ui/events/event_handler.h" #endif -using base::ASCIIToUTF16; - namespace views { +using ::base::ASCIIToUTF16; +using ::ui::mojom::DragOperation; + class TestMenuButton : public MenuButton { public: TestMenuButton() @@ -189,12 +190,12 @@ class TestDragDropClient : public aura::client::DragDropClient, ~TestDragDropClient() override; // aura::client::DragDropClient: - int StartDragAndDrop(std::unique_ptr data, - aura::Window* root_window, - aura::Window* source_window, - const gfx::Point& screen_location, - int operation, - ui::mojom::DragEventSource source) override; + DragOperation StartDragAndDrop(std::unique_ptr data, + aura::Window* root_window, + aura::Window* source_window, + const gfx::Point& screen_location, + int allowed_operations, + ui::mojom::DragEventSource source) override; void DragCancel() override; bool IsDragDropInProgress() override; void AddObserver(aura::client::DragDropClientObserver* observer) override {} @@ -216,18 +217,18 @@ TestDragDropClient::TestDragDropClient() = default; TestDragDropClient::~TestDragDropClient() = default; -int TestDragDropClient::StartDragAndDrop( +DragOperation TestDragDropClient::StartDragAndDrop( std::unique_ptr data, aura::Window* root_window, aura::Window* source_window, const gfx::Point& screen_location, - int operation, + int allowed_operations, ui::mojom::DragEventSource source) { if (IsDragDropInProgress()) - return ui::DragDropTypes::DRAG_NONE; + return DragOperation::kNone; drag_in_progress_ = true; target_ = root_window; - return operation; + return ui::PreferredDragOperation(allowed_operations); } void TestDragDropClient::DragCancel() { diff --git a/ui/views/controls/menu/menu_controller_unittest.cc b/ui/views/controls/menu/menu_controller_unittest.cc index 23d0bd6f82ad7a..0dd94b5c04e0db 100644 --- a/ui/views/controls/menu/menu_controller_unittest.cc +++ b/ui/views/controls/menu/menu_controller_unittest.cc @@ -69,9 +69,10 @@ namespace views { namespace test { - namespace { +using ::ui::mojom::DragOperation; + bool ShouldIgnoreScreenBoundsForMenus() { #if defined(USE_OZONE) if (features::IsUsingOzonePlatform()) { @@ -205,12 +206,12 @@ class TestDragDropClient : public aura::client::DragDropClient { ~TestDragDropClient() override = default; // aura::client::DragDropClient: - int StartDragAndDrop(std::unique_ptr data, - aura::Window* root_window, - aura::Window* source_window, - const gfx::Point& screen_location, - int operation, - ui::mojom::DragEventSource source) override; + DragOperation StartDragAndDrop(std::unique_ptr data, + aura::Window* root_window, + aura::Window* source_window, + const gfx::Point& screen_location, + int allowed_operations, + ui::mojom::DragEventSource source) override; void DragCancel() override; bool IsDragDropInProgress() override; @@ -225,16 +226,16 @@ class TestDragDropClient : public aura::client::DragDropClient { DISALLOW_COPY_AND_ASSIGN(TestDragDropClient); }; -int TestDragDropClient::StartDragAndDrop( +DragOperation TestDragDropClient::StartDragAndDrop( std::unique_ptr data, aura::Window* root_window, aura::Window* source_window, const gfx::Point& screen_location, - int operation, + int allowed_operations, ui::mojom::DragEventSource source) { drag_in_progress_ = true; start_drag_and_drop_callback_.Run(); - return 0; + return DragOperation::kNone; } void TestDragDropClient::DragCancel() { diff --git a/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone.cc b/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone.cc index 0bac1fd035a91e..a7c0701db43294 100644 --- a/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone.cc +++ b/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone.cc @@ -21,6 +21,7 @@ #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" #include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/dragdrop/drop_target_event.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h" #include "ui/base/layout.h" #include "ui/base/ui_base_features.h" #include "ui/display/screen.h" @@ -30,9 +31,10 @@ #include "ui/views/widget/widget.h" namespace views { - namespace { +using ::ui::mojom::DragOperation; + aura::Window* GetTargetWindow(aura::Window* root_window, const gfx::Point& point) { gfx::Point root_location(point); @@ -119,15 +121,15 @@ DesktopDragDropClientOzone::~DesktopDragDropClientOzone() { ResetDragDropTarget(true); } -int DesktopDragDropClientOzone::StartDragAndDrop( +DragOperation DesktopDragDropClientOzone::StartDragAndDrop( std::unique_ptr data, aura::Window* root_window, aura::Window* source_window, const gfx::Point& root_location, - int operation, + int allowed_operations, ui::mojom::DragEventSource source) { if (!drag_handler_) - return ui::DragDropTypes::DragOperation::DRAG_NONE; + return DragOperation::kNone; DCHECK(!drag_context_); drag_context_ = std::make_unique(); @@ -142,7 +144,6 @@ int DesktopDragDropClientOzone::StartDragAndDrop( aura::client::GetCursorClient(root_window); auto initial_cursor = source_window->GetHost()->last_cursor(); - drag_operation_ = operation; if (cursor_client) { cursor_client->SetCursor(ui::mojom::CursorType::kGrabbing); } @@ -164,14 +165,14 @@ int DesktopDragDropClientOzone::StartDragAndDrop( auto alive = weak_factory_.GetWeakPtr(); const bool drag_succeeded = drag_handler_->StartDrag( - *data.get(), operation, cursor_client->GetCursor(), + *data.get(), allowed_operations, cursor_client->GetCursor(), !source_window->HasCapture(), this); if (!alive) - return ui::DragDropTypes::DRAG_NONE; + return DragOperation::kNone; if (!drag_succeeded) - drag_operation_ = ui::DragDropTypes::DRAG_NONE; + drag_operation_ = DragOperation::kNone; if (cursor_client) cursor_client->SetCursor(initial_cursor); @@ -185,7 +186,7 @@ void DesktopDragDropClientOzone::DragCancel() { return; drag_handler_->CancelDrag(); - drag_operation_ = ui::DragDropTypes::DRAG_NONE; + drag_operation_ = DragOperation::kNone; } bool DesktopDragDropClientOzone::IsDragDropInProgress() { @@ -308,7 +309,7 @@ void DesktopDragDropClientOzone::OnDragLocationChanged( } void DesktopDragDropClientOzone::OnDragOperationChanged( - ui::DragDropTypes::DragOperation operation) { + DragOperation operation) { aura::client::CursorClient* cursor_client = aura::client::GetCursorClient(root_window_); if (!cursor_client) @@ -316,24 +317,24 @@ void DesktopDragDropClientOzone::OnDragOperationChanged( ui::mojom::CursorType cursor_type = ui::mojom::CursorType::kNull; switch (operation) { - case ui::DragDropTypes::DRAG_NONE: + case DragOperation::kNone: cursor_type = ui::mojom::CursorType::kDndNone; break; - case ui::DragDropTypes::DRAG_MOVE: + case DragOperation::kMove: cursor_type = ui::mojom::CursorType::kDndMove; break; - case ui::DragDropTypes::DRAG_COPY: + case DragOperation::kCopy: cursor_type = ui::mojom::CursorType::kDndCopy; break; - case ui::DragDropTypes::DRAG_LINK: + case DragOperation::kLink: cursor_type = ui::mojom::CursorType::kDndLink; break; } cursor_client->SetCursor(cursor_type); } -void DesktopDragDropClientOzone::OnDragFinished(int dnd_action) { - drag_operation_ = dnd_action; +void DesktopDragDropClientOzone::OnDragFinished(DragOperation operation) { + drag_operation_ = operation; } std::unique_ptr diff --git a/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone.h b/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone.h index 3fe03e664576aa..8fc0bdccfd1470 100644 --- a/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone.h +++ b/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone.h @@ -12,6 +12,7 @@ #include "ui/aura/client/drag_drop_client.h" #include "ui/aura/window_observer.h" #include "ui/base/cursor/cursor.h" +#include "ui/base/dragdrop/mojom/drag_drop_types.mojom-shared.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/gfx/geometry/point_f.h" #include "ui/gfx/native_widget_types.h" @@ -70,12 +71,13 @@ class VIEWS_EXPORT DesktopDragDropClientOzone }; // aura::client::DragDropClient - int StartDragAndDrop(std::unique_ptr data, - aura::Window* root_window, - aura::Window* source_window, - const gfx::Point& root_location, - int operation, - ui::mojom::DragEventSource source) override; + ui::mojom::DragOperation StartDragAndDrop( + std::unique_ptr data, + aura::Window* root_window, + aura::Window* source_window, + const gfx::Point& root_location, + int allowed_operations, + ui::mojom::DragEventSource source) override; void DragCancel() override; bool IsDragDropInProgress() override; void AddObserver(aura::client::DragDropClientObserver* observer) override; @@ -98,9 +100,8 @@ class VIEWS_EXPORT DesktopDragDropClientOzone // ui::WmDragHandler::Delegate void OnDragLocationChanged(const gfx::Point& screen_point_px) override; - void OnDragOperationChanged( - ui::DragDropTypes::DragOperation operation) override; - void OnDragFinished(int operation) override; + void OnDragOperationChanged(ui::mojom::DragOperation operation) override; + void OnDragFinished(ui::mojom::DragOperation operation) override; // Returns a DropTargetEvent to be passed to the DragDropDelegate. // Updates the delegate if needed, which in its turn calls their @@ -141,8 +142,8 @@ class VIEWS_EXPORT DesktopDragDropClientOzone // used at dropping. int last_drop_operation_ = 0; - // The operation bitfield. - int drag_operation_ = 0; + // The selected operation on drop. + ui::mojom::DragOperation drag_operation_ = ui::mojom::DragOperation::kNone; std::unique_ptr drag_context_; diff --git a/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone_unittest.cc b/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone_unittest.cc index 5dc374eee19ef2..20cd8d3f5cc84d 100644 --- a/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone_unittest.cc +++ b/ui/views/widget/desktop_aura/desktop_drag_drop_client_ozone_unittest.cc @@ -123,8 +123,8 @@ class FakePlatformWindow : public ui::PlatformWindow, public ui::WmDragHandler { drop_handler->OnDragLeave(); } - void CloseDrag(uint32_t dnd_action) { - drag_handler_delegate_->OnDragFinished(dnd_action); + void CloseDrag(DragOperation operation) { + drag_handler_delegate_->OnDragFinished(operation); std::move(drag_loop_quit_closure_).Run(); } @@ -133,7 +133,7 @@ class FakePlatformWindow : public ui::PlatformWindow, public ui::WmDragHandler { int updated_operation = OnDragMotion(gfx::PointF(), operation); OnDragDrop(nullptr); OnDragLeave(); - CloseDrag(updated_operation); + CloseDrag(ui::PreferredDragOperation(updated_operation)); } private: @@ -231,7 +231,7 @@ class DesktopDragDropClientOzoneTest : public ViewsTestBase { platform_window_->set_modifiers(modifiers); } - int StartDragAndDrop(int operation) { + DragOperation StartDragAndDrop(int allowed_operations) { auto data = std::make_unique(); data->SetString(u"Test"); SkBitmap drag_bitmap; @@ -242,7 +242,7 @@ class DesktopDragDropClientOzoneTest : public ViewsTestBase { return client_->StartDragAndDrop( std::move(data), widget_->GetNativeWindow()->GetRootWindow(), - widget_->GetNativeWindow(), gfx::Point(), operation, + widget_->GetNativeWindow(), gfx::Point(), allowed_operations, ui::mojom::DragEventSource::kMouse); } @@ -298,10 +298,10 @@ TEST_F(DesktopDragDropClientOzoneTest, DISABLED_StartDrag) { // Set the operation which the destination can accept. dragdrop_delegate_->SetOperation(DragOperation::kCopy); // Start Drag and Drop with the operations suggested. - int operation = StartDragAndDrop(ui::DragDropTypes::DRAG_COPY | - ui::DragDropTypes::DRAG_MOVE); + DragOperation operation = StartDragAndDrop(ui::DragDropTypes::DRAG_COPY | + ui::DragDropTypes::DRAG_MOVE); // The |operation| decided through negotiation should be 'DRAG_COPY'. - EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, operation); + EXPECT_EQ(DragOperation::kCopy, operation); EXPECT_EQ(1, dragdrop_delegate_->num_enters()); EXPECT_EQ(1, dragdrop_delegate_->num_updates()); @@ -317,10 +317,10 @@ TEST_F(DesktopDragDropClientOzoneTest, DISABLED_StartDragCtrlPressed) { // Set the operation which the destination can accept. dragdrop_delegate_->SetOperation(DragOperation::kCopy); // Start Drag and Drop with the operations suggested. - int operation = StartDragAndDrop(ui::DragDropTypes::DRAG_COPY | - ui::DragDropTypes::DRAG_MOVE); + DragOperation operation = StartDragAndDrop(ui::DragDropTypes::DRAG_COPY | + ui::DragDropTypes::DRAG_MOVE); // The |operation| decided through negotiation should be 'DRAG_COPY'. - EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, operation); + EXPECT_EQ(DragOperation::kCopy, operation); EXPECT_EQ(1, dragdrop_delegate_->num_enters()); EXPECT_EQ(1, dragdrop_delegate_->num_updates()); diff --git a/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.cc b/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.cc index 92a9e033a00344..90457093d4e600 100644 --- a/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.cc +++ b/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.cc @@ -25,7 +25,6 @@ DesktopDragDropClientWin::DesktopDragDropClientWin( HWND window, DesktopWindowTreeHostWin* desktop_host) : drag_drop_in_progress_(false), - drag_operation_(0), desktop_host_(desktop_host) { drop_target_ = new DesktopDropTargetWin(root_window); drop_target_->Init(window); @@ -36,15 +35,14 @@ DesktopDragDropClientWin::~DesktopDragDropClientWin() { DragCancel(); } -int DesktopDragDropClientWin::StartDragAndDrop( +ui::mojom::DragOperation DesktopDragDropClientWin::StartDragAndDrop( std::unique_ptr data, aura::Window* root_window, aura::Window* source_window, const gfx::Point& screen_location, - int operation, + int allowed_operations, ui::mojom::DragEventSource source) { drag_drop_in_progress_ = true; - drag_operation_ = operation; if (source == ui::mojom::DragEventSource::kTouch) { gfx::Point screen_point = display::win::ScreenWin::DIPToScreenPoint( {screen_location.x(), screen_location.y()}); @@ -78,7 +76,8 @@ int DesktopDragDropClientWin::StartDragAndDrop( HRESULT result = ::DoDragDrop( ui::OSExchangeDataProviderWin::GetIDataObject(*data.get()), drag_source_.Get(), - ui::DragDropTypes::DragOperationToDropEffect(operation), &effect); + ui::DragDropTypes::DragOperationToDropEffect(allowed_operations), + &effect); if (alive && source == ui::mojom::DragEventSource::kTouch) { // In a normal drag drop, ::DoDragDrop calls QueryContinueDrag every time // it gets a mouse or keyboard event. The windows doc @@ -109,12 +108,12 @@ int DesktopDragDropClientWin::StartDragAndDrop( if (result != DRAGDROP_S_DROP) effect = DROPEFFECT_NONE; - return ui::DragDropTypes::DropEffectToDragOperation(effect); + return ui::PreferredDragOperation( + ui::DragDropTypes::DropEffectToDragOperation(effect)); } void DesktopDragDropClientWin::DragCancel() { drag_source_->CancelDrag(); - drag_operation_ = 0; } bool DesktopDragDropClientWin::IsDragDropInProgress() { diff --git a/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h b/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h index 644de0cd15c7b7..34ec49256262cb 100644 --- a/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h +++ b/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h @@ -39,12 +39,13 @@ class VIEWS_EXPORT DesktopDragDropClientWin ~DesktopDragDropClientWin() override; // Overridden from aura::client::DragDropClient: - int StartDragAndDrop(std::unique_ptr data, - aura::Window* root_window, - aura::Window* source_window, - const gfx::Point& screen_location, - int operation, - ui::mojom::DragEventSource source) override; + ui::mojom::DragOperation StartDragAndDrop( + std::unique_ptr data, + aura::Window* root_window, + aura::Window* source_window, + const gfx::Point& screen_location, + int allowed_operations, + ui::mojom::DragEventSource source) override; void DragCancel() override; bool IsDragDropInProgress() override; void AddObserver(aura::client::DragDropClientObserver* observer) override; @@ -55,8 +56,6 @@ class VIEWS_EXPORT DesktopDragDropClientWin private: bool drag_drop_in_progress_; - int drag_operation_; - Microsoft::WRL::ComPtr drag_source_; scoped_refptr drop_target_; diff --git a/ui/views/widget/desktop_aura/x11_drag_drop_client_unittest.cc b/ui/views/widget/desktop_aura/x11_drag_drop_client_unittest.cc index d7644374df9d6e..b7df853049673b 100644 --- a/ui/views/widget/desktop_aura/x11_drag_drop_client_unittest.cc +++ b/ui/views/widget/desktop_aura/x11_drag_drop_client_unittest.cc @@ -43,9 +43,10 @@ #include "ui/views/widget/widget.h" namespace views { - namespace { +using ::ui::mojom::DragOperation; + class TestDragDropClient; // Collects messages which would otherwise be sent to |window_| via @@ -119,12 +120,12 @@ class SimpleTestDragDropClient : public aura::client::DragDropClient, bool IsMoveLoopRunning(); // aura::client::DragDropClient: - int StartDragAndDrop(std::unique_ptr data, - aura::Window* root_window, - aura::Window* source_window, - const gfx::Point& screen_location, - int operation, - ui::mojom::DragEventSource source) override; + DragOperation StartDragAndDrop(std::unique_ptr data, + aura::Window* root_window, + aura::Window* source_window, + const gfx::Point& screen_location, + int allowed_operations, + ui::mojom::DragEventSource source) override; void DragCancel() override; bool IsDragDropInProgress() override; void AddObserver(aura::client::DragDropClientObserver* observer) override; @@ -134,12 +135,11 @@ class SimpleTestDragDropClient : public aura::client::DragDropClient, // ui::XDragDropClient::Delegate: std::unique_ptr CreateWindowFinder() override; int UpdateDrag(const gfx::Point& screen_point) override; - void UpdateCursor( - ui::DragDropTypes::DragOperation negotiated_operation) override; + void UpdateCursor(DragOperation negotiated_operation) override; void OnBeginForeignDrag(x11::Window window) override; void OnEndForeignDrag() override; void OnBeforeDragLeave() override; - int PerformDrop() override; + DragOperation PerformDrop() override; void EndDragLoop() override; // XDragDropClient: @@ -306,14 +306,14 @@ std::unique_ptr SimpleTestDragDropClient::CreateMoveLoop( return base::WrapUnique(loop_); } -int SimpleTestDragDropClient::StartDragAndDrop( +DragOperation SimpleTestDragDropClient::StartDragAndDrop( std::unique_ptr data, aura::Window* root_window, aura::Window* source_window, const gfx::Point& screen_location, - int operation, + int allowed_operations, ui::mojom::DragEventSource source) { - InitDrag(operation, data.get()); + InitDrag(allowed_operations, data.get()); auto loop = CreateMoveLoop(this); @@ -351,12 +351,12 @@ SimpleTestDragDropClient::CreateWindowFinder() { return {}; } void SimpleTestDragDropClient::UpdateCursor( - ui::DragDropTypes::DragOperation negotiated_operation) {} + DragOperation negotiated_operation) {} void SimpleTestDragDropClient::OnBeginForeignDrag(x11::Window window) {} void SimpleTestDragDropClient::OnEndForeignDrag() {} void SimpleTestDragDropClient::OnBeforeDragLeave() {} -int SimpleTestDragDropClient::PerformDrop() { - return 0; +DragOperation SimpleTestDragDropClient::PerformDrop() { + return DragOperation::kNone; } void SimpleTestDragDropClient::EndDragLoop() { // std::move(quit_closure_).Run(); @@ -462,7 +462,7 @@ class X11DragDropClientTest : public ViewsTestBase { X11DragDropClientTest() = default; ~X11DragDropClientTest() override = default; - int StartDragAndDrop() { + DragOperation StartDragAndDrop() { auto data(std::make_unique()); data->SetString(u"Test"); SkBitmap drag_bitmap; @@ -605,15 +605,15 @@ TEST_F(X11DragDropClientTest, Basic) { base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&BasicStep2, client(), toplevel)); - int result = StartDragAndDrop(); - EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); + DragOperation result = StartDragAndDrop(); + EXPECT_EQ(DragOperation::kCopy, result); // Do another drag and drop to test that the data is properly cleaned up as a // result of the XdndFinished message. base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&BasicStep3, client(), toplevel)); result = StartDragAndDrop(); - EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); + EXPECT_EQ(DragOperation::kCopy, result); } namespace { @@ -646,8 +646,8 @@ void TargetDoesNotRespondStep2(TestDragDropClient* client) { TEST_F(X11DragDropClientTest, TargetDoesNotRespond) { base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&TargetDoesNotRespondStep2, client())); - int result = StartDragAndDrop(); - EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); + DragOperation result = StartDragAndDrop(); + EXPECT_EQ(DragOperation::kNone, result); } namespace { @@ -691,8 +691,8 @@ void QueuePositionStep2(TestDragDropClient* client) { TEST_F(X11DragDropClientTest, QueuePosition) { base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&QueuePositionStep2, client())); - int result = StartDragAndDrop(); - EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); + DragOperation result = StartDragAndDrop(); + EXPECT_EQ(DragOperation::kCopy, result); } namespace { @@ -743,8 +743,8 @@ void TargetChangesStep2(TestDragDropClient* client) { TEST_F(X11DragDropClientTest, TargetChanges) { base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&TargetChangesStep2, client())); - int result = StartDragAndDrop(); - EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, result); + DragOperation result = StartDragAndDrop(); + EXPECT_EQ(DragOperation::kCopy, result); } namespace { @@ -812,14 +812,14 @@ void RejectAfterMouseReleaseStep3(TestDragDropClient* client) { TEST_F(X11DragDropClientTest, RejectAfterMouseRelease) { base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&RejectAfterMouseReleaseStep2, client())); - int result = StartDragAndDrop(); - EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); + DragOperation result = StartDragAndDrop(); + EXPECT_EQ(DragOperation::kNone, result); // Repeat the test but reject the drop in the XdndFinished message instead. base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&RejectAfterMouseReleaseStep3, client())); result = StartDragAndDrop(); - EXPECT_EQ(ui::DragDropTypes::DRAG_NONE, result); + EXPECT_EQ(DragOperation::kNone, result); } } // namespace views