diff options
| author | yoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-26 04:20:26 +0000 | 
|---|---|---|
| committer | yoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-26 04:20:26 +0000 | 
| commit | c1c67017189e7aebca3cf12bdf76bc781dc55281 (patch) | |
| tree | 6074cf9ea7134b18d610b11a8da0fcdedb80105b /ash | |
| parent | 8bb746373531af59d55280eda9f890cf26a0bbf0 (diff) | |
| download | chromium_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')
| -rw-r--r-- | ash/ash.gyp | 2 | ||||
| -rw-r--r-- | ash/magnifier/magnification_controller.cc | 129 | ||||
| -rw-r--r-- | ash/magnifier/magnification_controller.h | 65 | ||||
| -rw-r--r-- | ash/shell.cc | 3 | ||||
| -rw-r--r-- | ash/shell.h | 6 | 
5 files changed, 205 insertions, 0 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 3d774e4..a56b7eb 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -101,6 +101,8 @@          'launcher/launcher_view.h',          'launcher/tabbed_launcher_button.cc',          'launcher/tabbed_launcher_button.h', +        'magnifier/magnification_controller.cc', +        'magnifier/magnification_controller.h',          'monitor/monitor_controller.cc',          'monitor/monitor_controller.h',          'monitor/multi_monitor_manager.cc', 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_ diff --git a/ash/shell.cc b/ash/shell.cc index 5d80ad2..38d1112 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -15,6 +15,7 @@  #include "ash/focus_cycler.h"  #include "ash/ime/input_method_event_filter.h"  #include "ash/launcher/launcher.h" +#include "ash/magnifier/magnification_controller.h"  #include "ash/monitor/monitor_controller.h"  #include "ash/monitor/multi_monitor_manager.h"  #include "ash/screen_ash.h" @@ -566,6 +567,7 @@ Shell::~Shell() {    // Alphabetical.    activation_controller_.reset();    drag_drop_controller_.reset(); +  magnification_controller_.reset();    resize_shadow_controller_.reset();    shadow_controller_.reset();    window_cycle_controller_.reset(); @@ -709,6 +711,7 @@ void Shell::Init() {    AddRootWindowEventFilter(tooltip_controller_.get());    drag_drop_controller_.reset(new internal::DragDropController); +  magnification_controller_.reset(new internal::MagnificationController);    power_button_controller_.reset(new PowerButtonController);    AddShellObserver(power_button_controller_.get());    video_detector_.reset(new VideoDetector); diff --git a/ash/shell.h b/ash/shell.h index 74ff8fc..38fb751 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -70,6 +70,7 @@ class EventClientImpl;  class FocusCycler;  class InputMethodEventFilter;  class KeyRewriterEventFilter; +class MagnificationController;  class MonitorController;  class PanelLayoutManager;  class PartialScreenshotEventFilter; @@ -232,6 +233,10 @@ class ASH_EXPORT Shell {      return user_wallpaper_delegate_.get();    } +  internal::MagnificationController* magnification_controller() { +    return magnification_controller_.get(); +  } +    Launcher* launcher() { return launcher_.get(); }    const ScreenAsh* screen() { return screen_; } @@ -333,6 +338,7 @@ class ASH_EXPORT Shell {    scoped_ptr<internal::FocusCycler> focus_cycler_;    scoped_ptr<internal::EventClientImpl> event_client_;    scoped_ptr<internal::MonitorController> monitor_controller_; +  scoped_ptr<internal::MagnificationController> magnification_controller_;    // An event filter that rewrites or drops a key event.    scoped_ptr<internal::KeyRewriterEventFilter> key_rewriter_filter_;  | 
