Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 81fea78 | 2013-07-18 23:58:28 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
Tom Anderson | 4ee8374 | 2022-07-14 20:58:41 | [diff] [blame] | 5 | #ifndef UI_LINUX_STATUS_ICON_LINUX_H_ |
6 | #define UI_LINUX_STATUS_ICON_LINUX_H_ | ||||
[email protected] | 81fea78 | 2013-07-18 23:58:28 | [diff] [blame] | 7 | |
Jan Wilken Dörrie | ad587c3 | 2021-03-11 14:09:27 | [diff] [blame] | 8 | #include <string> |
9 | |||||
Tom Anderson | 4ee8374 | 2022-07-14 20:58:41 | [diff] [blame] | 10 | #include "base/component_export.h" |
Keishi Hattori | f28f4f8 | 2022-06-21 11:32:15 | [diff] [blame] | 11 | #include "base/memory/raw_ptr.h" |
[email protected] | 81fea78 | 2013-07-18 23:58:28 | [diff] [blame] | 12 | |
13 | namespace gfx { | ||||
14 | class ImageSkia; | ||||
Tom Anderson | 513e016 | 2025-01-09 04:09:44 | [diff] [blame] | 15 | struct VectorIcon; |
[email protected] | 81fea78 | 2013-07-18 23:58:28 | [diff] [blame] | 16 | } |
17 | |||||
18 | namespace ui { | ||||
19 | class MenuModel; | ||||
20 | } // namespace ui | ||||
21 | |||||
Tom Anderson | 992d987 | 2022-07-14 21:24:50 | [diff] [blame] | 22 | namespace ui { |
[email protected] | 5a991a2 | 2013-09-10 09:22:19 | [diff] [blame] | 23 | |
Tom Anderson | 992d987 | 2022-07-14 21:24:50 | [diff] [blame] | 24 | // Since linux_ui cannot have dependencies on any chrome browser components |
[email protected] | 81fea78 | 2013-07-18 23:58:28 | [diff] [blame] | 25 | // we cannot inherit from StatusIcon. So we implement the necessary methods |
26 | // and let a wrapper class implement the StatusIcon interface and defer the | ||||
[email protected] | f528059f | 2013-08-28 08:23:59 | [diff] [blame] | 27 | // callbacks to a delegate. For the same reason, do not use StatusIconMenuModel. |
Tom Anderson | 4ee8374 | 2022-07-14 20:58:41 | [diff] [blame] | 28 | class COMPONENT_EXPORT(LINUX_UI) StatusIconLinux { |
[email protected] | 81fea78 | 2013-07-18 23:58:28 | [diff] [blame] | 29 | public: |
30 | class Delegate { | ||||
31 | public: | ||||
32 | virtual void OnClick() = 0; | ||||
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 33 | virtual bool HasClickAction() = 0; |
[email protected] | 81fea78 | 2013-07-18 23:58:28 | [diff] [blame] | 34 | |
Tom Anderson | 9cae289 | 2019-06-12 00:15:19 | [diff] [blame] | 35 | virtual const gfx::ImageSkia& GetImage() const = 0; |
Tom Anderson | 513e016 | 2025-01-09 04:09:44 | [diff] [blame] | 36 | virtual const gfx::VectorIcon* GetIcon() const = 0; |
Jan Wilken Dörrie | 5263957 | 2021-03-11 16:49:54 | [diff] [blame] | 37 | virtual const std::u16string& GetToolTip() const = 0; |
Tom Anderson | 1dd5061 | 2019-06-19 01:36:41 | [diff] [blame] | 38 | virtual ui::MenuModel* GetMenuModel() const = 0; |
Tom Anderson | 9cae289 | 2019-06-12 00:15:19 | [diff] [blame] | 39 | |
40 | // This should be called at most once by the implementation. | ||||
Tom Anderson | b137555 | 2019-06-20 20:26:11 | [diff] [blame] | 41 | virtual void OnImplInitializationFailed() = 0; |
Tom Anderson | 9cae289 | 2019-06-12 00:15:19 | [diff] [blame] | 42 | |
[email protected] | 81fea78 | 2013-07-18 23:58:28 | [diff] [blame] | 43 | protected: |
44 | virtual ~Delegate(); | ||||
45 | }; | ||||
46 | |||||
47 | StatusIconLinux(); | ||||
48 | virtual ~StatusIconLinux(); | ||||
49 | |||||
Tom Anderson | 513e016 | 2025-01-09 04:09:44 | [diff] [blame] | 50 | virtual void SetImage(const gfx::ImageSkia& image) = 0; |
51 | virtual void SetIcon(const gfx::VectorIcon& icon) = 0; | ||||
Jan Wilken Dörrie | 5263957 | 2021-03-11 16:49:54 | [diff] [blame] | 52 | virtual void SetToolTip(const std::u16string& tool_tip) = 0; |
[email protected] | 81fea78 | 2013-07-18 23:58:28 | [diff] [blame] | 53 | |
54 | // Invoked after a call to SetContextMenu() to let the platform-specific | ||||
55 | // subclass update the native context menu based on the new model. The | ||||
56 | // subclass should destroy the existing native context menu on this call. | ||||
57 | virtual void UpdatePlatformContextMenu(ui::MenuModel* model) = 0; | ||||
58 | |||||
[email protected] | f528059f | 2013-08-28 08:23:59 | [diff] [blame] | 59 | // Update all the enabled/checked states and the dynamic labels. Some status |
60 | // icon implementations do not refresh the native menu before showing so we | ||||
61 | // need to manually refresh it when the menu model changes. | ||||
62 | virtual void RefreshPlatformContextMenu(); | ||||
63 | |||||
Tom Anderson | b137555 | 2019-06-20 20:26:11 | [diff] [blame] | 64 | virtual void OnSetDelegate(); |
65 | |||||
66 | void SetDelegate(Delegate* delegate); | ||||
67 | |||||
[email protected] | 81fea78 | 2013-07-18 23:58:28 | [diff] [blame] | 68 | Delegate* delegate() { return delegate_; } |
[email protected] | 81fea78 | 2013-07-18 23:58:28 | [diff] [blame] | 69 | |
Tom Anderson | 9cae289 | 2019-06-12 00:15:19 | [diff] [blame] | 70 | protected: |
Jeffrey Cohen | bf84623 | 2023-07-11 23:17:45 | [diff] [blame] | 71 | raw_ptr<Delegate> delegate_ = nullptr; |
[email protected] | 81fea78 | 2013-07-18 23:58:28 | [diff] [blame] | 72 | }; |
73 | |||||
Tom Anderson | 992d987 | 2022-07-14 21:24:50 | [diff] [blame] | 74 | } // namespace ui |
[email protected] | 5a991a2 | 2013-09-10 09:22:19 | [diff] [blame] | 75 | |
Tom Anderson | 4ee8374 | 2022-07-14 20:58:41 | [diff] [blame] | 76 | #endif // UI_LINUX_STATUS_ICON_LINUX_H_ |