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()22 Dimension 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)32 void 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()47 const RectF& SelectOverlayInfo::GetFirstHandlePaintRect()
48 {
49 return handleLevelMode == HandleLevelMode::OVERLAY ? firstHandle.paintRect : firstHandle.localPaintRect;
50 }
51
GetSecondHandlePaintRect()52 const RectF& SelectOverlayInfo::GetSecondHandlePaintRect()
53 {
54 return handleLevelMode == HandleLevelMode::OVERLAY ? secondHandle.paintRect : secondHandle.localPaintRect;
55 }
56
CastToTextMenuShowMode(int32_t value)57 TextMenuShowMode 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
65 namespace TextSystemMenu {
IsDisableMenuItem(SystemServiceMenuDisableFlag flag)66 bool IsDisableMenuItem(SystemServiceMenuDisableFlag flag)
67 {
68 auto textMenuInfo = AceApplicationInfo::GetInstance().GetTextMenuInfo();
69 return (textMenuInfo.disableFlags & DISABLE_ALL_FLAG) == DISABLE_ALL_FLAG ||
70 (textMenuInfo.disableFlags & flag) == flag;
71 }
72 DEFINE_MENU_CHECK_METHOD_IMPL(Translate, DISABLE_TRANSLATE_FLAG)
73 DEFINE_MENU_CHECK_METHOD_IMPL(Search, DISABLE_SEARCH_FLAG)
74 DEFINE_MENU_CHECK_METHOD_IMPL(Share, DISABLE_SHARE_FLAG)
75 DEFINE_MENU_CHECK_METHOD_IMPL(CameraInput, DISABLE_CAMERA_INPUT_FLAG)
76 DEFINE_MENU_CHECK_METHOD_IMPL(AIWriter, DISABLE_AI_WRITER_FLAG)
77 DEFINE_MENU_CHECK_METHOD_IMPL(CollaborationService, DISABLE_COLLABORATION_SERVICE_FLAG)
78 DEFINE_MENU_CHECK_METHOD_IMPL(AIUrl, DISABLE_AI_MENU_URL_FLAG)
79 DEFINE_MENU_CHECK_METHOD_IMPL(AIPhone, DISABLE_AI_MENU_PHONE_FLAG)
80 DEFINE_MENU_CHECK_METHOD_IMPL(AIEmail, DISABLE_AI_MENU_EMAIL_FLAG)
81 DEFINE_MENU_CHECK_METHOD_IMPL(AIAddress, DISABLE_AI_MENU_ADDRESS_FLAG)
82 DEFINE_MENU_CHECK_METHOD_IMPL(AIDatetime, DISABLE_AI_MENU_DATETIME_FLAG)
83 DEFINE_MENU_CHECK_METHOD_IMPL(AskCelia, DISABLE_ASK_CELIA_FLAG)
84 } // namespace MenuController
85 } // namespace OHOS::Ace::NG