LibWeb: Implement <template> parsing

Note that there is currently no way to display them as we can't
currently clone nodes.

Adds special case for templates for dumping to console.
Doesn't add it to the DOM inspector as I'm not sure how to do it.
This commit is contained in:
Luke 2020-08-19 22:30:33 +01:00 committed by Andreas Kling
parent f48feae0b2
commit 7902d215b3
Notes: sideshowbarker 2024-07-19 03:23:09 +09:00
14 changed files with 174 additions and 28 deletions

View file

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLTemplateElement.h>
namespace Web::HTML {
@ -31,10 +32,30 @@ namespace Web::HTML {
HTMLTemplateElement::HTMLTemplateElement(DOM::Document& document, const FlyString& tag_name)
: HTMLElement(document, tag_name)
{
m_content = adopt(*new DOM::DocumentFragment(appropriate_template_contents_owner_document(document)));
m_content->set_host(*this);
}
HTMLTemplateElement::~HTMLTemplateElement()
{
}
DOM::Document& HTMLTemplateElement::appropriate_template_contents_owner_document(DOM::Document& document)
{
if (!document.created_for_appropriate_template_contents()) {
if (!document.associated_inert_template_document()) {
DOM::Document new_document;
new_document.set_created_for_appropriate_template_contents(true);
// FIXME: If doc is an HTML document, mark new doc as an HTML document also.
document.set_associated_inert_template_document(new_document);
}
return *document.associated_inert_template_document();
}
return document;
}
}