Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / event / events / mouse-wheel-event-processor.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // CLASS HEADER
18 #include <dali/internal/event/events/mouse-wheel-event-processor.h>
19
20 // INTERNAL INCLUDES
21 #include <dali/public-api/events/mouse-wheel-event.h>
22 #include <dali/public-api/events/hit-test-algorithm.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/integration-api/events/mouse-wheel-event-integ.h>
25 #include <dali/internal/event/common/stage-impl.h>
26 #include <dali/internal/event/actors/actor-impl.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace
35 {
36
37 #if defined(DEBUG_ENABLED)
38 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_MOUSE_WHEEL_PROCESSOR");
39 #endif
40
41 /**
42  *  Recursively deliver events to the actor and its parents, until the event is consumed or the stage is reached.
43  */
44 Dali::Actor EmitMouseWheelSignals( Dali::Actor actor, const MouseWheelEvent& event )
45 {
46   Dali::Actor consumedActor;
47
48   if ( actor )
49   {
50     Dali::Actor oldParent( actor.GetParent() );
51
52     Actor& actorImpl( GetImplementation(actor) );
53
54     bool consumed( false );
55
56     // Only do the conversion and emit the signal if the actor's mouse wheel signal has connections.
57     if ( actorImpl.GetMouseWheelEventRequired() )
58     {
59       // Emit the signal to the parent
60       consumed = actorImpl.EmitMouseWheelEventSignal( event );
61     }
62
63     if ( consumed )
64     {
65       // One of this actor's listeners has consumed the event so set this actor as the consumed actor.
66       consumedActor = Dali::Actor( &actorImpl );
67     }
68     else
69     {
70       // The actor may have been removed/reparented during the signal callbacks.
71       Dali::Actor parent = actor.GetParent();
72
73       if ( parent &&
74            (parent == oldParent) )
75       {
76         // One of the actor's parents may consumed the event and they should be set as the consumed actor.
77         consumedActor = EmitMouseWheelSignals( parent, event );
78       }
79     }
80   }
81
82   return consumedActor;
83 }
84
85 /**
86  * The function to be used in the hit-test algorithm to check whether the actor is mouse wheelable.
87  */
88 bool IsActorMouseWheelableFunction(Dali::Actor actor, Dali::HitTestAlgorithm::TraverseType type)
89 {
90   bool hittable = false;
91
92   switch (type)
93   {
94     case Dali::HitTestAlgorithm::CHECK_ACTOR:
95     {
96       if( GetImplementation(actor).GetMouseWheelEventRequired() && // Does the Application or derived actor type require a mouse wheel event?
97           GetImplementation(actor).IsHittable() )
98       {
99         hittable = true;
100       }
101       break;
102     }
103     case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE:
104     {
105       if( actor.IsVisible() ) // Actor is visible, if not visible then none of its children are visible.
106       {
107         hittable = true;
108       }
109       break;
110     }
111     default:
112     {
113       break;
114     }
115   }
116
117   return hittable;
118 };
119
120 } // unnamed namespace
121
122
123 MouseWheelEventProcessor::MouseWheelEventProcessor(Stage& stage)
124 : mStage(stage)
125 {
126 }
127
128 MouseWheelEventProcessor::~MouseWheelEventProcessor()
129 {
130 }
131
132 void MouseWheelEventProcessor::ProcessMouseWheelEvent(const Integration::MouseWheelEvent& event)
133 {
134   Stage& stage = mStage;
135   MouseWheelEvent mouseWheelEvent( event.direction, event.modifiers, event.point, event.z, event.timeStamp );
136
137   HitTestAlgorithm::Results hitTestResults;
138   HitTestAlgorithm::HitTest( Dali::Stage(&stage), event.point, hitTestResults, IsActorMouseWheelableFunction );
139
140   DALI_LOG_INFO( gLogFilter, Debug::General, "  Screen(%.0f, %.0f), HitActor(%p, %s), Local(%.2f, %.2f)\n",
141                  event.point.x, event.point.y,
142                  ( hitTestResults.actor ? (void*)&hitTestResults.actor.GetBaseObject() : NULL ),
143                  ( hitTestResults.actor ? hitTestResults.actor.GetName().c_str() : "" ),
144                  hitTestResults.actorCoordinates.x, hitTestResults.actorCoordinates.y );
145
146   // Recursively deliver events to the actor and its parents, until the event is consumed or the stage is reached.
147   Dali::Actor consumedActor = EmitMouseWheelSignals( hitTestResults.actor, mouseWheelEvent );
148
149   DALI_LOG_INFO( gLogFilter, Debug::Concise, "HitActor:      (%p) %s\n", hitTestResults.actor ? (void*)&hitTestResults.actor.GetBaseObject() : NULL, hitTestResults.actor ? hitTestResults.actor.GetName().c_str() : "" );
150   DALI_LOG_INFO( gLogFilter, Debug::Concise, "ConsumedActor: (%p) %s\n", consumedActor ? (void*)&consumedActor.GetBaseObject() : NULL, consumedActor ? consumedActor.GetName().c_str() : "" );
151
152 }
153
154 } // namespace Internal
155
156 } // namespace Dali