1 /* 2 * Copyright (c) 2022 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 "common/input_method_manager.h" 17 18 #include "components/ui_edit_text.h" 19 #include "gfx_utils/graphic_log.h" 20 #include "hal_tick.h" 21 22 namespace OHOS { GetInstance()23InputMethodManager& InputMethodManager::GetInstance() 24 { 25 static InputMethodManager InputMethodManager; 26 return InputMethodManager; 27 } 28 ShowInputMethod(UIView * view)29void InputMethodManager::ShowInputMethod(UIView* view) 30 { 31 if (view == nullptr) { 32 return; 33 } 34 35 if (inputMethodListener_ == nullptr) { 36 return; 37 } 38 39 inputView_ = view; 40 UIViewType viewType = view->GetViewType(); 41 if (viewType == UI_EDIT_TEXT) { 42 UIEditText* tmpView = reinterpret_cast<UIEditText*>(view); 43 InputMethodParam param; 44 param.view = view; 45 param.inputType = tmpView->GetInputType(); 46 47 if (tmpView->GetText() != nullptr) { 48 param.text = tmpView->GetText(); 49 } 50 51 inputMethodListener_->OnShow(param); 52 } 53 } 54 HideInputMethod()55void InputMethodManager::HideInputMethod() 56 { 57 if (inputMethodListener_ == nullptr) { 58 return; 59 } 60 61 inputMethodListener_->OnHide(); 62 } 63 SetInputMethodListener(InputMethodListener * listener)64void InputMethodManager::SetInputMethodListener(InputMethodListener* listener) 65 { 66 inputMethodListener_ = listener; 67 } 68 InsertText(std::string text)69void InputMethodManager::InsertText(std::string text) 70 { 71 if (inputView_ == nullptr) { 72 return; 73 } 74 75 UIViewType viewType = inputView_->GetViewType(); 76 if (viewType == UI_EDIT_TEXT) { 77 UIEditText* tmpView = reinterpret_cast<UIEditText*>(inputView_); 78 tmpView->InsertText(text); 79 } 80 } 81 DeleteBackward(uint16_t length)82void InputMethodManager::DeleteBackward(uint16_t length) 83 { 84 if (inputView_ == nullptr) { 85 return; 86 } 87 88 UIViewType viewType = inputView_->GetViewType(); 89 if (viewType == UI_EDIT_TEXT) { 90 UIEditText* tmpView = reinterpret_cast<UIEditText*>(inputView_); 91 tmpView->DeleteBackward(length); 92 } 93 } 94 SetInputType(InputType type)95void InputMethodManager::SetInputType(InputType type) 96 { 97 if (inputView_ == nullptr) { 98 return; 99 } 100 101 UIViewType viewType = inputView_->GetViewType(); 102 if (viewType == UI_EDIT_TEXT) { 103 UIEditText* tmpView = reinterpret_cast<UIEditText*>(inputView_); 104 tmpView->SetInputType(type); 105 } 106 } 107 OnKeyboardShow()108void InputMethodManager::OnKeyboardShow() {} 109 OnKeyboardHide()110void InputMethodManager::OnKeyboardHide() {} 111 } // namespace OHOS 112