Home | History | Annotate | Download | only in display
      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 <cmath>
      8 
      9 #include "ash/display/display_info.h"
     10 #include "ash/display/display_manager.h"
     11 #include "ash/shell.h"
     12 #include "ash/wm/window_util.h"
     13 #include "ui/aura/window.h"
     14 #include "ui/aura/window_event_dispatcher.h"
     15 #include "ui/compositor/dip_util.h"
     16 #include "ui/events/event.h"
     17 #include "ui/gfx/display.h"
     18 #include "ui/gfx/screen.h"
     19 #include "ui/wm/core/coordinate_conversion.h"
     20 
     21 namespace ash {
     22 namespace {
     23 
     24 // Boost factor for non-integrated displays.
     25 const float kBoostForNonIntegrated = 1.20f;
     26 
     27 }  // namespace
     28 
     29 EventTransformationHandler::EventTransformationHandler()
     30     : transformation_mode_(TRANSFORM_AUTO) {
     31 }
     32 
     33 EventTransformationHandler::~EventTransformationHandler() {
     34 }
     35 
     36 void EventTransformationHandler::OnScrollEvent(ui::ScrollEvent* event) {
     37   if (transformation_mode_ == TRANSFORM_NONE)
     38     return;
     39 
     40   // It is unnecessary to scale the event for the device scale factor since
     41   // the event locations etc. are already in DIP.
     42   gfx::Point point_in_screen(event->location());
     43   aura::Window* target = static_cast<aura::Window*>(event->target());
     44   ::wm::ConvertPointToScreen(target, &point_in_screen);
     45   const gfx::Display& display =
     46       Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen);
     47 
     48   // Apply some additional scaling if the display is non-integrated.
     49   if (!display.IsInternal())
     50     event->Scale(kBoostForNonIntegrated);
     51 }
     52 
     53 }  // namespace ash
     54