1c29fa5a6Sopenharmony_ci/* 2c29fa5a6Sopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License. 5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at 6c29fa5a6Sopenharmony_ci * 7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c29fa5a6Sopenharmony_ci * 9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and 13c29fa5a6Sopenharmony_ci * limitations under the License. 14c29fa5a6Sopenharmony_ci */ 15c29fa5a6Sopenharmony_ci 16c29fa5a6Sopenharmony_ci#ifndef KEY_OPTION_H 17c29fa5a6Sopenharmony_ci#define KEY_OPTION_H 18c29fa5a6Sopenharmony_ci 19c29fa5a6Sopenharmony_ci#include <set> 20c29fa5a6Sopenharmony_ci#include "nocopyable.h" 21c29fa5a6Sopenharmony_ci#include "parcel.h" 22c29fa5a6Sopenharmony_ci 23c29fa5a6Sopenharmony_cinamespace OHOS { 24c29fa5a6Sopenharmony_cinamespace MMI { 25c29fa5a6Sopenharmony_ciclass KeyOption { 26c29fa5a6Sopenharmony_cipublic: 27c29fa5a6Sopenharmony_ci KeyOption() = default; 28c29fa5a6Sopenharmony_ci DISALLOW_COPY_AND_MOVE(KeyOption); 29c29fa5a6Sopenharmony_ci 30c29fa5a6Sopenharmony_cipublic: 31c29fa5a6Sopenharmony_ci /** 32c29fa5a6Sopenharmony_ci * @brief Obtains previous keys. 33c29fa5a6Sopenharmony_ci * @return Returns previous keys. 34c29fa5a6Sopenharmony_ci * @since 9 35c29fa5a6Sopenharmony_ci */ 36c29fa5a6Sopenharmony_ci std::set<int32_t> GetPreKeys() const; 37c29fa5a6Sopenharmony_ci 38c29fa5a6Sopenharmony_ci /** 39c29fa5a6Sopenharmony_ci * @brief Sets previous keys, that is, the keys that are pressed first in a combination key. 40c29fa5a6Sopenharmony_ci * There is no requirement on the sequence of previous keys. 41c29fa5a6Sopenharmony_ci * @param preKeys Indicates the previous keys to set. 42c29fa5a6Sopenharmony_ci * @return void 43c29fa5a6Sopenharmony_ci * @since 9 44c29fa5a6Sopenharmony_ci */ 45c29fa5a6Sopenharmony_ci void SetPreKeys(const std::set<int32_t>& preKeys); 46c29fa5a6Sopenharmony_ci 47c29fa5a6Sopenharmony_ci /** 48c29fa5a6Sopenharmony_ci * @brief Obtains the final key. 49c29fa5a6Sopenharmony_ci * @return Returns the final key. 50c29fa5a6Sopenharmony_ci * @since 9 51c29fa5a6Sopenharmony_ci */ 52c29fa5a6Sopenharmony_ci int32_t GetFinalKey() const; 53c29fa5a6Sopenharmony_ci 54c29fa5a6Sopenharmony_ci /** 55c29fa5a6Sopenharmony_ci * @brief Sets the final key, that is, the key that is last pressed or released in a combination key. 56c29fa5a6Sopenharmony_ci * @param finalKey Indicates the final key. 57c29fa5a6Sopenharmony_ci * @return void 58c29fa5a6Sopenharmony_ci * @since 9 59c29fa5a6Sopenharmony_ci */ 60c29fa5a6Sopenharmony_ci void SetFinalKey(int32_t finalKey); 61c29fa5a6Sopenharmony_ci 62c29fa5a6Sopenharmony_ci /** 63c29fa5a6Sopenharmony_ci * @brief Checks whether the final key in a combination key is pressed or released. 64c29fa5a6Sopenharmony_ci * @return Returns <b>true</b> if the key is pressed; returns <b>false</b> if the key is released. 65c29fa5a6Sopenharmony_ci * @since 9 66c29fa5a6Sopenharmony_ci */ 67c29fa5a6Sopenharmony_ci bool IsFinalKeyDown() const; 68c29fa5a6Sopenharmony_ci 69c29fa5a6Sopenharmony_ci /** 70c29fa5a6Sopenharmony_ci * @brief Sets whether the final key in a combination key is pressed or released. 71c29fa5a6Sopenharmony_ci * @param pressed Indicates whether the key is pressed. The value <b>true</b> means that the key 72c29fa5a6Sopenharmony_ci * is pressed, and the value <b>false</b> means that the key is released. 73c29fa5a6Sopenharmony_ci * @return void 74c29fa5a6Sopenharmony_ci * @since 9 75c29fa5a6Sopenharmony_ci */ 76c29fa5a6Sopenharmony_ci void SetFinalKeyDown(bool pressed); 77c29fa5a6Sopenharmony_ci 78c29fa5a6Sopenharmony_ci /** 79c29fa5a6Sopenharmony_ci * @brief Obtains the duration when the final key is held down or the maximum duration between 80c29fa5a6Sopenharmony_ci * when the key is pressed and when the key is released. 81c29fa5a6Sopenharmony_ci * If the final key is pressed, this parameter indicates the duration when the final key is held down. 82c29fa5a6Sopenharmony_ci * If the last key is released, this parameter indicates the maximum duration between when the key 83c29fa5a6Sopenharmony_ci * is pressed and when the key is released. 84c29fa5a6Sopenharmony_ci * @return Returns the duration when the final key is held down or the maximum duration between 85c29fa5a6Sopenharmony_ci * when the key is pressed and when the key is released. 86c29fa5a6Sopenharmony_ci * @since 9 87c29fa5a6Sopenharmony_ci */ 88c29fa5a6Sopenharmony_ci int32_t GetFinalKeyDownDuration() const; 89c29fa5a6Sopenharmony_ci 90c29fa5a6Sopenharmony_ci /** 91c29fa5a6Sopenharmony_ci * @brief Get the delay time of lifting the last key. When the last key is lifted, the subscription 92c29fa5a6Sopenharmony_ci * will be delayed and triggered. 93c29fa5a6Sopenharmony_ci * @return Return to the delay time of lifting the last key. 94c29fa5a6Sopenharmony_ci * @since 9 95c29fa5a6Sopenharmony_ci */ 96c29fa5a6Sopenharmony_ci int32_t GetFinalKeyUpDelay() const; 97c29fa5a6Sopenharmony_ci 98c29fa5a6Sopenharmony_ci /** 99c29fa5a6Sopenharmony_ci * @brief Sets the duration when the final key is held down or the maximum duration between when 100c29fa5a6Sopenharmony_ci * the key is pressed and when the key is released. 101c29fa5a6Sopenharmony_ci * If the final key is pressed, this parameter indicates the duration when the final key is held down. 102c29fa5a6Sopenharmony_ci * If the last key is released, this parameter indicates the maximum duration between when the key 103c29fa5a6Sopenharmony_ci * is pressed and when the key is released. 104c29fa5a6Sopenharmony_ci * @param duration Indicates the duration when the final key is held down or the maximum duration 105c29fa5a6Sopenharmony_ci * between when the key is pressed and when the key is released. 106c29fa5a6Sopenharmony_ci * @return void 107c29fa5a6Sopenharmony_ci * @since 9 108c29fa5a6Sopenharmony_ci */ 109c29fa5a6Sopenharmony_ci void SetFinalKeyDownDuration(int32_t duration); 110c29fa5a6Sopenharmony_ci 111c29fa5a6Sopenharmony_ci /** 112c29fa5a6Sopenharmony_ci * @brief Set the delay time for lifting the last key. 113c29fa5a6Sopenharmony_ci * @param delay Delay time for lifting the last key. 114c29fa5a6Sopenharmony_ci * @return void 115c29fa5a6Sopenharmony_ci * @since 9 116c29fa5a6Sopenharmony_ci */ 117c29fa5a6Sopenharmony_ci void SetFinalKeyUpDelay(int32_t delay); 118c29fa5a6Sopenharmony_ci 119c29fa5a6Sopenharmony_ci bool IsRepeat() const; 120c29fa5a6Sopenharmony_ci 121c29fa5a6Sopenharmony_ci void SetRepeat(bool repeat); 122c29fa5a6Sopenharmony_ci 123c29fa5a6Sopenharmony_cipublic: 124c29fa5a6Sopenharmony_ci /** 125c29fa5a6Sopenharmony_ci * @brief Writes data to a <b>Parcel</b> object. 126c29fa5a6Sopenharmony_ci * @param out Indicates the object into which data will be written. 127c29fa5a6Sopenharmony_ci * @return Returns <b>true</b> if the data is successfully written; returns <b>false</b> otherwise. 128c29fa5a6Sopenharmony_ci * @since 9 129c29fa5a6Sopenharmony_ci */ 130c29fa5a6Sopenharmony_ci bool WriteToParcel(Parcel &out) const; 131c29fa5a6Sopenharmony_ci 132c29fa5a6Sopenharmony_ci /** 133c29fa5a6Sopenharmony_ci * @brief Reads data from a <b>Parcel</b> object. 134c29fa5a6Sopenharmony_ci * @param in Indicates the object from which data will be read. 135c29fa5a6Sopenharmony_ci * @return Returns <b>true</b> if the data is successfully read; returns <b>false</b> otherwise. 136c29fa5a6Sopenharmony_ci * @since 9 137c29fa5a6Sopenharmony_ci */ 138c29fa5a6Sopenharmony_ci bool ReadFromParcel(Parcel &in); 139c29fa5a6Sopenharmony_ci 140c29fa5a6Sopenharmony_ciprivate: 141c29fa5a6Sopenharmony_ci std::set<int32_t> preKeys_ {}; 142c29fa5a6Sopenharmony_ci int32_t finalKey_ { -1 }; 143c29fa5a6Sopenharmony_ci bool isFinalKeyDown_ { false }; 144c29fa5a6Sopenharmony_ci int32_t finalKeyDownDuration_ { 0 }; 145c29fa5a6Sopenharmony_ci int32_t finalKeyUpDelay_ { 0 }; 146c29fa5a6Sopenharmony_ci bool isRepeat_ { true }; 147c29fa5a6Sopenharmony_ci}; 148c29fa5a6Sopenharmony_ci} // namespace MMI 149c29fa5a6Sopenharmony_ci} // namespace OHOS 150c29fa5a6Sopenharmony_ci#endif // KEY_OPTION_H 151