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 #include "base/log/dump_log.h"
19 #include "core/components_ng/base/frame_node.h"
20 #include "core/components_ng/pattern/custom/custom_node.h"
21 #include "core/components_ng/pattern/custom/custom_node_pattern.h"
22 #include "core/components_v2/inspector/inspector_constants.h"
23 #include "core/pipeline/base/element_register.h"
24 #include "core/pipeline_ng/pipeline_context.h"
25 #include "core/pipeline_ng/ui_task_scheduler.h"
26
27 namespace OHOS::Ace::NG {
28
CreateCustomMeasureLayoutNode(int32_t nodeId,const std::string & viewKey)29 RefPtr<CustomMeasureLayoutNode> CustomMeasureLayoutNode::CreateCustomMeasureLayoutNode(
30 int32_t nodeId, const std::string& viewKey)
31 {
32 auto node = MakeRefPtr<CustomMeasureLayoutNode>(nodeId, viewKey);
33 node->InitializePatternAndContext();
34 ElementRegister::GetInstance()->AddUINode(node);
35 return node;
36 }
37
CustomMeasureLayoutNode(int32_t nodeId,const std::string & viewKey)38 CustomMeasureLayoutNode::CustomMeasureLayoutNode(int32_t nodeId, const std::string& viewKey)
39 : FrameNode(V2::JS_VIEW_ETS_TAG, nodeId, MakeRefPtr<CustomNodePattern>()), viewKey_(viewKey)
40 {}
41
FireOnMeasure(NG::LayoutWrapper * layoutWrapper)42 bool CustomMeasureLayoutNode::FireOnMeasure(NG::LayoutWrapper* layoutWrapper)
43 {
44 if (measureFunc_) {
45 measureFunc_(layoutWrapper);
46 return true;
47 }
48 return false;
49 }
50
FireOnLayout(NG::LayoutWrapper * layoutWrapper)51 bool CustomMeasureLayoutNode::FireOnLayout(NG::LayoutWrapper* layoutWrapper)
52 {
53 if (layoutFunc_) {
54 layoutFunc_(layoutWrapper);
55 return true;
56 }
57 return false;
58 }
59
FireOnUpdateParam(NG::LayoutWrapper * layoutWrapper)60 bool CustomMeasureLayoutNode::FireOnUpdateParam(NG::LayoutWrapper* layoutWrapper)
61 {
62 if (updateParamFunc_) {
63 updateParamFunc_(layoutWrapper);
64 return true;
65 }
66 return false;
67 }
68
69 } // namespace OHOS::Ace::NG
70