Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Unified Diff: ui/views/mus/native_widget_mus.cc

Issue 2266603002: mus: Implement interwindow drag and drop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Uploaded for a few comments. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/mus/native_widget_mus.cc
diff --git a/ui/views/mus/native_widget_mus.cc b/ui/views/mus/native_widget_mus.cc
index c98fa9069cae6021d5ddbccf1c0f4f39080412aa..05460dde0e5eef1b0c2ef053454a37788d8f6b70 100644
--- a/ui/views/mus/native_widget_mus.cc
+++ b/ui/views/mus/native_widget_mus.cc
@@ -32,9 +32,12 @@
#include "ui/gfx/path.h"
#include "ui/native_theme/native_theme_aura.h"
#include "ui/platform_window/platform_window_delegate.h"
+#include "ui/views/mus/drop_target_mus.h"
+#include "ui/views/mus/os_exchange_data_provider_mus.h"
#include "ui/views/mus/window_manager_constants_converters.h"
#include "ui/views/mus/window_manager_frame_values.h"
#include "ui/views/mus/window_tree_host_mus.h"
+#include "ui/views/widget/drop_helper.h"
#include "ui/views/widget/native_widget_aura.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/window/custom_frame_view.h"
@@ -522,6 +525,7 @@ NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate,
show_state_before_fullscreen_(ui::mojom::ShowState::DEFAULT),
ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
content_(new aura::Window(this)),
+ last_drop_operation_(ui::DragDropTypes::DRAG_NONE),
close_widget_factory_(this) {
window_->set_input_event_handler(this);
mus_window_observer_.reset(new MusWindowObserver(this));
@@ -696,6 +700,13 @@ void NativeWidgetMus::InitNativeWidget(const Widget::InitParams& params) {
aura::client::SetScreenPositionClient(hosted_window,
screen_position_client_.get());
+ // TODO(erg): Create and call CreateDragDropClient() here for maximum aura.
+
+ drop_target_.reset(new DropTargetMus(content_));
+ window_->SetCanAcceptDrags(drop_target_.get());
+ drop_helper_.reset(new DropHelper(GetWidget()->GetRootView()));
+ aura::client::SetDragDropDelegate(content_, this);
+
// TODO(erg): Remove this check when ash/mus/move_event_handler.cc's
// direct usage of ui::Window::SetPredefinedCursor() is switched to a
// private method on WindowManagerClient.
@@ -1117,13 +1128,33 @@ void NativeWidgetMus::FlashFrame(bool flash_frame) {
// NOTIMPLEMENTED();
}
-void NativeWidgetMus::RunShellDrag(
- View* view,
- const ui::OSExchangeData& data,
- const gfx::Point& location,
- int operation,
- ui::DragDropTypes::DragEventSource source) {
- // NOTIMPLEMENTED();
+void NativeWidgetMus::RunShellDrag(View* view,
+ const ui::OSExchangeData& data,
+ const gfx::Point& location,
+ int drag_operations,
+ ui::DragDropTypes::DragEventSource source) {
+ ReleaseCapture();
+
+ base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
+ base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
+ base::RunLoop run_loop;
+
+ std::map<std::string, std::vector<uint8_t>> drag_data =
+ static_cast<const OSExchangeDataProviderMus&>(data.provider()).GetData();
+
+ // TODO(erg): Right now, I'm passing the cursor_location, but maybe I want to
+ // pass OSExchangeData::GetDragImageOffset() instead?
+
+ bool success = false;
+ gfx::Point cursor_location = location;
+ window_->PerformDragDrop(
+ drag_data, drag_operations, cursor_location,
+ *data.provider().GetDragImage().bitmap(),
+ base::Bind(OnMoveLoopEnd, &success, run_loop.QuitClosure()));
+
+ run_loop.Run();
+
+ // In the aura version, we just throw the return code away.
}
void NativeWidgetMus::SchedulePaintInRect(const gfx::Rect& rect) {
@@ -1377,6 +1408,38 @@ void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) {
GetWidget()->Close();
}
+////////////////////////////////////////////////////////////////////////////////
+// NativeWidgetMus, aura::WindowDragDropDelegate implementation:
+
+void NativeWidgetMus::OnDragEntered(const ui::DropTargetEvent& event) {
+ DCHECK(drop_helper_);
+ last_drop_operation_ = drop_helper_->OnDragOver(
+ event.data(), event.location(), event.source_operations());
+}
+
+int NativeWidgetMus::OnDragUpdated(const ui::DropTargetEvent& event) {
+ DCHECK(drop_helper_);
+ last_drop_operation_ = drop_helper_->OnDragOver(
+ event.data(), event.location(), event.source_operations());
+ return last_drop_operation_;
+}
+
+void NativeWidgetMus::OnDragExited() {
+ DCHECK(drop_helper_);
+ drop_helper_->OnDragExit();
+}
+
+int NativeWidgetMus::OnPerformDrop(const ui::DropTargetEvent& event) {
+ DCHECK(drop_helper_);
+ // if (ShouldActivate())
+ // Activate();
+ return drop_helper_->OnDrop(event.data(), event.location(),
+ last_drop_operation_);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NativeWidgetMus, ui::InputEventHandler implementation:
+
void NativeWidgetMus::OnWindowInputEvent(
ui::Window* view,
const ui::Event& event_in,

Powered by Google App Engine
This is Rietveld 408576698