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

Side by Side Diff: chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_controller.cc

Issue 2638903003: Updates touch calibration API and plumbs through the native touch calibration method (Closed)
Patch Set: Resolving comments Created 3 years, 11 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
OLDNEW
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 "ash/touch/ash_touch_transform_controller.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/threading/thread_task_runner_handle.h"
10 #include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view .h" 11 #include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view .h"
11 #include "ui/display/screen.h" 12 #include "ui/display/screen.h"
12 #include "ui/events/event.h" 13 #include "ui/events/event.h"
13 #include "ui/events/event_constants.h" 14 #include "ui/events/event_constants.h"
14 15
15 namespace chromeos { 16 namespace chromeos {
16 17
17 // Time interval after a touch event during which all other touch events are 18 // Time interval after a touch event during which all other touch events are
18 // ignored during calibration. 19 // ignored during calibration.
19 const base::TimeDelta TouchCalibratorController::kTouchIntervalThreshold = 20 const base::TimeDelta TouchCalibratorController::kTouchIntervalThreshold =
20 base::TimeDelta::FromMilliseconds(200); 21 base::TimeDelta::FromMilliseconds(200);
21 22
22 TouchCalibratorController::TouchCalibratorController() 23 TouchCalibratorController::TouchCalibratorController()
23 : last_touch_timestamp_(base::Time::Now()) {} 24 : last_touch_timestamp_(base::Time::Now()) {}
24 25
25 TouchCalibratorController::~TouchCalibratorController() { 26 TouchCalibratorController::~TouchCalibratorController() {
26 touch_calibrator_views_.clear(); 27 touch_calibrator_views_.clear();
27 StopCalibration(); 28 StopCalibration();
28 } 29 }
29 30
30 void TouchCalibratorController::OnDisplayConfigurationChanged() { 31 void TouchCalibratorController::OnDisplayConfigurationChanged() {
31 touch_calibrator_views_.clear(); 32 touch_calibrator_views_.clear();
32 StopCalibration(); 33 StopCalibration();
33 } 34 }
34 35
36 void TouchCalibratorController::AddCallback(
37 const TouchCalibratorController::TouchCalibrationCallback& callback) {
38 has_callback_ = true;
39 callback_ = callback;
40 }
41
35 void TouchCalibratorController::StartCalibration( 42 void TouchCalibratorController::StartCalibration(
36 const display::Display& target_display) { 43 const display::Display& target_display) {
37 is_calibrating_ = true; 44 is_calibrating_ = true;
38 ash::Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); 45 ash::Shell::GetInstance()->window_tree_host_manager()->AddObserver(this);
39 target_display_ = target_display; 46 target_display_ = target_display;
40 47
41 // Clear all touch calibrator views used in any previous calibration. 48 // Clear all touch calibrator views used in any previous calibration.
42 touch_calibrator_views_.clear(); 49 touch_calibrator_views_.clear();
43 50
44 // Reset the calibration data. 51 // Reset the calibration data.
(...skipping 12 matching lines...) Expand all
57 true); 64 true);
58 65
59 // Add self as an event handler target. 66 // Add self as an event handler target.
60 ash::Shell::GetInstance()->AddPreTargetHandler(this); 67 ash::Shell::GetInstance()->AddPreTargetHandler(this);
61 } 68 }
62 69
63 void TouchCalibratorController::StopCalibration() { 70 void TouchCalibratorController::StopCalibration() {
64 if (!is_calibrating_) 71 if (!is_calibrating_)
65 return; 72 return;
66 is_calibrating_ = false; 73 is_calibrating_ = false;
74
67 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); 75 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this);
68 76
69 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration( 77 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration(
70 false); 78 false);
71 79
72 // Remove self as the event handler. 80 // Remove self as the event handler.
73 ash::Shell::GetInstance()->RemovePreTargetHandler(this); 81 ash::Shell::GetInstance()->RemovePreTargetHandler(this);
74 82
75 // Transition all touch calibrator views to their final state for a graceful 83 // Transition all touch calibrator views to their final state for a graceful
76 // exit. 84 // exit.
77 for (const auto& it : touch_calibrator_views_) 85 for (const auto& it : touch_calibrator_views_)
78 it.second->SkipToFinalState(); 86 it.second->SkipToFinalState();
79 } 87 }
80 88
81 // ui::EventHandler: 89 // ui::EventHandler:
82 void TouchCalibratorController::OnKeyEvent(ui::KeyEvent* key) { 90 void TouchCalibratorController::OnKeyEvent(ui::KeyEvent* key) {
83 if (!is_calibrating_) 91 if (!is_calibrating_)
84 return; 92 return;
85 // Detect ESC key press. 93 // Detect ESC key press.
86 if (key->type() == ui::ET_KEY_PRESSED && key->key_code() == ui::VKEY_ESCAPE) 94 if (key->type() == ui::ET_KEY_PRESSED && key->key_code() == ui::VKEY_ESCAPE) {
95 if (has_callback_) {
96 base::ThreadTaskRunnerHandle::Get()->PostTask(
97 FROM_HERE, base::Bind(callback_, false));
98 has_callback_ = false;
99 }
87 StopCalibration(); 100 StopCalibration();
101 }
88 key->StopPropagation(); 102 key->StopPropagation();
89 } 103 }
90 104
91 void TouchCalibratorController::OnTouchEvent(ui::TouchEvent* touch) { 105 void TouchCalibratorController::OnTouchEvent(ui::TouchEvent* touch) {
92 if (!is_calibrating_) 106 if (!is_calibrating_)
93 return; 107 return;
94 if (touch->type() != ui::ET_TOUCH_RELEASED) 108 if (touch->type() != ui::ET_TOUCH_RELEASED)
95 return; 109 return;
96 if (base::Time::Now() - last_touch_timestamp_ < kTouchIntervalThreshold) 110 if (base::Time::Now() - last_touch_timestamp_ < kTouchIntervalThreshold)
97 return; 111 return;
98 last_touch_timestamp_ = base::Time::Now(); 112 last_touch_timestamp_ = base::Time::Now();
99 113
100 TouchCalibratorView* target_screen_calibration_view = 114 TouchCalibratorView* target_screen_calibration_view =
101 touch_calibrator_views_[target_display_.id()].get(); 115 touch_calibrator_views_[target_display_.id()].get();
102 116
103 // If this is the final state, then store all calibration data and stop 117 // If this is the final state, then store all calibration data and stop
104 // calibration. 118 // calibration.
105 if (target_screen_calibration_view->state() == 119 if (target_screen_calibration_view->state() ==
106 TouchCalibratorView::CALIBRATION_COMPLETE) { 120 TouchCalibratorView::CALIBRATION_COMPLETE) {
107 StopCalibration(); 121 StopCalibration();
108 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData( 122 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData(
109 target_display_.id(), touch_point_quad_, 123 target_display_.id(), touch_point_quad_,
110 target_screen_calibration_view->size()); 124 target_screen_calibration_view->size());
125 if (has_callback_) {
126 base::ThreadTaskRunnerHandle::Get()->PostTask(
127 FROM_HERE, base::Bind(callback_, true));
128 has_callback_ = false;
129 }
111 return; 130 return;
112 } 131 }
113 132
114 int state_index; 133 int state_index;
115 // Maps the state to an integer value. Assigns a non negative integral value 134 // Maps the state to an integer value. Assigns a non negative integral value
116 // for a state in which the user can interact with the the interface. 135 // for a state in which the user can interact with the the interface.
117 switch (target_screen_calibration_view->state()) { 136 switch (target_screen_calibration_view->state()) {
118 case TouchCalibratorView::DISPLAY_POINT_1: 137 case TouchCalibratorView::DISPLAY_POINT_1:
119 state_index = 0; 138 state_index = 0;
120 break; 139 break;
(...skipping 20 matching lines...) Expand all
141 } else { 160 } else {
142 // TODO(malaykeshav): Display some kind of error for the user. 161 // TODO(malaykeshav): Display some kind of error for the user.
143 NOTREACHED() << "Touch calibration failed. Could not retrieve location for" 162 NOTREACHED() << "Touch calibration failed. Could not retrieve location for"
144 " display point. Retry calibration."; 163 " display point. Retry calibration.";
145 } 164 }
146 165
147 target_screen_calibration_view->AdvanceToNextState(); 166 target_screen_calibration_view->AdvanceToNextState();
148 } 167 }
149 168
150 } // namespace chromeos 169 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698