| 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/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ui/aura/event.h" | 8 #include "ui/aura/event.h" |
| 9 #include "ui/aura/event_filter.h" | 9 #include "ui/aura/event_filter.h" |
| 10 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 float scale, | 72 float scale, |
| 73 bool animate); | 73 bool animate); |
| 74 void EnsureRectIsVisibleDIP(const gfx::Rect& target_rect_in_dip, | 74 void EnsureRectIsVisibleDIP(const gfx::Rect& target_rect_in_dip, |
| 75 float scale, | 75 float scale, |
| 76 bool animate); | 76 bool animate); |
| 77 void EnsurePointIsVisibleWithScale(const gfx::Point& point, | 77 void EnsurePointIsVisibleWithScale(const gfx::Point& point, |
| 78 float scale, | 78 float scale, |
| 79 bool animate); | 79 bool animate); |
| 80 void OnMouseMove(const gfx::Point& location); | 80 void OnMouseMove(const gfx::Point& location); |
| 81 | 81 |
| 82 // Switch Magnified RootWindow to |new_root_window|. This does following: |
| 83 // - Unzoom the current root_window. |
| 84 // - Zoom the given new root_window |new_root_window|. |
| 85 // - Switch the target window from current window to |new_root_window|. |
| 86 void SwitchTargetRootWindow(aura::RootWindow* new_root_window); |
| 87 |
| 82 // Returns if the magnification scale is 1.0 or not (larger then 1.0). | 88 // Returns if the magnification scale is 1.0 or not (larger then 1.0). |
| 83 bool IsMagnified() const; | 89 bool IsMagnified() const; |
| 84 | 90 |
| 85 // Returns the rect of the magnification window. | 91 // Returns the rect of the magnification window. |
| 86 gfx::Rect GetWindowRectDIP(float scale) const; | 92 gfx::Rect GetWindowRectDIP(float scale) const; |
| 87 // Returns the size of the root window. | 93 // Returns the size of the root window. |
| 88 gfx::Size GetHostSizeDIP() const; | 94 gfx::Size GetHostSizeDIP() const; |
| 89 | 95 |
| 90 // Correct the givin scale value if nessesary. | 96 // Correct the givin scale value if nessesary. |
| 91 void ValidateScale(float* scale); | 97 void ValidateScale(float* scale); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 160 |
| 155 const gfx::Size host_size_in_dip = GetHostSizeDIP(); | 161 const gfx::Size host_size_in_dip = GetHostSizeDIP(); |
| 156 const gfx::Size window_size_in_dip = GetWindowRectDIP(scale).size(); | 162 const gfx::Size window_size_in_dip = GetWindowRectDIP(scale).size(); |
| 157 int max_x = host_size_in_dip.width() - window_size_in_dip.width(); | 163 int max_x = host_size_in_dip.width() - window_size_in_dip.width(); |
| 158 int max_y = host_size_in_dip.height() - window_size_in_dip.height(); | 164 int max_y = host_size_in_dip.height() - window_size_in_dip.height(); |
| 159 if (x > max_x) | 165 if (x > max_x) |
| 160 x = max_x; | 166 x = max_x; |
| 161 if (y > max_y) | 167 if (y > max_y) |
| 162 y = max_y; | 168 y = max_y; |
| 163 | 169 |
| 164 // Ignores 1 px diffirence because it may be error on calculation. | 170 // Does nothing if both the origin and the scale are not changed. |
| 165 if (std::abs(origin_.x() - x) <= 1 && | 171 if (origin_.x() == x && |
| 166 std::abs(origin_.y() - y) <= 1 && | 172 origin_.y() == y && |
| 167 scale == scale_) | 173 scale == scale_) { |
| 168 return false; | 174 return false; |
| 175 } |
| 169 | 176 |
| 170 origin_.set_x(x); | 177 origin_.set_x(x); |
| 171 origin_.set_y(y); | 178 origin_.set_y(y); |
| 172 scale_ = scale; | 179 scale_ = scale; |
| 173 | 180 |
| 174 // Creates transform matrix. | 181 // Creates transform matrix. |
| 175 ui::Transform transform; | 182 ui::Transform transform; |
| 176 // Flips the signs intentionally to convert them from the position of the | 183 // Flips the signs intentionally to convert them from the position of the |
| 177 // magnification window. | 184 // magnification window. |
| 178 transform.ConcatTranslate(-origin_.x(), -origin_.y()); | 185 transform.ConcatTranslate(-origin_.x(), -origin_.y()); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 // |kMinMagnifiedScaleThreshold|; | 333 // |kMinMagnifiedScaleThreshold|; |
| 327 if (*scale > kMaxMagnifiedScaleThreshold) | 334 if (*scale > kMaxMagnifiedScaleThreshold) |
| 328 *scale = kMaxMagnifiedScale; | 335 *scale = kMaxMagnifiedScale; |
| 329 } | 336 } |
| 330 | 337 |
| 331 void MagnificationControllerImpl::OnImplicitAnimationsCompleted() { | 338 void MagnificationControllerImpl::OnImplicitAnimationsCompleted() { |
| 332 root_window_->ShowCursor(true); | 339 root_window_->ShowCursor(true); |
| 333 is_on_zooming_ = false; | 340 is_on_zooming_ = false; |
| 334 } | 341 } |
| 335 | 342 |
| 343 void MagnificationControllerImpl::SwitchTargetRootWindow( |
| 344 aura::RootWindow* new_root_window) { |
| 345 if (new_root_window == root_window_) |
| 346 return; |
| 347 |
| 348 float scale = GetScale(); |
| 349 |
| 350 SetScale(1.0f, true); |
| 351 root_window_ = new_root_window; |
| 352 SetScale(scale, true); |
| 353 } |
| 354 |
| 336 //////////////////////////////////////////////////////////////////////////////// | 355 //////////////////////////////////////////////////////////////////////////////// |
| 337 // MagnificationControllerImpl: MagnificationController implementation | 356 // MagnificationControllerImpl: MagnificationController implementation |
| 338 | 357 |
| 339 void MagnificationControllerImpl::SetScale(float scale, bool animate) { | 358 void MagnificationControllerImpl::SetScale(float scale, bool animate) { |
| 340 if (!is_enabled_) | 359 if (!is_enabled_) |
| 341 return; | 360 return; |
| 342 | 361 |
| 343 ValidateScale(&scale); | 362 ValidateScale(&scale); |
| 344 | 363 |
| 345 // Try not to change the point which the mouse cursor indicates to. | 364 gfx::Point mouse_in_root = root_window_->GetLastMouseLocationInRoot(); |
| 346 const gfx::Rect window_rect = GetWindowRectDIP(scale); | 365 const gfx::Point origin = |
| 347 const gfx::Point mouse = gfx::Screen::GetCursorScreenPoint(); | 366 gfx::Point(mouse_in_root.x() * (1.0f - 1.0f / scale), |
| 348 const gfx::Point origin = gfx::Point(mouse.x() * (1.0f - 1.0f / scale), | 367 mouse_in_root.y() * (1.0f - 1.0f / scale)); |
| 349 mouse.y() * (1.0f - 1.0f / scale)); | |
| 350 Redraw(origin, scale, animate); | 368 Redraw(origin, scale, animate); |
| 351 } | 369 } |
| 352 | 370 |
| 353 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) { | 371 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) { |
| 354 if (!is_enabled_) | 372 if (!is_enabled_) |
| 355 return; | 373 return; |
| 356 | 374 |
| 357 Redraw(gfx::Point(x, y), scale_, animate); | 375 Redraw(gfx::Point(x, y), scale_, animate); |
| 358 } | 376 } |
| 359 | 377 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 //////////////////////////////////////////////////////////////////////////////// | 414 //////////////////////////////////////////////////////////////////////////////// |
| 397 // MagnificationControllerImpl: aura::EventFilter implementation | 415 // MagnificationControllerImpl: aura::EventFilter implementation |
| 398 | 416 |
| 399 bool MagnificationControllerImpl::PreHandleKeyEvent(aura::Window* target, | 417 bool MagnificationControllerImpl::PreHandleKeyEvent(aura::Window* target, |
| 400 aura::KeyEvent* event) { | 418 aura::KeyEvent* event) { |
| 401 return false; | 419 return false; |
| 402 } | 420 } |
| 403 | 421 |
| 404 bool MagnificationControllerImpl::PreHandleMouseEvent(aura::Window* target, | 422 bool MagnificationControllerImpl::PreHandleMouseEvent(aura::Window* target, |
| 405 aura::MouseEvent* event) { | 423 aura::MouseEvent* event) { |
| 406 if (IsMagnified() && event->type() == ui::ET_MOUSE_MOVED) | 424 if (IsMagnified() && event->type() == ui::ET_MOUSE_MOVED) { |
| 407 OnMouseMove(event->root_location()); | 425 aura::RootWindow* current_root = target->GetRootWindow(); |
| 426 gfx::Rect root_bounds = current_root->bounds(); |
| 427 |
| 428 if (root_bounds.Contains(event->root_location())) { |
| 429 if (current_root != root_window_) |
| 430 SwitchTargetRootWindow(current_root); |
| 431 |
| 432 OnMouseMove(event->root_location()); |
| 433 } |
| 434 } |
| 435 |
| 408 return false; | 436 return false; |
| 409 } | 437 } |
| 410 | 438 |
| 411 ui::TouchStatus MagnificationControllerImpl::PreHandleTouchEvent( | 439 ui::TouchStatus MagnificationControllerImpl::PreHandleTouchEvent( |
| 412 aura::Window* target, | 440 aura::Window* target, |
| 413 aura::TouchEvent* event) { | 441 aura::TouchEvent* event) { |
| 414 return ui::TOUCH_STATUS_UNKNOWN; | 442 return ui::TOUCH_STATUS_UNKNOWN; |
| 415 } | 443 } |
| 416 | 444 |
| 417 ui::GestureStatus MagnificationControllerImpl::PreHandleGestureEvent( | 445 ui::GestureStatus MagnificationControllerImpl::PreHandleGestureEvent( |
| 418 aura::Window* target, | 446 aura::Window* target, |
| 419 aura::GestureEvent* event) { | 447 aura::GestureEvent* event) { |
| 420 return ui::GESTURE_STATUS_UNKNOWN; | 448 return ui::GESTURE_STATUS_UNKNOWN; |
| 421 } | 449 } |
| 422 | 450 |
| 423 //////////////////////////////////////////////////////////////////////////////// | 451 //////////////////////////////////////////////////////////////////////////////// |
| 424 // MagnificationController: | 452 // MagnificationController: |
| 425 | 453 |
| 426 // static | 454 // static |
| 427 MagnificationController* MagnificationController::CreateInstance() { | 455 MagnificationController* MagnificationController::CreateInstance() { |
| 428 return new MagnificationControllerImpl(); | 456 return new MagnificationControllerImpl(); |
| 429 } | 457 } |
| 430 | 458 |
| 431 } // namespace internal | 459 } // namespace internal |
| 432 } // namespace ash | 460 } // namespace ash |
| OLD | NEW |