Revert "Revert "Revert "[Tizen] Revert "Use touch consumed return to set whether...
[platform/core/uifw/dali-core.git] / dali / internal / event / events / key-event-impl.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/events/key-event-impl.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-vector.h>
23
24 namespace Dali
25 {
26
27 namespace
28 {
29 const uint32_t MODIFIER_SHIFT   = 0x1;
30 const uint32_t MODIFIER_CTRL    = 0x2;
31 const uint32_t MODIFIER_ALT     = 0x4;
32 const int32_t  KEY_INVALID_CODE = -1;
33 }
34
35 namespace Internal
36 {
37
38 KeyEvent::KeyEvent()
39 : mKeyName( "" ),
40   mLogicalKey( "" ),
41   mKeyString( "" ),
42   mKeyCode( KEY_INVALID_CODE ),
43   mKeyModifier( 0 ),
44   mTime( 0 ),
45   mState( Dali::KeyEvent::DOWN ),
46   mCompose( "" ),
47   mDeviceName( "" ),
48   mDeviceClass( Device::Class::NONE ),
49   mDeviceSubclass( Device::Subclass::NONE )
50 {
51 }
52
53 KeyEvent::KeyEvent( const std::string& keyName,
54           const std::string& logicalKey,
55           const std::string& keyString,
56           int keyCode,
57           int keyModifier,
58           unsigned long timeStamp,
59           const Dali::KeyEvent::State& keyState,
60           const std::string& compose,
61           const std::string& deviceName,
62           const Device::Class::Type deviceClass,
63           const Device::Subclass::Type deviceSubclass )
64 : mKeyName( keyName ),
65   mLogicalKey( logicalKey ),
66   mKeyString( keyString ),
67   mKeyCode( keyCode ),
68   mKeyModifier( keyModifier ),
69   mTime( timeStamp ),
70   mState( keyState ),
71   mCompose( compose ),
72   mDeviceName( deviceName ),
73   mDeviceClass( deviceClass ),
74   mDeviceSubclass( deviceSubclass )
75 {
76 }
77
78 KeyEventPtr KeyEvent::New( const std::string& keyName,
79                            const std::string& logicalKey,
80                            const std::string& keyString,
81                            int keyCode,
82                            int keyModifier,
83                            unsigned long timeStamp,
84                            const Dali::KeyEvent::State& keyState,
85                            const std::string& compose,
86                            const std::string& deviceName,
87                            const Device::Class::Type deviceClass,
88                            const Device::Subclass::Type deviceSubclass )
89 {
90   KeyEventPtr keyEvent = new KeyEvent( keyName, logicalKey, keyString, keyCode, keyModifier, timeStamp, keyState, compose, deviceName, deviceClass, deviceSubclass );
91   return keyEvent;
92 }
93
94 bool KeyEvent::IsShiftModifier() const
95 {
96   return ( ( MODIFIER_SHIFT & mKeyModifier ) == MODIFIER_SHIFT );
97 }
98
99 bool KeyEvent::IsCtrlModifier() const
100 {
101   return ( ( MODIFIER_CTRL & mKeyModifier ) == MODIFIER_CTRL );
102 }
103
104 bool KeyEvent::IsAltModifier() const
105 {
106   return ( ( MODIFIER_ALT & mKeyModifier ) == MODIFIER_ALT );
107 }
108
109 const std::string& KeyEvent::GetCompose() const
110 {
111   return mCompose;
112 }
113
114 const std::string& KeyEvent::GetDeviceName() const
115 {
116   return mDeviceName;
117 }
118
119
120 Device::Class::Type KeyEvent::GetDeviceClass() const
121 {
122   return mDeviceClass;
123 }
124
125
126 Device::Subclass::Type KeyEvent::GetDeviceSubclass() const
127 {
128   return mDeviceSubclass;
129 }
130
131
132 const std::string& KeyEvent::GetKeyName() const
133 {
134   return mKeyName;
135 }
136
137
138 const std::string& KeyEvent::GetKeyString() const
139 {
140   return mKeyString;
141 }
142
143
144 const std::string& KeyEvent::GetLogicalKey() const
145 {
146   return mLogicalKey;
147 }
148
149
150 int32_t KeyEvent::GetKeyCode() const
151 {
152   return mKeyCode;
153 }
154
155
156 int32_t KeyEvent::GetKeyModifier() const
157 {
158   return mKeyModifier;
159 }
160
161
162 unsigned long KeyEvent::GetTime() const
163 {
164   return mTime;
165 }
166
167
168 Dali::KeyEvent::State KeyEvent::GetState() const
169 {
170   return mState;
171 }
172
173
174 void KeyEvent::SetKeyName( const std::string& keyName )
175 {
176   mKeyName = keyName;
177 }
178
179
180 void KeyEvent::SetKeyString( const std::string& keyString )
181 {
182   mKeyString = keyString;
183 }
184
185
186 void KeyEvent::SetKeyCode( int32_t keyCode )
187 {
188   mKeyCode = keyCode;
189 }
190
191
192 void KeyEvent::SetKeyModifier( int32_t keyModifier )
193 {
194   mKeyModifier = keyModifier;
195 }
196
197
198 void KeyEvent::SetTime( unsigned long time )
199 {
200   mTime = time;
201 }
202
203
204 void KeyEvent::SetState( const Dali::KeyEvent::State& state )
205 {
206   mState = state;
207 }
208
209 } // namespace Internal
210
211 } // namespace Dali