1 /*
2 * Copyright (c) 2023 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 "ohos_adapter/bridge/ark_imf_text_listener_adapter_impl.h"
17
18 #include "ohos_adapter/bridge/ark_imf_adapter_function_key_adapter_wrapper.h"
19
20 #include "base/bridge/ark_web_bridge_macros.h"
21
22 namespace OHOS::ArkWeb {
23
ArkIMFTextListenerAdapterImpl(std::shared_ptr<OHOS::NWeb::IMFTextListenerAdapter> ref)24 ArkIMFTextListenerAdapterImpl::ArkIMFTextListenerAdapterImpl(std::shared_ptr<OHOS::NWeb::IMFTextListenerAdapter> ref)
25 : real_(ref)
26 {}
27
InsertText(const ArkWebU16String & text)28 void ArkIMFTextListenerAdapterImpl::InsertText(const ArkWebU16String& text)
29 {
30 real_->InsertText(ArkWebU16StringStructToClass(text));
31 }
32
DeleteForward(int32_t length)33 void ArkIMFTextListenerAdapterImpl::DeleteForward(int32_t length)
34 {
35 real_->DeleteForward(length);
36 }
37
DeleteBackward(int32_t length)38 void ArkIMFTextListenerAdapterImpl::DeleteBackward(int32_t length)
39 {
40 real_->DeleteBackward(length);
41 }
42
SendKeyEventFromInputMethod()43 void ArkIMFTextListenerAdapterImpl::SendKeyEventFromInputMethod()
44 {
45 real_->SendKeyEventFromInputMethod();
46 }
47
SendKeyboardStatus(const int32_t & keyboardStatus)48 void ArkIMFTextListenerAdapterImpl::SendKeyboardStatus(const int32_t& keyboardStatus)
49 {
50 real_->SendKeyboardStatus((OHOS::NWeb::IMFAdapterKeyboardStatus)keyboardStatus);
51 }
52
SendFunctionKey(ArkWebRefPtr<ArkIMFAdapterFunctionKeyAdapter> functionKey)53 void ArkIMFTextListenerAdapterImpl::SendFunctionKey(ArkWebRefPtr<ArkIMFAdapterFunctionKeyAdapter> functionKey)
54 {
55 if (CHECK_REF_PTR_IS_NULL(functionKey)) {
56 real_->SendFunctionKey(nullptr);
57 }
58
59 real_->SendFunctionKey(std::make_shared<ArkIMFAdapterFunctionKeyAdapterWrapper>(functionKey));
60 }
61
SetKeyboardStatus(bool status)62 void ArkIMFTextListenerAdapterImpl::SetKeyboardStatus(bool status)
63 {
64 real_->SetKeyboardStatus(status);
65 }
66
MoveCursor(const uint32_t direction)67 void ArkIMFTextListenerAdapterImpl::MoveCursor(const uint32_t direction)
68 {
69 real_->MoveCursor((OHOS::NWeb::IMFAdapterDirection)direction);
70 }
71
HandleSetSelection(int32_t start,int32_t end)72 void ArkIMFTextListenerAdapterImpl::HandleSetSelection(int32_t start, int32_t end)
73 {
74 real_->HandleSetSelection(start, end);
75 }
76
HandleExtendAction(int32_t action)77 void ArkIMFTextListenerAdapterImpl::HandleExtendAction(int32_t action)
78 {
79 real_->HandleExtendAction(action);
80 }
81
HandleSelect(int32_t keyCode,int32_t cursorMoveSkip)82 void ArkIMFTextListenerAdapterImpl::HandleSelect(int32_t keyCode, int32_t cursorMoveSkip)
83 {
84 real_->HandleSelect(keyCode, cursorMoveSkip);
85 }
86
GetTextIndexAtCursor()87 int32_t ArkIMFTextListenerAdapterImpl::GetTextIndexAtCursor()
88 {
89 return real_->GetTextIndexAtCursor();
90 }
91
GetLeftTextOfCursor(int32_t number)92 ArkWebU16String ArkIMFTextListenerAdapterImpl::GetLeftTextOfCursor(int32_t number)
93 {
94 std::u16string str = real_->GetLeftTextOfCursor(number);
95
96 return ArkWebU16StringClassToStruct(str);
97 }
98
GetRightTextOfCursor(int32_t number)99 ArkWebU16String ArkIMFTextListenerAdapterImpl::GetRightTextOfCursor(int32_t number)
100 {
101 std::u16string str = real_->GetRightTextOfCursor(number);
102
103 return ArkWebU16StringClassToStruct(str);
104 }
105
SetPreviewText(const ArkWebU16String & text,int32_t start,int32_t end)106 int32_t ArkIMFTextListenerAdapterImpl::SetPreviewText(const ArkWebU16String& text, int32_t start, int32_t end)
107 {
108 return real_->SetPreviewText(ArkWebU16StringStructToClass(text), start, end);
109 }
110
FinishTextPreview()111 void ArkIMFTextListenerAdapterImpl::FinishTextPreview()
112 {
113 real_->FinishTextPreview();
114 }
115
SetNeedUnderLine(bool isNeedUnderline)116 void ArkIMFTextListenerAdapterImpl::SetNeedUnderLine(bool isNeedUnderline)
117 {
118 real_->SetNeedUnderLine(isNeedUnderline);
119 }
120
AutoFillWithIMFEvent(bool isUsername,bool isOtherAccount,bool isNewPassword,const ArkWebString & content)121 void ArkIMFTextListenerAdapterImpl::AutoFillWithIMFEvent(bool isUsername, bool isOtherAccount, bool isNewPassword,
122 const ArkWebString& content)
123 {
124 real_->AutoFillWithIMFEvent(isUsername, isOtherAccount, isNewPassword, ArkWebStringStructToClass(content));
125 }
126
KeyboardUpperRightCornerHide()127 void ArkIMFTextListenerAdapterImpl::KeyboardUpperRightCornerHide()
128 {
129 real_->KeyboardUpperRightCornerHide();
130 }
131 } // namespace OHOS::ArkWeb
132