Chromium Code Reviews| Index: components/exo/pointer.cc |
| diff --git a/components/exo/pointer.cc b/components/exo/pointer.cc |
| index 6c0c6482e26e753e6a00c62e76cb684625c378c3..e8a440b71a0a9874398dbf2eb9d8b881b8c377a9 100644 |
| --- a/components/exo/pointer.cc |
| +++ b/components/exo/pointer.cc |
| @@ -39,7 +39,13 @@ Pointer::Pointer(PointerDelegate* delegate) |
| surface_(nullptr), |
| focus_(nullptr), |
| cursor_scale_(1.0f) { |
| - ash::Shell::GetInstance()->AddPreTargetHandler(this); |
| + ash::Shell* ash_shell = ash::Shell::GetInstance(); |
|
reveman
2016/06/15 17:48:30
nit: not sure this temporary variable is needed bu
|
| + ash_shell->AddPreTargetHandler(this); |
| + |
| + wm::CursorManager* cursor_manager = ash_shell->cursor_manager(); |
| + DCHECK(cursor_manager); |
| + cursor_manager->AddObserver(this); |
| + use_large_cursor_ = (cursor_manager->GetCursorSet() == ui::CURSOR_SET_LARGE); |
| } |
| Pointer::~Pointer() { |
| @@ -52,6 +58,9 @@ Pointer::~Pointer() { |
| } |
| if (widget_) |
| widget_->CloseNow(); |
| + |
| + DCHECK(ash::Shell::GetInstance()->cursor_manager()); |
| + ash::Shell::GetInstance()->cursor_manager()->RemoveObserver(this); |
| ash::Shell::GetInstance()->RemovePreTargetHandler(this); |
| } |
| @@ -211,21 +220,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; |
| - } |
| + ResetCursor(); |
| } else { |
| if (widget_ && widget_->IsVisible()) |
| widget_->Hide(); |
| @@ -236,6 +231,11 @@ void Pointer::OnScrollEvent(ui::ScrollEvent* event) { |
| OnMouseEvent(event); |
| } |
| +void Pointer::OnCursorSetChanged(ui::CursorSetType cursor_set) { |
| + use_large_cursor_ = (cursor_set == ui::CURSOR_SET_LARGE); |
| + ResetCursor(); |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // SurfaceDelegate overrides: |
| @@ -294,4 +294,29 @@ Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const { |
| return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr; |
| } |
| +void Pointer::ResetCursor() { |
| + 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(); |
| + |
| + // TODO(yoshiki): Use large cursor asset instead of scaling. |
|
reveman
2016/06/15 17:48:30
nit: Remove this TODO as we should still apply the
|
| + if (use_large_cursor_) |
| + ui_scale *= 2; |
| + |
| + if (ui_scale != cursor_scale_) { |
| + gfx::Transform transform; |
| + transform.Scale(ui_scale, ui_scale); |
| + widget_->GetNativeWindow()->SetTransform(transform); |
| + cursor_scale_ = ui_scale; |
| + } |
| +} |
| + |
| } // namespace exo |