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

Unified Diff: components/exo/pointer.cc

Issue 2071553002: Initial support of large mouse cursor on Exosphere (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for comment #13 Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: components/exo/pointer.cc
diff --git a/components/exo/pointer.cc b/components/exo/pointer.cc
index 6c0c6482e26e753e6a00c62e76cb684625c378c3..2c12e19d5d704909b70f2f85a1a556ad9b8e7684 100644
--- a/components/exo/pointer.cc
+++ b/components/exo/pointer.cc
@@ -19,6 +19,8 @@
namespace exo {
namespace {
+static constexpr float kLargeCursorScale = 2.8;
+
// Synthesized events typically lack floating point precision so to avoid
// generating mouse event jitter we consider the location of these events
// to be the same as |location| if floored values match.
@@ -39,7 +41,12 @@ Pointer::Pointer(PointerDelegate* delegate)
surface_(nullptr),
focus_(nullptr),
cursor_scale_(1.0f) {
- ash::Shell::GetInstance()->AddPreTargetHandler(this);
+ ash::Shell* ash_shell = ash::Shell::GetInstance();
+ ash_shell->AddPreTargetHandler(this);
+
+ wm::CursorManager* cursor_manager = ash_shell->cursor_manager();
+ DCHECK(cursor_manager);
+ cursor_manager->AddObserver(this);
}
Pointer::~Pointer() {
@@ -52,7 +59,11 @@ Pointer::~Pointer() {
}
if (widget_)
widget_->CloseNow();
- ash::Shell::GetInstance()->RemovePreTargetHandler(this);
+
+ ash::Shell* ash_shell = ash::Shell::GetInstance();
+ DCHECK(ash_shell->cursor_manager());
+ ash_shell->cursor_manager()->RemoveObserver(this);
+ ash_shell->RemovePreTargetHandler(this);
}
void Pointer::SetCursor(Surface* surface, const gfx::Point& hotspot) {
@@ -211,21 +222,7 @@ void Pointer::OnMouseEvent(ui::MouseEvent* event) {
widget_->GetNativeWindow()->SetBounds(bounds);
}
- // Update cursor scale if the effective UI scale has changed since last
- // mouse event.
- display::Display display =
- display::Screen::GetScreen()->GetDisplayNearestWindow(
- widget_->GetNativeWindow());
- float ui_scale = ash::Shell::GetInstance()
- ->display_manager()
- ->GetDisplayInfo(display.id())
- .GetEffectiveUIScale();
- if (ui_scale != cursor_scale_) {
- gfx::Transform transform;
- transform.Scale(ui_scale, ui_scale);
- widget_->GetNativeWindow()->SetTransform(transform);
- cursor_scale_ = ui_scale;
- }
+ UpdateCursorScale();
} else {
if (widget_ && widget_->IsVisible())
widget_->Hide();
@@ -236,6 +233,10 @@ void Pointer::OnScrollEvent(ui::ScrollEvent* event) {
OnMouseEvent(event);
}
+void Pointer::OnCursorSetChanged(ui::CursorSetType cursor_set) {
+ UpdateCursorScale();
+}
+
////////////////////////////////////////////////////////////////////////////////
// SurfaceDelegate overrides:
@@ -294,4 +295,29 @@ Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const {
return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr;
}
+void Pointer::UpdateCursorScale() {
+ if (!focus_)
+ return;
+
+ // Update cursor scale if the effective UI scale has changed.
+ display::Display display =
+ display::Screen::GetScreen()->GetDisplayNearestWindow(
+ widget_->GetNativeWindow());
+ float ui_scale = ash::Shell::GetInstance()
+ ->display_manager()
+ ->GetDisplayInfo(display.id())
+ .GetEffectiveUIScale();
+
+ ash::Shell* ash_shell = ash::Shell::GetInstance();
+ if (ash_shell->cursor_manager()->GetCursorSet() == ui::CURSOR_SET_LARGE)
+ ui_scale *= kLargeCursorScale;
+
+ if (ui_scale != cursor_scale_) {
+ gfx::Transform transform;
+ transform.Scale(ui_scale, ui_scale);
+ widget_->GetNativeWindow()->SetTransform(transform);
+ cursor_scale_ = ui_scale;
+ }
+}
+
} // namespace exo

Powered by Google App Engine
This is Rietveld 408576698