event_transformation_handler.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ash/display/event_transformation_handler.h"
6
7#include "ash/screen_ash.h"
8#include "ash/shell.h"
9#include "ash/wm/coordinate_conversion.h"
10#include "ash/wm/window_util.h"
11#include "ui/aura/root_window.h"
12#include "ui/aura/window.h"
13#include "ui/base/events/event.h"
14#include "ui/compositor/dip_util.h"
15#include "ui/gfx/display.h"
16#include "ui/gfx/screen.h"
17
18namespace ash {
19namespace internal {
20namespace {
21
22// Boost factor for non-integrated displays.
23const float kBoostForNonIntegrated = 1.20f;
24}
25
26EventTransformationHandler::EventTransformationHandler()
27    : transformation_mode_(TRANSFORM_AUTO) {
28}
29
30EventTransformationHandler::~EventTransformationHandler() {
31}
32
33void EventTransformationHandler::OnScrollEvent(ui::ScrollEvent* event) {
34  if (transformation_mode_ == TRANSFORM_NONE)
35    return;
36
37  // Get the device scale factor and stack it on the final scale factor.
38  gfx::Point point_in_screen(event->location());
39  aura::Window* target = static_cast<aura::Window*>(event->target());
40  const float scale_at_target = ui::GetDeviceScaleFactor(target->layer());
41  float scale = scale_at_target;
42
43  // Apply some additional scaling if the display is non-integrated.
44  wm::ConvertPointToScreen(target, &point_in_screen);
45  const gfx::Display& display =
46      Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen);
47  if (!display.IsInternal())
48    scale *= kBoostForNonIntegrated;
49
50  event->Scale(scale);
51}
52
53}  // namespace internal
54}  // namespace ash
55
56