summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-11-09 12:32:20 +0000
committerLinus Groh <mail@linusgroh.de>2023-01-05 17:42:31 +0100
commit4084c66ad2e4cd5b37fdaabc7e36d30bfbfdfb7d (patch)
treeea03750beacbd0b900edefd712f09b63516d547e /Userland/Libraries
parent8cc0bdf777ebdb19fb995268c285f9831fbab4ae (diff)
downloadserenity-4084c66ad2e4cd5b37fdaabc7e36d30bfbfdfb7d.zip
LibWeb: Use CSS Pixels for viewport rects
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Length.cpp4
-rw-r--r--Userland/Libraries/LibWeb/CSS/Length.h4
-rw-r--r--Userland/Libraries/LibWeb/CSS/MediaQuery.cpp2
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleComputer.cpp4
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleComputer.h2
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.cpp10
-rw-r--r--Userland/Libraries/LibWeb/CSS/StyleValue.h8
7 files changed, 17 insertions, 17 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Length.cpp b/Userland/Libraries/LibWeb/CSS/Length.cpp
index d98e1fdd75..156ce7bb63 100644
--- a/Userland/Libraries/LibWeb/CSS/Length.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Length.cpp
@@ -70,7 +70,7 @@ Length Length::resolved(Layout::Node const& layout_node) const
return *this;
}
-CSSPixels Length::relative_length_to_px(Gfx::IntRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const
+CSSPixels Length::relative_length_to_px(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const
{
switch (m_type) {
case Type::Ex:
@@ -105,7 +105,7 @@ CSSPixels Length::to_px(Layout::Node const& layout_node) const
if (!layout_node.document().browsing_context())
return 0;
- auto const& viewport_rect = layout_node.document().browsing_context()->viewport_rect().to_type<float>().to_type<int>();
+ auto const& viewport_rect = layout_node.document().browsing_context()->viewport_rect();
auto* root_element = layout_node.document().document_element();
if (!root_element || !root_element->layout_node())
return 0;
diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h
index fe575292d4..ed1313c1ff 100644
--- a/Userland/Libraries/LibWeb/CSS/Length.h
+++ b/Userland/Libraries/LibWeb/CSS/Length.h
@@ -83,7 +83,7 @@ public:
CSSPixels to_px(Layout::Node const&) const;
- ALWAYS_INLINE CSSPixels to_px(Gfx::IntRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const
+ ALWAYS_INLINE CSSPixels to_px(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const
{
if (is_auto())
return 0;
@@ -124,7 +124,7 @@ public:
// this file already. To break the cyclic dependency, we must move all method definitions out.
bool operator==(Length const& other) const;
- CSSPixels relative_length_to_px(Gfx::IntRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const;
+ CSSPixels relative_length_to_px(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const;
private:
char const* unit_name() const;
diff --git a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp
index 58eb1171ed..80f17c6c45 100644
--- a/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp
+++ b/Userland/Libraries/LibWeb/CSS/MediaQuery.cpp
@@ -163,7 +163,7 @@ bool MediaFeature::compare(HTML::Window const& window, MediaFeatureValue left, C
left_px = left.length().absolute_length_to_px();
right_px = right.length().absolute_length_to_px();
} else {
- Gfx::IntRect viewport_rect { 0, 0, window.inner_width(), window.inner_height() };
+ auto viewport_rect = window.page()->web_exposed_screen_area();
auto const& initial_font = window.associated_document().style_computer().initial_font();
Gfx::FontPixelMetrics const& initial_font_metrics = initial_font.pixel_metrics();
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
index fe5cd96710..109ca571d1 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -1437,10 +1437,10 @@ void StyleComputer::invalidate_rule_cache()
m_rule_cache = nullptr;
}
-Gfx::IntRect StyleComputer::viewport_rect() const
+CSSPixelRect StyleComputer::viewport_rect() const
{
if (auto const* browsing_context = document().browsing_context())
- return browsing_context->viewport_rect().to_type<float>().to_type<int>();
+ return browsing_context->viewport_rect();
return {};
}
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.h b/Userland/Libraries/LibWeb/CSS/StyleComputer.h
index 8a530fe60c..4482ac6027 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.h
@@ -93,7 +93,7 @@ private:
template<typename Callback>
void for_each_stylesheet(CascadeOrigin, Callback) const;
- Gfx::IntRect viewport_rect() const;
+ CSSPixelRect viewport_rect() const;
CSSPixels root_element_font_size() const;
struct MatchingRuleSet {
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
index 3291363a1c..293834bac6 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp
@@ -2557,7 +2557,7 @@ NonnullRefPtr<LengthStyleValue> LengthStyleValue::create(Length const& length)
return adopt_ref(*new LengthStyleValue(length));
}
-static Optional<CSS::Length> absolutized_length(CSS::Length const& length, Gfx::IntRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, float font_size, float root_font_size)
+static Optional<CSS::Length> absolutized_length(CSS::Length const& length, CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size)
{
if (length.is_px())
return {};
@@ -2568,19 +2568,19 @@ static Optional<CSS::Length> absolutized_length(CSS::Length const& length, Gfx::
return {};
}
-NonnullRefPtr<StyleValue> StyleValue::absolutized(Gfx::IntRect const&, Gfx::FontPixelMetrics const&, float, float) const
+NonnullRefPtr<StyleValue> StyleValue::absolutized(CSSPixelRect const&, Gfx::FontPixelMetrics const&, CSSPixels, CSSPixels) const
{
return *this;
}
-NonnullRefPtr<StyleValue> LengthStyleValue::absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, float font_size, float root_font_size) const
+NonnullRefPtr<StyleValue> LengthStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const
{
if (auto length = absolutized_length(m_length, viewport_rect, font_metrics, font_size, root_font_size); length.has_value())
return LengthStyleValue::create(length.release_value());
return *this;
}
-NonnullRefPtr<StyleValue> ShadowStyleValue::absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, float font_size, float root_font_size) const
+NonnullRefPtr<StyleValue> ShadowStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const
{
auto absolutized_offset_x = absolutized_length(m_offset_x, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_offset_x);
auto absolutized_offset_y = absolutized_length(m_offset_y, viewport_rect, font_metrics, font_size, root_font_size).value_or(m_offset_y);
@@ -2589,7 +2589,7 @@ NonnullRefPtr<StyleValue> ShadowStyleValue::absolutized(Gfx::IntRect const& view
return ShadowStyleValue::create(m_color, absolutized_offset_x, absolutized_offset_y, absolutized_blur_radius, absolutized_spread_distance, m_placement);
}
-NonnullRefPtr<StyleValue> BorderRadiusStyleValue::absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, float font_size, float root_font_size) const
+NonnullRefPtr<StyleValue> BorderRadiusStyleValue::absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const
{
if (m_horizontal_radius.is_percentage() && m_vertical_radius.is_percentage())
return *this;
diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h
index 5c2a495464..fa79d6659b 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleValue.h
+++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h
@@ -395,7 +395,7 @@ public:
virtual bool has_number() const { return false; }
virtual bool has_integer() const { return false; }
- virtual NonnullRefPtr<StyleValue> absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, float font_size, float root_font_size) const;
+ virtual NonnullRefPtr<StyleValue> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const;
virtual Color to_color(Layout::NodeWithStyle const&) const { return {}; }
virtual EdgeRect to_rect() const { VERIFY_NOT_REACHED(); }
@@ -610,7 +610,7 @@ private:
m_is_elliptical = (m_horizontal_radius != m_vertical_radius);
}
- virtual NonnullRefPtr<StyleValue> absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, float font_size, float root_font_size) const override;
+ virtual NonnullRefPtr<StyleValue> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override;
bool m_is_elliptical;
LengthPercentage m_horizontal_radius;
@@ -1447,7 +1447,7 @@ public:
virtual DeprecatedString to_deprecated_string() const override { return m_length.to_deprecated_string(); }
virtual Length to_length() const override { return m_length; }
virtual ValueID to_identifier() const override { return has_auto() ? ValueID::Auto : ValueID::Invalid; }
- virtual NonnullRefPtr<StyleValue> absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, float font_size, float root_font_size) const override;
+ virtual NonnullRefPtr<StyleValue> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override;
virtual bool equals(StyleValue const& other) const override;
private:
@@ -1670,7 +1670,7 @@ private:
{
}
- virtual NonnullRefPtr<StyleValue> absolutized(Gfx::IntRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, float font_size, float root_font_size) const override;
+ virtual NonnullRefPtr<StyleValue> absolutized(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size) const override;
Color m_color;
Length m_offset_x;