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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 // view-port before the caret is completely out of sight. | 55 // view-port before the caret is completely out of sight. |
56 const int kCaretPanningMargin = 10; | 56 const int kCaretPanningMargin = 10; |
57 | 57 |
58 void MoveCursorTo(aura::WindowTreeHost* host, const gfx::Point& root_location) { | 58 void MoveCursorTo(aura::WindowTreeHost* host, const gfx::Point& root_location) { |
59 gfx::Point3F host_location_3f(root_location); | 59 gfx::Point3F host_location_3f(root_location); |
60 host->GetRootTransform().TransformPoint(&host_location_3f); | 60 host->GetRootTransform().TransformPoint(&host_location_3f); |
61 host->MoveCursorToHostLocation( | 61 host->MoveCursorToHostLocation( |
62 gfx::ToCeiledPoint(host_location_3f.AsPointF())); | 62 gfx::ToCeiledPoint(host_location_3f.AsPointF())); |
63 } | 63 } |
64 | 64 |
65 ui::InputMethod* GetInputMethod(aura::Window* root_window) { | |
66 if (root_window->GetHost()) | |
67 return root_window->GetHost()->GetInputMethod(); | |
68 return NULL; | |
James Cook
2015/06/01 22:20:59
nullptr
Shu Chen
2015/06/02 04:11:16
Done.
| |
69 } | |
70 | |
65 } // namespace | 71 } // namespace |
66 | 72 |
67 namespace ash { | 73 namespace ash { |
68 | 74 |
69 //////////////////////////////////////////////////////////////////////////////// | 75 //////////////////////////////////////////////////////////////////////////////// |
70 // MagnificationControllerImpl: | 76 // MagnificationControllerImpl: |
71 | 77 |
72 class MagnificationControllerImpl : virtual public MagnificationController, | 78 class MagnificationControllerImpl : virtual public MagnificationController, |
73 public ui::EventHandler, | 79 public ui::EventHandler, |
74 public ui::ImplicitAnimationObserver, | 80 public ui::ImplicitAnimationObserver, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 // Stores the last mouse cursor (or last touched) location. This value is | 204 // Stores the last mouse cursor (or last touched) location. This value is |
199 // used on zooming to keep this location visible. | 205 // used on zooming to keep this location visible. |
200 gfx::Point point_of_interest_; | 206 gfx::Point point_of_interest_; |
201 | 207 |
202 // Current scale, origin (left-top) position of the magnification window. | 208 // Current scale, origin (left-top) position of the magnification window. |
203 float scale_; | 209 float scale_; |
204 gfx::PointF origin_; | 210 gfx::PointF origin_; |
205 | 211 |
206 ScrollDirection scroll_direction_; | 212 ScrollDirection scroll_direction_; |
207 | 213 |
208 ui::InputMethod* input_method_; // Not owned. | |
209 | |
210 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl); | 214 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl); |
211 }; | 215 }; |
212 | 216 |
213 //////////////////////////////////////////////////////////////////////////////// | 217 //////////////////////////////////////////////////////////////////////////////// |
214 // MagnificationControllerImpl: | 218 // MagnificationControllerImpl: |
215 | 219 |
216 MagnificationControllerImpl::MagnificationControllerImpl() | 220 MagnificationControllerImpl::MagnificationControllerImpl() |
217 : root_window_(Shell::GetPrimaryRootWindow()), | 221 : root_window_(Shell::GetPrimaryRootWindow()), |
218 is_on_animation_(false), | 222 is_on_animation_(false), |
219 is_enabled_(false), | 223 is_enabled_(false), |
220 move_cursor_after_animation_(false), | 224 move_cursor_after_animation_(false), |
221 scale_(kNonMagnifiedScale), | 225 scale_(kNonMagnifiedScale), |
222 scroll_direction_(SCROLL_NONE), | 226 scroll_direction_(SCROLL_NONE) { |
223 input_method_(NULL) { | |
224 Shell::GetInstance()->AddPreTargetHandler(this); | 227 Shell::GetInstance()->AddPreTargetHandler(this); |
225 root_window_->AddObserver(this); | 228 root_window_->AddObserver(this); |
226 point_of_interest_ = root_window_->bounds().CenterPoint(); | 229 point_of_interest_ = root_window_->bounds().CenterPoint(); |
227 } | 230 } |
228 | 231 |
229 MagnificationControllerImpl::~MagnificationControllerImpl() { | 232 MagnificationControllerImpl::~MagnificationControllerImpl() { |
230 if (input_method_) | 233 ui::InputMethod* input_method = GetInputMethod(root_window_); |
231 input_method_->RemoveObserver(this); | 234 if (input_method) |
235 input_method->RemoveObserver(this); | |
232 | 236 |
233 root_window_->RemoveObserver(this); | 237 root_window_->RemoveObserver(this); |
234 | 238 |
235 Shell::GetInstance()->RemovePreTargetHandler(this); | 239 Shell::GetInstance()->RemovePreTargetHandler(this); |
236 } | 240 } |
237 | 241 |
238 void MagnificationControllerImpl::RedrawKeepingMousePosition( | 242 void MagnificationControllerImpl::RedrawKeepingMousePosition( |
239 float scale, bool animate) { | 243 float scale, bool animate) { |
240 gfx::Point mouse_in_root = point_of_interest_; | 244 gfx::Point mouse_in_root = point_of_interest_; |
241 | 245 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 } | 526 } |
523 | 527 |
524 void MagnificationControllerImpl::SetScrollDirection( | 528 void MagnificationControllerImpl::SetScrollDirection( |
525 ScrollDirection direction) { | 529 ScrollDirection direction) { |
526 scroll_direction_ = direction; | 530 scroll_direction_ = direction; |
527 StartOrStopScrollIfNecessary(); | 531 StartOrStopScrollIfNecessary(); |
528 } | 532 } |
529 | 533 |
530 void MagnificationControllerImpl::SetEnabled(bool enabled) { | 534 void MagnificationControllerImpl::SetEnabled(bool enabled) { |
531 Shell* shell = Shell::GetInstance(); | 535 Shell* shell = Shell::GetInstance(); |
536 ui::InputMethod* input_method = GetInputMethod(root_window_); | |
532 if (enabled) { | 537 if (enabled) { |
533 if (!input_method_) { | 538 if (!is_enabled_ && input_method) |
534 input_method_ = | 539 input_method->AddObserver(this); |
535 root_window_->GetProperty(aura::client::kRootWindowInputMethodKey); | |
536 if (input_method_) | |
537 input_method_->AddObserver(this); | |
538 } | |
539 | 540 |
540 float scale = | 541 float scale = |
541 Shell::GetInstance()->accessibility_delegate()-> | 542 Shell::GetInstance()->accessibility_delegate()-> |
542 GetSavedScreenMagnifierScale(); | 543 GetSavedScreenMagnifierScale(); |
543 if (scale <= 0.0f) | 544 if (scale <= 0.0f) |
544 scale = kInitialMagnifiedScale; | 545 scale = kInitialMagnifiedScale; |
545 ValidateScale(&scale); | 546 ValidateScale(&scale); |
546 | 547 |
547 // Do nothing, if already enabled with same scale. | 548 // Do nothing, if already enabled with same scale. |
548 if (is_enabled_ && scale == scale_) | 549 if (is_enabled_ && scale == scale_) |
549 return; | 550 return; |
550 | 551 |
551 is_enabled_ = enabled; | 552 is_enabled_ = enabled; |
552 RedrawKeepingMousePosition(scale, true); | 553 RedrawKeepingMousePosition(scale, true); |
553 shell->accessibility_delegate()->SaveScreenMagnifierScale(scale); | 554 shell->accessibility_delegate()->SaveScreenMagnifierScale(scale); |
554 } else { | 555 } else { |
555 // Do nothing, if already disabled. | 556 // Do nothing, if already disabled. |
556 if (!is_enabled_) | 557 if (!is_enabled_) |
557 return; | 558 return; |
558 | 559 |
559 if (input_method_) { | 560 if (input_method) |
560 input_method_->RemoveObserver(this); | 561 input_method->RemoveObserver(this); |
561 input_method_ = NULL; | |
562 } | |
563 | 562 |
564 RedrawKeepingMousePosition(kNonMagnifiedScale, true); | 563 RedrawKeepingMousePosition(kNonMagnifiedScale, true); |
565 is_enabled_ = enabled; | 564 is_enabled_ = enabled; |
566 } | 565 } |
567 } | 566 } |
568 | 567 |
569 bool MagnificationControllerImpl::IsEnabled() const { | 568 bool MagnificationControllerImpl::IsEnabled() const { |
570 return is_enabled_; | 569 return is_enabled_; |
571 } | 570 } |
572 | 571 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 | 737 |
739 //////////////////////////////////////////////////////////////////////////////// | 738 //////////////////////////////////////////////////////////////////////////////// |
740 // MagnificationController: | 739 // MagnificationController: |
741 | 740 |
742 // static | 741 // static |
743 MagnificationController* MagnificationController::CreateInstance() { | 742 MagnificationController* MagnificationController::CreateInstance() { |
744 return new MagnificationControllerImpl(); | 743 return new MagnificationControllerImpl(); |
745 } | 744 } |
746 | 745 |
747 } // namespace ash | 746 } // namespace ash |
OLD | NEW |