unified_brightness_view.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2018 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/system/brightness/unified_brightness_view.h"
  5. #include "ash/resources/vector_icons/vector_icons.h"
  6. #include "ash/shell.h"
  7. #include "ash/strings/grit/ash_strings.h"
  8. #include "ash/style/ash_color_provider.h"
  9. #include "ash/system/brightness/unified_brightness_slider_controller.h"
  10. #include "base/memory/scoped_refptr.h"
  11. #include "ui/gfx/paint_vector_icon.h"
  12. namespace ash {
  13. UnifiedBrightnessView::UnifiedBrightnessView(
  14. UnifiedBrightnessSliderController* controller,
  15. scoped_refptr<UnifiedSystemTrayModel> model)
  16. : UnifiedSliderView(views::Button::PressedCallback(),
  17. controller,
  18. kUnifiedMenuBrightnessIcon,
  19. IDS_ASH_STATUS_TRAY_BRIGHTNESS),
  20. model_(model) {
  21. button()->SetEnabled(false);
  22. model_->AddObserver(this);
  23. OnDisplayBrightnessChanged(false /* by_user */);
  24. }
  25. UnifiedBrightnessView::~UnifiedBrightnessView() {
  26. model_->RemoveObserver(this);
  27. }
  28. void UnifiedBrightnessView::OnDisplayBrightnessChanged(bool by_user) {
  29. SetSliderValue(model_->display_brightness(), by_user);
  30. }
  31. const char* UnifiedBrightnessView::GetClassName() const {
  32. return "UnifiedBrightnessView";
  33. }
  34. void UnifiedBrightnessView::OnThemeChanged() {
  35. UnifiedSliderView::OnThemeChanged();
  36. // Override the color for the icon. Since the button is set to disabled but
  37. // wants to keep the color for an enabled icon.
  38. button()->SetImage(
  39. views::Button::STATE_DISABLED,
  40. gfx::CreateVectorIcon(
  41. kUnifiedMenuBrightnessIcon,
  42. AshColorProvider::Get()->GetContentLayerColor(
  43. AshColorProvider::ContentLayerType::kButtonIconColor)));
  44. }
  45. } // namespace ash