mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:57:35 +00:00
LibWeb: Make SVG <svg> elements behave as CSS replaced elements
This makes SVG-in-HTML behave quite a bit better by following general replaced layout rules. It also turns <svg> elements into inline-level boxes instead of block-level boxes.
This commit is contained in:
parent
48abbefb99
commit
28b771560a
10 changed files with 21 additions and 14 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <LibWeb/Layout/InlineLevelIterator.h>
|
||||
#include <LibWeb/Layout/LineBuilder.h>
|
||||
#include <LibWeb/Layout/ReplacedBox.h>
|
||||
#include <LibWeb/Layout/SVGSVGBox.h>
|
||||
|
||||
namespace Web::Layout {
|
||||
|
||||
|
@ -109,6 +110,10 @@ void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode l
|
|||
|
||||
if (is<ReplacedBox>(box)) {
|
||||
auto& replaced = verify_cast<ReplacedBox>(box);
|
||||
|
||||
if (is<SVGSVGBox>(box))
|
||||
(void)layout_inside(replaced, layout_mode);
|
||||
|
||||
box_state.content_width = compute_width_for_replaced_element(m_state, replaced);
|
||||
box_state.content_height = compute_height_for_replaced_element(m_state, replaced);
|
||||
return;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
namespace Web::Layout {
|
||||
|
||||
SVGBox::SVGBox(DOM::Document& document, SVG::SVGElement& element, NonnullRefPtr<CSS::StyleProperties> style)
|
||||
: BlockContainer(document, &element, move(style))
|
||||
: Box(document, &element, move(style))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
namespace Web::Layout {
|
||||
|
||||
class SVGBox : public BlockContainer {
|
||||
class SVGBox : public Box {
|
||||
public:
|
||||
SVGBox(DOM::Document&, SVG::SVGElement&, NonnullRefPtr<CSS::StyleProperties>);
|
||||
virtual ~SVGBox() override = default;
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Layout/SVGSVGBox.h>
|
||||
#include <LibWeb/Layout/ReplacedBox.h>
|
||||
#include <LibWeb/Painting/SVGSVGPaintable.h>
|
||||
|
||||
namespace Web::Layout {
|
||||
|
||||
SVGSVGBox::SVGSVGBox(DOM::Document& document, SVG::SVGSVGElement& element, NonnullRefPtr<CSS::StyleProperties> properties)
|
||||
: SVGGraphicsBox(document, element, properties)
|
||||
: ReplacedBox(document, element, move(properties))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -6,17 +6,17 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Layout/SVGGraphicsBox.h>
|
||||
#include <LibWeb/Layout/ReplacedBox.h>
|
||||
#include <LibWeb/SVG/SVGSVGElement.h>
|
||||
|
||||
namespace Web::Layout {
|
||||
|
||||
class SVGSVGBox final : public SVGGraphicsBox {
|
||||
class SVGSVGBox final : public ReplacedBox {
|
||||
public:
|
||||
SVGSVGBox(DOM::Document&, SVG::SVGSVGElement&, NonnullRefPtr<CSS::StyleProperties>);
|
||||
virtual ~SVGSVGBox() override = default;
|
||||
|
||||
SVG::SVGSVGElement& dom_node() { return verify_cast<SVG::SVGSVGElement>(SVGGraphicsBox::dom_node()); }
|
||||
SVG::SVGSVGElement& dom_node() { return verify_cast<SVG::SVGSVGElement>(ReplacedBox::dom_node()); }
|
||||
|
||||
virtual bool can_have_children() const override { return true; }
|
||||
|
||||
|
|
|
@ -145,6 +145,8 @@ void TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::Context&
|
|||
|
||||
if (!dom_node.parent_or_shadow_host()) {
|
||||
m_layout_root = layout_node;
|
||||
} else if (layout_node->is_svg_box()) {
|
||||
m_parent_stack.last()->append_child(*layout_node);
|
||||
} else {
|
||||
insert_node_into_inline_or_block_ancestor(layout_node);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue