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 "event_checker.h"
17 #include <unordered_set>
18
19 namespace OHOS {
20 namespace MiscServices {
21 const std::unordered_set<std::string> EVENT_TYPES[static_cast<uint32_t>(EventSubscribeModule::MODULE_END)] = {
22 [static_cast<uint32_t>(EventSubscribeModule::INPUT_METHOD_CONTROLLER)] = { "insertText", "deleteLeft",
23 "deleteRight", "sendKeyboardStatus", "sendFunctionKey", "moveCursor", "handleExtendAction", "selectByRange",
24 "selectByMovement", "getLeftTextOfCursor", "getRightTextOfCursor", "getTextIndexAtCursor", "setPreviewText",
25 "finishTextPreview" },
26 [static_cast<uint32_t>(EventSubscribeModule::INPUT_METHOD_SETTING)] = { "imeChange", "imeShow", "imeHide" },
27 [static_cast<uint32_t>(EventSubscribeModule::INPUT_METHOD_ABILITY)] = { "inputStart", "inputStop", "keyboardShow",
28 "keyboardHide", "setCallingWindow", "setSubtype", "securityModeChange", "privateCommand",
29 "callingDisplayDidChange", "discardTypingText" },
30 [static_cast<uint32_t>(EventSubscribeModule::KEYBOARD_DELEGATE)] = { "editorAttributeChanged", "keyDown", "keyUp",
31 "keyEvent", "cursorContextChange", "selectionChange", "textChange" },
32 [static_cast<uint32_t>(EventSubscribeModule::KEYBOARD_PANEL_MANAGER)] = { "panelPrivateCommand", "isPanelShow" },
33 [static_cast<uint32_t>(EventSubscribeModule::PANEL)] = { "show", "hide", "sizeChange", "sizeUpdate" },
34 [static_cast<uint32_t>(EventSubscribeModule::TEXT_INPUT_CLIENT)] = { "attachOptionsDidChange" }
35 };
36
IsValidEventType(EventSubscribeModule module,const std::string & type)37 bool EventChecker::IsValidEventType(EventSubscribeModule module, const std::string &type)
38 {
39 if (module < EventSubscribeModule::MODULE_BEGIN || module >= EventSubscribeModule::MODULE_END) {
40 return false;
41 }
42 return EVENT_TYPES[static_cast<uint32_t>(module)].find(type) != EVENT_TYPES[static_cast<uint32_t>(module)].end();
43 }
44 } // namespace MiscServices
45 } // namespace OHOS