mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 06:07:34 +00:00
LibWeb: Port HTMLElement interface from DeprecatedString to String
This commit is contained in:
parent
938356da98
commit
2c69f273a0
3 changed files with 19 additions and 18 deletions
|
@ -58,8 +58,10 @@ void HTMLElement::visit_edges(Cell::Visitor& visitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/dom.html#dom-dir
|
// https://html.spec.whatwg.org/multipage/dom.html#dom-dir
|
||||||
DeprecatedString HTMLElement::dir() const
|
StringView HTMLElement::dir() const
|
||||||
{
|
{
|
||||||
|
// FIXME: This should probably be `Reflect` in the IDL.
|
||||||
|
// The dir IDL attribute on an element must reflect the dir content attribute of that element, limited to only known values.
|
||||||
auto dir = deprecated_attribute(HTML::AttributeNames::dir);
|
auto dir = deprecated_attribute(HTML::AttributeNames::dir);
|
||||||
#define __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(keyword) \
|
#define __ENUMERATE_HTML_ELEMENT_DIR_ATTRIBUTE(keyword) \
|
||||||
if (dir.equals_ignoring_ascii_case(#keyword##sv)) \
|
if (dir.equals_ignoring_ascii_case(#keyword##sv)) \
|
||||||
|
@ -70,7 +72,7 @@ DeprecatedString HTMLElement::dir() const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTMLElement::set_dir(DeprecatedString const& dir)
|
void HTMLElement::set_dir(String const& dir)
|
||||||
{
|
{
|
||||||
MUST(set_attribute(HTML::AttributeNames::dir, dir));
|
MUST(set_attribute(HTML::AttributeNames::dir, dir));
|
||||||
}
|
}
|
||||||
|
@ -89,22 +91,21 @@ bool HTMLElement::is_editable() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString HTMLElement::content_editable() const
|
StringView HTMLElement::content_editable() const
|
||||||
{
|
{
|
||||||
switch (m_content_editable_state) {
|
switch (m_content_editable_state) {
|
||||||
case ContentEditableState::True:
|
case ContentEditableState::True:
|
||||||
return "true";
|
return "true"sv;
|
||||||
case ContentEditableState::False:
|
case ContentEditableState::False:
|
||||||
return "false";
|
return "false"sv;
|
||||||
case ContentEditableState::Inherit:
|
case ContentEditableState::Inherit:
|
||||||
return "inherit";
|
return "inherit"sv;
|
||||||
default:
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
}
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/interaction.html#contenteditable
|
// https://html.spec.whatwg.org/multipage/interaction.html#contenteditable
|
||||||
WebIDL::ExceptionOr<void> HTMLElement::set_content_editable(DeprecatedString const& content_editable)
|
WebIDL::ExceptionOr<void> HTMLElement::set_content_editable(StringView content_editable)
|
||||||
{
|
{
|
||||||
if (content_editable.equals_ignoring_ascii_case("inherit"sv)) {
|
if (content_editable.equals_ignoring_ascii_case("inherit"sv)) {
|
||||||
remove_attribute(HTML::AttributeNames::contenteditable);
|
remove_attribute(HTML::AttributeNames::contenteditable);
|
||||||
|
@ -129,14 +130,14 @@ void HTMLElement::set_inner_text(StringView text)
|
||||||
set_needs_style_update(true);
|
set_needs_style_update(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString HTMLElement::inner_text()
|
String HTMLElement::inner_text()
|
||||||
{
|
{
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
|
|
||||||
// innerText for element being rendered takes visibility into account, so force a layout and then walk the layout tree.
|
// innerText for element being rendered takes visibility into account, so force a layout and then walk the layout tree.
|
||||||
document().update_layout();
|
document().update_layout();
|
||||||
if (!layout_node())
|
if (!layout_node())
|
||||||
return text_content();
|
return MUST(String::from_deprecated_string(text_content()));
|
||||||
|
|
||||||
Function<void(Layout::Node const&)> recurse = [&](auto& node) {
|
Function<void(Layout::Node const&)> recurse = [&](auto& node) {
|
||||||
for (auto* child = node.first_child(); child; child = child->next_sibling()) {
|
for (auto* child = node.first_child(); child; child = child->next_sibling()) {
|
||||||
|
@ -149,7 +150,7 @@ DeprecatedString HTMLElement::inner_text()
|
||||||
};
|
};
|
||||||
recurse(*layout_node());
|
recurse(*layout_node());
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
return MUST(builder.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsettop
|
// // https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsettop
|
||||||
|
|
|
@ -29,14 +29,14 @@ public:
|
||||||
|
|
||||||
DeprecatedString title() const { return deprecated_attribute(HTML::AttributeNames::title); }
|
DeprecatedString title() const { return deprecated_attribute(HTML::AttributeNames::title); }
|
||||||
|
|
||||||
DeprecatedString dir() const;
|
StringView dir() const;
|
||||||
void set_dir(DeprecatedString const&);
|
void set_dir(String const&);
|
||||||
|
|
||||||
virtual bool is_editable() const final;
|
virtual bool is_editable() const final;
|
||||||
DeprecatedString content_editable() const;
|
StringView content_editable() const;
|
||||||
WebIDL::ExceptionOr<void> set_content_editable(DeprecatedString const&);
|
WebIDL::ExceptionOr<void> set_content_editable(StringView);
|
||||||
|
|
||||||
DeprecatedString inner_text();
|
String inner_text();
|
||||||
void set_inner_text(StringView);
|
void set_inner_text(StringView);
|
||||||
|
|
||||||
int offset_top() const;
|
int offset_top() const;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#import <DOM/EventHandler.idl>
|
#import <DOM/EventHandler.idl>
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/semantics.html#htmlelement
|
// https://html.spec.whatwg.org/multipage/semantics.html#htmlelement
|
||||||
[Exposed=Window, UseDeprecatedAKString]
|
[Exposed=Window]
|
||||||
interface HTMLElement : Element {
|
interface HTMLElement : Element {
|
||||||
|
|
||||||
[HTMLConstructor] constructor();
|
[HTMLConstructor] constructor();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue