• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "core/components_ng/pattern/overlay/sheet_wrapper_pattern.h"
17 
18 namespace OHOS::Ace::NG {
19 
RegisterSheetMaskColorRes(const RefPtr<FrameNode> & maskNode,const RefPtr<FrameNode> & sheetNode,RefPtr<ResourceObject> & resObj)20 void SheetWrapperPattern::RegisterSheetMaskColorRes(const RefPtr<FrameNode>& maskNode,
21     const RefPtr<FrameNode>& sheetNode, RefPtr<ResourceObject>& resObj)
22 {
23     CHECK_NULL_VOID(maskNode);
24     auto pattern = maskNode->GetPattern<SheetWrapperPattern>();
25     CHECK_NULL_VOID(pattern);
26     if (resObj) {
27         auto maskNodeWK = AceType::WeakClaim(AceType::RawPtr(maskNode));
28         auto sheetNodeWK = AceType::WeakClaim(AceType::RawPtr(sheetNode));
29         auto&& updateFunc =
30             [maskNodeWK, sheetNodeWK](const RefPtr<ResourceObject>& resObj) {
31             // Parse the maskColor using the resource object.
32             // If parse failed, use the default value in sheetTheme.
33             Color maskColor;
34             bool result = ResourceParseUtils::ParseResColor(resObj, maskColor);
35             if (!result) {
36                 auto pipeline = PipelineBase::GetCurrentContext();
37                 CHECK_NULL_VOID(pipeline);
38                 auto sheetTheme = pipeline->GetTheme<SheetTheme>();
39                 CHECK_NULL_VOID(sheetTheme);
40                 maskColor = sheetTheme->GetMaskColor();
41             }
42 
43             // Update sheetStyle.
44             auto sheetNode = sheetNodeWK.Upgrade();
45             CHECK_NULL_VOID(sheetNode);
46             auto layoutProperty = sheetNode->GetLayoutProperty<SheetPresentationProperty>();
47             auto sheetStyle = layoutProperty->GetSheetStyleValue();
48             NG::SheetStyle sheetStyleVal = sheetStyle;
49             sheetStyleVal.maskColor = maskColor;
50             layoutProperty->UpdateSheetStyle(sheetStyleVal);
51 
52             // Update sheet mask background color.
53             auto maskNode = maskNodeWK.Upgrade();
54             CHECK_NULL_VOID(maskNode);
55             auto maskRenderContext = maskNode->GetRenderContext();
56             CHECK_NULL_VOID(maskRenderContext);
57             maskRenderContext->UpdateBackgroundColor(maskColor);
58         };
59         pattern->AddResObj("sheetWrapper.maskColor", resObj, std::move(updateFunc));
60     } else {
61         pattern->RemoveResObj("sheetWrapper.maskColor");
62     }
63 }
64 
UpdateSheetMaskResource(const RefPtr<FrameNode> & maskNode,const RefPtr<FrameNode> & sheetNode,NG::SheetStyle & sheetStyle)65 void SheetWrapperPattern::UpdateSheetMaskResource(const RefPtr<FrameNode>& maskNode,
66     const RefPtr<FrameNode>& sheetNode, NG::SheetStyle& sheetStyle)
67 {
68     if (sheetStyle.maskColor.has_value()) {
69         auto resObj = sheetStyle.GetMaskColorResObj();
70         RegisterSheetMaskColorRes(maskNode, sheetNode, resObj);
71     }
72 }
73 } // namespace OHOS::Ace::NG
74