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 "combination_key.h"
17
18 #include <map>
19 #include <set>
20
21 #include "keyboard_event.h"
22
23 namespace OHOS {
24 namespace MiscServices {
25 const std::map<CombinationKeyFunction, std::set<uint8_t>> COMBINATION_KEY_MAP{
26 { CombinationKeyFunction::SWITCH_LANGUAGE, { KeyboardEvent::SHIFT_LEFT_MASK, KeyboardEvent::SHIFT_RIGHT_MASK } },
27 { CombinationKeyFunction::SWITCH_IME,
28 {
29 KeyboardEvent::SHIFT_LEFT_MASK | KeyboardEvent::CTRL_LEFT_MASK,
30 KeyboardEvent::SHIFT_RIGHT_MASK | KeyboardEvent::CTRL_RIGHT_MASK,
31 KeyboardEvent::SHIFT_LEFT_MASK | KeyboardEvent::CTRL_RIGHT_MASK,
32 KeyboardEvent::SHIFT_RIGHT_MASK | KeyboardEvent::CTRL_LEFT_MASK,
33 KeyboardEvent::META_MASK | KeyboardEvent::SPACE_MASK,
34 } },
35 { CombinationKeyFunction::SWITCH_MODE, { KeyboardEvent::CAPS_MASK } },
36 };
37
IsMatch(CombinationKeyFunction combinationKey,uint32_t state)38 bool CombinationKey::IsMatch(CombinationKeyFunction combinationKey, uint32_t state)
39 {
40 IMSA_HILOGD("combinationKey: %{public}d, state: %{public}d.", combinationKey, state);
41 auto expectedKeys = COMBINATION_KEY_MAP.find(combinationKey);
42 if (expectedKeys == COMBINATION_KEY_MAP.end()) {
43 IMSA_HILOGD("unknown key function.");
44 return false;
45 }
46 return expectedKeys->second.find(state) != expectedKeys->second.end();
47 }
48 } // namespace MiscServices
49 } // namespace OHOS