mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +00:00
LibWeb: Switch to using AK::is and AK::downcast
This commit is contained in:
parent
fe6474e692
commit
71556e39a4
73 changed files with 249 additions and 433 deletions
|
@ -39,10 +39,8 @@ public:
|
|||
String target() const { return attribute(HTML::AttributeNames::target); }
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLAnchorElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::a;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLAnchorElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_element() && downcast<Web::Element>(node).local_name() == Web::HTML::TagNames::a; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -38,10 +38,8 @@ public:
|
|||
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) override;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLBRElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::br;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLBRElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_element() && downcast<Web::Element>(node).local_name() == Web::HTML::TagNames::br; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -42,10 +42,8 @@ private:
|
|||
NonnullRefPtr<Core::Timer> m_timer;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLBlinkElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::blink;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLBlinkElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_element() && downcast<Web::Element>(node).local_name() == Web::HTML::TagNames::blink; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -42,10 +42,8 @@ private:
|
|||
RefPtr<ImageStyleValue> m_background_style_value;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLBodyElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::body;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLBodyElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_element() && downcast<Web::Element>(node).local_name() == Web::HTML::TagNames::body; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -57,10 +57,8 @@ private:
|
|||
RefPtr<CanvasRenderingContext2D> m_context;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLCanvasElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::canvas;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLCanvasElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_element() && downcast<Web::Element>(node).local_name() == Web::HTML::TagNames::canvas; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -43,10 +43,8 @@ private:
|
|||
virtual bool is_html_element() const final { return true; }
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLElement>(const Node& node)
|
||||
{
|
||||
return node.is_html_element();
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element(); }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -38,10 +38,8 @@ public:
|
|||
virtual void apply_presentational_hints(StyleProperties&) const override;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLFontElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::font;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLFontElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_element() && downcast<Web::Element>(node).local_name() == Web::HTML::TagNames::font; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -63,7 +63,7 @@ void HTMLFormElement::submit(RefPtr<HTMLInputElement> submitter)
|
|||
Vector<URLQueryParam> parameters;
|
||||
|
||||
for_each_in_subtree_of_type<HTMLInputElement>([&](auto& node) {
|
||||
auto& input = to<HTMLInputElement>(node);
|
||||
auto& input = downcast<HTMLInputElement>(node);
|
||||
if (!input.name().is_null() && (input.type() != "submit" || &input == submitter))
|
||||
parameters.append({ input.name(), input.value() });
|
||||
return IterationDecision::Continue;
|
||||
|
|
|
@ -42,10 +42,8 @@ public:
|
|||
void submit(RefPtr<HTMLInputElement> submitter);
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLFormElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::form;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLFormElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element() && downcast<Web::HTMLElement>(node).local_name() == Web::HTML::TagNames::form; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -36,10 +36,8 @@ public:
|
|||
virtual ~HTMLHRElement() override;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLHRElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::hr;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLHRElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element() && downcast<Web::HTMLElement>(node).local_name() == Web::HTML::TagNames::hr; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -36,10 +36,8 @@ public:
|
|||
virtual ~HTMLHeadElement() override;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLHeadElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name().equals_ignoring_case("head");
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLHeadElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_element() && downcast<Web::Element>(node).local_name() == Web::HTML::TagNames::head; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -36,10 +36,8 @@ public:
|
|||
virtual ~HTMLHtmlElement() override;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLHtmlElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name().equals_ignoring_case("html");
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLHtmlElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element() && downcast<Web::HTMLElement>(node).local_name() == Web::HTML::TagNames::html; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -51,10 +51,8 @@ private:
|
|||
RefPtr<Frame> m_hosted_frame;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLIFrameElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::iframe;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLIFrameElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element() && downcast<Web::HTMLElement>(node).local_name() == Web::HTML::TagNames::iframe; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -60,10 +60,8 @@ private:
|
|||
ImageLoader m_image_loader;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLImageElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::img;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLImageElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_element() && downcast<Web::Element>(node).local_name() == Web::HTML::TagNames::img; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -83,7 +83,7 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties* p
|
|||
auto& text_box = page_view.add<GUI::TextBox>();
|
||||
text_box.set_text(value());
|
||||
text_box.on_change = [this] {
|
||||
auto& widget = to<LayoutWidget>(layout_node())->widget();
|
||||
auto& widget = downcast<LayoutWidget>(layout_node())->widget();
|
||||
const_cast<HTMLInputElement*>(this)->set_attribute(HTML::AttributeNames::value, static_cast<const GUI::TextBox&>(widget).text());
|
||||
};
|
||||
int text_width = Gfx::Font::default_font().width(value());
|
||||
|
|
|
@ -42,10 +42,8 @@ public:
|
|||
String name() const { return attribute(HTML::AttributeNames::name); }
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLInputElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::input;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLInputElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element() && downcast<Web::HTMLElement>(node).local_name() == Web::HTML::TagNames::input; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -64,10 +64,8 @@ private:
|
|||
RefPtr<StyleSheet> m_style_sheet;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLLinkElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::link;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLLinkElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element() && downcast<Web::HTMLElement>(node).local_name() == Web::HTML::TagNames::link; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -52,10 +52,8 @@ private:
|
|||
bool m_should_show_fallback_content { false };
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLObjectElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::object;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLObjectElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_element() && downcast<Web::Element>(node).local_name() == Web::HTML::TagNames::object; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -65,10 +65,8 @@ private:
|
|||
String m_script_source;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLScriptElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::script;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLScriptElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element() && downcast<Web::HTMLElement>(node).local_name() == Web::HTML::TagNames::script; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -46,7 +46,7 @@ void HTMLStyleElement::children_changed()
|
|||
StringBuilder builder;
|
||||
for_each_child([&](auto& child) {
|
||||
if (is<Text>(child))
|
||||
builder.append(to<Text>(child).text_content());
|
||||
builder.append(downcast<Text>(child).text_content());
|
||||
});
|
||||
m_stylesheet = parse_css(CSS::ParsingContext(document()), builder.to_string());
|
||||
if (m_stylesheet)
|
||||
|
|
|
@ -44,11 +44,8 @@ private:
|
|||
RefPtr<StyleSheet> m_stylesheet;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLStyleElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::style;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLStyleElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element() && downcast<Web::HTMLElement>(node).local_name() == Web::HTML::TagNames::style; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -39,10 +39,8 @@ private:
|
|||
virtual void apply_presentational_hints(StyleProperties&) const override;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLTableCellElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name().is_one_of(HTML::TagNames::td, HTML::TagNames::th);
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLTableCellElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element() && downcast<Web::HTMLElement>(node).local_name() == Web::HTML::TagNames::td; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -39,10 +39,8 @@ private:
|
|||
virtual void apply_presentational_hints(StyleProperties&) const override;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLTableElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::table;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLTableElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element() && downcast<Web::HTMLElement>(node).local_name() == Web::HTML::TagNames::table; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -36,10 +36,8 @@ public:
|
|||
virtual ~HTMLTableRowElement() override;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLTableRowElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name() == HTML::TagNames::tr;
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLTableRowElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element() && downcast<Web::HTMLElement>(node).local_name() == Web::HTML::TagNames::tr; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
|
@ -36,10 +36,8 @@ public:
|
|||
virtual ~HTMLTitleElement() override;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool is<HTMLTitleElement>(const Node& node)
|
||||
{
|
||||
return is<Element>(node) && to<Element>(node).local_name().equals_ignoring_case("title");
|
||||
}
|
||||
|
||||
}
|
||||
AK_BEGIN_TYPE_TRAITS(Web::HTMLTitleElement)
|
||||
static bool is_type(const Web::Node& node) { return node.is_html_element() && downcast<Web::HTMLElement>(node).local_name() == Web::HTML::TagNames::title; }
|
||||
AK_END_TYPE_TRAITS()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue