1 /* 2 * Copyright (c) 2023 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_PATTERNS_FOLDER_STACK_FOLDER_STACK_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_FOLDER_STACK_FOLDER_STACK_PATTERN_H 18 19 #include "base/thread/cancelable_callback.h" 20 #include "core/common/display_info.h" 21 #include "core/components/common/layout/constants.h" 22 #include "core/components_ng/pattern/folder_stack/folder_stack_event_hub.h" 23 #include "core/components_ng/pattern/folder_stack/folder_stack_layout_algorithm.h" 24 #include "core/components_ng/pattern/folder_stack/folder_stack_layout_property.h" 25 #include "core/components_ng/pattern/stack/stack_layout_algorithm.h" 26 #include "core/components_ng/pattern/stack/stack_pattern.h" 27 28 namespace OHOS::Ace::NG { 29 class ACE_EXPORT FolderStackPattern : public StackPattern { 30 DECLARE_ACE_TYPE(FolderStackPattern, Pattern); 31 32 public: 33 FolderStackPattern() = default; 34 ~FolderStackPattern() override = default; 35 CreateLayoutAlgorithm()36 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 37 { 38 return MakeRefPtr<FolderStackLayoutAlgorithm>(); 39 } 40 CreateLayoutProperty()41 RefPtr<LayoutProperty> CreateLayoutProperty() override 42 { 43 return MakeRefPtr<FolderStackLayoutProperty>(); 44 } 45 IsAtomicNode()46 bool IsAtomicNode() const override 47 { 48 return false; 49 } 50 CreatePaintProperty()51 RefPtr<PaintProperty> CreatePaintProperty() override 52 { 53 return MakeRefPtr<PaintProperty>(); 54 } 55 GetFocusPattern()56 FocusPattern GetFocusPattern() const override 57 { 58 return { FocusType::SCOPE, true }; 59 } 60 CreateEventHub()61 RefPtr<EventHub> CreateEventHub() override 62 { 63 return MakeRefPtr<FolderStackEventHub>(); 64 } 65 66 void BeforeCreateLayoutWrapper() override; 67 68 void RefreshStack(FoldStatus foldStatus); 69 70 void OnFolderStateChangeSend(FoldStatus foldStatus); 71 UpdateFoldStatusChangedCallbackId(std::optional<int32_t> id)72 void UpdateFoldStatusChangedCallbackId(std::optional<int32_t> id) 73 { 74 foldStatusChangedCallbackId_ = id; 75 } 76 HasFoldStatusChangedCallbackId()77 bool HasFoldStatusChangedCallbackId() 78 { 79 return foldStatusChangedCallbackId_.has_value(); 80 } 81 GetDisplayInfo()82 RefPtr<DisplayInfo> GetDisplayInfo() 83 { 84 return displayInfo_; 85 } 86 87 void DumpInfo() override; 88 GetNeedCallBack()89 bool GetNeedCallBack() 90 { 91 return needCallBack_; 92 } 93 SetNeedCallBack(bool needCallBack)94 void SetNeedCallBack(bool needCallBack) 95 { 96 needCallBack_ = needCallBack; 97 } 98 IsInHoverMode()99 bool IsInHoverMode() const 100 { 101 return hasInHoverMode_; 102 } 103 104 void SetLayoutBeforeAnimation(const RefPtr<FolderStackGroupNode>& hostNode); 105 106 private: 107 void OnDetachFromFrameNode(FrameNode* node) override; 108 void RegisterFoldStatusListener(); 109 void OnAttachToFrameNode() override; 110 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, bool skipMeasure, bool skipLayout) override; 111 void StartOffsetEnteringAnimation(); 112 RefPtr<RenderContext> GetRenderContext(); 113 void OnVisibleChange(bool isVisible) override; 114 void OnModifyDone() override; 115 void InitFolderStackPatternAppearCallback(); 116 void RestoreScreenState(); 117 void SetAutoRotate(); 118 void UpdateChildAlignment(); 119 std::optional<int32_t> foldStatusChangedCallbackId_; 120 bool isScreenRotationLocked_ = false; 121 Orientation lastOrientation_ = Orientation::UNSPECIFIED; 122 bool isNeedRestoreScreenState_ = false; 123 bool isAppearCallback_ = false; 124 RefPtr<DisplayInfo> displayInfo_; 125 bool hasInHoverMode_ = false; 126 bool needCallBack_ = false; 127 FoldStatus currentFoldStatus_ = FoldStatus::UNKNOWN; 128 FoldStatus lastFoldStatus_ = FoldStatus::UNKNOWN; 129 CancelableCallback<void()> foldStatusDelayTask_; 130 }; 131 } // namespace OHOS::Ace::NG 132 133 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_FOLDER_STACK_FOLDER_STACK_PATTERN_H 134