status_icon_linux.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2013 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 UI_LINUX_STATUS_ICON_LINUX_H_
  5. #define UI_LINUX_STATUS_ICON_LINUX_H_
  6. #include <string>
  7. #include "base/component_export.h"
  8. #include "base/memory/raw_ptr.h"
  9. namespace gfx {
  10. class ImageSkia;
  11. }
  12. namespace ui {
  13. class MenuModel;
  14. } // namespace ui
  15. namespace ui {
  16. // Since linux_ui cannot have dependencies on any chrome browser components
  17. // we cannot inherit from StatusIcon. So we implement the necessary methods
  18. // and let a wrapper class implement the StatusIcon interface and defer the
  19. // callbacks to a delegate. For the same reason, do not use StatusIconMenuModel.
  20. class COMPONENT_EXPORT(LINUX_UI) StatusIconLinux {
  21. public:
  22. class Delegate {
  23. public:
  24. virtual void OnClick() = 0;
  25. virtual bool HasClickAction() = 0;
  26. virtual const gfx::ImageSkia& GetImage() const = 0;
  27. virtual const std::u16string& GetToolTip() const = 0;
  28. virtual ui::MenuModel* GetMenuModel() const = 0;
  29. // This should be called at most once by the implementation.
  30. virtual void OnImplInitializationFailed() = 0;
  31. protected:
  32. virtual ~Delegate();
  33. };
  34. StatusIconLinux();
  35. virtual ~StatusIconLinux();
  36. virtual void SetIcon(const gfx::ImageSkia& image) = 0;
  37. virtual void SetToolTip(const std::u16string& tool_tip) = 0;
  38. // Invoked after a call to SetContextMenu() to let the platform-specific
  39. // subclass update the native context menu based on the new model. The
  40. // subclass should destroy the existing native context menu on this call.
  41. virtual void UpdatePlatformContextMenu(ui::MenuModel* model) = 0;
  42. // Update all the enabled/checked states and the dynamic labels. Some status
  43. // icon implementations do not refresh the native menu before showing so we
  44. // need to manually refresh it when the menu model changes.
  45. virtual void RefreshPlatformContextMenu();
  46. virtual void OnSetDelegate();
  47. void SetDelegate(Delegate* delegate);
  48. Delegate* delegate() { return delegate_; }
  49. protected:
  50. raw_ptr<Delegate> delegate_ = nullptr;
  51. };
  52. } // namespace ui
  53. #endif // UI_LINUX_STATUS_ICON_LINUX_H_