OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_cont roller.h" | 5 #include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_cont roller.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/touch/ash_touch_transform_controller.h" | |
8 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
9 #include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view .h" | 10 #include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view .h" |
10 #include "ui/display/screen.h" | 11 #include "ui/display/screen.h" |
11 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
12 #include "ui/events/event_constants.h" | 13 #include "ui/events/event_constants.h" |
13 | 14 |
14 namespace chromeos { | 15 namespace chromeos { |
15 | 16 |
16 // Time interval after a touch event during which all other touch events are | 17 // Time interval after a touch event during which all other touch events are |
17 // ignored during calibration. | 18 // ignored during calibration. |
(...skipping 27 matching lines...) Expand all Loading... | |
45 | 46 |
46 std::vector<display::Display> displays = | 47 std::vector<display::Display> displays = |
47 display::Screen::GetScreen()->GetAllDisplays(); | 48 display::Screen::GetScreen()->GetAllDisplays(); |
48 | 49 |
49 for (const display::Display& display : displays) { | 50 for (const display::Display& display : displays) { |
50 bool is_primary_view = display.id() == target_display_.id(); | 51 bool is_primary_view = display.id() == target_display_.id(); |
51 touch_calibrator_views_[display.id()] = | 52 touch_calibrator_views_[display.id()] = |
52 base::MakeUnique<TouchCalibratorView>(display, is_primary_view); | 53 base::MakeUnique<TouchCalibratorView>(display, is_primary_view); |
53 } | 54 } |
54 | 55 |
55 // TODO(malaykeshav): Call TouchTransformController::SetForCalibration() | 56 // TODO(malaykeshav): Call TouchTransformController::SetForCalibration() |
oshima
2017/01/18 01:57:16
nit: remove the comment?
malaykeshav
2017/01/18 02:08:38
Done
| |
57 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration( | |
58 true); | |
56 | 59 |
57 // Add self as an event handler target. | 60 // Add self as an event handler target. |
58 ash::Shell::GetInstance()->AddPreTargetHandler(this); | 61 ash::Shell::GetInstance()->AddPreTargetHandler(this); |
59 } | 62 } |
60 | 63 |
61 void TouchCalibratorController::StopCalibration() { | 64 void TouchCalibratorController::StopCalibration() { |
62 if (!is_calibrating_) | 65 if (!is_calibrating_) |
63 return; | 66 return; |
64 is_calibrating_ = false; | 67 is_calibrating_ = false; |
65 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); | 68 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); |
66 | 69 |
67 // TODO(malaykeshav): Call TouchTransformController::SetForCalibration() | 70 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration( |
71 false); | |
68 | 72 |
69 // Remove self as the event handler. | 73 // Remove self as the event handler. |
70 ash::Shell::GetInstance()->RemovePreTargetHandler(this); | 74 ash::Shell::GetInstance()->RemovePreTargetHandler(this); |
71 | 75 |
72 // Transition all touch calibrator views to their final state for a graceful | 76 // Transition all touch calibrator views to their final state for a graceful |
73 // exit. | 77 // exit. |
74 for (const auto& it : touch_calibrator_views_) | 78 for (const auto& it : touch_calibrator_views_) |
75 it.second->SkipToFinalState(); | 79 it.second->SkipToFinalState(); |
76 } | 80 } |
77 | 81 |
78 // ui::EventHandler: | 82 // ui::EventHandler: |
79 void TouchCalibratorController::OnKeyEvent(ui::KeyEvent* key) { | 83 void TouchCalibratorController::OnKeyEvent(ui::KeyEvent* key) { |
80 if (!is_calibrating_) | 84 if (!is_calibrating_) |
81 return; | 85 return; |
82 // Detect ESC key press. | 86 // Detect ESC key press. |
83 if (key->type() == ui::ET_KEY_PRESSED && key->key_code() == ui::VKEY_ESCAPE) | 87 if (key->type() == ui::ET_KEY_PRESSED && key->key_code() == ui::VKEY_ESCAPE) |
84 StopCalibration(); | 88 StopCalibration(); |
85 key->StopPropagation(); | 89 key->StopPropagation(); |
86 } | 90 } |
87 | 91 |
88 void TouchCalibratorController::OnTouchEvent(ui::TouchEvent* touch) { | 92 void TouchCalibratorController::OnTouchEvent(ui::TouchEvent* touch) { |
89 if (!is_calibrating_) | 93 if (!is_calibrating_) |
90 return; | 94 return; |
91 if (touch->type() != ui::ET_TOUCH_RELEASED) | 95 if (touch->type() != ui::ET_TOUCH_RELEASED) |
92 return; | 96 return; |
93 if (base::Time::Now() - last_touch_timestamp_ < kTouchIntervalThreshold) | 97 if (base::Time::Now() - last_touch_timestamp_ < kTouchIntervalThreshold) |
94 return; | 98 return; |
95 | |
96 last_touch_timestamp_ = base::Time::Now(); | 99 last_touch_timestamp_ = base::Time::Now(); |
97 | 100 |
98 TouchCalibratorView* target_screen_calibration_view = | 101 TouchCalibratorView* target_screen_calibration_view = |
99 touch_calibrator_views_[target_display_.id()].get(); | 102 touch_calibrator_views_[target_display_.id()].get(); |
100 | 103 |
104 // If this is the final state, then store all calibration data and stop | |
105 // calibration. | |
106 if (target_screen_calibration_view->state() == | |
107 TouchCalibratorView::CALIBRATION_COMPLETE) { | |
108 StopCalibration(); | |
109 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData( | |
110 target_display_.id(), touch_point_quad_, | |
111 target_screen_calibration_view->size()); | |
112 return; | |
113 } | |
114 | |
101 int state_index; | 115 int state_index; |
102 // Maps the state to an integer value. Assigns a non negative integral value | 116 // Maps the state to an integer value. Assigns a non negative integral value |
103 // for a state in which the user can interact with the the interface. | 117 // for a state in which the user can interact with the the interface. |
104 switch (target_screen_calibration_view->state()) { | 118 switch (target_screen_calibration_view->state()) { |
105 case TouchCalibratorView::DISPLAY_POINT_1: | 119 case TouchCalibratorView::DISPLAY_POINT_1: |
106 state_index = 0; | 120 state_index = 0; |
107 break; | 121 break; |
108 case TouchCalibratorView::DISPLAY_POINT_2: | 122 case TouchCalibratorView::DISPLAY_POINT_2: |
109 state_index = 1; | 123 state_index = 1; |
110 break; | 124 break; |
(...skipping 13 matching lines...) Expand all Loading... | |
124 gfx::Point display_point; | 138 gfx::Point display_point; |
125 if (target_screen_calibration_view->GetDisplayPointLocation(&display_point)) { | 139 if (target_screen_calibration_view->GetDisplayPointLocation(&display_point)) { |
126 touch_point_quad_[state_index] = | 140 touch_point_quad_[state_index] = |
127 std::make_pair(display_point, touch->location()); | 141 std::make_pair(display_point, touch->location()); |
128 } else { | 142 } else { |
129 // TODO(malaykeshav): Display some kind of error for the user. | 143 // TODO(malaykeshav): Display some kind of error for the user. |
130 NOTREACHED() << "Touch calibration failed. Could not retrieve location for" | 144 NOTREACHED() << "Touch calibration failed. Could not retrieve location for" |
131 " display point. Retry calibration."; | 145 " display point. Retry calibration."; |
132 } | 146 } |
133 | 147 |
134 // If this is the final state, then store all calibration data and stop | |
135 // calibration. | |
136 if (target_screen_calibration_view->state() == | |
137 TouchCalibratorView::CALIBRATION_COMPLETE) { | |
138 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData( | |
139 target_display_.id(), touch_point_quad_, | |
140 target_screen_calibration_view->size()); | |
141 StopCalibration(); | |
142 return; | |
143 } | |
144 | |
145 target_screen_calibration_view->AdvanceToNextState(); | 148 target_screen_calibration_view->AdvanceToNextState(); |
146 } | 149 } |
147 | 150 |
148 } // namespace chromeos | 151 } // namespace chromeos |
OLD | NEW |