Browse Source

Event::StopImmediatePropagation()

Michael Ragazzon 6 years ago
parent
commit
f139eb6a5c

+ 8 - 3
Include/RmlUi/Core/Event.h

@@ -95,11 +95,15 @@ public:
 	/// Checks if the event is of a certain id.
 	bool operator==(EventId id) const;
 
-	/// Has the event been stopped?
-	/// @return True if the event is still propogating
+	/// Returns true if the event is still propagating.
 	bool IsPropagating() const;
-	/// Stops the propagation of the event wherever it is
+	/// Returns true if the event is still immediate propagating.
+	bool IsImmediatePropagating() const;
+
+	/// Stops propagation of the event, but finish all listeners on the current element.
 	void StopPropagation();
+	/// Stops propagation of the event, including to any other listeners on the current element.
+	void StopImmediatePropagation();
 
 	/// Returns the value of one of the event's parameters.
 	/// @param key[in] The name of the desired parameter.
@@ -137,6 +141,7 @@ private:
 	bool interruptible;
 	
 	bool interrupted;
+	bool interrupted_immediate;
 	EventPhase phase;
 
 	bool has_mouse_position;

+ 1 - 1
Samples/basic/demo/src/main.cpp

@@ -198,7 +198,7 @@ public:
 		if (value == "exit")
 		{
 			element->GetParentNode()->SetInnerRML("<button onclick='confirm_exit'>Are you sure?</button>");
-			event.StopPropagation();
+			event.StopImmediatePropagation();
 		}
 		else if (value == "confirm_exit")
 		{

+ 1 - 1
Samples/invaders/data/pause.rml

@@ -20,7 +20,7 @@
 	<body template="window" onload="pause" onunload="unpause">
 		<br />
 		<p>Are you sure you want to end this game?</p>
-		<button onclick="goto high_score; close game_window">Yes</button>
+		<button onclick="goto high_score; close game_window" autofocus>Yes</button>
 		<button onclick="close">No!</button>
 	</body>
 </rml>

+ 15 - 0
Source/Core/Event.cpp

@@ -39,6 +39,7 @@ Event::Event() : id(EventId::Invalid)
 	phase = EventPhase::None;
 	interruptible = false;
 	interrupted = false;
+	interrupted_immediate = false;
 	current_element = nullptr;
 	target_element = nullptr;
 	has_mouse_position = false;
@@ -127,6 +128,20 @@ void Event::StopPropagation()
 	}
 }
 
+bool Event::IsImmediatePropagating() const
+{
+	return !interrupted_immediate;
+}
+
+void Event::StopImmediatePropagation()
+{
+	if(interruptible)
+	{
+		interrupted_immediate = true;
+		interrupted = true;
+	}
+}
+
 const Dictionary& Event::GetParameters() const
 {
 	return parameters;

+ 1 - 1
Source/Core/EventDispatcher.cpp

@@ -215,7 +215,7 @@ void EventDispatcher::TriggerEvents(Event& event, DefaultActionPhase default_act
 	{
 		entry.listener->ProcessEvent(event);
 		
-		if (!event.IsPropagating())
+		if (!event.IsImmediatePropagating())
 			break;
 	}
 

+ 4 - 4
readme.md

@@ -312,12 +312,12 @@ Breaking changes since RmlUi v2.0.
 
 - Rml::Core::String has been replaced by std::string, thus, interfacing with the library now requires you to change your string types. This change was motivated by a small performance gain, additionally, it should make it easier to interface with the library especially for users already using std::string in their codebase. Similarly, Rml::Core::WString is now an alias for std::wstring.
 - Querying the property of an element for size, position and similar may not work as expected right after changes to the document or style. This change is made for performance reasons, see the description under *performance* for reasoning and a workaround.
-- The Controls::DataGrid "min-rows" property has been replaced by an attribute of the same name.
+- The Controls::DataGrid "min-rows" property has been removed.
 - Removed RenderInterface::GetPixelsPerInch, instead the pixels per inch value has been fixed to 96 PPI, as per CSS specs. To achieve a scalable user interface, instead use the 'dp' unit.
 - Removed 'top' and 'bottom' from z-index property.
 - See changes to the declaration of decorators and font-effects above.
 - See changes to the render interface regarding transforms above.
-- The focus flag in `ElementDocument::Show` has been changed, with a new enum name and new options.
+- The focus flag in `ElementDocument::Show` has been changed, with a new enum name and new options, see above.
 - Also, see removal of manual reference counting above.
 
 
@@ -337,7 +337,7 @@ Each event type now has an associated EventId as well as a specification defined
 - `bubbles`: Whether the event executes the bubble phase. If true, all three phases: capture, target, and bubble, are executed. If false, only capture and target phases are executed.
 - `default_action_phase`: One of: None, Target, Bubble, TargetAndBubble. Specifies during which phases the default action is executed, if any. That is, the phase for which `Element::ProcessDefaultAction` is called. See above for details.
 
-For example, the event type `click` has the following specification:
+See `EventSpecification.cpp` for details of each event type. For example, the event type `click` has the following specification:
 ```
 id: EventId::Click
 type: "click"
@@ -354,7 +354,7 @@ EventId Rml::Core::RegisterEventType(const String& type, bool interruptible, boo
 After this call, any usage of this type will use the provided specification by default. The returned EventId can be used to dispatch events instead of the type string.
 
 Various changes:
-- All event listeners on the current element will always be called after calling StopPropagation(). However, the default action on the current element will be prevented. When propagating to the next element, the event is stopped. This behavior is consistent with the standard DOM events model.
+- All event listeners on the current element will always be called after calling `StopPropagation()`. However, the default action on the current element will be prevented. When propagating to the next element, the event is stopped. This behavior is consistent with the standard DOM events model. The event can be stopped immediately with `StopImmediatePropagation()`.
 - `Element::DispatchEvent` can now optionally take an `EventId` instead of a `String`.
 - The `resize` event now only applies to the document size, not individual elements.
 - The `scrollchange` event has been replaced by a function call. To capture scroll changes, instead use the `scroll` event.