• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 "input_method_agent_proxy.h"
17 #include "global.h"
18 #include "message_option.h"
19 
20 namespace OHOS {
21 namespace MiscServices {
22     using namespace ErrorCode;
InputMethodAgentProxy(const sptr<IRemoteObject> & object)23     InputMethodAgentProxy::InputMethodAgentProxy(const sptr<IRemoteObject> &object)
24         : IRemoteProxy<IInputMethodAgent>(object)
25     {
26     }
27 
DispatchKeyEvent(MessageParcel & data)28     bool InputMethodAgentProxy::DispatchKeyEvent(MessageParcel& data)
29     {
30         MessageParcel reply;
31         MessageOption option;
32 
33         auto ret = Remote()->SendRequest(DISPATCH_KEY_EVENT, data, reply, option);
34         if (ret != NO_ERROR) {
35             IMSA_HILOGE("InputMethodAgentProxy::DispatchKeyEvent SendRequest failed");
36         }
37         ret = reply.ReadBool();
38         return ret;
39     }
40 
OnCursorUpdate(int32_t positionX,int32_t positionY,int32_t height)41     void InputMethodAgentProxy::OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height)
42     {
43         MessageParcel data;
44         MessageParcel reply;
45         MessageOption option;
46         if (!data.WriteInterfaceToken(GetDescriptor())) {
47             IMSA_HILOGE("InputMethodAgentProxy::OnCursorUpdate descriptor is not match");
48             return;
49         }
50 
51         data.WriteInt32(positionX);
52         data.WriteInt32(positionY);
53         data.WriteInt32(height);
54 
55         Remote()->SendRequest(ON_CURSOR_UPDATE, data, reply, option);
56     }
57 
OnSelectionChange(std::u16string text,int32_t oldBegin,int32_t oldEnd,int32_t newBegin,int32_t newEnd)58     void InputMethodAgentProxy::OnSelectionChange(std::u16string text, int32_t oldBegin, int32_t oldEnd,
59                                                   int32_t newBegin, int32_t newEnd)
60     {
61         MessageParcel data;
62         MessageParcel reply;
63         MessageOption option;
64         if (!data.WriteInterfaceToken(GetDescriptor())) {
65             IMSA_HILOGE("InputMethodAgentProxy::OnSelectionChange descriptor is not match");
66             return;
67         }
68 
69         data.WriteString16(text);
70         data.WriteInt32(oldBegin);
71         data.WriteInt32(oldEnd);
72         data.WriteInt32(newBegin);
73         data.WriteInt32(newEnd);
74 
75         Remote()->SendRequest(ON_SELECTION_CHANGE, data, reply, option);
76     }
77 
SetCallingWindow(uint32_t windowId)78     void InputMethodAgentProxy::SetCallingWindow(uint32_t windowId)
79     {
80         MessageParcel data;
81         MessageParcel reply;
82         MessageOption option;
83         if (!data.WriteInterfaceToken(GetDescriptor())) {
84             IMSA_HILOGE("InputMethodAgentProxy::SetCallingWindow descriptor is not match");
85             return;
86         }
87 
88         data.WriteUint32(windowId);
89         Remote()->SendRequest(SET_CALLING_WINDOW_ID, data, reply, option);
90     }
91 } // namespace MiscServices
92 } // namespace OHOS
93