• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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/manager/drag_drop/drag_drop_func_wrapper.h"
17 
18 #include <mutex>
19 
20 #include "base/image/pixel_map.h"
21 #include "base/json/json_util.h"
22 #include "core/common/ace_engine.h"
23 #include "core/common/interaction/interaction_interface.h"
24 #include "core/common/udmf/udmf_client.h"
25 #include "core/components/common/layout/grid_system_manager.h"
26 #include "core/components/theme/blur_style_theme.h"
27 #include "core/components/theme/shadow_theme.h"
28 #include "core/components_ng/manager/drag_drop/drag_drop_manager.h"
29 #include "core/components_ng/pattern/image/image_pattern.h"
30 
31 namespace OHOS::Ace::NG {
32 namespace {
33 constexpr float DEFAULT_OPACITY = 0.95f;
34 constexpr Dimension PREVIEW_BORDER_RADIUS = 12.0_vp;
35 constexpr float BLUR_SIGMA_SCALE = 0.57735f;
36 constexpr float SCALE_HALF = 0.5f;
37 constexpr float MIN_OPACITY { 0.0f };
38 constexpr float MAX_OPACITY { 1.0f };
39 using DragNotifyMsg = OHOS::Ace::DragNotifyMsg;
40 using OnDragCallback = std::function<void(const DragNotifyMsg&)>;
41 using StopDragCallback = std::function<void()>;
42 constexpr int32_t MOUSE_POINTER_ID = 1001;
43 constexpr int32_t SOURCE_TOOL_PEN = 1;
44 constexpr int32_t SOURCE_TYPE_TOUCH = 2;
45 constexpr int32_t PEN_POINTER_ID = 102;
46 constexpr int32_t SOURCE_TYPE_MOUSE = 1;
47 }
48 
CheckInternalDragging(const RefPtr<Container> & container)49 static bool CheckInternalDragging(const RefPtr<Container>& container)
50 {
51     CHECK_NULL_RETURN(container, false);
52     auto pipelineContext = container->GetPipelineContext();
53     if (!pipelineContext || !pipelineContext->IsDragging()) {
54         return false;
55     }
56     return true;
57 }
58 
GetShadowInfoArray(std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction,std::vector<ShadowInfoCore> & shadowInfos)59 void GetShadowInfoArray(
60     std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction, std::vector<ShadowInfoCore>& shadowInfos)
61 {
62     auto minScaleWidth = NG::DragDropFuncWrapper::GetScaleWidth(dragAction->instanceId);
63     for (auto& pixelMap : dragAction->pixelMapList) {
64         double scale = 1.0;
65         if (pixelMap.GetRawPtr()) {
66             if (pixelMap->GetWidth() > minScaleWidth && dragAction->previewOption.isScaleEnabled) {
67                 scale = minScaleWidth / pixelMap->GetWidth();
68             }
69             auto pixelMapScale = dragAction->windowScale * scale;
70             pixelMap->Scale(pixelMapScale, pixelMapScale, AceAntiAliasingOption::HIGH);
71         }
72         int32_t width = pixelMap->GetWidth();
73         int32_t height = pixelMap->GetHeight();
74         double x = dragAction->touchPointX;
75         double y = dragAction->touchPointY;
76         if (!dragAction->hasTouchPoint) {
77             x = -width * PIXELMAP_WIDTH_RATE;
78             y = -height * PIXELMAP_HEIGHT_RATE;
79         }
80         ShadowInfoCore shadowInfo { pixelMap, -x, -y };
81         shadowInfos.push_back(shadowInfo);
82     }
83 }
84 
PostStopDrag(std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction,const RefPtr<Container> & container)85 void PostStopDrag(std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction, const RefPtr<Container>& container)
86 {
87     CHECK_NULL_VOID(container);
88     auto taskExecutor = container->GetTaskExecutor();
89     CHECK_NULL_VOID(taskExecutor);
90     auto windowId = container->GetWindowId();
91     taskExecutor->PostTask(
92         [dragAction, windowId]() {
93             CHECK_NULL_VOID(dragAction);
94             TAG_LOGI(AceLogTag::ACE_DRAG, "drag state is reject, stop drag, windowId is %{public}d.", windowId);
95             OHOS::Ace::DragDropRet dropResult { OHOS::Ace::DragRet::DRAG_CANCEL, false, windowId,
96                 OHOS::Ace::DragBehavior::UNKNOWN };
97             InteractionInterface::GetInstance()->StopDrag(dropResult);
98             InteractionInterface::GetInstance()->SetDragWindowVisible(false);
99         },
100         TaskExecutor::TaskType::UI, "ArkUIDragStop");
101 }
102 
ConfirmCurPointerEventInfo(std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction,const RefPtr<Container> & container)103 bool ConfirmCurPointerEventInfo(
104     std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction, const RefPtr<Container>& container)
105 {
106     CHECK_NULL_RETURN(dragAction, false);
107     CHECK_NULL_RETURN(container, false);
108     StopDragCallback stopDragCallback = [dragAction, container]() {
109         CHECK_NULL_VOID(dragAction);
110         CHECK_NULL_VOID(container);
111         bool needPostStopDrag = false;
112         if (dragAction->dragState == DragAdapterState::SENDING) {
113             needPostStopDrag = true;
114         }
115         {
116             std::lock_guard<std::mutex> lock(dragAction->dragStateMutex);
117             dragAction->dragState = DragAdapterState::REJECT;
118         }
119         if (needPostStopDrag) {
120             PostStopDrag(dragAction, container);
121         }
122     };
123     int32_t sourceTool = -1;
124     bool getPointSuccess = container->GetCurPointerEventInfo(dragAction->pointer, dragAction->x, dragAction->y,
125         dragAction->sourceType, sourceTool, std::move(stopDragCallback));
126     if (dragAction->sourceType == SOURCE_TYPE_MOUSE) {
127         dragAction->pointer = MOUSE_POINTER_ID;
128     } else if (dragAction->sourceType == SOURCE_TYPE_TOUCH && sourceTool == SOURCE_TOOL_PEN) {
129         dragAction->pointer = PEN_POINTER_ID;
130     }
131     return getPointSuccess;
132 }
133 
EnvelopedDragData(std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction,std::optional<DragDataCore> & dragData)134 void EnvelopedDragData(
135     std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction, std::optional<DragDataCore>& dragData)
136 {
137     auto container = AceEngine::Get().GetContainer(dragAction->instanceId);
138     CHECK_NULL_VOID(container);
139     auto displayInfo = container->GetDisplayInfo();
140     CHECK_NULL_VOID(displayInfo);
141     dragAction->displayId = static_cast<int32_t>(displayInfo->GetDisplayId());
142 
143     std::vector<ShadowInfoCore> shadowInfos;
144     GetShadowInfoArray(dragAction, shadowInfos);
145     if (shadowInfos.empty()) {
146         TAG_LOGE(AceLogTag::ACE_DRAG, "shadowInfo array is empty");
147         return;
148     }
149     auto pointerId = dragAction->pointer;
150     std::string udKey;
151     std::map<std::string, int64_t> summary;
152     int32_t dataSize = 1;
153     if (dragAction->unifiedData) {
154         int32_t ret = UdmfClient::GetInstance()->SetData(dragAction->unifiedData, udKey);
155         if (ret != 0) {
156             TAG_LOGI(AceLogTag::ACE_DRAG, "udmf set data failed, return value is %{public}d", ret);
157         } else {
158             ret = UdmfClient::GetInstance()->GetSummary(udKey, summary);
159             if (ret != 0) {
160                 TAG_LOGI(AceLogTag::ACE_DRAG, "get summary failed, return value is %{public}d", ret);
161             }
162         }
163         dataSize = static_cast<int32_t>(dragAction->unifiedData->GetSize());
164     }
165     int32_t recordSize = (dataSize != 0 ? dataSize : static_cast<int32_t>(shadowInfos.size()));
166     if (dragAction->previewOption.isNumber) {
167         recordSize = dragAction->previewOption.badgeNumber > 1 ? dragAction->previewOption.badgeNumber : 1;
168     } else if (!dragAction->previewOption.isShowBadge) {
169         recordSize = 1;
170     }
171     auto windowId = container->GetWindowId();
172     auto arkExtraInfoJson = JsonUtil::Create(true);
173     auto pipeline = container->GetPipelineContext();
174     CHECK_NULL_VOID(pipeline);
175     dragAction->dipScale = pipeline->GetDipScale();
176     arkExtraInfoJson->Put("dip_scale", dragAction->dipScale);
177     NG::DragDropFuncWrapper::UpdateExtraInfo(arkExtraInfoJson, dragAction->previewOption);
178     dragData = { shadowInfos, {}, udKey, dragAction->extraParams, arkExtraInfoJson->ToString(), dragAction->sourceType,
179         recordSize, pointerId, dragAction->x, dragAction->y, dragAction->displayId, windowId, true, false, summary };
180 }
181 
HandleCallback(std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction,const OHOS::Ace::DragNotifyMsg & dragNotifyMsg,const DragAdapterStatus & dragStatus)182 void HandleCallback(std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction,
183     const OHOS::Ace::DragNotifyMsg& dragNotifyMsg, const DragAdapterStatus& dragStatus)
184 {
185     TAG_LOGI(AceLogTag::ACE_DRAG, "drag notify message result is %{public}d.", dragNotifyMsg.result);
186     CHECK_NULL_VOID(dragAction);
187     bool hasHandle = false;
188     {
189         std::lock_guard<std::mutex> lock(dragAction->mutex);
190         hasHandle = dragAction->hasHandle;
191         dragAction->hasHandle = true;
192     }
193     if (hasHandle) {
194         return;
195     }
196     auto container = AceEngine::Get().GetContainer(dragAction->instanceId);
197     CHECK_NULL_VOID(container);
198     if (dragStatus == DragAdapterStatus::ENDED) {
199         auto pipelineContext = container->GetPipelineContext();
200         CHECK_NULL_VOID(pipelineContext);
201         pipelineContext->ResetDragging();
202     }
203     int32_t dragState = static_cast<int32_t>(dragStatus);
204     dragAction->callback(dragNotifyMsg, dragState);
205 }
206 
CheckStartAction(std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction,const RefPtr<Container> & container,const RefPtr<DragDropManager> & manager)207 int32_t CheckStartAction(std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction,
208     const RefPtr<Container>& container, const RefPtr<DragDropManager>& manager)
209 {
210     if (CheckInternalDragging(container)) {
211         return -1;
212     }
213     {
214         std::lock_guard<std::mutex> lock(dragAction->dragStateMutex);
215         if (manager->GetDragAction() != nullptr && (manager->GetDragAction())->dragState == DragAdapterState::SENDING) {
216             return -1;
217         }
218         dragAction->dragState = DragAdapterState::SENDING;
219     }
220     DragDropFuncWrapper::UpdatePreviewOptionDefaultAttr(dragAction->previewOption);
221     auto isGetPointSuccess = ConfirmCurPointerEventInfo(dragAction, container);
222     if (!isGetPointSuccess) {
223         return -1;
224     }
225     return 0;
226 }
227 
StartDragAction(std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction)228 int32_t DragDropFuncWrapper::StartDragAction(std::shared_ptr<OHOS::Ace::NG::ArkUIInteralDragAction> dragAction)
229 {
230     auto pipelineContext = PipelineContext::GetContextByContainerId(dragAction->instanceId);
231     CHECK_NULL_RETURN(pipelineContext, -1);
232     auto manager = pipelineContext->GetDragDropManager();
233     CHECK_NULL_RETURN(manager, -1);
234     auto container = AceEngine::Get().GetContainer(dragAction->instanceId);
235     CHECK_NULL_RETURN(container, -1);
236     auto windowScale = container->GetWindowScale();
237     CHECK_NULL_RETURN(windowScale, -1);
238     dragAction->windowScale = windowScale;
239     manager->SetDragAction(dragAction);
240     if (CheckStartAction(dragAction, container, manager) == -1) {
241         manager->GetDragAction()->dragState = DragAdapterState::INIT;
242         return -1;
243     }
244     std::optional<DragDataCore> dragData;
245     EnvelopedDragData(dragAction, dragData);
246     if (!dragData) {
247         {
248             std::lock_guard<std::mutex> lock(dragAction->dragStateMutex);
249             manager->GetDragAction()->dragState = DragAdapterState::INIT;
250         }
251         return -1;
252     }
253     OnDragCallback callback = [dragAction, manager](const OHOS::Ace::DragNotifyMsg& dragNotifyMsg) {
254         {
255             std::lock_guard<std::mutex> lock(dragAction->dragStateMutex);
256             dragAction->dragState = DragAdapterState::INIT;
257             manager->SetDragAction(dragAction);
258         }
259         HandleCallback(dragAction, dragNotifyMsg, DragAdapterStatus::ENDED);
260     };
261     NG::DragDropFuncWrapper::SetDraggingPointerAndPressedState(dragAction->pointer, dragAction->instanceId);
262     int32_t ret = InteractionInterface::GetInstance()->StartDrag(dragData.value(), callback);
263     if (ret != 0) {
264         manager->GetDragAction()->dragState = DragAdapterState::INIT;
265         return -1;
266     }
267     HandleCallback(dragAction, DragNotifyMsg {}, DragAdapterStatus::STARTED);
268     pipelineContext->SetIsDragging(true);
269     std::lock_guard<std::mutex> lock(dragAction->dragStateMutex);
270     if (dragAction->dragState == DragAdapterState::SENDING) {
271         dragAction->dragState = DragAdapterState::SUCCESS;
272         InteractionInterface::GetInstance()->SetDragWindowVisible(true);
273         auto pipelineContext = container->GetPipelineContext();
274         pipelineContext->OnDragEvent(
275             { dragAction->x, dragAction->y }, DragEventAction::DRAG_EVENT_START_FOR_CONTROLLER);
276         NG::DragDropFuncWrapper::DecideWhetherToStopDragging(
277             { dragAction->x, dragAction->y }, dragAction->extraParams, dragAction->pointer, dragAction->instanceId);
278     }
279     return 0;
280 }
281 
SetDraggingPointerAndPressedState(int32_t currentPointerId,int32_t containerId)282 void DragDropFuncWrapper::SetDraggingPointerAndPressedState(int32_t currentPointerId, int32_t containerId)
283 {
284     auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
285     CHECK_NULL_VOID(pipelineContext);
286     auto manager = pipelineContext->GetDragDropManager();
287     CHECK_NULL_VOID(manager);
288     manager->SetDraggingPointer(currentPointerId);
289     manager->SetDraggingPressedState(true);
290 }
291 
DecideWhetherToStopDragging(const PointerEvent & pointerEvent,const std::string & extraParams,int32_t currentPointerId,int32_t containerId)292 void DragDropFuncWrapper::DecideWhetherToStopDragging(
293     const PointerEvent& pointerEvent, const std::string& extraParams, int32_t currentPointerId, int32_t containerId)
294 {
295     auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
296     CHECK_NULL_VOID(pipelineContext);
297     auto manager = pipelineContext->GetDragDropManager();
298     CHECK_NULL_VOID(manager);
299     if (!manager->IsDraggingPressed(currentPointerId)) {
300         manager->OnDragEnd(pointerEvent, extraParams);
301     }
302 }
303 
UpdateDragPreviewOptionsFromModifier(std::function<void (WeakPtr<FrameNode>)> applyOnNodeSync,DragPreviewOption & option)304 void DragDropFuncWrapper::UpdateDragPreviewOptionsFromModifier(
305     std::function<void(WeakPtr<FrameNode>)> applyOnNodeSync, DragPreviewOption& option)
306 {
307     // create one temporary frame node for receiving the value from the modifier
308     auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
309         []() { return AceType::MakeRefPtr<ImagePattern>(); });
310     CHECK_NULL_VOID(imageNode);
311 
312     // execute the modifier
313     CHECK_NULL_VOID(applyOnNodeSync);
314     applyOnNodeSync(AceType::WeakClaim(AceType::RawPtr(imageNode)));
315 
316     // get values from the temporary frame node
317     auto imageContext = imageNode->GetRenderContext();
318     CHECK_NULL_VOID(imageContext);
319     auto opacity = imageContext->GetOpacity();
320     if (opacity.has_value() && (opacity.value()) <= MAX_OPACITY && (opacity.value()) >= MIN_OPACITY) {
321         option.options.opacity = opacity.value();
322     } else {
323         option.options.opacity = DEFAULT_OPACITY;
324     }
325 
326     auto shadow = imageContext->GetBackShadow();
327     if (shadow.has_value()) {
328         option.options.shadow = shadow.value();
329     }
330 
331     auto borderRadius = imageContext->GetBorderRadius();
332     if (borderRadius.has_value()) {
333         option.options.borderRadius = borderRadius;
334     }
335 
336     auto bgEffect = imageContext->GetBackgroundEffect();
337     if (bgEffect.has_value()) {
338         option.options.blurbgEffect.backGroundEffect = bgEffect.value();
339     } else {
340         auto blurstyletmp = imageContext->GetBackBlurStyle();
341         if (blurstyletmp.has_value()) {
342             bgEffect = BrulStyleToEffection(blurstyletmp);
343             if (bgEffect.has_value()) {
344                 option.options.blurbgEffect.backGroundEffect = bgEffect.value();
345             }
346         }
347     }
348 }
349 
UpdatePreviewOptionDefaultAttr(DragPreviewOption & option)350 void DragDropFuncWrapper::UpdatePreviewOptionDefaultAttr(DragPreviewOption& option)
351 {
352     option.options.opacity = DEFAULT_OPACITY;
353     if (option.isDefaultShadowEnabled) {
354         option.options.shadow = GetDefaultShadow();
355     } else {
356         option.options.shadow = std::nullopt;
357     }
358     if (option.isDefaultRadiusEnabled) {
359         option.options.borderRadius = GetDefaultBorderRadius();
360     } else {
361         option.options.borderRadius = std::nullopt;
362     }
363 }
364 
UpdateExtraInfo(std::unique_ptr<JsonValue> & arkExtraInfoJson,DragPreviewOption & option)365 void DragDropFuncWrapper::UpdateExtraInfo(std::unique_ptr<JsonValue>& arkExtraInfoJson,
366     DragPreviewOption& option)
367 {
368     CHECK_NULL_VOID(arkExtraInfoJson);
369     double opacity = option.options.opacity;
370     arkExtraInfoJson->Put("dip_opacity", opacity);
371     if (option.options.blurbgEffect.backGroundEffect.radius.IsValid()) {
372         option.options.blurbgEffect.ToJsonValue(arkExtraInfoJson);
373     }
374     PrepareShadowParametersForDragData(arkExtraInfoJson, option);
375     PrepareRadiusParametersForDragData(arkExtraInfoJson, option);
376 }
377 
PrepareRadiusParametersForDragData(std::unique_ptr<JsonValue> & arkExtraInfoJson,DragPreviewOption & option)378 void DragDropFuncWrapper::PrepareRadiusParametersForDragData(std::unique_ptr<JsonValue>& arkExtraInfoJson,
379     DragPreviewOption& option)
380 {
381     CHECK_NULL_VOID(arkExtraInfoJson);
382     auto borderRadius = option.options.borderRadius;
383     if (borderRadius.has_value()) {
384         if (borderRadius.value().radiusTopLeft.has_value()) {
385             arkExtraInfoJson->Put("drag_corner_radius1", borderRadius.value().radiusTopLeft.value().Value());
386         }
387         if (borderRadius.value().radiusTopRight.has_value()) {
388             arkExtraInfoJson->Put("drag_corner_radius2", borderRadius.value().radiusTopRight.value().Value());
389         }
390         if (borderRadius.value().radiusBottomRight.has_value()) {
391             arkExtraInfoJson->Put("drag_corner_radius3", borderRadius.value().radiusBottomRight.value().Value());
392         }
393         if (borderRadius.value().radiusBottomLeft.has_value()) {
394             arkExtraInfoJson->Put("drag_corner_radius4", borderRadius.value().radiusBottomLeft.value().Value());
395         }
396     }
397 }
398 
PrepareShadowParametersForDragData(std::unique_ptr<JsonValue> & arkExtraInfoJson,DragPreviewOption & option)399 void DragDropFuncWrapper::PrepareShadowParametersForDragData(std::unique_ptr<JsonValue>& arkExtraInfoJson,
400     DragPreviewOption& option)
401 {
402     CHECK_NULL_VOID(arkExtraInfoJson);
403     auto shadow = option.options.shadow;
404     if (!shadow.has_value() || !shadow->IsValid()) {
405         arkExtraInfoJson->Put("shadow_enable", false);
406         return;
407     }
408     arkExtraInfoJson->Put("drag_type", "non-text");
409     arkExtraInfoJson->Put("shadow_enable", true);
410     ParseShadowInfo(shadow.value(), arkExtraInfoJson);
411 }
412 
ParseShadowInfo(Shadow & shadow,std::unique_ptr<JsonValue> & arkExtraInfoJson)413 void DragDropFuncWrapper::ParseShadowInfo(Shadow& shadow, std::unique_ptr<JsonValue>& arkExtraInfoJson)
414 {
415     CHECK_NULL_VOID(arkExtraInfoJson);
416     arkExtraInfoJson->Put("shadow_is_filled", shadow.GetIsFilled());
417     arkExtraInfoJson->Put("drag_shadow_OffsetX", shadow.GetOffset().GetX());
418     arkExtraInfoJson->Put("drag_shadow_OffsetY", shadow.GetOffset().GetY());
419     arkExtraInfoJson->Put("shadow_mask", shadow.GetShadowType() == ShadowType::BLUR);
420     int32_t argb = static_cast<int32_t>(shadow.GetColor().GetValue());
421     arkExtraInfoJson->Put("drag_shadow_argb", argb);
422     int32_t strategy = static_cast<int32_t>(shadow.GetShadowColorStrategy());
423     arkExtraInfoJson->Put("shadow_color_strategy", strategy);
424     arkExtraInfoJson->Put("shadow_corner", shadow.GetBlurRadius());
425     arkExtraInfoJson->Put("shadow_elevation", shadow.GetElevation());
426     arkExtraInfoJson->Put("shadow_is_hardwareacceleration", shadow.GetHardwareAcceleration());
427 }
428 
GetDefaultShadow()429 std::optional<Shadow> DragDropFuncWrapper::GetDefaultShadow()
430 {
431     auto pipelineContext = PipelineContext::GetCurrentContext();
432     CHECK_NULL_RETURN(pipelineContext, std::nullopt);
433     auto shadowTheme = pipelineContext->GetTheme<ShadowTheme>();
434     CHECK_NULL_RETURN(shadowTheme, std::nullopt);
435     auto colorMode = SystemProperties::GetColorMode();
436     auto shadow = shadowTheme->GetShadow(ShadowStyle::OuterFloatingSM, colorMode);
437     shadow.SetIsFilled(true);
438     return shadow;
439 }
440 
GetDefaultBorderRadius()441 std::optional<BorderRadiusProperty> DragDropFuncWrapper::GetDefaultBorderRadius()
442 {
443     BorderRadiusProperty borderRadius;
444     borderRadius.SetRadius(PREVIEW_BORDER_RADIUS);
445     return borderRadius;
446 }
447 
RadiusToSigma(float radius)448 float DragDropFuncWrapper::RadiusToSigma(float radius)
449 {
450     return GreatNotEqual(radius, 0.0f) ? BLUR_SIGMA_SCALE * radius + SCALE_HALF : 0.0f;
451 }
452 
BrulStyleToEffection(const std::optional<BlurStyleOption> & blurStyleOp)453 std::optional<EffectOption> DragDropFuncWrapper::BrulStyleToEffection(
454     const std::optional<BlurStyleOption>& blurStyleOp)
455 {
456     auto pipeline = PipelineContext::GetCurrentContext();
457     CHECK_NULL_RETURN(pipeline, std::nullopt);
458     auto blurStyleTheme = pipeline->GetTheme<BlurStyleTheme>();
459     if (!blurStyleTheme) {
460         LOGW("cannot find theme of blurStyle, create blurStyle failed");
461         return std::nullopt;
462     }
463     ThemeColorMode colorMode = blurStyleOp->colorMode;
464     if (blurStyleOp->colorMode == ThemeColorMode::SYSTEM) {
465         colorMode = SystemProperties::GetColorMode() == ColorMode::DARK ? ThemeColorMode::DARK : ThemeColorMode::LIGHT;
466     }
467     auto blurParam = blurStyleTheme->GetBlurParameter(blurStyleOp->blurStyle, colorMode);
468     CHECK_NULL_RETURN(blurParam, std::nullopt);
469     auto ratio = blurStyleOp->scale;
470     auto maskColor = blurParam->maskColor.BlendOpacity(ratio);
471     auto radiusPx = blurParam->radius * pipeline->GetDipScale();
472     auto radiusBlur = RadiusToSigma(radiusPx) * ratio;
473     auto saturation = (blurParam->saturation - 1) * ratio + 1.0;
474     auto brightness = (blurParam->brightness - 1) * ratio + 1.0;
475     Dimension dimen(radiusBlur);
476     EffectOption bgEffection = {dimen, saturation, brightness, maskColor,
477         blurStyleOp->adaptiveColor, blurStyleOp->blurOption};
478     return std::optional<EffectOption>(bgEffection);
479 }
480 
GetScaleWidth(int32_t containerId)481 [[maybe_unused]] double DragDropFuncWrapper::GetScaleWidth(int32_t containerId)
482 {
483     auto pipeline = Container::GetContainer(containerId)->GetPipelineContext();
484     CHECK_NULL_RETURN(pipeline, -1.0f);
485     return DragDropManager::GetMaxWidthBaseOnGridSystem(pipeline);
486 }
487 
SetExtraInfo(int32_t containerId,std::string extraInfo)488 void DragDropFuncWrapper::SetExtraInfo(int32_t containerId, std::string extraInfo)
489 {
490     auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
491     CHECK_NULL_VOID(pipelineContext);
492     auto manager = pipelineContext->GetDragDropManager();
493     CHECK_NULL_VOID(manager);
494     manager->SetExtraInfo(extraInfo);
495 }
496 
497 } // namespace OHOS::Ace
498