summaryrefslogtreecommitdiffstats
path: root/ash/display/event_transformation_handler.cc
diff options
context:
space:
mode:
authormiletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-19 03:39:34 +0000
committermiletus@chromium.org <miletus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-19 03:39:34 +0000
commita1c0601dc65636bb6dca44dceef36b8823791fa0 (patch)
tree1e9b0febb49f34390a294762307253afd98cfe30 /ash/display/event_transformation_handler.cc
parent69cdc4e9c6f58514a6088dbf307be9f66341a5bf (diff)
downloadchromium_src-a1c0601dc65636bb6dca44dceef36b8823791fa0.zip
chromium_src-a1c0601dc65636bb6dca44dceef36b8823791fa0.tar.gz
chromium_src-a1c0601dc65636bb6dca44dceef36b8823791fa0.tar.bz2
Scale TouchEvent's radius when touchscreen is in mirror mode
TouchEvent's radius on Pixel is reported in the touchscreen's native resolution. When Pixel is connected to an external screen and running in mirror mode, the radius value is too large for the external screen's low display resolution. The radius value needs to be scaled properly in this case. BUG=229932 TEST=Switching to mirror mode when connecting Pixel to a low resolution external display, following the test in the issue and make sure the radius has a sensible value. Review URL: https://chromiumcodereview.appspot.com/14279002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195075 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/display/event_transformation_handler.cc')
-rw-r--r--ash/display/event_transformation_handler.cc42
1 files changed, 41 insertions, 1 deletions
diff --git a/ash/display/event_transformation_handler.cc b/ash/display/event_transformation_handler.cc
index 7ecc634..52cb647 100644
--- a/ash/display/event_transformation_handler.cc
+++ b/ash/display/event_transformation_handler.cc
@@ -4,6 +4,8 @@
#include "ash/display/event_transformation_handler.h"
+#include <cmath>
+
#include "ash/screen_ash.h"
#include "ash/shell.h"
#include "ash/wm/coordinate_conversion.h"
@@ -15,6 +17,10 @@
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
+#if defined(OS_CHROMEOS)
+#include "chromeos/display/output_configurator.h"
+#endif // defined(OS_CHROMEOS)
+
namespace ash {
namespace internal {
namespace {
@@ -50,6 +56,40 @@ void EventTransformationHandler::OnScrollEvent(ui::ScrollEvent* event) {
event->Scale(scale);
}
+#if defined(OS_CHROMEOS)
+// This is to scale the TouchEvent's radius when the touch display is in
+// mirror mode. TouchEvent's radius is often reported in the touchscreen's
+// native resolution. In mirror mode, the touch display could be configured
+// at a lower resolution. We scale down the radius using the ratio defined as
+// the sqrt of
+// (mirror_width * mirror_height) / (native_width * native_height)
+void EventTransformationHandler::OnTouchEvent(ui::TouchEvent* event) {
+ using chromeos::OutputConfigurator;
+ OutputConfigurator* output_configurator =
+ ash::Shell::GetInstance()->output_configurator();
+
+ if (output_configurator->output_state() != chromeos::STATE_DUAL_MIRROR)
+ return;
+
+ const std::map<int, float>& area_ratio_map =
+ output_configurator->GetMirroredDisplayAreaRatioMap();
+
+ // TODO(miletus): When there are more than 1 touchscreen (e.g. Link connected
+ // to an external touchscreen), the correct way to do is to have a way
+ // to find out which touchscreen is the event originating from and use the
+ // area ratio of that touchscreen to scale the event's radius.
+ // Tracked here crbug.com/233245
+ if (area_ratio_map.size() != 1) {
+ LOG(ERROR) << "Mirroring mode with " << area_ratio_map.size()
+ << " touch display found";
+ return;
+ }
+
+ float area_ratio_sqrt = std::sqrt(area_ratio_map.begin()->second);
+ event->set_radius_x(event->radius_x() * area_ratio_sqrt);
+ event->set_radius_y(event->radius_y() * area_ratio_sqrt);
+}
+#endif // defined(OS_CHROMEOS)
+
} // namespace internal
} // namespace ash
-