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 "platform_utils.h"
17
18 namespace OHOS::Ace::NG {
CopyPointerEventWithExtraProperty(const std::shared_ptr<MMI::PointerEvent> & pointerEvent,const AceLogTag aceLogTag)19 std::shared_ptr<MMI::PointerEvent> PlatformUtils::CopyPointerEventWithExtraProperty(
20 const std::shared_ptr<MMI::PointerEvent>& pointerEvent, const AceLogTag aceLogTag)
21 {
22 if (!pointerEvent) {
23 TAG_LOGW(aceLogTag, "The PointerEvent is null");
24 return nullptr;
25 }
26 std::shared_ptr<MMI::PointerEvent> newPointerEvent = std::make_shared<MMI::PointerEvent>(*pointerEvent);
27 CHECK_NULL_RETURN(newPointerEvent, nullptr);
28
29 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
30 newPointerEvent->SetEnhanceData(pointerEvent->GetEnhanceData());
31 #endif //OHOS_BUILD_ENABLE_SECURITY_COMPONENT
32 #ifdef OHOS_BUILD_ENABLE_ANCO
33 newPointerEvent->SetAncoDeal(pointerEvent->GetAncoDeal());
34 #endif //OHOS_BUILD_ENABLE_ANCO
35
36 newPointerEvent->SetHandlerEventType(pointerEvent->GetHandlerEventType());
37 // Copy extra property
38 std::shared_ptr<const uint8_t[]> raw;
39 uint32_t length = 0;
40 pointerEvent->GetExtraData(raw, length);
41 if (length == 0 || !raw) {
42 TAG_LOGW(aceLogTag, "The PointerEvent has no extra data.");
43 } else {
44 newPointerEvent->SetExtraData(raw, length);
45 }
46 newPointerEvent->SetSensorInputTime(pointerEvent->GetSensorInputTime());
47
48 return newPointerEvent;
49 }
50 } // namespace OHOS::Ace::NG