1 /*
2  * Copyright (c) 2021-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_BASE_LAYOUT_GRID_SYSTEM_MANAGER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_LAYOUT_GRID_SYSTEM_MANAGER_H
18 
19 #include <mutex>
20 
21 #include "base/geometry/dimension.h"
22 #include "base/memory/ace_type.h"
23 #include "core/components/common/layout/grid_layout_info.h"
24 #include "core/components/common/layout/screen_system_manager.h"
25 
26 namespace OHOS::Ace {
27 
28 class GridColumnInfo;
29 struct SystemGridInfo {
30     SystemGridInfo() = default;
SystemGridInfoSystemGridInfo31     SystemGridInfo(
32         GridSizeType sizeType, const Dimension& gutter, const Dimension& margin, int32_t columns, int32_t maxColumns)
33         : sizeType(sizeType), gutter(gutter), margin(margin), columns(columns), maxColumns(maxColumns)
34     {}
SystemGridInfoSystemGridInfo35     SystemGridInfo(GridSizeType sizeType, const Dimension& gutter, const Dimension& margin, int32_t columns)
36         : sizeType(sizeType), gutter(gutter), margin(margin), columns(columns), maxColumns(columns)
37     {}
38     ACE_FORCE_EXPORT std::string ToString() const;
39 
40     GridSizeType sizeType = GridSizeType::UNDEFINED;
41     Dimension gutter;
42     Dimension margin;
43     int32_t columns = 0;
44     int32_t maxColumns = 0;
45 };
46 
47 class ACE_FORCE_EXPORT GridSystemManager final {
48 public:
49     ~GridSystemManager() = default;
50     ACE_EXPORT static GridSystemManager& GetInstance();
51 
52     const SystemGridInfo& GetCurrentGridInfo();
53 
54     static SystemGridInfo GetSystemGridInfo(const GridSizeType& sizeType);
55     static RefPtr<GridColumnInfo> GetInfoByType(const GridColumnType& type);
56     // width is use px unit.
57     SystemGridInfo GetSystemGridInfo(const GridTemplateType& templateType, double width);
58     double GetScreenWidth(const RefPtr<PipelineBase>& pipeline = nullptr) const
59     {
60         return ScreenSystemManager::GetInstance().GetScreenWidth(pipeline);
61     }
62 
GetDipScale()63     double GetDipScale() const
64     {
65         return ScreenSystemManager::GetInstance().GetDipScale();
66     }
67 
GetCurrentSize()68     GridSizeType GetCurrentSize() const
69     {
70         return ScreenSystemManager::GetInstance().GetCurrentSize();
71     }
72 
GetDensity()73     double GetDensity() const
74     {
75         return ScreenSystemManager::GetInstance().GetDensity();
76     }
77 
78 private:
79     GridSystemManager() = default;
80 
81     static GridSystemManager* instance_;
82     static std::mutex mutex_;
83 
84     SystemGridInfo systemGridInfo_;
85 
86     ACE_DISALLOW_COPY_AND_MOVE(GridSystemManager);
87 };
88 
89 } // namespace OHOS::Ace
90 
91 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_LAYOUT_GRID_SYSTEM_MANAGER_H
92