1 /*
2  * Copyright (c) 2022-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_PATTERN_INDEXER_INDEXER_PAINT_PROPERTY_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_INDEXER_INDEXER_PAINT_PROPERTY_H
18 
19 #include "core/components/common/properties/color.h"
20 #include "core/components/common/properties/decoration.h"
21 #include "core/components/indexer/indexer_theme.h"
22 #include "core/components_ng/base/inspector_filter.h"
23 #include "core/components_ng/pattern/indexer/indexer_theme.h"
24 #include "core/components_ng/property/property.h"
25 #include "core/components_ng/render/paint_property.h"
26 #include "core/pipeline_ng/pipeline_context.h"
27 
28 namespace OHOS::Ace::NG {
29 class ACE_EXPORT IndexerPaintProperty : public PaintProperty {
30     DECLARE_ACE_TYPE(IndexerPaintProperty, PaintProperty);
31 
32 public:
33     IndexerPaintProperty() = default;
34 
35     ~IndexerPaintProperty() override = default;
36 
Clone()37     RefPtr<PaintProperty> Clone() const override
38     {
39         auto value = MakeRefPtr<IndexerPaintProperty>();
40         value->PaintProperty::UpdatePaintProperty(DynamicCast<PaintProperty>(this));
41         value->propSelectedBackgroundColor_ = CloneSelectedBackgroundColor();
42         value->propPopupBackground_ = ClonePopupBackground();
43         value->propPopupSelectedColor_ = ClonePopupSelectedColor();
44         value->propPopupUnselectedColor_ = ClonePopupUnselectedColor();
45         value->propPopupItemBackground_ = ClonePopupItemBackground();
46         value->propPopupBorderRadius_ = ClonePopupBorderRadius();
47         value->propPopupItemBorderRadius_ = ClonePopupItemBorderRadius();
48         value->propItemBorderRadius_ = CloneItemBorderRadius();
49         value->propIndexerBorderRadius_ = CloneIndexerBorderRadius();
50         value->propPopupBackgroundBlurStyle_ = ClonePopupBackgroundBlurStyle();
51         value->propPopupTitleBackground_ = ClonePopupTitleBackground();
52 
53         return value;
54     }
55 
Reset()56     void Reset() override
57     {
58         PaintProperty::Reset();
59         ResetSelectedBackgroundColor();
60         ResetPopupBackground();
61         ResetPopupSelectedColor();
62         ResetPopupUnselectedColor();
63         ResetPopupItemBackground();
64         ResetPopupBorderRadius();
65         ResetPopupItemBorderRadius();
66         ResetItemBorderRadius();
67         ResetIndexerBorderRadius();
68         ResetPopupBackgroundBlurStyle();
69         ResetPopupTitleBackground();
70     }
71 
ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)72     void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override
73     {
74         PaintProperty::ToJsonValue(json, filter);
75         /* no fixed attr below, just return */
76         if (filter.IsFastFilter()) {
77             return;
78         }
79         json->PutExtAttr("selectedBackgroundColor",
80             propSelectedBackgroundColor_.value_or(Color::WHITE).ColorToString().c_str(), filter);
81         json->PutExtAttr("popupBackground",
82             propPopupBackground_.value_or(Color::WHITE).ColorToString().c_str(), filter);
83         auto pipeline = PipelineContext::GetCurrentContext();
84         CHECK_NULL_VOID(pipeline);
85         auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
86         CHECK_NULL_VOID(indexerTheme);
87         json->PutExtAttr("popupSelectedColor", propPopupSelectedColor_.
88             value_or(indexerTheme->GetPopupSelectedTextColor()).ColorToString().c_str(), filter);
89         json->PutExtAttr("popupUnselectedColor", propPopupUnselectedColor_.
90             value_or(indexerTheme->GetPopupUnselectedTextColor()).ColorToString().c_str(), filter);
91         json->PutExtAttr("popupItemBackground", propPopupItemBackground_.
92             value_or(indexerTheme->GetPopupBackgroundColor()).ColorToString().c_str(), filter);
93         if (propPopupBorderRadius_.has_value()) {
94             json->PutExtAttr("popupBorderRadius", propPopupBorderRadius_.value().ToString().c_str(), filter);
95         } else {
96             json->PutExtAttr("popupBorderRadius",
97                 Dimension(NG::BUBBLE_RADIUS, DimensionUnit::VP).ToString().c_str(), filter);
98         }
99         if (propPopupItemBorderRadius_.has_value()) {
100             json->PutExtAttr("popupItemBorderRadius",
101                 propPopupItemBorderRadius_.value().ToString().c_str(), filter);
102         } else {
103             json->PutExtAttr("popupItemBorderRadius",
104                 Dimension(NG::BUBBLE_ITEM_RADIUS, DimensionUnit::VP).ToString().c_str(), filter);
105         }
106         if (propItemBorderRadius_.has_value()) {
107             json->PutExtAttr("itemBorderRadius", propItemBorderRadius_.value().ToString().c_str(), filter);
108         } else {
109             json->PutExtAttr("itemBorderRadius",
110                 Dimension(NG::INDEXER_ITEM_DEFAULT_RADIUS, DimensionUnit::VP).ToString().c_str(), filter);
111         }
112         if (propIndexerBorderRadius_.has_value()) {
113             json->PutExtAttr("indexerBorderRadius", propIndexerBorderRadius_.value().ToString().c_str(), filter);
114         } else {
115             json->PutExtAttr("indexerBorderRadius",
116                 Dimension(NG::INDEXER_DEFAULT_RADIUS, DimensionUnit::VP).ToString().c_str(), filter);
117         }
118         BlurStyleOption blurStyleOption;
119         if (propPopupBackgroundBlurStyle_.has_value()) {
120             blurStyleOption = propPopupBackgroundBlurStyle_.value();
121         } else {
122             blurStyleOption.blurStyle = BlurStyle::COMPONENT_REGULAR;
123         }
124         auto jsonValue = JsonUtil::Create(true);
125         blurStyleOption.ToJsonValue(jsonValue, filter);
126         json->PutExtAttr("popupBackgroundBlurStyle",
127             jsonValue->GetValue("backgroundBlurStyle")->GetValue("value"), filter);
128         json->PutExtAttr("popupTitleBackground", propPopupTitleBackground_.
129             value_or(indexerTheme->GetPopupTitleBackground()).ColorToString().c_str(), filter);
130     }
131 
132     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PopupSelectedColor, Color, PROPERTY_UPDATE_RENDER);
133     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PopupUnselectedColor, Color, PROPERTY_UPDATE_RENDER);
134     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectedBackgroundColor, Color, PROPERTY_UPDATE_RENDER);
135     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PopupBackground, Color, PROPERTY_UPDATE_RENDER);
136     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PopupItemBackground, Color, PROPERTY_UPDATE_RENDER);
137     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PopupBorderRadius, Dimension, PROPERTY_UPDATE_MEASURE);
138     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PopupItemBorderRadius, Dimension, PROPERTY_UPDATE_MEASURE);
139     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(ItemBorderRadius, Dimension, PROPERTY_UPDATE_MEASURE);
140     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IndexerBorderRadius, Dimension, PROPERTY_UPDATE_MEASURE);
141     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PopupBackgroundBlurStyle, BlurStyleOption, PROPERTY_UPDATE_RENDER);
142     ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(PopupTitleBackground, Color, PROPERTY_UPDATE_RENDER);
143 };
144 } // namespace OHOS::Ace::NG
145 
146 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_INDEXER_INDEXER_PAINT_PROPERTY_H
147