Commit 84fc425e authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Misc. cleanup, ash/ edition.

* Inline temps
* Range-based for
* Split DCHECKs
* Better units
* Shorten code

Bug: none
Change-Id: I4f501c85c38f91efb3a6c94f2d3248f03cc808c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2358998
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798540}
parent dc0018f5
......@@ -115,10 +115,8 @@ void AccessibilityFocusRingGroup::AnimateFocusRings(base::TimeTicks timestamp) {
return;
}
double fraction = delta / transition_time;
// Ease-in effect.
fraction = pow(fraction, 0.3);
const double fraction = pow(delta / transition_time, 0.3);
// Handle corner case where we're animating but we don't have previous
// rings.
......@@ -129,8 +127,8 @@ void AccessibilityFocusRingGroup::AnimateFocusRings(base::TimeTicks timestamp) {
previous_focus_rings_[0], focus_rings_[0], fraction));
} else {
ash::ComputeOpacity(&(focus_animation_info_), timestamp);
for (size_t i = 0; i < focus_layers_.size(); ++i)
focus_layers_[i]->SetOpacity(focus_animation_info_.opacity);
for (auto& focus_layer : focus_layers_)
focus_layer->SetOpacity(focus_animation_info_.opacity);
}
}
......
......@@ -33,9 +33,7 @@ void ComputeOpacity(LayerAnimationInfo* animation_info,
opacity = 1.0 - (change_delta / (fade_in_time + fade_out_time));
// Layer::SetOpacity will throw an error if we're not within 0...1.
opacity = base::ClampToRange(opacity, 0.0f, 1.0f);
animation_info->opacity = opacity;
animation_info->opacity = base::ClampToRange(opacity, 0.0f, 1.0f);
}
} // namespace ash
\ No newline at end of file
......@@ -33,8 +33,7 @@ SpokenFeedbackEnabler::~SpokenFeedbackEnabler() {}
void SpokenFeedbackEnabler::OnTimer() {
base::TimeTicks now = ui::EventTimeForNow();
double tick_count_f = (now - start_time_) / kTimerDelay;
int tick_count = base::ClampRound(tick_count_f);
int tick_count = base::ClampRound((now - start_time_) / kTimerDelay);
AccessibilityControllerImpl* controller =
Shell::Get()->accessibility_controller();
......
......@@ -159,9 +159,8 @@ void TouchAccessibilityEnabler::CancelTimer() {
}
void TouchAccessibilityEnabler::OnTimer() {
base::TimeTicks now = Now();
double tick_count_f = (now - two_finger_start_time_) / kTimerDelay;
int tick_count = base::ClampRound(tick_count_f);
const int tick_count =
base::ClampRound((Now() - two_finger_start_time_) / kTimerDelay);
if (tick_count == kTimerTicksOfFirstSoundFeedback) {
base::RecordAction(
......
......@@ -95,8 +95,9 @@ const base::circular_deque<FastInkPoints::FastInkPoint>& FastInkPoints::points()
float FastInkPoints::GetFadeoutFactor(int index) const {
DCHECK(!life_duration_.is_zero());
DCHECK(0 <= index && index < GetNumberOfPoints());
base::TimeDelta age = collection_latest_time_ - points_[index].time;
DCHECK_GE(index, 0);
DCHECK_LT(index, GetNumberOfPoints());
const base::TimeDelta age = collection_latest_time_ - points_[index].time;
return std::min(age / life_duration_, 1.0);
}
......
......@@ -35,9 +35,7 @@ int FpsCounter::ComputeSmoothness() {
base::TimeDelta elapsed = base::TimeTicks::Now() - start_time_;
float refresh_rate = compositor_->refresh_rate();
int expected_frame_number =
std::floor(refresh_rate * elapsed.InMillisecondsF() /
base::Time::kMillisecondsPerSecond);
const int expected_frame_number = (refresh_rate * elapsed).InSeconds();
int actual_frame_number = end_frame_number - start_frame_number_;
int smoothness = actual_frame_number < expected_frame_number
? smoothness =
......
......@@ -32,9 +32,9 @@ void SplitTimeIntoHoursAndMinutes(const base::TimeDelta& time,
int* minutes) {
DCHECK(hours);
DCHECK(minutes);
const int total_minutes = base::ClampRound(time.InSecondsF() / 60);
*hours = total_minutes / 60;
*minutes = total_minutes % 60;
*minutes = base::ClampRound(time / base::TimeDelta::FromMinutes(1));
*hours = *minutes / 60;
*minutes %= 60;
}
} // namespace power_utils
......
......@@ -200,7 +200,7 @@ bool PowerNotificationController::UpdateNotificationStateForRemainingTime() {
// The notification includes a rounded minutes value, so round the estimate
// received from the power manager to match.
const int remaining_minutes =
base::ClampRound(remaining_time->InSecondsF() / 60.0);
base::ClampRound(*remaining_time / base::TimeDelta::FromMinutes(1));
if (remaining_minutes >= kNoWarningMinutes ||
PowerStatus::Get()->IsBatteryFull()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment