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
19namespace OHOS {
20namespace MiscServices {
21const 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" },
25    [static_cast<uint32_t>(EventSubscribeModule::INPUT_METHOD_SETTING)] = { "imeChange", "imeShow", "imeHide" },
26    [static_cast<uint32_t>(EventSubscribeModule::INPUT_METHOD_ABILITY)] = { "inputStart", "inputStop", "keyboardShow",
27        "keyboardHide", "setCallingWindow", "setSubtype", "securityModeChange", "privateCommand" },
28    [static_cast<uint32_t>(EventSubscribeModule::KEYBOARD_DELEGATE)] = { "editorAttributeChanged", "keyDown", "keyUp",
29        "keyEvent", "cursorContextChange", "selectionChange", "textChange" },
30    [static_cast<uint32_t>(EventSubscribeModule::KEYBOARD_PANEL_MANAGER)] = { "panelPrivateCommand", "isPanelShow" },
31    [static_cast<uint32_t>(EventSubscribeModule::PANEL)] = { "show", "hide", "sizeChange" }
32};
33
34bool EventChecker::IsValidEventType(EventSubscribeModule module, const std::string &type)
35{
36    if (module < EventSubscribeModule::MODULE_BEGIN || module >= EventSubscribeModule::MODULE_END) {
37        return false;
38    }
39    return EVENT_TYPES[static_cast<uint32_t>(module)].find(type) != EVENT_TYPES[static_cast<uint32_t>(module)].end();
40}
41} // namespace MiscServices
42} // namespace OHOS