forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcast_touch_device_manager.cc
80 lines (64 loc) · 2.7 KB
/
cast_touch_device_manager.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromecast/browser/cast_touch_device_manager.h"
#include "chromecast/graphics/cast_screen.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/devices/touchscreen_device.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/size_f.h"
namespace chromecast {
namespace shell {
namespace {
ui::TouchDeviceTransform GetDeviceTransform(
const ui::TouchscreenDevice& touchscreen,
int64_t display_id,
display::Display::Rotation rotation,
const gfx::Rect& native_bounds_in_pixel) {
gfx::SizeF touchscreen_size = gfx::SizeF(touchscreen.size);
ui::TouchDeviceTransform touch_device_transform;
touch_device_transform.display_id = display_id;
touch_device_transform.device_id = touchscreen.id;
touch_device_transform.transform.Translate(native_bounds_in_pixel.x(),
native_bounds_in_pixel.y());
touch_device_transform.transform.Scale(
native_bounds_in_pixel.width() / touchscreen_size.width(),
native_bounds_in_pixel.height() / touchscreen_size.height());
return touch_device_transform;
}
} // namespace
CastTouchDeviceManager::CastTouchDeviceManager() {
ui::DeviceDataManager::GetInstance()->AddObserver(this);
}
CastTouchDeviceManager::~CastTouchDeviceManager() {
ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
}
void CastTouchDeviceManager::OnTouchscreenDeviceConfigurationChanged() {
UpdateTouchscreenConfiguration();
}
void CastTouchDeviceManager::OnDisplayConfigured(
int64_t display_id,
display::Display::Rotation rotation,
const gfx::Rect& native_bounds_in_pixel) {
display_id_ = display_id;
display_rotation_ = rotation;
native_display_bounds_in_pixel_ = native_bounds_in_pixel;
UpdateTouchscreenConfiguration();
}
void CastTouchDeviceManager::UpdateTouchscreenConfiguration() {
const std::vector<ui::TouchscreenDevice>& touchscreen_devices =
ui::DeviceDataManager::GetInstance()->GetTouchscreenDevices();
if (native_display_bounds_in_pixel_ == gfx::Rect())
return; // Waiting for display configuration.
std::vector<ui::TouchDeviceTransform> touch_device_transforms;
// All touchscreens are mapped onto primary display.
for (const auto& touchscreen : touchscreen_devices) {
touch_device_transforms.push_back(
GetDeviceTransform(touchscreen, display_id_, display_rotation_,
native_display_bounds_in_pixel_));
}
ui::DeviceDataManager::GetInstance()->ConfigureTouchDevices(
touch_device_transforms);
}
} // namespace shell
} // namespace chromecast