1 /*
2 * Copyright (c) 2022 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/custom/custom_measure_layout_node.h"
17
18 namespace OHOS::Ace::NG {
19
CreateCustomMeasureLayoutNode(int32_t nodeId,const std::string & viewKey)20 RefPtr<CustomMeasureLayoutNode> CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(
21 int32_t nodeId, const std::string& viewKey)
22 {
23 auto node = MakeRefPtr<CustomMeasureLayoutNode>(nodeId, viewKey);
24 node->InitializePatternAndContext();
25 ElementRegister::GetInstance()->AddUINode(node);
26 return node;
27 }
28
CustomMeasureLayoutNode(int32_t nodeId,const std::string & viewKey)29 CustomMeasureLayoutNode::CustomMeasureLayoutNode(int32_t nodeId, const std::string& viewKey)
30 : FrameNode(V2::JS_VIEW_ETS_TAG, nodeId, MakeRefPtr<CustomNodePattern>()), viewKey_(viewKey)
31 {}
32
FireOnMeasure(NG::LayoutWrapper * layoutWrapper)33 bool CustomMeasureLayoutNode::FireOnMeasure(NG::LayoutWrapper* layoutWrapper)
34 {
35 if (measureFunc_) {
36 measureFunc_(layoutWrapper);
37 return true;
38 }
39 return false;
40 }
41
FireOnLayout(NG::LayoutWrapper * layoutWrapper)42 bool CustomMeasureLayoutNode::FireOnLayout(NG::LayoutWrapper* layoutWrapper)
43 {
44 if (layoutFunc_) {
45 layoutFunc_(layoutWrapper);
46 return true;
47 }
48 return false;
49 }
50
FireOnUpdateParam(NG::LayoutWrapper * layoutWrapper)51 bool CustomMeasureLayoutNode::FireOnUpdateParam(NG::LayoutWrapper* layoutWrapper)
52 {
53 if (updateParamFunc_) {
54 updateParamFunc_(layoutWrapper);
55 return true;
56 }
57 return false;
58 }
59
60 } // namespace OHOS::Ace::NG
61