| 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 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration( |
| 57 true); |
| 56 | 58 |
| 57 // Add self as an event handler target. | 59 // Add self as an event handler target. |
| 58 ash::Shell::GetInstance()->AddPreTargetHandler(this); | 60 ash::Shell::GetInstance()->AddPreTargetHandler(this); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void TouchCalibratorController::StopCalibration() { | 63 void TouchCalibratorController::StopCalibration() { |
| 62 if (!is_calibrating_) | 64 if (!is_calibrating_) |
| 63 return; | 65 return; |
| 64 is_calibrating_ = false; | 66 is_calibrating_ = false; |
| 65 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); | 67 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); |
| 66 | 68 |
| 67 // TODO(malaykeshav): Call TouchTransformController::SetForCalibration() | 69 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration( |
| 70 false); |
| 68 | 71 |
| 69 // Remove self as the event handler. | 72 // Remove self as the event handler. |
| 70 ash::Shell::GetInstance()->RemovePreTargetHandler(this); | 73 ash::Shell::GetInstance()->RemovePreTargetHandler(this); |
| 71 | 74 |
| 72 // Transition all touch calibrator views to their final state for a graceful | 75 // Transition all touch calibrator views to their final state for a graceful |
| 73 // exit. | 76 // exit. |
| 74 for (const auto& it : touch_calibrator_views_) | 77 for (const auto& it : touch_calibrator_views_) |
| 75 it.second->SkipToFinalState(); | 78 it.second->SkipToFinalState(); |
| 76 } | 79 } |
| 77 | 80 |
| 78 // ui::EventHandler: | 81 // ui::EventHandler: |
| 79 void TouchCalibratorController::OnKeyEvent(ui::KeyEvent* key) { | 82 void TouchCalibratorController::OnKeyEvent(ui::KeyEvent* key) { |
| 80 if (!is_calibrating_) | 83 if (!is_calibrating_) |
| 81 return; | 84 return; |
| 82 // Detect ESC key press. | 85 // Detect ESC key press. |
| 83 if (key->type() == ui::ET_KEY_PRESSED && key->key_code() == ui::VKEY_ESCAPE) | 86 if (key->type() == ui::ET_KEY_PRESSED && key->key_code() == ui::VKEY_ESCAPE) |
| 84 StopCalibration(); | 87 StopCalibration(); |
| 85 key->StopPropagation(); | 88 key->StopPropagation(); |
| 86 } | 89 } |
| 87 | 90 |
| 88 void TouchCalibratorController::OnTouchEvent(ui::TouchEvent* touch) { | 91 void TouchCalibratorController::OnTouchEvent(ui::TouchEvent* touch) { |
| 89 if (!is_calibrating_) | 92 if (!is_calibrating_) |
| 90 return; | 93 return; |
| 91 if (touch->type() != ui::ET_TOUCH_RELEASED) | 94 if (touch->type() != ui::ET_TOUCH_RELEASED) |
| 92 return; | 95 return; |
| 93 if (base::Time::Now() - last_touch_timestamp_ < kTouchIntervalThreshold) | 96 if (base::Time::Now() - last_touch_timestamp_ < kTouchIntervalThreshold) |
| 94 return; | 97 return; |
| 95 | |
| 96 last_touch_timestamp_ = base::Time::Now(); | 98 last_touch_timestamp_ = base::Time::Now(); |
| 97 | 99 |
| 98 TouchCalibratorView* target_screen_calibration_view = | 100 TouchCalibratorView* target_screen_calibration_view = |
| 99 touch_calibrator_views_[target_display_.id()].get(); | 101 touch_calibrator_views_[target_display_.id()].get(); |
| 100 | 102 |
| 103 // If this is the final state, then store all calibration data and stop |
| 104 // calibration. |
| 105 if (target_screen_calibration_view->state() == |
| 106 TouchCalibratorView::CALIBRATION_COMPLETE) { |
| 107 StopCalibration(); |
| 108 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData( |
| 109 target_display_.id(), touch_point_quad_, |
| 110 target_screen_calibration_view->size()); |
| 111 return; |
| 112 } |
| 113 |
| 101 int state_index; | 114 int state_index; |
| 102 // Maps the state to an integer value. Assigns a non negative integral value | 115 // 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. | 116 // for a state in which the user can interact with the the interface. |
| 104 switch (target_screen_calibration_view->state()) { | 117 switch (target_screen_calibration_view->state()) { |
| 105 case TouchCalibratorView::DISPLAY_POINT_1: | 118 case TouchCalibratorView::DISPLAY_POINT_1: |
| 106 state_index = 0; | 119 state_index = 0; |
| 107 break; | 120 break; |
| 108 case TouchCalibratorView::DISPLAY_POINT_2: | 121 case TouchCalibratorView::DISPLAY_POINT_2: |
| 109 state_index = 1; | 122 state_index = 1; |
| 110 break; | 123 break; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 124 gfx::Point display_point; | 137 gfx::Point display_point; |
| 125 if (target_screen_calibration_view->GetDisplayPointLocation(&display_point)) { | 138 if (target_screen_calibration_view->GetDisplayPointLocation(&display_point)) { |
| 126 touch_point_quad_[state_index] = | 139 touch_point_quad_[state_index] = |
| 127 std::make_pair(display_point, touch->location()); | 140 std::make_pair(display_point, touch->location()); |
| 128 } else { | 141 } else { |
| 129 // TODO(malaykeshav): Display some kind of error for the user. | 142 // TODO(malaykeshav): Display some kind of error for the user. |
| 130 NOTREACHED() << "Touch calibration failed. Could not retrieve location for" | 143 NOTREACHED() << "Touch calibration failed. Could not retrieve location for" |
| 131 " display point. Retry calibration."; | 144 " display point. Retry calibration."; |
| 132 } | 145 } |
| 133 | 146 |
| 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(); | 147 target_screen_calibration_view->AdvanceToNextState(); |
| 146 } | 148 } |
| 147 | 149 |
| 148 } // namespace chromeos | 150 } // namespace chromeos |
| OLD | NEW |