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 #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_VIEW_MEASURE_LAYOUT_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_VIEW_MEASURE_LAYOUT_H
18 
19 #include <utility>
20 
21 #include "base/memory/ace_type.h"
22 #include "core/components_ng/layout/layout_wrapper.h"
23 #include "core/components_ng/pattern/custom/custom_measure_layout_param.h"
24 #include "frameworks/bridge/declarative_frontend/engine/js_ref_ptr.h"
25 
26 namespace OHOS::Ace::Framework {
27 
28 // used for deprecated ets interface onMeasure and onLayout
29 class JSMeasureLayoutParam : public NG::MeasureLayoutParam {
30     DECLARE_ACE_TYPE(JSMeasureLayoutParam, NG::MeasureLayoutParam);
31 public:
32     JSMeasureLayoutParam(NG::LayoutWrapper* layoutWrapper);
33     JSRef<JSObject> GetConstraint();
GetChildArray()34     JSRef<JSArray> GetChildArray()
35     {
36         return childArray_;
37     }
38     void Init() override;
39     void Update(NG::LayoutWrapper* layoutWrapper) override;
40     static RefPtr<JSMeasureLayoutParam> GetInstance(NG::LayoutWrapper* layoutWrapper);
41 private:
42     void GenChildArray(int32_t start, int32_t end);
43     JSRef<JSArray> childArray_;
44 };
45 
46 // used for ets interface onMeasureSize and onPlaceChildren
47 class JSMeasureLayoutParamNG : public NG::MeasureLayoutParam {
48     DECLARE_ACE_TYPE(JSMeasureLayoutParamNG, NG::MeasureLayoutParam);
49 public:
50     JSMeasureLayoutParamNG(NG::LayoutWrapper* layoutWrapper);
51     JSRef<JSObject> GetConstraint();
52     JSRef<JSObject> GetPlaceChildrenConstraint();
GetChildArray()53     JSRef<JSArray> GetChildArray()
54     {
55         return childArray_;
56     }
57     void Init() override;
58     JSRef<JSObject> GetSelfLayoutInfo();
59     void UpdateSize(int32_t index, const NG::SizeF& size) override;
60     void Update(NG::LayoutWrapper* layoutWrapper) override;
61     static RefPtr<JSMeasureLayoutParamNG> GetInstance(NG::LayoutWrapper* layoutWrapper);
62 private:
63     void GenChildArray(int32_t start, int32_t end);
64     JSRef<JSArray> childArray_;
65 };
66 
67 class ACE_EXPORT ViewMeasureLayout : AceType {
68     DECLARE_ACE_TYPE(ViewMeasureLayout, AceType);
69 
70 public:
71     ViewMeasureLayout() = default;
~ViewMeasureLayout()72     ~ViewMeasureLayout() override {}
73 
74 #ifdef USE_ARK_ENGINE
75     static panda::Local<panda::JSValueRef> JSMeasure(panda::JsiRuntimeCallInfo* info);
76     static panda::Local<panda::JSValueRef> JSLayout(panda::JsiRuntimeCallInfo* info);
77     static panda::Local<panda::JSValueRef> JSPlaceChildren(panda::JsiRuntimeCallInfo* info);
78     static panda::Local<panda::JSValueRef> JSGetMargin(panda::JsiRuntimeCallInfo* info);
79     static panda::Local<panda::JSValueRef> JSGetPadding(panda::JsiRuntimeCallInfo* info);
80     static panda::Local<panda::JSValueRef> JSGetBorderWidth(panda::JsiRuntimeCallInfo* info);
81 #endif
82 };
83 
84 } // namespace OHOS::Ace::Framework
85 
86 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_VIEW_MEASURE_LAYOUT_H