| 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/touch_transformer_controller.h" | 8 #include "ash/touch/touch_transformer_controller.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view
.h" | 10 #include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_view
.h" |
| 11 #include "ui/display/screen.h" | 11 #include "ui/display/screen.h" |
| 12 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
| 13 #include "ui/events/event_constants.h" | 13 #include "ui/events/event_constants.h" |
| 14 | 14 |
| 15 namespace chromeos { | 15 namespace chromeos { |
| 16 | 16 |
| 17 // 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 |
| 18 // ignored during calibration. | 18 // ignored during calibration. |
| 19 const base::TimeDelta TouchCalibratorController::kTouchIntervalThreshold = | 19 const base::TimeDelta TouchCalibratorController::kTouchIntervalThreshold = |
| 20 base::TimeDelta::FromMilliseconds(200); | 20 base::TimeDelta::FromMilliseconds(200); |
| 21 | 21 |
| 22 TouchCalibratorController::TouchCalibratorController() | 22 TouchCalibratorController::TouchCalibratorController() |
| 23 : last_touch_timestamp_(base::Time::Now()) { | 23 : last_touch_timestamp_(base::Time::Now()) {} |
| 24 ash::Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); | |
| 25 } | |
| 26 | 24 |
| 27 TouchCalibratorController::~TouchCalibratorController() { | 25 TouchCalibratorController::~TouchCalibratorController() { |
| 28 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); | |
| 29 touch_calibrator_views_.clear(); | 26 touch_calibrator_views_.clear(); |
| 30 StopCalibration(); | 27 StopCalibration(); |
| 31 } | 28 } |
| 32 | 29 |
| 33 void TouchCalibratorController::OnDisplayConfigurationChanged() { | 30 void TouchCalibratorController::OnDisplayConfigurationChanged() { |
| 34 touch_calibrator_views_.clear(); | 31 touch_calibrator_views_.clear(); |
| 35 StopCalibration(); | 32 StopCalibration(); |
| 36 } | 33 } |
| 37 | 34 |
| 38 void TouchCalibratorController::StartCalibration( | 35 void TouchCalibratorController::StartCalibration( |
| 39 const display::Display& target_display) { | 36 const display::Display& target_display) { |
| 40 is_calibrating_ = true; | 37 is_calibrating_ = true; |
| 38 ash::Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); |
| 41 target_display_ = target_display; | 39 target_display_ = target_display; |
| 42 | 40 |
| 43 // Clear all touch calibrator views used in any previous calibration. | 41 // Clear all touch calibrator views used in any previous calibration. |
| 44 touch_calibrator_views_.clear(); | 42 touch_calibrator_views_.clear(); |
| 45 | 43 |
| 46 // Reset the calibration data. | 44 // Reset the calibration data. |
| 47 touch_point_quad_.fill(std::make_pair(gfx::Point(0, 0), gfx::Point(0, 0))); | 45 touch_point_quad_.fill(std::make_pair(gfx::Point(0, 0), gfx::Point(0, 0))); |
| 48 | 46 |
| 49 std::vector<display::Display> displays = | 47 std::vector<display::Display> displays = |
| 50 display::Screen::GetScreen()->GetAllDisplays(); | 48 display::Screen::GetScreen()->GetAllDisplays(); |
| 51 | 49 |
| 52 for (const display::Display& display : displays) { | 50 for (const display::Display& display : displays) { |
| 53 bool is_primary_view = display.id() == target_display_.id(); | 51 bool is_primary_view = display.id() == target_display_.id(); |
| 54 touch_calibrator_views_[display.id()] = | 52 touch_calibrator_views_[display.id()] = |
| 55 base::MakeUnique<TouchCalibratorView>(display, is_primary_view); | 53 base::MakeUnique<TouchCalibratorView>(display, is_primary_view); |
| 56 } | 54 } |
| 57 | 55 |
| 58 // TODO(malaykeshav): Call TouchTransformerController::SetForCalibration() | 56 // TODO(malaykeshav): Call TouchTransformerController::SetForCalibration() |
| 59 | 57 |
| 60 // Add self as an event handler target. | 58 // Add self as an event handler target. |
| 61 ash::Shell::GetInstance()->AddPreTargetHandler(this); | 59 ash::Shell::GetInstance()->AddPreTargetHandler(this); |
| 62 } | 60 } |
| 63 | 61 |
| 64 void TouchCalibratorController::StopCalibration() { | 62 void TouchCalibratorController::StopCalibration() { |
| 65 if (!is_calibrating_) | 63 if (!is_calibrating_) |
| 66 return; | 64 return; |
| 67 is_calibrating_ = false; | 65 is_calibrating_ = false; |
| 66 ash::Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); |
| 68 | 67 |
| 69 // TODO(malaykeshav): Call TouchTransformerController::SetForCalibration() | 68 // TODO(malaykeshav): Call TouchTransformerController::SetForCalibration() |
| 70 | 69 |
| 71 // Remove self as the event handler. | 70 // Remove self as the event handler. |
| 72 ash::Shell::GetInstance()->RemovePreTargetHandler(this); | 71 ash::Shell::GetInstance()->RemovePreTargetHandler(this); |
| 73 | 72 |
| 74 // Transition all touch calibrator views to their final state for a graceful | 73 // Transition all touch calibrator views to their final state for a graceful |
| 75 // exit. | 74 // exit. |
| 76 for (const auto& it : touch_calibrator_views_) | 75 for (const auto& it : touch_calibrator_views_) |
| 77 it.second->SkipToFinalState(); | 76 it.second->SkipToFinalState(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 target_display_.id(), touch_point_quad_, | 136 target_display_.id(), touch_point_quad_, |
| 138 target_screen_calibration_view->size()); | 137 target_screen_calibration_view->size()); |
| 139 StopCalibration(); | 138 StopCalibration(); |
| 140 return; | 139 return; |
| 141 } | 140 } |
| 142 | 141 |
| 143 target_screen_calibration_view->AdvanceToNextState(); | 142 target_screen_calibration_view->AdvanceToNextState(); |
| 144 } | 143 } |
| 145 | 144 |
| 146 } // namespace chromeos | 145 } // namespace chromeos |
| OLD | NEW |