1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

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

LibWeb keeps growing and the Web namespace is filling up fast.
Let's put DOM stuff into Web::DOM, just like we already started doing
with SVG stuff in Web::SVG.
This commit is contained in:
Andreas Kling 2020-07-26 19:37:56 +02:00
parent 96d13f75cf
commit 11ff9d0f17
178 changed files with 516 additions and 523 deletions

View file

@ -34,7 +34,7 @@ namespace Web {
namespace SelectorEngine {
static bool matches_hover_pseudo_class(const Element& element)
static bool matches_hover_pseudo_class(const DOM::Element& element)
{
auto* hovered_node = element.document().hovered_node();
if (!hovered_node)
@ -44,7 +44,7 @@ static bool matches_hover_pseudo_class(const Element& element)
return element.is_ancestor_of(*hovered_node);
}
bool matches(const Selector::SimpleSelector& component, const Element& element)
bool matches(const Selector::SimpleSelector& component, const DOM::Element& element)
{
switch (component.pseudo_class) {
case Selector::SimpleSelector::PseudoClass::None:
@ -76,7 +76,7 @@ bool matches(const Selector::SimpleSelector& component, const Element& element)
return false;
break;
case Selector::SimpleSelector::PseudoClass::Empty:
if (element.first_child_of_type<Element>() || element.first_child_of_type<Text>())
if (element.first_child_of_type<DOM::Element>() || element.first_child_of_type<DOM::Text>())
return false;
break;
case Selector::SimpleSelector::PseudoClass::Root:
@ -116,7 +116,7 @@ bool matches(const Selector::SimpleSelector& component, const Element& element)
}
}
bool matches(const Selector& selector, int component_list_index, const Element& element)
bool matches(const 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) {
@ -129,17 +129,17 @@ bool matches(const Selector& selector, int component_list_index, const Element&
case Selector::ComplexSelector::Relation::Descendant:
ASSERT(component_list_index != 0);
for (auto* ancestor = element.parent(); ancestor; ancestor = ancestor->parent()) {
if (!is<Element>(*ancestor))
if (!is<DOM::Element>(*ancestor))
continue;
if (matches(selector, component_list_index - 1, downcast<Element>(*ancestor)))
if (matches(selector, component_list_index - 1, downcast<DOM::Element>(*ancestor)))
return true;
}
return false;
case Selector::ComplexSelector::Relation::ImmediateChild:
ASSERT(component_list_index != 0);
if (!element.parent() || !is<Element>(*element.parent()))
if (!element.parent() || !is<DOM::Element>(*element.parent()))
return false;
return matches(selector, component_list_index - 1, downcast<Element>(*element.parent()));
return matches(selector, component_list_index - 1, downcast<DOM::Element>(*element.parent()));
case Selector::ComplexSelector::Relation::AdjacentSibling:
ASSERT(component_list_index != 0);
if (auto* sibling = element.previous_element_sibling())
@ -156,7 +156,7 @@ bool matches(const Selector& selector, int component_list_index, const Element&
ASSERT_NOT_REACHED();
}
bool matches(const Selector& selector, const Element& element)
bool matches(const Selector& selector, const DOM::Element& element)
{
ASSERT(!selector.complex_selectors().is_empty());
return matches(selector, selector.complex_selectors().size() - 1, element);

View file

@ -27,15 +27,10 @@
#pragma once
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/DOM/Element.h>
namespace Web {
namespace Web::SelectorEngine {
class Element;
namespace SelectorEngine {
bool matches(const Selector&, const Element&);
}
bool matches(const Selector&, const DOM::Element&);
}

View file

@ -94,7 +94,7 @@ String StyleProperties::string_or_fallback(CSS::PropertyID id, const StringView&
return value.value()->to_string();
}
Color StyleProperties::color_or_fallback(CSS::PropertyID id, const Document& document, Color fallback) const
Color StyleProperties::color_or_fallback(CSS::PropertyID id, const DOM::Document& document, Color fallback) const
{
auto value = property(id);
if (!value.has_value())

View file

@ -59,7 +59,7 @@ public:
Length length_or_fallback(CSS::PropertyID, const Length& fallback) const;
LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id) const;
String string_or_fallback(CSS::PropertyID, const StringView& fallback) const;
Color color_or_fallback(CSS::PropertyID, const Document&, Color fallback) const;
Color color_or_fallback(CSS::PropertyID, const DOM::Document&, Color fallback) const;
CSS::TextAlign text_align() const;
CSS::Display display() const;
Optional<CSS::Float> float_() const;

View file

@ -37,7 +37,7 @@
namespace Web {
StyleResolver::StyleResolver(Document& document)
StyleResolver::StyleResolver(DOM::Document& document)
: m_document(document)
{
}
@ -66,7 +66,7 @@ void StyleResolver::for_each_stylesheet(Callback callback) const
}
}
Vector<MatchingRule> StyleResolver::collect_matching_rules(const Element& element) const
Vector<MatchingRule> StyleResolver::collect_matching_rules(const DOM::Element& element) const
{
Vector<MatchingRule> matching_rules;
@ -203,7 +203,7 @@ static inline void set_property_border_style(StyleProperties& style, const Style
style.set_property(CSS::PropertyID::BorderLeftStyle, value);
}
static void set_property_expanding_shorthands(StyleProperties& style, CSS::PropertyID property_id, const StyleValue& value, Document& document)
static void set_property_expanding_shorthands(StyleProperties& style, CSS::PropertyID property_id, const StyleValue& value, DOM::Document& document)
{
CSS::ParsingContext context(document);
@ -519,7 +519,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
style.set_property(property_id, value);
}
NonnullRefPtr<StyleProperties> StyleResolver::resolve_style(const Element& element, const StyleProperties* parent_style) const
NonnullRefPtr<StyleProperties> StyleResolver::resolve_style(const DOM::Element& element, const StyleProperties* parent_style) const
{
auto style = StyleProperties::create();

View file

@ -29,15 +29,10 @@
#include <AK/NonnullRefPtrVector.h>
#include <AK/OwnPtr.h>
#include <LibWeb/CSS/StyleProperties.h>
#include <LibWeb/Forward.h>
namespace Web {
class Document;
class Element;
class ParentNode;
class StyleRule;
class StyleSheet;
struct MatchingRule {
RefPtr<StyleRule> rule;
size_t style_sheet_index { 0 };
@ -47,15 +42,15 @@ struct MatchingRule {
class StyleResolver {
public:
explicit StyleResolver(Document&);
explicit StyleResolver(DOM::Document&);
~StyleResolver();
Document& document() { return m_document; }
const Document& document() const { return m_document; }
DOM::Document& document() { return m_document; }
const DOM::Document& document() const { return m_document; }
NonnullRefPtr<StyleProperties> resolve_style(const Element&, const StyleProperties* parent_style) const;
NonnullRefPtr<StyleProperties> resolve_style(const DOM::Element&, const StyleProperties* parent_style) const;
Vector<MatchingRule> collect_matching_rules(const Element&) const;
Vector<MatchingRule> collect_matching_rules(const DOM::Element&) const;
static bool is_inherited_property(CSS::PropertyID);
@ -63,7 +58,7 @@ private:
template<typename Callback>
void for_each_stylesheet(Callback) const;
Document& m_document;
DOM::Document& m_document;
};
}

View file

@ -33,7 +33,7 @@ void StyleSheetList::add_sheet(NonnullRefPtr<StyleSheet> sheet)
m_sheets.append(move(sheet));
}
StyleSheetList::StyleSheetList(Document& document)
StyleSheetList::StyleSheetList(DOM::Document& document)
: m_document(document)
{
}

View file

@ -33,7 +33,7 @@ namespace Web::CSS {
class StyleSheetList : public RefCounted<StyleSheetList> {
public:
static NonnullRefPtr<StyleSheetList> create(Document& document)
static NonnullRefPtr<StyleSheetList> create(DOM::Document& document)
{
return adopt(*new StyleSheetList(document));
}
@ -43,9 +43,9 @@ public:
const NonnullRefPtrVector<StyleSheet>& sheets() const { return m_sheets; }
private:
explicit StyleSheetList(Document&);
explicit StyleSheetList(DOM::Document&);
Document& m_document;
DOM::Document& m_document;
NonnullRefPtrVector<StyleSheet> m_sheets;
};

View file

@ -167,7 +167,7 @@ String IdentifierStyleValue::to_string() const
}
}
Color IdentifierStyleValue::to_color(const Document& document) const
Color IdentifierStyleValue::to_color(const DOM::Document& document) const
{
if (id() == CSS::ValueID::VendorSpecificLink)
return document.link_color();
@ -287,7 +287,7 @@ Color IdentifierStyleValue::to_color(const Document& document) const
}
}
ImageStyleValue::ImageStyleValue(const URL& url, Document& document)
ImageStyleValue::ImageStyleValue(const URL& url, DOM::Document& document)
: StyleValue(Type::Image)
, m_url(url)
, m_document(document.make_weak_ptr())

View file

@ -182,7 +182,7 @@ public:
virtual String to_string() const = 0;
virtual Length to_length() const { return Length::make_auto(); }
virtual Color to_color(const Document&) const { return {}; }
virtual Color to_color(const DOM::Document&) const { return {}; }
virtual bool is_auto() const { return false; }
@ -276,7 +276,7 @@ public:
Color color() const { return m_color; }
String to_string() const override { return m_color.to_string(); }
Color to_color(const Document&) const override { return m_color; }
Color to_color(const DOM::Document&) const override { return m_color; }
private:
explicit ColorStyleValue(Color color)
@ -299,7 +299,7 @@ public:
CSS::ValueID id() const { return m_id; }
virtual String to_string() const override;
virtual Color to_color(const Document&) const override;
virtual Color to_color(const DOM::Document&) const override;
private:
explicit IdentifierStyleValue(CSS::ValueID id)
@ -315,7 +315,7 @@ class ImageStyleValue final
: public StyleValue
, public ImageResourceClient {
public:
static NonnullRefPtr<ImageStyleValue> create(const URL& url, Document& document) { return adopt(*new ImageStyleValue(url, document)); }
static NonnullRefPtr<ImageStyleValue> create(const URL& url, DOM::Document& document) { return adopt(*new ImageStyleValue(url, document)); }
virtual ~ImageStyleValue() override { }
String to_string() const override { return String::format("Image{%s}", m_url.to_string().characters()); }
@ -323,13 +323,13 @@ public:
const Gfx::Bitmap* bitmap() const { return m_bitmap; }
private:
ImageStyleValue(const URL&, Document&);
ImageStyleValue(const URL&, DOM::Document&);
// ^ResourceClient
virtual void resource_did_load() override;
URL m_url;
WeakPtr<Document> m_document;
WeakPtr<DOM::Document> m_document;
RefPtr<Gfx::Bitmap> m_bitmap;
};