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

Side by Side Diff: ui/views/mus/drag_drop_client_mus.cc

Issue 2323553002: mash: Use the new mus drag and drop API to get drag working in mash. (Closed)
Patch Set: another make unique Created 4 years, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/mus/drag_drop_client_mus.h"
6
7 #include <map>
8 #include <string>
9 #include <vector>
10
11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h"
13 #include "services/ui/public/cpp/window.h"
14 #include "ui/aura/window.h"
15 #include "ui/views/mus/os_exchange_data_provider_mus.h"
16
17 namespace views {
18 namespace {
19
20 DragDropClientMus* current_dragging_client = nullptr;
21
22 } // namespace
23
24 DragDropClientMus::DragDropClientMus(ui::Window* ui_window)
25 : ui_window_(ui_window) {}
26
27 DragDropClientMus::~DragDropClientMus() {}
28
29 int DragDropClientMus::StartDragAndDrop(
30 const ui::OSExchangeData& data,
31 aura::Window* root_window,
32 aura::Window* source_window,
33 const gfx::Point& screen_location,
34 int drag_operations,
35 ui::DragDropTypes::DragEventSource source) {
36 std::map<std::string, std::vector<uint8_t>> drag_data =
37 static_cast<const OSExchangeDataProviderMus&>(data.provider()).GetData();
38
39 // TODO(erg): Right now, I'm passing the cursor_location, but maybe I want to
40 // pass OSExchangeData::GetDragImageOffset() instead?
41
42 bool success = false;
43 gfx::Point cursor_location = screen_location;
44 uint32_t action_taken = ui::mojom::kDropEffectNone;
45 current_dragging_client = this;
46 ui_window_->PerformDragDrop(
47 drag_data, drag_operations, cursor_location,
48 *data.provider().GetDragImage().bitmap(),
49 base::Bind(&DragDropClientMus::OnMoveLoopEnd, base::Unretained(this),
50 &success, &action_taken));
51
52 base::MessageLoop* loop = base::MessageLoop::current();
53 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop);
54 base::RunLoop run_loop;
55
56 runloop_quit_closure_ = run_loop.QuitClosure();
57 run_loop.Run();
58 current_dragging_client = nullptr;
59
60 return action_taken;
61 }
62
63 void DragDropClientMus::DragUpdate(aura::Window* target,
64 const ui::LocatedEvent& event) {
65 // Only called on OSX.
66 NOTREACHED();
67 }
68
69 void DragDropClientMus::Drop(aura::Window* target,
70 const ui::LocatedEvent& event) {
71 // Only called on OSX.
72 NOTREACHED();
73 }
74
75 void DragDropClientMus::DragCancel() {
76 ui_window_->CancelDragDrop();
77 }
78
79 bool DragDropClientMus::IsDragDropInProgress() {
80 return !!current_dragging_client;
81 }
82
83 void DragDropClientMus::OnMoveLoopEnd(bool* out_success,
84 uint32_t* out_action,
85 bool in_success,
86 uint32_t in_action) {
87 *out_success = in_success;
88 *out_action = in_action;
89 runloop_quit_closure_.Run();
90 }
91
92 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698