1 /*
2  * Copyright (C) 2024-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 FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_TASKS_TASK_IMSA_H
17 #define FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_TASKS_TASK_IMSA_H
18 
19 #include "task.h"
20 
21 #include "input_attribute.h"
22 #include "input_client_info.h"
23 #include "input_method_ability.h"
24 #include "input_method_property.h"
25 #include "iremote_object.h"
26 
27 namespace OHOS {
28 namespace MiscServices {
29 
30 class TaskImsaStartInput : public Task {
31 public:
TaskImsaStartInput(const InputClientInfo &client, bool fromClient)32     TaskImsaStartInput(const InputClientInfo &client, bool fromClient) : Task(TASK_TYPE_IMSA_START_INPUT)
33     {
34         auto func = [=]() {
35             InputMethodAbility::GetInstance()->StartInput(client, fromClient);
36         };
37         actions_.emplace_back(std::make_unique<Action>(func));
38     }
39     ~TaskImsaStartInput() = default;
40 };
41 
42 class TaskImsaStopInput : public Task {
43 public:
TaskImsaStopInput(sptr<IRemoteObject> channel)44     explicit TaskImsaStopInput(sptr<IRemoteObject> channel) : Task(TASK_TYPE_IMSA_STOP_INPUT)
45     {
46         auto func = [=]() {
47             InputMethodAbility::GetInstance()->StopInput(channel);
48         };
49         actions_.emplace_back(std::make_unique<Action>(func));
50     }
51     ~TaskImsaStopInput() = default;
52 };
53 
54 class TaskImsaShowKeyboard : public Task {
55 public:
TaskImsaShowKeyboard()56     TaskImsaShowKeyboard() : Task(TASK_TYPE_IMSA_SHOW_KEYBOARD)
57     {
58         auto func = [=]() {
59             InputMethodAbility::GetInstance()->ShowKeyboard();
60         };
61         actions_.emplace_back(std::make_unique<Action>(func));
62     }
63     ~TaskImsaShowKeyboard() = default;
64 };
65 
66 class TaskImsaHideKeyboard : public Task {
67 public:
TaskImsaHideKeyboard(bool force)68     explicit TaskImsaHideKeyboard(bool force) : Task(TASK_TYPE_IMSA_HIDE_KEYBOARD)
69     {
70         auto func = [=]() {
71             InputMethodAbility::GetInstance()->HideKeyboard(force);
72         };
73         actions_.emplace_back(std::make_unique<Action>(func));
74     }
75     ~TaskImsaHideKeyboard() = default;
76 };
77 
78 class TaskImsaOnClientInactive : public Task {
79 public:
TaskImsaOnClientInactive(sptr<IRemoteObject> channel)80     explicit TaskImsaOnClientInactive(sptr<IRemoteObject> channel) : Task(TASK_TYPE_IMSA_CLIENT_INACTIVE)
81     {
82         auto func = [=]() {
83             InputMethodAbility::GetInstance()->OnClientInactive(channel);
84         };
85         actions_.emplace_back(std::make_unique<Action>(func));
86     }
87     ~TaskImsaOnClientInactive() = default;
88 };
89 
90 class TaskImsaInitInputCtrlChannel : public Task {
91 public:
TaskImsaInitInputCtrlChannel(sptr<IRemoteObject> channel)92     explicit TaskImsaInitInputCtrlChannel(sptr<IRemoteObject> channel) : Task(TASK_TYPE_IMSA_INIT_INPUT_CTRL_CHANNEL)
93     {
94         auto func = [=]() {
95             InputMethodAbility::GetInstance()->OnInitInputControlChannel(channel);
96         };
97         actions_.emplace_back(std::make_unique<Action>(func));
98     }
99     ~TaskImsaInitInputCtrlChannel() = default;
100 };
101 
102 class TaskImsaOnCursorUpdate : public Task {
103 public:
TaskImsaOnCursorUpdate(int32_t x, int32_t y, int32_t h)104     TaskImsaOnCursorUpdate(int32_t x, int32_t y, int32_t h) : Task(TASK_TYPE_IMSA_CURSOR_UPDATE)
105     {
106         auto func = [=]() {
107             InputMethodAbility::GetInstance()->OnCursorUpdate(x, y, h);
108         };
109         actions_.emplace_back(std::make_unique<Action>(func));
110     }
111     ~TaskImsaOnCursorUpdate() = default;
112 };
113 
114 class TaskImsaOnSelectionChange : public Task {
115 public:
TaskImsaOnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd)116     TaskImsaOnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd)
117         : Task(TASK_TYPE_IMSA_SELECTION_CHANGE)
118     {
119         auto func = [=]() {
120             InputMethodAbility::GetInstance()->OnSelectionChange(text, oldBegin, oldEnd, newBegin, newEnd);
121         };
122         actions_.emplace_back(std::make_unique<Action>(func));
123     }
124     ~TaskImsaOnSelectionChange() = default;
125 };
126 
127 class TaskImsaAttributeChange : public Task {
128 public:
TaskImsaAttributeChange(InputAttribute attr)129     explicit TaskImsaAttributeChange(InputAttribute attr) : Task(TASK_TYPE_IMSA_ATTRIBUTE_CHANGE)
130     {
131         auto func = [=]() {
132             InputMethodAbility::GetInstance()->OnAttributeChange(attr);
133         };
134         actions_.emplace_back(std::make_unique<Action>(func));
135     }
136     ~TaskImsaAttributeChange() = default;
137 };
138 
139 class TaskImsaStopInputService : public Task {
140 public:
TaskImsaStopInputService(bool isTerminateIme)141     explicit TaskImsaStopInputService(bool isTerminateIme) : Task(TASK_TYPE_IMSA_STOP_INPUT_SERVICE)
142     {
143         auto func = [=]() {
144             InputMethodAbility::GetInstance()->OnStopInputService(isTerminateIme);
145         };
146         actions_.emplace_back(std::make_unique<Action>(func));
147     }
148     ~TaskImsaStopInputService() = default;
149 };
150 
151 class TaskImsaOnSetSubProperty : public Task {
152 public:
TaskImsaOnSetSubProperty(SubProperty prop)153     explicit TaskImsaOnSetSubProperty(SubProperty prop) : Task(TASK_TYPE_IMSA_SET_SUBPROPERTY)
154     {
155         auto func = [=]() {
156             InputMethodAbility::GetInstance()->OnSetSubtype(prop);
157         };
158         actions_.emplace_back(std::make_unique<Action>(func));
159     }
160     ~TaskImsaOnSetSubProperty() = default;
161 };
162 
163 class TaskImsaSetCoreAndAgent : public Task {
164 public:
TaskImsaSetCoreAndAgent()165     TaskImsaSetCoreAndAgent() : Task(TASK_TYPE_IMSA_SET_CORE_AND_AGENT)
166     {
167         auto func = [=]() {
168             InputMethodAbility::GetInstance()->SetCoreAndAgent();
169         };
170         actions_.emplace_back(std::make_unique<Action>(func));
171     }
172     ~TaskImsaSetCoreAndAgent() = default;
173 };
174 
175 } // namespace MiscServices
176 } // namespace OHOS
177 
178 #endif // FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_TASKS_TASK_IMSA_H