event_transformation_handler.cc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #include "ash/display/event_transformation_handler.h"
  5. #include <cmath>
  6. #include "ui/aura/window.h"
  7. #include "ui/aura/window_event_dispatcher.h"
  8. #include "ui/display/display.h"
  9. #include "ui/display/screen.h"
  10. #include "ui/events/event.h"
  11. #include "ui/wm/core/coordinate_conversion.h"
  12. namespace ash {
  13. namespace {
  14. // Boost factor for non-integrated displays.
  15. const float kBoostForNonIntegrated = 1.20f;
  16. } // namespace
  17. EventTransformationHandler::EventTransformationHandler()
  18. : transformation_mode_(TRANSFORM_AUTO) {}
  19. EventTransformationHandler::~EventTransformationHandler() = default;
  20. void EventTransformationHandler::OnScrollEvent(ui::ScrollEvent* event) {
  21. if (transformation_mode_ == TRANSFORM_NONE)
  22. return;
  23. // It is unnecessary to scale the event for the device scale factor since
  24. // the event locations etc. are already in DIP.
  25. gfx::Point point_in_screen(event->location());
  26. aura::Window* target = static_cast<aura::Window*>(event->target());
  27. ::wm::ConvertPointToScreen(target, &point_in_screen);
  28. const display::Display& display =
  29. display::Screen::GetScreen()->GetDisplayNearestPoint(point_in_screen);
  30. // Apply some additional scaling if the display is non-integrated.
  31. if (!display.IsInternal())
  32. event->Scale(kBoostForNonIntegrated);
  33. }
  34. } // namespace ash