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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_LAYOUTS_LAYOUT_WRAPPER_BUILDER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_LAYOUTS_LAYOUT_WRAPPER_BUILDER_H 18 19 #include <list> 20 #include <map> 21 #include <unordered_map> 22 23 #include "base/memory/ace_type.h" 24 #include "base/utils/noncopyable.h" 25 26 namespace OHOS::Ace::NG { 27 28 class LayoutWrapper; 29 30 class LayoutWrapperBuilder : public AceType { 31 DECLARE_ACE_TYPE(LayoutWrapperBuilder, AceType) 32 public: 33 LayoutWrapperBuilder() = default; 34 ~LayoutWrapperBuilder() override = default; 35 36 RefPtr<LayoutWrapper> GetOrCreateWrapperByIndex(int32_t index); 37 38 virtual const std::list<RefPtr<LayoutWrapper>>& GetCachedChildLayoutWrapper() = 0; 39 40 const std::list<RefPtr<LayoutWrapper>>& ExpandAllChildWrappers(); 41 42 void RemoveAllChildInRenderTree(); 43 GetTotalCount()44 int32_t GetTotalCount() 45 { 46 return OnGetTotalCount(); 47 } 48 SetStartIndex(int32_t startIndex)49 void SetStartIndex(int32_t startIndex) 50 { 51 startIndex_ = startIndex; 52 } 53 GetStartIndex()54 int32_t GetStartIndex() const 55 { 56 return startIndex_; 57 } 58 SetCacheCount(int32_t cacheCount)59 void SetCacheCount(int32_t cacheCount) 60 { 61 cacheCount_ = cacheCount < 0 ? 1 : cacheCount; 62 } 63 SwapDirtyAndUpdateBuildCache()64 virtual void SwapDirtyAndUpdateBuildCache() {} 65 AdjustGridOffset()66 virtual void AdjustGridOffset() {} 67 68 protected: 69 virtual int32_t OnGetTotalCount() = 0; 70 virtual RefPtr<LayoutWrapper> OnGetOrCreateWrapperByIndex(int32_t index) = 0; 71 virtual const std::list<RefPtr<LayoutWrapper>>& OnExpandChildLayoutWrapper() = 0; 72 73 std::unordered_map<int32_t, RefPtr<LayoutWrapper>> wrapperMap_; 74 75 int32_t startIndex_ = 0; 76 int32_t cacheCount_ = 0; 77 78 ACE_DISALLOW_COPY_AND_MOVE(LayoutWrapperBuilder); 79 }; 80 81 } // namespace OHOS::Ace::NG 82 83 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_LAYOUTS_LAYOUT_WRAPPER_BUILDER_H 84