1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_TITLE_NODE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_TITLE_NODE_H
18
19 #include "core/components_ng/pattern/custom/custom_node.h"
20
21 namespace OHOS::Ace::NG {
22
23 const std::string EVENT_NAME_COLOR_CONFIGURATION = "arkui_color_configuration";
24 const std::string EVENT_NAME_HIDE_SPLIT = "arkui_hide_split";
25 const std::string EVENT_NAME_MAXIMIZE_VISIBILITY = "arkui_maximize_visibility";
26 const std::string EVENT_NAME_MINIMIZE_VISIBILITY = "arkui_minimize_visibility";
27 const std::string EVENT_NAME_CLOSE_VISIBILITY = "arkui_close_visibility";
28 const std::string EVENT_NAME_CLOSE_STATUS = "arkui_close_status";
29 const std::string EVENT_NAME_MAXIMIZE_IS_RECOVER = "arkui_maximize_is_recover";
30 const std::string EVENT_NAME_MENU_WIDTH_CHANGE = "arkui_menu_width_change";
31 const std::string EVENT_NAME_BUTTON_SPACING_CHANGE = "arkui_button_spacing_change";
32 const std::string EVENT_NAME_COLOR_CONFIGURATION_LOCKED = "arkui_color_mode_locked";
33 const std::string EVENT_NAME_BUTTON_SIZE_CHANGE = "arkui_button_size_change";
34 const std::string EVENT_NAME_BUTTON_RIGHT_OFFSET_CHANGE = "arkui_button_right_offset_change";
35 const std::string EVENT_NAME_BUTTON_ICON_SIZE_CHANGE = "arkui_button_icon_size_change";
36 const std::string EVENT_NAME_BUTTON_BACKGROUND_CORNER_RADIUS_CHANGE = "arkui_button_background_corner_radius_change";
37
38 namespace {
BoolToString(bool value)39 inline std::string BoolToString(bool value)
40 {
41 return value ? "true" : "false";
42 }
43 } // namespace
44
45 class ACE_EXPORT CustomTitleNode : public CustomNode {
46 DECLARE_ACE_TYPE(CustomTitleNode, CustomNode);
47
48 public:
49 static RefPtr<CustomTitleNode> CreateCustomTitleNode(int32_t nodeId, const std::string& viewKey);
50
51 CustomTitleNode(int32_t nodeId, const std::string& viewKey);
52 ~CustomTitleNode() override = default;
53
SetAppTitleCallback(const std::function<void (const std::string &)> & callback)54 void SetAppTitleCallback(const std::function<void(const std::string&)>& callback)
55 {
56 appTitleCallback_ = callback;
57 }
58
FireAppTitleCallback(const std::string & title)59 void FireAppTitleCallback(const std::string& title)
60 {
61 if (appTitleCallback_) {
62 appTitleCallback_(title);
63 }
64 }
65
SetAppIconCallback(const std::function<void (const RefPtr<PixelMap> &)> & callback)66 void SetAppIconCallback(const std::function<void(const RefPtr<PixelMap>&)>& callback)
67 {
68 appIconCallback_ = callback;
69 }
70
FireAppIconCallback(const RefPtr<PixelMap> & icon)71 void FireAppIconCallback(const RefPtr<PixelMap>& icon)
72 {
73 if (appIconCallback_) {
74 appIconCallback_(icon);
75 }
76 }
77
SetOnWindowFocusedCallback(const std::function<void ()> & callback)78 void SetOnWindowFocusedCallback(const std::function<void()>& callback)
79 {
80 onWindowFocusedCallback_ = callback;
81 }
82
FireOnWindowFocusedCallback()83 void FireOnWindowFocusedCallback()
84 {
85 if (onWindowFocusedCallback_) {
86 onWindowFocusedCallback_();
87 }
88 }
89
SetOnWindowUnfocusedCallback(const std::function<void ()> & callback)90 void SetOnWindowUnfocusedCallback(const std::function<void()>& callback)
91 {
92 onWindowUnfocusedCallback_ = callback;
93 }
94
FireOnWindowUnfocusedCallback()95 void FireOnWindowUnfocusedCallback()
96 {
97 if (onWindowUnfocusedCallback_) {
98 onWindowUnfocusedCallback_();
99 }
100 }
101
SetCustomCallback(const std::function<void (const std::string & eventName,const std::string & param)> & callback)102 void SetCustomCallback(const std::function<void(const std::string& eventName, const std::string& param)>& callback)
103 {
104 customCallback_ = callback;
105 }
106
FireCustomCallback(const std::string & eventName,const std::string & param)107 void FireCustomCallback(const std::string& eventName, const std::string& param)
108 {
109 if (customCallback_) {
110 customCallback_(eventName, param);
111 }
112 }
113
FireCustomCallback(const std::string & eventName,bool value)114 void FireCustomCallback(const std::string& eventName, bool value)
115 {
116 if (customCallback_) {
117 customCallback_(eventName, BoolToString(value));
118 }
119 }
120
121 private:
122 std::function<void(const std::string&)> appTitleCallback_ = nullptr;
123 std::function<void(const RefPtr<PixelMap>&)> appIconCallback_ = nullptr;
124 std::function<void()> onWindowFocusedCallback_ = nullptr;
125 std::function<void()> onWindowUnfocusedCallback_ = nullptr;
126
127 std::function<void(const std::string&, const std::string&)> customCallback_ = nullptr;
128 };
129 } // namespace OHOS::Ace::NG
130 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_BASE_CUSTOM_NODE_H