| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/system/night_light/night_light_controller.h" | 5 #include "ash/system/night_light/night_light_controller.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/public/cpp/ash_pref_names.h" | 8 #include "ash/public/cpp/ash_pref_names.h" |
| 9 #include "ash/session/session_controller.h" | 9 #include "ash/session/session_controller.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // Default start time at 6:00 PM as an offset from 00:00. | 23 // Default start time at 6:00 PM as an offset from 00:00. |
| 24 const int kDefaultStartTimeOffsetMinutes = 18 * 60; | 24 const int kDefaultStartTimeOffsetMinutes = 18 * 60; |
| 25 | 25 |
| 26 // Default end time at 6:00 AM as an offset from 00:00. | 26 // Default end time at 6:00 AM as an offset from 00:00. |
| 27 const int kDefaultEndTimeOffsetMinutes = 6 * 60; | 27 const int kDefaultEndTimeOffsetMinutes = 6 * 60; |
| 28 | 28 |
| 29 constexpr float kDefaultColorTemperature = 0.5f; | 29 constexpr float kDefaultColorTemperature = 0.5f; |
| 30 | 30 |
| 31 // The duration of the temperature change animation for | 31 // The duration of the temperature change animation for |
| 32 // AnimationDurationType::kShort. | 32 // AnimationDurationType::kShort. |
| 33 constexpr int kManualAnimationDurationSec = 2; | 33 constexpr base::TimeDelta kManualAnimationDuration = |
| 34 base::TimeDelta::FromSeconds(1); |
| 34 | 35 |
| 35 // The duration of the temperature change animation for | 36 // The duration of the temperature change animation for |
| 36 // AnimationDurationType::kLong. | 37 // AnimationDurationType::kLong. |
| 37 constexpr int kAutomaticAnimationDurationSec = 20; | 38 constexpr base::TimeDelta kAutomaticAnimationDuration = |
| 39 base::TimeDelta::FromSeconds(20); |
| 38 | 40 |
| 39 class NightLightControllerDelegateImpl : public NightLightController::Delegate { | 41 class NightLightControllerDelegateImpl : public NightLightController::Delegate { |
| 40 public: | 42 public: |
| 41 NightLightControllerDelegateImpl() = default; | 43 NightLightControllerDelegateImpl() = default; |
| 42 ~NightLightControllerDelegateImpl() override = default; | 44 ~NightLightControllerDelegateImpl() override = default; |
| 43 | 45 |
| 44 // ash::NightLightController::Delegate: | 46 // ash::NightLightController::Delegate: |
| 45 base::Time GetNow() const override { return base::Time::Now(); } | 47 base::Time GetNow() const override { return base::Time::Now(); } |
| 46 base::Time GetSunsetTime() const override { return GetSunRiseSet(false); } | 48 base::Time GetSunsetTime() const override { return GetSunRiseSet(false); } |
| 47 base::Time GetSunriseTime() const override { return GetSunRiseSet(true); } | 49 base::Time GetSunriseTime() const override { return GetSunRiseSet(true); } |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 NotifyClientWithScheduleChange(); | 254 NotifyClientWithScheduleChange(); |
| 253 } | 255 } |
| 254 } | 256 } |
| 255 | 257 |
| 256 void NightLightController::SetDelegateForTesting( | 258 void NightLightController::SetDelegateForTesting( |
| 257 std::unique_ptr<Delegate> delegate) { | 259 std::unique_ptr<Delegate> delegate) { |
| 258 delegate_ = std::move(delegate); | 260 delegate_ = std::move(delegate); |
| 259 } | 261 } |
| 260 | 262 |
| 261 void NightLightController::RefreshLayersTemperature() { | 263 void NightLightController::RefreshLayersTemperature() { |
| 262 ApplyColorTemperatureToLayers( | 264 ApplyColorTemperatureToLayers(GetEnabled() ? GetColorTemperature() : 0.0f, |
| 263 GetEnabled() ? GetColorTemperature() : 0.0f, | 265 animation_duration_ == AnimationDuration::kShort |
| 264 base::TimeDelta::FromSeconds(animation_duration_ == | 266 ? kManualAnimationDuration |
| 265 AnimationDuration::kShort | 267 : kAutomaticAnimationDuration); |
| 266 ? kManualAnimationDurationSec | |
| 267 : kAutomaticAnimationDurationSec)); | |
| 268 | 268 |
| 269 // Reset the animation type back to manual to consume any automatically set | 269 // Reset the animation type back to manual to consume any automatically set |
| 270 // animations. | 270 // animations. |
| 271 last_animation_duration_ = animation_duration_; | 271 last_animation_duration_ = animation_duration_; |
| 272 animation_duration_ = AnimationDuration::kShort; | 272 animation_duration_ = AnimationDuration::kShort; |
| 273 Shell::Get()->SetCursorCompositingEnabled(GetEnabled()); | 273 Shell::Get()->SetCursorCompositingEnabled(GetEnabled()); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void NightLightController::StartWatchingPrefsChanges() { | 276 void NightLightController::StartWatchingPrefsChanges() { |
| 277 DCHECK(active_user_pref_service_); | 277 DCHECK(active_user_pref_service_); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 } | 461 } |
| 462 | 462 |
| 463 void NightLightController::ScheduleNextToggle(base::TimeDelta delay) { | 463 void NightLightController::ScheduleNextToggle(base::TimeDelta delay) { |
| 464 timer_.Start( | 464 timer_.Start( |
| 465 FROM_HERE, delay, | 465 FROM_HERE, delay, |
| 466 base::Bind(&NightLightController::SetEnabled, base::Unretained(this), | 466 base::Bind(&NightLightController::SetEnabled, base::Unretained(this), |
| 467 !GetEnabled(), AnimationDuration::kLong)); | 467 !GetEnabled(), AnimationDuration::kLong)); |
| 468 } | 468 } |
| 469 | 469 |
| 470 } // namespace ash | 470 } // namespace ash |
| OLD | NEW |