Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: ash/display/event_transformation_handler.cc

Issue 14279002: Scale TouchEvent's radius when touchscreen is in mirror mode (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: including chromeos/display/output_configurator.h only when defined(OS_CHROMEOS) Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/display/event_transformation_handler.h ('k') | ash/shell.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
8
7 #include "ash/screen_ash.h" 9 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 10 #include "ash/shell.h"
9 #include "ash/wm/coordinate_conversion.h" 11 #include "ash/wm/coordinate_conversion.h"
10 #include "ash/wm/window_util.h" 12 #include "ash/wm/window_util.h"
11 #include "ui/aura/root_window.h" 13 #include "ui/aura/root_window.h"
12 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
13 #include "ui/base/events/event.h" 15 #include "ui/base/events/event.h"
14 #include "ui/compositor/dip_util.h" 16 #include "ui/compositor/dip_util.h"
15 #include "ui/gfx/display.h" 17 #include "ui/gfx/display.h"
16 #include "ui/gfx/screen.h" 18 #include "ui/gfx/screen.h"
17 19
20 #if defined(OS_CHROMEOS)
21 #include "chromeos/display/output_configurator.h"
22 #endif // defined(OS_CHROMEOS)
23
18 namespace ash { 24 namespace ash {
19 namespace internal { 25 namespace internal {
20 namespace { 26 namespace {
21 27
22 // Boost factor for non-integrated displays. 28 // Boost factor for non-integrated displays.
23 const float kBoostForNonIntegrated = 1.20f; 29 const float kBoostForNonIntegrated = 1.20f;
24 } 30 }
25 31
26 EventTransformationHandler::EventTransformationHandler() 32 EventTransformationHandler::EventTransformationHandler()
27 : transformation_mode_(TRANSFORM_AUTO) { 33 : transformation_mode_(TRANSFORM_AUTO) {
(...skipping 15 matching lines...) Expand all
43 // Apply some additional scaling if the display is non-integrated. 49 // Apply some additional scaling if the display is non-integrated.
44 wm::ConvertPointToScreen(target, &point_in_screen); 50 wm::ConvertPointToScreen(target, &point_in_screen);
45 const gfx::Display& display = 51 const gfx::Display& display =
46 Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen); 52 Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen);
47 if (!display.IsInternal()) 53 if (!display.IsInternal())
48 scale *= kBoostForNonIntegrated; 54 scale *= kBoostForNonIntegrated;
49 55
50 event->Scale(scale); 56 event->Scale(scale);
51 } 57 }
52 58
59 #if defined(OS_CHROMEOS)
60 // 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
62 // 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
64 // the sqrt of
65 // (mirror_width * mirror_height) / (native_width * native_height)
66 void EventTransformationHandler::OnTouchEvent(ui::TouchEvent* event) {
67 using chromeos::OutputConfigurator;
68 OutputConfigurator* output_configurator =
69 ash::Shell::GetInstance()->output_configurator();
70
71 if (output_configurator->output_state() != chromeos::STATE_DUAL_MIRROR)
72 return;
73
74 const std::map<int, float>& area_ratio_map =
75 output_configurator->GetMirroredDisplayAreaRatioMap();
76
77 // TODO(miletus): When there are more than 1 touchscreen (e.g. Link connected
78 // to an external touchscreen), the correct way to do is to have a way
79 // to find out which touchscreen is the event originating from and use the
80 // area ratio of that touchscreen to scale the event's radius.
81 // Tracked here crbug.com/233245
82 if (area_ratio_map.size() != 1) {
83 LOG(ERROR) << "Mirroring mode with " << area_ratio_map.size()
84 << " touch display found";
85 return;
86 }
87
88 float area_ratio_sqrt = std::sqrt(area_ratio_map.begin()->second);
89 event->set_radius_x(event->radius_x() * area_ratio_sqrt);
90 event->set_radius_y(event->radius_y() * area_ratio_sqrt);
91 }
92 #endif // defined(OS_CHROMEOS)
93
53 } // namespace internal 94 } // namespace internal
54 } // namespace ash 95 } // namespace ash
55
OLDNEW
« no previous file with comments | « ash/display/event_transformation_handler.h ('k') | ash/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698