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

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

Issue 23452037: Do not scale ScrollEvent by device scale factor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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> 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
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 // The original purpose of this function is to scale scroll events
44 // w.r.t. the screen resolution and physical size as what we do for
45 // pointer motions in the CrOS X server patch (i.e. linear scaling
46 // w.r.t. the device scale factor and 20% more for non-integrated
47 // display). However, Aura scroll events differs from X's pointer
48 // motions in an important way where the consumers of scroll events
49 // assume the use of DIP instead of real pixels. Scaling them by the
50 // device scale factor would result in over-scaling and make high
51 // resolution device (e.g. Pixel) to have faster scrolling speed than
52 // normal ones.
53 //
54 // Our solution here is to NOT scale events by the device scale factor
55 // and instead let the scroll event to enjoy the "implicit" scaling
56 // due to the use of DIP (e.g. treating the scroll values as DIPs
57 // implies an implicit scaling factor of 2 in terms of physical
58 // distance on the Pixel screen). All the Views that consume these
59 // events would also behave identically both on Pixel and non-Pixel
60 // devices as they take the values as DIPs (e.g. 2f back/forward
61 // gesture and 3f tab switching would have equal sensitivity).
sadrul 2013/09/18 15:36:41 Does 'It is not necessary to scale the event for t
oshima 2013/09/18 16:26:10 Agreed.
Shecky Lin 2013/09/20 04:44:10 Done.
44 gfx::Point point_in_screen(event->location()); 62 gfx::Point point_in_screen(event->location());
45 aura::Window* target = static_cast<aura::Window*>(event->target()); 63 aura::Window* target = static_cast<aura::Window*>(event->target());
46 const float scale_at_target = ui::GetDeviceScaleFactor(target->layer()); 64 float scale = 1.0;
47 float scale = scale_at_target;
48 65
49 // Apply some additional scaling if the display is non-integrated. 66 // Apply some additional scaling if the display is non-integrated.
50 wm::ConvertPointToScreen(target, &point_in_screen); 67 wm::ConvertPointToScreen(target, &point_in_screen);
51 const gfx::Display& display = 68 const gfx::Display& display =
52 Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen); 69 Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen);
53 if (!display.IsInternal()) 70 if (!display.IsInternal())
54 scale *= kBoostForNonIntegrated; 71 scale *= kBoostForNonIntegrated;
oshima 2013/09/18 16:26:10 if (display.Internal()) event->Scale(kBoostForN
Shecky Lin 2013/09/20 04:44:10 Done.
55 72
56 event->Scale(scale); 73 event->Scale(scale);
57 } 74 }
58 75
59 #if defined(OS_CHROMEOS) 76 #if defined(OS_CHROMEOS)
60 // This is to scale the TouchEvent's radius when the touch display is in 77 // 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 78 // mirror mode. TouchEvent's radius is often reported in the touchscreen's
62 // native resolution. In mirror mode, the touch display could be configured 79 // 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 80 // at a lower resolution. We scale down the radius using the ratio defined as
64 // the sqrt of 81 // the sqrt of
(...skipping 24 matching lines...) Expand all
89 } 106 }
90 107
91 float area_ratio_sqrt = std::sqrt(area_ratio_map.begin()->second); 108 float area_ratio_sqrt = std::sqrt(area_ratio_map.begin()->second);
92 event->set_radius_x(event->radius_x() * area_ratio_sqrt); 109 event->set_radius_x(event->radius_x() * area_ratio_sqrt);
93 event->set_radius_y(event->radius_y() * area_ratio_sqrt); 110 event->set_radius_y(event->radius_y() * area_ratio_sqrt);
94 } 111 }
95 #endif // defined(OS_CHROMEOS) 112 #endif // defined(OS_CHROMEOS)
96 113
97 } // namespace internal 114 } // namespace internal
98 } // namespace ash 115 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698