stylus_battery_delegate.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2020 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. #ifndef ASH_SYSTEM_PALETTE_STYLUS_BATTERY_DELEGATE_H_
  5. #define ASH_SYSTEM_PALETTE_STYLUS_BATTERY_DELEGATE_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/system/power/peripheral_battery_listener.h"
  8. #include "base/callback_forward.h"
  9. #include "base/scoped_observation.h"
  10. #include "base/time/time.h"
  11. #include "third_party/skia/include/core/SkColor.h"
  12. #include "ui/gfx/image/image_skia.h"
  13. namespace ui {
  14. class ColorProvider;
  15. } // namespace ui
  16. namespace ash {
  17. class ASH_EXPORT StylusBatteryDelegate
  18. : public PeripheralBatteryListener::Observer {
  19. public:
  20. using Callback = base::RepeatingCallback<void()>;
  21. StylusBatteryDelegate();
  22. StylusBatteryDelegate(const StylusBatteryDelegate& other) = delete;
  23. StylusBatteryDelegate& operator=(const StylusBatteryDelegate& other) = delete;
  24. ~StylusBatteryDelegate() override;
  25. SkColor GetColorForBatteryLevel() const;
  26. gfx::ImageSkia GetBatteryImage(ui::ColorProvider* color_provider) const;
  27. gfx::ImageSkia GetBatteryStatusUnknownImage() const;
  28. void SetBatteryUpdateCallback(Callback battery_update_callback);
  29. bool IsBatteryCharging() const;
  30. bool IsBatteryLevelLow() const;
  31. bool IsBatteryStatusStale() const;
  32. bool IsBatteryStatusEligible() const;
  33. bool ShouldShowBatteryStatus() const;
  34. absl::optional<uint8_t> battery_level() const { return battery_level_; }
  35. private:
  36. bool IsBatteryInfoValid(
  37. const PeripheralBatteryListener::BatteryInfo& battery) const;
  38. // PeripheralBatteryListener::Observer:
  39. void OnAddingBattery(
  40. const PeripheralBatteryListener::BatteryInfo& battery) override;
  41. void OnRemovingBattery(
  42. const PeripheralBatteryListener::BatteryInfo& battery) override;
  43. void OnUpdatedBatteryLevel(
  44. const PeripheralBatteryListener::BatteryInfo& battery) override;
  45. PeripheralBatteryListener::BatteryInfo::ChargeStatus battery_charge_status_ =
  46. PeripheralBatteryListener::BatteryInfo::ChargeStatus::kUnknown;
  47. absl::optional<uint8_t> battery_level_;
  48. absl::optional<base::TimeTicks> last_update_timestamp_;
  49. bool last_update_eligible_ = false;
  50. Callback battery_update_callback_;
  51. base::ScopedObservation<PeripheralBatteryListener,
  52. PeripheralBatteryListener::Observer>
  53. battery_observation_{this};
  54. };
  55. } // namespace ash
  56. #endif // ASH_SYSTEM_PALETTE_STYLUS_BATTERY_DELEGATE_H_