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)26void 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 } 41 GetSize(double width) const42ScreenSizeType ScreenSystemManager::GetSize(double width) const 43 { 44 ScreenSizeType size = ScreenSizeType::UNDEFINED; 45 auto context = PipelineBase::GetCurrentContext(); 46 CHECK_NULL_RETURN(context, size); 47 auto dipScale = context->GetDipScale(); 48 if (width < MAX_SCREEN_WIDTH_SM.Value() * dipScale) { 49 size = ScreenSizeType::XS; 50 } else if (width < MAX_SCREEN_WIDTH_MD.Value() * dipScale) { 51 size = ScreenSizeType::SM; 52 } else if (width < MAX_SCREEN_WIDTH_LG.Value() * dipScale) { 53 size = ScreenSizeType::MD; 54 } else if (width < MAX_SCREEN_WIDTH_XL.Value() * dipScale) { 55 size = ScreenSizeType::LG; 56 } else { 57 size = ScreenSizeType::XL; 58 } 59 return size; 60 } 61 } // namespace OHOS::Ace 62