• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         } },
34     { CombinationKeyFunction::SWITCH_MODE, { KeyboardEvent::CAPS_MASK } },
35 };
36 
IsMatch(CombinationKeyFunction combinationKey,uint32_t state)37 bool CombinationKey::IsMatch(CombinationKeyFunction combinationKey, uint32_t state)
38 {
39     IMSA_HILOGD("combinationKey: %{public}d, state: %{public}d", combinationKey, state);
40     auto expectedKeys = COMBINATION_KEY_MAP.find(combinationKey);
41     if (expectedKeys == COMBINATION_KEY_MAP.end()) {
42         IMSA_HILOGD("known key function");
43         return false;
44     }
45     return expectedKeys->second.find(state) != expectedKeys->second.end();
46 }
47 } // namespace MiscServices
48 } // namespace OHOS