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 "frameworks/bridge/declarative_frontend/engine/js_ref_ptr.h" 24 25 namespace OHOS::Ace::Framework { 26 27 class ACE_EXPORT ViewMeasureLayout : AceType { 28 DECLARE_ACE_TYPE(ViewMeasureLayout, AceType); 29 30 public: 31 ViewMeasureLayout() = default; ~ViewMeasureLayout()32 ~ViewMeasureLayout() override 33 { 34 LOGD("Destroy: ViewMeasureLayout"); 35 } 36 37 #ifdef USE_ARK_ENGINE 38 static panda::Local<panda::JSValueRef> JSMeasure(panda::JsiRuntimeCallInfo* info); 39 static panda::Local<panda::JSValueRef> JSLayout(panda::JsiRuntimeCallInfo* info); 40 static panda::Local<panda::JSValueRef> JSPlaceChildren(panda::JsiRuntimeCallInfo* info); 41 SetMeasureChildren(std::list<RefPtr<NG::LayoutWrapper>> children)42 static void SetMeasureChildren(std::list<RefPtr<NG::LayoutWrapper>> children) 43 { 44 measureChildren_ = std::move(children); 45 iterMeasureChildren_ = measureChildren_.begin(); 46 } 47 SetLayoutChildren(std::list<RefPtr<NG::LayoutWrapper>> children)48 static void SetLayoutChildren(std::list<RefPtr<NG::LayoutWrapper>> children) 49 { 50 layoutChildren_ = std::move(children); 51 iterLayoutChildren_ = layoutChildren_.begin(); 52 } 53 SetDefaultMeasureConstraint(NG::LayoutConstraintF constraint)54 static void SetDefaultMeasureConstraint(NG::LayoutConstraintF constraint) 55 { 56 measureDefaultConstraint_ = constraint; 57 } 58 59 private: 60 static thread_local std::list<RefPtr<NG::LayoutWrapper>> measureChildren_; 61 static thread_local std::list<RefPtr<NG::LayoutWrapper>>::iterator iterMeasureChildren_; 62 static thread_local std::list<RefPtr<NG::LayoutWrapper>> layoutChildren_; 63 static thread_local std::list<RefPtr<NG::LayoutWrapper>>::iterator iterLayoutChildren_; 64 static thread_local NG::LayoutConstraintF measureDefaultConstraint_; 65 #endif 66 }; 67 68 } // namespace OHOS::Ace::Framework 69 70 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_VIEW_MEASURE_LAYOUT_H