XMLNodeHandlerBody.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "XMLNodeHandlerBody.h"
  2. #include "../../Include/RmlUi/Core/ElementDocument.h"
  3. #include "../../Include/RmlUi/Core/Factory.h"
  4. #include "../../Include/RmlUi/Core/XMLParser.h"
  5. #include "XMLParseTools.h"
  6. namespace Rml {
  7. XMLNodeHandlerBody::XMLNodeHandlerBody() {}
  8. XMLNodeHandlerBody::~XMLNodeHandlerBody() {}
  9. Element* XMLNodeHandlerBody::ElementStart(XMLParser* parser, const String& /*name*/, const XMLAttributes& attributes)
  10. {
  11. Element* element = parser->GetParseFrame()->element;
  12. // Apply any attributes to the document, but only if the current element is the root of the current document,
  13. // which should only hold for body elements, but not for inline injected templates.
  14. ElementDocument* document = parser->GetParseFrame()->element->GetOwnerDocument();
  15. if (document && document == element)
  16. {
  17. for (auto& pair : attributes)
  18. {
  19. Variant* attribute = document->GetAttribute(pair.first);
  20. if (attribute && *attribute != pair.second && pair.first != "template")
  21. {
  22. Log::Message(Log::LT_WARNING, "Overriding attribute '%s' in element %s during template injection.", pair.first.c_str(),
  23. element->GetAddress().c_str());
  24. }
  25. }
  26. document->SetAttributes(attributes);
  27. }
  28. // Check for and apply any template
  29. String template_name = Get<String>(attributes, "template", "");
  30. if (!template_name.empty())
  31. {
  32. element = XMLParseTools::ParseTemplate(element, template_name);
  33. }
  34. // Tell the parser to use the element handler for all children
  35. parser->PushDefaultHandler();
  36. return element;
  37. }
  38. bool XMLNodeHandlerBody::ElementEnd(XMLParser* /*parser*/, const String& /*name*/)
  39. {
  40. return true;
  41. }
  42. bool XMLNodeHandlerBody::ElementData(XMLParser* parser, const String& data, XMLDataType /*type*/)
  43. {
  44. return Factory::InstanceElementText(parser->GetParseFrame()->element, data);
  45. }
  46. } // namespace Rml