1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef ASH_TOUCH_TOUCH_TRANSFORMER_CONTROLLER_H_
6 #define ASH_TOUCH_TOUCH_TRANSFORMER_CONTROLLER_H_
8 #include "ash/ash_export.h"
9 #include "ash/display/display_controller.h"
10 #include "ui/gfx/transform.h"
13 struct TouchscreenDevice
;
18 // TouchTransformerController listens to display configuration change
19 // and updates the touch transformation for touch displays.
20 class ASH_EXPORT TouchTransformerController
21 : public DisplayController::Observer
{
23 TouchTransformerController();
24 ~TouchTransformerController() override
;
26 // Updates the TouchTransformer for touch device and pushes the new
27 // TouchTransformer into device manager.
28 void UpdateTouchTransformer() const;
30 // DisplayController::Observer:
31 void OnDisplaysInitialized() override
;
32 void OnDisplayConfigurationChanged() override
;
35 FRIEND_TEST_ALL_PREFIXES(TouchTransformerControllerTest
,
36 MirrorModeLetterboxing
);
37 FRIEND_TEST_ALL_PREFIXES(TouchTransformerControllerTest
,
38 MirrorModePillarboxing
);
39 FRIEND_TEST_ALL_PREFIXES(TouchTransformerControllerTest
, SoftwareMirrorMode
);
40 FRIEND_TEST_ALL_PREFIXES(TouchTransformerControllerTest
, ExtendedMode
);
41 FRIEND_TEST_ALL_PREFIXES(TouchTransformerControllerTest
, TouchRadiusScale
);
43 // Returns a transform that will be used to change an event's location from
44 // the touchscreen's coordinate system into |display|'s coordinate system.
45 // The transform is also responsible for properly scaling the display if the
46 // display supports panel fitting.
48 // On X11 events are reported in framebuffer coordinate space, so the
49 // |framebuffer_size| is used for scaling.
50 // On Ozone events are reported in the touchscreen's resolution, so
51 // |touch_display| is used to determine the size and scale the event.
52 gfx::Transform
GetTouchTransform(const DisplayInfo
& display
,
53 const DisplayInfo
& touch_display
,
54 const ui::TouchscreenDevice
& touchscreen
,
55 const gfx::Size
& framebuffer_size
) const;
57 // Returns the scaling factor for the touch radius such that it scales the
58 // radius from |touch_device|'s coordinate system to the |touch_display|'s
60 double GetTouchResolutionScale(
61 const DisplayInfo
& touch_display
,
62 const ui::TouchscreenDevice
& touch_device
) const;
64 // For the provided |display| update the touch radius mapping.
65 void UpdateTouchRadius(const DisplayInfo
& display
) const;
67 // For a given |target_display| and |target_display_id| update the touch
68 // transformation based on the touchscreen associated with |touch_display|.
69 // |target_display_id| is the display id whose root window will receive the
71 // |touch_display| is the physical display that has the touchscreen
72 // from which the events arrive.
73 // |target_display| provides the dimensions to which the touch event will be
75 void UpdateTouchTransform(int64_t target_display_id
,
76 const DisplayInfo
& touch_display
,
77 const DisplayInfo
& target_display
) const;
79 DISALLOW_COPY_AND_ASSIGN(TouchTransformerController
);
84 #endif // ASH_TOUCH_TOUCH_TRANSFORMER_CONTROLLER_H_