ambient_animation_shield_controller.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/ambient/ui/ambient_animation_shield_controller.h"
  5. #include "base/check.h"
  6. #include "base/logging.h"
  7. #include "ui/views/view.h"
  8. namespace ash {
  9. AmbientAnimationShieldController::AmbientAnimationShieldController(
  10. std::unique_ptr<views::View> shield_view,
  11. views::View* parent_view)
  12. : shield_view_(std::move(shield_view)), parent_view_(parent_view) {
  13. DCHECK(shield_view_);
  14. DCHECK(parent_view_);
  15. auto* dark_light_mode_controller = DarkLightModeControllerImpl::Get();
  16. color_provider_observer_.Observe(dark_light_mode_controller);
  17. // Call OnColorModeChanged() directly to capture the initial dark-mode value.
  18. OnColorModeChanged(dark_light_mode_controller->IsDarkModeEnabled());
  19. }
  20. AmbientAnimationShieldController::~AmbientAnimationShieldController() = default;
  21. void AmbientAnimationShieldController::OnColorModeChanged(
  22. bool dark_mode_enabled) {
  23. bool shield_is_active = parent_view_->Contains(shield_view_.get());
  24. if (dark_mode_enabled && !shield_is_active) {
  25. DVLOG(4) << "Adding dark mode shield";
  26. parent_view_->AddChildView(shield_view_.get());
  27. } else if (!dark_mode_enabled && shield_is_active) {
  28. DVLOG(4) << "Removing dark mode shield";
  29. parent_view_->RemoveChildView(shield_view_.get());
  30. }
  31. }
  32. } // namespace ash