1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 06:37:40 +00:00

LibDraw: Put all classes in the Gfx namespace

I started adding things to a Draw namespace, but it somehow felt really
wrong seeing Draw::Rect and Draw::Bitmap, etc. So instead, let's rename
the library to LibGfx. :^)
This commit is contained in:
Andreas Kling 2020-02-06 11:56:38 +01:00
parent 939a605334
commit 11580babbf
269 changed files with 1513 additions and 1315 deletions

View file

@ -136,9 +136,9 @@ void StyleProperties::load_font() const
dbg() << "Failed to find a font for family " << font_family << " weight " << font_weight;
if (font_weight == "bold")
m_font = Font::default_bold_font();
m_font = Gfx::Font::default_bold_font();
else
m_font = Font::default_font();
m_font = Gfx::Font::default_font();
return;
}
@ -146,7 +146,7 @@ void StyleProperties::load_font() const
dbg() << "Found font " << file_name << " for family " << font_family << " weight " << font_weight;
#endif
m_font = Font::load_from_file(String::format("/res/fonts/%s", file_name.characters()));
m_font = Gfx::Font::load_from_file(String::format("/res/fonts/%s", file_name.characters()));
FontCache::the().set({ font_family, font_weight }, *m_font);
}

View file

@ -31,7 +31,9 @@
#include <LibDraw/Font.h>
#include <LibHTML/CSS/StyleValue.h>
namespace Gfx {
class Color;
}
class StyleProperties : public RefCounted<StyleProperties> {
public:
@ -57,7 +59,7 @@ public:
String string_or_fallback(CSS::PropertyID, const StringView& fallback) const;
Color color_or_fallback(CSS::PropertyID, const Document&, Color fallback) const;
const Font& font() const
const Gfx::Font& font() const
{
if (!m_font)
load_font();
@ -74,5 +76,5 @@ private:
void load_font() const;
mutable RefPtr<Font> m_font;
mutable RefPtr<Gfx::Font> m_font;
};

View file

@ -68,7 +68,7 @@ ImageStyleValue::ImageStyleValue(const URL& url, Document& document)
ResourceLoader::the().load(url, [this, protector](auto& data) {
if (!m_document)
return;
m_bitmap = load_png_from_memory(data.data(), data.size());
m_bitmap = Gfx::load_png_from_memory(data.data(), data.size());
if (!m_bitmap)
return;
// FIXME: Do less than a full repaint if possible?

View file

@ -213,12 +213,12 @@ public:
String to_string() const override { return String::format("Image{%s}", m_url.to_string().characters()); }
const GraphicsBitmap* bitmap() const { return m_bitmap; }
const Gfx::Bitmap* bitmap() const { return m_bitmap; }
private:
ImageStyleValue(const URL&, Document&);
URL m_url;
WeakPtr<Document> m_document;
RefPtr<GraphicsBitmap> m_bitmap;
RefPtr<Gfx::Bitmap> m_bitmap;
};

View file

@ -162,7 +162,7 @@ Color Document::background_color(const Palette& palette) const
return background_color.value()->to_color(*this);
}
RefPtr<GraphicsBitmap> Document::background_image() const
RefPtr<Gfx::Bitmap> Document::background_image() const
{
auto* body_element = body();
if (!body_element)

View file

@ -40,7 +40,10 @@ namespace Core {
class Timer;
}
namespace Gfx {
class Palette;
}
class Frame;
class HTMLBodyElement;
class HTMLHtmlElement;
@ -90,8 +93,8 @@ public:
Frame* frame() { return m_frame.ptr(); }
const Frame* frame() const { return m_frame.ptr(); }
Color background_color(const Palette&) const;
RefPtr<GraphicsBitmap> background_image() const;
Color background_color(const Gfx::Palette&) const;
RefPtr<Gfx::Bitmap> background_image() const;
Color link_color() const;
void set_link_color(Color);

View file

@ -60,7 +60,7 @@ void HTMLImageElement::load_image(const String& src)
}
m_encoded_data = data;
m_image_decoder = ImageDecoder::create(m_encoded_data.data(), m_encoded_data.size());
m_image_decoder = Gfx::ImageDecoder::create(m_encoded_data.data(), m_encoded_data.size());
document().update_layout();
});
}
@ -100,7 +100,7 @@ RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const StyleProperties* p
return adopt(*new LayoutImage(*this, move(style)));
}
const GraphicsBitmap* HTMLImageElement::bitmap() const
const Gfx::Bitmap* HTMLImageElement::bitmap() const
{
if (!m_image_decoder)
return nullptr;
@ -118,5 +118,5 @@ void HTMLImageElement::set_volatile(Badge<LayoutDocument>, bool v)
bool has_image = m_image_decoder->set_nonvolatile();
if (has_image)
return;
m_image_decoder = ImageDecoder::create(m_encoded_data.data(), m_encoded_data.size());
m_image_decoder = Gfx::ImageDecoder::create(m_encoded_data.data(), m_encoded_data.size());
}

View file

@ -44,8 +44,8 @@ public:
int preferred_width() const;
int preferred_height() const;
const GraphicsBitmap* bitmap() const;
const ImageDecoder* image_decoder() const { return m_image_decoder; }
const Gfx::Bitmap* bitmap() const;
const Gfx::ImageDecoder* image_decoder() const { return m_image_decoder; }
void set_volatile(Badge<LayoutDocument>, bool);
@ -54,6 +54,6 @@ private:
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
RefPtr<ImageDecoder> m_image_decoder;
RefPtr<Gfx::ImageDecoder> m_image_decoder;
ByteBuffer m_encoded_data;
};

View file

@ -52,7 +52,7 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties*)
RefPtr<GUI::Widget> widget;
if (type() == "submit") {
auto button = GUI::Button::construct(value(), &html_view);
int text_width = Font::default_font().width(value());
int text_width = Gfx::Font::default_font().width(value());
button->set_relative_rect(0, 0, text_width + 20, 20);
button->on_click = [this](auto&) {
if (auto* form = first_ancestor_of_type<HTMLFormElement>()) {
@ -68,7 +68,7 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties*)
auto& widget = to<LayoutWidget>(layout_node())->widget();
const_cast<HTMLInputElement*>(this)->set_attribute("value", static_cast<const GUI::TextBox&>(widget).text());
};
int text_width = Font::default_font().width(value());
int text_width = Gfx::Font::default_font().width(value());
text_box->set_relative_rect(0, 0, text_width + 20, 20);
widget = text_box;
}

View file

@ -35,9 +35,9 @@
DOMTreeModel::DOMTreeModel(Document& document)
: m_document(document)
{
m_document_icon.set_bitmap_for_size(16, GraphicsBitmap::load_from_file("/res/icons/16x16/filetype-html.png"));
m_element_icon.set_bitmap_for_size(16, GraphicsBitmap::load_from_file("/res/icons/16x16/inspector-object.png"));
m_text_icon.set_bitmap_for_size(16, GraphicsBitmap::load_from_file("/res/icons/16x16/filetype-unknown.png"));
m_document_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-html.png"));
m_element_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png"));
m_text_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/filetype-unknown.png"));
}
DOMTreeModel::~DOMTreeModel()

View file

@ -33,7 +33,7 @@ FontCache& FontCache::the()
return cache;
}
RefPtr<Font> FontCache::get(const FontSelector& font_selector) const
RefPtr<Gfx::Font> FontCache::get(const FontSelector& font_selector) const
{
auto cached_font = m_fonts.get(font_selector);
if (cached_font.has_value())
@ -41,7 +41,7 @@ RefPtr<Font> FontCache::get(const FontSelector& font_selector) const
return nullptr;
}
void FontCache::set(const FontSelector& font_selector, NonnullRefPtr<Font> font)
void FontCache::set(const FontSelector& font_selector, NonnullRefPtr<Gfx::Font> font)
{
m_fonts.set(font_selector, move(font));
}

View file

@ -29,7 +29,9 @@
#include <AK/HashMap.h>
#include <AK/String.h>
namespace Gfx {
class Font;
}
struct FontSelector {
String family;
@ -51,10 +53,10 @@ struct Traits<FontSelector> : public GenericTraits<FontSelector> {
class FontCache {
public:
static FontCache& the();
RefPtr<Font> get(const FontSelector&) const;
void set(const FontSelector&, NonnullRefPtr<Font>);
RefPtr<Gfx::Font> get(const FontSelector&) const;
void set(const FontSelector&, NonnullRefPtr<Gfx::Font>);
private:
FontCache() {}
mutable HashMap<FontSelector, NonnullRefPtr<Font>> m_fonts;
mutable HashMap<FontSelector, NonnullRefPtr<Gfx::Font>> m_fonts;
};

View file

@ -52,14 +52,14 @@ void Frame::set_document(Document* document)
m_document->attach_to_frame({}, *this);
}
void Frame::set_size(const Size& size)
void Frame::set_size(const Gfx::Size& size)
{
if (m_size == size)
return;
m_size = size;
}
void Frame::set_viewport_rect(const Rect& rect)
void Frame::set_viewport_rect(const Gfx::Rect& rect)
{
if (m_viewport_rect == rect)
return;
@ -69,7 +69,7 @@ void Frame::set_viewport_rect(const Rect& rect)
m_document->layout_node()->did_set_viewport_rect({}, rect);
}
void Frame::set_needs_display(const Rect& rect)
void Frame::set_needs_display(const Gfx::Rect& rect)
{
if (!m_viewport_rect.intersects(rect))
return;

View file

@ -50,13 +50,13 @@ public:
HtmlView* html_view() { return m_html_view; }
const HtmlView* html_view() const { return m_html_view; }
const Size& size() const { return m_size; }
void set_size(const Size&);
const Gfx::Size& size() const { return m_size; }
void set_size(const Gfx::Size&);
void set_needs_display(const Rect&);
Function<void(const Rect&)> on_set_needs_display;
void set_needs_display(const Gfx::Rect&);
Function<void(const Gfx::Rect&)> on_set_needs_display;
void set_viewport_rect(const Rect&);
void set_viewport_rect(const Gfx::Rect&);
Rect viewport_rect() const { return m_viewport_rect; }
private:
@ -64,6 +64,6 @@ private:
WeakPtr<HtmlView> m_html_view;
RefPtr<Document> m_document;
Size m_size;
Rect m_viewport_rect;
Gfx::Size m_size;
Gfx::Rect m_viewport_rect;
};

View file

@ -60,8 +60,8 @@ HtmlView::HtmlView(GUI::Widget* parent)
update(adjusted_rect);
};
set_frame_shape(FrameShape::Container);
set_frame_shadow(FrameShadow::Sunken);
set_frame_shape(Gfx::FrameShape::Container);
set_frame_shadow(Gfx::FrameShadow::Sunken);
set_frame_thickness(2);
set_should_hide_unnecessary_scrollbars(true);
set_background_role(ColorRole::Base);
@ -297,7 +297,7 @@ static RefPtr<Document> create_image_document(const ByteBuffer& data, const URL&
auto document = adopt(*new Document);
document->set_url(url);
auto bitmap = load_png_from_memory(data.data(), data.size());
auto bitmap = Gfx::load_png_from_memory(data.data(), data.size());
ASSERT(bitmap);
auto html_element = create_element(document, "html");

View file

@ -344,7 +344,7 @@ void LayoutBlock::render(RenderingContext& context)
}
}
HitTestResult LayoutBlock::hit_test(const Point& position) const
HitTestResult LayoutBlock::hit_test(const Gfx::Point& position) const
{
if (!children_are_inline())
return LayoutBox::hit_test(position);

View file

@ -49,7 +49,7 @@ public:
LineBox& ensure_last_line_box();
LineBox& add_line_box();
virtual HitTestResult hit_test(const Point&) const override;
virtual HitTestResult hit_test(const Gfx::Point&) const override;
LayoutBlock* previous_sibling() { return to<LayoutBlock>(LayoutNode::previous_sibling()); }
const LayoutBlock* previous_sibling() const { return to<LayoutBlock>(LayoutNode::previous_sibling()); }

View file

@ -207,7 +207,7 @@ void LayoutBox::render(RenderingContext& context)
LayoutNodeWithStyleAndBoxModelMetrics::render(context);
}
HitTestResult LayoutBox::hit_test(const Point& position) const
HitTestResult LayoutBox::hit_test(const Gfx::Point& position) const
{
// FIXME: It would be nice if we could confidently skip over hit testing
// parts of the layout tree, but currently we can't just check

View file

@ -42,7 +42,7 @@ public:
FloatSize size() const { return rect().size(); }
FloatPoint position() const { return rect().location(); }
virtual HitTestResult hit_test(const Point& position) const override;
virtual HitTestResult hit_test(const Gfx::Point& position) const override;
virtual void set_needs_display() override;
bool is_body() const;

View file

@ -57,7 +57,7 @@ void LayoutDocument::layout()
rect().set_bottom(lowest_bottom);
}
void LayoutDocument::did_set_viewport_rect(Badge<Frame>, const Rect& a_viewport_rect)
void LayoutDocument::did_set_viewport_rect(Badge<Frame>, const Gfx::Rect& a_viewport_rect)
{
FloatRect viewport_rect(a_viewport_rect.x(), a_viewport_rect.y(), a_viewport_rect.width(), a_viewport_rect.height());
for_each_in_subtree_of_type<LayoutImage>([&](auto& layout_image) {

View file

@ -41,7 +41,7 @@ public:
const LayoutRange& selection() const { return m_selection; }
LayoutRange& selection() { return m_selection; }
void did_set_viewport_rect(Badge<Frame>, const Rect&);
void did_set_viewport_rect(Badge<Frame>, const Gfx::Rect&);
private:
LayoutRange m_selection;

View file

@ -44,7 +44,7 @@ void LayoutImage::layout()
rect().set_width(node().preferred_width());
rect().set_height(node().preferred_height());
} else if (renders_as_alt_text()) {
auto& font = Font::default_font();
auto& font = Gfx::Font::default_font();
auto alt = node().alt();
if (alt.is_empty())
alt = node().src();
@ -68,12 +68,12 @@ void LayoutImage::render(RenderingContext& context)
return;
if (renders_as_alt_text()) {
context.painter().set_font(Font::default_font());
StylePainter::paint_frame(context.painter(), enclosing_int_rect(rect()), context.palette(), FrameShape::Container, FrameShadow::Sunken, 2);
context.painter().set_font(Gfx::Font::default_font());
Gfx::StylePainter::paint_frame(context.painter(), enclosing_int_rect(rect()), context.palette(), Gfx::FrameShape::Container, Gfx::FrameShadow::Sunken, 2);
auto alt = node().alt();
if (alt.is_empty())
alt = node().src();
context.painter().draw_text(enclosing_int_rect(rect()), alt, TextAlignment::Center, style().color_or_fallback(CSS::PropertyID::Color, document(), Color::Black), TextElision::Right);
context.painter().draw_text(enclosing_int_rect(rect()), alt, Gfx::TextAlignment::Center, style().color_or_fallback(CSS::PropertyID::Color, document(), Color::Black), Gfx::TextElision::Right);
} else if (node().bitmap())
context.painter().draw_scaled_bitmap(enclosing_int_rect(rect()), *node().bitmap(), node().bitmap()->rect());
LayoutReplaced::render(context);

View file

@ -71,7 +71,7 @@ void LayoutNode::render(RenderingContext& context)
});
}
HitTestResult LayoutNode::hit_test(const Point& position) const
HitTestResult LayoutNode::hit_test(const Gfx::Point& position) const
{
HitTestResult result;
for_each_child([&](auto& child) {

View file

@ -54,7 +54,7 @@ class LayoutNode : public TreeNode<LayoutNode> {
public:
virtual ~LayoutNode();
virtual HitTestResult hit_test(const Point&) const;
virtual HitTestResult hit_test(const Gfx::Point&) const;
bool is_anonymous() const { return !m_node; }
const Node* node() const { return m_node; }

View file

@ -82,7 +82,7 @@ void LayoutText::render_fragment(RenderingContext& context, const LineBoxFragmen
if (is_underline)
painter.draw_line(enclosing_int_rect(fragment.rect()).bottom_left().translated(0, 1), enclosing_int_rect(fragment.rect()).bottom_right().translated(0, 1), color);
painter.draw_text(enclosing_int_rect(fragment.rect()), m_text_for_rendering.substring_view(fragment.start(), fragment.length()), TextAlignment::TopLeft, color);
painter.draw_text(enclosing_int_rect(fragment.rect()), m_text_for_rendering.substring_view(fragment.start(), fragment.length()), Gfx::TextAlignment::TopLeft, color);
}
template<typename Callback>

View file

@ -48,11 +48,11 @@ public:
void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
Rect viewport_rect() const { return m_viewport_rect; }
void set_viewport_rect(const Rect& rect) { m_viewport_rect = rect; }
void set_viewport_rect(const Gfx::Rect& rect) { m_viewport_rect = rect; }
private:
GUI::Painter& m_painter;
Palette m_palette;
Rect m_viewport_rect;
Gfx::Rect m_viewport_rect;
bool m_should_show_line_box_borders { false };
};