• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 "key_event.h"
17 
18 #include <memory>
19 namespace OHOS {
Initialize(MultimodalProperty & multimodalProperty,KeyProperty & keyProperty)20 void KeyEvent::Initialize(MultimodalProperty &multimodalProperty, KeyProperty &keyProperty)
21 {
22     MultimodalEvent::Initialize(multimodalProperty);
23     keyProperty_.isPressed = keyProperty.isPressed;
24     keyProperty_.keyCode = keyProperty.keyCode;
25     keyProperty_.keyDownDuration = keyProperty.keyDownDuration;
26 }
27 
GetMaxKeyCode()28 int KeyEvent::GetMaxKeyCode()
29 {
30     return NOW_MAX_CODE;
31 }
32 
IsKeyDown()33 bool KeyEvent::IsKeyDown()
34 {
35     return keyProperty_.isPressed;
36 }
37 
GetKeyCode()38 int KeyEvent::GetKeyCode()
39 {
40     return keyProperty_.keyCode;
41 }
42 
GetKeyDownDuration()43 int KeyEvent::GetKeyDownDuration()
44 {
45     return keyProperty_.keyDownDuration;
46 }
47 
Marshalling(Parcel & parcel) const48 bool KeyEvent::Marshalling(Parcel &parcel) const
49 {
50     bool result = parcel.WriteInt32(multiProperty_.highLevelEvent);
51     if (!result) {
52         return result;
53     }
54     result = parcel.WriteString(multiProperty_.uuid);
55     if (!result) {
56         return result;
57     }
58     result = parcel.WriteInt32(multiProperty_.sourceType);
59     if (!result) {
60         return result;
61     }
62     result = parcel.WriteInt32(multiProperty_.occurredTime);
63     if (!result) {
64         return result;
65     }
66     result = parcel.WriteString(multiProperty_.deviceId);
67     if (!result) {
68         return result;
69     }
70     result = parcel.WriteInt32(multiProperty_.inputDeviceId);
71     if (!result) {
72         return result;
73     }
74     result = parcel.WriteBool(multiProperty_.isHighLevelEvent);
75     if (!result) {
76         return result;
77     }
78 
79     result = parcel.WriteBool(keyProperty_.isPressed);
80     if (!result) {
81         return result;
82     }
83     result = parcel.WriteInt32(keyProperty_.keyCode);
84     if (!result) {
85         return result;
86     }
87     result = parcel.WriteInt32(keyProperty_.keyDownDuration);
88     if (!result) {
89         return result;
90     }
91 
92     return result;
93 }
94 
Unmarshalling(Parcel & parcel)95 KeyEvent *KeyEvent::Unmarshalling(Parcel &parcel)
96 {
97     KeyProperty property;
98     MultimodalProperty multiProperty;
99 
100     multiProperty.highLevelEvent = parcel.ReadInt32();
101     multiProperty.uuid = parcel.ReadString();
102     multiProperty.sourceType = parcel.ReadInt32();
103     multiProperty.occurredTime = parcel.ReadInt32();
104     multiProperty.deviceId = parcel.ReadString();
105     multiProperty.inputDeviceId = parcel.ReadInt32();
106     multiProperty.isHighLevelEvent = parcel.ReadBool();
107     property.isPressed = parcel.ReadBool();
108     property.keyCode = parcel.ReadInt32();
109     property.keyDownDuration = parcel.ReadInt32();
110     KeyEvent *event = new (std::nothrow) KeyEvent();
111     if (event == nullptr) {
112         return nullptr;
113     }
114     event->Initialize(multiProperty, property);
115     return event;
116 }
117 }
118