mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:47:44 +00:00
LibHTML: Add a simple <style> element for inline CSS
This commit is contained in:
parent
7912592f89
commit
a4fccc02ec
4 changed files with 49 additions and 0 deletions
28
Libraries/LibHTML/DOM/HTMLStyleElement.cpp
Normal file
28
Libraries/LibHTML/DOM/HTMLStyleElement.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include <LibHTML/DOM/Document.h>
|
||||||
|
#include <LibHTML/DOM/HTMLStyleElement.h>
|
||||||
|
#include <LibHTML/Parser/CSSParser.h>
|
||||||
|
|
||||||
|
HTMLStyleElement::HTMLStyleElement(Document& document, const String& tag_name)
|
||||||
|
: HTMLElement(document, tag_name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
HTMLStyleElement::~HTMLStyleElement()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTMLStyleElement::inserted_into(Node& new_parent)
|
||||||
|
{
|
||||||
|
m_stylesheet = parse_css(text_content());
|
||||||
|
if (m_stylesheet)
|
||||||
|
document().add_sheet(*m_stylesheet);
|
||||||
|
HTMLElement::inserted_into(new_parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HTMLStyleElement::removed_from(Node& old_parent)
|
||||||
|
{
|
||||||
|
if (m_stylesheet) {
|
||||||
|
// FIXME: Remove the sheet from the document
|
||||||
|
}
|
||||||
|
return HTMLElement::removed_from(old_parent);
|
||||||
|
}
|
17
Libraries/LibHTML/DOM/HTMLStyleElement.h
Normal file
17
Libraries/LibHTML/DOM/HTMLStyleElement.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibHTML/DOM/HTMLElement.h>
|
||||||
|
|
||||||
|
class StyleSheet;
|
||||||
|
|
||||||
|
class HTMLStyleElement : public HTMLElement {
|
||||||
|
public:
|
||||||
|
HTMLStyleElement(Document&, const String& tag_name);
|
||||||
|
virtual ~HTMLStyleElement() override;
|
||||||
|
|
||||||
|
virtual void inserted_into(Node&) override;
|
||||||
|
virtual void removed_from(Node&) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
RefPtr<StyleSheet> m_stylesheet;
|
||||||
|
};
|
|
@ -7,6 +7,7 @@ LIBHTML_OBJS = \
|
||||||
DOM/HTMLHeadingElement.o \
|
DOM/HTMLHeadingElement.o \
|
||||||
DOM/HTMLHeadElement.o \
|
DOM/HTMLHeadElement.o \
|
||||||
DOM/HTMLHtmlElement.o \
|
DOM/HTMLHtmlElement.o \
|
||||||
|
DOM/HTMLStyleElement.o \
|
||||||
DOM/HTMLTitleElement.o \
|
DOM/HTMLTitleElement.o \
|
||||||
DOM/Document.o \
|
DOM/Document.o \
|
||||||
DOM/Text.o \
|
DOM/Text.o \
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <LibHTML/DOM/HTMLHeadElement.h>
|
#include <LibHTML/DOM/HTMLHeadElement.h>
|
||||||
#include <LibHTML/DOM/HTMLHeadingElement.h>
|
#include <LibHTML/DOM/HTMLHeadingElement.h>
|
||||||
#include <LibHTML/DOM/HTMLHtmlElement.h>
|
#include <LibHTML/DOM/HTMLHtmlElement.h>
|
||||||
|
#include <LibHTML/DOM/HTMLStyleElement.h>
|
||||||
#include <LibHTML/DOM/HTMLTitleElement.h>
|
#include <LibHTML/DOM/HTMLTitleElement.h>
|
||||||
#include <LibHTML/DOM/Text.h>
|
#include <LibHTML/DOM/Text.h>
|
||||||
#include <LibHTML/Parser/HTMLParser.h>
|
#include <LibHTML/Parser/HTMLParser.h>
|
||||||
|
@ -21,6 +22,8 @@ static NonnullRefPtr<Element> create_element(Document& document, const String& t
|
||||||
return adopt(*new HTMLHtmlElement(document, tag_name));
|
return adopt(*new HTMLHtmlElement(document, tag_name));
|
||||||
if (lowercase_tag_name == "head")
|
if (lowercase_tag_name == "head")
|
||||||
return adopt(*new HTMLHeadElement(document, tag_name));
|
return adopt(*new HTMLHeadElement(document, tag_name));
|
||||||
|
if (lowercase_tag_name == "style")
|
||||||
|
return adopt(*new HTMLStyleElement(document, tag_name));
|
||||||
if (lowercase_tag_name == "title")
|
if (lowercase_tag_name == "title")
|
||||||
return adopt(*new HTMLTitleElement(document, tag_name));
|
return adopt(*new HTMLTitleElement(document, tag_name));
|
||||||
if (lowercase_tag_name == "h1"
|
if (lowercase_tag_name == "h1"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue