mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-09 19:16:02 +00:00
LibWeb: Support creating ColorResolutionContext from AbstractElement
No functionality changes.
This commit is contained in:
parent
e0e00220fe
commit
db439d224a
Notes:
github-actions[bot]
2025-08-04 10:30:29 +00:00
Author: https://github.com/Calme1709
Commit: db439d224a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5517
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/gmta
4 changed files with 31 additions and 0 deletions
|
@ -75,6 +75,20 @@
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
|
ColorResolutionContext ColorResolutionContext::for_element(DOM::AbstractElement const& element)
|
||||||
|
{
|
||||||
|
auto color_scheme = element.computed_properties()->color_scheme(element.document().page().preferred_color_scheme(), element.document().supported_color_schemes());
|
||||||
|
|
||||||
|
CalculationResolutionContext calculation_resolution_context { .length_resolution_context = Length::ResolutionContext::for_element(element) };
|
||||||
|
|
||||||
|
return {
|
||||||
|
.color_scheme = color_scheme,
|
||||||
|
.current_color = element.computed_properties()->color_or_fallback(PropertyID::Color, { color_scheme, CSS::InitialValues::color(), element.document(), calculation_resolution_context }, CSS::InitialValues::color()),
|
||||||
|
.document = element.document(),
|
||||||
|
.calculation_resolution_context = calculation_resolution_context
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
ColorResolutionContext ColorResolutionContext::for_layout_node_with_style(Layout::NodeWithStyle const& layout_node)
|
ColorResolutionContext ColorResolutionContext::for_layout_node_with_style(Layout::NodeWithStyle const& layout_node)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -89,6 +89,7 @@ struct ColorResolutionContext {
|
||||||
GC::Ptr<DOM::Document const> document;
|
GC::Ptr<DOM::Document const> document;
|
||||||
CalculationResolutionContext calculation_resolution_context;
|
CalculationResolutionContext calculation_resolution_context;
|
||||||
|
|
||||||
|
[[nodiscard]] static ColorResolutionContext for_element(DOM::AbstractElement const&);
|
||||||
[[nodiscard]] static ColorResolutionContext for_layout_node_with_style(Layout::NodeWithStyle const&);
|
[[nodiscard]] static ColorResolutionContext for_layout_node_with_style(Layout::NodeWithStyle const&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,21 @@ CSSPixels Length::viewport_relative_length_to_px(CSSPixelRect const& viewport_re
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Length::ResolutionContext Length::ResolutionContext::for_element(DOM::AbstractElement const& element)
|
||||||
|
{
|
||||||
|
auto const* root_element = element.element().document().document_element();
|
||||||
|
|
||||||
|
VERIFY(element.computed_properties());
|
||||||
|
VERIFY(root_element);
|
||||||
|
VERIFY(root_element->computed_properties());
|
||||||
|
|
||||||
|
return Length::ResolutionContext {
|
||||||
|
.viewport_rect = element.element().navigable()->viewport_rect(),
|
||||||
|
.font_metrics = { element.computed_properties()->font_size(), element.computed_properties()->first_available_computed_font().pixel_metrics() },
|
||||||
|
.root_font_metrics = { root_element->computed_properties()->font_size(), root_element->computed_properties()->first_available_computed_font().pixel_metrics() }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Length::ResolutionContext Length::ResolutionContext::for_window(HTML::Window const& window)
|
Length::ResolutionContext Length::ResolutionContext::for_window(HTML::Window const& window)
|
||||||
{
|
{
|
||||||
auto const& initial_font = window.associated_document().style_computer().initial_font();
|
auto const& initial_font = window.associated_document().style_computer().initial_font();
|
||||||
|
|
|
@ -162,6 +162,7 @@ public:
|
||||||
StringView unit_name() const;
|
StringView unit_name() const;
|
||||||
|
|
||||||
struct ResolutionContext {
|
struct ResolutionContext {
|
||||||
|
[[nodiscard]] static ResolutionContext for_element(DOM::AbstractElement const&);
|
||||||
[[nodiscard]] static ResolutionContext for_window(HTML::Window const&);
|
[[nodiscard]] static ResolutionContext for_window(HTML::Window const&);
|
||||||
[[nodiscard]] static ResolutionContext for_layout_node(Layout::Node const&);
|
[[nodiscard]] static ResolutionContext for_layout_node(Layout::Node const&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue