Chromium Code Reviews| 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/display/display_controller.h" | |
| 8 #include "ash/display/screen_position_controller.h" | |
| 7 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ui/aura/client/screen_position_client.h" | |
| 8 #include "ui/aura/event.h" | 11 #include "ui/aura/event.h" |
| 9 #include "ui/aura/event_filter.h" | 12 #include "ui/aura/event_filter.h" |
| 10 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
| 11 #include "ui/aura/shared/compound_event_filter.h" | 14 #include "ui/aura/shared/compound_event_filter.h" |
| 12 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 13 #include "ui/aura/window_property.h" | 16 #include "ui/aura/window_property.h" |
| 14 #include "ui/gfx/point3.h" | 17 #include "ui/gfx/point3.h" |
| 15 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
| 16 #include "ui/compositor/dip_util.h" | 19 #include "ui/compositor/dip_util.h" |
| 17 #include "ui/compositor/layer.h" | 20 #include "ui/compositor/layer.h" |
| 18 #include "ui/compositor/layer_animation_observer.h" | 21 #include "ui/compositor/layer_animation_observer.h" |
| 19 #include "ui/compositor/scoped_layer_animation_settings.h" | 22 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 const float kMaxMagnifiedScale = 4.0f; | 26 const float kMaxMagnifiedScale = 4.0f; |
| 24 const float kMaxMagnifiedScaleThreshold = 4.0f; | 27 const float kMaxMagnifiedScaleThreshold = 4.0f; |
| 25 const float kMinMagnifiedScaleThreshold = 1.1f; | 28 const float kMinMagnifiedScaleThreshold = 1.1f; |
| 26 const float kNonMagnifiedScale = 1.0f; | 29 const float kNonMagnifiedScale = 1.0f; |
| 27 | 30 |
| 28 const float kInitialMagnifiedScale = 2.0f; | 31 const float kInitialMagnifiedScale = 2.0f; |
| 29 | 32 |
| 33 // Convets position from screen coordinate to root_window coordinate. | |
| 34 void ConvertsCoordinateFromScreenToRoot(aura::RootWindow* root_window, | |
|
sky
2012/08/06 15:09:47
I believe Yusuke is adding something similar here
yoshiki
2012/08/06 22:22:16
Thank you for advice. This converts just to curren
| |
| 35 gfx::Point* point) { | |
| 36 aura::client::ScreenPositionClient* screen_position_client = | |
| 37 aura::client::GetScreenPositionClient(root_window); | |
| 38 screen_position_client->ConvertPointFromScreen(root_window, point); | |
| 39 } | |
| 40 | |
| 30 } // namespace | 41 } // namespace |
| 31 | 42 |
| 32 namespace ash { | 43 namespace ash { |
| 33 namespace internal { | 44 namespace internal { |
| 34 | 45 |
| 35 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
| 36 // MagnificationControllerImpl: | 47 // MagnificationControllerImpl: |
| 37 | 48 |
| 38 class MagnificationControllerImpl : virtual public MagnificationController, | 49 class MagnificationControllerImpl : virtual public MagnificationController, |
| 39 public aura::EventFilter, | 50 public aura::EventFilter, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 float scale, | 83 float scale, |
| 73 bool animate); | 84 bool animate); |
| 74 void EnsureRectIsVisibleDIP(const gfx::Rect& target_rect_in_dip, | 85 void EnsureRectIsVisibleDIP(const gfx::Rect& target_rect_in_dip, |
| 75 float scale, | 86 float scale, |
| 76 bool animate); | 87 bool animate); |
| 77 void EnsurePointIsVisibleWithScale(const gfx::Point& point, | 88 void EnsurePointIsVisibleWithScale(const gfx::Point& point, |
| 78 float scale, | 89 float scale, |
| 79 bool animate); | 90 bool animate); |
| 80 void OnMouseMove(const gfx::Point& location); | 91 void OnMouseMove(const gfx::Point& location); |
| 81 | 92 |
| 93 // Switch Magnified RootWindow to |new_root_window|. This does following: | |
| 94 // - Unzoom the current root_window. | |
| 95 // - Zoom the given new root_window |new_root_window|. | |
| 96 // - Switch the target window from current window to |new_root_window|. | |
| 97 void SwitchTargetRootWindow(aura::RootWindow* new_root_window); | |
| 98 | |
| 82 // Returns if the magnification scale is 1.0 or not (larger then 1.0). | 99 // Returns if the magnification scale is 1.0 or not (larger then 1.0). |
| 83 bool IsMagnified() const; | 100 bool IsMagnified() const; |
| 84 | 101 |
| 85 // Returns the rect of the magnification window. | 102 // Returns the rect of the magnification window. |
| 86 gfx::Rect GetWindowRectDIP(float scale) const; | 103 gfx::Rect GetWindowRectDIP(float scale) const; |
| 87 // Returns the size of the root window. | 104 // Returns the size of the root window. |
| 88 gfx::Size GetHostSizeDIP() const; | 105 gfx::Size GetHostSizeDIP() const; |
| 89 | 106 |
| 90 // Correct the givin scale value if nessesary. | 107 // Correct the givin scale value if nessesary. |
| 91 void ValidateScale(float* scale); | 108 void ValidateScale(float* scale); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 | 171 |
| 155 const gfx::Size host_size_in_dip = GetHostSizeDIP(); | 172 const gfx::Size host_size_in_dip = GetHostSizeDIP(); |
| 156 const gfx::Size window_size_in_dip = GetWindowRectDIP(scale).size(); | 173 const gfx::Size window_size_in_dip = GetWindowRectDIP(scale).size(); |
| 157 int max_x = host_size_in_dip.width() - window_size_in_dip.width(); | 174 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(); | 175 int max_y = host_size_in_dip.height() - window_size_in_dip.height(); |
| 159 if (x > max_x) | 176 if (x > max_x) |
| 160 x = max_x; | 177 x = max_x; |
| 161 if (y > max_y) | 178 if (y > max_y) |
| 162 y = max_y; | 179 y = max_y; |
| 163 | 180 |
| 164 // Ignores 1 px diffirence because it may be error on calculation. | 181 // Does nothing if both the origin and the scale are not changed. |
| 165 if (std::abs(origin_.x() - x) <= 1 && | 182 if (origin_.x() == x && |
| 166 std::abs(origin_.y() - y) <= 1 && | 183 origin_.y() == y && |
| 167 scale == scale_) | 184 scale == scale_) { |
| 168 return false; | 185 return false; |
| 186 } | |
| 169 | 187 |
| 170 origin_.set_x(x); | 188 origin_.set_x(x); |
| 171 origin_.set_y(y); | 189 origin_.set_y(y); |
| 172 scale_ = scale; | 190 scale_ = scale; |
| 173 | 191 |
| 174 // Creates transform matrix. | 192 // Creates transform matrix. |
| 175 ui::Transform transform; | 193 ui::Transform transform; |
| 176 // Flips the signs intentionally to convert them from the position of the | 194 // Flips the signs intentionally to convert them from the position of the |
| 177 // magnification window. | 195 // magnification window. |
| 178 transform.ConcatTranslate(-origin_.x(), -origin_.y()); | 196 transform.ConcatTranslate(-origin_.x(), -origin_.y()); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 // |kMinMagnifiedScaleThreshold|; | 344 // |kMinMagnifiedScaleThreshold|; |
| 327 if (*scale > kMaxMagnifiedScaleThreshold) | 345 if (*scale > kMaxMagnifiedScaleThreshold) |
| 328 *scale = kMaxMagnifiedScale; | 346 *scale = kMaxMagnifiedScale; |
| 329 } | 347 } |
| 330 | 348 |
| 331 void MagnificationControllerImpl::OnImplicitAnimationsCompleted() { | 349 void MagnificationControllerImpl::OnImplicitAnimationsCompleted() { |
| 332 root_window_->ShowCursor(true); | 350 root_window_->ShowCursor(true); |
| 333 is_on_zooming_ = false; | 351 is_on_zooming_ = false; |
| 334 } | 352 } |
| 335 | 353 |
| 354 void MagnificationControllerImpl::SwitchTargetRootWindow( | |
| 355 aura::RootWindow* new_root_window) { | |
| 356 float scale = GetScale(); | |
|
sky
2012/08/06 15:09:47
Should this do nothing if new_root_window == root_
yoshiki
2012/08/06 22:22:16
Done.
| |
| 357 | |
| 358 SetScale(1.0f, true); | |
| 359 root_window_ = new_root_window; | |
| 360 SetScale(scale, true); | |
| 361 } | |
| 362 | |
| 336 //////////////////////////////////////////////////////////////////////////////// | 363 //////////////////////////////////////////////////////////////////////////////// |
| 337 // MagnificationControllerImpl: MagnificationController implementation | 364 // MagnificationControllerImpl: MagnificationController implementation |
| 338 | 365 |
| 339 void MagnificationControllerImpl::SetScale(float scale, bool animate) { | 366 void MagnificationControllerImpl::SetScale(float scale, bool animate) { |
| 340 if (!is_enabled_) | 367 if (!is_enabled_) |
| 341 return; | 368 return; |
| 342 | 369 |
| 343 ValidateScale(&scale); | 370 ValidateScale(&scale); |
| 344 | 371 |
| 345 // Try not to change the point which the mouse cursor indicates to. | 372 // Try not to change the point which the mouse cursor indicates to. |
| 346 const gfx::Rect window_rect = GetWindowRectDIP(scale); | 373 gfx::Point mouse_in_root = gfx::Screen::GetCursorScreenPoint(); |
| 347 const gfx::Point mouse = gfx::Screen::GetCursorScreenPoint(); | 374 if (DisplayController::IsExtendedDesktopEnabled()) |
| 348 const gfx::Point origin = gfx::Point(mouse.x() * (1.0f - 1.0f / scale), | 375 ConvertsCoordinateFromScreenToRoot(root_window_, &mouse_in_root); |
| 349 mouse.y() * (1.0f - 1.0f / scale)); | 376 |
| 377 const gfx::Point origin = | |
| 378 gfx::Point(mouse_in_root.x() * (1.0f - 1.0f / scale), | |
| 379 mouse_in_root.y() * (1.0f - 1.0f / scale)); | |
| 350 Redraw(origin, scale, animate); | 380 Redraw(origin, scale, animate); |
| 351 } | 381 } |
| 352 | 382 |
| 353 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) { | 383 void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) { |
| 354 if (!is_enabled_) | 384 if (!is_enabled_) |
| 355 return; | 385 return; |
| 356 | 386 |
| 357 Redraw(gfx::Point(x, y), scale_, animate); | 387 Redraw(gfx::Point(x, y), scale_, animate); |
| 358 } | 388 } |
| 359 | 389 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 //////////////////////////////////////////////////////////////////////////////// | 426 //////////////////////////////////////////////////////////////////////////////// |
| 397 // MagnificationControllerImpl: aura::EventFilter implementation | 427 // MagnificationControllerImpl: aura::EventFilter implementation |
| 398 | 428 |
| 399 bool MagnificationControllerImpl::PreHandleKeyEvent(aura::Window* target, | 429 bool MagnificationControllerImpl::PreHandleKeyEvent(aura::Window* target, |
| 400 aura::KeyEvent* event) { | 430 aura::KeyEvent* event) { |
| 401 return false; | 431 return false; |
| 402 } | 432 } |
| 403 | 433 |
| 404 bool MagnificationControllerImpl::PreHandleMouseEvent(aura::Window* target, | 434 bool MagnificationControllerImpl::PreHandleMouseEvent(aura::Window* target, |
| 405 aura::MouseEvent* event) { | 435 aura::MouseEvent* event) { |
| 406 if (IsMagnified() && event->type() == ui::ET_MOUSE_MOVED) | 436 if (IsMagnified() && event->type() == ui::ET_MOUSE_MOVED) { |
| 407 OnMouseMove(event->root_location()); | 437 aura::RootWindow* current_root = target->GetRootWindow(); |
| 438 gfx::Rect root_bounds = current_root->bounds(); | |
| 439 | |
| 440 if (root_bounds.Contains(event->root_location())) { | |
| 441 if (current_root != root_window_) | |
| 442 SwitchTargetRootWindow(current_root); | |
| 443 | |
| 444 OnMouseMove(event->root_location()); | |
| 445 } | |
| 446 } | |
| 447 | |
| 408 return false; | 448 return false; |
| 409 } | 449 } |
| 410 | 450 |
| 411 ui::TouchStatus MagnificationControllerImpl::PreHandleTouchEvent( | 451 ui::TouchStatus MagnificationControllerImpl::PreHandleTouchEvent( |
| 412 aura::Window* target, | 452 aura::Window* target, |
| 413 aura::TouchEvent* event) { | 453 aura::TouchEvent* event) { |
| 414 return ui::TOUCH_STATUS_UNKNOWN; | 454 return ui::TOUCH_STATUS_UNKNOWN; |
| 415 } | 455 } |
| 416 | 456 |
| 417 ui::GestureStatus MagnificationControllerImpl::PreHandleGestureEvent( | 457 ui::GestureStatus MagnificationControllerImpl::PreHandleGestureEvent( |
| 418 aura::Window* target, | 458 aura::Window* target, |
| 419 aura::GestureEvent* event) { | 459 aura::GestureEvent* event) { |
| 420 return ui::GESTURE_STATUS_UNKNOWN; | 460 return ui::GESTURE_STATUS_UNKNOWN; |
| 421 } | 461 } |
| 422 | 462 |
| 423 //////////////////////////////////////////////////////////////////////////////// | 463 //////////////////////////////////////////////////////////////////////////////// |
| 424 // MagnificationController: | 464 // MagnificationController: |
| 425 | 465 |
| 426 // static | 466 // static |
| 427 MagnificationController* MagnificationController::CreateInstance() { | 467 MagnificationController* MagnificationController::CreateInstance() { |
| 428 return new MagnificationControllerImpl(); | 468 return new MagnificationControllerImpl(); |
| 429 } | 469 } |
| 430 | 470 |
| 431 } // namespace internal | 471 } // namespace internal |
| 432 } // namespace ash | 472 } // namespace ash |
| OLD | NEW |