Commit 09a954f4 authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Commit Bot

Reland "Exo: Undo conflation of relative-pointer and pointer-constraints"

This reverts commit 9189f6dd.

Reason for revert: This CL is unrelated to the test that is was suspected of making flaky.

Original change's description:
> Revert "Exo: Undo conflation of relative-pointer and pointer-constraints"
> 
> This reverts commit 01116522.
> 
> Reason for revert: suspected of causing
> PointerLockBrowserTestWithOptions.UnadjustedMovement to be flaky
> 
> See bug: 1043985
> 
> Original change's description:
> > Exo: Undo conflation of relative-pointer and pointer-constraints
> > 
> > When it was first implemented, adding a relative-pointer-delegate would
> > also enable pointer capture (locking the pointer).
> > 
> > This change makes it so that the pointer can only be locked through the
> > pointer-constraints protocol.
> > 
> > Bug: b/124059008
> > Test: exo_unittests, manual testting using ArcPointerCaptureTestApp
> > Change-Id: Ied0f1c658aa713026e622f4ce26009e261d4f653
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1992355
> > Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
> > Commit-Queue: Prabir Pradhan <prabirmsp@chromium.org>
> > Auto-Submit: Prabir Pradhan <prabirmsp@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#733497}
> 
> TBR=mukai@chromium.org,oshima@chromium.org,prabirmsp@chromium.org
> 
> Change-Id: I8581f298f099cb7a9a006a1b578f6345184da1d3
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: b/124059008
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2012517
> Reviewed-by: Nina Satragno <nsatragno@chromium.org>
> Commit-Queue: Nina Satragno <nsatragno@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#733612}

TBR=mukai@chromium.org,oshima@chromium.org,nsatragno@chromium.org,prabirmsp@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: b/124059008
Change-Id: I5e0c6615b9dce0c48f94d6b227763cfc205954b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2015301Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarNina Satragno <nsatragno@chromium.org>
Commit-Queue: Prabir Pradhan <prabirmsp@chromium.org>
Auto-Submit: Prabir Pradhan <prabirmsp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734655}
parent d8cf940f
......@@ -225,62 +225,6 @@ void Pointer::UnregisterRelativePointerDelegate(
relative_pointer_delegate_ = nullptr;
}
bool Pointer::EnablePointerCapture() {
if (!base::FeatureList::IsEnabled(kPointerCapture))
return false;
// You are not allowed to have more than one capture active.
if (capture_window_)
return false;
aura::Window* active_window = WMHelper::GetInstance()->GetActiveWindow();
if (!active_window) {
LOG(ERROR) << "Failed to enable pointer capture: "
"active window not found";
return false;
}
auto* top_level_widget =
views::Widget::GetTopLevelWidgetForNativeView(active_window);
if (!top_level_widget) {
LOG(ERROR) << "Failed to enable pointer capture: "
"active window does not have associated widget";
return false;
}
Surface* root_surface =
GetShellMainSurface(top_level_widget->GetNativeWindow());
if (!root_surface ||
!delegate_->CanAcceptPointerEventsForSurface(root_surface)) {
LOG(ERROR) << "Failed to enable pointer capture: "
"cannot find window for capture";
return false;
}
return EnablePointerCapture(root_surface);
}
void Pointer::DisablePointerCapture() {
// Early out if pointer capture is not enabled.
if (!capture_window_)
return;
// Remove the pre-target handler that consumes all mouse events.
aura::Env::GetInstance()->RemovePreTargetHandler(this);
auto* cursor_client = WMHelper::GetInstance()->GetCursorClient();
cursor_client->UnlockCursor();
cursor_client->ShowCursor();
aura::Window* root = capture_window_->GetRootWindow();
gfx::Point p = location_when_pointer_capture_enabled_
? *location_when_pointer_capture_enabled_
: root->bounds().CenterPoint();
root->MoveCursorTo(p);
capture_window_ = nullptr;
location_when_pointer_capture_enabled_.reset();
UpdateCursor();
}
bool Pointer::ConstrainPointer(PointerConstraintDelegate* delegate) {
// Pointer lock is a chromeos-only feature (i.e. the chromeos::features
// namespace only exists in chromeos builds). So we do not compile pointer
......@@ -345,6 +289,29 @@ bool Pointer::EnablePointerCapture(Surface* capture_surface) {
return true;
}
void Pointer::DisablePointerCapture() {
// Early out if pointer capture is not enabled.
if (!capture_window_)
return;
// Remove the pre-target handler that consumes all mouse events.
aura::Env::GetInstance()->RemovePreTargetHandler(this);
auto* cursor_client = WMHelper::GetInstance()->GetCursorClient();
cursor_client->UnlockCursor();
cursor_client->ShowCursor();
aura::Window* root = capture_window_->GetRootWindow();
gfx::Point p = location_when_pointer_capture_enabled_
? *location_when_pointer_capture_enabled_
: root->bounds().CenterPoint();
root->MoveCursorTo(p);
capture_window_ = nullptr;
location_when_pointer_capture_enabled_.reset();
UpdateCursor();
}
////////////////////////////////////////////////////////////////////////////////
// SurfaceDelegate overrides:
......
......@@ -92,17 +92,6 @@ class Pointer : public SurfaceTreeHost,
void RegisterRelativePointerDelegate(RelativePointerDelegate* delegate);
void UnregisterRelativePointerDelegate(RelativePointerDelegate* delegate);
// Capture the pointer for the top-most surface. Returns true iff the capture
// succeeded.
//
// TODO(b/124059008): Historically, exo needed to guess what the correct
// capture window was, as it did not implement wayland's pointer capture
// protocol.
bool EnablePointerCapture();
// Remove the currently active pointer capture (if there is one).
void DisablePointerCapture();
// Enable the pointer constraint on the given surface. Returns true if the
// lock was granted, false otherwise.
//
......@@ -121,6 +110,9 @@ class Pointer : public SurfaceTreeHost,
// succeeded.
bool EnablePointerCapture(Surface* capture_surface);
// Remove the currently active pointer capture (if there is one).
void DisablePointerCapture();
// Returns the effective target for |event|.
Surface* GetEffectiveTargetForEvent(ui::LocatedEvent* event) const;
......
......@@ -27,20 +27,11 @@ class WaylandRelativePointerDelegate : public RelativePointerDelegate {
WaylandRelativePointerDelegate(wl_resource* resource, Pointer* pointer)
: resource_(resource), pointer_(pointer) {
pointer->RegisterRelativePointerDelegate(this);
// TODO(b/124059008): See below, when requesting relative motion we will
// also try to gain pointer lock even though the client hasn't asked for it
// yet...
pointer_->EnablePointerCapture();
}
~WaylandRelativePointerDelegate() override {
if (pointer_) {
// TODO(b/124059008): For whatever reason, exo conflates pointer capture
// and relative motion. Normally in wayland, removing the relative pointer
// would not break pointer capture, but in exo that is the case.
pointer_->DisablePointerCapture();
if (pointer_)
pointer_->UnregisterRelativePointerDelegate(this);
}
}
void OnPointerDestroying(Pointer* pointer) override { pointer_ = nullptr; }
void OnPointerRelativeMotion(base::TimeTicks time_stamp,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment