mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +00:00
LibWeb: Move box_type_agnostic_position() from layout node to paintable
For this method, there is no need to go through the layout node when we can directly reach the paintable.
This commit is contained in:
parent
31e5b5f5de
commit
814bed33b4
8 changed files with 39 additions and 36 deletions
|
@ -33,6 +33,7 @@
|
||||||
#include <LibWeb/Layout/Viewport.h>
|
#include <LibWeb/Layout/Viewport.h>
|
||||||
#include <LibWeb/Namespace.h>
|
#include <LibWeb/Namespace.h>
|
||||||
#include <LibWeb/Page/Page.h>
|
#include <LibWeb/Page/Page.h>
|
||||||
|
#include <LibWeb/Painting/Paintable.h>
|
||||||
#include <LibWeb/URL/URL.h>
|
#include <LibWeb/URL/URL.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
@ -391,9 +392,9 @@ CSSPixelPoint BrowsingContext::to_top_level_position(CSSPixelPoint a_position)
|
||||||
break;
|
break;
|
||||||
if (!ancestor->container())
|
if (!ancestor->container())
|
||||||
return {};
|
return {};
|
||||||
if (!ancestor->container()->layout_node())
|
if (!ancestor->container()->paintable())
|
||||||
return {};
|
return {};
|
||||||
position.translate_by(ancestor->container()->layout_node()->box_type_agnostic_position());
|
position.translate_by(ancestor->container()->paintable()->box_type_agnostic_position());
|
||||||
}
|
}
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,7 +215,7 @@ int HTMLElement::offset_top() const
|
||||||
// ignoring any transforms that apply to the element and its ancestors, and terminate this algorithm.
|
// ignoring any transforms that apply to the element and its ancestors, and terminate this algorithm.
|
||||||
auto offset_parent = this->offset_parent();
|
auto offset_parent = this->offset_parent();
|
||||||
if (!offset_parent || !offset_parent->layout_node()) {
|
if (!offset_parent || !offset_parent->layout_node()) {
|
||||||
auto position = layout_node()->box_type_agnostic_position();
|
auto position = paintable()->box_type_agnostic_position();
|
||||||
return position.y().to_int();
|
return position.y().to_int();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,8 +224,8 @@ int HTMLElement::offset_top() const
|
||||||
// from the y-coordinate of the top border edge of the first box associated with the element,
|
// from the y-coordinate of the top border edge of the first box associated with the element,
|
||||||
// relative to the initial containing block origin,
|
// relative to the initial containing block origin,
|
||||||
// ignoring any transforms that apply to the element and its ancestors.
|
// ignoring any transforms that apply to the element and its ancestors.
|
||||||
auto offset_parent_position = offset_parent->layout_node()->box_type_agnostic_position();
|
auto offset_parent_position = offset_parent->paintable()->box_type_agnostic_position();
|
||||||
auto position = layout_node()->box_type_agnostic_position();
|
auto position = paintable()->box_type_agnostic_position();
|
||||||
return position.y().to_int() - offset_parent_position.y().to_int();
|
return position.y().to_int() - offset_parent_position.y().to_int();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ int HTMLElement::offset_left() const
|
||||||
// ignoring any transforms that apply to the element and its ancestors, and terminate this algorithm.
|
// ignoring any transforms that apply to the element and its ancestors, and terminate this algorithm.
|
||||||
auto offset_parent = this->offset_parent();
|
auto offset_parent = this->offset_parent();
|
||||||
if (!offset_parent || !offset_parent->layout_node()) {
|
if (!offset_parent || !offset_parent->layout_node()) {
|
||||||
auto position = layout_node()->box_type_agnostic_position();
|
auto position = paintable()->box_type_agnostic_position();
|
||||||
return position.x().to_int();
|
return position.x().to_int();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,8 +257,8 @@ int HTMLElement::offset_left() const
|
||||||
// from the x-coordinate of the left border edge of the first CSS layout box associated with the element,
|
// from the x-coordinate of the left border edge of the first CSS layout box associated with the element,
|
||||||
// relative to the initial containing block origin,
|
// relative to the initial containing block origin,
|
||||||
// ignoring any transforms that apply to the element and its ancestors.
|
// ignoring any transforms that apply to the element and its ancestors.
|
||||||
auto offset_parent_position = offset_parent->layout_node()->box_type_agnostic_position();
|
auto offset_parent_position = offset_parent->paintable()->box_type_agnostic_position();
|
||||||
auto position = layout_node()->box_type_agnostic_position();
|
auto position = paintable()->box_type_agnostic_position();
|
||||||
return position.x().to_int() - offset_parent_position.x().to_int();
|
return position.x().to_int() - offset_parent_position.x().to_int();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <LibWeb/Layout/Node.h>
|
#include <LibWeb/Layout/Node.h>
|
||||||
#include <LibWeb/Loader/GeneratedPagesLoader.h>
|
#include <LibWeb/Loader/GeneratedPagesLoader.h>
|
||||||
#include <LibWeb/Page/Page.h>
|
#include <LibWeb/Page/Page.h>
|
||||||
|
#include <LibWeb/Painting/Paintable.h>
|
||||||
#include <LibWeb/Platform/EventLoopPlugin.h>
|
#include <LibWeb/Platform/EventLoopPlugin.h>
|
||||||
#include <LibWeb/XHR/FormData.h>
|
#include <LibWeb/XHR/FormData.h>
|
||||||
|
|
||||||
|
@ -1920,9 +1921,9 @@ CSSPixelPoint Navigable::to_top_level_position(CSSPixelPoint a_position)
|
||||||
break;
|
break;
|
||||||
if (!ancestor->container())
|
if (!ancestor->container())
|
||||||
return {};
|
return {};
|
||||||
if (!ancestor->container()->layout_node())
|
if (!ancestor->container()->paintable())
|
||||||
return {};
|
return {};
|
||||||
position.translate_by(ancestor->container()->layout_node()->box_type_agnostic_position());
|
position.translate_by(ancestor->container()->paintable()->box_type_agnostic_position());
|
||||||
}
|
}
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,29 +251,6 @@ void Node::set_needs_display()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSPixelPoint Node::box_type_agnostic_position() const
|
|
||||||
{
|
|
||||||
if (is<Box>(*this))
|
|
||||||
return verify_cast<Box>(*this).paintable_box()->absolute_position();
|
|
||||||
VERIFY(is_inline());
|
|
||||||
|
|
||||||
if (paintable() && paintable()->is_inline_paintable()) {
|
|
||||||
auto const& inline_paintable = static_cast<Painting::InlinePaintable const&>(*paintable());
|
|
||||||
if (!inline_paintable.fragments().is_empty())
|
|
||||||
return inline_paintable.fragments().first().absolute_rect().location();
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
|
||||||
|
|
||||||
CSSPixelPoint position;
|
|
||||||
if (auto const* block = containing_block(); block && block->paintable() && is<Painting::PaintableWithLines>(*block->paintable())) {
|
|
||||||
static_cast<Painting::PaintableWithLines const&>(*block->paintable_box()).for_each_fragment([&](auto& fragment) {
|
|
||||||
position = fragment.absolute_rect().location();
|
|
||||||
return IterationDecision::Break;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Node::is_floating() const
|
bool Node::is_floating() const
|
||||||
{
|
{
|
||||||
if (!has_style())
|
if (!has_style())
|
||||||
|
|
|
@ -160,8 +160,6 @@ public:
|
||||||
bool children_are_inline() const { return m_children_are_inline; }
|
bool children_are_inline() const { return m_children_are_inline; }
|
||||||
void set_children_are_inline(bool value) { m_children_are_inline = value; }
|
void set_children_are_inline(bool value) { m_children_are_inline = value; }
|
||||||
|
|
||||||
CSSPixelPoint box_type_agnostic_position() const;
|
|
||||||
|
|
||||||
enum class SelectionState {
|
enum class SelectionState {
|
||||||
None, // No selection
|
None, // No selection
|
||||||
Start, // Selection starts in this Node
|
Start, // Selection starts in this Node
|
||||||
|
|
|
@ -116,7 +116,7 @@ static Gfx::StandardCursor cursor_css_to_gfx(Optional<CSS::Cursor> cursor)
|
||||||
|
|
||||||
static CSSPixelPoint compute_mouse_event_offset(CSSPixelPoint position, Layout::Node const& layout_node)
|
static CSSPixelPoint compute_mouse_event_offset(CSSPixelPoint position, Layout::Node const& layout_node)
|
||||||
{
|
{
|
||||||
auto top_left_of_layout_node = layout_node.box_type_agnostic_position();
|
auto top_left_of_layout_node = layout_node.paintable()->box_type_agnostic_position();
|
||||||
return {
|
return {
|
||||||
position.x() - top_left_of_layout_node.x(),
|
position.x() - top_left_of_layout_node.x(),
|
||||||
position.y() - top_left_of_layout_node.y()
|
position.y() - top_left_of_layout_node.y()
|
||||||
|
|
|
@ -131,4 +131,28 @@ PaintableBox const* Paintable::nearest_scrollable_ancestor_within_stacking_conte
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSSPixelPoint Paintable::box_type_agnostic_position() const
|
||||||
|
{
|
||||||
|
if (is_paintable_box())
|
||||||
|
return static_cast<PaintableBox const*>(this)->absolute_position();
|
||||||
|
|
||||||
|
VERIFY(is_inline());
|
||||||
|
if (is_inline_paintable()) {
|
||||||
|
auto const& inline_paintable = static_cast<Painting::InlinePaintable const&>(*this);
|
||||||
|
if (!inline_paintable.fragments().is_empty())
|
||||||
|
return inline_paintable.fragments().first().absolute_rect().location();
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
CSSPixelPoint position;
|
||||||
|
if (auto const* block = containing_block(); block && block->paintable() && is<Painting::PaintableWithLines>(*block->paintable())) {
|
||||||
|
static_cast<Painting::PaintableWithLines const&>(*block->paintable_box()).for_each_fragment([&](auto& fragment) {
|
||||||
|
position = fragment.absolute_rect().location();
|
||||||
|
return IterationDecision::Break;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -186,6 +186,8 @@ public:
|
||||||
|
|
||||||
PaintableBox const* nearest_scrollable_ancestor_within_stacking_context() const;
|
PaintableBox const* nearest_scrollable_ancestor_within_stacking_context() const;
|
||||||
|
|
||||||
|
CSSPixelPoint box_type_agnostic_position() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit Paintable(Layout::Node const&);
|
explicit Paintable(Layout::Node const&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue