diff options
author | sheckylin@chromium.org <sheckylin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-10 06:49:11 +0000 |
---|---|---|
committer | sheckylin@chromium.org <sheckylin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-10 06:49:11 +0000 |
commit | 682990f75f1a8684d42be83129b6ca30caa9eca2 (patch) | |
tree | 61e62372ac7bb6fe03ee700739dba376c1dab424 /ash/display | |
parent | 002de2f6f5aa1287b779c178f39dd112861b9c69 (diff) | |
download | chromium_src-682990f75f1a8684d42be83129b6ca30caa9eca2.zip chromium_src-682990f75f1a8684d42be83129b6ca30caa9eca2.tar.gz chromium_src-682990f75f1a8684d42be83129b6ca30caa9eca2.tar.bz2 |
Scaling scroll/fling events in multi-monitor setup
The CL adds an event filter that transforms input event properties
in the extended desktop environment. It currently scales scroll/fling
events' offset values based on the following logic:
1. Linear scaling w.r.t. the device scale factor, which is 2x for
highDPI displays.
2. 1.2x scaling for external displays, since they are usually larger
than internal ones.
Both scalings can stack on each other, i.e. you can get as high as
a 2.4x boost if you have a high DPI external display.
Contributed by sheckylin@chromium.org
BUG=chromium:166392
TEST=Tested on link w/o external display.
Change-Id: Ie29e03fcf9f6e5ae1dd6231990103237c3129fd6
Review URL: https://chromiumcodereview.appspot.com/11743013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176038 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/display')
-rw-r--r-- | ash/display/event_transformation_handler.cc | 57 | ||||
-rw-r--r-- | ash/display/event_transformation_handler.h | 47 |
2 files changed, 104 insertions, 0 deletions
diff --git a/ash/display/event_transformation_handler.cc b/ash/display/event_transformation_handler.cc new file mode 100644 index 0000000..380399d --- /dev/null +++ b/ash/display/event_transformation_handler.cc @@ -0,0 +1,57 @@ +// Copyright (c) 2013 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/display/event_transformation_handler.h" + +#include "ash/display/display_manager.h" +#include "ash/screen_ash.h" +#include "ash/shell.h" +#include "ash/wm/coordinate_conversion.h" +#include "ash/wm/window_util.h" +#include "ui/aura/root_window.h" +#include "ui/aura/window.h" +#include "ui/base/events/event.h" +#include "ui/compositor/dip_util.h" +#include "ui/gfx/display.h" +#include "ui/gfx/screen.h" + +namespace ash { +namespace internal { +namespace { + +// Boost factor for non-integrated displays. +const float kBoostForNonIntegrated = 1.20f; +} + +EventTransformationHandler::EventTransformationHandler() + : transformation_mode_(TRANSFORM_AUTO) { +} + +EventTransformationHandler::~EventTransformationHandler() { +} + +void EventTransformationHandler::OnScrollEvent(ui::ScrollEvent* event) { + if (transformation_mode_ == TRANSFORM_NONE) + return; + + // Get the device scale factor and stack it on the final scale factor. + gfx::Point point_in_screen(event->location()); + aura::Window* target = static_cast<aura::Window*>(event->target()); + const float scale_at_target = ui::GetDeviceScaleFactor(target->layer()); + float scale = scale_at_target; + + // Apply some additional scaling if the display is non-integrated. + wm::ConvertPointToScreen(target, &point_in_screen); + const gfx::Display& display = + Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen); + DisplayManager* display_manager = Shell::GetInstance()->display_manager(); + if (!display_manager->IsInternalDisplayId(display.id())) + scale *= kBoostForNonIntegrated; + + event->Scale(scale); +} + +} // namespace internal +} // namespace ash + diff --git a/ash/display/event_transformation_handler.h b/ash/display/event_transformation_handler.h new file mode 100644 index 0000000..9cf0add --- /dev/null +++ b/ash/display/event_transformation_handler.h @@ -0,0 +1,47 @@ +// Copyright (c) 2013 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_DISPLAY_EVENT_TRANSFORMATION_HANDLER_H_ +#define ASH_DISPLAY_EVENT_TRANSFORMATION_HANDLER_H_ + +#include "ash/ash_export.h" +#include "base/compiler_specific.h" +#include "ui/base/events/event_handler.h" + +namespace ash { + +namespace internal { + +// An event filter that transforms input event properties in extended desktop +// environment. It currently handles only ScrollEvents. +class ASH_EXPORT EventTransformationHandler : public ui::EventHandler { + public: + enum TransformationMode { + TRANSFORM_AUTO, // Transform events by the default amount. + // 1. Linear scaling w.r.t. the device scale factor. + // 2. Add 20% more for non-integrated displays. + TRANSFORM_NONE, // No transformation. + }; + + EventTransformationHandler(); + virtual ~EventTransformationHandler(); + + void set_transformation_mode(TransformationMode transformation_mode) { + transformation_mode_ = transformation_mode; + } + + // Overridden from ui::EventHandler. + virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; + + private: + TransformationMode transformation_mode_; + + DISALLOW_COPY_AND_ASSIGN(EventTransformationHandler); +}; + +} // namespace internal +} // namespace ash + +#endif // ASH_DISPLAY_EVENT_TRANSFORMATION_HANDLER_H_ + |