| 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 "ash/laser/laser_pointer_controller.h" | 5 #include "ash/laser/laser_pointer_controller.h" |
| 6 | 6 |
| 7 #include "ash/common/system/chromeos/palette/palette_utils.h" | 7 #include "ash/common/system/chromeos/palette/palette_utils.h" |
| 8 #include "ash/laser/laser_pointer_view.h" | 8 #include "ash/laser/laser_pointer_view.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ui/display/screen.h" | 10 #include "ui/display/screen.h" |
| 11 #include "ui/views/widget/widget.h" | 11 #include "ui/views/widget/widget.h" |
| 12 | 12 |
| 13 namespace ash { | 13 namespace ash { |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // A point gets removed from the collection if it is older than | 16 // A point gets removed from the collection if it is older than |
| 17 // |kPointLifeDurationMs|. | 17 // |kPointLifeDurationMs|. |
| 18 const int kPointLifeDurationMs = 200; | 18 const int kPointLifeDurationMs = 200; |
| 19 | 19 |
| 20 // When no move events are being received we add a new point every | 20 // When no move events are being received we add a new point every |
| 21 // |kAddStationaryPointsDelayMs| so that points older than | 21 // |kAddStationaryPointsDelayMs| so that points older than |
| 22 // |kPointLifeDurationMs| can get removed. | 22 // |kPointLifeDurationMs| can get removed. |
| 23 const int kAddStationaryPointsDelayMs = 5; | 23 // Note: Using a delay less than the screen refresh interval will not |
| 24 // provide a visual benefit but instead just waste time performing |
| 25 // unnecessary updates. 16ms is the refresh interval on most devices. |
| 26 // TODO(reveman): Use real VSYNC interval instead of a hard-coded delay. |
| 27 const int kAddStationaryPointsDelayMs = 16; |
| 24 | 28 |
| 25 } // namespace | 29 } // namespace |
| 26 | 30 |
| 27 LaserPointerController::LaserPointerController() | 31 LaserPointerController::LaserPointerController() |
| 28 : stationary_timer_(new base::Timer( | 32 : stationary_timer_(new base::Timer( |
| 29 FROM_HERE, | 33 FROM_HERE, |
| 30 base::TimeDelta::FromMilliseconds(kAddStationaryPointsDelayMs), | 34 base::TimeDelta::FromMilliseconds(kAddStationaryPointsDelayMs), |
| 31 base::Bind(&LaserPointerController::AddStationaryPoint, | 35 base::Bind(&LaserPointerController::AddStationaryPoint, |
| 32 base::Unretained(this)), | 36 base::Unretained(this)), |
| 33 true /* is_repeating */)) { | 37 true /* is_repeating */)) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // add points when |laser_pointer_view_| is null. | 125 // add points when |laser_pointer_view_| is null. |
| 122 stationary_timer_->Stop(); | 126 stationary_timer_->Stop(); |
| 123 if (laser_pointer_view_) { | 127 if (laser_pointer_view_) { |
| 124 is_fading_away_ = false; | 128 is_fading_away_ = false; |
| 125 laser_pointer_view_.reset(); | 129 laser_pointer_view_.reset(); |
| 126 } | 130 } |
| 127 } | 131 } |
| 128 | 132 |
| 129 void LaserPointerController::RestartTimer() { | 133 void LaserPointerController::RestartTimer() { |
| 130 stationary_timer_repeat_count_ = 0; | 134 stationary_timer_repeat_count_ = 0; |
| 131 if (!stationary_timer_->IsRunning()) | 135 stationary_timer_->Reset(); |
| 132 stationary_timer_->Reset(); | |
| 133 } | 136 } |
| 134 | 137 |
| 135 void LaserPointerController::AddStationaryPoint() { | 138 void LaserPointerController::AddStationaryPoint() { |
| 136 if (is_fading_away_) | 139 if (is_fading_away_) |
| 137 laser_pointer_view_->UpdateTime(); | 140 laser_pointer_view_->UpdateTime(); |
| 138 else | 141 else |
| 139 laser_pointer_view_->AddNewPoint(current_stylus_location_); | 142 laser_pointer_view_->AddNewPoint(current_stylus_location_); |
| 140 | 143 |
| 141 // We can stop repeating the timer once the stylus has been stationary for | 144 // We can stop repeating the timer once the stylus has been stationary for |
| 142 // longer than the life of a point. | 145 // longer than the life of a point. |
| 143 if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >= | 146 if (stationary_timer_repeat_count_ * kAddStationaryPointsDelayMs >= |
| 144 kPointLifeDurationMs) { | 147 kPointLifeDurationMs) { |
| 145 stationary_timer_->Stop(); | 148 stationary_timer_->Stop(); |
| 146 // Reset the view if the timer expires and the view was in process of fading | 149 // Reset the view if the timer expires and the view was in process of fading |
| 147 // away. | 150 // away. |
| 148 if (is_fading_away_) | 151 if (is_fading_away_) |
| 149 DestroyLaserPointerView(); | 152 DestroyLaserPointerView(); |
| 150 } | 153 } |
| 151 stationary_timer_repeat_count_++; | 154 stationary_timer_repeat_count_++; |
| 152 } | 155 } |
| 153 } // namespace ash | 156 } // namespace ash |
| OLD | NEW |