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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_STYLUS_STYLUS_DETECTOR_CALLBACK_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_STYLUS_STYLUS_DETECTOR_CALLBACK_H
18 
19 #include "interfaces/inner_api/ace/stylus/stylus_detector_interface.h"
20 
21 #include "core/components_ng/base/frame_node.h"
22 #include "core/components_ng/render/paragraph.h"
23 
24 namespace OHOS::Ace {
25 class StylusDetectorCallBack : public OHOS::Ace::IStylusDetectorCallback {
26 public:
27     explicit StylusDetectorCallBack() = default;
28     virtual ~StylusDetectorCallBack() = default;
29     static int32_t RequestFocus(int32_t nodeId, const RefPtr<TaskExecutor>& taskScheduler);
30     static int32_t SetText(int32_t nodeId, void* data, const RefPtr<TaskExecutor>& taskScheduler,
31         std::shared_ptr<IAceStylusCallback> callback);
32     static int32_t GetText(int32_t nodeId, const RefPtr<TaskExecutor>& taskScheduler,
33         std::shared_ptr<IAceStylusCallback> callback);
34     static int32_t DeleteText(int32_t nodeId, void* data, const RefPtr<TaskExecutor>& taskScheduler);
35     static int32_t ChoiceText(int32_t nodeId, void* data, const RefPtr<TaskExecutor>& taskScheduler);
36     static int32_t InsertSpace(int32_t nodeId, void* data, const RefPtr<TaskExecutor>& taskScheduler);
37     static int32_t MoveCursor(int32_t nodeId, void* data, const RefPtr<TaskExecutor>& taskScheduler);
38 
39     static int32_t Redo(int32_t nodeId, const RefPtr<TaskExecutor>& taskScheduler);
40     static int32_t Undo(int32_t nodeId, const RefPtr<TaskExecutor>& taskScheduler);
41     int32_t OnDetector(
42         const CommandType& command, void* data, std::shared_ptr<IAceStylusCallback> callback) override;
43     bool OnDetectorSync(const CommandType& command) override;
44 
45 private:
46     static int32_t HandleMoveCursor(const RefPtr<NG::FrameNode>& frameNode, NG::PositionWithAffinity sInd,
47         bool showHandle);
48     static NG::PositionWithAffinity GetGlyphPositionByGlobalOffset(const RefPtr<NG::FrameNode>& frameNode,
49         const Offset& offset);
50     static std::tuple<int32_t, int32_t, int32_t> CalculateIntersectedRegion(NG::PositionWithAffinity sInd,
51         NG::PositionWithAffinity eInd, int32_t wtextLength);
52     static NG::OffsetF GetPaintRectGlobalOffset(const RefPtr<NG::FrameNode>& frameNode);
53 };
54 } // namespace OHOS::Ace
55 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_STYLUS_STYLUS_DETECTOR_CALLBACK_H