1 /* 2 * Copyright (c) 2024 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_CROWN_EVENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_CROWN_EVENT_H 18 #include <map> 19 #include "core/event/ace_events.h" 20 #include "core/event/non_pointer_event.h" 21 22 namespace OHOS::MMI { 23 class CrownEvent; 24 } 25 26 namespace OHOS::Ace { 27 28 enum class CrownSensitivity: int32_t { 29 LOW = 0, 30 MEDIUM = 1, 31 HIGH = 2, 32 }; 33 34 enum class CrownAction : int32_t { 35 BEGIN, 36 UPDATE, 37 END, 38 UNKNOWN, 39 }; 40 41 struct CrownEvent final : public NonPointerEvent { 42 std::shared_ptr<MMI::PointerEvent> pointerEvent_; 43 CrownAction action = CrownAction::UNKNOWN; 44 TimeStamp timeStamp; 45 double angularVelocity = 0.0; 46 double degree = 0.0; 47 int32_t touchEventId = 0; 48 bool isInjected = false; 49 CrownEventfinal50 CrownEvent() 51 { 52 eventType = UIInputEventType::CROWN; 53 } CrownEventfinal54 CrownEvent(CrownAction action, TimeStamp timeStamp, double angularVelocity, double degree, bool isInjected) 55 : action(action), timeStamp(timeStamp), angularVelocity(angularVelocity), degree(degree), 56 isInjected(isInjected) 57 {} 58 CrownEvent(CrownAction action, int64_t timeStamp = 0, double angularVelocity = 0.0, double degree = 0.0, 59 bool isInjected = false) 60 { 61 std::chrono::milliseconds milliseconds(timeStamp); 62 TimeStamp time(milliseconds); 63 new (this) CrownEvent(action, time, angularVelocity, degree, isInjected); 64 } 65 ~CrownEvent() = default; 66 SetTimeStampfinal67 void SetTimeStamp(int64_t timeInt) 68 { 69 std::chrono::milliseconds milliseconds(timeInt); 70 TimeStamp time(milliseconds); 71 timeStamp = time; 72 } 73 SetActionfinal74 void SetAction(CrownAction crownAction) 75 { 76 action = crownAction; 77 } 78 SetPointerEventfinal79 void SetPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) 80 { 81 pointerEvent_ = pointerEvent; 82 } 83 GetPointerEventfinal84 const std::shared_ptr<MMI::PointerEvent>& GetPointerEvent() const 85 { 86 return pointerEvent_; 87 } 88 }; 89 90 class ACE_EXPORT CrownEventInfo : public BaseEventInfo { DECLARE_RELATIONSHIP_OF_CLASSES(CrownEventInfo,BaseEventInfo)91 DECLARE_RELATIONSHIP_OF_CLASSES(CrownEventInfo, BaseEventInfo) 92 93 public: 94 explicit CrownEventInfo(const CrownEvent& event) : BaseEventInfo("CrownEvent") 95 { 96 SetTimeStamp(event.timeStamp); 97 angularVelocity_ = event.angularVelocity; 98 degree_ = event.degree; 99 action_ = event.action; 100 isInjected_ = event.isInjected; 101 }; 102 ~CrownEventInfo() override = default; 103 GetAngularVelocity()104 double GetAngularVelocity() const 105 { 106 return angularVelocity_; 107 } 108 GetDegree()109 double GetDegree() const 110 { 111 return degree_; 112 } 113 GetAction()114 CrownAction GetAction() const 115 { 116 return action_; 117 } 118 GetIsInjected()119 bool GetIsInjected() const 120 { 121 return isInjected_; 122 } 123 private: 124 double angularVelocity_ = 0.0; 125 double degree_ = 0.0; 126 CrownAction action_ = CrownAction::UNKNOWN; 127 bool isInjected_ = false; 128 }; 129 130 using OnCrownEventFunc = std::function<bool(const CrownEvent&)>; 131 using OnCrownCallbackFunc = std::function<void(CrownEventInfo&)>; 132 133 } // namespace OHOS::Ace 134 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_EVENT_CROWN_EVENT_H 135