| 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 "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
| 8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
| 9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 10 #include "ash/display/root_window_transformers.h" | 10 #include "ash/display/root_window_transformers.h" |
| 11 #include "ash/host/ash_window_tree_host.h" | 11 #include "ash/host/ash_window_tree_host.h" |
| 12 #include "ash/host/root_window_transformer.h" | 12 #include "ash/host/root_window_transformer.h" |
| 13 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
| 14 #include "ash/screen_util.h" | 14 #include "ash/screen_util.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/system/tray/system_tray_delegate.h" | 16 #include "ash/system/tray/system_tray_delegate.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
| 19 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
| 20 #include "ui/aura/client/aura_constants.h" | |
| 21 #include "ui/aura/client/cursor_client.h" | 20 #include "ui/aura/client/cursor_client.h" |
| 22 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 23 #include "ui/aura/window_tree_host.h" | 22 #include "ui/aura/window_tree_host.h" |
| 24 #include "ui/base/ime/input_method.h" | 23 #include "ui/base/ime/input_method.h" |
| 25 #include "ui/base/ime/input_method_observer.h" | 24 #include "ui/base/ime/input_method_observer.h" |
| 26 #include "ui/base/ime/text_input_client.h" | 25 #include "ui/base/ime/text_input_client.h" |
| 27 #include "ui/compositor/dip_util.h" | 26 #include "ui/compositor/dip_util.h" |
| 28 #include "ui/compositor/layer.h" | 27 #include "ui/compositor/layer.h" |
| 29 #include "ui/compositor/layer_animation_observer.h" | 28 #include "ui/compositor/layer_animation_observer.h" |
| 30 #include "ui/compositor/scoped_layer_animation_settings.h" | 29 #include "ui/compositor/scoped_layer_animation_settings.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // |kCaretPanningMargin| from the edge, the view-port moves. | 67 // |kCaretPanningMargin| from the edge, the view-port moves. |
| 69 const int kCaretPanningMargin = 50; | 68 const int kCaretPanningMargin = 50; |
| 70 | 69 |
| 71 void MoveCursorTo(aura::WindowTreeHost* host, const gfx::Point& root_location) { | 70 void MoveCursorTo(aura::WindowTreeHost* host, const gfx::Point& root_location) { |
| 72 gfx::Point3F host_location_3f(root_location); | 71 gfx::Point3F host_location_3f(root_location); |
| 73 host->GetRootTransform().TransformPoint(&host_location_3f); | 72 host->GetRootTransform().TransformPoint(&host_location_3f); |
| 74 host->MoveCursorToHostLocation( | 73 host->MoveCursorToHostLocation( |
| 75 gfx::ToCeiledPoint(host_location_3f.AsPointF())); | 74 gfx::ToCeiledPoint(host_location_3f.AsPointF())); |
| 76 } | 75 } |
| 77 | 76 |
| 77 ui::InputMethod* GetInputMethod(aura::Window* root_window) { |
| 78 if (root_window->GetHost()) |
| 79 return root_window->GetHost()->GetInputMethod(); |
| 80 return nullptr; |
| 81 } |
| 82 |
| 78 } // namespace | 83 } // namespace |
| 79 | 84 |
| 80 namespace ash { | 85 namespace ash { |
| 81 | 86 |
| 82 //////////////////////////////////////////////////////////////////////////////// | 87 //////////////////////////////////////////////////////////////////////////////// |
| 83 // MagnificationControllerImpl: | 88 // MagnificationControllerImpl: |
| 84 | 89 |
| 85 class MagnificationControllerImpl : virtual public MagnificationController, | 90 class MagnificationControllerImpl : virtual public MagnificationController, |
| 86 public ui::EventHandler, | 91 public ui::EventHandler, |
| 87 public ui::ImplicitAnimationObserver, | 92 public ui::ImplicitAnimationObserver, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // Stores the last mouse cursor (or last touched) location. This value is | 240 // Stores the last mouse cursor (or last touched) location. This value is |
| 236 // used on zooming to keep this location visible. | 241 // used on zooming to keep this location visible. |
| 237 gfx::Point point_of_interest_; | 242 gfx::Point point_of_interest_; |
| 238 | 243 |
| 239 // Current scale, origin (left-top) position of the magnification window. | 244 // Current scale, origin (left-top) position of the magnification window. |
| 240 float scale_; | 245 float scale_; |
| 241 gfx::PointF origin_; | 246 gfx::PointF origin_; |
| 242 | 247 |
| 243 ScrollDirection scroll_direction_; | 248 ScrollDirection scroll_direction_; |
| 244 | 249 |
| 245 ui::InputMethod* input_method_; // Not owned. | |
| 246 | |
| 247 // Timer for moving magnifier window when it fires. | 250 // Timer for moving magnifier window when it fires. |
| 248 base::OneShotTimer<MagnificationControllerImpl> move_magnifier_timer_; | 251 base::OneShotTimer<MagnificationControllerImpl> move_magnifier_timer_; |
| 249 | 252 |
| 250 // Most recent caret position in |root_window_| coordinates. | 253 // Most recent caret position in |root_window_| coordinates. |
| 251 gfx::Point caret_point_; | 254 gfx::Point caret_point_; |
| 252 | 255 |
| 253 // Flag for disabling moving magnifier delay. It can only be true in testing | 256 // Flag for disabling moving magnifier delay. It can only be true in testing |
| 254 // mode. | 257 // mode. |
| 255 bool disable_move_magnifier_delay_; | 258 bool disable_move_magnifier_delay_; |
| 256 | 259 |
| 257 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl); | 260 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl); |
| 258 }; | 261 }; |
| 259 | 262 |
| 260 //////////////////////////////////////////////////////////////////////////////// | 263 //////////////////////////////////////////////////////////////////////////////// |
| 261 // MagnificationControllerImpl: | 264 // MagnificationControllerImpl: |
| 262 | 265 |
| 263 MagnificationControllerImpl::MagnificationControllerImpl() | 266 MagnificationControllerImpl::MagnificationControllerImpl() |
| 264 : root_window_(Shell::GetPrimaryRootWindow()), | 267 : root_window_(Shell::GetPrimaryRootWindow()), |
| 265 is_on_animation_(false), | 268 is_on_animation_(false), |
| 266 is_enabled_(false), | 269 is_enabled_(false), |
| 267 keep_focus_centered_(false), | 270 keep_focus_centered_(false), |
| 268 move_cursor_after_animation_(false), | 271 move_cursor_after_animation_(false), |
| 269 scale_(kNonMagnifiedScale), | 272 scale_(kNonMagnifiedScale), |
| 270 scroll_direction_(SCROLL_NONE), | 273 scroll_direction_(SCROLL_NONE), |
| 271 input_method_(NULL), | |
| 272 disable_move_magnifier_delay_(false) { | 274 disable_move_magnifier_delay_(false) { |
| 273 Shell::GetInstance()->AddPreTargetHandler(this); | 275 Shell::GetInstance()->AddPreTargetHandler(this); |
| 274 root_window_->AddObserver(this); | 276 root_window_->AddObserver(this); |
| 275 point_of_interest_ = root_window_->bounds().CenterPoint(); | 277 point_of_interest_ = root_window_->bounds().CenterPoint(); |
| 276 } | 278 } |
| 277 | 279 |
| 278 MagnificationControllerImpl::~MagnificationControllerImpl() { | 280 MagnificationControllerImpl::~MagnificationControllerImpl() { |
| 279 if (input_method_) | 281 ui::InputMethod* input_method = GetInputMethod(root_window_); |
| 280 input_method_->RemoveObserver(this); | 282 if (input_method) |
| 283 input_method->RemoveObserver(this); |
| 281 | 284 |
| 282 root_window_->RemoveObserver(this); | 285 root_window_->RemoveObserver(this); |
| 283 | 286 |
| 284 Shell::GetInstance()->RemovePreTargetHandler(this); | 287 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 285 } | 288 } |
| 286 | 289 |
| 287 void MagnificationControllerImpl::RedrawKeepingMousePosition( | 290 void MagnificationControllerImpl::RedrawKeepingMousePosition( |
| 288 float scale, bool animate) { | 291 float scale, bool animate) { |
| 289 gfx::Point mouse_in_root = point_of_interest_; | 292 gfx::Point mouse_in_root = point_of_interest_; |
| 290 | 293 |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 } | 580 } |
| 578 | 581 |
| 579 void MagnificationControllerImpl::SetScrollDirection( | 582 void MagnificationControllerImpl::SetScrollDirection( |
| 580 ScrollDirection direction) { | 583 ScrollDirection direction) { |
| 581 scroll_direction_ = direction; | 584 scroll_direction_ = direction; |
| 582 StartOrStopScrollIfNecessary(); | 585 StartOrStopScrollIfNecessary(); |
| 583 } | 586 } |
| 584 | 587 |
| 585 void MagnificationControllerImpl::SetEnabled(bool enabled) { | 588 void MagnificationControllerImpl::SetEnabled(bool enabled) { |
| 586 Shell* shell = Shell::GetInstance(); | 589 Shell* shell = Shell::GetInstance(); |
| 590 ui::InputMethod* input_method = GetInputMethod(root_window_); |
| 587 if (enabled) { | 591 if (enabled) { |
| 588 if (!input_method_) { | 592 if (!is_enabled_ && input_method) |
| 589 input_method_ = | 593 input_method->AddObserver(this); |
| 590 root_window_->GetProperty(aura::client::kRootWindowInputMethodKey); | |
| 591 if (input_method_) | |
| 592 input_method_->AddObserver(this); | |
| 593 } | |
| 594 | 594 |
| 595 float scale = | 595 float scale = |
| 596 Shell::GetInstance()->accessibility_delegate()-> | 596 Shell::GetInstance()->accessibility_delegate()-> |
| 597 GetSavedScreenMagnifierScale(); | 597 GetSavedScreenMagnifierScale(); |
| 598 if (scale <= 0.0f) | 598 if (scale <= 0.0f) |
| 599 scale = kInitialMagnifiedScale; | 599 scale = kInitialMagnifiedScale; |
| 600 ValidateScale(&scale); | 600 ValidateScale(&scale); |
| 601 | 601 |
| 602 // Do nothing, if already enabled with same scale. | 602 // Do nothing, if already enabled with same scale. |
| 603 if (is_enabled_ && scale == scale_) | 603 if (is_enabled_ && scale == scale_) |
| 604 return; | 604 return; |
| 605 | 605 |
| 606 is_enabled_ = enabled; | 606 is_enabled_ = enabled; |
| 607 RedrawKeepingMousePosition(scale, true); | 607 RedrawKeepingMousePosition(scale, true); |
| 608 shell->accessibility_delegate()->SaveScreenMagnifierScale(scale); | 608 shell->accessibility_delegate()->SaveScreenMagnifierScale(scale); |
| 609 } else { | 609 } else { |
| 610 // Do nothing, if already disabled. | 610 // Do nothing, if already disabled. |
| 611 if (!is_enabled_) | 611 if (!is_enabled_) |
| 612 return; | 612 return; |
| 613 | 613 |
| 614 if (input_method_) { | 614 if (input_method) |
| 615 input_method_->RemoveObserver(this); | 615 input_method->RemoveObserver(this); |
| 616 input_method_ = NULL; | |
| 617 } | |
| 618 | 616 |
| 619 RedrawKeepingMousePosition(kNonMagnifiedScale, true); | 617 RedrawKeepingMousePosition(kNonMagnifiedScale, true); |
| 620 is_enabled_ = enabled; | 618 is_enabled_ = enabled; |
| 621 } | 619 } |
| 622 } | 620 } |
| 623 | 621 |
| 624 bool MagnificationControllerImpl::IsEnabled() const { | 622 bool MagnificationControllerImpl::IsEnabled() const { |
| 625 return is_enabled_; | 623 return is_enabled_; |
| 626 } | 624 } |
| 627 | 625 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 | 846 |
| 849 //////////////////////////////////////////////////////////////////////////////// | 847 //////////////////////////////////////////////////////////////////////////////// |
| 850 // MagnificationController: | 848 // MagnificationController: |
| 851 | 849 |
| 852 // static | 850 // static |
| 853 MagnificationController* MagnificationController::CreateInstance() { | 851 MagnificationController* MagnificationController::CreateInstance() { |
| 854 return new MagnificationControllerImpl(); | 852 return new MagnificationControllerImpl(); |
| 855 } | 853 } |
| 856 | 854 |
| 857 } // namespace ash | 855 } // namespace ash |
| OLD | NEW |