122736c2fSopenharmony_ci/*
222736c2fSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
322736c2fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
422736c2fSopenharmony_ci * you may not use this file except in compliance with the License.
522736c2fSopenharmony_ci * You may obtain a copy of the License at
622736c2fSopenharmony_ci *
722736c2fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
822736c2fSopenharmony_ci *
922736c2fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1022736c2fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1122736c2fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1222736c2fSopenharmony_ci * See the License for the specific language governing permissions and
1322736c2fSopenharmony_ci * limitations under the License.
1422736c2fSopenharmony_ci */
1522736c2fSopenharmony_ci
1622736c2fSopenharmony_ci#include "event_checker.h"
1722736c2fSopenharmony_ci#include <unordered_set>
1822736c2fSopenharmony_ci
1922736c2fSopenharmony_cinamespace OHOS {
2022736c2fSopenharmony_cinamespace MiscServices {
2122736c2fSopenharmony_ciconst std::unordered_set<std::string> EVENT_TYPES[static_cast<uint32_t>(EventSubscribeModule::MODULE_END)] = {
2222736c2fSopenharmony_ci    [static_cast<uint32_t>(EventSubscribeModule::INPUT_METHOD_CONTROLLER)] = { "insertText", "deleteLeft",
2322736c2fSopenharmony_ci        "deleteRight", "sendKeyboardStatus", "sendFunctionKey", "moveCursor", "handleExtendAction", "selectByRange",
2422736c2fSopenharmony_ci        "selectByMovement", "getLeftTextOfCursor", "getRightTextOfCursor", "getTextIndexAtCursor" },
2522736c2fSopenharmony_ci    [static_cast<uint32_t>(EventSubscribeModule::INPUT_METHOD_SETTING)] = { "imeChange", "imeShow", "imeHide" },
2622736c2fSopenharmony_ci    [static_cast<uint32_t>(EventSubscribeModule::INPUT_METHOD_ABILITY)] = { "inputStart", "inputStop", "keyboardShow",
2722736c2fSopenharmony_ci        "keyboardHide", "setCallingWindow", "setSubtype", "securityModeChange", "privateCommand" },
2822736c2fSopenharmony_ci    [static_cast<uint32_t>(EventSubscribeModule::KEYBOARD_DELEGATE)] = { "editorAttributeChanged", "keyDown", "keyUp",
2922736c2fSopenharmony_ci        "keyEvent", "cursorContextChange", "selectionChange", "textChange" },
3022736c2fSopenharmony_ci    [static_cast<uint32_t>(EventSubscribeModule::KEYBOARD_PANEL_MANAGER)] = { "panelPrivateCommand", "isPanelShow" },
3122736c2fSopenharmony_ci    [static_cast<uint32_t>(EventSubscribeModule::PANEL)] = { "show", "hide", "sizeChange" }
3222736c2fSopenharmony_ci};
3322736c2fSopenharmony_ci
3422736c2fSopenharmony_cibool EventChecker::IsValidEventType(EventSubscribeModule module, const std::string &type)
3522736c2fSopenharmony_ci{
3622736c2fSopenharmony_ci    if (module < EventSubscribeModule::MODULE_BEGIN || module >= EventSubscribeModule::MODULE_END) {
3722736c2fSopenharmony_ci        return false;
3822736c2fSopenharmony_ci    }
3922736c2fSopenharmony_ci    return EVENT_TYPES[static_cast<uint32_t>(module)].find(type) != EVENT_TYPES[static_cast<uint32_t>(module)].end();
4022736c2fSopenharmony_ci}
4122736c2fSopenharmony_ci} // namespace MiscServices
4222736c2fSopenharmony_ci} // namespace OHOS