mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:57:35 +00:00
LibHTML: Flesh out <img> element with LayoutImage and LayoutReplaced
This patch adds parsing of <img> into HTMLImageElement objects. It also adds LayoutImage and its parent class LayoutReplaced, which is going to represent CSS "replaced elements."
This commit is contained in:
parent
7162347563
commit
09dccb3224
11 changed files with 96 additions and 2 deletions
20
Libraries/LibHTML/Layout/LayoutImage.cpp
Normal file
20
Libraries/LibHTML/Layout/LayoutImage.cpp
Normal file
|
@ -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);
|
||||
}
|
18
Libraries/LibHTML/Layout/LayoutImage.h
Normal file
18
Libraries/LibHTML/Layout/LayoutImage.h
Normal file
|
@ -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:
|
||||
};
|
|
@ -4,6 +4,7 @@
|
|||
LayoutInline::LayoutInline(const Node& node, RefPtr<StyleProperties> style_properties)
|
||||
: LayoutNode(&node, move(style_properties))
|
||||
{
|
||||
set_inline(true);
|
||||
}
|
||||
|
||||
LayoutInline::~LayoutInline()
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 };
|
||||
};
|
||||
|
|
13
Libraries/LibHTML/Layout/LayoutReplaced.cpp
Normal file
13
Libraries/LibHTML/Layout/LayoutReplaced.cpp
Normal file
|
@ -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()
|
||||
{
|
||||
}
|
12
Libraries/LibHTML/Layout/LayoutReplaced.h
Normal file
12
Libraries/LibHTML/Layout/LayoutReplaced.h
Normal file
|
@ -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:
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue