瀏覽代碼

Let all event listeners on the current element finish when calling StopPropagation().

Michael Ragazzon 6 年之前
父節點
當前提交
b3c4f5a97d
共有 4 個文件被更改,包括 12 次插入7 次删除
  1. 2 1
      Samples/basic/benchmark/src/main.cpp
  2. 3 3
      Source/Core/EventDispatcher.cpp
  3. 1 1
      Source/Core/EventSpecification.cpp
  4. 6 2
      readme.md

+ 2 - 1
Samples/basic/benchmark/src/main.cpp

@@ -102,7 +102,8 @@ public:
 		  (After Windows feature update and MSVC update, no code change): 109.0  [0bba316]
 		  (After Windows feature update and MSVC update, no code change): 109.0  [0bba316]
 		  Fixes and element style iterators: 108.0  [0bba316]
 		  Fixes and element style iterators: 108.0  [0bba316]
 		  Update definition speedup: 115.0  [5d138fa]
 		  Update definition speedup: 115.0  [5d138fa]
-		  (Release mode, no code change): 135.0  [5d138fa]
+		  (Full release mode, no code change): 135.0  [5d138fa]
+		  EventIDs: 139.0  [d2c3956]
 		  
 		  
 		*/
 		*/
 
 

+ 3 - 3
Source/Core/EventDispatcher.cpp

@@ -191,10 +191,10 @@ void EventDispatcher::TriggerEvents(Event* event, DefaultActionPhase default_act
 	{
 	{
 		// Dispatch all actions
 		// Dispatch all actions
 		Listeners& listeners = (*itr).second;
 		Listeners& listeners = (*itr).second;
-		for (size_t i = 0; i < listeners.size() && event->IsPropagating(); i++)
+		for (size_t i = 0; i < listeners.size(); i++)
 		{
 		{
-			if (phase == EventPhase::Target 
-				|| (phase == EventPhase::Capture && listeners[i].in_capture_phase) 
+			if (phase == EventPhase::Target
+				|| (phase == EventPhase::Capture && listeners[i].in_capture_phase)
 				|| (phase == EventPhase::Bubble && !listeners[i].in_capture_phase))
 				|| (phase == EventPhase::Bubble && !listeners[i].in_capture_phase))
 			{
 			{
 				listeners[i].listener->ProcessEvent(*event);
 				listeners[i].listener->ProcessEvent(*event);

+ 1 - 1
Source/Core/EventSpecification.cpp

@@ -46,7 +46,7 @@ void Initialize()
 {
 {
 	// Must be specified in the same order as in EventId
 	// Must be specified in the same order as in EventId
 	specifications = {
 	specifications = {
-		//      id                 name      interruptible  bubbles     default_action
+		//      id                 type      interruptible  bubbles     default_action
 		{EventId::Invalid       , "invalid"       , false , false , DefaultActionPhase::None},
 		{EventId::Invalid       , "invalid"       , false , false , DefaultActionPhase::None},
 		{EventId::Mousedown     , "mousedown"     , true  , true  , DefaultActionPhase::TargetAndBubble},
 		{EventId::Mousedown     , "mousedown"     , true  , true  , DefaultActionPhase::TargetAndBubble},
 		{EventId::Mousescroll   , "mousescroll"   , true  , true  , DefaultActionPhase::TargetAndBubble},
 		{EventId::Mousescroll   , "mousescroll"   , true  , true  , DefaultActionPhase::TargetAndBubble},

+ 6 - 2
readme.md

@@ -52,7 +52,7 @@ Events have some differences, however the existing API should mostly still work.
 
 
 There is now a distinction between actions executed in event listeners, and default actions for events:
 There is now a distinction between actions executed in event listeners, and default actions for events:
 
 
-- Event listeners are attached to an element as before. Events following the normal phases: capture (root -> target), target, and bubble (target -> root). Each event listener can be either attached to the bubble phase (default) or capture phase. The target element always fire if reached. Each event type specifies whether it executes the bubble phase or not, see below for details.
+- Event listeners are attached to an element as before. Events following the normal phases: capture (root -> target), target, and bubble (target -> root). Each event listener can be either attached to the bubble phase (default) or capture phase. The target element always fire if reached. Listeners are executed in the order they are added to the element. Each event type specifies whether it executes the bubble phase or not, see below for details.
 - Default actions are primarily for actions performed internally in the library. They are executed in the function `virtual void Element::ProcessDefaultAction(Event& event)`. However, any object that derives from `Element` can override the default behavior and add new behavior. The default actions follow the normal event phases, but are only executed in the phase according to the `default_action_phase` which is defined for each event type. If an event is cancelled with `Event::StopPropagation()`, then the default action is not performed unless already executed.
 - Default actions are primarily for actions performed internally in the library. They are executed in the function `virtual void Element::ProcessDefaultAction(Event& event)`. However, any object that derives from `Element` can override the default behavior and add new behavior. The default actions follow the normal event phases, but are only executed in the phase according to the `default_action_phase` which is defined for each event type. If an event is cancelled with `Event::StopPropagation()`, then the default action is not performed unless already executed.
 
 
 
 
@@ -72,7 +72,11 @@ default_action_phase: BubbleAndTarget
 ```
 ```
 
 
 Whenever an event listener is added or event is dispatched, and the provided event type does not already have a specification, the default specification
 Whenever an event listener is added or event is dispatched, and the provided event type does not already have a specification, the default specification
-`interruptible: true, bubbles: true, default_action_phase: None` is added for that event type. The default specification can be overriden by first calling `EventId Rocket::Core::RegisterEventType(const String& name, bool interruptible, bool bubbles, DefaultActionPhase default_action_phase)`. This is only necessary once for each application run.
+`interruptible: true, bubbles: true, default_action_phase: None` is added for that event type. The default specification can be overriden by first calling `EventId Rocket::Core::RegisterEventType(const String& name, bool interruptible, bool bubbles, DefaultActionPhase default_action_phase)`. This is only necessary once for each application run, and should be performed before listeners of the same type are used.
+
+Other changes:
+
+- All event listeners on the current element will always be called after calling StopPropagation(). Only when propagating to the next element, the event is stopped. This is the same behavior as in Javascript.
 
 
 Breaking change:
 Breaking change: