Browse Source

Initial document_base_tag branch

aquawicket 5 years ago
parent
commit
e60d16e386

+ 10 - 0
Include/RmlUi/Core/Context.h

@@ -90,6 +90,7 @@ public:
 	/// Creates a new, empty document and places it into this context.
 	/// Creates a new, empty document and places it into this context.
 	/// @param[in] tag The document type to create.
 	/// @param[in] tag The document type to create.
 	/// @return The new document, or nullptr if no document could be created.
 	/// @return The new document, or nullptr if no document could be created.
+	// FIXME - tag parameter should be named instancer_name, it references to instancer_name in InstanceElement(), not the tag name.
 	ElementDocument* CreateDocument(const String& tag = "body");
 	ElementDocument* CreateDocument(const String& tag = "body");
 	/// Load a document into the context.
 	/// Load a document into the context.
 	/// @param[in] document_path The path to the document to load.
 	/// @param[in] document_path The path to the document to load.
@@ -239,6 +240,14 @@ public:
 	/// @return True if succesfully removed, false if no data model was found.
 	/// @return True if succesfully removed, false if no data model was found.
 	bool RemoveDataModel(const String& name);
 	bool RemoveDataModel(const String& name);
 
 
+	/// This will set the documents base <tag> before creation. Default = "body"
+	/// @param[in] tag The name of the base tag. Example: "html"
+	void SetDocumentsBaseTag(const String& tag);
+
+	/// Gets the name of the documents base tag.
+	/// @return The current documents base tag name.
+	String GetDocumentsBaseTag();
+
 protected:
 protected:
 	void Release() override;
 	void Release() override;
 
 
@@ -246,6 +255,7 @@ private:
 	String name;
 	String name;
 	Vector2i dimensions;
 	Vector2i dimensions;
 	float density_independent_pixel_ratio;
 	float density_independent_pixel_ratio;
+	String documents_base_tag = "body";
 
 
 	ContextInstancer* instancer;
 	ContextInstancer* instancer;
 
 

+ 14 - 3
Source/Core/Context.cpp

@@ -63,7 +63,7 @@ Context::Context(const String& name) : name(name), dimensions(0, 0), density_ind
 	root->SetOffset(Vector2f(0, 0), nullptr);
 	root->SetOffset(Vector2f(0, 0), nullptr);
 	root->SetProperty(PropertyId::ZIndex, Property(0, Property::NUMBER));
 	root->SetProperty(PropertyId::ZIndex, Property(0, Property::NUMBER));
 
 
-	cursor_proxy = Factory::InstanceElement(nullptr, "body", "body", XMLAttributes());
+	cursor_proxy = Factory::InstanceElement(nullptr, documents_base_tag, documents_base_tag, XMLAttributes());
 	ElementDocument* cursor_proxy_document = rmlui_dynamic_cast< ElementDocument* >(cursor_proxy.get());
 	ElementDocument* cursor_proxy_document = rmlui_dynamic_cast< ElementDocument* >(cursor_proxy.get());
 	if (cursor_proxy_document)
 	if (cursor_proxy_document)
 		cursor_proxy_document->context = this;
 		cursor_proxy_document->context = this;
@@ -214,10 +214,11 @@ bool Context::Render()
 	return true;
 	return true;
 }
 }
 
 
-// Creates a new, empty document and places it into this context.
+// FIXME - tag parameter should be named instancer_name, it references to instancer_name in InstanceElement(), not the tag name.
+// Creates a new, empty document and places it into this context. 
 ElementDocument* Context::CreateDocument(const String& tag)
 ElementDocument* Context::CreateDocument(const String& tag)
 {
 {
-	ElementPtr element = Factory::InstanceElement(nullptr, tag, "body", XMLAttributes());
+	ElementPtr element = Factory::InstanceElement(nullptr, tag, documents_base_tag, XMLAttributes());
 	if (!element)
 	if (!element)
 	{
 	{
 		Log::Message(Log::LT_ERROR, "Failed to instance document on tag '%s', instancer returned nullptr.", tag.c_str());
 		Log::Message(Log::LT_ERROR, "Failed to instance document on tag '%s', instancer returned nullptr.", tag.c_str());
@@ -1298,4 +1299,14 @@ void Context::Release()
 	}
 	}
 }
 }
 
 
+void Context::SetDocumentsBaseTag(const String& tag)
+{
+	documents_base_tag = tag;
+}
+
+String Context::GetDocumentsBaseTag()
+{
+	return documents_base_tag;
+}
+
 } // namespace Rml
 } // namespace Rml

+ 6 - 3
Source/Core/Factory.cpp

@@ -410,9 +410,12 @@ bool Factory::InstanceElementText(Element* parent, const String& in_text)
 	{
 	{
 		RMLUI_ZoneScopedNC("InstanceStream", 0xDC143C);
 		RMLUI_ZoneScopedNC("InstanceStream", 0xDC143C);
 		auto stream = std::make_unique<StreamMemory>(text.size() + 32);
 		auto stream = std::make_unique<StreamMemory>(text.size() + 32);
-		stream->Write("<body>", 6);
+		String tag = parent->GetContext()->GetDocumentsBaseTag();
+		String open_tag = "<" + tag + ">";
+		String close_tag = "</" + tag + ">";
+		stream->Write(open_tag.c_str(), open_tag.size());
 		stream->Write(text);
 		stream->Write(text);
-		stream->Write("</body>", 7);
+		stream->Write(close_tag.c_str(), close_tag.size());
 		stream->Seek(0, SEEK_SET);
 		stream->Seek(0, SEEK_SET);
 
 
 		InstanceElementStream(parent, stream.get());
 		InstanceElementStream(parent, stream.get());
@@ -465,7 +468,7 @@ ElementPtr Factory::InstanceDocumentStream(Context* context, Stream* stream)
 {
 {
 	RMLUI_ZoneScoped;
 	RMLUI_ZoneScoped;
 
 
-	ElementPtr element = Factory::InstanceElement(nullptr, "body", "body", XMLAttributes());
+	ElementPtr element = Factory::InstanceElement(nullptr, context->GetDocumentsBaseTag(), context->GetDocumentsBaseTag(), XMLAttributes());
 	if (!element)
 	if (!element)
 	{
 	{
 		Log::Message(Log::LT_ERROR, "Failed to instance document, instancer returned nullptr.");
 		Log::Message(Log::LT_ERROR, "Failed to instance document, instancer returned nullptr.");

+ 0 - 1
Source/Core/XMLNodeHandlerBody.cpp

@@ -45,7 +45,6 @@ XMLNodeHandlerBody::~XMLNodeHandlerBody()
 Element* XMLNodeHandlerBody::ElementStart(XMLParser* parser, const String& RMLUI_UNUSED_ASSERT_PARAMETER(name), const XMLAttributes& attributes)
 Element* XMLNodeHandlerBody::ElementStart(XMLParser* parser, const String& RMLUI_UNUSED_ASSERT_PARAMETER(name), const XMLAttributes& attributes)
 {
 {
 	RMLUI_UNUSED_ASSERT(name);
 	RMLUI_UNUSED_ASSERT(name);
-	RMLUI_ASSERT(name == "body");
 
 
 	Element* element = parser->GetParseFrame()->element;
 	Element* element = parser->GetParseFrame()->element;
 
 

+ 1 - 1
Source/Debugger/MenuSource.h

@@ -89,5 +89,5 @@ static const char* menu_rml = R"RML(
 	<button id="event-log-button">Event Log</button>
 	<button id="event-log-button">Event Log</button>
 	<button id="debug-info-button">Element Info</button>
 	<button id="debug-info-button">Element Info</button>
 	<button id="outlines-button">Outlines</button>
 	<button id="outlines-button">Outlines</button>
-</div>;
+</div>
 )RML";
 )RML";