| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/display/event_transformation_handler.h" | 5 #include "ash/display/event_transformation_handler.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 : transformation_mode_(TRANSFORM_AUTO) { | 33 : transformation_mode_(TRANSFORM_AUTO) { |
| 34 } | 34 } |
| 35 | 35 |
| 36 EventTransformationHandler::~EventTransformationHandler() { | 36 EventTransformationHandler::~EventTransformationHandler() { |
| 37 } | 37 } |
| 38 | 38 |
| 39 void EventTransformationHandler::OnScrollEvent(ui::ScrollEvent* event) { | 39 void EventTransformationHandler::OnScrollEvent(ui::ScrollEvent* event) { |
| 40 if (transformation_mode_ == TRANSFORM_NONE) | 40 if (transformation_mode_ == TRANSFORM_NONE) |
| 41 return; | 41 return; |
| 42 | 42 |
| 43 // Get the device scale factor and stack it on the final scale factor. | 43 // It is unnecessary to scale the event for the device scale factor since |
| 44 // the event locations etc. are already in DIP. |
| 44 gfx::Point point_in_screen(event->location()); | 45 gfx::Point point_in_screen(event->location()); |
| 45 aura::Window* target = static_cast<aura::Window*>(event->target()); | 46 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 46 const float scale_at_target = ui::GetDeviceScaleFactor(target->layer()); | |
| 47 float scale = scale_at_target; | |
| 48 | |
| 49 // Apply some additional scaling if the display is non-integrated. | |
| 50 wm::ConvertPointToScreen(target, &point_in_screen); | 47 wm::ConvertPointToScreen(target, &point_in_screen); |
| 51 const gfx::Display& display = | 48 const gfx::Display& display = |
| 52 Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen); | 49 Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen); |
| 50 |
| 51 // Apply some additional scaling if the display is non-integrated. |
| 53 if (!display.IsInternal()) | 52 if (!display.IsInternal()) |
| 54 scale *= kBoostForNonIntegrated; | 53 event->Scale(kBoostForNonIntegrated); |
| 55 | |
| 56 event->Scale(scale); | |
| 57 } | 54 } |
| 58 | 55 |
| 59 #if defined(OS_CHROMEOS) | 56 #if defined(OS_CHROMEOS) |
| 60 // This is to scale the TouchEvent's radius when the touch display is in | 57 // This is to scale the TouchEvent's radius when the touch display is in |
| 61 // mirror mode. TouchEvent's radius is often reported in the touchscreen's | 58 // mirror mode. TouchEvent's radius is often reported in the touchscreen's |
| 62 // native resolution. In mirror mode, the touch display could be configured | 59 // native resolution. In mirror mode, the touch display could be configured |
| 63 // at a lower resolution. We scale down the radius using the ratio defined as | 60 // at a lower resolution. We scale down the radius using the ratio defined as |
| 64 // the sqrt of | 61 // the sqrt of |
| 65 // (mirror_width * mirror_height) / (native_width * native_height) | 62 // (mirror_width * mirror_height) / (native_width * native_height) |
| 66 void EventTransformationHandler::OnTouchEvent(ui::TouchEvent* event) { | 63 void EventTransformationHandler::OnTouchEvent(ui::TouchEvent* event) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 89 } | 86 } |
| 90 | 87 |
| 91 float area_ratio_sqrt = std::sqrt(area_ratio_map.begin()->second); | 88 float area_ratio_sqrt = std::sqrt(area_ratio_map.begin()->second); |
| 92 event->set_radius_x(event->radius_x() * area_ratio_sqrt); | 89 event->set_radius_x(event->radius_x() * area_ratio_sqrt); |
| 93 event->set_radius_y(event->radius_y() * area_ratio_sqrt); | 90 event->set_radius_y(event->radius_y() * area_ratio_sqrt); |
| 94 } | 91 } |
| 95 #endif // defined(OS_CHROMEOS) | 92 #endif // defined(OS_CHROMEOS) |
| 96 | 93 |
| 97 } // namespace internal | 94 } // namespace internal |
| 98 } // namespace ash | 95 } // namespace ash |
| OLD | NEW |