1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 19:54:57 +00:00

LibHTML: Add a way to get a Document's title

You can now query Document::title() to get a String containing whatever
is inside the document's <title> tag.

In support of this, this patch adds the <html>, <head> and <title>
elements.
This commit is contained in:
Andreas Kling 2019-09-29 16:24:57 +02:00
parent 0c6af2d5b4
commit b94c7665a9
12 changed files with 116 additions and 1 deletions

View file

@ -2,7 +2,10 @@
#include <AK/StringBuilder.h>
#include <LibHTML/DOM/Element.h>
#include <LibHTML/DOM/HTMLAnchorElement.h>
#include <LibHTML/DOM/HTMLHeadElement.h>
#include <LibHTML/DOM/HTMLHeadingElement.h>
#include <LibHTML/DOM/HTMLHtmlElement.h>
#include <LibHTML/DOM/HTMLTitleElement.h>
#include <LibHTML/DOM/Text.h>
#include <LibHTML/Parser/HTMLParser.h>
#include <ctype.h>
@ -13,6 +16,12 @@ static NonnullRefPtr<Element> create_element(Document& document, const String& t
auto lowercase_tag_name = tag_name.to_lowercase();
if (lowercase_tag_name == "a")
return adopt(*new HTMLAnchorElement(document, tag_name));
if (lowercase_tag_name == "html")
return adopt(*new HTMLHtmlElement(document, tag_name));
if (lowercase_tag_name == "head")
return adopt(*new HTMLHeadElement(document, tag_name));
if (lowercase_tag_name == "title")
return adopt(*new HTMLTitleElement(document, tag_name));
if (lowercase_tag_name == "h1"
|| lowercase_tag_name == "h2"
|| lowercase_tag_name == "h3"