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 #include <ctime>
28 
29 namespace OHOS::Ace::NG {
30 class ACE_EXPORT FolderStackPattern : public StackPattern {
31     DECLARE_ACE_TYPE(FolderStackPattern, Pattern);
32 
33 public:
34     FolderStackPattern() = default;
35     ~FolderStackPattern() override = default;
36 
CreateLayoutAlgorithm()37     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
38     {
39         return MakeRefPtr<FolderStackLayoutAlgorithm>();
40     }
41 
CreateLayoutProperty()42     RefPtr<LayoutProperty> CreateLayoutProperty() override
43     {
44         return MakeRefPtr<FolderStackLayoutProperty>();
45     }
46 
IsAtomicNode()47     bool IsAtomicNode() const override
48     {
49         return false;
50     }
51 
CreatePaintProperty()52     RefPtr<PaintProperty> CreatePaintProperty() override
53     {
54         return MakeRefPtr<PaintProperty>();
55     }
56 
GetFocusPattern()57     FocusPattern GetFocusPattern() const override
58     {
59         return { FocusType::SCOPE, true };
60     }
61 
CreateEventHub()62     RefPtr<EventHub> CreateEventHub() override
63     {
64         return MakeRefPtr<FolderStackEventHub>();
65     }
66 
67     void BeforeCreateLayoutWrapper() override;
68 
69     void RefreshStack(FoldStatus foldStatus);
70 
71     void OnFolderStateChangeSend(FoldStatus foldStatus);
72 
UpdateFoldStatusChangedCallbackId(std::optional<int32_t> id)73     void UpdateFoldStatusChangedCallbackId(std::optional<int32_t> id)
74     {
75         foldStatusChangedCallbackId_ = id;
76     }
77 
HasFoldStatusChangedCallbackId()78     bool HasFoldStatusChangedCallbackId()
79     {
80         return foldStatusChangedCallbackId_.has_value();
81     }
82 
GetDisplayInfo()83     RefPtr<DisplayInfo> GetDisplayInfo()
84     {
85         return displayInfo_;
86     }
87 
88     void DumpInfo() override;
89     void DumpSimplifyInfo(std::unique_ptr<JsonValue>& json) override;
IsInHoverMode()90     bool IsInHoverMode() const
91     {
92         return hasInHoverMode_;
93     }
94 
95     void SetLayoutBeforeAnimation(const RefPtr<FolderStackGroupNode>& hostNode);
96 
SetLastTime(std::time_t time)97     void SetLastTime(std::time_t time)
98     {
99         lastTime_ = time;
100     }
GetLastTime()101     std::time_t GetLastTime()
102     {
103         return lastTime_;
104     }
105 
HasFoldStatusDelayTask()106     bool HasFoldStatusDelayTask() const
107     {
108         return hasFoldStatusDelayTask_;
109     }
110 
111 private:
112     void OnDetachFromFrameNode(FrameNode* node) override;
113     void RegisterFoldStatusListener();
114     void OnAttachToFrameNode() override;
115     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, bool skipMeasure, bool skipLayout) override;
116     void StartOffsetEnteringAnimation();
117     RefPtr<RenderContext> GetRenderContext();
118     void OnVisibleChange(bool isVisible) override;
119     void OnModifyDone() override;
120     void InitFolderStackPatternAppearCallback();
121     void RestoreScreenState();
122     void SetAutoRotate();
123     void UpdateChildAlignment();
124     std::optional<int32_t> foldStatusChangedCallbackId_;
125     bool isScreenRotationLocked_ = false;
126     Orientation lastOrientation_ = Orientation::UNSPECIFIED;
127     bool isNeedRestoreScreenState_ = false;
128     bool isAppearCallback_ = false;
129     RefPtr<DisplayInfo> displayInfo_;
130     bool hasInHoverMode_ = false;
131     FoldStatus currentFoldStatus_ = FoldStatus::UNKNOWN;
132     FoldStatus lastFoldStatus_ = FoldStatus::UNKNOWN;
133     CancelableCallback<void()> foldStatusDelayTask_;
134     std::time_t lastTime_ = std::time(0);
135     bool hasFoldStatusDelayTask_ = false;
136 };
137 } // namespace OHOS::Ace::NG
138 
139 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_FOLDER_STACK_FOLDER_STACK_PATTERN_H
140