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

Side by Side Diff: ash/magnifier/magnification_controller.cc

Issue 2886843004: Fix jittering cursor in screen magnifier mode (Closed)
Patch Set: Fix unstable cursor in dual-display magnified mode Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | ash/magnifier/magnification_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/magnifier/magnification_controller.h" 5 #include "ash/magnifier/magnification_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/accelerators/accelerator_controller.h" 10 #include "ash/accelerators/accelerator_controller.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // 1) If the screen is scrolling (i.e. animating) and should scroll further, 160 // 1) If the screen is scrolling (i.e. animating) and should scroll further,
161 // it does nothing. 161 // it does nothing.
162 // 2) If the screen is scrolling (i.e. animating) and the direction is NONE, 162 // 2) If the screen is scrolling (i.e. animating) and the direction is NONE,
163 // it stops the scrolling animation. 163 // it stops the scrolling animation.
164 // 3) If the direction is set to value other than NONE, it starts the 164 // 3) If the direction is set to value other than NONE, it starts the
165 // scrolling/ animation towards that direction. 165 // scrolling/ animation towards that direction.
166 void StartOrStopScrollIfNecessary(); 166 void StartOrStopScrollIfNecessary();
167 167
168 // Redraw with the given zoom scale keeping the mouse cursor location. In 168 // Redraw with the given zoom scale keeping the mouse cursor location. In
169 // other words, zoom (or unzoom) centering around the cursor. 169 // other words, zoom (or unzoom) centering around the cursor.
170 void RedrawKeepingMousePosition(float scale, bool animate); 170 // Ignore mouse position change after redrawing if |ignore_mouse_change| is
171 // true.
172 void RedrawKeepingMousePosition(float scale,
173 bool animate,
174 bool ignore_mouse_change);
171 175
172 void OnMouseMove(const gfx::Point& location); 176 void OnMouseMove(const gfx::Point& location);
173 177
174 // Move the mouse cursot to the given point. Actual move will be done when 178 // Move the mouse cursot to the given point. Actual move will be done when
175 // the animation is completed. This should be called after animation is 179 // the animation is completed. This should be called after animation is
176 // started. 180 // started.
177 void AfterAnimationMoveCursorTo(const gfx::Point& location); 181 void AfterAnimationMoveCursorTo(const gfx::Point& location);
178 182
179 // Returns if the magnification scale is 1.0 or not (larger then 1.0). 183 // Returns if the magnification scale is 1.0 or not (larger then 1.0).
180 bool IsMagnified() const; 184 bool IsMagnified() const;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 MagnificationControllerImpl::~MagnificationControllerImpl() { 289 MagnificationControllerImpl::~MagnificationControllerImpl() {
286 ui::InputMethod* input_method = GetInputMethod(root_window_); 290 ui::InputMethod* input_method = GetInputMethod(root_window_);
287 if (input_method) 291 if (input_method)
288 input_method->RemoveObserver(this); 292 input_method->RemoveObserver(this);
289 293
290 root_window_->RemoveObserver(this); 294 root_window_->RemoveObserver(this);
291 295
292 Shell::Get()->RemovePreTargetHandler(this); 296 Shell::Get()->RemovePreTargetHandler(this);
293 } 297 }
294 298
295 void MagnificationControllerImpl::RedrawKeepingMousePosition(float scale, 299 void MagnificationControllerImpl::RedrawKeepingMousePosition(
296 bool animate) { 300 float scale,
301 bool animate,
302 bool ignore_mouse_change) {
297 gfx::Point mouse_in_root = point_of_interest_; 303 gfx::Point mouse_in_root = point_of_interest_;
298
299 // mouse_in_root is invalid value when the cursor is hidden. 304 // mouse_in_root is invalid value when the cursor is hidden.
300 if (!root_window_->bounds().Contains(mouse_in_root)) 305 if (!root_window_->bounds().Contains(mouse_in_root))
301 mouse_in_root = root_window_->bounds().CenterPoint(); 306 mouse_in_root = root_window_->bounds().CenterPoint();
302 307
303 const gfx::PointF origin = gfx::PointF( 308 const gfx::PointF origin = gfx::PointF(
304 mouse_in_root.x() - (scale_ / scale) * (mouse_in_root.x() - origin_.x()), 309 mouse_in_root.x() - (scale_ / scale) * (mouse_in_root.x() - origin_.x()),
305 mouse_in_root.y() - (scale_ / scale) * (mouse_in_root.y() - origin_.y())); 310 mouse_in_root.y() - (scale_ / scale) * (mouse_in_root.y() - origin_.y()));
306 bool changed = 311 bool changed =
307 RedrawDIP(origin, scale, animate ? kDefaultAnimationDurationInMs : 0, 312 RedrawDIP(origin, scale, animate ? kDefaultAnimationDurationInMs : 0,
308 kDefaultAnimationTweenType); 313 kDefaultAnimationTweenType);
309 if (changed) 314 if (!ignore_mouse_change && changed)
310 AfterAnimationMoveCursorTo(mouse_in_root); 315 AfterAnimationMoveCursorTo(mouse_in_root);
311 } 316 }
312 317
313 bool MagnificationControllerImpl::Redraw(const gfx::PointF& position, 318 bool MagnificationControllerImpl::Redraw(const gfx::PointF& position,
314 float scale, 319 float scale,
315 bool animate) { 320 bool animate) {
316 const gfx::PointF position_in_dip = 321 const gfx::PointF position_in_dip =
317 ui::ConvertPointToDIP(root_window_->layer(), position); 322 ui::ConvertPointToDIP(root_window_->layer(), position);
318 return RedrawDIP(position_in_dip, scale, 323 return RedrawDIP(position_in_dip, scale,
319 animate ? kDefaultAnimationDurationInMs : 0, 324 animate ? kDefaultAnimationDurationInMs : 0,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 DCHECK(new_root_window); 457 DCHECK(new_root_window);
453 458
454 if (new_root_window == root_window_) 459 if (new_root_window == root_window_)
455 return; 460 return;
456 461
457 // Stores the previous scale. 462 // Stores the previous scale.
458 float scale = GetScale(); 463 float scale = GetScale();
459 464
460 // Unmagnify the previous root window. 465 // Unmagnify the previous root window.
461 root_window_->RemoveObserver(this); 466 root_window_->RemoveObserver(this);
467 // Do not move mouse back to its original position (point at border of the
468 // root window) after redrawing as doing so will trigger root window switch
469 // again.
462 if (redraw_original_root_window) 470 if (redraw_original_root_window)
463 RedrawKeepingMousePosition(1.0f, true); 471 RedrawKeepingMousePosition(1.0f, true, true);
464 root_window_ = new_root_window; 472 root_window_ = new_root_window;
465 RedrawKeepingMousePosition(scale, true); 473 RedrawKeepingMousePosition(scale, true, true);
474
466 root_window_->AddObserver(this); 475 root_window_->AddObserver(this);
467 } 476 }
468 477
469 void MagnificationControllerImpl::AfterAnimationMoveCursorTo( 478 void MagnificationControllerImpl::AfterAnimationMoveCursorTo(
470 const gfx::Point& location) { 479 const gfx::Point& location) {
471 DCHECK(root_window_); 480 DCHECK(root_window_);
472 481
473 aura::client::CursorClient* cursor_client = 482 aura::client::CursorClient* cursor_client =
474 aura::client::GetCursorClient(root_window_); 483 aura::client::GetCursorClient(root_window_);
475 if (cursor_client) { 484 if (cursor_client) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 568
560 //////////////////////////////////////////////////////////////////////////////// 569 ////////////////////////////////////////////////////////////////////////////////
561 // MagnificationControllerImpl: MagnificationController implementation 570 // MagnificationControllerImpl: MagnificationController implementation
562 571
563 void MagnificationControllerImpl::SetScale(float scale, bool animate) { 572 void MagnificationControllerImpl::SetScale(float scale, bool animate) {
564 if (!is_enabled_) 573 if (!is_enabled_)
565 return; 574 return;
566 575
567 ValidateScale(&scale); 576 ValidateScale(&scale);
568 Shell::Get()->accessibility_delegate()->SaveScreenMagnifierScale(scale); 577 Shell::Get()->accessibility_delegate()->SaveScreenMagnifierScale(scale);
569 RedrawKeepingMousePosition(scale, animate); 578 RedrawKeepingMousePosition(scale, animate, false);
570 } 579 }
571 580
572 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) { 581 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) {
573 if (!is_enabled_) 582 if (!is_enabled_)
574 return; 583 return;
575 584
576 Redraw(gfx::PointF(x, y), scale_, animate); 585 Redraw(gfx::PointF(x, y), scale_, animate);
577 } 586 }
578 587
579 void MagnificationControllerImpl::MoveWindow(const gfx::Point& point, 588 void MagnificationControllerImpl::MoveWindow(const gfx::Point& point,
(...skipping 21 matching lines...) Expand all
601 shell->accessibility_delegate()->GetSavedScreenMagnifierScale(); 610 shell->accessibility_delegate()->GetSavedScreenMagnifierScale();
602 if (scale <= 0.0f) 611 if (scale <= 0.0f)
603 scale = kInitialMagnifiedScale; 612 scale = kInitialMagnifiedScale;
604 ValidateScale(&scale); 613 ValidateScale(&scale);
605 614
606 // Do nothing, if already enabled with same scale. 615 // Do nothing, if already enabled with same scale.
607 if (is_enabled_ && scale == scale_) 616 if (is_enabled_ && scale == scale_)
608 return; 617 return;
609 618
610 is_enabled_ = enabled; 619 is_enabled_ = enabled;
611 RedrawKeepingMousePosition(scale, true); 620 RedrawKeepingMousePosition(scale, true, false);
612 shell->accessibility_delegate()->SaveScreenMagnifierScale(scale); 621 shell->accessibility_delegate()->SaveScreenMagnifierScale(scale);
613 } else { 622 } else {
614 // Do nothing, if already disabled. 623 // Do nothing, if already disabled.
615 if (!is_enabled_) 624 if (!is_enabled_)
616 return; 625 return;
617 626
618 if (input_method) 627 if (input_method)
619 input_method->RemoveObserver(this); 628 input_method->RemoveObserver(this);
620 629
621 RedrawKeepingMousePosition(kNonMagnifiedScale, true); 630 RedrawKeepingMousePosition(kNonMagnifiedScale, true, false);
622 is_enabled_ = enabled; 631 is_enabled_ = enabled;
623 } 632 }
624 } 633 }
625 634
626 bool MagnificationControllerImpl::IsEnabled() const { 635 bool MagnificationControllerImpl::IsEnabled() const {
627 return is_enabled_; 636 return is_enabled_;
628 } 637 }
629 638
630 void MagnificationControllerImpl::SetKeepFocusCentered( 639 void MagnificationControllerImpl::SetKeepFocusCentered(
631 bool keep_focus_centered) { 640 bool keep_focus_centered) {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 894
886 //////////////////////////////////////////////////////////////////////////////// 895 ////////////////////////////////////////////////////////////////////////////////
887 // MagnificationController: 896 // MagnificationController:
888 897
889 // static 898 // static
890 MagnificationController* MagnificationController::CreateInstance() { 899 MagnificationController* MagnificationController::CreateInstance() {
891 return new MagnificationControllerImpl(); 900 return new MagnificationControllerImpl();
892 } 901 }
893 902
894 } // namespace ash 903 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/magnifier/magnification_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698