| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/ws/touch_controller.h" | 5 #include "services/ui/ws/touch_controller.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "services/ui/ws/display.h" | 11 #include "services/ui/ws/display.h" |
| 12 #include "services/ui/ws/display_manager.h" | 12 #include "services/ui/ws/display_manager.h" |
| 13 #include "ui/events/devices/device_data_manager.h" | 13 #include "ui/events/devices/device_data_manager.h" |
| 14 #include "ui/events/devices/touchscreen_device.h" | 14 #include "ui/events/devices/touchscreen_device.h" |
| 15 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 16 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 namespace ws { | 19 namespace ws { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Computes the scale ratio for the TouchEvent's radius. | 23 // Computes the scale ratio for the TouchEvent's radius. |
| 24 double ComputeTouchResolutionScale(const Display* touch_display, | 24 double ComputeTouchResolutionScale(const Display* touch_display, |
| 25 const ui::TouchscreenDevice& touch_device) { | 25 const ui::TouchscreenDevice& touch_device) { |
| 26 gfx::Size touch_display_size = touch_display->GetSize(); | 26 gfx::Size touch_display_size = touch_display->GetPixelSize(); |
| 27 | 27 |
| 28 if (touch_device.size.IsEmpty() || touch_display_size.IsEmpty()) | 28 if (touch_device.size.IsEmpty() || touch_display_size.IsEmpty()) |
| 29 return 1.0; | 29 return 1.0; |
| 30 | 30 |
| 31 double display_area = touch_display_size.GetArea(); | 31 double display_area = touch_display_size.GetArea(); |
| 32 double touch_area = touch_device.size.GetArea(); | 32 double touch_area = touch_device.size.GetArea(); |
| 33 double ratio = std::sqrt(display_area / touch_area); | 33 double ratio = std::sqrt(display_area / touch_area); |
| 34 | 34 |
| 35 return ratio; | 35 return ratio; |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Computes a touch transform that maps from window bounds to touchscreen size. | 38 // Computes a touch transform that maps from window bounds to touchscreen size. |
| 39 // Assumes scale factor of 1.0. | 39 // Assumes scale factor of 1.0. |
| 40 gfx::Transform ComputeTouchTransform( | 40 gfx::Transform ComputeTouchTransform( |
| 41 const Display* touch_display, | 41 const Display* touch_display, |
| 42 const ui::TouchscreenDevice& touch_device) { | 42 const ui::TouchscreenDevice& touch_device) { |
| 43 gfx::Size touch_display_size = touch_display->GetSize(); | 43 gfx::Size touch_display_size = touch_display->GetPixelSize(); |
| 44 | 44 |
| 45 gfx::SizeF current_size(touch_display_size); | 45 gfx::SizeF current_size(touch_display_size); |
| 46 gfx::SizeF touch_area(touch_device.size); | 46 gfx::SizeF touch_area(touch_device.size); |
| 47 gfx::Transform transform; | 47 gfx::Transform transform; |
| 48 | 48 |
| 49 if (current_size.IsEmpty() || touch_area.IsEmpty()) | 49 if (current_size.IsEmpty() || touch_area.IsEmpty()) |
| 50 return transform; | 50 return transform; |
| 51 | 51 |
| 52 // Take care of scaling between touchscreen area and display resolution. | 52 // Take care of scaling between touchscreen area and display resolution. |
| 53 transform.Scale(current_size.width() / touch_area.width(), | 53 transform.Scale(current_size.width() / touch_area.width(), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 void TouchController::OnTouchscreenDeviceConfigurationChanged() { | 100 void TouchController::OnTouchscreenDeviceConfigurationChanged() { |
| 101 UpdateTouchTransforms(); | 101 UpdateTouchTransforms(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace ws | 104 } // namespace ws |
| 105 } // namespace ui | 105 } // namespace ui |
| OLD | NEW |