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

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
35 void TouchCalibratorController::StartCalibration( 36 void TouchCalibratorController::StartCalibration(
36 const display::Display& target_display) { 37 const display::Display& target_display,
38 const TouchCalibratorController::TouchCalibrationCallback& callback) {
37 is_calibrating_ = true; 39 is_calibrating_ = true;
40 callback_ = callback;
41
38 ash::Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); 42 ash::Shell::GetInstance()->window_tree_host_manager()->AddObserver(this);
39 target_display_ = target_display; 43 target_display_ = target_display;
40 44
41 // Clear all touch calibrator views used in any previous calibration. 45 // Clear all touch calibrator views used in any previous calibration.
42 touch_calibrator_views_.clear(); 46 touch_calibrator_views_.clear();
43 47
44 // Reset the calibration data. 48 // Reset the calibration data.
45 touch_point_quad_.fill(std::make_pair(gfx::Point(0, 0), gfx::Point(0, 0))); 49 touch_point_quad_.fill(std::make_pair(gfx::Point(0, 0), gfx::Point(0, 0)));
46 50
47 std::vector<display::Display> displays = 51 std::vector<display::Display> displays =
48 display::Screen::GetScreen()->GetAllDisplays(); 52 display::Screen::GetScreen()->GetAllDisplays();
49 53
50 for (const display::Display& display : displays) { 54 for (const display::Display& display : displays) {
51 bool is_primary_view = display.id() == target_display_.id(); 55 bool is_primary_view = display.id() == target_display_.id();
52 touch_calibrator_views_[display.id()] = 56 touch_calibrator_views_[display.id()] =
53 base::MakeUnique<TouchCalibratorView>(display, is_primary_view); 57 base::MakeUnique<TouchCalibratorView>(display, is_primary_view);
54 } 58 }
55 59
56 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration( 60 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration(
57 true); 61 true);
58 62
59 // Add self as an event handler target. 63 // Add self as an event handler target.
60 ash::Shell::GetInstance()->AddPreTargetHandler(this); 64 ash::Shell::GetInstance()->AddPreTargetHandler(this);
61 } 65 }
62 66
63 void TouchCalibratorController::StopCalibration() { 67 void TouchCalibratorController::StopCalibration() {
64 if (!is_calibrating_) 68 if (!is_calibrating_)
65 return; 69 return;
66 is_calibrating_ = false; 70 is_calibrating_ = false;
71
67 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); 72 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this);
68 73
69 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration( 74 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration(
70 false); 75 false);
71 76
72 // Remove self as the event handler. 77 // Remove self as the event handler.
73 ash::Shell::GetInstance()->RemovePreTargetHandler(this); 78 ash::Shell::GetInstance()->RemovePreTargetHandler(this);
74 79
75 // Transition all touch calibrator views to their final state for a graceful 80 // Transition all touch calibrator views to their final state for a graceful
76 // exit. 81 // exit.
77 for (const auto& it : touch_calibrator_views_) 82 for (const auto& it : touch_calibrator_views_)
78 it.second->SkipToFinalState(); 83 it.second->SkipToFinalState();
84
85 callback_.Reset();
stevenjb 2017/01/19 17:19:01 Run callback_ with 'false' here instead of line 94
malaykeshav 2017/01/19 23:49:06 Done
79 } 86 }
80 87
81 // ui::EventHandler: 88 // ui::EventHandler:
82 void TouchCalibratorController::OnKeyEvent(ui::KeyEvent* key) { 89 void TouchCalibratorController::OnKeyEvent(ui::KeyEvent* key) {
83 if (!is_calibrating_) 90 if (!is_calibrating_)
84 return; 91 return;
85 // Detect ESC key press. 92 // Detect ESC key press.
86 if (key->type() == ui::ET_KEY_PRESSED && key->key_code() == ui::VKEY_ESCAPE) 93 if (key->type() == ui::ET_KEY_PRESSED && key->key_code() == ui::VKEY_ESCAPE) {
94 if (callback_) {
95 base::ThreadTaskRunnerHandle::Get()->PostTask(
96 FROM_HERE, base::Bind(callback_, false));
97 callback_.Reset();
98 }
87 StopCalibration(); 99 StopCalibration();
100 }
88 key->StopPropagation(); 101 key->StopPropagation();
89 } 102 }
90 103
91 void TouchCalibratorController::OnTouchEvent(ui::TouchEvent* touch) { 104 void TouchCalibratorController::OnTouchEvent(ui::TouchEvent* touch) {
92 if (!is_calibrating_) 105 if (!is_calibrating_)
93 return; 106 return;
94 if (touch->type() != ui::ET_TOUCH_RELEASED) 107 if (touch->type() != ui::ET_TOUCH_RELEASED)
95 return; 108 return;
96 if (base::Time::Now() - last_touch_timestamp_ < kTouchIntervalThreshold) 109 if (base::Time::Now() - last_touch_timestamp_ < kTouchIntervalThreshold)
97 return; 110 return;
98 last_touch_timestamp_ = base::Time::Now(); 111 last_touch_timestamp_ = base::Time::Now();
99 112
100 TouchCalibratorView* target_screen_calibration_view = 113 TouchCalibratorView* target_screen_calibration_view =
101 touch_calibrator_views_[target_display_.id()].get(); 114 touch_calibrator_views_[target_display_.id()].get();
102 115
103 // If this is the final state, then store all calibration data and stop 116 // If this is the final state, then store all calibration data and stop
104 // calibration. 117 // calibration.
105 if (target_screen_calibration_view->state() == 118 if (target_screen_calibration_view->state() ==
106 TouchCalibratorView::CALIBRATION_COMPLETE) { 119 TouchCalibratorView::CALIBRATION_COMPLETE) {
120 if (callback_) {
121 base::ThreadTaskRunnerHandle::Get()->PostTask(
122 FROM_HERE, base::Bind(callback_, true));
123 callback_.Reset();
124 }
107 StopCalibration(); 125 StopCalibration();
108 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData( 126 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData(
109 target_display_.id(), touch_point_quad_, 127 target_display_.id(), touch_point_quad_,
110 target_screen_calibration_view->size()); 128 target_screen_calibration_view->size());
111 return; 129 return;
112 } 130 }
113 131
114 int state_index; 132 int state_index;
115 // Maps the state to an integer value. Assigns a non negative integral value 133 // 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. 134 // for a state in which the user can interact with the the interface.
(...skipping 24 matching lines...) Expand all
141 } else { 159 } else {
142 // TODO(malaykeshav): Display some kind of error for the user. 160 // TODO(malaykeshav): Display some kind of error for the user.
143 NOTREACHED() << "Touch calibration failed. Could not retrieve location for" 161 NOTREACHED() << "Touch calibration failed. Could not retrieve location for"
144 " display point. Retry calibration."; 162 " display point. Retry calibration.";
145 } 163 }
146 164
147 target_screen_calibration_view->AdvanceToNextState(); 165 target_screen_calibration_view->AdvanceToNextState();
148 } 166 }
149 167
150 } // namespace chromeos 168 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698