• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_ADAPTER_OHOS_OSAL_PAGE_VIEWPORT_CONFIG_OHOS_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_OSAL_PAGE_VIEWPORT_CONFIG_OHOS_H
18 
19 #include <map>
20 #include <stack>
21 
22 #include "core/common/page_viewport_config.h"
23 #include "core/components_ng/manager/safe_area/safe_area_manager.h"
24 #include "core/pipeline_ng/pipeline_context.h"
25 #include "interfaces/inner_api/ace/viewport_config.h"
26 
27 #include "wm/window.h"
28 #include "wm/wm_common.h"
29 
30 namespace OHOS::Ace {
31 using AvoidAreaInfo = std::map<Rosen::AvoidAreaType, Rosen::AvoidArea>;
32 
33 class PageViewportConfigOhos : public PageViewportConfig {
34     DECLARE_ACE_TYPE(PageViewportConfigOhos, PageViewportConfig);
35 public:
36     PageViewportConfigOhos() = default;
37     ~PageViewportConfigOhos() = default;
38 
39     RefPtr<PageViewportConfig> Clone() const override;
40 
SetPipelineContext(const WeakPtr<NG::PipelineContext> & pipeline)41     void SetPipelineContext(const WeakPtr<NG::PipelineContext>& pipeline)
42     {
43         pipeline_ = pipeline;
44     }
SetViewportConfig(const ViewportConfig & config)45     void SetViewportConfig(const ViewportConfig& config)
46     {
47         config_ = config;
48     }
49 
50     NG::LayoutConstraintF CreateRootLayoutConstraint() const override;
51     NG::SafeAreaInsets GetSafeArea() const override;
SetAvoidAreas(const AvoidAreaInfo & info)52     void SetAvoidAreas(const AvoidAreaInfo& info)
53     {
54         avoidAreas_ = info;
55     }
56 
GetWidth()57     int32_t GetWidth() const override
58     {
59         return config_.Width();
60     }
GetOrientation()61     DisplayOrientation GetOrientation() const override
62     {
63         return static_cast<DisplayOrientation>(config_.Orientation());
64     }
65     void ApplySafeArea() override;
66     void RestoreSafeArea() override;
67 
68 private:
69     struct BackupInfo {
70         uint32_t rootWidth = 0;
71         uint32_t rootHeight = 0;
72         std::map<OHOS::Rosen::AvoidAreaType, NG::SafeAreaInsets> safeAreas;
73     };
74     std::stack<BackupInfo> backupInfos_;
75     ViewportConfig config_;
76     AvoidAreaInfo avoidAreas_;
77     WeakPtr<NG::PipelineContext> pipeline_;
78 };
79 } // namespace OHOS::Ace
80 #endif // FOUNDATION_ACE_ADAPTER_OHOS_OSAL_PAGE_VIEWPORT_CONFIG_OHOS_H
81