LibWeb: Move CSS classes into the Web::CSS namespace

This commit is contained in:
Andreas Kling 2020-07-26 20:01:35 +02:00
parent 3e389f4cdc
commit 1f008c95b6
Notes: sideshowbarker 2024-07-19 04:35:42 +09:00
100 changed files with 358 additions and 366 deletions

View File

@ -338,7 +338,7 @@ Tab::Tab(Type type)
"Dump Style sheets", [this](auto&) {
if (m_type == Type::InProcessWebView) {
for (auto& sheet : m_page_view->document()->style_sheets().sheets()) {
dump_sheet(sheet);
Web::dump_sheet(sheet);
}
} else {
TODO();

View File

@ -28,7 +28,7 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/HTMLHtmlElement.h>
namespace Web {
namespace Web::CSS {
float Length::relative_length_to_px(const LayoutNode& layout_node) const
{

View File

@ -29,7 +29,7 @@
#include <AK/String.h>
#include <LibWeb/Forward.h>
namespace Web {
namespace Web::CSS {
class Length {
public:

View File

@ -28,7 +28,7 @@
#include <LibWeb/CSS/Length.h>
namespace Web {
namespace Web::CSS {
struct LengthBox {
Length top { Length::make_auto() };

View File

@ -26,7 +26,7 @@
#include <LibWeb/CSS/Selector.h>
namespace Web {
namespace Web::CSS {
Selector::Selector(Vector<ComplexSelector>&& component_lists)
: m_complex_selectors(move(component_lists))

View File

@ -29,7 +29,7 @@
#include <AK/FlyString.h>
#include <AK/Vector.h>
namespace Web {
namespace Web::CSS {
class Selector {
public:

View File

@ -30,9 +30,7 @@
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/Text.h>
namespace Web {
namespace SelectorEngine {
namespace Web::SelectorEngine {
static bool matches_hover_pseudo_class(const DOM::Element& element)
{
@ -44,57 +42,57 @@ static bool matches_hover_pseudo_class(const DOM::Element& element)
return element.is_ancestor_of(*hovered_node);
}
bool matches(const Selector::SimpleSelector& component, const DOM::Element& element)
bool matches(const CSS::Selector::SimpleSelector& component, const DOM::Element& element)
{
switch (component.pseudo_class) {
case Selector::SimpleSelector::PseudoClass::None:
case CSS::Selector::SimpleSelector::PseudoClass::None:
break;
case Selector::SimpleSelector::PseudoClass::Link:
case CSS::Selector::SimpleSelector::PseudoClass::Link:
if (!element.is_link())
return false;
break;
case Selector::SimpleSelector::PseudoClass::Visited:
case CSS::Selector::SimpleSelector::PseudoClass::Visited:
// FIXME: Maybe match this selector sometimes?
return false;
case Selector::SimpleSelector::PseudoClass::Hover:
case CSS::Selector::SimpleSelector::PseudoClass::Hover:
if (!matches_hover_pseudo_class(element))
return false;
break;
case Selector::SimpleSelector::PseudoClass::Focus:
case CSS::Selector::SimpleSelector::PseudoClass::Focus:
// FIXME: Implement matches_focus_pseudo_class(element)
return false;
case Selector::SimpleSelector::PseudoClass::FirstChild:
case CSS::Selector::SimpleSelector::PseudoClass::FirstChild:
if (element.previous_element_sibling())
return false;
break;
case Selector::SimpleSelector::PseudoClass::LastChild:
case CSS::Selector::SimpleSelector::PseudoClass::LastChild:
if (element.next_element_sibling())
return false;
break;
case Selector::SimpleSelector::PseudoClass::OnlyChild:
case CSS::Selector::SimpleSelector::PseudoClass::OnlyChild:
if (element.previous_element_sibling() || element.next_element_sibling())
return false;
break;
case Selector::SimpleSelector::PseudoClass::Empty:
case CSS::Selector::SimpleSelector::PseudoClass::Empty:
if (element.first_child_of_type<DOM::Element>() || element.first_child_of_type<DOM::Text>())
return false;
break;
case Selector::SimpleSelector::PseudoClass::Root:
case CSS::Selector::SimpleSelector::PseudoClass::Root:
if (!element.is_html_element())
return false;
break;
}
switch (component.attribute_match_type) {
case Selector::SimpleSelector::AttributeMatchType::HasAttribute:
case CSS::Selector::SimpleSelector::AttributeMatchType::HasAttribute:
if (!element.has_attribute(component.attribute_name))
return false;
break;
case Selector::SimpleSelector::AttributeMatchType::ExactValueMatch:
case CSS::Selector::SimpleSelector::AttributeMatchType::ExactValueMatch:
if (element.attribute(component.attribute_name) != component.attribute_value)
return false;
break;
case Selector::SimpleSelector::AttributeMatchType::Contains:
case CSS::Selector::SimpleSelector::AttributeMatchType::Contains:
if (!element.attribute(component.attribute_name).split(' ').contains_slow(component.attribute_value))
return false;
break;
@ -103,20 +101,20 @@ bool matches(const Selector::SimpleSelector& component, const DOM::Element& elem
}
switch (component.type) {
case Selector::SimpleSelector::Type::Universal:
case CSS::Selector::SimpleSelector::Type::Universal:
return true;
case Selector::SimpleSelector::Type::Id:
case CSS::Selector::SimpleSelector::Type::Id:
return component.value == element.attribute(HTML::AttributeNames::id);
case Selector::SimpleSelector::Type::Class:
case CSS::Selector::SimpleSelector::Type::Class:
return element.has_class(component.value);
case Selector::SimpleSelector::Type::TagName:
case CSS::Selector::SimpleSelector::Type::TagName:
return component.value == element.local_name();
default:
ASSERT_NOT_REACHED();
}
}
bool matches(const Selector& selector, int component_list_index, const DOM::Element& element)
bool matches(const CSS::Selector& selector, int component_list_index, const DOM::Element& element)
{
auto& component_list = selector.complex_selectors()[component_list_index];
for (auto& component : component_list.compound_selector) {
@ -124,9 +122,9 @@ bool matches(const Selector& selector, int component_list_index, const DOM::Elem
return false;
}
switch (component_list.relation) {
case Selector::ComplexSelector::Relation::None:
case CSS::Selector::ComplexSelector::Relation::None:
return true;
case Selector::ComplexSelector::Relation::Descendant:
case CSS::Selector::ComplexSelector::Relation::Descendant:
ASSERT(component_list_index != 0);
for (auto* ancestor = element.parent(); ancestor; ancestor = ancestor->parent()) {
if (!is<DOM::Element>(*ancestor))
@ -135,17 +133,17 @@ bool matches(const Selector& selector, int component_list_index, const DOM::Elem
return true;
}
return false;
case Selector::ComplexSelector::Relation::ImmediateChild:
case CSS::Selector::ComplexSelector::Relation::ImmediateChild:
ASSERT(component_list_index != 0);
if (!element.parent() || !is<DOM::Element>(*element.parent()))
return false;
return matches(selector, component_list_index - 1, downcast<DOM::Element>(*element.parent()));
case Selector::ComplexSelector::Relation::AdjacentSibling:
case CSS::Selector::ComplexSelector::Relation::AdjacentSibling:
ASSERT(component_list_index != 0);
if (auto* sibling = element.previous_element_sibling())
return matches(selector, component_list_index - 1, *sibling);
return false;
case Selector::ComplexSelector::Relation::GeneralSibling:
case CSS::Selector::ComplexSelector::Relation::GeneralSibling:
ASSERT(component_list_index != 0);
for (auto* sibling = element.previous_element_sibling(); sibling; sibling = sibling->previous_element_sibling()) {
if (matches(selector, component_list_index - 1, *sibling))
@ -156,12 +154,10 @@ bool matches(const Selector& selector, int component_list_index, const DOM::Elem
ASSERT_NOT_REACHED();
}
bool matches(const Selector& selector, const DOM::Element& element)
bool matches(const CSS::Selector& selector, const DOM::Element& element)
{
ASSERT(!selector.complex_selectors().is_empty());
return matches(selector, selector.complex_selectors().size() - 1, element);
}
}
}

View File

@ -31,6 +31,6 @@
namespace Web::SelectorEngine {
bool matches(const Selector&, const DOM::Element&);
bool matches(const CSS::Selector&, const DOM::Element&);
}

View File

@ -26,7 +26,7 @@
#include <LibWeb/CSS/StyleDeclaration.h>
namespace Web {
namespace Web::CSS {
StyleDeclaration::StyleDeclaration(Vector<StyleProperty>&& properties)
: m_properties(move(properties))

View File

@ -30,7 +30,7 @@
#include <AK/Vector.h>
#include <LibWeb/CSS/StyleValue.h>
namespace Web {
namespace Web::CSS {
struct StyleProperty {
CSS::PropertyID property_id;

View File

@ -29,7 +29,7 @@
#include <LibWeb/FontCache.h>
#include <ctype.h>
namespace Web {
namespace Web::CSS {
StyleProperties::StyleProperties()
{

View File

@ -33,7 +33,7 @@
#include <LibWeb/CSS/LengthBox.h>
#include <LibWeb/CSS/StyleValue.h>
namespace Web {
namespace Web::CSS {
class StyleProperties : public RefCounted<StyleProperties> {
public:

View File

@ -35,7 +35,7 @@
#include <ctype.h>
#include <stdio.h>
namespace Web {
namespace Web::CSS {
StyleResolver::StyleResolver(DOM::Document& document)
: m_document(document)

View File

@ -31,7 +31,7 @@
#include <LibWeb/CSS/StyleProperties.h>
#include <LibWeb/Forward.h>
namespace Web {
namespace Web::CSS {
struct MatchingRule {
RefPtr<StyleRule> rule;

View File

@ -26,7 +26,7 @@
#include <LibWeb/CSS/StyleRule.h>
namespace Web {
namespace Web::CSS {
StyleRule::StyleRule(Vector<Selector>&& selectors, NonnullRefPtr<StyleDeclaration>&& declaration)
: m_selectors(move(selectors))

View File

@ -30,7 +30,7 @@
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/CSS/StyleDeclaration.h>
namespace Web {
namespace Web::CSS {
class StyleRule : public RefCounted<StyleRule> {
AK_MAKE_NONCOPYABLE(StyleRule);

View File

@ -26,7 +26,7 @@
#include <LibWeb/CSS/StyleSheet.h>
namespace Web {
namespace Web::CSS {
StyleSheet::StyleSheet(NonnullRefPtrVector<StyleRule>&& rules)
: m_rules(move(rules))

View File

@ -29,7 +29,7 @@
#include <AK/NonnullRefPtrVector.h>
#include <LibWeb/CSS/StyleRule.h>
namespace Web {
namespace Web::CSS {
class StyleSheet : public RefCounted<StyleSheet> {
public:

View File

@ -34,7 +34,7 @@
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/PageView.h>
namespace Web {
namespace Web::CSS {
StyleValue::StyleValue(Type type)
: m_type(type)

View File

@ -149,10 +149,6 @@ enum class Float {
Right,
};
}
namespace Web {
class StyleValue : public RefCounted<StyleValue> {
public:
virtual ~StyleValue();

View File

@ -63,7 +63,7 @@ namespace Web::DOM {
Document::Document(const URL& url)
: ParentNode(*this, NodeType::DOCUMENT_NODE)
, m_style_resolver(make<StyleResolver>(*this))
, m_style_resolver(make<CSS::StyleResolver>(*this))
, m_style_sheets(CSS::StyleSheetList::create(*this))
, m_url(url)
, m_window(Window::create_with_document(*this))
@ -213,7 +213,7 @@ RefPtr<Gfx::Bitmap> Document::background_image() const
if (!background_image.has_value() || !background_image.value()->is_image())
return {};
auto& image_value = static_cast<const ImageStyleValue&>(*background_image.value());
auto& image_value = static_cast<const CSS::ImageStyleValue&>(*background_image.value());
if (!image_value.bitmap())
return {};
@ -270,9 +270,9 @@ void Document::update_layout()
layout();
}
RefPtr<LayoutNode> Document::create_layout_node(const StyleProperties*)
RefPtr<LayoutNode> Document::create_layout_node(const CSS::StyleProperties*)
{
return adopt(*new LayoutDocument(*this, StyleProperties::create()));
return adopt(*new LayoutDocument(*this, CSS::StyleProperties::create()));
}
void Document::set_link_color(Color color)

View File

@ -69,8 +69,8 @@ public:
void fixup();
StyleResolver& style_resolver() { return *m_style_resolver; }
const StyleResolver& style_resolver() const { return *m_style_resolver; }
CSS::StyleResolver& style_resolver() { return *m_style_resolver; }
const CSS::StyleResolver& style_resolver() const { return *m_style_resolver; }
CSS::StyleSheetList& style_sheets() { return *m_style_sheets; }
const CSS::StyleSheetList& style_sheets() const { return *m_style_sheets; }
@ -158,9 +158,9 @@ public:
const String& compat_mode() const;
private:
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
OwnPtr<StyleResolver> m_style_resolver;
OwnPtr<CSS::StyleResolver> m_style_resolver;
RefPtr<CSS::StyleSheetList> m_style_sheets;
RefPtr<Node> m_hovered_node;
RefPtr<Node> m_inspected_node;

View File

@ -107,7 +107,7 @@ bool Element::has_class(const FlyString& class_name) const
return false;
}
RefPtr<LayoutNode> Element::create_layout_node(const StyleProperties* parent_style)
RefPtr<LayoutNode> Element::create_layout_node(const CSS::StyleProperties* parent_style)
{
auto style = document().style_resolver().resolve_style(*this, parent_style);
const_cast<Element&>(*this).m_resolved_style = style;
@ -164,7 +164,7 @@ enum class StyleDifference {
NeedsRelayout,
};
static StyleDifference compute_style_difference(const StyleProperties& old_style, const StyleProperties& new_style, const Document& document)
static StyleDifference compute_style_difference(const CSS::StyleProperties& old_style, const CSS::StyleProperties& new_style, const Document& document)
{
if (old_style == new_style)
return StyleDifference::None;
@ -223,7 +223,7 @@ void Element::recompute_style()
}
}
NonnullRefPtr<StyleProperties> Element::computed_style()
NonnullRefPtr<CSS::StyleProperties> Element::computed_style()
{
auto properties = m_resolved_style->clone();
if (layout_node() && layout_node()->has_style()) {

View File

@ -66,7 +66,7 @@ public:
bool has_class(const FlyString&) const;
const Vector<FlyString>& class_names() const { return m_classes; }
virtual void apply_presentational_hints(StyleProperties&) const { }
virtual void apply_presentational_hints(CSS::StyleProperties&) const { }
virtual void parse_attribute(const FlyString& name, const String& value);
void recompute_style();
@ -76,14 +76,14 @@ public:
String name() const { return attribute(HTML::AttributeNames::name); }
const StyleProperties* resolved_style() const { return m_resolved_style.ptr(); }
NonnullRefPtr<StyleProperties> computed_style();
const CSS::StyleProperties* resolved_style() const { return m_resolved_style.ptr(); }
NonnullRefPtr<CSS::StyleProperties> computed_style();
String inner_html() const;
void set_inner_html(StringView);
protected:
RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
private:
Attribute* find_attribute(const FlyString& name);
@ -92,7 +92,7 @@ private:
FlyString m_tag_name;
Vector<Attribute> m_attributes;
RefPtr<StyleProperties> m_resolved_style;
RefPtr<CSS::StyleProperties> m_resolved_style;
Vector<FlyString> m_classes;
};

View File

@ -110,7 +110,7 @@ const Element* Node::previous_element_sibling() const
return nullptr;
}
RefPtr<LayoutNode> Node::create_layout_node(const StyleProperties*)
RefPtr<LayoutNode> Node::create_layout_node(const CSS::StyleProperties*)
{
return nullptr;
}

View File

@ -78,7 +78,7 @@ public:
RefPtr<Node> append_child(NonnullRefPtr<Node>, bool notify = true);
RefPtr<Node> insert_before(NonnullRefPtr<Node> node, RefPtr<Node> child, bool notify = true);
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style);
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style);
virtual FlyString node_name() const = 0;

View File

@ -38,7 +38,7 @@ Text::~Text()
{
}
RefPtr<LayoutNode> Text::create_layout_node(const StyleProperties*)
RefPtr<LayoutNode> Text::create_layout_node(const CSS::StyleProperties*)
{
return adopt(*new LayoutText(document(), *this));
}

View File

@ -40,7 +40,7 @@ public:
virtual FlyString node_name() const override { return "#text"; }
private:
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
};
}

View File

@ -199,28 +199,28 @@ void dump_tree(const LayoutNode& layout_node)
--indent;
}
void dump_selector(const Selector& selector)
void dump_selector(const CSS::Selector& selector)
{
dbgprintf(" Selector:\n");
dbgprintf(" CSS::Selector:\n");
for (auto& complex_selector : selector.complex_selectors()) {
dbgprintf(" ");
const char* relation_description = "";
switch (complex_selector.relation) {
case Selector::ComplexSelector::Relation::None:
case CSS::Selector::ComplexSelector::Relation::None:
relation_description = "None";
break;
case Selector::ComplexSelector::Relation::ImmediateChild:
case CSS::Selector::ComplexSelector::Relation::ImmediateChild:
relation_description = "ImmediateChild";
break;
case Selector::ComplexSelector::Relation::Descendant:
case CSS::Selector::ComplexSelector::Relation::Descendant:
relation_description = "Descendant";
break;
case Selector::ComplexSelector::Relation::AdjacentSibling:
case CSS::Selector::ComplexSelector::Relation::AdjacentSibling:
relation_description = "AdjacentSibling";
break;
case Selector::ComplexSelector::Relation::GeneralSibling:
case CSS::Selector::ComplexSelector::Relation::GeneralSibling:
relation_description = "GeneralSibling";
break;
}
@ -232,75 +232,75 @@ void dump_selector(const Selector& selector)
auto& simple_selector = complex_selector.compound_selector[i];
const char* type_description = "Unknown";
switch (simple_selector.type) {
case Selector::SimpleSelector::Type::Invalid:
case CSS::Selector::SimpleSelector::Type::Invalid:
type_description = "Invalid";
break;
case Selector::SimpleSelector::Type::Universal:
case CSS::Selector::SimpleSelector::Type::Universal:
type_description = "Universal";
break;
case Selector::SimpleSelector::Type::Id:
case CSS::Selector::SimpleSelector::Type::Id:
type_description = "Id";
break;
case Selector::SimpleSelector::Type::Class:
case CSS::Selector::SimpleSelector::Type::Class:
type_description = "Class";
break;
case Selector::SimpleSelector::Type::TagName:
case CSS::Selector::SimpleSelector::Type::TagName:
type_description = "TagName";
break;
}
const char* attribute_match_type_description = "";
switch (simple_selector.attribute_match_type) {
case Selector::SimpleSelector::AttributeMatchType::None:
case CSS::Selector::SimpleSelector::AttributeMatchType::None:
break;
case Selector::SimpleSelector::AttributeMatchType::HasAttribute:
case CSS::Selector::SimpleSelector::AttributeMatchType::HasAttribute:
attribute_match_type_description = "HasAttribute";
break;
case Selector::SimpleSelector::AttributeMatchType::ExactValueMatch:
case CSS::Selector::SimpleSelector::AttributeMatchType::ExactValueMatch:
attribute_match_type_description = "ExactValueMatch";
break;
case Selector::SimpleSelector::AttributeMatchType::Contains:
case CSS::Selector::SimpleSelector::AttributeMatchType::Contains:
attribute_match_type_description = "Contains";
break;
}
const char* pseudo_class_description = "";
switch (simple_selector.pseudo_class) {
case Selector::SimpleSelector::PseudoClass::Link:
case CSS::Selector::SimpleSelector::PseudoClass::Link:
pseudo_class_description = "Link";
break;
case Selector::SimpleSelector::PseudoClass::Visited:
case CSS::Selector::SimpleSelector::PseudoClass::Visited:
pseudo_class_description = "Visited";
break;
case Selector::SimpleSelector::PseudoClass::None:
case CSS::Selector::SimpleSelector::PseudoClass::None:
pseudo_class_description = "None";
break;
case Selector::SimpleSelector::PseudoClass::Root:
case CSS::Selector::SimpleSelector::PseudoClass::Root:
pseudo_class_description = "Root";
break;
case Selector::SimpleSelector::PseudoClass::Focus:
case CSS::Selector::SimpleSelector::PseudoClass::Focus:
pseudo_class_description = "Focus";
break;
case Selector::SimpleSelector::PseudoClass::Empty:
case CSS::Selector::SimpleSelector::PseudoClass::Empty:
pseudo_class_description = "Empty";
break;
case Selector::SimpleSelector::PseudoClass::Hover:
case CSS::Selector::SimpleSelector::PseudoClass::Hover:
pseudo_class_description = "Hover";
break;
case Selector::SimpleSelector::PseudoClass::LastChild:
case CSS::Selector::SimpleSelector::PseudoClass::LastChild:
pseudo_class_description = "LastChild";
break;
case Selector::SimpleSelector::PseudoClass::FirstChild:
case CSS::Selector::SimpleSelector::PseudoClass::FirstChild:
pseudo_class_description = "FirstChild";
break;
case Selector::SimpleSelector::PseudoClass::OnlyChild:
case CSS::Selector::SimpleSelector::PseudoClass::OnlyChild:
pseudo_class_description = "OnlyChild";
break;
}
dbgprintf("%s:%s", type_description, simple_selector.value.characters());
if (simple_selector.pseudo_class != Selector::SimpleSelector::PseudoClass::None)
if (simple_selector.pseudo_class != CSS::Selector::SimpleSelector::PseudoClass::None)
dbgprintf(" pseudo_class=%s", pseudo_class_description);
if (simple_selector.attribute_match_type != Selector::SimpleSelector::AttributeMatchType::None) {
if (simple_selector.attribute_match_type != CSS::Selector::SimpleSelector::AttributeMatchType::None) {
dbgprintf(" [%s, name='%s', value='%s']", attribute_match_type_description, simple_selector.attribute_name.characters(), simple_selector.attribute_value.characters());
}
@ -311,7 +311,7 @@ void dump_selector(const Selector& selector)
}
}
void dump_rule(const StyleRule& rule)
void dump_rule(const CSS::StyleRule& rule)
{
dbgprintf("Rule:\n");
for (auto& selector : rule.selectors()) {
@ -323,7 +323,7 @@ void dump_rule(const StyleRule& rule)
}
}
void dump_sheet(const StyleSheet& sheet)
void dump_sheet(const CSS::StyleSheet& sheet)
{
dbgprintf("StyleSheet{%p}: %d rule(s)\n", &sheet, sheet.rules().size());

View File

@ -32,9 +32,9 @@ namespace Web {
void dump_tree(const DOM::Node&);
void dump_tree(const LayoutNode&);
void dump_sheet(const StyleSheet&);
void dump_rule(const StyleRule&);
void dump_selector(const Selector&);
void dump_sheet(const CSS::StyleSheet&);
void dump_rule(const CSS::StyleRule&);
void dump_selector(const CSS::Selector&);
#undef HTML_DEBUG

View File

@ -26,6 +26,14 @@
#pragma once
namespace Web::CSS {
class Selector;
class StyleProperties;
class StyleResolver;
class StyleRule;
class StyleSheet;
}
namespace Web::DOM {
class Document;
class DocumentType;
@ -72,12 +80,7 @@ class PageView;
class PaintContext;
class Resource;
class ResourceLoader;
class Selector;
class StackingContext;
class StyleProperties;
class StyleResolver;
class StyleRule;
class StyleSheet;
class XMLHttpRequest;
}

View File

@ -38,7 +38,7 @@ HTMLBRElement::~HTMLBRElement()
{
}
RefPtr<LayoutNode> HTMLBRElement::create_layout_node(const StyleProperties*)
RefPtr<LayoutNode> HTMLBRElement::create_layout_node(const CSS::StyleProperties*)
{
return adopt(*new LayoutBreak(document(), *this));
}

View File

@ -35,7 +35,7 @@ public:
HTMLBRElement(DOM::Document&, const FlyString& local_name);
virtual ~HTMLBRElement() override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
};
}

View File

@ -40,17 +40,17 @@ HTMLBodyElement::~HTMLBodyElement()
{
}
void HTMLBodyElement::apply_presentational_hints(StyleProperties& style) const
void HTMLBodyElement::apply_presentational_hints(CSS::StyleProperties& style) const
{
for_each_attribute([&](auto& name, auto& value) {
if (name.equals_ignoring_case("bgcolor")) {
auto color = Color::from_string(value);
if (color.has_value())
style.set_property(CSS::PropertyID::BackgroundColor, ColorStyleValue::create(color.value()));
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()));
} else if (name.equals_ignoring_case("text")) {
auto color = Color::from_string(value);
if (color.has_value())
style.set_property(CSS::PropertyID::Color, ColorStyleValue::create(color.value()));
style.set_property(CSS::PropertyID::Color, CSS::ColorStyleValue::create(color.value()));
} else if (name.equals_ignoring_case("background")) {
ASSERT(m_background_style_value);
style.set_property(CSS::PropertyID::BackgroundImage, *m_background_style_value);
@ -74,7 +74,7 @@ void HTMLBodyElement::parse_attribute(const FlyString& name, const String& value
if (color.has_value())
document().set_visited_link_color(color.value());
} else if (name.equals_ignoring_case("background")) {
m_background_style_value = ImageStyleValue::create(document().complete_url(value), const_cast<DOM::Document&>(document()));
m_background_style_value = CSS::ImageStyleValue::create(document().complete_url(value), const_cast<DOM::Document&>(document()));
}
}

View File

@ -36,10 +36,10 @@ public:
virtual ~HTMLBodyElement() override;
virtual void parse_attribute(const FlyString&, const String&) override;
virtual void apply_presentational_hints(StyleProperties&) const override;
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
private:
RefPtr<ImageStyleValue> m_background_style_value;
RefPtr<CSS::ImageStyleValue> m_background_style_value;
};
}

View File

@ -55,7 +55,7 @@ unsigned HTMLCanvasElement::height() const
return attribute(HTML::AttributeNames::height).to_uint().value_or(150);
}
RefPtr<LayoutNode> HTMLCanvasElement::create_layout_node(const StyleProperties* parent_style)
RefPtr<LayoutNode> 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)

View File

@ -51,7 +51,7 @@ public:
unsigned height() const;
private:
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
RefPtr<Gfx::Bitmap> m_bitmap;
RefPtr<CanvasRenderingContext2D> m_context;

View File

@ -39,13 +39,13 @@ HTMLFontElement::~HTMLFontElement()
{
}
void HTMLFontElement::apply_presentational_hints(StyleProperties& style) const
void HTMLFontElement::apply_presentational_hints(CSS::StyleProperties& style) const
{
for_each_attribute([&](auto& name, auto& value) {
if (name.equals_ignoring_case("color")) {
auto color = Color::from_string(value);
if (color.has_value())
style.set_property(CSS::PropertyID::Color, ColorStyleValue::create(color.value()));
style.set_property(CSS::PropertyID::Color, CSS::ColorStyleValue::create(color.value()));
}
});
}

View File

@ -35,7 +35,7 @@ public:
HTMLFontElement(DOM::Document&, const FlyString& local_name);
virtual ~HTMLFontElement() override;
virtual void apply_presentational_hints(StyleProperties&) const override;
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
};
}

View File

@ -50,7 +50,7 @@ HTMLIFrameElement::~HTMLIFrameElement()
{
}
RefPtr<LayoutNode> HTMLIFrameElement::create_layout_node(const StyleProperties* parent_style)
RefPtr<LayoutNode> 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)));

View File

@ -35,7 +35,7 @@ public:
HTMLIFrameElement(DOM::Document&, const FlyString& local_name);
virtual ~HTMLIFrameElement() override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
Frame* hosted_frame() { return m_hosted_frame; }
const Frame* hosted_frame() const { return m_hosted_frame; }

View File

@ -61,7 +61,7 @@ HTMLImageElement::~HTMLImageElement()
{
}
void HTMLImageElement::apply_presentational_hints(StyleProperties& style) const
void HTMLImageElement::apply_presentational_hints(CSS::StyleProperties& style) const
{
for_each_attribute([&](auto& name, auto& value) {
if (name == HTML::AttributeNames::width) {
@ -84,7 +84,7 @@ 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 StyleProperties* parent_style)
RefPtr<LayoutNode> 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)

View File

@ -51,11 +51,11 @@ public:
const Gfx::Bitmap* bitmap() const;
private:
virtual void apply_presentational_hints(StyleProperties&) const override;
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
void animate();
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
ImageLoader m_image_loader;
};

View File

@ -46,7 +46,7 @@ HTMLInputElement::~HTMLInputElement()
{
}
RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties* parent_style)
RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const CSS::StyleProperties* parent_style)
{
ASSERT(document().frame());
auto& frame = *document().frame();

View File

@ -35,7 +35,7 @@ public:
HTMLInputElement(DOM::Document&, const FlyString& local_name);
virtual ~HTMLInputElement() override;
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
virtual RefPtr<LayoutNode> 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); }

View File

@ -79,7 +79,7 @@ void HTMLLinkElement::load_stylesheet(const URL& url)
{
// First insert an empty style sheet in the document sheet list.
// There's probably a nicer way to do this, but this ensures that sheets are in document order.
m_style_sheet = StyleSheet::create({});
m_style_sheet = CSS::StyleSheet::create({});
document().style_sheets().add_sheet(*m_style_sheet);
LoadRequest request;

View File

@ -61,7 +61,7 @@ private:
};
unsigned m_relationship { 0 };
RefPtr<StyleSheet> m_style_sheet;
RefPtr<CSS::StyleSheet> m_style_sheet;
};
}

View File

@ -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 StyleProperties* parent_style)
RefPtr<LayoutNode> HTMLObjectElement::create_layout_node(const CSS::StyleProperties* parent_style)
{
if (m_should_show_fallback_content)
return HTMLElement::create_layout_node(parent_style);

View File

@ -46,7 +46,7 @@ public:
String type() const { return attribute(HTML::AttributeNames::type); }
private:
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
ImageLoader m_image_loader;
bool m_should_show_fallback_content { false };

View File

@ -52,7 +52,7 @@ void HTMLStyleElement::children_changed()
if (m_stylesheet)
document().style_sheets().add_sheet(*m_stylesheet);
else
document().style_sheets().add_sheet(StyleSheet::create({}));
document().style_sheets().add_sheet(CSS::StyleSheet::create({}));
HTMLElement::children_changed();
}

View File

@ -30,8 +30,6 @@
namespace Web {
class StyleSheet;
class HTMLStyleElement : public HTMLElement {
public:
HTMLStyleElement(DOM::Document&, const FlyString& local_name);
@ -41,7 +39,7 @@ public:
virtual void removed_from(Node&) override;
private:
RefPtr<StyleSheet> m_stylesheet;
RefPtr<CSS::StyleSheet> m_stylesheet;
};
}

View File

@ -38,13 +38,13 @@ HTMLTableCellElement::~HTMLTableCellElement()
{
}
void HTMLTableCellElement::apply_presentational_hints(StyleProperties& style) const
void HTMLTableCellElement::apply_presentational_hints(CSS::StyleProperties& style) const
{
for_each_attribute([&](auto& name, auto& value) {
if (name == HTML::AttributeNames::bgcolor) {
auto color = Color::from_string(value);
if (color.has_value())
style.set_property(CSS::PropertyID::BackgroundColor, ColorStyleValue::create(color.value()));
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()));
return;
}
if (name == HTML::AttributeNames::align) {

View File

@ -36,7 +36,7 @@ public:
virtual ~HTMLTableCellElement() override;
private:
virtual void apply_presentational_hints(StyleProperties&) const override;
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
};
}

View File

@ -38,7 +38,7 @@ HTMLTableElement::~HTMLTableElement()
{
}
void HTMLTableElement::apply_presentational_hints(StyleProperties& style) const
void HTMLTableElement::apply_presentational_hints(CSS::StyleProperties& style) const
{
for_each_attribute([&](auto& name, auto& value) {
if (name == HTML::AttributeNames::width) {
@ -49,7 +49,7 @@ void HTMLTableElement::apply_presentational_hints(StyleProperties& style) const
if (name == HTML::AttributeNames::bgcolor) {
auto color = Color::from_string(value);
if (color.has_value())
style.set_property(CSS::PropertyID::BackgroundColor, ColorStyleValue::create(color.value()));
style.set_property(CSS::PropertyID::BackgroundColor, CSS::ColorStyleValue::create(color.value()));
return;
}
});

View File

@ -36,7 +36,7 @@ public:
virtual ~HTMLTableElement() override;
private:
virtual void apply_presentational_hints(StyleProperties&) const override;
virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
};
}

View File

@ -40,15 +40,14 @@ struct PixelBox {
struct BoxModelMetrics {
public:
LengthBox margin;
LengthBox padding;
LengthBox border;
LengthBox offset;
CSS::LengthBox margin;
CSS::LengthBox padding;
CSS::LengthBox border;
CSS::LengthBox offset;
PixelBox margin_box(const LayoutNode&) const;
PixelBox padding_box(const LayoutNode&) const;
PixelBox border_box(const LayoutNode&) const;
};
}

View File

@ -38,7 +38,7 @@
namespace Web {
LayoutBlock::LayoutBlock(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<StyleProperties> style)
LayoutBlock::LayoutBlock(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutBox(document, node, move(style))
{
}
@ -69,7 +69,7 @@ void LayoutBlock::layout_absolutely_positioned_descendant(LayoutBox& box)
{
box.layout(LayoutMode::Default);
auto& box_model = box.box_model();
auto zero_value = Length::make_px(0);
auto zero_value = CSS::Length::make_px(0);
auto specified_width = box.style().width().resolved_or_auto(box, width());
@ -78,10 +78,10 @@ void LayoutBlock::layout_absolutely_positioned_descendant(LayoutBox& box)
box_model.margin.right = box.style().margin().right.resolved_or_auto(box, width());
box_model.margin.bottom = box.style().margin().bottom.resolved_or_auto(box, height());
box_model.border.left = Length::make_px(box.style().border_left().width);
box_model.border.right = Length::make_px(box.style().border_right().width);
box_model.border.top = Length::make_px(box.style().border_top().width);
box_model.border.bottom = Length::make_px(box.style().border_bottom().width);
box_model.border.left = CSS::Length::make_px(box.style().border_left().width);
box_model.border.right = CSS::Length::make_px(box.style().border_right().width);
box_model.border.top = CSS::Length::make_px(box.style().border_top().width);
box_model.border.bottom = CSS::Length::make_px(box.style().border_bottom().width);
box_model.offset.left = box.style().offset().left.resolved_or_auto(box, width());
box_model.offset.top = box.style().offset().top.resolved_or_auto(box, height());
@ -283,10 +283,10 @@ void LayoutBlock::layout_inline_children(LayoutMode layout_mode)
void LayoutBlock::compute_width_for_absolutely_positioned_block()
{
auto& containing_block = *this->containing_block();
auto zero_value = Length::make_px(0);
auto zero_value = CSS::Length::make_px(0);
auto margin_left = Length::make_auto();
auto margin_right = Length::make_auto();
auto margin_left = CSS::Length::make_auto();
auto margin_right = CSS::Length::make_auto();
const auto border_left = style().border_left().width;
const auto border_right = style().border_right().width;
const auto padding_left = style().padding().left.resolved(zero_value, *this, containing_block.width());
@ -301,29 +301,29 @@ void LayoutBlock::compute_width_for_absolutely_positioned_block()
auto width = a_width;
auto solve_for_left = [&] {
return Length(containing_block.width() - margin_left.to_px(*this) - border_left - padding_left.to_px(*this) - width.to_px(*this) - padding_right.to_px(*this) - border_right - margin_right.to_px(*this) - right.to_px(*this), Length::Type::Px);
return CSS::Length(containing_block.width() - margin_left.to_px(*this) - border_left - padding_left.to_px(*this) - width.to_px(*this) - padding_right.to_px(*this) - border_right - margin_right.to_px(*this) - right.to_px(*this), CSS::Length::Type::Px);
};
auto solve_for_width = [&] {
return Length(containing_block.width() - left.to_px(*this) - margin_left.to_px(*this) - border_left - padding_left.to_px(*this) - padding_right.to_px(*this) - border_right - margin_right.to_px(*this) - right.to_px(*this), Length::Type::Px);
return CSS::Length(containing_block.width() - left.to_px(*this) - margin_left.to_px(*this) - border_left - padding_left.to_px(*this) - padding_right.to_px(*this) - border_right - margin_right.to_px(*this) - right.to_px(*this), CSS::Length::Type::Px);
};
auto solve_for_right = [&] {
return Length(containing_block.width() - left.to_px(*this) - margin_left.to_px(*this) - border_left - padding_left.to_px(*this) - width.to_px(*this) - padding_right.to_px(*this) - border_right - margin_right.to_px(*this), Length::Type::Px);
return CSS::Length(containing_block.width() - left.to_px(*this) - margin_left.to_px(*this) - border_left - padding_left.to_px(*this) - width.to_px(*this) - padding_right.to_px(*this) - border_right - margin_right.to_px(*this), CSS::Length::Type::Px);
};
// If all three of 'left', 'width', and 'right' are 'auto':
if (left.is_auto() && width.is_auto() && right.is_auto()) {
// First set any 'auto' values for 'margin-left' and 'margin-right' to 0.
if (margin_left.is_auto())
margin_left = Length::make_px(0);
margin_left = CSS::Length::make_px(0);
if (margin_right.is_auto())
margin_right = Length::make_px(0);
margin_right = CSS::Length::make_px(0);
// Then, if the 'direction' property of the element establishing the static-position containing block
// is 'ltr' set 'left' to the static position and apply rule number three below;
// otherwise, set 'right' to the static position and apply rule number one below.
// FIXME: This is very hackish.
left = Length::make_px(0);
left = CSS::Length::make_px(0);
goto Rule3;
}
@ -333,9 +333,9 @@ void LayoutBlock::compute_width_for_absolutely_positioned_block()
}
if (margin_left.is_auto())
margin_left = Length::make_px(0);
margin_left = CSS::Length::make_px(0);
if (margin_right.is_auto())
margin_right = Length::make_px(0);
margin_right = CSS::Length::make_px(0);
// 1. 'left' and 'width' are 'auto' and 'right' is not 'auto',
// then the width is shrink-to-fit. Then solve for 'left'
@ -343,7 +343,7 @@ void LayoutBlock::compute_width_for_absolutely_positioned_block()
auto result = calculate_shrink_to_fit_width();
solve_for_left();
auto available_width = solve_for_width();
width = Length(min(max(result.preferred_minimum_width, available_width.to_px(*this)), result.preferred_width), Length::Type::Px);
width = CSS::Length(min(max(result.preferred_minimum_width, available_width.to_px(*this)), result.preferred_width), CSS::Length::Type::Px);
}
// 2. 'left' and 'right' are 'auto' and 'width' is not 'auto',
@ -365,7 +365,7 @@ void LayoutBlock::compute_width_for_absolutely_positioned_block()
auto result = calculate_shrink_to_fit_width();
right = solve_for_right();
auto available_width = solve_for_width();
width = Length(min(max(result.preferred_minimum_width, available_width.to_px(*this)), result.preferred_width), Length::Type::Px);
width = CSS::Length(min(max(result.preferred_minimum_width, available_width.to_px(*this)), result.preferred_width), CSS::Length::Type::Px);
}
// 4. 'left' is 'auto', 'width' and 'right' are not 'auto', then solve for 'left'
@ -413,8 +413,8 @@ void LayoutBlock::compute_width_for_absolutely_positioned_block()
box_model().margin.left = margin_left;
box_model().margin.right = margin_right;
box_model().border.left = Length::make_px(border_left);
box_model().border.right = Length::make_px(border_right);
box_model().border.left = CSS::Length::make_px(border_left);
box_model().border.right = CSS::Length::make_px(border_right);
box_model().padding.left = padding_left;
box_model().padding.right = padding_right;
}
@ -433,15 +433,15 @@ void LayoutBlock::compute_width()
float width_of_containing_block = this->width_of_logical_containing_block();
auto zero_value = Length::make_px(0);
auto zero_value = CSS::Length::make_px(0);
auto margin_left = Length::make_auto();
auto margin_right = Length::make_auto();
auto margin_left = CSS::Length::make_auto();
auto margin_right = CSS::Length::make_auto();
const auto padding_left = style().padding().left.resolved_or_zero(*this, width_of_containing_block);
const auto padding_right = style().padding().right.resolved_or_zero(*this, width_of_containing_block);
auto try_compute_width = [&](const auto& a_width) {
Length width = a_width;
CSS::Length width = a_width;
margin_left = style().margin().left.resolved_or_zero(*this, width_of_containing_block);
margin_right = style().margin().right.resolved_or_zero(*this, width_of_containing_block);
@ -473,20 +473,20 @@ void LayoutBlock::compute_width()
if (margin_right.is_auto())
margin_right = zero_value;
if (underflow_px >= 0) {
width = Length(underflow_px, Length::Type::Px);
width = CSS::Length(underflow_px, CSS::Length::Type::Px);
} else {
width = zero_value;
margin_right = Length(margin_right.to_px(*this) + underflow_px, Length::Type::Px);
margin_right = CSS::Length(margin_right.to_px(*this) + underflow_px, CSS::Length::Type::Px);
}
} else {
if (!margin_left.is_auto() && !margin_right.is_auto()) {
margin_right = Length(margin_right.to_px(*this) + underflow_px, Length::Type::Px);
margin_right = CSS::Length(margin_right.to_px(*this) + underflow_px, CSS::Length::Type::Px);
} else if (!margin_left.is_auto() && margin_right.is_auto()) {
margin_right = Length(underflow_px, Length::Type::Px);
margin_right = CSS::Length(underflow_px, CSS::Length::Type::Px);
} else if (margin_left.is_auto() && !margin_right.is_auto()) {
margin_left = Length(underflow_px, Length::Type::Px);
margin_left = CSS::Length(underflow_px, CSS::Length::Type::Px);
} else { // margin_left.is_auto() && margin_right.is_auto()
auto half_of_the_underflow = Length(underflow_px / 2, Length::Type::Px);
auto half_of_the_underflow = CSS::Length(underflow_px / 2, CSS::Length::Type::Px);
margin_left = half_of_the_underflow;
margin_right = half_of_the_underflow;
}
@ -514,7 +514,7 @@ void LayoutBlock::compute_width()
auto result = calculate_shrink_to_fit_width();
// Then the shrink-to-fit width is: min(max(preferred minimum width, available width), preferred width).
width = Length(min(max(result.preferred_minimum_width, available_width), result.preferred_width), Length::Type::Px);
width = CSS::Length(min(max(result.preferred_minimum_width, available_width), result.preferred_width), CSS::Length::Type::Px);
}
}
@ -547,8 +547,8 @@ void LayoutBlock::compute_width()
set_width(used_width.to_px(*this));
box_model().margin.left = margin_left;
box_model().margin.right = margin_right;
box_model().border.left = Length::make_px(style().border_left().width);
box_model().border.right = Length::make_px(style().border_right().width);
box_model().border.left = CSS::Length::make_px(style().border_left().width);
box_model().border.right = CSS::Length::make_px(style().border_right().width);
box_model().padding.left = padding_left;
box_model().padding.right = padding_right;
}
@ -561,8 +561,8 @@ void LayoutBlock::place_block_level_replaced_element_in_normal_flow(LayoutReplac
replaced_element_box_model.margin.top = box.style().margin().top.resolved_or_zero(*this, containing_block.width());
replaced_element_box_model.margin.bottom = box.style().margin().bottom.resolved_or_zero(*this, containing_block.width());
replaced_element_box_model.border.top = Length::make_px(box.style().border_top().width);
replaced_element_box_model.border.bottom = Length::make_px(box.style().border_bottom().width);
replaced_element_box_model.border.top = CSS::Length::make_px(box.style().border_top().width);
replaced_element_box_model.border.bottom = CSS::Length::make_px(box.style().border_bottom().width);
replaced_element_box_model.padding.top = box.style().padding().top.resolved_or_zero(*this, containing_block.width());
replaced_element_box_model.padding.bottom = box.style().padding().bottom.resolved_or_zero(*this, containing_block.width());
@ -609,15 +609,15 @@ LayoutBlock::ShrinkToFitResult LayoutBlock::calculate_shrink_to_fit_width()
void LayoutBlock::place_block_level_non_replaced_element_in_normal_flow(LayoutBlock& block)
{
auto zero_value = Length::make_px(0);
auto zero_value = CSS::Length::make_px(0);
auto& containing_block = *this;
auto& box = block.box_model();
auto& style = block.style();
box.margin.top = style.margin().top.resolved(zero_value, *this, containing_block.width());
box.margin.bottom = style.margin().bottom.resolved(zero_value, *this, containing_block.width());
box.border.top = Length::make_px(style.border_top().width);
box.border.bottom = Length::make_px(style.border_bottom().width);
box.border.top = CSS::Length::make_px(style.border_top().width);
box.border.bottom = CSS::Length::make_px(style.border_bottom().width);
box.padding.top = style.padding().top.resolved(zero_value, *this, containing_block.width());
box.padding.bottom = style.padding().bottom.resolved(zero_value, *this, containing_block.width());
@ -671,10 +671,10 @@ void LayoutBlock::compute_height()
{
auto& containing_block = *this->containing_block();
Length specified_height;
CSS::Length specified_height;
if (style().height().is_percentage() && !containing_block.style().height().is_absolute()) {
specified_height = Length::make_auto();
specified_height = CSS::Length::make_auto();
} else {
specified_height = style().height().resolved_or_auto(*this, containing_block.height());
}
@ -683,8 +683,8 @@ void LayoutBlock::compute_height()
box_model().margin.top = style().margin().top.resolved_or_zero(*this, containing_block.width());
box_model().margin.bottom = style().margin().bottom.resolved_or_zero(*this, containing_block.width());
box_model().border.top = Length::make_px(style().border_top().width);
box_model().border.bottom = Length::make_px(style().border_bottom().width);
box_model().border.top = CSS::Length::make_px(style().border_top().width);
box_model().border.bottom = CSS::Length::make_px(style().border_bottom().width);
box_model().padding.top = style().padding().top.resolved_or_zero(*this, containing_block.width());
box_model().padding.bottom = style().padding().bottom.resolved_or_zero(*this, containing_block.width());
@ -742,12 +742,12 @@ HitTestResult LayoutBlock::hit_test(const Gfx::IntPoint& position) const
return { absolute_rect().contains(position.x(), position.y()) ? this : nullptr };
}
NonnullRefPtr<StyleProperties> LayoutBlock::style_for_anonymous_block() const
NonnullRefPtr<CSS::StyleProperties> LayoutBlock::style_for_anonymous_block() const
{
auto new_style = StyleProperties::create();
auto new_style = CSS::StyleProperties::create();
specified_style().for_each_property([&](auto property_id, auto& value) {
if (StyleResolver::is_inherited_property(property_id))
if (CSS::StyleResolver::is_inherited_property(property_id))
new_style->set_property(property_id, value);
});

View File

@ -33,7 +33,7 @@ namespace Web {
class LayoutBlock : public LayoutBox {
public:
LayoutBlock(DOM::Document&, const DOM::Node*, NonnullRefPtr<StyleProperties>);
LayoutBlock(DOM::Document&, const DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutBlock() override;
virtual const char* class_name() const override { return "LayoutBlock"; }
@ -87,7 +87,7 @@ private:
void place_block_level_replaced_element_in_normal_flow(LayoutReplaced&);
void layout_absolutely_positioned_descendant(LayoutBox&);
NonnullRefPtr<StyleProperties> style_for_anonymous_block() const;
NonnullRefPtr<CSS::StyleProperties> style_for_anonymous_block() const;
void layout_inline_children(LayoutMode);
void layout_contained_boxes(LayoutMode);

View File

@ -186,7 +186,7 @@ void LayoutBox::paint(PaintContext& context, PaintPhase phase)
auto bgimage = specified_style().property(CSS::PropertyID::BackgroundImage);
if (bgimage.has_value() && bgimage.value()->is_image()) {
auto& image_value = static_cast<const ImageStyleValue&>(*bgimage.value());
auto& image_value = static_cast<const CSS::ImageStyleValue&>(*bgimage.value());
if (image_value.bitmap()) {
context.painter().draw_tiled_bitmap(enclosing_int_rect(padded_rect), *image_value.bitmap());
}

View File

@ -71,7 +71,7 @@ public:
virtual void paint(PaintContext&, PaintPhase) override;
protected:
LayoutBox(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<StyleProperties> style)
LayoutBox(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutNodeWithStyleAndBoxModelMetrics(document, node, move(style))
{
}

View File

@ -30,7 +30,7 @@
namespace Web {
LayoutBreak::LayoutBreak(DOM::Document& document, const HTMLBRElement& element)
: LayoutNodeWithStyleAndBoxModelMetrics(document, &element, StyleProperties::create())
: LayoutNodeWithStyleAndBoxModelMetrics(document, &element, CSS::StyleProperties::create())
{
set_inline(true);
}

View File

@ -31,7 +31,7 @@
namespace Web {
LayoutCanvas::LayoutCanvas(DOM::Document& document, const HTMLCanvasElement& element, NonnullRefPtr<StyleProperties> style)
LayoutCanvas::LayoutCanvas(DOM::Document& document, const HTMLCanvasElement& element, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutReplaced(document, element, move(style))
{
}

View File

@ -35,7 +35,7 @@ class HTMLCanvasElement;
class LayoutCanvas : public LayoutReplaced {
public:
LayoutCanvas(DOM::Document&, const HTMLCanvasElement&, NonnullRefPtr<StyleProperties>);
LayoutCanvas(DOM::Document&, const HTMLCanvasElement&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutCanvas() override;
virtual void layout(LayoutMode = LayoutMode::Default) override;

View File

@ -33,7 +33,7 @@
namespace Web {
LayoutDocument::LayoutDocument(DOM::Document& document, NonnullRefPtr<StyleProperties> style)
LayoutDocument::LayoutDocument(DOM::Document& document, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutBlock(document, &document, move(style))
{
}

View File

@ -33,7 +33,7 @@ namespace Web {
class LayoutDocument final : public LayoutBlock {
public:
explicit LayoutDocument(DOM::Document&, NonnullRefPtr<StyleProperties>);
explicit LayoutDocument(DOM::Document&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutDocument() override;
const DOM::Document& node() const { return static_cast<const DOM::Document&>(*LayoutNode::node()); }

View File

@ -37,7 +37,7 @@
namespace Web {
LayoutFrame::LayoutFrame(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
LayoutFrame::LayoutFrame(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutReplaced(document, element, move(style))
{
}

View File

@ -33,7 +33,7 @@ namespace Web {
class LayoutFrame final : public LayoutReplaced {
public:
LayoutFrame(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
LayoutFrame(DOM::Document&, const DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutFrame() override;
virtual void paint(PaintContext&, PaintPhase) override;

View File

@ -32,7 +32,7 @@
namespace Web {
LayoutImage::LayoutImage(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style, const ImageLoader& image_loader)
LayoutImage::LayoutImage(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style, const ImageLoader& image_loader)
: LayoutReplaced(document, element, move(style))
, m_image_loader(image_loader)
{

View File

@ -35,7 +35,7 @@ class HTMLImageElement;
class LayoutImage : public LayoutReplaced {
public:
LayoutImage(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>, const ImageLoader&);
LayoutImage(DOM::Document&, const DOM::Element&, NonnullRefPtr<CSS::StyleProperties>, const ImageLoader&);
virtual ~LayoutImage() override;
virtual void layout(LayoutMode = LayoutMode::Default) override;

View File

@ -30,7 +30,7 @@
namespace Web {
LayoutInline::LayoutInline(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
LayoutInline::LayoutInline(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutNodeWithStyleAndBoxModelMetrics(document, &element, move(style))
{
set_inline(true);

View File

@ -34,7 +34,7 @@ class LayoutBlock;
class LayoutInline : public LayoutNodeWithStyleAndBoxModelMetrics {
public:
LayoutInline(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
LayoutInline(DOM::Document&, const DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutInline() override;
virtual const char* class_name() const override { return "LayoutInline"; }
};

View File

@ -29,7 +29,7 @@
namespace Web {
LayoutListItem::LayoutListItem(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
LayoutListItem::LayoutListItem(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutBlock(document, &element, move(style))
{
}

View File

@ -35,7 +35,7 @@ class LayoutListItemMarker;
class LayoutListItem final : public LayoutBlock {
public:
LayoutListItem(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
LayoutListItem(DOM::Document&, const DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutListItem() override;
virtual void layout(LayoutMode = LayoutMode::Default) override;

View File

@ -30,7 +30,7 @@
namespace Web {
LayoutListItemMarker::LayoutListItemMarker(DOM::Document& document)
: LayoutBox(document, nullptr, StyleProperties::create())
: LayoutBox(document, nullptr, CSS::StyleProperties::create())
{
}

View File

@ -163,7 +163,7 @@ void LayoutNode::set_needs_display()
float LayoutNode::font_size() const
{
// FIXME: This doesn't work right for relative font-sizes
auto length = specified_style().length_or_fallback(CSS::PropertyID::FontSize, Length(10, Length::Type::Px));
auto length = specified_style().length_or_fallback(CSS::PropertyID::FontSize, CSS::Length(10, CSS::Length::Type::Px));
return length.raw_value();
}
@ -208,7 +208,7 @@ bool LayoutNode::is_fixed_position() const
return position == CSS::Position::Fixed;
}
LayoutNodeWithStyle::LayoutNodeWithStyle(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<StyleProperties> specified_style)
LayoutNodeWithStyle::LayoutNodeWithStyle(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> specified_style)
: LayoutNode(document, node)
, m_specified_style(move(specified_style))
{
@ -216,7 +216,7 @@ LayoutNodeWithStyle::LayoutNodeWithStyle(DOM::Document& document, const DOM::Nod
apply_style(*m_specified_style);
}
void LayoutNodeWithStyle::apply_style(const StyleProperties& specified_style)
void LayoutNodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
{
auto& style = static_cast<MutableLayoutStyle&>(m_style);

View File

@ -147,7 +147,7 @@ public:
virtual LayoutNode& inline_wrapper() { return *this; }
const StyleProperties& specified_style() const;
const CSS::StyleProperties& specified_style() const;
const ImmutableLayoutStyle& style() const;
LayoutNodeWithStyle* parent();
@ -214,20 +214,20 @@ class LayoutNodeWithStyle : public LayoutNode {
public:
virtual ~LayoutNodeWithStyle() override { }
const StyleProperties& specified_style() const { return m_specified_style; }
void set_specified_style(const StyleProperties& style) { m_specified_style = style; }
const CSS::StyleProperties& specified_style() const { return m_specified_style; }
void set_specified_style(const CSS::StyleProperties& style) { m_specified_style = style; }
const ImmutableLayoutStyle& style() const { return static_cast<const ImmutableLayoutStyle&>(m_style); }
void apply_style(const StyleProperties&);
void apply_style(const CSS::StyleProperties&);
protected:
LayoutNodeWithStyle(DOM::Document&, const DOM::Node*, NonnullRefPtr<StyleProperties>);
LayoutNodeWithStyle(DOM::Document&, const DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
private:
LayoutStyle m_style;
NonnullRefPtr<StyleProperties> m_specified_style;
NonnullRefPtr<CSS::StyleProperties> m_specified_style;
CSS::Position m_position;
CSS::TextAlign m_text_align;
};
@ -238,7 +238,7 @@ public:
const BoxModelMetrics& box_model() const { return m_box_model; }
protected:
LayoutNodeWithStyleAndBoxModelMetrics(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<StyleProperties> style)
LayoutNodeWithStyleAndBoxModelMetrics(DOM::Document& document, const DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutNodeWithStyle(document, node, move(style))
{
}
@ -247,7 +247,7 @@ private:
BoxModelMetrics m_box_model;
};
inline const StyleProperties& LayoutNode::specified_style() const
inline const CSS::StyleProperties& LayoutNode::specified_style() const
{
if (m_has_style)
return static_cast<const LayoutNodeWithStyle*>(this)->specified_style();

View File

@ -30,7 +30,7 @@
namespace Web {
LayoutReplaced::LayoutReplaced(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
LayoutReplaced::LayoutReplaced(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutBox(document, &element, move(style))
{
// FIXME: Allow non-inline replaced elements.
@ -45,7 +45,7 @@ float LayoutReplaced::calculate_width() const
{
// 10.3.2 [Inline,] replaced elements
auto zero_value = Length::make_px(0);
auto zero_value = CSS::Length::make_px(0);
auto& containing_block = *this->containing_block();
auto margin_left = style().margin().left.resolved_or_zero(*this, containing_block.width());

View File

@ -33,7 +33,7 @@ namespace Web {
class LayoutReplaced : public LayoutBox {
public:
LayoutReplaced(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
LayoutReplaced(DOM::Document&, const DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutReplaced() override;
const DOM::Element& node() const { return downcast<DOM::Element>(*LayoutNode::node()); }

View File

@ -31,7 +31,7 @@
namespace Web {
LayoutSVG::LayoutSVG(DOM::Document& document, const SVG::SVGSVGElement& element, NonnullRefPtr<StyleProperties> style)
LayoutSVG::LayoutSVG(DOM::Document& document, const SVG::SVGSVGElement& element, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutReplaced(document, element, move(style))
{
}

View File

@ -36,7 +36,7 @@ class SVGSVGElement;
class LayoutSVG : public LayoutReplaced {
public:
LayoutSVG(DOM::Document&, const SVG::SVGSVGElement&, NonnullRefPtr<StyleProperties>);
LayoutSVG(DOM::Document&, const SVG::SVGSVGElement&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutSVG() override = default;
virtual void layout(LayoutMode = LayoutMode::Default) override;
virtual void paint(PaintContext&, PaintPhase) override;

View File

@ -51,16 +51,16 @@ public:
CSS::TextAlign text_align() const { return m_text_align; }
CSS::Position position() const { return m_position; }
CSS::WhiteSpace white_space() const { return m_white_space; }
const Length& width() const { return m_width; }
const Length& min_width() const { return m_min_width; }
const Length& max_width() const { return m_max_width; }
const Length& height() const { return m_height; }
const Length& min_height() const { return m_min_height; }
const Length& max_height() const { return m_max_height; }
const CSS::Length& width() const { return m_width; }
const CSS::Length& min_width() const { return m_min_width; }
const CSS::Length& max_width() const { return m_max_width; }
const CSS::Length& height() const { return m_height; }
const CSS::Length& min_height() const { return m_min_height; }
const CSS::Length& max_height() const { return m_max_height; }
const LengthBox& offset() const { return m_offset; }
const LengthBox& margin() const { return m_margin; }
const LengthBox& padding() const { return m_padding; }
const CSS::LengthBox& offset() const { return m_offset; }
const CSS::LengthBox& margin() const { return m_margin; }
const CSS::LengthBox& padding() const { return m_padding; }
const BorderData& border_left() const { return m_border_left; }
const BorderData& border_top() const { return m_border_top; }
@ -73,15 +73,15 @@ protected:
CSS::TextAlign m_text_align;
CSS::Position m_position;
CSS::WhiteSpace m_white_space { InitialValues::white_space() };
Length m_width;
Length m_min_width;
Length m_max_width;
Length m_height;
Length m_min_height;
Length m_max_height;
LengthBox m_offset;
LengthBox m_margin;
LengthBox m_padding;
CSS::Length m_width;
CSS::Length m_min_width;
CSS::Length m_max_width;
CSS::Length m_height;
CSS::Length m_min_height;
CSS::Length m_max_height;
CSS::LengthBox m_offset;
CSS::LengthBox m_margin;
CSS::LengthBox m_padding;
BorderData m_border_left;
BorderData m_border_top;
BorderData m_border_right;
@ -98,15 +98,15 @@ public:
void set_text_align(CSS::TextAlign text_align) { m_text_align = text_align; }
void set_position(CSS::Position position) { m_position = position; }
void set_white_space(CSS::WhiteSpace value) { m_white_space = value; }
void set_width(const Length& width) { m_width = width; }
void set_min_width(const Length& width) { m_min_width = width; }
void set_max_width(const Length& width) { m_max_width = width; }
void set_height(const Length& height) { m_height = height; }
void set_min_height(const Length& height) { m_min_height = height; }
void set_max_height(const Length& height) { m_max_height = height; }
void set_offset(const LengthBox& offset) { m_offset = offset; }
void set_margin(const LengthBox& margin) { m_margin = margin; }
void set_padding(const LengthBox& padding) { m_padding = padding; }
void set_width(const CSS::Length& width) { m_width = width; }
void set_min_width(const CSS::Length& width) { m_min_width = width; }
void set_max_width(const CSS::Length& width) { m_max_width = width; }
void set_height(const CSS::Length& height) { m_height = height; }
void set_min_height(const CSS::Length& height) { m_min_height = height; }
void set_max_height(const CSS::Length& height) { m_max_height = height; }
void set_offset(const CSS::LengthBox& offset) { m_offset = offset; }
void set_margin(const CSS::LengthBox& margin) { m_margin = margin; }
void set_padding(const CSS::LengthBox& padding) { m_padding = padding; }
BorderData& border_left() { return m_border_left; }
BorderData& border_top() { return m_border_top; }
BorderData& border_right() { return m_border_right; }

View File

@ -30,7 +30,7 @@
namespace Web {
LayoutTable::LayoutTable(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
LayoutTable::LayoutTable(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutBlock(document, &element, move(style))
{
}

View File

@ -34,7 +34,7 @@ class LayoutTableRow;
class LayoutTable final : public LayoutBlock {
public:
LayoutTable(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
LayoutTable(DOM::Document&, const DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutTable() override;
virtual void layout(LayoutMode = LayoutMode::Default) override;

View File

@ -30,7 +30,7 @@
namespace Web {
LayoutTableCell::LayoutTableCell(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
LayoutTableCell::LayoutTableCell(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutBlock(document, &element, move(style))
{
}

View File

@ -32,7 +32,7 @@ namespace Web {
class LayoutTableCell final : public LayoutBlock {
public:
LayoutTableCell(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
LayoutTableCell(DOM::Document&, const DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutTableCell() override;
LayoutTableCell* next_cell() { return next_sibling_of_type<LayoutTableCell>(); }

View File

@ -31,7 +31,7 @@
namespace Web {
LayoutTableRow::LayoutTableRow(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
LayoutTableRow::LayoutTableRow(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutBox(document, &element, move(style))
{
}

View File

@ -34,7 +34,7 @@ class LayoutTableCell;
class LayoutTableRow final : public LayoutBox {
public:
LayoutTableRow(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
LayoutTableRow(DOM::Document&, const DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutTableRow() override;
void layout_row(const Vector<float>& column_widths);

View File

@ -31,7 +31,7 @@
namespace Web {
LayoutTableRowGroup::LayoutTableRowGroup(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<StyleProperties> style)
LayoutTableRowGroup::LayoutTableRowGroup(DOM::Document& document, const DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
: LayoutBlock(document, &element, move(style))
{
}

View File

@ -32,7 +32,7 @@ namespace Web {
class LayoutTableRowGroup final : public LayoutBlock {
public:
LayoutTableRowGroup(DOM::Document&, const DOM::Element&, NonnullRefPtr<StyleProperties>);
LayoutTableRowGroup(DOM::Document&, const DOM::Element&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~LayoutTableRowGroup() override;
virtual void layout(LayoutMode = LayoutMode::Default) override;

View File

@ -55,7 +55,7 @@ static bool is_all_whitespace(const StringView& string)
return true;
}
const String& LayoutText::text_for_style(const StyleProperties& style) const
const String& LayoutText::text_for_style(const CSS::StyleProperties& style) const
{
static String one_space = " ";
if (is_all_whitespace(node().data())) {

View File

@ -40,7 +40,7 @@ public:
const DOM::Text& node() const { return static_cast<const DOM::Text&>(*LayoutNode::node()); }
const String& text_for_style(const StyleProperties&) const;
const String& text_for_style(const CSS::StyleProperties&) const;
const String& text_for_rendering() const { return m_text_for_rendering; }
virtual const char* class_name() const override { return "LayoutText"; }
@ -50,7 +50,7 @@ public:
virtual void split_into_lines(LayoutBlock& container, LayoutMode) override;
const StyleProperties& specified_style() const { return parent()->specified_style(); }
const CSS::StyleProperties& specified_style() const { return parent()->specified_style(); }
private:
void split_into_lines_by_rules(LayoutBlock& container, LayoutMode, bool do_collapse, bool do_wrap_lines, bool do_wrap_breaks);

View File

@ -37,7 +37,7 @@ LayoutTreeBuilder::LayoutTreeBuilder()
{
}
static RefPtr<LayoutNode> create_layout_tree(DOM::Node& node, const StyleProperties* parent_style)
static RefPtr<LayoutNode> create_layout_tree(DOM::Node& node, const CSS::StyleProperties* parent_style)
{
auto layout_node = node.create_layout_node(parent_style);
if (!layout_node)

View File

@ -37,7 +37,7 @@
namespace Web {
LayoutWidget::LayoutWidget(DOM::Document& document, const DOM::Element& element, GUI::Widget& widget)
: LayoutReplaced(document, element, StyleProperties::create())
: LayoutReplaced(document, element, CSS::StyleProperties::create())
, m_widget(widget)
{
set_has_intrinsic_width(true);

View File

@ -264,31 +264,31 @@ static Optional<float> try_parse_float(const StringView& string)
return is_negative ? -value : value;
}
static Length parse_length(const CSS::ParsingContext& context, const StringView& view, bool& is_bad_length)
static CSS::Length parse_length(const CSS::ParsingContext& context, const StringView& view, bool& is_bad_length)
{
Length::Type type = Length::Type::Undefined;
CSS::Length::Type type = CSS::Length::Type::Undefined;
Optional<float> value;
if (view.ends_with('%')) {
type = Length::Type::Percentage;
type = CSS::Length::Type::Percentage;
value = try_parse_float(view.substring_view(0, view.length() - 1));
} else if (view.to_string().to_lowercase().ends_with("px")) {
type = Length::Type::Px;
type = CSS::Length::Type::Px;
value = try_parse_float(view.substring_view(0, view.length() - 2));
} else if (view.to_string().to_lowercase().ends_with("pt")) {
type = Length::Type::Pt;
type = CSS::Length::Type::Pt;
value = try_parse_float(view.substring_view(0, view.length() - 2));
} else if (view.to_string().to_lowercase().ends_with("rem")) {
type = Length::Type::Rem;
type = CSS::Length::Type::Rem;
value = try_parse_float(view.substring_view(0, view.length() - 3));
} else if (view.to_string().to_lowercase().ends_with("em")) {
type = Length::Type::Em;
type = CSS::Length::Type::Em;
value = try_parse_float(view.substring_view(0, view.length() - 2));
} else if (view == "0") {
type = Length::Type::Px;
type = CSS::Length::Type::Px;
value = 0;
} else if (context.in_quirks_mode()) {
type = Length::Type::Px;
type = CSS::Length::Type::Px;
value = try_parse_float(view);
} else {
value = try_parse_float(view);
@ -299,61 +299,61 @@ static Length parse_length(const CSS::ParsingContext& context, const StringView&
if (!value.has_value())
return {};
return Length(value.value(), type);
return CSS::Length(value.value(), type);
}
RefPtr<StyleValue> parse_css_value(const CSS::ParsingContext& context, const StringView& string)
RefPtr<CSS::StyleValue> parse_css_value(const CSS::ParsingContext& context, const StringView& string)
{
bool is_bad_length = false;
auto length = parse_length(context, string, is_bad_length);
if (is_bad_length)
return nullptr;
if (!length.is_undefined())
return LengthStyleValue::create(length);
return CSS::LengthStyleValue::create(length);
if (string.equals_ignoring_case("inherit"))
return InheritStyleValue::create();
return CSS::InheritStyleValue::create();
if (string.equals_ignoring_case("initial"))
return InitialStyleValue::create();
return CSS::InitialStyleValue::create();
if (string.equals_ignoring_case("auto"))
return LengthStyleValue::create(Length::make_auto());
return CSS::LengthStyleValue::create(CSS::Length::make_auto());
auto color = parse_css_color(context, string);
if (color.has_value())
return ColorStyleValue::create(color.value());
return CSS::ColorStyleValue::create(color.value());
if (string == "-libweb-link")
return IdentifierStyleValue::create(CSS::ValueID::VendorSpecificLink);
return CSS::IdentifierStyleValue::create(CSS::ValueID::VendorSpecificLink);
else if (string.starts_with("-libweb-palette-")) {
auto value_id = value_id_for_palette_string(string.substring_view(16, string.length() - 16));
return IdentifierStyleValue::create(value_id);
return CSS::IdentifierStyleValue::create(value_id);
}
return StringStyleValue::create(string);
return CSS::StringStyleValue::create(string);
}
RefPtr<LengthStyleValue> parse_line_width(const CSS::ParsingContext& context, const StringView& part)
RefPtr<CSS::LengthStyleValue> parse_line_width(const CSS::ParsingContext& context, const StringView& part)
{
auto value = parse_css_value(context, part);
if (value && value->is_length())
return static_ptr_cast<LengthStyleValue>(value);
return static_ptr_cast<CSS::LengthStyleValue>(value);
return nullptr;
}
RefPtr<ColorStyleValue> parse_color(const CSS::ParsingContext& context, const StringView& part)
RefPtr<CSS::ColorStyleValue> parse_color(const CSS::ParsingContext& context, const StringView& part)
{
auto value = parse_css_value(context, part);
if (value && value->is_color())
return static_ptr_cast<ColorStyleValue>(value);
return static_ptr_cast<CSS::ColorStyleValue>(value);
return nullptr;
}
RefPtr<StringStyleValue> parse_line_style(const CSS::ParsingContext& context, const StringView& part)
RefPtr<CSS::StringStyleValue> parse_line_style(const CSS::ParsingContext& context, const StringView& part)
{
auto parsed_value = parse_css_value(context, part);
if (!parsed_value || !parsed_value->is_string())
return nullptr;
auto value = static_ptr_cast<StringStyleValue>(parsed_value);
auto value = static_ptr_cast<CSS::StringStyleValue>(parsed_value);
if (value->to_string() == "dotted")
return value;
if (value->to_string() == "dashed")
@ -448,7 +448,7 @@ public:
return ch == '~' || ch == '>' || ch == '+';
}
Optional<Selector::SimpleSelector> parse_simple_selector()
Optional<CSS::Selector::SimpleSelector> parse_simple_selector()
{
auto index_at_start = index;
@ -458,34 +458,34 @@ public:
if (!peek() || peek() == '{' || peek() == ',' || is_combinator(peek()))
return {};
Selector::SimpleSelector::Type type;
CSS::Selector::SimpleSelector::Type type;
if (peek() == '*') {
type = Selector::SimpleSelector::Type::Universal;
type = CSS::Selector::SimpleSelector::Type::Universal;
consume_one();
return Selector::SimpleSelector {
return CSS::Selector::SimpleSelector {
type,
Selector::SimpleSelector::PseudoClass::None,
CSS::Selector::SimpleSelector::PseudoClass::None,
String(),
Selector::SimpleSelector::AttributeMatchType::None,
CSS::Selector::SimpleSelector::AttributeMatchType::None,
String(),
String()
};
}
if (peek() == '.') {
type = Selector::SimpleSelector::Type::Class;
type = CSS::Selector::SimpleSelector::Type::Class;
consume_one();
} else if (peek() == '#') {
type = Selector::SimpleSelector::Type::Id;
type = CSS::Selector::SimpleSelector::Type::Id;
consume_one();
} else if (isalpha(peek())) {
type = Selector::SimpleSelector::Type::TagName;
type = CSS::Selector::SimpleSelector::Type::TagName;
} else {
type = Selector::SimpleSelector::Type::Universal;
type = CSS::Selector::SimpleSelector::Type::Universal;
}
if (type != Selector::SimpleSelector::Type::Universal) {
if (type != CSS::Selector::SimpleSelector::Type::Universal) {
while (is_valid_selector_char(peek()))
buffer.append(consume_one());
PARSE_ASSERT(!buffer.is_null());
@ -493,23 +493,23 @@ public:
auto value = String::copy(buffer);
if (type == Selector::SimpleSelector::Type::TagName) {
if (type == CSS::Selector::SimpleSelector::Type::TagName) {
// Some stylesheets use uppercase tag names, so here's a hack to just lowercase them internally.
value = value.to_lowercase();
}
Selector::SimpleSelector simple_selector {
CSS::Selector::SimpleSelector simple_selector {
type,
Selector::SimpleSelector::PseudoClass::None,
CSS::Selector::SimpleSelector::PseudoClass::None,
value,
Selector::SimpleSelector::AttributeMatchType::None,
CSS::Selector::SimpleSelector::AttributeMatchType::None,
String(),
String()
};
buffer.clear();
if (peek() == '[') {
Selector::SimpleSelector::AttributeMatchType attribute_match_type = Selector::SimpleSelector::AttributeMatchType::HasAttribute;
CSS::Selector::SimpleSelector::AttributeMatchType attribute_match_type = CSS::Selector::SimpleSelector::AttributeMatchType::HasAttribute;
String attribute_name;
String attribute_value;
bool in_value = false;
@ -519,10 +519,10 @@ public:
char ch = consume_one();
if (ch == '=' || (ch == '~' && peek() == '=')) {
if (ch == '=') {
attribute_match_type = Selector::SimpleSelector::AttributeMatchType::ExactValueMatch;
attribute_match_type = CSS::Selector::SimpleSelector::AttributeMatchType::ExactValueMatch;
} else if (ch == '~') {
consume_one();
attribute_match_type = Selector::SimpleSelector::AttributeMatchType::Contains;
attribute_match_type = CSS::Selector::SimpleSelector::AttributeMatchType::Contains;
}
attribute_name = String::copy(buffer);
buffer.clear();
@ -586,23 +586,23 @@ public:
return {};
if (pseudo_name.equals_ignoring_case("link"))
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Link;
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Link;
else if (pseudo_name.equals_ignoring_case("visited"))
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Visited;
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Visited;
else if (pseudo_name.equals_ignoring_case("hover"))
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Hover;
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Hover;
else if (pseudo_name.equals_ignoring_case("focus"))
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Focus;
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Focus;
else if (pseudo_name.equals_ignoring_case("first-child"))
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::FirstChild;
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::FirstChild;
else if (pseudo_name.equals_ignoring_case("last-child"))
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::LastChild;
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::LastChild;
else if (pseudo_name.equals_ignoring_case("only-child"))
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::OnlyChild;
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::OnlyChild;
else if (pseudo_name.equals_ignoring_case("empty"))
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Empty;
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Empty;
else if (pseudo_name.equals_ignoring_case("root"))
simple_selector.pseudo_class = Selector::SimpleSelector::PseudoClass::Root;
simple_selector.pseudo_class = CSS::Selector::SimpleSelector::PseudoClass::Root;
}
if (index == index_at_start) {
@ -613,9 +613,9 @@ public:
return simple_selector;
}
Optional<Selector::ComplexSelector> parse_complex_selector()
Optional<CSS::Selector::ComplexSelector> parse_complex_selector()
{
auto relation = Selector::ComplexSelector::Relation::Descendant;
auto relation = CSS::Selector::ComplexSelector::Relation::Descendant;
if (peek() == '{' || peek() == ',')
return {};
@ -623,13 +623,13 @@ public:
if (is_combinator(peek())) {
switch (peek()) {
case '>':
relation = Selector::ComplexSelector::Relation::ImmediateChild;
relation = CSS::Selector::ComplexSelector::Relation::ImmediateChild;
break;
case '+':
relation = Selector::ComplexSelector::Relation::AdjacentSibling;
relation = CSS::Selector::ComplexSelector::Relation::AdjacentSibling;
break;
case '~':
relation = Selector::ComplexSelector::Relation::GeneralSibling;
relation = CSS::Selector::ComplexSelector::Relation::GeneralSibling;
break;
}
consume_one();
@ -638,7 +638,7 @@ public:
consume_whitespace_or_comments();
Vector<Selector::SimpleSelector> simple_selectors;
Vector<CSS::Selector::SimpleSelector> simple_selectors;
for (;;) {
auto component = parse_simple_selector();
if (!component.has_value())
@ -651,12 +651,12 @@ public:
if (simple_selectors.is_empty())
return {};
return Selector::ComplexSelector { relation, move(simple_selectors) };
return CSS::Selector::ComplexSelector { relation, move(simple_selectors) };
}
void parse_selector()
{
Vector<Selector::ComplexSelector> complex_selectors;
Vector<CSS::Selector::ComplexSelector> complex_selectors;
for (;;) {
auto index_before = index;
@ -673,12 +673,12 @@ public:
if (complex_selectors.is_empty())
return;
complex_selectors.first().relation = Selector::ComplexSelector::Relation::None;
complex_selectors.first().relation = CSS::Selector::ComplexSelector::Relation::None;
current_rule.selectors.append(Selector(move(complex_selectors)));
current_rule.selectors.append(CSS::Selector(move(complex_selectors)));
}
Optional<Selector> parse_individual_selector()
Optional<CSS::Selector> parse_individual_selector()
{
parse_selector();
if (current_rule.selectors.is_empty())
@ -785,7 +785,7 @@ public:
return { string, important };
}
Optional<StyleProperty> parse_property()
Optional<CSS::StyleProperty> parse_property()
{
consume_whitespace_or_comments();
if (peek() == ';') {
@ -817,7 +817,7 @@ public:
auto value = parse_css_value(m_context, property_value);
if (!value)
return {};
return StyleProperty { property_id, value.release_nonnull(), important };
return CSS::StyleProperty { property_id, value.release_nonnull(), important };
}
void parse_declaration()
@ -861,20 +861,20 @@ public:
consume_specific('{');
parse_declaration();
consume_specific('}');
rules.append(StyleRule::create(move(current_rule.selectors), StyleDeclaration::create(move(current_rule.properties))));
rules.append(CSS::StyleRule::create(move(current_rule.selectors), CSS::StyleDeclaration::create(move(current_rule.properties))));
consume_whitespace_or_comments();
}
RefPtr<StyleSheet> parse_sheet()
RefPtr<CSS::StyleSheet> parse_sheet()
{
while (index < css.length()) {
parse_rule();
}
return StyleSheet::create(move(rules));
return CSS::StyleSheet::create(move(rules));
}
RefPtr<StyleDeclaration> parse_standalone_declaration()
RefPtr<CSS::StyleDeclaration> parse_standalone_declaration()
{
consume_whitespace_or_comments();
for (;;) {
@ -885,17 +885,17 @@ public:
if (!peek())
break;
}
return StyleDeclaration::create(move(current_rule.properties));
return CSS::StyleDeclaration::create(move(current_rule.properties));
}
private:
CSS::ParsingContext m_context;
NonnullRefPtrVector<StyleRule> rules;
NonnullRefPtrVector<CSS::StyleRule> rules;
struct CurrentRule {
Vector<Selector> selectors;
Vector<StyleProperty> properties;
Vector<CSS::Selector> selectors;
Vector<CSS::StyleProperty> properties;
};
CurrentRule current_rule;
@ -906,33 +906,33 @@ private:
StringView css;
};
Optional<Selector> parse_selector(const CSS::ParsingContext& context, const StringView& selector_text)
Optional<CSS::Selector> parse_selector(const CSS::ParsingContext& context, const StringView& selector_text)
{
CSSParser parser(context, selector_text);
return parser.parse_individual_selector();
}
RefPtr<StyleSheet> parse_css(const CSS::ParsingContext& context, const StringView& css)
RefPtr<CSS::StyleSheet> parse_css(const CSS::ParsingContext& context, const StringView& css)
{
if (css.is_empty())
return StyleSheet::create({});
return CSS::StyleSheet::create({});
CSSParser parser(context, css);
return parser.parse_sheet();
}
RefPtr<StyleDeclaration> parse_css_declaration(const CSS::ParsingContext& context, const StringView& css)
RefPtr<CSS::StyleDeclaration> parse_css_declaration(const CSS::ParsingContext& context, const StringView& css)
{
if (css.is_empty())
return StyleDeclaration::create({});
return CSS::StyleDeclaration::create({});
CSSParser parser(context, css);
return parser.parse_standalone_declaration();
}
RefPtr<StyleValue> parse_html_length(const DOM::Document& document, const StringView& string)
RefPtr<CSS::StyleValue> parse_html_length(const DOM::Document& document, const StringView& string)
{
auto integer = string.to_int();
if (integer.has_value())
return LengthStyleValue::create(Length::make_px(integer.value()));
return CSS::LengthStyleValue::create(CSS::Length::make_px(integer.value()));
return parse_css_value(CSS::ParsingContext(document), string);
}

View File

@ -44,15 +44,15 @@ private:
namespace Web {
RefPtr<StyleSheet> parse_css(const CSS::ParsingContext&, const StringView&);
RefPtr<StyleDeclaration> parse_css_declaration(const CSS::ParsingContext&, const StringView&);
RefPtr<StyleValue> parse_css_value(const CSS::ParsingContext&, const StringView&);
Optional<Selector> parse_selector(const CSS::ParsingContext&, const StringView&);
RefPtr<CSS::StyleSheet> parse_css(const CSS::ParsingContext&, const StringView&);
RefPtr<CSS::StyleDeclaration> parse_css_declaration(const CSS::ParsingContext&, const StringView&);
RefPtr<CSS::StyleValue> parse_css_value(const CSS::ParsingContext&, const StringView&);
Optional<CSS::Selector> parse_selector(const CSS::ParsingContext&, const StringView&);
RefPtr<LengthStyleValue> parse_line_width(const CSS::ParsingContext&, const StringView&);
RefPtr<ColorStyleValue> parse_color(const CSS::ParsingContext&, const StringView&);
RefPtr<StringStyleValue> parse_line_style(const CSS::ParsingContext&, const StringView&);
RefPtr<CSS::LengthStyleValue> parse_line_width(const CSS::ParsingContext&, const StringView&);
RefPtr<CSS::ColorStyleValue> parse_color(const CSS::ParsingContext&, const StringView&);
RefPtr<CSS::StringStyleValue> parse_line_style(const CSS::ParsingContext&, const StringView&);
RefPtr<StyleValue> parse_html_length(const DOM::Document&, const StringView&);
RefPtr<CSS::StyleValue> parse_html_length(const DOM::Document&, const StringView&);
}

View File

@ -43,7 +43,7 @@ SVGSVGElement::SVGSVGElement(DOM::Document& document, const FlyString& tag_name)
{
}
RefPtr<LayoutNode> SVGSVGElement::create_layout_node(const StyleProperties* parent_style)
RefPtr<LayoutNode> SVGSVGElement::create_layout_node(const CSS::StyleProperties* parent_style)
{
auto style = document().style_resolver().resolve_style(*this, parent_style);
if (style->display() == CSS::Display::None)

View File

@ -35,7 +35,7 @@ class SVGSVGElement final : public SVGGraphicsElement {
public:
SVGSVGElement(DOM::Document&, const FlyString& tag_name);
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
virtual RefPtr<LayoutNode> create_layout_node(const CSS::StyleProperties* parent_style) override;
const RefPtr<Gfx::Bitmap> bitmap() const { return m_bitmap; }
bool create_bitmap_as_top_level_svg_element();

View File

@ -1,6 +1,6 @@
#!/bin/sh
echo "namespace Web {"
echo "namespace Web::CSS {"
echo "extern const char $1[];"
echo "const char $1[] = \"\\"
grep -v '^ *#' < "$2" | while IFS= read -r line; do

View File

@ -32,7 +32,7 @@
namespace Web {
StylePropertiesModel::StylePropertiesModel(const StyleProperties& properties)
StylePropertiesModel::StylePropertiesModel(const CSS::StyleProperties& properties)
: m_properties(properties)
{
properties.for_each_property([&](auto property_id, auto& property_value) {

View File

@ -41,7 +41,7 @@ public:
__Count
};
static NonnullRefPtr<StylePropertiesModel> create(const StyleProperties& properties) { return adopt(*new StylePropertiesModel(properties)); }
static NonnullRefPtr<StylePropertiesModel> create(const CSS::StyleProperties& properties) { return adopt(*new StylePropertiesModel(properties)); }
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return Column::__Count; }
@ -50,10 +50,10 @@ public:
virtual void update() override;
private:
explicit StylePropertiesModel(const StyleProperties& properties);
const StyleProperties& properties() const { return *m_properties; }
explicit StylePropertiesModel(const CSS::StyleProperties& properties);
const CSS::StyleProperties& properties() const { return *m_properties; }
NonnullRefPtr<StyleProperties> m_properties;
NonnullRefPtr<CSS::StyleProperties> m_properties;
struct Value {
String name;