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_INTERFACE_INNERKITS_STYLUS_STYLUS_DETECTOR_INTERFACE_H
17 #define FOUNDATION_ACE_INTERFACE_INNERKITS_STYLUS_STYLUS_DETECTOR_INTERFACE_H
18 
19 #include <functional>
20 #include <memory>
21 #include <optional>
22 #include <string>
23 
24 namespace OHOS::Ace {
25 struct NotifyInfo {
26     int componentId;
27     int x;
28     int y;
29     std::string bundleName;
30 };
31 
32 struct ResultData {
33     int errorCode;
34     std::string errorMessage;
35     std::string resultData;
36 };
37 
38 enum CommandType {
39     COMMAND_REQUEST_FOCUS,
40     COMMAND_CLEAR_HIT,
41     COMMAND_SET_TEXT,
42     COMMAND_GET_TEXT,
43     COMMAND_UNDO,
44     COMMAND_REDO,
45     COMMAND_CANUNDO,
46     COMMAND_CANREDO,
47     COMMAND_DELETE_TEXT,
48     COMMAND_CHOICE_TEXT,
49     COMMAND_INSERT_SPACE,
50     COMMAND_MOVE_CURSOR,
51     COMMAND_INVALID
52 };
53 
54 struct Command {
55     CommandType commandType;
56 };
57 
58 struct StylusGestureRect {
59     float Left;
60     float Top;
61     float Width;
62     float Height;
63 };
64 
65 struct MoveCursorOption {
66     int32_t x;
67     int32_t y;
68     bool showHandle;
69 };
70 
71 struct ChoiceTextOption {
72     StylusGestureRect rect;
73     bool showMenu;
74 };
75 
76 class IAceStylusCallback {
77 public:
78     virtual ~IAceStylusCallback() = default;
79     virtual void Callback(ResultData resultData) = 0;
80 };
81 
82 class IStylusDetectorCallback {
83 public:
84     virtual ~IStylusDetectorCallback() = default;
85     virtual int32_t OnDetector(const CommandType& command, void* data, std::shared_ptr<IAceStylusCallback> callback);
86     virtual bool OnDetectorSync(const CommandType& command);
87 };
88 
89 class StylusDetectorInterface {
90 public:
91     virtual bool IsEnable() = 0;
92     virtual bool RegisterStylusInteractionListener(const std::string& bundleName,
93         const std::shared_ptr<IStylusDetectorCallback>& callback) = 0;
94     virtual void UnRegisterStylusInteractionListener(const std::string& bundleName) = 0;
95     virtual bool Notify(const NotifyInfo& notifyInfo) = 0;
96 
97 protected:
~StylusDetectorInterface()98     virtual ~StylusDetectorInterface() {}
99 };
100 } // namespace OHOS::Ace
101 #endif // FOUNDATION_ACE_INTERFACE_INNERKITS_STYLUS_STYLUS_DETECTOR_INTERFACE_H