mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
LibHTML: Implement basic tiled background image support
It's now possible to set a page background image via <body background>. Also, HtmlView now officially handles rendering the body element's background (color, image or both.) LayoutBox is responsible for all other background rendering. Note that it's not yet possible to use CSS background-image properties directly, since we can't parse them yet. :^)
This commit is contained in:
parent
96f10c8de2
commit
5a34225999
11 changed files with 101 additions and 7 deletions
|
@ -7,6 +7,7 @@ enum class PropertyID {
|
|||
Invalid,
|
||||
|
||||
BackgroundColor,
|
||||
BackgroundImage,
|
||||
BorderBottomColor,
|
||||
BorderBottomStyle,
|
||||
BorderBottomWidth,
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#include <LibDraw/GraphicsBitmap.h>
|
||||
#include <LibDraw/PNGLoader.h>
|
||||
#include <LibHTML/CSS/StyleValue.h>
|
||||
#include <LibHTML/DOM/Document.h>
|
||||
#include <LibHTML/Frame.h>
|
||||
#include <LibHTML/ResourceLoader.h>
|
||||
|
||||
StyleValue::StyleValue(Type type)
|
||||
: m_type(type)
|
||||
|
@ -28,3 +32,20 @@ Color IdentifierStyleValue::to_color(const Document& document) const
|
|||
return document.link_color();
|
||||
return {};
|
||||
}
|
||||
|
||||
ImageStyleValue::ImageStyleValue(const URL& url, Document& document)
|
||||
: StyleValue(Type::Image)
|
||||
, m_url(url)
|
||||
, m_document(document.make_weak_ptr())
|
||||
{
|
||||
NonnullRefPtr<ImageStyleValue> protector(*this);
|
||||
ResourceLoader::the().load(url, [this, protector](auto& data) {
|
||||
if (!m_document)
|
||||
return;
|
||||
m_bitmap = load_png_from_memory(data.data(), data.size());
|
||||
if (!m_bitmap)
|
||||
return;
|
||||
// FIXME: Do less than a full repaint if possible?
|
||||
m_document->frame()->set_needs_display({});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
#include <AK/RefPtr.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/URL.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibDraw/Color.h>
|
||||
#include <LibDraw/GraphicsBitmap.h>
|
||||
#include <LibHTML/CSS/Length.h>
|
||||
#include <LibHTML/CSS/PropertyID.h>
|
||||
|
||||
|
@ -32,6 +35,7 @@ public:
|
|||
Length,
|
||||
Color,
|
||||
Identifier,
|
||||
Image,
|
||||
};
|
||||
|
||||
Type type() const { return m_type; }
|
||||
|
@ -40,6 +44,7 @@ public:
|
|||
bool is_initial() const { return type() == Type::Initial; }
|
||||
bool is_color() const { return type() == Type::Color; }
|
||||
bool is_identifier() const { return type() == Type::Identifier; }
|
||||
bool is_image() const { return type() == Type::Image; }
|
||||
|
||||
virtual String to_string() const = 0;
|
||||
virtual Length to_length() const { return {}; }
|
||||
|
@ -171,3 +176,20 @@ private:
|
|||
|
||||
CSS::ValueID m_id { CSS::ValueID::Invalid };
|
||||
};
|
||||
|
||||
class ImageStyleValue final : public StyleValue {
|
||||
public:
|
||||
static NonnullRefPtr<ImageStyleValue> create(const URL& url, Document& document) { return adopt(*new ImageStyleValue(url, document)); }
|
||||
virtual ~ImageStyleValue() override {}
|
||||
|
||||
String to_string() const override { return String::format("Image{%s}", m_url.to_string().characters()); }
|
||||
|
||||
const GraphicsBitmap* bitmap() const { return m_bitmap; }
|
||||
|
||||
private:
|
||||
ImageStyleValue(const URL&, Document&);
|
||||
|
||||
URL m_url;
|
||||
WeakPtr<Document> m_document;
|
||||
RefPtr<GraphicsBitmap> m_bitmap;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue