mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:37:37 +00:00
LibWeb: Rename LayoutNode classes and move them into Layout namespace
Bring the names of various boxes closer to spec language. This should hopefully make things easier to understand and hack on. :^) Some notable changes: - LayoutNode -> Layout::Node - LayoutBox -> Layout::Box - LayoutBlock -> Layout::BlockBox - LayoutReplaced -> Layout::ReplacedBox - LayoutDocument -> Layout::InitialContainingBlockBox - LayoutText -> Layout::TextNode - LayoutInline -> Layout::InlineNode Note that this is not strictly a "box tree" as we also hang inline/text nodes in the same tree, and they don't generate boxes. (Instead, they contribute line box fragments to their containing block!)
This commit is contained in:
parent
f358f2255f
commit
5aeab9878e
114 changed files with 863 additions and 880 deletions
|
@ -25,7 +25,7 @@
|
|||
*/
|
||||
|
||||
#include <LibWeb/HTML/HTMLBRElement.h>
|
||||
#include <LibWeb/Layout/LayoutBreak.h>
|
||||
#include <LibWeb/Layout/BreakNode.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -38,9 +38,9 @@ HTMLBRElement::~HTMLBRElement()
|
|||
{
|
||||
}
|
||||
|
||||
RefPtr<LayoutNode> HTMLBRElement::create_layout_node(const CSS::StyleProperties*)
|
||||
RefPtr<Layout::Node> HTMLBRElement::create_layout_node(const CSS::StyleProperties*)
|
||||
{
|
||||
return adopt(*new LayoutBreak(document(), *this));
|
||||
return adopt(*new Layout::BreakNode(document(), *this));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
HTMLBRElement(DOM::Document&, const QualifiedName& qualified_name);
|
||||
virtual ~HTMLBRElement() override;
|
||||
|
||||
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <LibWeb/CSS/StyleProperties.h>
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
#include <LibWeb/HTML/HTMLBlinkElement.h>
|
||||
#include <LibWeb/Layout/LayoutNode.h>
|
||||
#include <LibWeb/Layout/Node.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/CanvasRenderingContext2D.h>
|
||||
#include <LibWeb/HTML/HTMLCanvasElement.h>
|
||||
#include <LibWeb/Layout/LayoutCanvas.h>
|
||||
#include <LibWeb/Layout/CanvasBox.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -55,12 +55,12 @@ unsigned HTMLCanvasElement::height() const
|
|||
return attribute(HTML::AttributeNames::height).to_uint().value_or(150);
|
||||
}
|
||||
|
||||
RefPtr<LayoutNode> HTMLCanvasElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
||||
RefPtr<Layout::Node> HTMLCanvasElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
||||
{
|
||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||
if (style->display() == CSS::Display::None)
|
||||
return nullptr;
|
||||
return adopt(*new LayoutCanvas(document(), *this, move(style)));
|
||||
return adopt(*new Layout::CanvasBox(document(), *this, move(style)));
|
||||
}
|
||||
|
||||
CanvasRenderingContext2D* HTMLCanvasElement::get_context(String type)
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
class LayoutDocument;
|
||||
|
||||
class HTMLCanvasElement final : public HTMLElement {
|
||||
public:
|
||||
using WrapperType = Bindings::HTMLCanvasElementWrapper;
|
||||
|
@ -51,7 +49,7 @@ public:
|
|||
unsigned height() const;
|
||||
|
||||
private:
|
||||
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||
|
||||
RefPtr<Gfx::Bitmap> m_bitmap;
|
||||
RefPtr<CanvasRenderingContext2D> m_context;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <AK/StringBuilder.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/Layout/LayoutText.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -117,10 +117,10 @@ String HTMLElement::inner_text()
|
|||
if (!layout_node())
|
||||
return text_content();
|
||||
|
||||
Function<void(const LayoutNode&)> recurse = [&](auto& node) {
|
||||
Function<void(const Layout::Node&)> recurse = [&](auto& node) {
|
||||
for (auto* child = node.first_child(); child; child = child->next_sibling()) {
|
||||
if (child->is_text())
|
||||
builder.append(downcast<LayoutText>(*child).text_for_rendering());
|
||||
builder.append(downcast<Layout::TextNode>(*child).text_for_rendering());
|
||||
if (child->is_break())
|
||||
builder.append('\n');
|
||||
recurse(*child);
|
||||
|
|
|
@ -35,8 +35,7 @@
|
|||
#include <LibWeb/HTML/HTMLIFrameElement.h>
|
||||
#include <LibWeb/HTML/Parser/HTMLDocumentParser.h>
|
||||
#include <LibWeb/InProcessWebView.h>
|
||||
#include <LibWeb/Layout/LayoutFrame.h>
|
||||
#include <LibWeb/Layout/LayoutWidget.h>
|
||||
#include <LibWeb/Layout/FrameBox.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
#include <LibWeb/Origin.h>
|
||||
#include <LibWeb/Page/Frame.h>
|
||||
|
@ -52,10 +51,10 @@ HTMLIFrameElement::~HTMLIFrameElement()
|
|||
{
|
||||
}
|
||||
|
||||
RefPtr<LayoutNode> HTMLIFrameElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
||||
RefPtr<Layout::Node> HTMLIFrameElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
||||
{
|
||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||
return adopt(*new LayoutFrame(document(), *this, move(style)));
|
||||
return adopt(*new Layout::FrameBox(document(), *this, move(style)));
|
||||
}
|
||||
|
||||
void HTMLIFrameElement::document_did_attach_to_frame(Frame& frame)
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
HTMLIFrameElement(DOM::Document&, const QualifiedName& qualified_name);
|
||||
virtual ~HTMLIFrameElement() override;
|
||||
|
||||
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||
|
||||
Frame* content_frame() { return m_content_frame; }
|
||||
const Frame* content_frame() const { return m_content_frame; }
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/HTML/HTMLImageElement.h>
|
||||
#include <LibWeb/Layout/LayoutImage.h>
|
||||
#include <LibWeb/Layout/ImageBox.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
@ -83,12 +83,12 @@ void HTMLImageElement::parse_attribute(const FlyString& name, const String& valu
|
|||
m_image_loader.load(document().complete_url(value));
|
||||
}
|
||||
|
||||
RefPtr<LayoutNode> HTMLImageElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
||||
RefPtr<Layout::Node> HTMLImageElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
||||
{
|
||||
auto style = document().style_resolver().resolve_style(*this, parent_style);
|
||||
if (style->display() == CSS::Display::None)
|
||||
return nullptr;
|
||||
return adopt(*new LayoutImage(document(), *this, move(style), m_image_loader));
|
||||
return adopt(*new Layout::ImageBox(document(), *this, move(style), m_image_loader));
|
||||
}
|
||||
|
||||
const Gfx::Bitmap* HTMLImageElement::bitmap() const
|
||||
|
|
|
@ -53,7 +53,7 @@ private:
|
|||
|
||||
void animate();
|
||||
|
||||
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||
|
||||
ImageLoader m_image_loader;
|
||||
};
|
||||
|
|
|
@ -31,9 +31,9 @@
|
|||
#include <LibWeb/HTML/HTMLFormElement.h>
|
||||
#include <LibWeb/HTML/HTMLInputElement.h>
|
||||
#include <LibWeb/InProcessWebView.h>
|
||||
#include <LibWeb/Layout/LayoutButton.h>
|
||||
#include <LibWeb/Layout/LayoutCheckBox.h>
|
||||
#include <LibWeb/Layout/LayoutWidget.h>
|
||||
#include <LibWeb/Layout/ButtonBox.h>
|
||||
#include <LibWeb/Layout/CheckBox.h>
|
||||
#include <LibWeb/Layout/WidgetBox.h>
|
||||
#include <LibWeb/Page/Frame.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
@ -47,7 +47,7 @@ HTMLInputElement::~HTMLInputElement()
|
|||
{
|
||||
}
|
||||
|
||||
void HTMLInputElement::did_click_button(Badge<LayoutButton>)
|
||||
void HTMLInputElement::did_click_button(Badge<Layout::ButtonBox>)
|
||||
{
|
||||
dispatch_event(DOM::Event::create("click"));
|
||||
|
||||
|
@ -60,7 +60,7 @@ void HTMLInputElement::did_click_button(Badge<LayoutButton>)
|
|||
}
|
||||
}
|
||||
|
||||
RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
||||
RefPtr<Layout::Node> HTMLInputElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
||||
{
|
||||
ASSERT(document().page());
|
||||
auto& page = *document().page();
|
||||
|
@ -74,15 +74,15 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const CSS::StyleProperti
|
|||
return nullptr;
|
||||
|
||||
if (type().equals_ignoring_case("submit") || type().equals_ignoring_case("button"))
|
||||
return adopt(*new LayoutButton(document(), *this, move(style)));
|
||||
return adopt(*new Layout::ButtonBox(document(), *this, move(style)));
|
||||
|
||||
if (type() == "checkbox")
|
||||
return adopt(*new LayoutCheckBox(document(), *this, move(style)));
|
||||
return adopt(*new Layout::CheckBox(document(), *this, move(style)));
|
||||
|
||||
auto& text_box = page_view.add<GUI::TextBox>();
|
||||
text_box.set_text(value());
|
||||
text_box.on_change = [this] {
|
||||
auto& widget = downcast<LayoutWidget>(layout_node())->widget();
|
||||
auto& widget = downcast<Layout::WidgetBox>(layout_node())->widget();
|
||||
const_cast<HTMLInputElement*>(this)->set_attribute(HTML::AttributeNames::value, static_cast<const GUI::TextBox&>(widget).text());
|
||||
};
|
||||
int text_width = Gfx::Font::default_font().width(value());
|
||||
|
@ -93,7 +93,7 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const CSS::StyleProperti
|
|||
text_width = Gfx::Font::default_font().glyph_width('x') * size.value();
|
||||
}
|
||||
text_box.set_relative_rect(0, 0, text_width + 20, 20);
|
||||
return adopt(*new LayoutWidget(document(), *this, text_box));
|
||||
return adopt(*new Layout::WidgetBox(document(), *this, text_box));
|
||||
}
|
||||
|
||||
void HTMLInputElement::set_checked(bool checked)
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
HTMLInputElement(DOM::Document&, const QualifiedName& qualified_name);
|
||||
virtual ~HTMLInputElement() override;
|
||||
|
||||
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||
|
||||
String type() const { return attribute(HTML::AttributeNames::type); }
|
||||
String value() const { return attribute(HTML::AttributeNames::value); }
|
||||
|
@ -48,7 +48,7 @@ public:
|
|||
|
||||
bool enabled() const;
|
||||
|
||||
void did_click_button(Badge<LayoutButton>);
|
||||
void did_click_button(Badge<Layout::ButtonBox>);
|
||||
|
||||
private:
|
||||
bool m_checked { false };
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/Event.h>
|
||||
#include <LibWeb/HTML/HTMLObjectElement.h>
|
||||
#include <LibWeb/Layout/LayoutImage.h>
|
||||
#include <LibWeb/Layout/ImageBox.h>
|
||||
#include <LibWeb/Loader/ResourceLoader.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
@ -61,7 +61,7 @@ void HTMLObjectElement::parse_attribute(const FlyString& name, const String& val
|
|||
m_image_loader.load(document().complete_url(value));
|
||||
}
|
||||
|
||||
RefPtr<LayoutNode> HTMLObjectElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
||||
RefPtr<Layout::Node> HTMLObjectElement::create_layout_node(const CSS::StyleProperties* parent_style)
|
||||
{
|
||||
if (m_should_show_fallback_content)
|
||||
return HTMLElement::create_layout_node(parent_style);
|
||||
|
@ -70,7 +70,7 @@ RefPtr<LayoutNode> HTMLObjectElement::create_layout_node(const CSS::StylePropert
|
|||
if (style->display() == CSS::Display::None)
|
||||
return nullptr;
|
||||
if (m_image_loader.has_image())
|
||||
return adopt(*new LayoutImage(document(), *this, move(style), m_image_loader));
|
||||
return adopt(*new Layout::ImageBox(document(), *this, move(style), m_image_loader));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
String type() const { return attribute(HTML::AttributeNames::type); }
|
||||
|
||||
private:
|
||||
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||
virtual RefPtr<Layout::Node> create_layout_node(const CSS::StyleProperties* parent_style) override;
|
||||
|
||||
ImageLoader m_image_loader;
|
||||
bool m_should_show_fallback_content { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue