• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "core/components/common/layout/screen_system_manager.h"
17 
18 namespace OHOS::Ace {
19 namespace {
20     constexpr Dimension MAX_SCREEN_WIDTH_SM = 320.0_vp;
21     constexpr Dimension MAX_SCREEN_WIDTH_MD = 600.0_vp;
22     constexpr Dimension MAX_SCREEN_WIDTH_LG = 840.0_vp;
23     constexpr Dimension MAX_SCREEN_WIDTH_XL = 1024.0_vp;
24 } // namespace
25 
OnSurfaceChanged(double width)26 void ScreenSystemManager::OnSurfaceChanged(double width)
27 {
28     screenWidth_ = width;
29     if (width < MAX_SCREEN_WIDTH_SM.Value() * density_) {
30         currentSize_ = ScreenSizeType::XS;
31     } else if (width < MAX_SCREEN_WIDTH_MD.Value() * density_) {
32         currentSize_ = ScreenSizeType::SM;
33     } else if (width < MAX_SCREEN_WIDTH_LG.Value() * density_) {
34         currentSize_ = ScreenSizeType::MD;
35     } else if (width < MAX_SCREEN_WIDTH_XL.Value() * density_) {
36         currentSize_ = ScreenSizeType::LG;
37     } else {
38         currentSize_ = ScreenSizeType::XL;
39     }
40     LOGD("OnSurfaceChanged: %{public}f", width);
41 }
42 
GetSize(double width) const43 ScreenSizeType ScreenSystemManager::GetSize(double width) const
44 {
45     ScreenSizeType size = ScreenSizeType::UNDEFINED;
46     if (width < MAX_SCREEN_WIDTH_SM.Value() * dipScale_) {
47         size = ScreenSizeType::XS;
48     } else if (width < MAX_SCREEN_WIDTH_MD.Value() * dipScale_) {
49         size = ScreenSizeType::SM;
50     } else if (width < MAX_SCREEN_WIDTH_LG.Value() * dipScale_) {
51         size = ScreenSizeType::MD;
52     } else if (width < MAX_SCREEN_WIDTH_XL.Value() * dipScale_) {
53         size = ScreenSizeType::LG;
54     } else {
55         size = ScreenSizeType::XL;
56     }
57     return size;
58 }
59 } // namespace OHOS::Ace
60