summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authoryoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-22 02:18:05 +0000
committeryoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-22 02:18:05 +0000
commit9613eacf26ab9f04831a88a8a90831020b548918 (patch)
tree378d9b88b0eb6caf24ad32abe81c92e898f4661f /ash
parent6097cb525fabf26d254f79f400ac5362a8b094e9 (diff)
downloadchromium_src-9613eacf26ab9f04831a88a8a90831020b548918.zip
chromium_src-9613eacf26ab9f04831a88a8a90831020b548918.tar.gz
chromium_src-9613eacf26ab9f04831a88a8a90831020b548918.tar.bz2
Full-screen Magnifier: Support warping the cursor on the edge
With this CL, a magnified region will moved when the cursor on the edge. Only on debug build, we can test the this magnifier with "Ctrl + {" and "Ctrl + }" shortcut. These shortcut keys are temporary. These will be removed just after either the shortcuts or setting UI are fixed. BUG=126880 TEST=manual test (even with high-DPI and external display) Review URL: https://chromiumcodereview.appspot.com/10388141 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143514 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/accelerators/accelerator_controller.cc28
-rw-r--r--ash/accelerators/accelerator_table.cc2
-rw-r--r--ash/accelerators/accelerator_table.h2
-rw-r--r--ash/magnifier/magnification_controller.cc409
-rw-r--r--ash/magnifier/magnification_controller.h40
-rw-r--r--ash/shell.cc4
6 files changed, 390 insertions, 95 deletions
diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc
index 6690675..37ffbb6 100644
--- a/ash/accelerators/accelerator_controller.cc
+++ b/ash/accelerators/accelerator_controller.cc
@@ -4,6 +4,8 @@
#include "ash/accelerators/accelerator_controller.h"
+#include <cmath>
+
#include "ash/accelerators/accelerator_table.h"
#include "ash/ash_switches.h"
#include "ash/caps_lock_delegate.h"
@@ -13,6 +15,7 @@
#include "ash/launcher/launcher.h"
#include "ash/launcher/launcher_delegate.h"
#include "ash/launcher/launcher_model.h"
+#include "ash/magnifier/magnification_controller.h"
#include "ash/monitor/monitor_controller.h"
#include "ash/monitor/multi_monitor_manager.h"
#include "ash/root_window_controller.h"
@@ -47,6 +50,11 @@
namespace ash {
namespace {
+// Factor of magnification scale. For example, when this value is 1.189, scale
+// value will be changed x1.000, x1.189, x1.414, x1.681, x2.000, ...
+// Note: this value is 2.0 ^ (1 / 4).
+const float kMagnificationFactor = 1.18920712;
+
bool DebugShortcutsEnabled() {
#if defined(NDEBUG)
return CommandLine::ForCurrentProcess()->HasSwitch(
@@ -236,6 +244,22 @@ bool HandlePrintWindowHierarchy() {
return true;
}
+// Magnify the screen
+bool HandleMagnifyScreen(int delta_index) {
+ float scale =
+ ash::Shell::GetInstance()->magnification_controller()->GetScale();
+ // Calculate rounded logarithm (base kMagnificationFactor) of scale.
+ int scale_index =
+ std::floor(std::log(scale) / std::log(kMagnificationFactor) + 0.5);
+
+ int new_scale_index = std::max(0, std::min(8, scale_index + delta_index));
+
+ ash::Shell::GetInstance()->magnification_controller()->
+ SetScale(std::pow(kMagnificationFactor, new_scale_index), true);
+
+ return true;
+}
+
#endif // !defined(NDEBUG)
} // namespace
@@ -564,6 +588,10 @@ bool AcceleratorController::PerformAction(int action,
internal::MultiMonitorManager::ToggleMonitorScale();
return true;
#if !defined(NDEBUG)
+ case MAGNIFY_SCREEN_ZOOM_IN:
+ return HandleMagnifyScreen(1);
+ case MAGNIFY_SCREEN_ZOOM_OUT:
+ return HandleMagnifyScreen(-1);
case PRINT_LAYER_HIERARCHY:
return HandlePrintLayerHierarchy();
case PRINT_WINDOW_HIERARCHY:
diff --git a/ash/accelerators/accelerator_table.cc b/ash/accelerators/accelerator_table.cc
index b32b2cb..f6b2ab4 100644
--- a/ash/accelerators/accelerator_table.cc
+++ b/ash/accelerators/accelerator_table.cc
@@ -118,6 +118,8 @@ const AcceleratorData kAcceleratorData[] = {
{ true, ui::VKEY_HOME, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN,
MONITOR_TOGGLE_SCALE },
#if !defined(NDEBUG)
+ { true, ui::VKEY_OEM_4, ui::EF_CONTROL_DOWN, MAGNIFY_SCREEN_ZOOM_IN},
+ { true, ui::VKEY_OEM_6, ui::EF_CONTROL_DOWN, MAGNIFY_SCREEN_ZOOM_OUT},
{ true, ui::VKEY_L, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
PRINT_LAYER_HIERARCHY },
{ true, ui::VKEY_W, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN,
diff --git a/ash/accelerators/accelerator_table.h b/ash/accelerators/accelerator_table.h
index 25b118e..fca8ba6 100644
--- a/ash/accelerators/accelerator_table.h
+++ b/ash/accelerators/accelerator_table.h
@@ -72,6 +72,8 @@ enum AcceleratorAction {
TOGGLE_DESKTOP_BACKGROUND_MODE,
TOGGLE_ROOT_WINDOW_FULL_SCREEN,
#if !defined(NDEBUG)
+ MAGNIFY_SCREEN_ZOOM_IN,
+ MAGNIFY_SCREEN_ZOOM_OUT,
PRINT_LAYER_HIERARCHY,
PRINT_WINDOW_HIERARCHY,
#endif
diff --git a/ash/magnifier/magnification_controller.cc b/ash/magnifier/magnification_controller.cc
index bd79c5e..c732006 100644
--- a/ash/magnifier/magnification_controller.cc
+++ b/ash/magnifier/magnification_controller.cc
@@ -5,10 +5,16 @@
#include "ash/magnifier/magnification_controller.h"
#include "ash/shell.h"
+#include "ui/aura/event.h"
+#include "ui/aura/event_filter.h"
#include "ui/aura/root_window.h"
+#include "ui/aura/shared/compound_event_filter.h"
#include "ui/aura/window.h"
#include "ui/aura/window_property.h"
+#include "ui/gfx/point3.h"
+#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer.h"
+#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
namespace {
@@ -23,106 +29,371 @@ const float kMinimumMagnifiScaleThreshold = 1.1f;
namespace ash {
namespace internal {
-MagnificationController::MagnificationController()
- : scale_(1.0f), x_(0), y_(0) {
- root_window_ = ash::Shell::GetPrimaryRootWindow();
+////////////////////////////////////////////////////////////////////////////////
+// MagnificationControllerImpl:
+
+class MagnificationControllerImpl : virtual public MagnificationController,
+ public aura::EventFilter,
+ public ui::ImplicitAnimationObserver {
+ public:
+ MagnificationControllerImpl();
+ virtual ~MagnificationControllerImpl();
+
+ // MagnificationController overrides:
+ virtual void SetScale(float scale, bool animate) OVERRIDE;
+ virtual float GetScale() const OVERRIDE { return scale_; }
+ virtual void MoveWindow(int x, int y, bool animate) OVERRIDE;
+ virtual void MoveWindow(const gfx::Point& point, bool animate) OVERRIDE;
+ virtual gfx::Point GetWindowPosition() const OVERRIDE { return origin_; }
+ virtual void EnsureRectIsVisible(const gfx::Rect& rect,
+ bool animate) OVERRIDE;
+ virtual void EnsurePointIsVisible(const gfx::Point& point,
+ bool animate) OVERRIDE;
+
+ private:
+ // ui::ImplicitAnimationObserver overrides:
+ virtual void OnImplicitAnimationsCompleted() OVERRIDE;
+
+ // Redraws the magnification window with the given origin position and the
+ // given scale. Returns true if the window is changed; otherwise, false.
+ // These methods should be called internally just after the scale and/or
+ // the position are changed to redraw the window.
+ bool Redraw(const gfx::Point& position, float scale, bool animate);
+ bool RedrawDIP(const gfx::Point& position, float scale, bool animate);
+
+ // Ensures that the given point, rect or last mouse location is inside
+ // magnification window. If not, the controller moves the window to contain
+ // the given point/rect.
+ void EnsureRectIsVisibleWithScale(const gfx::Rect& target_rect,
+ float scale,
+ bool animate);
+ void EnsureRectIsVisibleDIP(const gfx::Rect& target_rect_in_dip,
+ float scale,
+ bool animate);
+ void EnsurePointIsVisibleWithScale(const gfx::Point& point,
+ float scale,
+ bool animate);
+ void OnMouseMove(const gfx::Point& location);
+
+ // Returns if the magnification scale is 1.0 or not (larger then 1.0).
+ bool IsMagnified() const;
+
+ // Returns the rect of the magnification window.
+ gfx::Rect GetWindowRectDIP(float scale) const;
+ // Returns the size of the root window.
+ gfx::Size GetHostSizeDIP() const;
+
+ // Correct the givin scale value if nessesary.
+ void ValidateScale(float* scale);
+
+ // aura::EventFilter overrides:
+ virtual bool PreHandleKeyEvent(aura::Window* target,
+ aura::KeyEvent* event) OVERRIDE;
+ virtual bool PreHandleMouseEvent(aura::Window* target,
+ aura::MouseEvent* event) OVERRIDE;
+ virtual ui::TouchStatus PreHandleTouchEvent(aura::Window* target,
+ aura::TouchEvent* event) OVERRIDE;
+ virtual ui::GestureStatus PreHandleGestureEvent(
+ aura::Window* target,
+ aura::GestureEvent* event) OVERRIDE;
+
+ aura::RootWindow* root_window_;
+
+ // True if the magnified window is in motion of zooming or un-zooming effect.
+ // Otherwise, false.
+ bool is_on_zooming_;
+
+ // Current scale, origin (left-top) position of the magnification window.
+ float scale_;
+ gfx::Point origin_;
+
+ DISALLOW_COPY_AND_ASSIGN(MagnificationControllerImpl);
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// MagnificationControllerImpl:
+
+MagnificationControllerImpl::MagnificationControllerImpl()
+ : root_window_(ash::Shell::GetPrimaryRootWindow()),
+ is_on_zooming_(false),
+ scale_(1.0f) {
+ Shell::GetInstance()->AddEnvEventFilter(this);
}
-void MagnificationController::SetScale(float scale) {
- scale_ = scale;
- RedrawScreen(true);
+MagnificationControllerImpl::~MagnificationControllerImpl() {
+ Shell::GetInstance()->RemoveEnvEventFilter(this);
}
-void MagnificationController::MoveWindow(int x, int y) {
- y_ = y;
- x_ = x;
- RedrawScreen(true);
+bool MagnificationControllerImpl::Redraw(const gfx::Point& position,
+ float scale,
+ bool animate) {
+ const gfx::Point position_in_dip =
+ ui::ConvertPointToDIP(root_window_->layer(), position);
+ return RedrawDIP(position_in_dip, scale, animate);
}
-void MagnificationController::MoveWindow(const gfx::Point& point) {
- MoveWindow(point.x(), point.y());
+bool MagnificationControllerImpl::RedrawDIP(const gfx::Point& position_in_dip,
+ float scale,
+ bool animate) {
+ int x = position_in_dip.x();
+ int y = position_in_dip.y();
+
+ ValidateScale(&scale);
+
+ if (x < 0)
+ x = 0;
+ if (y < 0)
+ y = 0;
+
+ const gfx::Size host_size_in_dip = GetHostSizeDIP();
+ const gfx::Size window_size_in_dip = GetWindowRectDIP(scale).size();
+ int max_x = host_size_in_dip.width() - window_size_in_dip.width();
+ int max_y = host_size_in_dip.height() - window_size_in_dip.height();
+ if (x > max_x)
+ x = max_x;
+ 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_)
+ return false;
+
+ origin_.set_x(x);
+ origin_.set_y(y);
+ scale_ = scale;
+
+ // Creates transform matrix.
+ ui::Transform transform;
+ // Flips the signs intentionally to convert them from the position of the
+ // magnification window.
+ transform.ConcatTranslate(-origin_.x(), -origin_.y());
+ transform.ConcatScale(scale_, scale_);
+
+ ui::ScopedLayerAnimationSettings settings(
+ root_window_->layer()->GetAnimator());
+ settings.AddObserver(this);
+ settings.SetPreemptionStrategy(
+ ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
+ settings.SetTweenType(ui::Tween::EASE_OUT);
+ settings.SetTransitionDuration(
+ base::TimeDelta::FromMilliseconds(animate ? 100 : 0));
+
+ root_window_->layer()->SetTransform(transform);
+
+ return true;
}
-void MagnificationController::EnsureShowRect(const gfx::Rect& target_rect) {
- gfx::Rect rect = GetWindowRect().AdjustToFit(target_rect);
- MoveWindow(rect.x(), rect.y());
+void MagnificationControllerImpl::EnsureRectIsVisibleWithScale(
+ const gfx::Rect& target_rect,
+ float scale,
+ bool animate) {
+ const gfx::Rect target_rect_in_dip =
+ ui::ConvertRectToDIP(root_window_->layer(), target_rect);
+ EnsureRectIsVisibleDIP(target_rect_in_dip, scale, animate);
}
-void MagnificationController::EnsureShowPoint(const gfx::Point& point,
- bool animation) {
- gfx::Rect rect = GetWindowRect();
+void MagnificationControllerImpl::EnsureRectIsVisibleDIP(
+ const gfx::Rect& target_rect,
+ float scale,
+ bool animate) {
+ ValidateScale(&scale);
- if (rect.Contains(point))
+ const gfx::Rect window_rect = GetWindowRectDIP(scale);
+ if (scale == scale_ && window_rect.Contains(target_rect))
return;
- if (point.x() < rect.x())
- x_ = point.x();
- else if(rect.right() < point.x())
- x_ = point.x() - rect.width();
+ // TODO(yoshiki): Un-zoom and change the scale if the magnification window
+ // can't contain the whole given rect.
+
+ gfx::Rect rect = window_rect;
+ if (target_rect.width() > rect.width())
+ rect.set_x(target_rect.CenterPoint().x() - rect.x() / 2);
+ else if (target_rect.right() < rect.x())
+ rect.set_x(target_rect.right());
+ else if (rect.right() < target_rect.x())
+ rect.set_x(target_rect.x() - rect.width());
- if (point.y() < rect.y())
- y_ = point.y();
- else if(rect.bottom() < point.y())
- y_ = point.y() - rect.height();
+ if (rect.height() > window_rect.height())
+ rect.set_y(target_rect.CenterPoint().y() - rect.y() / 2);
+ else if (target_rect.bottom() < rect.y())
+ rect.set_y(target_rect.bottom());
+ else if (rect.bottom() < target_rect.y())
+ rect.set_y(target_rect.y() - rect.height());
- RedrawScreen(animation);
+ RedrawDIP(rect.origin(), scale, animate);
}
-void MagnificationController::RedrawScreen(bool animation) {
+void MagnificationControllerImpl::EnsurePointIsVisibleWithScale(
+ const gfx::Point& point,
+ float scale,
+ bool animate) {
+ EnsureRectIsVisibleWithScale(gfx::Rect(point, gfx::Size(0, 0)),
+ scale,
+ animate);
+}
+
+void MagnificationControllerImpl::OnMouseMove(const gfx::Point& location) {
+ gfx::Point mouse(location);
+
+ int x = origin_.x();
+ int y = origin_.y();
+ bool start_zoom = false;
+
+ const gfx::Rect window_rect = GetWindowRectDIP(scale_);
+ const int left = window_rect.x();
+ const int right = window_rect.right();
+ const int width_margin = static_cast<int>(0.1f * window_rect.width());
+ const int width_offset = static_cast<int>(0.5f * window_rect.width());
+
+ if (mouse.x() < left + width_margin) {
+ x -= width_offset;
+ start_zoom = true;
+ } else if (right - width_margin < mouse.x()) {
+ x += width_offset;
+ start_zoom = true;
+ }
+
+ const int top = window_rect.y();
+ const int bottom = window_rect.bottom();
+ // Uses same margin with x-axis's one.
+ const int height_margin = width_margin;
+ const int height_offset = static_cast<int>(0.5f * window_rect.height());
+ if (mouse.y() < top + height_margin) {
+ y -= height_offset;
+ start_zoom = true;
+ } else if (bottom - height_margin < mouse.y()) {
+ y += height_offset;
+ start_zoom = true;
+ }
+
+ if (start_zoom && !is_on_zooming_) {
+ bool ret = Redraw(gfx::Point(x, y), scale_, true);
+
+ if (ret) {
+ is_on_zooming_ = true;
+
+ int x_diff = origin_.x() - window_rect.x();
+ int y_diff = origin_.y() - window_rect.y();
+ // If the magnified region is moved, hides the mouse cursor and moves it.
+ if (x_diff != 0 || y_diff != 0) {
+ ash::Shell::GetInstance()->
+ env_filter()->set_update_cursor_visibility(false);
+ root_window_->ShowCursor(false);
+ mouse.set_x(mouse.x() - (origin_.x() - window_rect.x()));
+ mouse.set_y(mouse.y() - (origin_.y() - window_rect.y()));
+ root_window_->MoveCursorTo(mouse);
+ }
+ }
+ }
+}
+
+gfx::Size MagnificationControllerImpl::GetHostSizeDIP() const {
+ return ui::ConvertSizeToDIP(root_window_->layer(),
+ root_window_->GetHostSize());
+}
+
+gfx::Rect MagnificationControllerImpl::GetWindowRectDIP(float scale) const {
+ const gfx::Size size_in_dip =
+ ui::ConvertSizeToDIP(root_window_->layer(),
+ root_window_->GetHostSize());
+ const int width = size_in_dip.width() / scale;
+ const int height = size_in_dip.height() / scale;
+
+ return gfx::Rect(origin_.x(), origin_.y(), width, height);
+}
+
+bool MagnificationControllerImpl::IsMagnified() const {
+ return scale_ >= kMinimumMagnifiScaleThreshold;
+}
+
+void MagnificationControllerImpl::ValidateScale(float* scale) {
// Adjust the scale to just |kMinimumMagnifiScale| if scale is smaller than
// |kMinimumMagnifiScaleThreshold|;
- if (scale_ < kMinimumMagnifiScaleThreshold)
- scale_ = kMinimumMagnifiScale;
+ if (*scale < kMinimumMagnifiScaleThreshold)
+ *scale = kMinimumMagnifiScale;
+
// Adjust the scale to just |kMinimumMagnifiScale| if scale is bigger than
// |kMinimumMagnifiScaleThreshold|;
- if (scale_ > kMaximumMagnifiScaleThreshold)
- scale_ = kMaximumMagnifiScale;
+ if (*scale > kMaximumMagnifiScaleThreshold)
+ *scale = kMaximumMagnifiScale;
+}
- if (x_ < 0)
- x_ = 0;
- if (y_ < 0)
- y_ = 0;
+void MagnificationControllerImpl::OnImplicitAnimationsCompleted() {
+ root_window_->ShowCursor(true);
+ is_on_zooming_ = false;
+}
- gfx::Size host_size = root_window_->GetHostSize();
- gfx::Size window_size = GetWindowRect().size();
- int max_x = host_size.width() - window_size.width();
- int max_y = host_size.height() - window_size.height();
- if (x_ > max_x)
- x_ = max_x;
- if (y_ > max_y)
- y_ = max_y;
+////////////////////////////////////////////////////////////////////////////////
+// MagnificationControllerImpl: MagnificationController implementation
+void MagnificationControllerImpl::SetScale(float scale, bool animate) {
+ ValidateScale(&scale);
- float scale = scale_;
- int x = x_;
- int y = y_;
+ // Try not to change the point which the mouse cursor indicates to.
+ const gfx::Rect window_rect = GetWindowRectDIP(scale);
+ const gfx::Point mouse = root_window_->last_mouse_location();
+ const gfx::Point origin = gfx::Point(mouse.x() * (1.0f - 1.0f / scale),
+ mouse.y() * (1.0f - 1.0f / scale));
+ Redraw(origin, scale, animate);
+}
- // Creates transform matrix.
- ui::Transform transform;
- // Flips the signs intentionally to convert them from the position of the
- // magnification window.
- transform.ConcatTranslate(-x, -y);
- transform.ConcatScale(scale, scale);
-
- if (animation) {
- ui::ScopedLayerAnimationSettings settings(
- root_window_->layer()->GetAnimator());
- settings.SetPreemptionStrategy(
- ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
- settings.SetTweenType(ui::Tween::EASE_IN_OUT);
- settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(100));
- }
+void MagnificationControllerImpl::MoveWindow(int x, int y, bool animate) {
+ Redraw(gfx::Point(x, y), scale_, animate);
+}
- root_window_->layer()->SetTransform(transform);
+void MagnificationControllerImpl::MoveWindow(const gfx::Point& point,
+ bool animate) {
+ Redraw(point, scale_, animate);
+}
+
+void MagnificationControllerImpl::EnsureRectIsVisible(
+ const gfx::Rect& target_rect,
+ bool animate) {
+ EnsureRectIsVisibleWithScale(target_rect, scale_, animate);
+}
+
+void MagnificationControllerImpl::EnsurePointIsVisible(
+ const gfx::Point& point,
+ bool animate) {
+ EnsurePointIsVisibleWithScale(point, scale_, animate);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// MagnificationControllerImpl: aura::EventFilter implementation
+
+bool MagnificationControllerImpl::PreHandleKeyEvent(aura::Window* target,
+ aura::KeyEvent* event) {
+ return false;
+}
+
+bool MagnificationControllerImpl::PreHandleMouseEvent(aura::Window* target,
+ aura::MouseEvent* event) {
+ if (IsMagnified())
+ OnMouseMove(event->root_location());
+ return false;
+}
+
+ui::TouchStatus MagnificationControllerImpl::PreHandleTouchEvent(
+ aura::Window* target,
+ aura::TouchEvent* event) {
+ return ui::TOUCH_STATUS_UNKNOWN;
+}
+
+ui::GestureStatus MagnificationControllerImpl::PreHandleGestureEvent(
+ aura::Window* target,
+ aura::GestureEvent* event) {
+ return ui::GESTURE_STATUS_UNKNOWN;
}
-gfx::Rect MagnificationController::GetWindowRect() {
- gfx::Size size = root_window_->GetHostSize();
- int width = size.width() / scale_;
- int height = size.height() / scale_;
+////////////////////////////////////////////////////////////////////////////////
+// MagnificationController:
- return gfx::Rect(x_, y_, width, height);
+// static
+MagnificationController* MagnificationController::CreateInstance() {
+ return new MagnificationControllerImpl();
}
} // namespace internal
diff --git a/ash/magnifier/magnification_controller.h b/ash/magnifier/magnification_controller.h
index f0927b6..a97d171 100644
--- a/ash/magnifier/magnification_controller.h
+++ b/ash/magnifier/magnification_controller.h
@@ -8,6 +8,8 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/aura/event_filter.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
@@ -20,42 +22,30 @@ namespace internal {
class MagnificationController {
public:
- MagnificationController();
-
virtual ~MagnificationController() {}
+ // Creates a new MagnificationController. The caller takes ownership of the
+ // returned object.
+ static MagnificationController* CreateInstance();
+
// Sets the magnification ratio. 1.0f means no magnification.
- void SetScale(float scale);
+ virtual void SetScale(float scale, bool animate) = 0;
// Returns the current magnification ratio.
- float GetScale() const { return scale_; }
+ virtual float GetScale() const = 0;
// Set the top-left point of the magnification window.
- void MoveWindow(int x, int y);
- void MoveWindow(const gfx::Point& point);
+ virtual void MoveWindow(int x, int y, bool animate) = 0;
+ virtual void MoveWindow(const gfx::Point& point, bool animate) = 0;
// Returns the current top-left point of the magnification window.
- gfx::Point GetWindowPosition() const { return gfx::Point(x_, y_); }
+ virtual gfx::Point GetWindowPosition() const = 0;
// Ensures that the given point/rect is inside the magnification window. If
// not, the controller moves the window to contain the given point/rect.
- void EnsureShowRect(const gfx::Rect& rect);
- void EnsureShowPoint(const gfx::Point& point, bool animation);
-
- private:
- aura::RootWindow* root_window_;
-
- // Current scale, position of the magnification window.
- float scale_;
- int x_;
- int y_;
-
- // Returns the rect of the magnification window.
- gfx::Rect GetWindowRect();
- // Moves the magnification window to new scale and position. This method
- // should be called internally just after the scale and/or the position are
- // changed.
- void RedrawScreen(bool animation);
+ virtual void EnsureRectIsVisible(const gfx::Rect& rect, bool animate) = 0;
+ virtual void EnsurePointIsVisible(const gfx::Point& point, bool animate) = 0;
- DISALLOW_COPY_AND_ASSIGN(MagnificationController);
+ protected:
+ MagnificationController() {}
};
} // namespace internal
diff --git a/ash/shell.cc b/ash/shell.cc
index ecdeab0..b871421 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -418,13 +418,15 @@ void Shell::Init() {
window_modality_controller_.reset(new internal::WindowModalityController);
AddEnvEventFilter(window_modality_controller_.get());
+ magnification_controller_.reset(
+ internal::MagnificationController::CreateInstance());
+
if (internal::MonitorController::IsExtendedDesktopEnabled()) {
mouse_cursor_filter_.reset(
new internal::MouseCursorEventFilter(monitor_controller_.get()));
AddEnvEventFilter(mouse_cursor_filter_.get());
}
- magnification_controller_.reset(new internal::MagnificationController);
high_contrast_controller_.reset(new HighContrastController);
video_detector_.reset(new VideoDetector);
window_cycle_controller_.reset(new WindowCycleController);