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

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

Issue 37733003: Make GetRootWindow() return a Window instead of a RootWindow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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/accessibility_delegate.h" 7 #include "ash/accessibility_delegate.h"
8 #include "ash/display/root_window_transformers.h" 8 #include "ash/display/root_window_transformers.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray_delegate.h" 10 #include "ash/system/tray/system_tray_delegate.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 // Move the mouse cursot to the given point. Actual move will be done when 121 // 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 122 // the animation is completed. This should be called after animation is
123 // started. 123 // started.
124 void AfterAnimationMoveCursorTo(const gfx::Point& location); 124 void AfterAnimationMoveCursorTo(const gfx::Point& location);
125 125
126 // Switch Magnified RootWindow to |new_root_window|. This does following: 126 // Switch Magnified RootWindow to |new_root_window|. This does following:
127 // - Unzoom the current root_window. 127 // - Unzoom the current root_window.
128 // - Zoom the given new root_window |new_root_window|. 128 // - Zoom the given new root_window |new_root_window|.
129 // - Switch the target window from current window to |new_root_window|. 129 // - Switch the target window from current window to |new_root_window|.
130 void SwitchTargetRootWindow(aura::RootWindow* new_root_window, 130 void SwitchTargetRootWindow(aura::Window* new_root_window,
131 bool redraw_original_root_window); 131 bool redraw_original_root_window);
132 132
133 // Returns if the magnification scale is 1.0 or not (larger then 1.0). 133 // Returns if the magnification scale is 1.0 or not (larger then 1.0).
134 bool IsMagnified() const; 134 bool IsMagnified() const;
135 135
136 // Returns the rect of the magnification window. 136 // Returns the rect of the magnification window.
137 gfx::RectF GetWindowRectDIP(float scale) const; 137 gfx::RectF GetWindowRectDIP(float scale) const;
138 // Returns the size of the root window. 138 // Returns the size of the root window.
139 gfx::Size GetHostSizeDIP() const; 139 gfx::Size GetHostSizeDIP() const;
140 140
141 // Correct the givin scale value if nessesary. 141 // Correct the givin scale value if nessesary.
142 void ValidateScale(float* scale); 142 void ValidateScale(float* scale);
143 143
144 // ui::EventHandler overrides: 144 // ui::EventHandler overrides:
145 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 145 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
146 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; 146 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
147 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; 147 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
148 148
149 // Target root window. This must not be NULL. 149 // Target root window. This must not be NULL.
150 aura::RootWindow* root_window_; 150 aura::Window* root_window_;
151 151
152 // True if the magnified window is currently animating a change. Otherwise, 152 // True if the magnified window is currently animating a change. Otherwise,
153 // false. 153 // false.
154 bool is_on_animation_; 154 bool is_on_animation_;
155 155
156 bool is_enabled_; 156 bool is_enabled_;
157 157
158 // True if the cursor needs to move the given position after the animation 158 // True if the cursor needs to move the given position after the animation
159 // will be finished. When using this, set |position_after_animation_| as well. 159 // will be finished. When using this, set |position_after_animation_| as well.
160 bool move_cursor_after_animation_; 160 bool move_cursor_after_animation_;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 settings.SetPreemptionStrategy( 266 settings.SetPreemptionStrategy(
267 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 267 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
268 settings.SetTweenType(gfx::Tween::EASE_OUT); 268 settings.SetTweenType(gfx::Tween::EASE_OUT);
269 settings.SetTransitionDuration( 269 settings.SetTransitionDuration(
270 base::TimeDelta::FromMilliseconds(animate ? 100 : 0)); 270 base::TimeDelta::FromMilliseconds(animate ? 100 : 0));
271 271
272 gfx::Display display = 272 gfx::Display display =
273 Shell::GetScreen()->GetDisplayNearestWindow(root_window_); 273 Shell::GetScreen()->GetDisplayNearestWindow(root_window_);
274 scoped_ptr<aura::RootWindowTransformer> transformer( 274 scoped_ptr<aura::RootWindowTransformer> transformer(
275 internal::CreateRootWindowTransformerForDisplay(root_window_, display)); 275 internal::CreateRootWindowTransformerForDisplay(root_window_, display));
276 root_window_->SetRootWindowTransformer(transformer.Pass()); 276 root_window_->GetDispatcher()->SetRootWindowTransformer(transformer.Pass());
277 277
278 if (animate) 278 if (animate)
279 is_on_animation_ = true; 279 is_on_animation_ = true;
280 280
281 return true; 281 return true;
282 } 282 }
283 283
284 void MagnificationControllerImpl::EnsureRectIsVisibleWithScale( 284 void MagnificationControllerImpl::EnsureRectIsVisibleWithScale(
285 const gfx::Rect& target_rect, 285 const gfx::Rect& target_rect,
286 float scale, 286 float scale,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 y = top + y_diff; 373 y = top + y_diff;
374 374
375 if (start_zoom && !is_on_animation_) { 375 if (start_zoom && !is_on_animation_) {
376 // No animation on panning. 376 // No animation on panning.
377 bool animate = false; 377 bool animate = false;
378 bool ret = RedrawDIP(gfx::Point(x, y), scale_, animate); 378 bool ret = RedrawDIP(gfx::Point(x, y), scale_, animate);
379 379
380 if (ret) { 380 if (ret) {
381 // If the magnified region is moved, hides the mouse cursor and moves it. 381 // If the magnified region is moved, hides the mouse cursor and moves it.
382 if (x_diff != 0 || y_diff != 0) 382 if (x_diff != 0 || y_diff != 0)
383 MoveCursorTo(root_window_, mouse); 383 MoveCursorTo(root_window_->GetDispatcher(), mouse);
384 } 384 }
385 } 385 }
386 } 386 }
387 387
388 void MagnificationControllerImpl::AfterAnimationMoveCursorTo( 388 void MagnificationControllerImpl::AfterAnimationMoveCursorTo(
389 const gfx::Point& location) { 389 const gfx::Point& location) {
390 DCHECK(root_window_); 390 DCHECK(root_window_);
391 391
392 aura::client::CursorClient* cursor_client = 392 aura::client::CursorClient* cursor_client =
393 aura::client::GetCursorClient(root_window_); 393 aura::client::GetCursorClient(root_window_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 *scale = kMaxMagnifiedScale; 430 *scale = kMaxMagnifiedScale;
431 431
432 DCHECK(kNonMagnifiedScale <= *scale && *scale <= kMaxMagnifiedScale); 432 DCHECK(kNonMagnifiedScale <= *scale && *scale <= kMaxMagnifiedScale);
433 } 433 }
434 434
435 void MagnificationControllerImpl::OnImplicitAnimationsCompleted() { 435 void MagnificationControllerImpl::OnImplicitAnimationsCompleted() {
436 if (!is_on_animation_) 436 if (!is_on_animation_)
437 return; 437 return;
438 438
439 if (move_cursor_after_animation_) { 439 if (move_cursor_after_animation_) {
440 MoveCursorTo(root_window_, position_after_animation_); 440 MoveCursorTo(root_window_->GetDispatcher(), position_after_animation_);
441 move_cursor_after_animation_ = false; 441 move_cursor_after_animation_ = false;
442 442
443 aura::client::CursorClient* cursor_client = 443 aura::client::CursorClient* cursor_client =
444 aura::client::GetCursorClient(root_window_); 444 aura::client::GetCursorClient(root_window_);
445 if (cursor_client) 445 if (cursor_client)
446 cursor_client->EnableMouseEvents(); 446 cursor_client->EnableMouseEvents();
447 } 447 }
448 448
449 is_on_animation_ = false; 449 is_on_animation_ = false;
450 } 450 }
451 451
452 void MagnificationControllerImpl::OnWindowDestroying( 452 void MagnificationControllerImpl::OnWindowDestroying(
453 aura::Window* root_window) { 453 aura::Window* root_window) {
454 if (root_window == root_window_) { 454 if (root_window == root_window_) {
455 // There must be at least one root window because this controller is 455 // There must be at least one root window because this controller is
456 // destroyed before the root windows get destroyed. 456 // destroyed before the root windows get destroyed.
457 DCHECK(root_window); 457 DCHECK(root_window);
458 458
459 aura::RootWindow* target_root_window = Shell::GetTargetRootWindow(); 459 aura::Window* target_root_window = Shell::GetTargetRootWindow();
460 CHECK(target_root_window); 460 CHECK(target_root_window);
461 461
462 // The destroyed root window must not be target. 462 // The destroyed root window must not be target.
463 CHECK_NE(target_root_window, root_window); 463 CHECK_NE(target_root_window, root_window);
464 // Don't redraw the old root window as it's being destroyed. 464 // Don't redraw the old root window as it's being destroyed.
465 SwitchTargetRootWindow(target_root_window, false); 465 SwitchTargetRootWindow(target_root_window, false);
466 point_of_interest_ = target_root_window->bounds().CenterPoint(); 466 point_of_interest_ = target_root_window->bounds().CenterPoint();
467 } 467 }
468 } 468 }
469 469
470 void MagnificationControllerImpl::OnWindowBoundsChanged( 470 void MagnificationControllerImpl::OnWindowBoundsChanged(
471 aura::Window* window, 471 aura::Window* window,
472 const gfx::Rect& old_bounds, 472 const gfx::Rect& old_bounds,
473 const gfx::Rect& new_bounds) { 473 const gfx::Rect& new_bounds) {
474 // TODO(yoshiki): implement here. crbug.com/230979 474 // TODO(yoshiki): implement here. crbug.com/230979
475 } 475 }
476 476
477 void MagnificationControllerImpl::SwitchTargetRootWindow( 477 void MagnificationControllerImpl::SwitchTargetRootWindow(
478 aura::RootWindow* new_root_window, 478 aura::Window* new_root_window,
479 bool redraw_original_root_window) { 479 bool redraw_original_root_window) {
480 DCHECK(new_root_window); 480 DCHECK(new_root_window);
481 481
482 if (new_root_window == root_window_) 482 if (new_root_window == root_window_)
483 return; 483 return;
484 484
485 // Stores the previous scale. 485 // Stores the previous scale.
486 float scale = GetScale(); 486 float scale = GetScale();
487 487
488 // Unmagnify the previous root window. 488 // Unmagnify the previous root window.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 570
571 bool MagnificationControllerImpl::IsEnabled() const { 571 bool MagnificationControllerImpl::IsEnabled() const {
572 return is_enabled_; 572 return is_enabled_;
573 } 573 }
574 574
575 //////////////////////////////////////////////////////////////////////////////// 575 ////////////////////////////////////////////////////////////////////////////////
576 // MagnificationControllerImpl: aura::EventFilter implementation 576 // MagnificationControllerImpl: aura::EventFilter implementation
577 577
578 void MagnificationControllerImpl::OnMouseEvent(ui::MouseEvent* event) { 578 void MagnificationControllerImpl::OnMouseEvent(ui::MouseEvent* event) {
579 aura::Window* target = static_cast<aura::Window*>(event->target()); 579 aura::Window* target = static_cast<aura::Window*>(event->target());
580 aura::RootWindow* current_root = target->GetRootWindow(); 580 aura::Window* current_root = target->GetRootWindow();
581 gfx::Rect root_bounds = current_root->bounds(); 581 gfx::Rect root_bounds = current_root->bounds();
582 582
583 if (root_bounds.Contains(event->root_location())) { 583 if (root_bounds.Contains(event->root_location())) {
584 // This must be before |SwitchTargetRootWindow()|. 584 // This must be before |SwitchTargetRootWindow()|.
585 point_of_interest_ = event->root_location(); 585 point_of_interest_ = event->root_location();
586 586
587 if (current_root != root_window_) { 587 if (current_root != root_window_) {
588 DCHECK(current_root); 588 DCHECK(current_root);
589 SwitchTargetRootWindow(current_root, true); 589 SwitchTargetRootWindow(current_root, true);
590 } 590 }
(...skipping 17 matching lines...) Expand all
608 scale += scroll_event->y_offset() * kScrollScaleChangeFactor; 608 scale += scroll_event->y_offset() * kScrollScaleChangeFactor;
609 SetScale(scale, true); 609 SetScale(scale, true);
610 event->StopPropagation(); 610 event->StopPropagation();
611 return; 611 return;
612 } 612 }
613 } 613 }
614 } 614 }
615 615
616 void MagnificationControllerImpl::OnTouchEvent(ui::TouchEvent* event) { 616 void MagnificationControllerImpl::OnTouchEvent(ui::TouchEvent* event) {
617 aura::Window* target = static_cast<aura::Window*>(event->target()); 617 aura::Window* target = static_cast<aura::Window*>(event->target());
618 aura::RootWindow* current_root = target->GetRootWindow(); 618 aura::Window* current_root = target->GetRootWindow();
619 if (current_root == root_window_) { 619 if (current_root == root_window_) {
620 gfx::Rect root_bounds = current_root->bounds(); 620 gfx::Rect root_bounds = current_root->bounds();
621 if (root_bounds.Contains(event->root_location())) 621 if (root_bounds.Contains(event->root_location()))
622 point_of_interest_ = event->root_location(); 622 point_of_interest_ = event->root_location();
623 } 623 }
624 } 624 }
625 625
626 //////////////////////////////////////////////////////////////////////////////// 626 ////////////////////////////////////////////////////////////////////////////////
627 // MagnificationController: 627 // MagnificationController:
628 628
629 // static 629 // static
630 MagnificationController* MagnificationController::CreateInstance() { 630 MagnificationController* MagnificationController::CreateInstance() {
631 return new MagnificationControllerImpl(); 631 return new MagnificationControllerImpl();
632 } 632 }
633 633
634 } // namespace ash 634 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher_item_delegate.h ('k') | ash/magnifier/magnification_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698