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_ng/pattern/select_overlay/select_overlay_property.h" 17 18 #include "core/components/text_overlay/text_overlay_theme.h" 19 #include "core/pipeline_ng/pipeline_context.h" 20 21 namespace OHOS::Ace::NG { GetDefaultLineWidth()22Dimension SelectHandleInfo::GetDefaultLineWidth() 23 { 24 const Dimension defaultLineWidth = 2.0_vp; 25 auto pipeline = PipelineContext::GetCurrentContextSafelyWithCheck(); 26 CHECK_NULL_RETURN(pipeline, defaultLineWidth); 27 auto theme = pipeline->GetTheme<TextOverlayTheme>(); 28 CHECK_NULL_RETURN(theme, defaultLineWidth); 29 return theme->GetHandleLineWidth(); 30 } 31 GetCallerNodeAncestorViewPort(RectF & viewPort)32void SelectOverlayInfo::GetCallerNodeAncestorViewPort(RectF& viewPort) 33 { 34 if (ancestorViewPort) { 35 viewPort = ancestorViewPort.value(); 36 } else { 37 auto frameNode = callerFrameNode.Upgrade(); 38 if (frameNode) { 39 auto viewPortOption = frameNode->GetViewPort(true); 40 if (viewPortOption.has_value()) { 41 viewPort = viewPortOption.value(); 42 } 43 } 44 } 45 } 46 GetFirstHandlePaintRect()47const RectF& SelectOverlayInfo::GetFirstHandlePaintRect() 48 { 49 return handleLevelMode == HandleLevelMode::OVERLAY ? firstHandle.paintRect : firstHandle.localPaintRect; 50 } 51 GetSecondHandlePaintRect()52const RectF& SelectOverlayInfo::GetSecondHandlePaintRect() 53 { 54 return handleLevelMode == HandleLevelMode::OVERLAY ? secondHandle.paintRect : secondHandle.localPaintRect; 55 } 56 CastToTextMenuShowMode(int32_t value)57TextMenuShowMode CastToTextMenuShowMode(int32_t value) 58 { 59 if (value <= static_cast<int32_t>(TextMenuShowMode::BEGIN) || value > static_cast<int32_t>(TextMenuShowMode::END)) { 60 return TextMenuShowMode::DEFAULT; 61 } 62 return static_cast<TextMenuShowMode>(value); 63 } 64 } // namespace OHOS::Ace::NG