diff options
-rw-r--r-- | Libraries/LibHTML/DOM/HTMLImageElement.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibHTML/DOM/HTMLImageElement.h | 12 | ||||
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutImage.cpp | 20 | ||||
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutImage.h | 18 | ||||
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutInline.cpp | 1 | ||||
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutInline.h | 1 | ||||
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutNode.h | 5 | ||||
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutReplaced.cpp | 13 | ||||
-rw-r--r-- | Libraries/LibHTML/Layout/LayoutReplaced.h | 12 | ||||
-rw-r--r-- | Libraries/LibHTML/Makefile.shared | 3 | ||||
-rw-r--r-- | Libraries/LibHTML/Parser/HTMLParser.cpp | 3 |
11 files changed, 96 insertions, 2 deletions
diff --git a/Libraries/LibHTML/DOM/HTMLImageElement.cpp b/Libraries/LibHTML/DOM/HTMLImageElement.cpp new file mode 100644 index 0000000000..864cc2b91e --- /dev/null +++ b/Libraries/LibHTML/DOM/HTMLImageElement.cpp @@ -0,0 +1,10 @@ +#include <LibHTML/DOM/HTMLImageElement.h> + +HTMLImageElement::HTMLImageElement(Document& document, const String& tag_name) + : HTMLElement(document, tag_name) +{ +} + +HTMLImageElement::~HTMLImageElement() +{ +} diff --git a/Libraries/LibHTML/DOM/HTMLImageElement.h b/Libraries/LibHTML/DOM/HTMLImageElement.h new file mode 100644 index 0000000000..0bb37bd2ed --- /dev/null +++ b/Libraries/LibHTML/DOM/HTMLImageElement.h @@ -0,0 +1,12 @@ +#pragma once + +#include <LibHTML/DOM/HTMLElement.h> + +class HTMLImageElement : public HTMLElement { +public: + HTMLImageElement(Document&, const String& tag_name); + virtual ~HTMLImageElement() override; + + String alt() const { return attribute("alt"); } + String src() const { return attribute("src"); } +}; diff --git a/Libraries/LibHTML/Layout/LayoutImage.cpp b/Libraries/LibHTML/Layout/LayoutImage.cpp new file mode 100644 index 0000000000..36dcafafaf --- /dev/null +++ b/Libraries/LibHTML/Layout/LayoutImage.cpp @@ -0,0 +1,20 @@ +#include <LibHTML/Layout/LayoutImage.h> + +LayoutImage::LayoutImage(const HTMLImageElement& element, NonnullRefPtr<StyleProperties> style) + : LayoutReplaced(element, move(style)) +{ +} + +LayoutImage::~LayoutImage() +{ +} + +void LayoutImage::layout() +{ + LayoutReplaced::layout(); +} + +void LayoutImage::render(RenderingContext& context) +{ + LayoutReplaced::render(context); +} diff --git a/Libraries/LibHTML/Layout/LayoutImage.h b/Libraries/LibHTML/Layout/LayoutImage.h new file mode 100644 index 0000000000..0a6105a891 --- /dev/null +++ b/Libraries/LibHTML/Layout/LayoutImage.h @@ -0,0 +1,18 @@ +#pragma once + +#include <LibHTML/DOM/HTMLImageElement.h> +#include <LibHTML/Layout/LayoutReplaced.h> + +class HTMLImageElement; + +class LayoutImage : public LayoutReplaced { +public: + LayoutImage(const HTMLImageElement&, NonnullRefPtr<StyleProperties>); + virtual ~LayoutImage() override; + + virtual void layout() override; + virtual void render(RenderingContext&) override; + + const HTMLImageElement& node() const { return static_cast<const HTMLImageElement&>(LayoutReplaced::node()); } +private: +}; diff --git a/Libraries/LibHTML/Layout/LayoutInline.cpp b/Libraries/LibHTML/Layout/LayoutInline.cpp index 345bfbdef6..60f195faf5 100644 --- a/Libraries/LibHTML/Layout/LayoutInline.cpp +++ b/Libraries/LibHTML/Layout/LayoutInline.cpp @@ -4,6 +4,7 @@ LayoutInline::LayoutInline(const Node& node, RefPtr<StyleProperties> style_properties) : LayoutNode(&node, move(style_properties)) { + set_inline(true); } LayoutInline::~LayoutInline() diff --git a/Libraries/LibHTML/Layout/LayoutInline.h b/Libraries/LibHTML/Layout/LayoutInline.h index 34dfba49d6..8eecf9fc49 100644 --- a/Libraries/LibHTML/Layout/LayoutInline.h +++ b/Libraries/LibHTML/Layout/LayoutInline.h @@ -10,7 +10,6 @@ public: virtual ~LayoutInline() override; virtual const char* class_name() const override { return "LayoutInline"; } - virtual bool is_inline() const override { return true; } virtual void split_into_lines(LayoutBlock& container); diff --git a/Libraries/LibHTML/Layout/LayoutNode.h b/Libraries/LibHTML/Layout/LayoutNode.h index 2055a12f4e..f75da03d6c 100644 --- a/Libraries/LibHTML/Layout/LayoutNode.h +++ b/Libraries/LibHTML/Layout/LayoutNode.h @@ -53,7 +53,9 @@ public: virtual const char* class_name() const { return "LayoutNode"; } virtual bool is_text() const { return false; } virtual bool is_block() const { return false; } - virtual bool is_inline() const { return false; } + + bool is_inline() const { return m_inline; } + void set_inline(bool b) { m_inline = b; } virtual void layout(); virtual void render(RenderingContext&); @@ -81,4 +83,5 @@ private: RefPtr<StyleProperties> m_style_properties; BoxModelMetrics m_style; Rect m_rect; + bool m_inline { false }; }; diff --git a/Libraries/LibHTML/Layout/LayoutReplaced.cpp b/Libraries/LibHTML/Layout/LayoutReplaced.cpp new file mode 100644 index 0000000000..2634be9b09 --- /dev/null +++ b/Libraries/LibHTML/Layout/LayoutReplaced.cpp @@ -0,0 +1,13 @@ +#include <LibHTML/DOM/Element.h> +#include <LibHTML/Layout/LayoutReplaced.h> + +LayoutReplaced::LayoutReplaced(const Element& element, NonnullRefPtr<StyleProperties> style) + : LayoutNode(&element, move(style)) +{ + // FIXME: Allow non-inline replaced elements. + set_inline(true); +} + +LayoutReplaced::~LayoutReplaced() +{ +} diff --git a/Libraries/LibHTML/Layout/LayoutReplaced.h b/Libraries/LibHTML/Layout/LayoutReplaced.h new file mode 100644 index 0000000000..40f11a283c --- /dev/null +++ b/Libraries/LibHTML/Layout/LayoutReplaced.h @@ -0,0 +1,12 @@ +#include <LibHTML/DOM/Element.h> +#include <LibHTML/Layout/LayoutNode.h> + +class LayoutReplaced : public LayoutNode { +public: + LayoutReplaced(const Element&, NonnullRefPtr<StyleProperties>); + virtual ~LayoutReplaced(); + + const Element& node() const { return static_cast<const Element&>(*LayoutNode::node()); } + +private: +}; diff --git a/Libraries/LibHTML/Makefile.shared b/Libraries/LibHTML/Makefile.shared index 3427f2bd06..831eefa4c2 100644 --- a/Libraries/LibHTML/Makefile.shared +++ b/Libraries/LibHTML/Makefile.shared @@ -12,6 +12,7 @@ LIBHTML_OBJS = \ DOM/HTMLTitleElement.o \ DOM/HTMLBodyElement.o \ DOM/HTMLFontElement.o \ + DOM/HTMLImageElement.o \ DOM/Document.o \ DOM/Text.o \ CSS/Selector.o \ @@ -29,6 +30,8 @@ LIBHTML_OBJS = \ Layout/LayoutBlock.o \ Layout/LayoutInline.o \ Layout/LayoutDocument.o \ + Layout/LayoutReplaced.o \ + Layout/LayoutImage.o \ Layout/BoxModelMetrics.o \ Layout/LineBox.o \ Layout/LineBoxFragment.o \ diff --git a/Libraries/LibHTML/Parser/HTMLParser.cpp b/Libraries/LibHTML/Parser/HTMLParser.cpp index 4d48f0b82e..eddf861b39 100644 --- a/Libraries/LibHTML/Parser/HTMLParser.cpp +++ b/Libraries/LibHTML/Parser/HTMLParser.cpp @@ -9,6 +9,7 @@ #include <LibHTML/DOM/HTMLHeadElement.h> #include <LibHTML/DOM/HTMLHeadingElement.h> #include <LibHTML/DOM/HTMLHtmlElement.h> +#include <LibHTML/DOM/HTMLImageElement.h> #include <LibHTML/DOM/HTMLStyleElement.h> #include <LibHTML/DOM/HTMLTitleElement.h> #include <LibHTML/DOM/Text.h> @@ -35,6 +36,8 @@ static NonnullRefPtr<Element> create_element(Document& document, const String& t return adopt(*new HTMLStyleElement(document, tag_name)); if (lowercase_tag_name == "title") return adopt(*new HTMLTitleElement(document, tag_name)); + if (lowercase_tag_name == "img") + return adopt(*new HTMLImageElement(document, tag_name)); if (lowercase_tag_name == "h1" || lowercase_tag_name == "h2" || lowercase_tag_name == "h3" |