OLD | NEW |
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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 MagnificationControllerImpl::~MagnificationControllerImpl() { | 284 MagnificationControllerImpl::~MagnificationControllerImpl() { |
285 ui::InputMethod* input_method = GetInputMethod(root_window_); | 285 ui::InputMethod* input_method = GetInputMethod(root_window_); |
286 if (input_method) | 286 if (input_method) |
287 input_method->RemoveObserver(this); | 287 input_method->RemoveObserver(this); |
288 | 288 |
289 root_window_->RemoveObserver(this); | 289 root_window_->RemoveObserver(this); |
290 | 290 |
291 Shell::GetInstance()->RemovePreTargetHandler(this); | 291 Shell::GetInstance()->RemovePreTargetHandler(this); |
292 } | 292 } |
293 | 293 |
294 void MagnificationControllerImpl::RedrawKeepingMousePosition( | 294 void MagnificationControllerImpl::RedrawKeepingMousePosition(float scale, |
295 float scale, bool animate) { | 295 bool animate) { |
296 gfx::Point mouse_in_root = point_of_interest_; | 296 gfx::Point mouse_in_root = point_of_interest_; |
297 | 297 |
298 // mouse_in_root is invalid value when the cursor is hidden. | 298 // mouse_in_root is invalid value when the cursor is hidden. |
299 if (!root_window_->bounds().Contains(mouse_in_root)) | 299 if (!root_window_->bounds().Contains(mouse_in_root)) |
300 mouse_in_root = root_window_->bounds().CenterPoint(); | 300 mouse_in_root = root_window_->bounds().CenterPoint(); |
301 | 301 |
302 const gfx::PointF origin = | 302 const gfx::PointF origin = gfx::PointF( |
303 gfx::PointF(mouse_in_root.x() - | 303 mouse_in_root.x() - (scale_ / scale) * (mouse_in_root.x() - origin_.x()), |
304 (scale_ / scale) * (mouse_in_root.x() - origin_.x()), | 304 mouse_in_root.y() - (scale_ / scale) * (mouse_in_root.y() - origin_.y())); |
305 mouse_in_root.y() - | 305 bool changed = |
306 (scale_ / scale) * (mouse_in_root.y() - origin_.y())); | 306 RedrawDIP(origin, scale, animate ? kDefaultAnimationDurationInMs : 0, |
307 bool changed = RedrawDIP(origin, scale, | 307 kDefaultAnimationTweenType); |
308 animate ? kDefaultAnimationDurationInMs : 0, | |
309 kDefaultAnimationTweenType); | |
310 if (changed) | 308 if (changed) |
311 AfterAnimationMoveCursorTo(mouse_in_root); | 309 AfterAnimationMoveCursorTo(mouse_in_root); |
312 } | 310 } |
313 | 311 |
314 bool MagnificationControllerImpl::Redraw(const gfx::PointF& position, | 312 bool MagnificationControllerImpl::Redraw(const gfx::PointF& position, |
315 float scale, | 313 float scale, |
316 bool animate) { | 314 bool animate) { |
317 const gfx::PointF position_in_dip = | 315 const gfx::PointF position_in_dip = |
318 ui::ConvertPointToDIP(root_window_->layer(), position); | 316 ui::ConvertPointToDIP(root_window_->layer(), position); |
319 return RedrawDIP(position_in_dip, scale, | 317 return RedrawDIP(position_in_dip, scale, |
(...skipping 20 matching lines...) Expand all Loading... |
340 const gfx::Size host_size_in_dip = GetHostSizeDIP(); | 338 const gfx::Size host_size_in_dip = GetHostSizeDIP(); |
341 const gfx::SizeF window_size_in_dip = GetWindowRectDIP(scale).size(); | 339 const gfx::SizeF window_size_in_dip = GetWindowRectDIP(scale).size(); |
342 float max_x = host_size_in_dip.width() - window_size_in_dip.width(); | 340 float max_x = host_size_in_dip.width() - window_size_in_dip.width(); |
343 float max_y = host_size_in_dip.height() - window_size_in_dip.height(); | 341 float max_y = host_size_in_dip.height() - window_size_in_dip.height(); |
344 if (x > max_x) | 342 if (x > max_x) |
345 x = max_x; | 343 x = max_x; |
346 if (y > max_y) | 344 if (y > max_y) |
347 y = max_y; | 345 y = max_y; |
348 | 346 |
349 // Does nothing if both the origin and the scale are not changed. | 347 // Does nothing if both the origin and the scale are not changed. |
350 if (origin_.x() == x && | 348 if (origin_.x() == x && origin_.y() == y && scale == scale_) { |
351 origin_.y() == y && | |
352 scale == scale_) { | |
353 return false; | 349 return false; |
354 } | 350 } |
355 | 351 |
356 origin_.set_x(x); | 352 origin_.set_x(x); |
357 origin_.set_y(y); | 353 origin_.set_y(y); |
358 scale_ = scale; | 354 scale_ = scale; |
359 | 355 |
360 // Creates transform matrix. | 356 // Creates transform matrix. |
361 gfx::Transform transform; | 357 gfx::Transform transform; |
362 // Flips the signs intentionally to convert them from the position of the | 358 // Flips the signs intentionally to convert them from the position of the |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 } | 557 } |
562 | 558 |
563 //////////////////////////////////////////////////////////////////////////////// | 559 //////////////////////////////////////////////////////////////////////////////// |
564 // MagnificationControllerImpl: MagnificationController implementation | 560 // MagnificationControllerImpl: MagnificationController implementation |
565 | 561 |
566 void MagnificationControllerImpl::SetScale(float scale, bool animate) { | 562 void MagnificationControllerImpl::SetScale(float scale, bool animate) { |
567 if (!is_enabled_) | 563 if (!is_enabled_) |
568 return; | 564 return; |
569 | 565 |
570 ValidateScale(&scale); | 566 ValidateScale(&scale); |
571 Shell::GetInstance()->accessibility_delegate()-> | 567 Shell::GetInstance()->accessibility_delegate()->SaveScreenMagnifierScale( |
572 SaveScreenMagnifierScale(scale); | 568 scale); |
573 RedrawKeepingMousePosition(scale, animate); | 569 RedrawKeepingMousePosition(scale, animate); |
574 } | 570 } |
575 | 571 |
576 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) { | 572 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) { |
577 if (!is_enabled_) | 573 if (!is_enabled_) |
578 return; | 574 return; |
579 | 575 |
580 Redraw(gfx::PointF(x, y), scale_, animate); | 576 Redraw(gfx::PointF(x, y), scale_, animate); |
581 } | 577 } |
582 | 578 |
(...skipping 11 matching lines...) Expand all Loading... |
594 StartOrStopScrollIfNecessary(); | 590 StartOrStopScrollIfNecessary(); |
595 } | 591 } |
596 | 592 |
597 void MagnificationControllerImpl::SetEnabled(bool enabled) { | 593 void MagnificationControllerImpl::SetEnabled(bool enabled) { |
598 Shell* shell = Shell::GetInstance(); | 594 Shell* shell = Shell::GetInstance(); |
599 ui::InputMethod* input_method = GetInputMethod(root_window_); | 595 ui::InputMethod* input_method = GetInputMethod(root_window_); |
600 if (enabled) { | 596 if (enabled) { |
601 if (!is_enabled_ && input_method) | 597 if (!is_enabled_ && input_method) |
602 input_method->AddObserver(this); | 598 input_method->AddObserver(this); |
603 | 599 |
604 float scale = | 600 float scale = Shell::GetInstance() |
605 Shell::GetInstance()->accessibility_delegate()-> | 601 ->accessibility_delegate() |
606 GetSavedScreenMagnifierScale(); | 602 ->GetSavedScreenMagnifierScale(); |
607 if (scale <= 0.0f) | 603 if (scale <= 0.0f) |
608 scale = kInitialMagnifiedScale; | 604 scale = kInitialMagnifiedScale; |
609 ValidateScale(&scale); | 605 ValidateScale(&scale); |
610 | 606 |
611 // Do nothing, if already enabled with same scale. | 607 // Do nothing, if already enabled with same scale. |
612 if (is_enabled_ && scale == scale_) | 608 if (is_enabled_ && scale == scale_) |
613 return; | 609 return; |
614 | 610 |
615 is_enabled_ = enabled; | 611 is_enabled_ = enabled; |
616 RedrawKeepingMousePosition(scale, true); | 612 RedrawKeepingMousePosition(scale, true); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 caret_point_ = caret_bounds.CenterPoint(); | 814 caret_point_ = caret_bounds.CenterPoint(); |
819 // |caret_point_| in |root_window_| coordinates. | 815 // |caret_point_| in |root_window_| coordinates. |
820 ::wm::ConvertPointFromScreen(root_window_, &caret_point_); | 816 ::wm::ConvertPointFromScreen(root_window_, &caret_point_); |
821 | 817 |
822 // If the feature for centering the text input focus is disabled, the | 818 // If the feature for centering the text input focus is disabled, the |
823 // magnifier window will be moved to follow the focus with a panning margin. | 819 // magnifier window will be moved to follow the focus with a panning margin. |
824 if (!KeepFocusCentered()) { | 820 if (!KeepFocusCentered()) { |
825 // Visible window_rect in |root_window_| coordinates. | 821 // Visible window_rect in |root_window_| coordinates. |
826 const gfx::Rect visible_window_rect = GetViewportRect(); | 822 const gfx::Rect visible_window_rect = GetViewportRect(); |
827 const int panning_margin = kCaretPanningMargin / scale_; | 823 const int panning_margin = kCaretPanningMargin / scale_; |
828 MoveMagnifierWindowFollowPoint(caret_point_, | 824 MoveMagnifierWindowFollowPoint(caret_point_, panning_margin, panning_margin, |
829 panning_margin, | |
830 panning_margin, | |
831 visible_window_rect.width() / 2, | 825 visible_window_rect.width() / 2, |
832 visible_window_rect.height() / 2); | 826 visible_window_rect.height() / 2); |
833 return; | 827 return; |
834 } | 828 } |
835 | 829 |
836 // Move the magnifier window to center the focus with a little delay. | 830 // Move the magnifier window to center the focus with a little delay. |
837 // In Gmail compose window, when user types a blank space, it will insert | 831 // In Gmail compose window, when user types a blank space, it will insert |
838 // a non-breaking space(NBSP). NBSP will be replaced with a blank space | 832 // a non-breaking space(NBSP). NBSP will be replaced with a blank space |
839 // character when user types a non-blank space character later, which causes | 833 // character when user types a non-blank space character later, which causes |
840 // OnCaretBoundsChanged be called twice. The first call moves the caret back | 834 // OnCaretBoundsChanged be called twice. The first call moves the caret back |
(...skipping 13 matching lines...) Expand all Loading... |
854 | 848 |
855 //////////////////////////////////////////////////////////////////////////////// | 849 //////////////////////////////////////////////////////////////////////////////// |
856 // MagnificationController: | 850 // MagnificationController: |
857 | 851 |
858 // static | 852 // static |
859 MagnificationController* MagnificationController::CreateInstance() { | 853 MagnificationController* MagnificationController::CreateInstance() { |
860 return new MagnificationControllerImpl(); | 854 return new MagnificationControllerImpl(); |
861 } | 855 } |
862 | 856 |
863 } // namespace ash | 857 } // namespace ash |
OLD | NEW |