Chromium Code Reviews| Index: ui/views/mus/drop_target_mus.cc |
| diff --git a/ui/views/mus/drop_target_mus.cc b/ui/views/mus/drop_target_mus.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a640e1274a71d36116a8aed66d9db10c8f46caae |
| --- /dev/null |
| +++ b/ui/views/mus/drop_target_mus.cc |
| @@ -0,0 +1,156 @@ |
| +// Copyright 2016 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. |
| + |
| +#include "ui/views/mus/drop_target_mus.h" |
| + |
| +#include <map> |
| +#include <string> |
| +#include <utility> |
| +#include <vector> |
| + |
| +#include "services/ui/public/interfaces/window_tree_constants.mojom.h" |
| +#include "ui/aura/window.h" |
| +#include "ui/aura/window_tree_host.h" |
| +#include "ui/base/dragdrop/drag_drop_types.h" |
| +#include "ui/base/dragdrop/drop_target_event.h" |
| +#include "ui/views/mus/os_exchange_data_provider_mus.h" |
| +#include "ui/wm/public/drag_drop_client.h" |
| +#include "ui/wm/public/drag_drop_delegate.h" |
| + |
| +namespace views { |
| + |
| +static_assert(ui::DragDropTypes::DRAG_NONE == ui::mojom::kDropEffectNone, |
| + "Drag constants must be the same"); |
| +static_assert(ui::DragDropTypes::DRAG_MOVE == ui::mojom::kDropEffectMove, |
| + "Drag constants must be the same"); |
| +static_assert(ui::DragDropTypes::DRAG_COPY == ui::mojom::kDropEffectCopy, |
| + "Drag constants must be the same"); |
| +static_assert(ui::DragDropTypes::DRAG_LINK == ui::mojom::kDropEffectLink, |
| + "Drag constants must be the same"); |
| + |
| +DropTargetMus::DropTargetMus(aura::Window* root_window) |
| + : root_window_(root_window), target_window_(nullptr) {} |
| + |
| +DropTargetMus::~DropTargetMus() {} |
| + |
| +// TODO(erg): |mime_data| could be arbitrarily large. Maybe try to elide |
| +// sending it when target window == source window? |
| + |
| +void DropTargetMus::Translate(uint32_t key_state, |
|
sky
2016/09/23 16:14:08
The name translate is rather generic and doesn't r
Elliot Glaysher
2016/09/23 21:40:48
I'd prefer to keep "Translate()" because every oth
|
| + const gfx::Point& point, |
| + uint32_t effect, |
| + std::unique_ptr<ui::OSExchangeData>* data, |
| + std::unique_ptr<ui::DropTargetEvent>* event, |
| + aura::client::DragDropDelegate** delegate) { |
| + gfx::Point location = point; |
| + gfx::Point root_location = location; |
| + root_window_->GetHost()->ConvertPointFromNativeScreen(&root_location); |
| + aura::Window* target_window = |
| + root_window_->GetEventHandlerForPoint(root_location); |
| + bool target_window_changed = false; |
| + if (target_window != target_window_) { |
| + if (target_window_) |
| + NotifyDragLeave(); |
| + target_window_ = target_window; |
| + if (target_window_) |
| + target_window_->AddObserver(this); |
| + target_window_changed = true; |
| + } |
| + *delegate = NULL; |
|
sky
2016/09/23 16:14:08
nullptr
|
| + if (!target_window_) |
| + return; |
| + *delegate = aura::client::GetDragDropDelegate(target_window_); |
| + if (!*delegate) |
| + return; |
| + |
| + data->reset(new ui::OSExchangeData( |
|
sky
2016/09/23 16:14:08
MakeUnique for OsExchangeData?
|
| + base::MakeUnique<OSExchangeDataProviderMus>(mime_data_))); |
| + location = root_location; |
| + aura::Window::ConvertPointToTarget(root_window_, target_window_, &location); |
| + event->reset( |
| + new ui::DropTargetEvent(*(data->get()), location, root_location, effect)); |
|
sky
2016/09/23 16:14:08
MakeUnique
|
| + (*event)->set_flags(key_state); |
| + if (target_window_changed) |
| + (*delegate)->OnDragEntered(*event->get()); |
| +} |
| + |
| +void DropTargetMus::NotifyDragLeave() { |
|
sky
2016/09/23 16:14:08
As this calls OnDragExited it seems weird to name
|
| + if (!target_window_) |
| + return; |
| + |
| + aura::client::DragDropDelegate* delegate = |
| + aura::client::GetDragDropDelegate(target_window_); |
| + if (delegate) |
| + delegate->OnDragExited(); |
| + |
| + target_window_->RemoveObserver(this); |
| + target_window_ = NULL; |
|
sky
2016/09/23 16:14:08
nullptr
|
| +} |
| + |
| +// TODO(erg): Make sure our views using process calls this so that we don't |
| +// round trip with the mus process. |
| +void DropTargetMus::OnDragDropStart( |
| + std::map<std::string, std::vector<uint8_t>> mime_data) { |
| + // We store the mime data here because we need to access it during each phase |
| + // of the drag, but we also don't move the data cross-process multiple times. |
| + mime_data_ = std::move(mime_data); |
|
sky
2016/09/23 16:14:08
Why do you need to create OsExchangeData on every
Elliot Glaysher
2016/09/23 21:40:48
Created an OSExchangeData here instead.
|
| +} |
| + |
| +uint32_t DropTargetMus::OnDragEnter(uint32_t key_state, |
| + const gfx::Point& position, |
| + uint32_t effect_bitmask) { |
| + std::unique_ptr<ui::OSExchangeData> data; |
| + std::unique_ptr<ui::DropTargetEvent> event; |
| + aura::client::DragDropDelegate* delegate = nullptr; |
| + // Translate will call OnDragEntered. |
| + Translate(key_state, position, effect_bitmask, &data, &event, &delegate); |
| + return ui::mojom::kDropEffectNone; |
| +} |
| + |
| +uint32_t DropTargetMus::OnDragOver(uint32_t key_state, |
| + const gfx::Point& position, |
| + uint32_t effect) { |
| + int drag_operation = ui::DragDropTypes::DRAG_NONE; |
| + std::unique_ptr<ui::OSExchangeData> data; |
| + std::unique_ptr<ui::DropTargetEvent> event; |
| + aura::client::DragDropDelegate* delegate = nullptr; |
| + |
| + Translate(key_state, position, effect, &data, &event, &delegate); |
| + if (delegate) |
| + drag_operation = delegate->OnDragUpdated(*event); |
| + return drag_operation; |
| +} |
| + |
| +void DropTargetMus::OnDragLeave() { |
| + NotifyDragLeave(); |
| +} |
| + |
| +uint32_t DropTargetMus::OnCompleteDrop(uint32_t key_state, |
| + const gfx::Point& position, |
| + uint32_t effect) { |
| + int drag_operation = ui::DragDropTypes::DRAG_NONE; |
| + std::unique_ptr<ui::OSExchangeData> data; |
| + std::unique_ptr<ui::DropTargetEvent> event; |
| + aura::client::DragDropDelegate* delegate = nullptr; |
| + Translate(key_state, position, effect, &data, &event, &delegate); |
| + if (delegate) |
| + drag_operation = delegate->OnPerformDrop(*event); |
| + if (target_window_) { |
| + target_window_->RemoveObserver(this); |
| + target_window_ = NULL; |
|
sky
2016/09/23 16:14:08
nullptr
|
| + } |
| + |
| + return drag_operation; |
| +} |
| + |
| +void DropTargetMus::OnDragDropDone() { |
| + mime_data_.clear(); |
| +} |
| + |
| +void DropTargetMus::OnWindowDestroyed(aura::Window* window) { |
| + DCHECK(window == target_window_); |
|
sky
2016/09/23 16:14:08
DCHECK_EQ
|
| + target_window_ = NULL; |
|
sky
2016/09/23 16:14:08
nullptr
|
| +} |
| + |
| +} // namespace views |