mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
LibHTML: Respect the system theme
LibHTML will now use the palette colors for the default document background and the text. As always, a page can override this default styling with CSS if it really wants a specific color or style. Fixes https://github.com/SerenityOS/serenity/issues/963
This commit is contained in:
parent
7557251fac
commit
0f42908073
Notes:
sideshowbarker
2024-07-19 10:21:02 +09:00
Author: https://github.com/bugaevc Commit: https://github.com/SerenityOS/serenity/commit/0f429080736 Pull-request: https://github.com/SerenityOS/serenity/pull/1019
5 changed files with 14 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
|||
#include <AK/FileSystemPath.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibCore/CTimer.h>
|
||||
#include <LibGUI/GApplication.h>
|
||||
#include <LibHTML/CSS/StyleResolver.h>
|
||||
#include <LibHTML/DOM/Document.h>
|
||||
#include <LibHTML/DOM/DocumentType.h>
|
||||
|
@ -116,19 +117,20 @@ void Document::detach_from_frame(Badge<Frame>, Frame&)
|
|||
m_frame = nullptr;
|
||||
}
|
||||
|
||||
Color Document::background_color() const
|
||||
Color Document::background_color(const Palette& palette) const
|
||||
{
|
||||
auto default_color = palette.base();
|
||||
auto* body_element = body();
|
||||
if (!body_element)
|
||||
return Color::White;
|
||||
return default_color;
|
||||
|
||||
auto* body_layout_node = body_element->layout_node();
|
||||
if (!body_layout_node)
|
||||
return Color::White;
|
||||
return default_color;
|
||||
|
||||
auto background_color = body_layout_node->style().property(CSS::PropertyID::BackgroundColor);
|
||||
if (!background_color.has_value() || !background_color.value()->is_color())
|
||||
return Color::White;
|
||||
return default_color;
|
||||
|
||||
return background_color.value()->to_color(*this);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <LibHTML/CSS/StyleSheet.h>
|
||||
#include <LibHTML/DOM/ParentNode.h>
|
||||
|
||||
class Palette;
|
||||
class CTimer;
|
||||
class Frame;
|
||||
class HTMLBodyElement;
|
||||
|
@ -60,7 +61,7 @@ public:
|
|||
Frame* frame() { return m_frame.ptr(); }
|
||||
const Frame* frame() const { return m_frame.ptr(); }
|
||||
|
||||
Color background_color() const;
|
||||
Color background_color(const Palette&) const;
|
||||
RefPtr<GraphicsBitmap> background_image() const;
|
||||
|
||||
Color link_color() const { return m_link_color; }
|
||||
|
|
|
@ -38,7 +38,7 @@ HtmlView::HtmlView(GWidget* parent)
|
|||
set_frame_shadow(FrameShadow::Sunken);
|
||||
set_frame_thickness(2);
|
||||
set_should_hide_unnecessary_scrollbars(true);
|
||||
set_background_color(Color::White);
|
||||
set_background_role(ColorRole::Base);
|
||||
}
|
||||
|
||||
HtmlView::~HtmlView()
|
||||
|
@ -122,7 +122,7 @@ void HtmlView::paint_event(GPaintEvent& event)
|
|||
return;
|
||||
}
|
||||
|
||||
painter.fill_rect(event.rect(), document()->background_color());
|
||||
painter.fill_rect(event.rect(), document()->background_color(palette()));
|
||||
|
||||
if (auto background_bitmap = document()->background_image()) {
|
||||
painter.draw_tiled_bitmap(event.rect(), *background_bitmap);
|
||||
|
|
|
@ -15,5 +15,6 @@ void LayoutListItemMarker::render(RenderingContext& context)
|
|||
Rect bullet_rect { 0, 0, 4, 4 };
|
||||
bullet_rect.center_within(enclosing_int_rect(rect()));
|
||||
// FIXME: It would be nicer to not have to go via the parent here to get our inherited style.
|
||||
context.painter().fill_rect(bullet_rect, parent()->style().color_or_fallback(CSS::PropertyID::Color, document(), Color::Black));
|
||||
auto color = parent()->style().color_or_fallback(CSS::PropertyID::Color, document(), context.palette().base_text());
|
||||
context.painter().fill_rect(bullet_rect, color);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ void LayoutText::render_fragment(RenderingContext& context, const LineBoxFragmen
|
|||
if (background_color.has_value() && background_color.value()->is_color())
|
||||
painter.fill_rect(enclosing_int_rect(fragment.rect()), background_color.value()->to_color(document()));
|
||||
|
||||
auto color = style().color_or_fallback(CSS::PropertyID::Color, document(), Color::Black);
|
||||
auto color = style().color_or_fallback(CSS::PropertyID::Color, document(), context.palette().base_text());
|
||||
auto text_decoration = style().string_or_fallback(CSS::PropertyID::TextDecoration, "none");
|
||||
|
||||
if (document().inspected_node() == &node())
|
||||
|
@ -146,7 +146,7 @@ void LayoutText::split_into_lines(LayoutBlock& container)
|
|||
if (style().string_or_fallback(CSS::PropertyID::WhiteSpace, "normal") == "pre") {
|
||||
split_preformatted_into_lines(container);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Collapse whitespace into single spaces
|
||||
auto utf8_view = Utf8View(node().data());
|
||||
|
|
Loading…
Reference in a new issue