XMLNodeHandlerDefault.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "XMLNodeHandlerDefault.h"
  2. #include "../../Include/RmlUi/Core/Element.h"
  3. #include "../../Include/RmlUi/Core/ElementUtilities.h"
  4. #include "../../Include/RmlUi/Core/Factory.h"
  5. #include "../../Include/RmlUi/Core/Log.h"
  6. #include "../../Include/RmlUi/Core/Profiling.h"
  7. #include "../../Include/RmlUi/Core/XMLParser.h"
  8. #include "XMLParseTools.h"
  9. namespace Rml {
  10. XMLNodeHandlerDefault::XMLNodeHandlerDefault() {}
  11. XMLNodeHandlerDefault::~XMLNodeHandlerDefault() {}
  12. Element* XMLNodeHandlerDefault::ElementStart(XMLParser* parser, const String& name, const XMLAttributes& attributes)
  13. {
  14. RMLUI_ZoneScopedC(0x556B2F);
  15. // Determine the parent
  16. Element* parent = parser->GetParseFrame()->element;
  17. // Attempt to instance the element with the instancer
  18. ElementPtr element = Factory::InstanceElement(parent, name, name, attributes);
  19. if (!element)
  20. {
  21. Log::Message(Log::LT_ERROR, "Failed to create element for tag %s, instancer returned nullptr.", name.c_str());
  22. return nullptr;
  23. }
  24. // Move and append the element to the parent
  25. Element* result = parent->AppendChild(std::move(element));
  26. return result;
  27. }
  28. bool XMLNodeHandlerDefault::ElementEnd(XMLParser* /*parser*/, const String& /*name*/)
  29. {
  30. return true;
  31. }
  32. bool XMLNodeHandlerDefault::ElementData(XMLParser* parser, const String& data, XMLDataType type)
  33. {
  34. RMLUI_ZoneScopedC(0x006400);
  35. // Determine the parent
  36. Element* parent = parser->GetParseFrame()->element;
  37. RMLUI_ASSERT(parent);
  38. if (type == XMLDataType::InnerXML)
  39. {
  40. // Structural data views use the raw inner xml contents of the node, store them as an attribute to be processed by the data view.
  41. parent->SetAttribute("rmlui-inner-rml", data);
  42. return true;
  43. }
  44. // Parse the text into the element
  45. return Factory::InstanceElementText(parent, data);
  46. }
  47. } // namespace Rml