summaryrefslogtreecommitdiffstats
path: root/ash/magnifier
diff options
context:
space:
mode:
authoryoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-26 04:20:26 +0000
committeryoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-26 04:20:26 +0000
commitc1c67017189e7aebca3cf12bdf76bc781dc55281 (patch)
tree6074cf9ea7134b18d610b11a8da0fcdedb80105b /ash/magnifier
parent8bb746373531af59d55280eda9f890cf26a0bbf0 (diff)
downloadchromium_src-c1c67017189e7aebca3cf12bdf76bc781dc55281.zip
chromium_src-c1c67017189e7aebca3cf12bdf76bc781dc55281.tar.gz
chromium_src-c1c67017189e7aebca3cf12bdf76bc781dc55281.tar.bz2
Implements the graphics layer of the screen magnifier.
This patch contains only the graphics layer. The control layer will be on another patch. BUG=chromium-os:26713 TEST=manual Review URL: http://codereview.chromium.org/9950082 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134066 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/magnifier')
-rw-r--r--ash/magnifier/magnification_controller.cc129
-rw-r--r--ash/magnifier/magnification_controller.h65
2 files changed, 194 insertions, 0 deletions
diff --git a/ash/magnifier/magnification_controller.cc b/ash/magnifier/magnification_controller.cc
new file mode 100644
index 0000000..262a9c4
--- /dev/null
+++ b/ash/magnifier/magnification_controller.cc
@@ -0,0 +1,129 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/magnifier/magnification_controller.h"
+
+#include "ash/shell.h"
+#include "ui/aura/root_window.h"
+#include "ui/aura/window.h"
+#include "ui/aura/window_property.h"
+#include "ui/gfx/compositor/layer.h"
+#include "ui/gfx/compositor/scoped_layer_animation_settings.h"
+
+namespace {
+
+const float kMaximumMagnifiScale = 4.0f;
+const float kMaximumMagnifiScaleThreshold = 4.0f;
+const float kMinimumMagnifiScale = 1.0f;
+const float kMinimumMagnifiScaleThreshold = 1.1f;
+
+} // namespace
+
+namespace ash {
+namespace internal {
+
+MagnificationController::MagnificationController()
+ : scale_(1.0f), x_(0), y_(0) {
+ root_window_ = ash::Shell::GetRootWindow();
+}
+
+void MagnificationController::SetScale(float scale) {
+ scale_ = scale;
+ RedrawScreen(true);
+}
+
+void MagnificationController::MoveWindow(int x, int y) {
+ y_ = y;
+ x_ = x;
+ RedrawScreen(true);
+}
+
+void MagnificationController::MoveWindow(const gfx::Point& point) {
+ MoveWindow(point.x(), point.y());
+}
+
+void MagnificationController::EnsureShowRect(const gfx::Rect& target_rect) {
+ gfx::Rect rect = GetWindowRect().AdjustToFit(target_rect);
+ MoveWindow(rect.x(), rect.y());
+}
+
+void MagnificationController::EnsureShowPoint(const gfx::Point& point,
+ bool animation) {
+ gfx::Rect rect = GetWindowRect();
+
+ if (rect.Contains(point))
+ return;
+
+ if (point.x() < rect.x())
+ x_ = point.x();
+ else if(rect.right() < point.x())
+ x_ = point.x() - rect.width();
+
+ if (point.y() < rect.y())
+ y_ = point.y();
+ else if(rect.bottom() < point.y())
+ y_ = point.y() - rect.height();
+
+ RedrawScreen(animation);
+}
+
+void MagnificationController::RedrawScreen(bool animation) {
+
+ // Adjust the scale to just |kMinimumMagnifiScale| if scale is smaller than
+ // |kMinimumMagnifiScaleThreshold|;
+ if (scale_ < kMinimumMagnifiScaleThreshold)
+ scale_ = kMinimumMagnifiScale;
+ // Adjust the scale to just |kMinimumMagnifiScale| if scale is bigger than
+ // |kMinimumMagnifiScaleThreshold|;
+ if (scale_ > kMaximumMagnifiScaleThreshold)
+ scale_ = kMaximumMagnifiScale;
+
+ if (x_ < 0)
+ x_ = 0;
+ if (y_ < 0)
+ y_ = 0;
+
+ 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;
+
+
+ float scale = scale_;
+ int x = x_;
+ int y = y_;
+
+ // 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));
+ }
+
+ root_window_->layer()->SetTransform(transform);
+}
+
+gfx::Rect MagnificationController::GetWindowRect() {
+ gfx::Size size = root_window_->GetHostSize();
+ int width = size.width() / scale_;
+ int height = size.height() / scale_;
+
+ return gfx::Rect(x_, y_, width, height);
+}
+
+} // namespace internal
+} // namespace ash
diff --git a/ash/magnifier/magnification_controller.h b/ash/magnifier/magnification_controller.h
new file mode 100644
index 0000000..fe50168
--- /dev/null
+++ b/ash/magnifier/magnification_controller.h
@@ -0,0 +1,65 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_MAGNIFIER_MAGNIFICATION_CONTROLLER_H_
+#define ASH_MAGNIFIER_MAGNIFICATION_CONTROLLER_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
+
+namespace aura {
+class RootWindow;
+}
+
+namespace ash {
+namespace internal {
+
+class MagnificationController {
+ public:
+ MagnificationController();
+
+ virtual ~MagnificationController() {}
+
+ // Sets the magnification ratio. 1.0f means no magnification.
+ void SetScale(float scale);
+ // Returns the current magnification ratio.
+ float GetScale() const { return scale_; }
+
+ // Set the top-left point of the magnification window.
+ void MoveWindow(int x, int y);
+ void MoveWindow(const gfx::Point& point);
+ // Returns the current top-left point of the magnification window.
+ gfx::Point GetWindowPosition() const { return gfx::Point(x_, y_); }
+
+ // 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);
+
+ DISALLOW_COPY_AND_ASSIGN(MagnificationController);
+};
+
+} // namespace internal
+} // namespace ash
+
+#endif // ASH_MAGNIFIER_MAGNIFICATION_CONTROLLER_H_