• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MANAGER_SAFE_AREA_SAFE_AREA_MANAGER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_SAFE_AREA_SAFE_AREA_MANAGER_H
18 
19 #include "base/memory/ace_type.h"
20 #include "base/utils/noncopyable.h"
21 #include "core/components_ng/base/frame_node.h"
22 #include "core/components_ng/property/safe_area_insets.h"
23 
24 namespace OHOS::Ace::NG {
25 // SafeAreaManager stores layout information to apply SafeArea correctly.
26 class SafeAreaManager : public virtual AceType {
27     DECLARE_ACE_TYPE(SafeAreaManager, AceType);
28 
29 public:
30     SafeAreaManager() = default;
31     ~SafeAreaManager() override = default;
32 
33     bool UpdateSystemSafeArea(const SafeAreaInsets& safeArea);
34     SafeAreaInsets GetSystemSafeArea() const;
35     bool UpdateCutoutSafeArea(const SafeAreaInsets& safeArea);
36     SafeAreaInsets GetCutoutSafeArea() const;
37 
38     SafeAreaInsets GetSafeArea() const;
39 
40     bool UpdateKeyboardSafeArea(float keyboardHeight);
41 
GetKeyboardInset()42     SafeAreaInsets::Inset GetKeyboardInset() const
43     {
44         return keyboardInset_;
45     }
46 
UpdateKeyboardOffset(float offset)47     void UpdateKeyboardOffset(float offset)
48     {
49         keyboardOffset_ = offset;
50     }
GetKeyboardOffset()51     float GetKeyboardOffset() const
52     {
53         return keyboardOffset_;
54     }
55 
56     SafeAreaInsets GetCombinedSafeArea(const SafeAreaExpandOpts& opts) const;
57 
GetGeoRestoreNodes()58     const std::set<WeakPtr<FrameNode>>& GetGeoRestoreNodes() const
59     {
60         return geoRestoreNodes_;
61     }
62 
AddGeoRestoreNode(const WeakPtr<FrameNode> & node)63     void AddGeoRestoreNode(const WeakPtr<FrameNode>& node)
64     {
65         geoRestoreNodes_.insert(node);
66     }
67 
RemoveRestoreNode(const WeakPtr<FrameNode> & node)68     void RemoveRestoreNode(const WeakPtr<FrameNode>& node)
69     {
70         geoRestoreNodes_.erase(node);
71     }
72 
GetSafeAreaCurve()73     RefPtr<InterpolatingSpring> GetSafeAreaCurve() const
74     {
75         return safeAreaCurve_;
76     }
77 
78     bool SetIsFullScreen(bool value);
79     bool SetIgnoreSafeArea(bool value);
80 
81 private:
82     // app window is full screen
83     bool isFullScreen_ = false;
84     bool ignoreSafeArea_ = false;
85 
86     SafeAreaInsets systemSafeArea_;
87     SafeAreaInsets cutoutSafeArea_;
88     // bottom direction only
89     SafeAreaInsets::Inset keyboardInset_;
90     std::set<WeakPtr<FrameNode>> geoRestoreNodes_;
91     // amount of offset to apply to Page when keyboard is up
92     float keyboardOffset_ = 0.0f;
93     static constexpr float SAFE_AREA_VELOCITY = 0.0f;
94     static constexpr float SAFE_AREA_MASS = 1.0f;
95     static constexpr float SAFE_AREA_STIFFNESS = 228.0f;
96     static constexpr float SAFE_AREA_DAMPING = 30.0f;
97     RefPtr<InterpolatingSpring> safeAreaCurve_ = AceType::MakeRefPtr<InterpolatingSpring>(
98         SAFE_AREA_VELOCITY, SAFE_AREA_MASS, SAFE_AREA_STIFFNESS, SAFE_AREA_DAMPING);
99 
100     ACE_DISALLOW_COPY_AND_MOVE(SafeAreaManager);
101 };
102 } // namespace OHOS::Ace::NG
103 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_SAFE_AREA_SAFE_AREA_MANAGER_H
104