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

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

Issue 155493002: Add key based scrolling on magnified screen for kiosk mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
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 "ash/accelerators/accelerator_controller.h"
7 #include "ash/accessibility_delegate.h" 8 #include "ash/accessibility_delegate.h"
9 #include "ash/ash_switches.h"
8 #include "ash/display/root_window_transformers.h" 10 #include "ash/display/root_window_transformers.h"
9 #include "ash/shell.h" 11 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray_delegate.h" 12 #include "ash/system/tray/system_tray_delegate.h"
13 #include "base/command_line.h"
11 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
12 #include "ui/aura/client/cursor_client.h" 15 #include "ui/aura/client/cursor_client.h"
13 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
14 #include "ui/aura/root_window_transformer.h" 17 #include "ui/aura/root_window_transformer.h"
15 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
16 #include "ui/aura/window_property.h" 19 #include "ui/aura/window_property.h"
17 #include "ui/compositor/dip_util.h" 20 #include "ui/compositor/dip_util.h"
18 #include "ui/compositor/layer.h" 21 #include "ui/compositor/layer.h"
19 #include "ui/compositor/layer_animation_observer.h" 22 #include "ui/compositor/layer_animation_observer.h"
20 #include "ui/compositor/scoped_layer_animation_settings.h" 23 #include "ui/compositor/scoped_layer_animation_settings.h"
(...skipping 13 matching lines...) Expand all
34 const float kMinMagnifiedScaleThreshold = 1.1f; 37 const float kMinMagnifiedScaleThreshold = 1.1f;
35 const float kNonMagnifiedScale = 1.0f; 38 const float kNonMagnifiedScale = 1.0f;
36 39
37 const float kInitialMagnifiedScale = 2.0f; 40 const float kInitialMagnifiedScale = 2.0f;
38 const float kScrollScaleChangeFactor = 0.05f; 41 const float kScrollScaleChangeFactor = 0.05f;
39 42
40 // Threadshold of panning. If the cursor moves to within pixels (in DIP) of 43 // Threadshold of panning. If the cursor moves to within pixels (in DIP) of
41 // |kPanningMergin| from the edge, the view-port moves. 44 // |kPanningMergin| from the edge, the view-port moves.
42 const int kPanningMergin = 100; 45 const int kPanningMergin = 100;
43 46
47 bool magnifier_accelerator_enabled = false;
48
44 void MoveCursorTo(aura::RootWindow* root_window, 49 void MoveCursorTo(aura::RootWindow* root_window,
45 const gfx::Point& root_location) { 50 const gfx::Point& root_location) {
46 gfx::Point3F host_location_3f(root_location); 51 gfx::Point3F host_location_3f(root_location);
47 root_window->host()->GetRootTransform().TransformPoint(&host_location_3f); 52 root_window->host()->GetRootTransform().TransformPoint(&host_location_3f);
48 root_window->MoveCursorToHostLocation( 53 root_window->MoveCursorToHostLocation(
49 gfx::ToCeiledPoint(host_location_3f.AsPointF())); 54 gfx::ToCeiledPoint(host_location_3f.AsPointF()));
50 } 55 }
51 56
52 } // namespace 57 } // namespace
53 58
(...skipping 13 matching lines...) Expand all
67 // MagnificationController overrides: 72 // MagnificationController overrides:
68 virtual void SetEnabled(bool enabled) OVERRIDE; 73 virtual void SetEnabled(bool enabled) OVERRIDE;
69 virtual bool IsEnabled() const OVERRIDE; 74 virtual bool IsEnabled() const OVERRIDE;
70 virtual void SetScale(float scale, bool animate) OVERRIDE; 75 virtual void SetScale(float scale, bool animate) OVERRIDE;
71 virtual float GetScale() const OVERRIDE { return scale_; } 76 virtual float GetScale() const OVERRIDE { return scale_; }
72 virtual void MoveWindow(int x, int y, bool animate) OVERRIDE; 77 virtual void MoveWindow(int x, int y, bool animate) OVERRIDE;
73 virtual void MoveWindow(const gfx::Point& point, bool animate) OVERRIDE; 78 virtual void MoveWindow(const gfx::Point& point, bool animate) OVERRIDE;
74 virtual gfx::Point GetWindowPosition() const OVERRIDE { 79 virtual gfx::Point GetWindowPosition() const OVERRIDE {
75 return gfx::ToFlooredPoint(origin_); 80 return gfx::ToFlooredPoint(origin_);
76 } 81 }
77 virtual void EnsureRectIsVisible(const gfx::Rect& rect, 82 virtual void SetScrollDirection(ScrollDirection direction) OVERRIDE;
78 bool animate) OVERRIDE; 83
79 virtual void EnsurePointIsVisible(const gfx::Point& point,
80 bool animate) OVERRIDE;
81 // For test 84 // For test
82 virtual gfx::Point GetPointOfInterestForTesting() OVERRIDE { 85 virtual gfx::Point GetPointOfInterestForTesting() OVERRIDE {
83 return point_of_interest_; 86 return point_of_interest_;
84 } 87 }
85 88
86 private: 89 private:
87 // ui::ImplicitAnimationObserver overrides: 90 // ui::ImplicitAnimationObserver overrides:
88 virtual void OnImplicitAnimationsCompleted() OVERRIDE; 91 virtual void OnImplicitAnimationsCompleted() OVERRIDE;
89 92
90 // aura::WindowObserver overrides: 93 // aura::WindowObserver overrides:
91 virtual void OnWindowDestroying(aura::Window* root_window) OVERRIDE; 94 virtual void OnWindowDestroying(aura::Window* root_window) OVERRIDE;
92 virtual void OnWindowBoundsChanged(aura::Window* window, 95 virtual void OnWindowBoundsChanged(aura::Window* window,
93 const gfx::Rect& old_bounds, 96 const gfx::Rect& old_bounds,
94 const gfx::Rect& new_bounds) OVERRIDE; 97 const gfx::Rect& new_bounds) OVERRIDE;
95 98
96 // Redraws the magnification window with the given origin position and the 99 // Redraws the magnification window with the given origin position and the
97 // given scale. Returns true if the window is changed; otherwise, false. 100 // given scale. Returns true if the window is changed; otherwise, false.
98 // These methods should be called internally just after the scale and/or 101 // These methods should be called internally just after the scale and/or
99 // the position are changed to redraw the window. 102 // the position are changed to redraw the window.
100 bool Redraw(const gfx::PointF& position, float scale, bool animate); 103 bool Redraw(const gfx::PointF& position, float scale, bool animate);
101 bool RedrawDIP(const gfx::PointF& position, float scale, bool animate); 104 bool RedrawDIP(const gfx::PointF& position, float scale, bool animate);
102 105
106 // 1) If the screen is scrolling (i.e. animating) and should scroll further,
107 // it does nothing.
108 // 2) If the screen is scrolling (i.e. animating) and the direction is NONE,
109 // it stops the scrolling animation.
110 // 3) If the direction is set to value other than NONE, it starts the
111 // scrolling/ animation towards that direction.
112 void StartOrStopScrollIfNecessary();
113
103 // Redraw with the given zoom scale keeping the mouse cursor location. In 114 // Redraw with the given zoom scale keeping the mouse cursor location. In
104 // other words, zoom (or unzoom) centering around the cursor. 115 // other words, zoom (or unzoom) centering around the cursor.
105 void RedrawKeepingMousePosition(float scale, bool animate); 116 void RedrawKeepingMousePosition(float scale, bool animate);
106 117
107 // Ensures that the given point, rect or last mouse location is inside
108 // magnification window. If not, the controller moves the window to contain
109 // the given point/rect.
110 void EnsureRectIsVisibleWithScale(const gfx::Rect& target_rect,
111 float scale,
112 bool animate);
113 void EnsureRectIsVisibleDIP(const gfx::Rect& target_rect_in_dip,
114 float scale,
115 bool animate);
116 void EnsurePointIsVisibleWithScale(const gfx::Point& point,
117 float scale,
118 bool animate);
119 void OnMouseMove(const gfx::Point& location); 118 void OnMouseMove(const gfx::Point& location);
120 119
121 // Move the mouse cursot to the given point. Actual move will be done when 120 // Move the mouse cursot to the given point. Actual move will be done when
122 // the animation is completed. This should be called after animation is 121 // the animation is completed. This should be called after animation is
123 // started. 122 // started.
124 void AfterAnimationMoveCursorTo(const gfx::Point& location); 123 void AfterAnimationMoveCursorTo(const gfx::Point& location);
125 124
126 // Switch Magnified RootWindow to |new_root_window|. This does following: 125 // Switch Magnified RootWindow to |new_root_window|. This does following:
127 // - Unzoom the current root_window. 126 // - Unzoom the current root_window.
128 // - Zoom the given new root_window |new_root_window|. 127 // - Zoom the given new root_window |new_root_window|.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 gfx::Point position_after_animation_; 161 gfx::Point position_after_animation_;
163 162
164 // Stores the last mouse cursor (or last touched) location. This value is 163 // Stores the last mouse cursor (or last touched) location. This value is
165 // used on zooming to keep this location visible. 164 // used on zooming to keep this location visible.
166 gfx::Point point_of_interest_; 165 gfx::Point point_of_interest_;
167 166
168 // Current scale, origin (left-top) position of the magnification window. 167 // Current scale, origin (left-top) position of the magnification window.
169 float scale_; 168 float scale_;
170 gfx::PointF origin_; 169 gfx::PointF origin_;
171 170
171 ScrollDirection scroll_direction_;
172
172 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl); 173 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl);
173 }; 174 };
174 175
175 //////////////////////////////////////////////////////////////////////////////// 176 ////////////////////////////////////////////////////////////////////////////////
176 // MagnificationControllerImpl: 177 // MagnificationControllerImpl:
177 178
178 MagnificationControllerImpl::MagnificationControllerImpl() 179 MagnificationControllerImpl::MagnificationControllerImpl()
179 : root_window_(ash::Shell::GetPrimaryRootWindow()), 180 : root_window_(Shell::GetPrimaryRootWindow()),
180 is_on_animation_(false), 181 is_on_animation_(false),
181 is_enabled_(false), 182 is_enabled_(false),
182 move_cursor_after_animation_(false), 183 move_cursor_after_animation_(false),
183 scale_(kNonMagnifiedScale) { 184 scale_(kNonMagnifiedScale),
185 scroll_direction_(SCROLL_NONE) {
184 Shell::GetInstance()->AddPreTargetHandler(this); 186 Shell::GetInstance()->AddPreTargetHandler(this);
185 root_window_->AddObserver(this); 187 root_window_->AddObserver(this);
186 point_of_interest_ = root_window_->bounds().CenterPoint(); 188 point_of_interest_ = root_window_->bounds().CenterPoint();
187 } 189 }
188 190
189 MagnificationControllerImpl::~MagnificationControllerImpl() { 191 MagnificationControllerImpl::~MagnificationControllerImpl() {
190 root_window_->RemoveObserver(this); 192 root_window_->RemoveObserver(this);
191 193
192 Shell::GetInstance()->RemovePreTargetHandler(this); 194 Shell::GetInstance()->RemovePreTargetHandler(this);
193 } 195 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 internal::CreateRootWindowTransformerForDisplay(root_window_, display)); 277 internal::CreateRootWindowTransformerForDisplay(root_window_, display));
276 root_window_->GetDispatcher()->host()->SetRootWindowTransformer( 278 root_window_->GetDispatcher()->host()->SetRootWindowTransformer(
277 transformer.Pass()); 279 transformer.Pass());
278 280
279 if (animate) 281 if (animate)
280 is_on_animation_ = true; 282 is_on_animation_ = true;
281 283
282 return true; 284 return true;
283 } 285 }
284 286
285 void MagnificationControllerImpl::EnsureRectIsVisibleWithScale( 287 void MagnificationControllerImpl::StartOrStopScrollIfNecessary() {
286 const gfx::Rect& target_rect, 288 // This value controls the scrolling speed.
287 float scale, 289 const int kMoveOffset = 40;
288 bool animate) { 290 if (is_on_animation_) {
289 const gfx::Rect target_rect_in_dip = 291 if (scroll_direction_ == SCROLL_NONE)
290 ui::ConvertRectToDIP(root_window_->layer(), target_rect); 292 root_window_->layer()->GetAnimator()->StopAnimating();
291 EnsureRectIsVisibleDIP(target_rect_in_dip, scale, animate); 293 return;
292 } 294 }
293 295
294 void MagnificationControllerImpl::EnsureRectIsVisibleDIP( 296 gfx::PointF new_origin = origin_;
295 const gfx::Rect& target_rect, 297 switch (scroll_direction_) {
296 float scale, 298 case SCROLL_NONE:
297 bool animate) { 299 // No need to take action.
298 ValidateScale(&scale); 300 return;
299 301 case SCROLL_LEFT:
300 const gfx::Rect window_rect = gfx::ToEnclosingRect(GetWindowRectDIP(scale)); 302 new_origin.Offset(-kMoveOffset, 0);
301 if (scale == scale_ && window_rect.Contains(target_rect)) 303 break;
302 return; 304 case SCROLL_RIGHT:
303 305 new_origin.Offset(kMoveOffset, 0);
304 // TODO(yoshiki): Un-zoom and change the scale if the magnification window 306 break;
305 // can't contain the whole given rect. 307 case SCROLL_UP:
306 308 new_origin.Offset(0, -kMoveOffset);
307 gfx::Rect rect = window_rect; 309 break;
308 if (target_rect.width() > rect.width()) 310 case SCROLL_DOWN:
309 rect.set_x(target_rect.CenterPoint().x() - rect.x() / 2); 311 new_origin.Offset(0, kMoveOffset);
310 else if (target_rect.right() < rect.x()) 312 break;
311 rect.set_x(target_rect.right()); 313 }
312 else if (rect.right() < target_rect.x()) 314 RedrawDIP(new_origin, scale_, true);
313 rect.set_x(target_rect.x() - rect.width());
314
315 if (rect.height() > window_rect.height())
316 rect.set_y(target_rect.CenterPoint().y() - rect.y() / 2);
317 else if (target_rect.bottom() < rect.y())
318 rect.set_y(target_rect.bottom());
319 else if (rect.bottom() < target_rect.y())
320 rect.set_y(target_rect.y() - rect.height());
321
322 RedrawDIP(rect.origin(), scale, animate);
323 }
324
325 void MagnificationControllerImpl::EnsurePointIsVisibleWithScale(
326 const gfx::Point& point,
327 float scale,
328 bool animate) {
329 EnsureRectIsVisibleWithScale(gfx::Rect(point, gfx::Size(0, 0)),
330 scale,
331 animate);
332 } 315 }
333 316
334 void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) { 317 void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) {
335 DCHECK(root_window_); 318 DCHECK(root_window_);
336 319
337 gfx::Point mouse(location); 320 gfx::Point mouse(location);
338 321
339 int x = origin_.x(); 322 int x = origin_.x();
340 int y = origin_.y(); 323 int y = origin_.y();
341 bool start_zoom = false; 324 bool start_zoom = false;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 MoveCursorTo(root_window_->GetDispatcher(), position_after_animation_); 424 MoveCursorTo(root_window_->GetDispatcher(), position_after_animation_);
442 move_cursor_after_animation_ = false; 425 move_cursor_after_animation_ = false;
443 426
444 aura::client::CursorClient* cursor_client = 427 aura::client::CursorClient* cursor_client =
445 aura::client::GetCursorClient(root_window_); 428 aura::client::GetCursorClient(root_window_);
446 if (cursor_client) 429 if (cursor_client)
447 cursor_client->EnableMouseEvents(); 430 cursor_client->EnableMouseEvents();
448 } 431 }
449 432
450 is_on_animation_ = false; 433 is_on_animation_ = false;
434
435 StartOrStopScrollIfNecessary();
451 } 436 }
452 437
453 void MagnificationControllerImpl::OnWindowDestroying( 438 void MagnificationControllerImpl::OnWindowDestroying(
454 aura::Window* root_window) { 439 aura::Window* root_window) {
455 if (root_window == root_window_) { 440 if (root_window == root_window_) {
456 // There must be at least one root window because this controller is 441 // There must be at least one root window because this controller is
457 // destroyed before the root windows get destroyed. 442 // destroyed before the root windows get destroyed.
458 DCHECK(root_window); 443 DCHECK(root_window);
459 444
460 aura::Window* target_root_window = Shell::GetTargetRootWindow(); 445 aura::Window* target_root_window = Shell::GetTargetRootWindow();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 } 482 }
498 483
499 //////////////////////////////////////////////////////////////////////////////// 484 ////////////////////////////////////////////////////////////////////////////////
500 // MagnificationControllerImpl: MagnificationController implementation 485 // MagnificationControllerImpl: MagnificationController implementation
501 486
502 void MagnificationControllerImpl::SetScale(float scale, bool animate) { 487 void MagnificationControllerImpl::SetScale(float scale, bool animate) {
503 if (!is_enabled_) 488 if (!is_enabled_)
504 return; 489 return;
505 490
506 ValidateScale(&scale); 491 ValidateScale(&scale);
507 ash::Shell::GetInstance()->accessibility_delegate()-> 492 Shell::GetInstance()->accessibility_delegate()->
508 SaveScreenMagnifierScale(scale); 493 SaveScreenMagnifierScale(scale);
509 RedrawKeepingMousePosition(scale, animate); 494 RedrawKeepingMousePosition(scale, animate);
510 } 495 }
511 496
512 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) { 497 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) {
513 if (!is_enabled_) 498 if (!is_enabled_)
514 return; 499 return;
515 500
516 Redraw(gfx::Point(x, y), scale_, animate); 501 Redraw(gfx::Point(x, y), scale_, animate);
517 } 502 }
518 503
519 void MagnificationControllerImpl::MoveWindow(const gfx::Point& point, 504 void MagnificationControllerImpl::MoveWindow(const gfx::Point& point,
520 bool animate) { 505 bool animate) {
521 if (!is_enabled_) 506 if (!is_enabled_)
522 return; 507 return;
523 508
524 Redraw(point, scale_, animate); 509 Redraw(point, scale_, animate);
525 } 510 }
526 511
527 void MagnificationControllerImpl::EnsureRectIsVisible( 512 void MagnificationControllerImpl::SetScrollDirection(
528 const gfx::Rect& target_rect, 513 ScrollDirection direction) {
529 bool animate) { 514 scroll_direction_ = direction;
530 if (!is_enabled_) 515 StartOrStopScrollIfNecessary();
531 return;
532
533 EnsureRectIsVisibleWithScale(target_rect, scale_, animate);
534 }
535
536 void MagnificationControllerImpl::EnsurePointIsVisible(
537 const gfx::Point& point,
538 bool animate) {
539 if (!is_enabled_)
540 return;
541
542 EnsurePointIsVisibleWithScale(point, scale_, animate);
543 } 516 }
544 517
545 void MagnificationControllerImpl::SetEnabled(bool enabled) { 518 void MagnificationControllerImpl::SetEnabled(bool enabled) {
519 Shell* shell = Shell::GetInstance();
546 if (enabled) { 520 if (enabled) {
547 float scale = 521 float scale =
548 ash::Shell::GetInstance()->accessibility_delegate()-> 522 Shell::GetInstance()->accessibility_delegate()->
549 GetSavedScreenMagnifierScale(); 523 GetSavedScreenMagnifierScale();
550 if (scale <= 0.0f) 524 if (scale <= 0.0f)
551 scale = kInitialMagnifiedScale; 525 scale = kInitialMagnifiedScale;
552 ValidateScale(&scale); 526 ValidateScale(&scale);
553 527
554 // Do nothing, if already enabled with same scale. 528 // Do nothing, if already enabled with same scale.
555 if (is_enabled_ && scale == scale_) 529 if (is_enabled_ && scale == scale_)
556 return; 530 return;
557 531
558 is_enabled_ = enabled; 532 is_enabled_ = enabled;
559 RedrawKeepingMousePosition(scale, true); 533 RedrawKeepingMousePosition(scale, true);
560 ash::Shell::GetInstance()->accessibility_delegate()-> 534 shell->accessibility_delegate()->SaveScreenMagnifierScale(scale);
561 SaveScreenMagnifierScale(scale); 535 if (IsMagnifierAcceleratorsEnabled())
536 shell->accelerator_controller()->InstallMagnifierAccelerators();
562 } else { 537 } else {
563 // Do nothing, if already disabled. 538 // Do nothing, if already disabled.
564 if (!is_enabled_) 539 if (!is_enabled_)
565 return; 540 return;
566 541
567 RedrawKeepingMousePosition(kNonMagnifiedScale, true); 542 RedrawKeepingMousePosition(kNonMagnifiedScale, true);
568 is_enabled_ = enabled; 543 is_enabled_ = enabled;
544 if (IsMagnifierAcceleratorsEnabled())
545 shell->accelerator_controller()->UninstallMagnifierAccelerators();
569 } 546 }
570 } 547 }
571 548
572 bool MagnificationControllerImpl::IsEnabled() const { 549 bool MagnificationControllerImpl::IsEnabled() const {
573 return is_enabled_; 550 return is_enabled_;
574 } 551 }
575 552
576 //////////////////////////////////////////////////////////////////////////////// 553 ////////////////////////////////////////////////////////////////////////////////
577 // MagnificationControllerImpl: aura::EventFilter implementation 554 // MagnificationControllerImpl: aura::EventFilter implementation
578 555
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 } 602 }
626 603
627 //////////////////////////////////////////////////////////////////////////////// 604 ////////////////////////////////////////////////////////////////////////////////
628 // MagnificationController: 605 // MagnificationController:
629 606
630 // static 607 // static
631 MagnificationController* MagnificationController::CreateInstance() { 608 MagnificationController* MagnificationController::CreateInstance() {
632 return new MagnificationControllerImpl(); 609 return new MagnificationControllerImpl();
633 } 610 }
634 611
612 // static
613 bool MagnificationController::IsMagnifierAcceleratorsEnabled() {
614 return magnifier_accelerator_enabled ||
615 CommandLine::ForCurrentProcess()->HasSwitch(
616 switches::kAshEnableMagnifierAccelerators);
617 }
618
619 // static
620 void MagnificationController::SetMagnifierAcceleratorsEnabled(
621 bool enabled) {
622 magnifier_accelerator_enabled = enabled;
623 }
624
635 } // namespace ash 625 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698