• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_PATTERNS_NAVIGATION_NAVIGATION_OPTIONS_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAVIGATION_OPTIONS_H
18 
19 #include <optional>
20 
21 #include "core/components/common/properties/color.h"
22 #include "core/components/common/properties/decoration.h"
23 #include "core/components_ng/pattern/navigation/navigation_declaration.h"
24 
25 namespace OHOS::Ace::NG {
26 struct NavigationBackgroundOptions {
27     std::optional<Color> color;
28     std::optional<BlurStyleOption> blurStyleOption;
29     std::optional<EffectOption> effectOption;
30     struct resourceUpdater {
31         RefPtr<ResourceObject> resObj;
32         std::function<void(const RefPtr<ResourceObject>&, NavigationBackgroundOptions&)> updateFunc;
33     };
34     std::unordered_map<std::string, resourceUpdater> resMap_;
35 
36     bool operator== (const NavigationBackgroundOptions& other) const
37     {
38         return color == other.color && blurStyleOption == other.blurStyleOption && effectOption == other.effectOption;
39     }
40 
41     bool operator!= (const NavigationBackgroundOptions& other) const
42     {
43         return !(*this == other);
44     }
45 
AddResourceNavigationBackgroundOptions46     void AddResource(const std::string& key, const RefPtr<ResourceObject>& resObj,
47         std::function<void(const RefPtr<ResourceObject>&, NavigationBackgroundOptions&)>&& updateFunc)
48     {
49         if (resObj == nullptr || !updateFunc) {
50             return;
51         }
52         resMap_[key] = { resObj, std::move(updateFunc) };
53     }
54 
ReloadResourcesNavigationBackgroundOptions55     void ReloadResources()
56     {
57         for (const auto& [key, resourceUpdater] : resMap_) {
58             resourceUpdater.updateFunc(resourceUpdater.resObj, *this);
59         }
60     }
61 };
62 
63 struct NavigationBarOptions {
64     std::optional<BarStyle> barStyle;
65     std::optional<CalcDimension> paddingStart;
66     std::optional<CalcDimension> paddingEnd;
67     bool textHideOptions = false;
68 
69     bool operator== (const NavigationBarOptions& other) const
70     {
71         return barStyle == other.barStyle && paddingStart == other.paddingStart
72             && paddingEnd == other.paddingEnd;
73     }
74 
75     bool operator!= (const NavigationBarOptions& other) const
76     {
77         return !(*this == other);
78     }
79 };
80 
81 struct MoreButtonOptions {
82     NavigationBackgroundOptions bgOptions;
83 
84     bool operator== (const MoreButtonOptions& other) const
85     {
86         return bgOptions == other.bgOptions;
87     }
88 
89     bool operator!= (const MoreButtonOptions& other) const
90     {
91         return !(*this == other);
92     }
93 
ToJsonValueMoreButtonOptions94     void ToJsonValue(std::unique_ptr<JsonValue>& json, const NG::InspectorFilter& filter) const
95     {
96         // add backgroundBlurStyleOptions
97         if (bgOptions.blurStyleOption.has_value()) {
98             bgOptions.blurStyleOption.value().ToJsonValue(json, filter);
99         } else {
100             json->PutExtAttr("backgroundBlurStyle", JsonUtil::Create(true), filter);
101         }
102         // add backgroundEffect
103         if (bgOptions.effectOption.has_value()) {
104             bgOptions.effectOption.value().ToJsonValue(json, filter);
105         } else {
106             json->PutExtAttr("backgroundEffect", JsonUtil::Create(true), filter);
107         }
108         // add backgroundBlurStyle
109         if (bgOptions.blurStyleOption.has_value()) {
110             const char* STYLE[] = { "BlurStyle.NONE", "BlurStyle.Thin", "BlurStyle.Regular", "BlurStyle.Thick",
111                 "BlurStyle.BACKGROUND_THIN", "BlurStyle.BACKGROUND_REGULAR", "BlurStyle.BACKGROUND_THICK",
112                 "BlurStyle.BACKGROUND_ULTRA_THICK", "BlurStyle.COMPONENT_ULTRA_THIN", "BlurStyle.COMPONENT_THIN",
113                 "BlurStyle.COMPONENT_REGULAR", "BlurStyle.COMPONENT_THICK", "BlurStyle.COMPONENT_ULTRA_THICK" };
114             int32_t styleEnum = static_cast<int32_t>(bgOptions.blurStyleOption.value().blurStyle);
115             json->PutExtAttr("backgroundBlurStyleValue", STYLE[styleEnum], filter);
116         } else {
117             json->PutExtAttr("backgroundBlurStyleValue", "undefined", filter);
118         }
119     }
120 };
121 
122 using TextStyleApplyFunc = std::function<void(WeakPtr<FrameNode>)>;
123 struct NavigationTextOptions {
124     TextStyleApplyFunc mainTitleApplyFunc;
125     TextStyleApplyFunc subTitleApplyFunc;
126 
ResetNavigationTextOptions127     void Reset()
128     {
129         mainTitleApplyFunc = nullptr;
130         subTitleApplyFunc = nullptr;
131     }
132 };
133 
134 struct NavigationTitlebarOptions {
135     NavigationBackgroundOptions bgOptions;
136     NavigationBarOptions brOptions;
137     NavigationTextOptions textOptions;
138     bool enableHoverMode = false;
139 
140     bool operator== (const NavigationTitlebarOptions& other) const
141     {
142         return bgOptions == other.bgOptions && brOptions == other.brOptions
143             && enableHoverMode == other.enableHoverMode;
144     }
145 
146     bool operator!= (const NavigationTitlebarOptions& other) const
147     {
148         return !(*this == other);
149     }
150 
ToJsonValueNavigationTitlebarOptions151     void ToJsonValue(std::unique_ptr<JsonValue>& json, const NG::InspectorFilter& filter) const
152     {
153         // add backgroundBlurStyleOptions
154         if (bgOptions.blurStyleOption.has_value()) {
155             bgOptions.blurStyleOption.value().ToJsonValue(json, filter);
156         } else {
157             json->PutExtAttr("backgroundBlurStyle", JsonUtil::Create(true), filter);
158         }
159         // add backgroundEffect
160         if (bgOptions.effectOption.has_value()) {
161             bgOptions.effectOption.value().ToJsonValue(json, filter);
162         } else {
163             json->PutExtAttr("backgroundEffect", JsonUtil::Create(true), filter);
164         }
165     }
166 };
167 
168 struct NavigationToolbarOptions {
169     NavigationBackgroundOptions bgOptions;
170     // toolBar not support paddingStart and paddingEnd of NavigationBarOptions now
171     NavigationBarOptions brOptions;
172     MoreButtonOptions mbOptions;
173 
174     bool operator== (const NavigationToolbarOptions& other) const
175     {
176         return bgOptions == other.bgOptions && brOptions == other.brOptions && mbOptions == other.mbOptions;
177     }
178 
179     bool operator!= (const NavigationToolbarOptions& other) const
180     {
181         return !(*this == other);
182     }
183 
ToJsonValueNavigationToolbarOptions184     void ToJsonValue(std::unique_ptr<JsonValue>& json, const NG::InspectorFilter& filter) const
185     {
186         // add backgroundBlurStyleOptions
187         if (bgOptions.blurStyleOption.has_value()) {
188             bgOptions.blurStyleOption.value().ToJsonValue(json, filter);
189         } else {
190             json->PutExtAttr("backgroundBlurStyle", JsonUtil::Create(true), filter);
191         }
192         // add backgroundEffect
193         if (bgOptions.effectOption.has_value()) {
194             bgOptions.effectOption.value().ToJsonValue(json, filter);
195         } else {
196             json->PutExtAttr("backgroundEffect", JsonUtil::Create(true), filter);
197         }
198     }
199 };
200 
201 struct ImageOption {
202     bool noPixMap;
203     bool isValidImage;
204 };
205 
206 struct NavigationMenuOptions {
207     MoreButtonOptions mbOptions;
208 
209     bool operator== (const NavigationMenuOptions& other) const
210     {
211         return mbOptions == other.mbOptions;
212     }
213 
214     bool operator!= (const NavigationMenuOptions& other) const
215     {
216         return !(*this == other);
217     }
218 
ToJsonValueNavigationMenuOptions219     void ToJsonValue(std::unique_ptr<JsonValue>& json, const NG::InspectorFilter& filter) const
220     {
221         mbOptions.ToJsonValue(json, filter);
222     }
223 };
224 
225 } // namespace OHOS::Ace::NG
226 
227 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_NAVIGATION_NAVIGATION_OPTIONS_H
228