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

Side by Side Diff: ui/views/mus/drop_target_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, 3 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/drop_target_mus.h"
6
7 #include "services/ui/public/interfaces/window_tree_constants.mojom.h"
8 #include "ui/aura/window.h"
9 #include "ui/aura/window_tree_host.h"
10 #include "ui/base/dragdrop/drag_drop_types.h"
11 #include "ui/base/dragdrop/drop_target_event.h"
12 #include "ui/views/mus/os_exchange_data_provider_mus.h"
13 #include "ui/wm/public/drag_drop_client.h"
14 #include "ui/wm/public/drag_drop_delegate.h"
15
16 namespace views {
17
18 static_assert(ui::DragDropTypes::DRAG_NONE == ui::mojom::kDropEffectNone,
19 "Drag constants must be the same");
20 static_assert(ui::DragDropTypes::DRAG_MOVE == ui::mojom::kDropEffectMove,
21 "Drag constants must be the same");
22 static_assert(ui::DragDropTypes::DRAG_COPY == ui::mojom::kDropEffectCopy,
23 "Drag constants must be the same");
24 static_assert(ui::DragDropTypes::DRAG_LINK == ui::mojom::kDropEffectLink,
25 "Drag constants must be the same");
26
27 // TODO(erg): Pass in an aura root_window from the caller?
28 DropTargetMus::DropTargetMus(aura::Window* root_window)
29 : root_window_(root_window), target_window_(nullptr) {}
30
31 DropTargetMus::~DropTargetMus() {}
32
33 // TODO(erg): |mime_data| could be arbitrarily large. Maybe try to elide
34 // sending it when target window == source window?
35
36 void DropTargetMus::Translate(uint32_t key_state,
37 const gfx::Point& point,
38 uint32_t effect,
39 std::unique_ptr<ui::OSExchangeData>* data,
40 std::unique_ptr<ui::DropTargetEvent>* event,
41 aura::client::DragDropDelegate** delegate) {
42 gfx::Point location = point;
43 gfx::Point root_location = location;
44 root_window_->GetHost()->ConvertPointFromNativeScreen(&root_location);
45 aura::Window* target_window =
46 root_window_->GetEventHandlerForPoint(root_location);
47 bool target_window_changed = false;
48 if (target_window != target_window_) {
49 if (target_window_)
50 NotifyDragLeave();
51 target_window_ = target_window;
52 if (target_window_)
53 target_window_->AddObserver(this);
54 target_window_changed = true;
55 }
56 *delegate = NULL;
57 if (!target_window_)
58 return;
59 *delegate = aura::client::GetDragDropDelegate(target_window_);
60 if (!*delegate)
61 return;
62
63 data->reset(new ui::OSExchangeData(
64 base::MakeUnique<OSExchangeDataProviderMus>(mime_data_)));
65 location = root_location;
66 aura::Window::ConvertPointToTarget(root_window_, target_window_, &location);
67 event->reset(
68 new ui::DropTargetEvent(*(data->get()), location, root_location, effect));
69 (*event)->set_flags(key_state);
70 if (target_window_changed)
71 (*delegate)->OnDragEntered(*event->get());
72 }
73
74 void DropTargetMus::NotifyDragLeave() {
75 if (!target_window_)
76 return;
77
78 aura::client::DragDropDelegate* delegate =
79 aura::client::GetDragDropDelegate(target_window_);
80 if (delegate)
81 delegate->OnDragExited();
82
83 target_window_->RemoveObserver(this);
84 target_window_ = NULL;
85 }
86
87 uint32_t DropTargetMus::OnDragEnter(
88 std::map<std::string, std::vector<uint8_t>> mime_data,
89 uint32_t key_state,
90 const gfx::Point& position,
91 uint32_t effect_bitmask) {
92 // We store the mime data here because we need to access it during each phase
93 // of the drag, but we also don't move the data cross-process multiple times.
94 mime_data_ = std::move(mime_data);
95
96 std::unique_ptr<ui::OSExchangeData> data;
97 std::unique_ptr<ui::DropTargetEvent> event;
98 aura::client::DragDropDelegate* delegate = nullptr;
99 // Translate will call OnDragEntered.
100 Translate(key_state, position, effect_bitmask, &data, &event, &delegate);
101 return ui::mojom::kDropEffectNone;
102 }
103
104 uint32_t DropTargetMus::OnDragOver(uint32_t key_state,
105 const gfx::Point& position,
106 uint32_t effect) {
107 int drag_operation = ui::DragDropTypes::DRAG_NONE;
108 std::unique_ptr<ui::OSExchangeData> data;
109 std::unique_ptr<ui::DropTargetEvent> event;
110 aura::client::DragDropDelegate* delegate = nullptr;
111
112 Translate(key_state, position, effect, &data, &event, &delegate);
113 if (delegate)
114 drag_operation = delegate->OnDragUpdated(*event);
115 return drag_operation;
116 }
117
118 void DropTargetMus::OnDragLeave() {
119 NotifyDragLeave();
120 }
121
122 uint32_t DropTargetMus::OnDragDrop(uint32_t key_state,
123 const gfx::Point& position,
124 uint32_t effect) {
125 int drag_operation = ui::DragDropTypes::DRAG_NONE;
126 std::unique_ptr<ui::OSExchangeData> data;
127 std::unique_ptr<ui::DropTargetEvent> event;
128 aura::client::DragDropDelegate* delegate = nullptr;
129 Translate(key_state, position, effect, &data, &event, &delegate);
130 if (delegate)
131 drag_operation = delegate->OnPerformDrop(*event);
132 if (target_window_) {
133 target_window_->RemoveObserver(this);
134 target_window_ = NULL;
135 }
136 // Finally, we reset the set of the.
137 mime_data_.clear();
138
139 return drag_operation;
140 }
141
142 void DropTargetMus::OnWindowDestroyed(aura::Window* window) {
143 DCHECK(window == target_window_);
144 target_window_ = NULL;
145 }
146
147 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698