mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:07:44 +00:00
LibWeb: Convert Layout::Node to new pixel units
This commit is contained in:
parent
65cdf89a8b
commit
5d8e3f5122
7 changed files with 18 additions and 18 deletions
|
@ -138,7 +138,7 @@ NonnullRefPtr<Gfx::Font> StyleProperties::font_fallback(bool monospace, bool bol
|
|||
return Platform::FontPlugin::the().default_font();
|
||||
}
|
||||
|
||||
float StyleProperties::line_height(Layout::Node const& layout_node) const
|
||||
CSSPixels StyleProperties::line_height(Layout::Node const& layout_node) const
|
||||
{
|
||||
auto line_height = property(CSS::PropertyID::LineHeight);
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ public:
|
|||
m_font = move(font);
|
||||
}
|
||||
|
||||
float line_height(Layout::Node const&) const;
|
||||
CSSPixels line_height(Layout::Node const&) const;
|
||||
|
||||
bool operator==(StyleProperties const&) const;
|
||||
|
||||
|
|
|
@ -447,7 +447,7 @@ CSSPixelPoint BrowsingContext::to_top_level_position(CSSPixelPoint a_position)
|
|||
return {};
|
||||
if (!ancestor->container()->layout_node())
|
||||
return {};
|
||||
position.translate_by(ancestor->container()->layout_node()->box_type_agnostic_position().to_type<CSSPixels>());
|
||||
position.translate_by(ancestor->container()->layout_node()->box_type_agnostic_position());
|
||||
}
|
||||
return position;
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ int HTMLElement::offset_top() const
|
|||
return 0;
|
||||
auto position = layout_node()->box_type_agnostic_position();
|
||||
auto parent_position = parent_element()->layout_node()->box_type_agnostic_position();
|
||||
return position.y() - parent_position.y();
|
||||
return position.y().value() - parent_position.y().value();
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetleft
|
||||
|
@ -183,7 +183,7 @@ int HTMLElement::offset_left() const
|
|||
return 0;
|
||||
auto position = layout_node()->box_type_agnostic_position();
|
||||
auto parent_position = parent_element()->layout_node()->box_type_agnostic_position();
|
||||
return position.x() - parent_position.x();
|
||||
return position.x().value() - parent_position.x().value();
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetwidth
|
||||
|
|
|
@ -181,7 +181,7 @@ void LineBuilder::update_last_line()
|
|||
auto const typographic_height = font_metrics.ascent + font_metrics.descent;
|
||||
auto const leading = line_height - typographic_height;
|
||||
auto const half_leading = leading / 2;
|
||||
return font_metrics.ascent + half_leading;
|
||||
return CSSPixels(font_metrics.ascent) + half_leading;
|
||||
}();
|
||||
|
||||
auto line_box_baseline = [&] {
|
||||
|
@ -190,7 +190,7 @@ void LineBuilder::update_last_line()
|
|||
auto const& font = fragment.layout_node().font();
|
||||
auto const line_height = fragment.layout_node().line_height();
|
||||
auto const font_metrics = font.pixel_metrics();
|
||||
auto const typographic_height = font_metrics.ascent + font_metrics.descent;
|
||||
auto const typographic_height = CSSPixels(font_metrics.ascent + font_metrics.descent);
|
||||
auto const leading = line_height - typographic_height;
|
||||
auto const half_leading = leading / 2;
|
||||
|
||||
|
@ -198,7 +198,7 @@ void LineBuilder::update_last_line()
|
|||
|
||||
CSSPixels fragment_baseline = 0;
|
||||
if (fragment.layout_node().is_text_node()) {
|
||||
fragment_baseline = font_metrics.ascent + half_leading;
|
||||
fragment_baseline = CSSPixels(font_metrics.ascent) + half_leading;
|
||||
} else {
|
||||
auto const& box = verify_cast<Layout::Box>(fragment.layout_node());
|
||||
fragment_baseline = box_baseline(m_layout_state, box);
|
||||
|
|
|
@ -164,16 +164,16 @@ void Node::set_needs_display()
|
|||
});
|
||||
}
|
||||
|
||||
Gfx::FloatPoint Node::box_type_agnostic_position() const
|
||||
CSSPixelPoint Node::box_type_agnostic_position() const
|
||||
{
|
||||
if (is<Box>(*this))
|
||||
return verify_cast<Box>(*this).paint_box()->absolute_position().to_type<float>();
|
||||
return verify_cast<Box>(*this).paint_box()->absolute_position();
|
||||
VERIFY(is_inline());
|
||||
Gfx::FloatPoint position;
|
||||
CSSPixelPoint position;
|
||||
if (auto* block = containing_block()) {
|
||||
block->paint_box()->for_each_fragment([&](auto& fragment) {
|
||||
if (&fragment.layout_node() == this || is_ancestor_of(fragment.layout_node())) {
|
||||
position = fragment.absolute_rect().location().template to_type<float>();
|
||||
position = fragment.absolute_rect().location();
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
|
|
|
@ -110,8 +110,8 @@ public:
|
|||
bool can_contain_boxes_with_position_absolute() const;
|
||||
|
||||
Gfx::Font const& font() const;
|
||||
const CSS::ImmutableComputedValues& computed_values() const;
|
||||
float line_height() const;
|
||||
CSS::ImmutableComputedValues const& computed_values() const;
|
||||
CSSPixels line_height() const;
|
||||
|
||||
NodeWithStyle* parent();
|
||||
NodeWithStyle const* parent() const;
|
||||
|
@ -128,7 +128,7 @@ public:
|
|||
bool children_are_inline() const { return m_children_are_inline; }
|
||||
void set_children_are_inline(bool value) { m_children_are_inline = value; }
|
||||
|
||||
Gfx::FloatPoint box_type_agnostic_position() const;
|
||||
CSSPixelPoint box_type_agnostic_position() const;
|
||||
|
||||
enum class SelectionState {
|
||||
None, // No selection
|
||||
|
@ -177,7 +177,7 @@ public:
|
|||
void apply_style(const CSS::StyleProperties&);
|
||||
|
||||
Gfx::Font const& font() const { return *m_font; }
|
||||
float line_height() const { return m_line_height; }
|
||||
CSSPixels line_height() const { return m_line_height; }
|
||||
Vector<CSS::BackgroundLayerData> const& background_layers() const { return computed_values().background_layers(); }
|
||||
const CSS::AbstractImageStyleValue* list_style_image() const { return m_list_style_image; }
|
||||
|
||||
|
@ -190,7 +190,7 @@ protected:
|
|||
private:
|
||||
CSS::ComputedValues m_computed_values;
|
||||
RefPtr<Gfx::Font> m_font;
|
||||
float m_line_height { 0 };
|
||||
CSSPixels m_line_height { 0 };
|
||||
RefPtr<CSS::AbstractImageStyleValue> m_list_style_image;
|
||||
};
|
||||
|
||||
|
@ -230,7 +230,7 @@ inline const CSS::ImmutableComputedValues& Node::computed_values() const
|
|||
return parent()->computed_values();
|
||||
}
|
||||
|
||||
inline float Node::line_height() const
|
||||
inline CSSPixels Node::line_height() const
|
||||
{
|
||||
if (m_has_style)
|
||||
return static_cast<NodeWithStyle const*>(this)->line_height();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue