Chromium Code Reviews| Index: ash/magnifier/magnification_controller.cc |
| diff --git a/ash/magnifier/magnification_controller.cc b/ash/magnifier/magnification_controller.cc |
| index ff2ea926b665153300329b47800ab16596c0e48c..26f1bd48b5d803fed00e759297621c17a877a08f 100644 |
| --- a/ash/magnifier/magnification_controller.cc |
| +++ b/ash/magnifier/magnification_controller.cc |
| @@ -4,7 +4,10 @@ |
| #include "ash/magnifier/magnification_controller.h" |
| +#include "ash/display/display_controller.h" |
| +#include "ash/display/screen_position_controller.h" |
| #include "ash/shell.h" |
| +#include "ui/aura/client/screen_position_client.h" |
| #include "ui/aura/event.h" |
| #include "ui/aura/event_filter.h" |
| #include "ui/aura/root_window.h" |
| @@ -27,6 +30,14 @@ const float kNonMagnifiedScale = 1.0f; |
| const float kInitialMagnifiedScale = 2.0f; |
| +// Convets position from screen coordinate to root_window coordinate. |
| +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
|
| + gfx::Point* point) { |
| + aura::client::ScreenPositionClient* screen_position_client = |
| + aura::client::GetScreenPositionClient(root_window); |
| + screen_position_client->ConvertPointFromScreen(root_window, point); |
| +} |
| + |
| } // namespace |
| namespace ash { |
| @@ -79,6 +90,12 @@ class MagnificationControllerImpl : virtual public MagnificationController, |
| bool animate); |
| void OnMouseMove(const gfx::Point& location); |
| + // Switch Magnified RootWindow to |new_root_window|. This does following: |
| + // - Unzoom the current root_window. |
| + // - Zoom the given new root_window |new_root_window|. |
| + // - Switch the target window from current window to |new_root_window|. |
| + void SwitchTargetRootWindow(aura::RootWindow* new_root_window); |
| + |
| // Returns if the magnification scale is 1.0 or not (larger then 1.0). |
| bool IsMagnified() const; |
| @@ -161,11 +178,12 @@ bool MagnificationControllerImpl::RedrawDIP(const gfx::Point& position_in_dip, |
| if (y > max_y) |
| y = max_y; |
| - // Ignores 1 px diffirence because it may be error on calculation. |
| - if (std::abs(origin_.x() - x) <= 1 && |
| - std::abs(origin_.y() - y) <= 1 && |
| - scale == scale_) |
| + // Does nothing if both the origin and the scale are not changed. |
| + if (origin_.x() == x && |
| + origin_.y() == y && |
| + scale == scale_) { |
| return false; |
| + } |
| origin_.set_x(x); |
| origin_.set_y(y); |
| @@ -333,6 +351,15 @@ void MagnificationControllerImpl::OnImplicitAnimationsCompleted() { |
| is_on_zooming_ = false; |
| } |
| +void MagnificationControllerImpl::SwitchTargetRootWindow( |
| + aura::RootWindow* new_root_window) { |
| + 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.
|
| + |
| + SetScale(1.0f, true); |
| + root_window_ = new_root_window; |
| + SetScale(scale, true); |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // MagnificationControllerImpl: MagnificationController implementation |
| @@ -343,10 +370,13 @@ void MagnificationControllerImpl::SetScale(float scale, bool animate) { |
| ValidateScale(&scale); |
| // Try not to change the point which the mouse cursor indicates to. |
| - const gfx::Rect window_rect = GetWindowRectDIP(scale); |
| - const gfx::Point mouse = gfx::Screen::GetCursorScreenPoint(); |
| - const gfx::Point origin = gfx::Point(mouse.x() * (1.0f - 1.0f / scale), |
| - mouse.y() * (1.0f - 1.0f / scale)); |
| + gfx::Point mouse_in_root = gfx::Screen::GetCursorScreenPoint(); |
| + if (DisplayController::IsExtendedDesktopEnabled()) |
| + ConvertsCoordinateFromScreenToRoot(root_window_, &mouse_in_root); |
| + |
| + const gfx::Point origin = |
| + gfx::Point(mouse_in_root.x() * (1.0f - 1.0f / scale), |
| + mouse_in_root.y() * (1.0f - 1.0f / scale)); |
| Redraw(origin, scale, animate); |
| } |
| @@ -403,8 +433,18 @@ bool MagnificationControllerImpl::PreHandleKeyEvent(aura::Window* target, |
| bool MagnificationControllerImpl::PreHandleMouseEvent(aura::Window* target, |
| aura::MouseEvent* event) { |
| - if (IsMagnified() && event->type() == ui::ET_MOUSE_MOVED) |
| - OnMouseMove(event->root_location()); |
| + if (IsMagnified() && event->type() == ui::ET_MOUSE_MOVED) { |
| + aura::RootWindow* current_root = target->GetRootWindow(); |
| + gfx::Rect root_bounds = current_root->bounds(); |
| + |
| + if (root_bounds.Contains(event->root_location())) { |
| + if (current_root != root_window_) |
| + SwitchTargetRootWindow(current_root); |
| + |
| + OnMouseMove(event->root_location()); |
| + } |
| + } |
| + |
| return false; |
| } |