Skip to content

Commit

Permalink
exo: extended-drag: Implement cursor locking
Browse files Browse the repository at this point in the history
Context: Wayland Protocol needs to be extended to make it possible to
properly support full Chromium's tab dragging experience. Further
details in the Design document [1].

This is the third of a patch series which implements extended-drag in
Exo compositor. This one implements cursor locking options, required for
Chrome's tab dragging, otherwise DragDropController would update the
cursor shape based on the widget under the cursor accept DND operation
or not, which is meaningless for tab/window dragging purposes. Refer to
the design doc for more details.

[1] https://docs.google.com/document/d/1s6OwTi_WC-pS21WLGQYI39yw2m42ZlVolUXBclljXB4/edit?usp=sharing

R=oshima@chromium.org

Bug: 1099418
Change-Id: Ie41f487b26e2eda72dd5be25590d8565e6a5edcb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2401358
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822690}
  • Loading branch information
nickdiego authored and Commit Bot committed Oct 30, 2020
1 parent 57f34d1 commit bc34b23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions components/exo/extended_drag_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ void ExtendedDragSource::OnToplevelWindowDragStarted(
ui::mojom::DragEventSource source) {
pointer_location_ = start_location;
drag_event_source_ = source;
MaybeLockCursor();

if (dragged_window_holder_ && dragged_window_holder_->toplevel_window())
StartDrag(dragged_window_holder_->toplevel_window(), start_location);
}
Expand Down Expand Up @@ -199,6 +201,20 @@ void ExtendedDragSource::OnDataSourceDestroying(DataSource* source) {
source_ = nullptr;
}

void ExtendedDragSource::MaybeLockCursor() {
if (delegate_->ShouldLockCursor()) {
ash::Shell::Get()->cursor_manager()->LockCursor();
cursor_locked_ = true;
}
}

void ExtendedDragSource::UnlockCursor() {
if (cursor_locked_) {
ash::Shell::Get()->cursor_manager()->UnlockCursor();
cursor_locked_ = false;
}
}

void ExtendedDragSource::StartDrag(aura::Window* toplevel,
const gfx::PointF& pointer_location) {
// Ensure |toplevel| window does skip events while it's being dragged.
Expand Down Expand Up @@ -252,6 +268,7 @@ gfx::Point ExtendedDragSource::CalculateOrigin(aura::Window* target) const {
void ExtendedDragSource::Cleanup() {
event_blocker_.reset();
dragged_window_holder_.reset();
UnlockCursor();
}

aura::Window* ExtendedDragSource::GetDraggedWindowForTesting() {
Expand Down
3 changes: 3 additions & 0 deletions components/exo/extended_drag_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class ExtendedDragSource : public DataSourceObserver,
private:
class DraggedWindowHolder;

void MaybeLockCursor();
void UnlockCursor();
void StartDrag(aura::Window* toplevel,
const gfx::PointF& pointer_location_in_screen);
void OnDraggedWindowVisibilityChanging(bool visible);
Expand All @@ -100,6 +102,7 @@ class ExtendedDragSource : public DataSourceObserver,
DataSource* source_ = nullptr;
gfx::PointF pointer_location_;
ui::mojom::DragEventSource drag_event_source_;
bool cursor_locked_ = false;

std::unique_ptr<DraggedWindowHolder> dragged_window_holder_;
std::unique_ptr<aura::ScopedWindowEventTargetingBlocker> event_blocker_;
Expand Down

0 comments on commit bc34b23

Please sign in to comment.