[dali_2.3.27] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / events / key-event-processor.cpp
1 /*
2  * Copyright (c) 2023 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-processor.h>
20
21 // EXTERNAL INCLUDES
22 #ifdef TRACE_ENABLED
23 #include <sstream> ///< for std::ostringstream
24 #endif
25
26 // INTERNAL INCLUDES
27 #include <dali/integration-api/events/key-event-integ.h>
28 #include <dali/integration-api/trace.h>
29 #include <dali/internal/event/common/scene-impl.h>
30 #include <dali/internal/event/events/key-event-impl.h>
31 #include <dali/public-api/events/key-event.h>
32
33 namespace Dali
34 {
35 namespace Internal
36 {
37 namespace
38 {
39 DALI_INIT_TRACE_FILTER(gTraceFilter, DALI_TRACE_PERFORMANCE_MARKER, false);
40
41 #ifdef TRACE_ENABLED
42 const char* KEY_EVENT_STATES[Dali::KeyEvent::State::UP + 1] =
43   {
44     "DOWN",
45     "UP",
46 };
47 #endif
48 } // namespace
49
50 KeyEventProcessor::KeyEventProcessor(Scene& scene)
51 : mScene(scene)
52 {
53 }
54
55 KeyEventProcessor::~KeyEventProcessor() = default;
56
57 void KeyEventProcessor::ProcessKeyEvent(const Integration::KeyEvent& event)
58 {
59   KeyEventPtr    keyEvent(new KeyEvent(event.keyName, event.logicalKey, event.keyString, event.keyCode, event.keyModifier, event.time, static_cast<Dali::KeyEvent::State>(event.state), event.compose, event.deviceName, event.deviceClass, event.deviceSubclass));
60   keyEvent->SetRepeat(event.isRepeat);
61   keyEvent->SetWindowId(event.windowId);
62   Dali::KeyEvent keyEventHandle(keyEvent.Get());
63
64   DALI_TRACE_BEGIN_WITH_MESSAGE_GENERATOR(gTraceFilter, "DALI_PROCESS_KEY_EVENT", [&](std::ostringstream& oss) {
65     oss << "[name:" << event.keyName << ", code:" << event.keyCode << ", state:" << KEY_EVENT_STATES[event.state] << ", time:" << event.time << "]";
66   });
67
68   // Emit the key event signal from the scene.
69   bool consumed = false;
70   if(!keyEventHandle.IsNoInterceptModifier())
71   {
72     consumed = mScene.EmitInterceptKeyEventSignal(keyEventHandle);
73   }
74   if(!consumed)
75   {
76     consumed = mScene.EmitKeyEventGeneratedSignal(keyEventHandle);
77   }
78   if(!consumed)
79   {
80     mScene.EmitKeyEventSignal(keyEventHandle);
81   }
82   DALI_TRACE_END(gTraceFilter, "DALI_PROCESS_KEY_EVENT");
83 }
84
85 } // namespace Internal
86
87 } // namespace Dali