1 /*
2 * Copyright (c) 2025 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/common/share/text_share_adapter.h"
17
18 #include "adapter/ohos/entrance/ace_container.h"
19 #include "core/common/share/text_share_mgr.h"
20
21 namespace OHOS::Ace {
StartTextShareTask(const int32_t containerId,const NG::RectF & contentRect,const std::string & shareText)22 void TextShareAdapter::StartTextShareTask(
23 const int32_t containerId, const NG::RectF& contentRect, const std::string& shareText)
24 {
25 auto currentContext = PipelineContext::GetCurrentContextSafelyWithCheck();
26 CHECK_NULL_VOID(currentContext);
27 auto aceContainer = Platform::AceContainer::GetContainer(containerId);
28 CHECK_NULL_VOID(aceContainer);
29 auto abilityContext = aceContainer->GetAbilityContext();
30 Rosen::Rect anchorRect {
31 .posX_ = static_cast<int32_t>(contentRect.GetX()),
32 .posY_ = static_cast<int32_t>(contentRect.GetY()),
33 .width_ = static_cast<uint32_t>(contentRect.Width()),
34 .height_ = static_cast<uint32_t>(contentRect.Height()),
35 };
36 auto windowName = aceContainer->GetWindowName();
37 auto uiExecutor = SingleTaskExecutor::Make(
38 currentContext->GetTaskExecutor(), TaskExecutor::TaskType::UI);
39 uiExecutor.PostTask(
40 [abilityContext, anchorRect, windowName, shareText] {
41 (void)TextShareMgr::GetInstance().StartUpShareFunc(
42 abilityContext, anchorRect, windowName, shareText);
43 },
44 "ArkUITextInitTextShare", PriorityType::VIP);
45 }
46
GetMaxTextShareLength()47 uint64_t TextShareAdapter::GetMaxTextShareLength()
48 {
49 return TextShareMgr::GetInstance().GetMaxTextLength();
50 }
51 } // namespace OHOS::Ace