mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
LibWeb: Implement Element.innerText
Reading the property has a few warts (see FIXMEs in the included tests), but with this the timestamps on http://45.33.8.238/ get localized :^) Since the Date() constructor currently ignores all arguments, they don't get localized correctly but are all set to the current time, but hey, it's still progress from a certain point of view.
This commit is contained in:
parent
2f85af2a20
commit
2460980d2c
6 changed files with 86 additions and 1 deletions
|
@ -41,6 +41,7 @@
|
|||
#include <LibWeb/Layout/LayoutTableCell.h>
|
||||
#include <LibWeb/Layout/LayoutTableRow.h>
|
||||
#include <LibWeb/Layout/LayoutTableRowGroup.h>
|
||||
#include <LibWeb/Layout/LayoutText.h>
|
||||
#include <LibWeb/Layout/LayoutTreeBuilder.h>
|
||||
|
||||
namespace Web::DOM {
|
||||
|
@ -295,6 +296,39 @@ String Element::inner_html() const
|
|||
return builder.to_string();
|
||||
}
|
||||
|
||||
void Element::set_inner_text(StringView text)
|
||||
{
|
||||
remove_all_children();
|
||||
append_child(document().create_text_node(text));
|
||||
|
||||
set_needs_style_update(true);
|
||||
document().schedule_style_update();
|
||||
document().invalidate_layout();
|
||||
}
|
||||
|
||||
String Element::inner_text()
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
||||
// innerText for element being rendered takes visibility into account, so force a layout and then walk the layout tree.
|
||||
document().layout();
|
||||
if (!layout_node())
|
||||
return text_content();
|
||||
|
||||
Function<void(const LayoutNode&)> recurse = [&](auto& node) {
|
||||
for (auto* child = node.first_child(); child; child = child->next_sibling()) {
|
||||
if (child->is_text())
|
||||
builder.append(downcast<LayoutText>(*child).text_for_rendering());
|
||||
if (child->is_break())
|
||||
builder.append('\n');
|
||||
recurse(*child);
|
||||
}
|
||||
};
|
||||
recurse(*layout_node());
|
||||
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
bool Element::is_focused() const
|
||||
{
|
||||
return document().focused_element() == this;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue