122736c2fSopenharmony_ci/*
222736c2fSopenharmony_ci * Copyright (c) 2022 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 "combination_key.h"
1722736c2fSopenharmony_ci
1822736c2fSopenharmony_ci#include <map>
1922736c2fSopenharmony_ci#include <set>
2022736c2fSopenharmony_ci
2122736c2fSopenharmony_ci#include "keyboard_event.h"
2222736c2fSopenharmony_ci
2322736c2fSopenharmony_cinamespace OHOS {
2422736c2fSopenharmony_cinamespace MiscServices {
2522736c2fSopenharmony_ciconst std::map<CombinationKeyFunction, std::set<uint8_t>> COMBINATION_KEY_MAP{
2622736c2fSopenharmony_ci    { CombinationKeyFunction::SWITCH_LANGUAGE, { KeyboardEvent::SHIFT_LEFT_MASK, KeyboardEvent::SHIFT_RIGHT_MASK } },
2722736c2fSopenharmony_ci    { CombinationKeyFunction::SWITCH_IME,
2822736c2fSopenharmony_ci        {
2922736c2fSopenharmony_ci            KeyboardEvent::SHIFT_LEFT_MASK | KeyboardEvent::CTRL_LEFT_MASK,
3022736c2fSopenharmony_ci            KeyboardEvent::SHIFT_RIGHT_MASK | KeyboardEvent::CTRL_RIGHT_MASK,
3122736c2fSopenharmony_ci            KeyboardEvent::SHIFT_LEFT_MASK | KeyboardEvent::CTRL_RIGHT_MASK,
3222736c2fSopenharmony_ci            KeyboardEvent::SHIFT_RIGHT_MASK | KeyboardEvent::CTRL_LEFT_MASK,
3322736c2fSopenharmony_ci            KeyboardEvent::META_MASK | KeyboardEvent::SPACE_MASK,
3422736c2fSopenharmony_ci        } },
3522736c2fSopenharmony_ci    { CombinationKeyFunction::SWITCH_MODE, { KeyboardEvent::CAPS_MASK } },
3622736c2fSopenharmony_ci};
3722736c2fSopenharmony_ci
3822736c2fSopenharmony_cibool CombinationKey::IsMatch(CombinationKeyFunction combinationKey, uint32_t state)
3922736c2fSopenharmony_ci{
4022736c2fSopenharmony_ci    IMSA_HILOGD("combinationKey: %{public}d, state: %{public}d.", combinationKey, state);
4122736c2fSopenharmony_ci    auto expectedKeys = COMBINATION_KEY_MAP.find(combinationKey);
4222736c2fSopenharmony_ci    if (expectedKeys == COMBINATION_KEY_MAP.end()) {
4322736c2fSopenharmony_ci        IMSA_HILOGD("unknown key function.");
4422736c2fSopenharmony_ci        return false;
4522736c2fSopenharmony_ci    }
4622736c2fSopenharmony_ci    return expectedKeys->second.find(state) != expectedKeys->second.end();
4722736c2fSopenharmony_ci}
4822736c2fSopenharmony_ci} // namespace MiscServices
4922736c2fSopenharmony_ci} // namespace OHOS