12d4d9a4dSopenharmony_ci/* 22d4d9a4dSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 32d4d9a4dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 42d4d9a4dSopenharmony_ci * you may not use this file except in compliance with the License. 52d4d9a4dSopenharmony_ci * You may obtain a copy of the License at 62d4d9a4dSopenharmony_ci * 72d4d9a4dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 82d4d9a4dSopenharmony_ci * 92d4d9a4dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 102d4d9a4dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 112d4d9a4dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 122d4d9a4dSopenharmony_ci * See the License for the specific language governing permissions and 132d4d9a4dSopenharmony_ci * limitations under the License. 142d4d9a4dSopenharmony_ci */ 152d4d9a4dSopenharmony_ci 162d4d9a4dSopenharmony_ci#include "touchpad_event_fragment.h" 172d4d9a4dSopenharmony_ci 182d4d9a4dSopenharmony_cinamespace OHOS { 192d4d9a4dSopenharmony_cinamespace DistributedHardware { 202d4d9a4dSopenharmony_cinamespace DistributedInput { 212d4d9a4dSopenharmony_cinamespace { 222d4d9a4dSopenharmony_ci constexpr size_t MIN_EVENT_FRAG_SIZE = 2; 232d4d9a4dSopenharmony_ci} 242d4d9a4dSopenharmony_cibool TouchPadEventFragment::IsShouldDrop() 252d4d9a4dSopenharmony_ci{ 262d4d9a4dSopenharmony_ci return events.size() == MIN_EVENT_FRAG_SIZE; 272d4d9a4dSopenharmony_ci} 282d4d9a4dSopenharmony_ci 292d4d9a4dSopenharmony_cibool TouchPadEventFragment::IsTouchPadOptFinish() const 302d4d9a4dSopenharmony_ci{ 312d4d9a4dSopenharmony_ci bool isFinish = false; 322d4d9a4dSopenharmony_ci for (const auto &ev : events) { 332d4d9a4dSopenharmony_ci if (ev.type == EV_KEY && ev.code == BTN_TOUCH && ev.value == KEY_UP_STATE) { 342d4d9a4dSopenharmony_ci isFinish = true; 352d4d9a4dSopenharmony_ci break; 362d4d9a4dSopenharmony_ci } 372d4d9a4dSopenharmony_ci } 382d4d9a4dSopenharmony_ci 392d4d9a4dSopenharmony_ci return isFinish; 402d4d9a4dSopenharmony_ci} 412d4d9a4dSopenharmony_ci 422d4d9a4dSopenharmony_cibool TouchPadEventFragment::IsTouchPadOptStart() const 432d4d9a4dSopenharmony_ci{ 442d4d9a4dSopenharmony_ci bool isStart = false; 452d4d9a4dSopenharmony_ci for (const auto &ev : events) { 462d4d9a4dSopenharmony_ci if (ev.type == EV_KEY && ev.code == BTN_TOUCH && ev.value == KEY_DOWN_STATE) { 472d4d9a4dSopenharmony_ci isStart = true; 482d4d9a4dSopenharmony_ci break; 492d4d9a4dSopenharmony_ci } 502d4d9a4dSopenharmony_ci } 512d4d9a4dSopenharmony_ci 522d4d9a4dSopenharmony_ci return isStart; 532d4d9a4dSopenharmony_ci} 542d4d9a4dSopenharmony_ci 552d4d9a4dSopenharmony_civoid TouchPadEventFragment::PushEvent(const RawEvent &event) 562d4d9a4dSopenharmony_ci{ 572d4d9a4dSopenharmony_ci this->events.push_back(event); 582d4d9a4dSopenharmony_ci} 592d4d9a4dSopenharmony_ci 602d4d9a4dSopenharmony_cistd::vector<RawEvent> TouchPadEventFragment::GetEvents() 612d4d9a4dSopenharmony_ci{ 622d4d9a4dSopenharmony_ci return this->events; 632d4d9a4dSopenharmony_ci} 642d4d9a4dSopenharmony_ci} // namespace DistributedInput 652d4d9a4dSopenharmony_ci} // namespace DistributedHardware 662d4d9a4dSopenharmony_ci} // namespace OHOS