summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkotwicz <pkotwicz@chromium.org>2015-01-27 12:08:19 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-27 20:10:22 +0000
commitf52514eaab866573a7022cea2da3b93f1c18924d (patch)
treec3e0649d801cc7cce8d3c18cc1b8f65ed3bd5d94
parent1db093769786287b1a34ef49c30ecf6bf64a7bfc (diff)
downloadchromium_src-f52514eaab866573a7022cea2da3b93f1c18924d.zip
chromium_src-f52514eaab866573a7022cea2da3b93f1c18924d.tar.gz
chromium_src-f52514eaab866573a7022cea2da3b93f1c18924d.tar.bz2
[Ozone] Constrain the cursor when overscan insets are set
Constrain the mouse cursor to the painted region of the screen when overscan insets are set. BUG=427619 TEST=Manual, see bug Review URL: https://codereview.chromium.org/873563002 Cr-Commit-Position: refs/heads/master@{#313336}
-rw-r--r--ash/host/ash_window_tree_host_ozone.cc13
-rw-r--r--ui/aura/window_tree_host_ozone.cc80
-rw-r--r--ui/aura/window_tree_host_ozone.h26
-rw-r--r--ui/events/ozone/evdev/cursor_delegate_evdev.h4
-rw-r--r--ui/events/ozone/evdev/event_converter_evdev_impl_unittest.cc2
-rw-r--r--ui/events/ozone/evdev/input_injector_evdev_unittest.cc2
-rw-r--r--ui/events/ozone/evdev/tablet_event_converter_evdev.cc12
-rw-r--r--ui/events/ozone/evdev/tablet_event_converter_evdev_unittest.cc16
-rw-r--r--ui/ozone/platform/caca/caca_window.cc2
-rw-r--r--ui/ozone/platform/caca/caca_window.h1
-rw-r--r--ui/ozone/platform/dri/dri_cursor.cc51
-rw-r--r--ui/ozone/platform/dri/dri_cursor.h17
-rw-r--r--ui/ozone/platform/dri/dri_window.cc17
-rw-r--r--ui/ozone/platform/dri/dri_window.h5
-rw-r--r--ui/ozone/platform/egltest/ozone_platform_egltest.cc4
-rw-r--r--ui/ozone/platform/test/test_window.cc3
-rw-r--r--ui/ozone/platform/test/test_window.h1
-rw-r--r--ui/platform_window/platform_window.h6
-rw-r--r--ui/platform_window/win/win_window.cc3
-rw-r--r--ui/platform_window/win/win_window.h1
-rw-r--r--ui/platform_window/x11/x11_window.cc3
-rw-r--r--ui/platform_window/x11/x11_window.h1
22 files changed, 170 insertions, 100 deletions
diff --git a/ash/host/ash_window_tree_host_ozone.cc b/ash/host/ash_window_tree_host_ozone.cc
index a2e336b..860d1ed 100644
--- a/ash/host/ash_window_tree_host_ozone.cc
+++ b/ash/host/ash_window_tree_host_ozone.cc
@@ -13,6 +13,7 @@
#include "ui/gfx/transform.h"
#include "ui/ozone/public/input_controller.h"
#include "ui/ozone/public/ozone_platform.h"
+#include "ui/platform_window/platform_window.h"
namespace ash {
namespace {
@@ -37,6 +38,7 @@ class AshWindowTreeHostOzone : public AshWindowTreeHost,
gfx::Transform GetInverseRootTransform() const override;
void UpdateRootWindowSize(const gfx::Size& host_size) override;
void OnCursorVisibilityChangedNative(bool show) override;
+ void SetBounds(const gfx::Rect& bounds) override;
void DispatchEvent(ui::Event* event) override;
// Temporarily disable the tap-to-click feature. Used on CrOS.
@@ -59,7 +61,10 @@ void AshWindowTreeHostOzone::ToggleFullScreen() {
}
bool AshWindowTreeHostOzone::ConfineCursorToRootWindow() {
- return false;
+ gfx::Rect confined_bounds(GetBounds().size());
+ confined_bounds.Inset(transformer_helper_.GetHostInsets());
+ platform_window()->ConfineCursorToBounds(confined_bounds);
+ return true;
}
void AshWindowTreeHostOzone::UnConfineCursor() {
@@ -69,6 +74,7 @@ void AshWindowTreeHostOzone::UnConfineCursor() {
void AshWindowTreeHostOzone::SetRootWindowTransformer(
scoped_ptr<RootWindowTransformer> transformer) {
transformer_helper_.SetRootWindowTransformer(transformer.Pass());
+ ConfineCursorToRootWindow();
}
gfx::Insets AshWindowTreeHostOzone::GetHostInsets() const {
@@ -99,6 +105,11 @@ void AshWindowTreeHostOzone::OnCursorVisibilityChangedNative(bool show) {
SetTapToClickPaused(!show);
}
+void AshWindowTreeHostOzone::SetBounds(const gfx::Rect& bounds) {
+ WindowTreeHostOzone::SetBounds(bounds);
+ ConfineCursorToRootWindow();
+}
+
void AshWindowTreeHostOzone::DispatchEvent(ui::Event* event) {
if (event->IsLocatedEvent())
TranslateLocatedEvent(static_cast<ui::LocatedEvent*>(event));
diff --git a/ui/aura/window_tree_host_ozone.cc b/ui/aura/window_tree_host_ozone.cc
index 69ec8dd..0b6df97 100644
--- a/ui/aura/window_tree_host_ozone.cc
+++ b/ui/aura/window_tree_host_ozone.cc
@@ -21,46 +21,6 @@ WindowTreeHostOzone::~WindowTreeHostOzone() {
DestroyDispatcher();
}
-gfx::Rect WindowTreeHostOzone::GetBounds() const {
- return platform_window_->GetBounds();
-}
-
-void WindowTreeHostOzone::OnBoundsChanged(const gfx::Rect& new_bounds) {
- // TOOD(spang): Should we determine which parts changed?
- OnHostResized(new_bounds.size());
- OnHostMoved(new_bounds.origin());
-}
-
-void WindowTreeHostOzone::OnDamageRect(const gfx::Rect& damaged_region) {
-}
-
-void WindowTreeHostOzone::DispatchEvent(ui::Event* event) {
- SendEventToProcessor(event);
-}
-
-void WindowTreeHostOzone::OnCloseRequest() {
- OnHostCloseRequested();
-}
-
-void WindowTreeHostOzone::OnClosed() {
-}
-
-void WindowTreeHostOzone::OnWindowStateChanged(
- ui::PlatformWindowState new_state) {
-}
-
-void WindowTreeHostOzone::OnLostCapture() {
-}
-
-void WindowTreeHostOzone::OnAcceleratedWidgetAvailable(
- gfx::AcceleratedWidget widget) {
- widget_ = widget;
- CreateCompositor(widget_);
-}
-
-void WindowTreeHostOzone::OnActivationChanged(bool active) {
-}
-
ui::EventSource* WindowTreeHostOzone::GetEventSource() {
return this;
}
@@ -77,6 +37,10 @@ void WindowTreeHostOzone::Hide() {
platform_window_->Hide();
}
+gfx::Rect WindowTreeHostOzone::GetBounds() const {
+ return platform_window_->GetBounds();
+}
+
void WindowTreeHostOzone::SetBounds(const gfx::Rect& bounds) {
platform_window_->SetBounds(bounds);
}
@@ -107,6 +71,42 @@ void WindowTreeHostOzone::MoveCursorToNative(const gfx::Point& location) {
void WindowTreeHostOzone::OnCursorVisibilityChangedNative(bool show) {
}
+void WindowTreeHostOzone::OnBoundsChanged(const gfx::Rect& new_bounds) {
+ // TOOD(spang): Should we determine which parts changed?
+ OnHostResized(new_bounds.size());
+ OnHostMoved(new_bounds.origin());
+}
+
+void WindowTreeHostOzone::OnDamageRect(const gfx::Rect& damaged_region) {
+}
+
+void WindowTreeHostOzone::DispatchEvent(ui::Event* event) {
+ SendEventToProcessor(event);
+}
+
+void WindowTreeHostOzone::OnCloseRequest() {
+ OnHostCloseRequested();
+}
+
+void WindowTreeHostOzone::OnClosed() {
+}
+
+void WindowTreeHostOzone::OnWindowStateChanged(
+ ui::PlatformWindowState new_state) {
+}
+
+void WindowTreeHostOzone::OnLostCapture() {
+}
+
+void WindowTreeHostOzone::OnAcceleratedWidgetAvailable(
+ gfx::AcceleratedWidget widget) {
+ widget_ = widget;
+ CreateCompositor(widget_);
+}
+
+void WindowTreeHostOzone::OnActivationChanged(bool active) {
+}
+
ui::EventProcessor* WindowTreeHostOzone::GetEventProcessor() {
return dispatcher();
}
diff --git a/ui/aura/window_tree_host_ozone.h b/ui/aura/window_tree_host_ozone.h
index 716ff7a..e4fcd02 100644
--- a/ui/aura/window_tree_host_ozone.h
+++ b/ui/aura/window_tree_host_ozone.h
@@ -26,7 +26,20 @@ class AURA_EXPORT WindowTreeHostOzone : public WindowTreeHost,
protected:
// WindowTreeHost:
+ ui::EventSource* GetEventSource() override;
+ gfx::AcceleratedWidget GetAcceleratedWidget() override;
+ void Show() override;
+ void Hide() override;
gfx::Rect GetBounds() const override;
+ void SetBounds(const gfx::Rect& bounds) override;
+ gfx::Point GetLocationOnNativeScreen() const override;
+ void SetCapture() override;
+ void ReleaseCapture() override;
+ void SetCursorNative(gfx::NativeCursor cursor_type) override;
+ void MoveCursorToNative(const gfx::Point& location) override;
+ void OnCursorVisibilityChangedNative(bool show) override;
+
+ ui::PlatformWindow* platform_window() { return platform_window_.get(); }
private:
// ui::PlatformWindowDelegate:
@@ -40,19 +53,6 @@ class AURA_EXPORT WindowTreeHostOzone : public WindowTreeHost,
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override;
void OnActivationChanged(bool active) override;
- // WindowTreeHost:
- ui::EventSource* GetEventSource() override;
- gfx::AcceleratedWidget GetAcceleratedWidget() override;
- void Show() override;
- void Hide() override;
- void SetBounds(const gfx::Rect& bounds) override;
- gfx::Point GetLocationOnNativeScreen() const override;
- void SetCapture() override;
- void ReleaseCapture() override;
- void SetCursorNative(gfx::NativeCursor cursor_type) override;
- void MoveCursorToNative(const gfx::Point& location) override;
- void OnCursorVisibilityChangedNative(bool show) override;
-
// ui::EventSource overrides.
ui::EventProcessor* GetEventProcessor() override;
diff --git a/ui/events/ozone/evdev/cursor_delegate_evdev.h b/ui/events/ozone/evdev/cursor_delegate_evdev.h
index 98f96b5..bba23d1 100644
--- a/ui/events/ozone/evdev/cursor_delegate_evdev.h
+++ b/ui/events/ozone/evdev/cursor_delegate_evdev.h
@@ -32,8 +32,8 @@ class EVENTS_OZONE_EVDEV_EXPORT CursorDelegateEvdev {
// Cursor visibility.
virtual bool IsCursorVisible() = 0;
- // The bounds of the display that the cursor is currently on
- virtual gfx::Rect GetCursorDisplayBounds() = 0;
+ // The bounds that the cursor is confined to.
+ virtual gfx::Rect GetCursorConfinedBounds() = 0;
};
} // namespace ui
diff --git a/ui/events/ozone/evdev/event_converter_evdev_impl_unittest.cc b/ui/events/ozone/evdev/event_converter_evdev_impl_unittest.cc
index f7f05ec..dbfad11 100644
--- a/ui/events/ozone/evdev/event_converter_evdev_impl_unittest.cc
+++ b/ui/events/ozone/evdev/event_converter_evdev_impl_unittest.cc
@@ -64,7 +64,7 @@ class MockCursorEvdev : public CursorDelegateEvdev {
cursor_location_ = gfx::PointF(delta.x(), delta.y());
}
bool IsCursorVisible() override { return 1; }
- gfx::Rect GetCursorDisplayBounds() override {
+ gfx::Rect GetCursorConfinedBounds() override {
NOTIMPLEMENTED();
return gfx::Rect();
}
diff --git a/ui/events/ozone/evdev/input_injector_evdev_unittest.cc b/ui/events/ozone/evdev/input_injector_evdev_unittest.cc
index c4c58ff..7d871e3 100644
--- a/ui/events/ozone/evdev/input_injector_evdev_unittest.cc
+++ b/ui/events/ozone/evdev/input_injector_evdev_unittest.cc
@@ -60,7 +60,7 @@ class MockCursorEvdev : public CursorDelegateEvdev {
cursor_location_ = gfx::PointF(delta.x(), delta.y());
}
bool IsCursorVisible() override { return 1; }
- gfx::Rect GetCursorDisplayBounds() override {
+ gfx::Rect GetCursorConfinedBounds() override {
NOTIMPLEMENTED();
return gfx::Rect();
}
diff --git a/ui/events/ozone/evdev/tablet_event_converter_evdev.cc b/ui/events/ozone/evdev/tablet_event_converter_evdev.cc
index 58dafb9..1c28d5b 100644
--- a/ui/events/ozone/evdev/tablet_event_converter_evdev.cc
+++ b/ui/events/ozone/evdev/tablet_event_converter_evdev.cc
@@ -110,15 +110,15 @@ void TabletEventConverterEvdev::ConvertAbsEvent(const input_event& input) {
}
void TabletEventConverterEvdev::UpdateCursor() {
- gfx::Rect display_bounds = cursor_->GetCursorDisplayBounds();
+ gfx::Rect confined_bounds = cursor_->GetCursorConfinedBounds();
int x =
- ((x_abs_location_ - x_abs_min_) * display_bounds.width()) / x_abs_range_;
- int y =
- ((y_abs_location_ - y_abs_min_) * display_bounds.height()) / y_abs_range_;
+ ((x_abs_location_ - x_abs_min_) * confined_bounds.width()) / x_abs_range_;
+ int y = ((y_abs_location_ - y_abs_min_) * confined_bounds.height()) /
+ y_abs_range_;
- x += display_bounds.x();
- y += display_bounds.y();
+ x += confined_bounds.x();
+ y += confined_bounds.y();
cursor_->MoveCursorTo(gfx::PointF(x, y));
}
diff --git a/ui/events/ozone/evdev/tablet_event_converter_evdev_unittest.cc b/ui/events/ozone/evdev/tablet_event_converter_evdev_unittest.cc
index 8451ad2..77651d4 100644
--- a/ui/events/ozone/evdev/tablet_event_converter_evdev_unittest.cc
+++ b/ui/events/ozone/evdev/tablet_event_converter_evdev_unittest.cc
@@ -77,7 +77,7 @@ class MockTabletEventConverterEvdev : public TabletEventConverterEvdev {
class MockTabletCursorEvdev : public CursorDelegateEvdev {
public:
- MockTabletCursorEvdev() { cursor_display_bounds_ = gfx::Rect(1024, 768); }
+ MockTabletCursorEvdev() { cursor_confined_bounds_ = gfx::Rect(1024, 768); }
~MockTabletCursorEvdev() override {}
// CursorDelegateEvdev:
@@ -91,11 +91,13 @@ class MockTabletCursorEvdev : public CursorDelegateEvdev {
void MoveCursor(const gfx::Vector2dF& delta) override { NOTREACHED(); }
bool IsCursorVisible() override { return 1; }
gfx::PointF GetLocation() override { return cursor_location_; }
- gfx::Rect GetCursorDisplayBounds() override { return cursor_display_bounds_; }
+ gfx::Rect GetCursorConfinedBounds() override {
+ return cursor_confined_bounds_;
+ }
private:
gfx::PointF cursor_location_;
- gfx::Rect cursor_display_bounds_;
+ gfx::Rect cursor_confined_bounds_;
DISALLOW_COPY_AND_ASSIGN(MockTabletCursorEvdev);
};
@@ -251,7 +253,7 @@ TEST_F(TabletEventConverterEvdevTest, MoveTopRight) {
EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type());
EXPECT_GT(cursor()->GetLocation().x(),
- cursor()->GetCursorDisplayBounds().width() - EPSILON);
+ cursor()->GetCursorConfinedBounds().width() - EPSILON);
EXPECT_LT(cursor()->GetLocation().y(), EPSILON);
}
@@ -285,7 +287,7 @@ TEST_F(TabletEventConverterEvdevTest, MoveBottomLeft) {
EXPECT_LT(cursor()->GetLocation().x(), EPSILON);
EXPECT_GT(cursor()->GetLocation().y(),
- cursor()->GetCursorDisplayBounds().height() - EPSILON);
+ cursor()->GetCursorConfinedBounds().height() - EPSILON);
}
TEST_F(TabletEventConverterEvdevTest, MoveBottomRight) {
@@ -319,9 +321,9 @@ TEST_F(TabletEventConverterEvdevTest, MoveBottomRight) {
EXPECT_EQ(ui::ET_MOUSE_MOVED, event->type());
EXPECT_GT(cursor()->GetLocation().x(),
- cursor()->GetCursorDisplayBounds().height() - EPSILON);
+ cursor()->GetCursorConfinedBounds().height() - EPSILON);
EXPECT_GT(cursor()->GetLocation().y(),
- cursor()->GetCursorDisplayBounds().height() - EPSILON);
+ cursor()->GetCursorConfinedBounds().height() - EPSILON);
}
TEST_F(TabletEventConverterEvdevTest, Tap) {
diff --git a/ui/ozone/platform/caca/caca_window.cc b/ui/ozone/platform/caca/caca_window.cc
index 8f2e039..c0cb840 100644
--- a/ui/ozone/platform/caca/caca_window.cc
+++ b/ui/ozone/platform/caca/caca_window.cc
@@ -134,6 +134,8 @@ void CacaWindow::SetCursor(PlatformCursor cursor) {}
void CacaWindow::MoveCursorTo(const gfx::Point& location) {}
+void CacaWindow::ConfineCursorToBounds(const gfx::Rect& bounds) {}
+
bool CacaWindow::CanDispatchEvent(const PlatformEvent& event) { return true; }
uint32_t CacaWindow::DispatchEvent(const PlatformEvent& ne) {
diff --git a/ui/ozone/platform/caca/caca_window.h b/ui/ozone/platform/caca/caca_window.h
index 70115d09..b0a20ee 100644
--- a/ui/ozone/platform/caca/caca_window.h
+++ b/ui/ozone/platform/caca/caca_window.h
@@ -60,6 +60,7 @@ class CacaWindow : public PlatformWindow, public PlatformEventDispatcher {
void Restore() override;
void SetCursor(PlatformCursor cursor) override;
void MoveCursorTo(const gfx::Point& location) override;
+ void ConfineCursorToBounds(const gfx::Rect& bounds) override;
// PlatformEventDispatcher:
bool CanDispatchEvent(const PlatformEvent& event) override;
diff --git a/ui/ozone/platform/dri/dri_cursor.cc b/ui/ozone/platform/dri/dri_cursor.cc
index 7fb10a9..8ad5e07 100644
--- a/ui/ozone/platform/dri/dri_cursor.cc
+++ b/ui/ozone/platform/dri/dri_cursor.cc
@@ -52,7 +52,8 @@ void DriCursor::SetCursor(gfx::AcceleratedWidget window,
}
void DriCursor::OnWindowAdded(gfx::AcceleratedWidget window,
- const gfx::Rect& bounds) {
+ const gfx::Rect& bounds_in_screen,
+ const gfx::Rect& cursor_confined_bounds) {
#if DCHECK_IS_ON()
if (!ui_task_runner_)
ui_task_runner_ = base::ThreadTaskRunnerHandle::Get();
@@ -63,8 +64,9 @@ void DriCursor::OnWindowAdded(gfx::AcceleratedWidget window,
if (state_.window == gfx::kNullAcceleratedWidget) {
// First window added & cursor is not placed. Place it.
state_.window = window;
- state_.bounds = bounds;
- SetCursorLocationLocked(bounds.CenterPoint() - bounds.OffsetFromOrigin());
+ state_.display_bounds_in_screen = bounds_in_screen;
+ state_.confined_bounds = cursor_confined_bounds;
+ SetCursorLocationLocked(cursor_confined_bounds.CenterPoint());
}
}
@@ -74,19 +76,18 @@ void DriCursor::OnWindowRemoved(gfx::AcceleratedWidget window) {
if (state_.window == window) {
// Try to find a new location for the cursor.
- gfx::PointF screen_location =
- state_.location + state_.bounds.OffsetFromOrigin();
DriWindow* dest_window = window_manager_->GetPrimaryWindow();
if (dest_window) {
state_.window = dest_window->GetAcceleratedWidget();
- state_.bounds = dest_window->GetBounds();
- SetCursorLocationLocked(state_.bounds.CenterPoint() -
- state_.bounds.OffsetFromOrigin());
+ state_.display_bounds_in_screen = dest_window->GetBounds();
+ state_.confined_bounds = dest_window->GetCursorConfinedBounds();
+ SetCursorLocationLocked(state_.confined_bounds.CenterPoint());
SendCursorShowLocked();
} else {
state_.window = gfx::kNullAcceleratedWidget;
- state_.bounds = gfx::Rect();
+ state_.display_bounds_in_screen = gfx::Rect();
+ state_.confined_bounds = gfx::Rect();
state_.location = gfx::Point();
}
}
@@ -102,14 +103,17 @@ void DriCursor::PrepareForBoundsChange(gfx::AcceleratedWidget window) {
// TODO(spang): The GPU-side code should handle this.
if (state_.window == window)
SendCursorHideLocked();
+
+ // The cursor will be shown and moved once the confined bounds for |window|
+ // are updated.
}
-void DriCursor::CommitBoundsChange(gfx::AcceleratedWidget window,
- const gfx::Rect& bounds) {
+void DriCursor::ConfineCursorToBounds(gfx::AcceleratedWidget window,
+ const gfx::Rect& bounds) {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
base::AutoLock lock(state_.lock);
if (state_.window == window) {
- state_.bounds = bounds;
+ state_.confined_bounds = bounds;
SetCursorLocationLocked(state_.location);
SendCursorShowLocked();
}
@@ -128,7 +132,8 @@ void DriCursor::MoveCursorTo(gfx::AcceleratedWidget window,
SendCursorHideLocked();
DriWindow* dri_window = window_manager_->GetWindow(window);
- state_.bounds = dri_window->GetBounds();
+ state_.display_bounds_in_screen = dri_window->GetBounds();
+ state_.confined_bounds = dri_window->GetCursorConfinedBounds();
state_.window = window;
}
@@ -146,7 +151,8 @@ void DriCursor::MoveCursorTo(const gfx::PointF& screen_location) {
// TODO(spang): Moving between windows doesn't work here, but
// is not needed for current uses.
- SetCursorLocationLocked(screen_location - state_.bounds.OffsetFromOrigin());
+ SetCursorLocationLocked(screen_location -
+ state_.display_bounds_in_screen.OffsetFromOrigin());
}
void DriCursor::MoveCursor(const gfx::Vector2dF& delta) {
@@ -174,12 +180,13 @@ bool DriCursor::IsCursorVisible() {
gfx::PointF DriCursor::GetLocation() {
base::AutoLock lock(state_.lock);
- return state_.location + state_.bounds.OffsetFromOrigin();
+ return state_.location + state_.display_bounds_in_screen.OffsetFromOrigin();
}
-gfx::Rect DriCursor::GetCursorDisplayBounds() {
+gfx::Rect DriCursor::GetCursorConfinedBounds() {
base::AutoLock lock(state_.lock);
- return state_.bounds;
+ return state_.confined_bounds +
+ state_.display_bounds_in_screen.OffsetFromOrigin();
}
void DriCursor::OnChannelEstablished(
@@ -196,7 +203,7 @@ void DriCursor::OnChannelEstablished(
state_.send_runner = send_runner;
state_.send_callback = send_callback;
// Initial set for this GPU process will happen after the window
- // initializes, in CommitBoundsChange.
+ // initializes, in ConfineCursorToBounds().
}
void DriCursor::OnChannelDestroyed(int host_id) {
@@ -216,11 +223,11 @@ bool DriCursor::OnMessageReceived(const IPC::Message& message) {
void DriCursor::SetCursorLocationLocked(const gfx::PointF& location) {
state_.lock.AssertAcquired();
- const gfx::Size& size = state_.bounds.size();
gfx::PointF clamped_location = location;
- clamped_location.SetToMax(gfx::PointF(0, 0));
+ clamped_location.SetToMax(state_.confined_bounds.origin());
// Right and bottom edges are exclusive.
- clamped_location.SetToMin(gfx::PointF(size.width() - 1, size.height() - 1));
+ clamped_location.SetToMin(gfx::PointF(state_.confined_bounds.right() - 1,
+ state_.confined_bounds.bottom() - 1));
state_.location = clamped_location;
}
@@ -266,7 +273,7 @@ void DriCursor::SendLocked(IPC::Message* message) {
base::Bind(state_.send_callback, message)))
return;
- // Drop disconnected updates. DriWindow will call CommitBoundsChange()
+ // Drop disconnected updates. DriWindow will call ConfineCursorToBounds()
// when we connect to initialize the cursor location.
delete message;
}
diff --git a/ui/ozone/platform/dri/dri_cursor.h b/ui/ozone/platform/dri/dri_cursor.h
index f66f400..d012166 100644
--- a/ui/ozone/platform/dri/dri_cursor.h
+++ b/ui/ozone/platform/dri/dri_cursor.h
@@ -41,13 +41,17 @@ class DriCursor : public CursorDelegateEvdev, public GpuPlatformSupportHost {
void SetCursor(gfx::AcceleratedWidget window, PlatformCursor platform_cursor);
// Handle window lifecycle.
- void OnWindowAdded(gfx::AcceleratedWidget window, const gfx::Rect& bounds);
+ void OnWindowAdded(gfx::AcceleratedWidget window,
+ const gfx::Rect& bounds_in_screen,
+ const gfx::Rect& cursor_confined_bounds);
void OnWindowRemoved(gfx::AcceleratedWidget window);
// Handle window bounds changes.
void PrepareForBoundsChange(gfx::AcceleratedWidget window);
- void CommitBoundsChange(gfx::AcceleratedWidget window,
- const gfx::Rect& bounds);
+
+ // Confines the cursor to |confined_bounds| for |window|.
+ void ConfineCursorToBounds(gfx::AcceleratedWidget window,
+ const gfx::Rect& bounds);
// CursorDelegateEvdev:
void MoveCursorTo(gfx::AcceleratedWidget window,
@@ -56,7 +60,7 @@ class DriCursor : public CursorDelegateEvdev, public GpuPlatformSupportHost {
void MoveCursor(const gfx::Vector2dF& delta) override;
bool IsCursorVisible() override;
gfx::PointF GetLocation() override;
- gfx::Rect GetCursorDisplayBounds() override;
+ gfx::Rect GetCursorConfinedBounds() override;
// GpuPlatformSupportHost:
void OnChannelEstablished(
@@ -102,7 +106,10 @@ class DriCursor : public CursorDelegateEvdev, public GpuPlatformSupportHost {
gfx::PointF location;
// The bounds of the display under the cursor.
- gfx::Rect bounds;
+ gfx::Rect display_bounds_in_screen;
+
+ // The bounds that the cursor is confined to in |window|.
+ gfx::Rect confined_bounds;
int host_id;
diff --git a/ui/ozone/platform/dri/dri_window.cc b/ui/ozone/platform/dri/dri_window.cc
index 9796d13..1973890 100644
--- a/ui/ozone/platform/dri/dri_window.cc
+++ b/ui/ozone/platform/dri/dri_window.cc
@@ -50,7 +50,7 @@ DriWindow::~DriWindow() {
void DriWindow::Initialize() {
sender_->AddChannelObserver(this);
PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
- cursor_->OnWindowAdded(widget_, bounds_);
+ cursor_->OnWindowAdded(widget_, bounds_, GetCursorConfinedBounds());
delegate_->OnAcceleratedWidgetAvailable(widget_);
}
@@ -58,6 +58,11 @@ gfx::AcceleratedWidget DriWindow::GetAcceleratedWidget() {
return widget_;
}
+gfx::Rect DriWindow::GetCursorConfinedBounds() const {
+ return cursor_confined_bounds_.IsEmpty() ? gfx::Rect(bounds_.size())
+ : cursor_confined_bounds_;
+}
+
void DriWindow::Show() {}
void DriWindow::Hide() {}
@@ -98,6 +103,14 @@ void DriWindow::MoveCursorTo(const gfx::Point& location) {
event_factory_->WarpCursorTo(widget_, location);
}
+void DriWindow::ConfineCursorToBounds(const gfx::Rect& bounds) {
+ if (cursor_confined_bounds_ == bounds)
+ return;
+
+ cursor_confined_bounds_ = bounds;
+ cursor_->ConfineCursorToBounds(widget_, bounds);
+}
+
bool DriWindow::CanDispatchEvent(const PlatformEvent& ne) {
DCHECK(ne);
Event* event = static_cast<Event*>(ne);
@@ -156,6 +169,7 @@ uint32_t DriWindow::DispatchEvent(const PlatformEvent& native_event) {
void DriWindow::OnChannelEstablished() {
sender_->Send(new OzoneGpuMsg_CreateWindowDelegate(widget_));
SendBoundsChange();
+ cursor_->ConfineCursorToBounds(widget_, GetCursorConfinedBounds());
}
void DriWindow::OnChannelDestroyed() {
@@ -164,7 +178,6 @@ void DriWindow::OnChannelDestroyed() {
void DriWindow::SendBoundsChange() {
cursor_->PrepareForBoundsChange(widget_);
sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds_));
- cursor_->CommitBoundsChange(widget_, bounds_);
}
} // namespace ui
diff --git a/ui/ozone/platform/dri/dri_window.h b/ui/ozone/platform/dri/dri_window.h
index cc6b9c5..5d5072d 100644
--- a/ui/ozone/platform/dri/dri_window.h
+++ b/ui/ozone/platform/dri/dri_window.h
@@ -39,6 +39,8 @@ class DriWindow : public PlatformWindow,
gfx::AcceleratedWidget GetAcceleratedWidget();
+ gfx::Rect GetCursorConfinedBounds() const;
+
// PlatformWindow:
void Show() override;
void Hide() override;
@@ -53,6 +55,7 @@ class DriWindow : public PlatformWindow,
void Restore() override;
void SetCursor(PlatformCursor cursor) override;
void MoveCursorTo(const gfx::Point& location) override;
+ void ConfineCursorToBounds(const gfx::Rect& bounds) override;
// PlatformEventDispatcher:
bool CanDispatchEvent(const PlatformEvent& event) override;
@@ -75,6 +78,8 @@ class DriWindow : public PlatformWindow,
gfx::Rect bounds_;
gfx::AcceleratedWidget widget_;
+ gfx::Rect cursor_confined_bounds_;
+
DISALLOW_COPY_AND_ASSIGN(DriWindow);
};
diff --git a/ui/ozone/platform/egltest/ozone_platform_egltest.cc b/ui/ozone/platform/egltest/ozone_platform_egltest.cc
index 0e43298..becbb81c 100644
--- a/ui/ozone/platform/egltest/ozone_platform_egltest.cc
+++ b/ui/ozone/platform/egltest/ozone_platform_egltest.cc
@@ -94,6 +94,7 @@ class EgltestWindow : public PlatformWindow, public PlatformEventDispatcher {
void Restore() override;
void SetCursor(PlatformCursor cursor) override;
void MoveCursorTo(const gfx::Point& location) override;
+ void ConfineCursorToBounds(const gfx::Rect& bounds) override;
// PlatformEventDispatcher:
bool CanDispatchEvent(const PlatformEvent& event) override;
@@ -172,6 +173,9 @@ void EgltestWindow::MoveCursorTo(const gfx::Point& location) {
event_factory_->WarpCursorTo(window_id_, location);
}
+void EgltestWindow::ConfineCursorToBounds(const gfx::Rect& bounds) {
+}
+
bool EgltestWindow::CanDispatchEvent(const ui::PlatformEvent& ne) {
return true;
}
diff --git a/ui/ozone/platform/test/test_window.cc b/ui/ozone/platform/test/test_window.cc
index 2cfa26c..2890ccf 100644
--- a/ui/ozone/platform/test/test_window.cc
+++ b/ui/ozone/platform/test/test_window.cc
@@ -77,4 +77,7 @@ void TestWindow::SetCursor(PlatformCursor cursor) {
void TestWindow::MoveCursorTo(const gfx::Point& location) {
}
+void TestWindow::ConfineCursorToBounds(const gfx::Rect& bounds) {
+}
+
} // namespace ui
diff --git a/ui/ozone/platform/test/test_window.h b/ui/ozone/platform/test/test_window.h
index 64397e7..aaeb003 100644
--- a/ui/ozone/platform/test/test_window.h
+++ b/ui/ozone/platform/test/test_window.h
@@ -39,6 +39,7 @@ class TestWindow : public PlatformWindow {
void Restore() override;
void SetCursor(PlatformCursor cursor) override;
void MoveCursorTo(const gfx::Point& location) override;
+ void ConfineCursorToBounds(const gfx::Rect& bounds) override;
private:
PlatformWindowDelegate* delegate_;
diff --git a/ui/platform_window/platform_window.h b/ui/platform_window/platform_window.h
index d5f5750..6e6ace1 100644
--- a/ui/platform_window/platform_window.h
+++ b/ui/platform_window/platform_window.h
@@ -42,7 +42,13 @@ class PlatformWindow {
virtual void Restore() = 0;
virtual void SetCursor(PlatformCursor cursor) = 0;
+
+ // Moves the cursor to |location|. Location is in platform window coordinates.
virtual void MoveCursorTo(const gfx::Point& location) = 0;
+
+ // Confines the cursor to |bounds| when it is in the platform window. |bounds|
+ // is in platform window coordinates.
+ virtual void ConfineCursorToBounds(const gfx::Rect& bounds) = 0;
};
} // namespace ui
diff --git a/ui/platform_window/win/win_window.cc b/ui/platform_window/win/win_window.cc
index f3402c3..9bc8892 100644
--- a/ui/platform_window/win/win_window.cc
+++ b/ui/platform_window/win/win_window.cc
@@ -107,6 +107,9 @@ void WinWindow::SetCursor(PlatformCursor cursor) {}
void WinWindow::MoveCursorTo(const gfx::Point& location) {}
+void WinWindow::ConfineCursorToBounds(const gfx::Rect& bounds) {
+}
+
LRESULT WinWindow::OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) {
// TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
tracked_objects::ScopedTracker tracking_profile(
diff --git a/ui/platform_window/win/win_window.h b/ui/platform_window/win/win_window.h
index 65ffb5a..12aa7ad 100644
--- a/ui/platform_window/win/win_window.h
+++ b/ui/platform_window/win/win_window.h
@@ -35,6 +35,7 @@ class WIN_WINDOW_EXPORT WinWindow : public NON_EXPORTED_BASE(PlatformWindow),
virtual void Restore() override;
virtual void SetCursor(PlatformCursor cursor) override;
virtual void MoveCursorTo(const gfx::Point& location) override;
+ virtual void ConfineCursorToBounds(const gfx::Rect& bounds) override;
CR_BEGIN_MSG_MAP_EX(WinWindow)
CR_MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
diff --git a/ui/platform_window/x11/x11_window.cc b/ui/platform_window/x11/x11_window.cc
index c270654..14e6fdf 100644
--- a/ui/platform_window/x11/x11_window.cc
+++ b/ui/platform_window/x11/x11_window.cc
@@ -251,6 +251,9 @@ void X11Window::SetCursor(PlatformCursor cursor) {}
void X11Window::MoveCursorTo(const gfx::Point& location) {}
+void X11Window::ConfineCursorToBounds(const gfx::Rect& bounds) {
+}
+
bool X11Window::CanDispatchEvent(const PlatformEvent& event) {
return FindXEventTarget(event) == xwindow_;
}
diff --git a/ui/platform_window/x11/x11_window.h b/ui/platform_window/x11/x11_window.h
index eb75912..b964b89 100644
--- a/ui/platform_window/x11/x11_window.h
+++ b/ui/platform_window/x11/x11_window.h
@@ -42,6 +42,7 @@ class X11_WINDOW_EXPORT X11Window : public PlatformWindow,
void Restore() override;
void SetCursor(PlatformCursor cursor) override;
void MoveCursorTo(const gfx::Point& location) override;
+ void ConfineCursorToBounds(const gfx::Rect& bounds) override;
// PlatformEventDispatcher:
bool CanDispatchEvent(const PlatformEvent& event) override;