mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
LibHTML: Collapse all-whitespace LayoutText into a single ' ' char.
This commit is contained in:
parent
8a0e21b22b
commit
0522a8f71c
Notes:
sideshowbarker
2024-07-19 13:35:28 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/0522a8f71c0
3 changed files with 21 additions and 1 deletions
|
@ -38,7 +38,7 @@ void dump_tree(const LayoutNode& node)
|
|||
printf(" ");
|
||||
printf("%s{%p}", node.class_name(), &node);
|
||||
if (node.is_text())
|
||||
printf(" \"%s\"", static_cast<const LayoutText&>(node).node().data().characters());
|
||||
printf(" \"%s\"", static_cast<const LayoutText&>(node).text().characters());
|
||||
printf("\n");
|
||||
++indent;
|
||||
node.for_each_child([](auto& child) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <LibHTML/LayoutText.h>
|
||||
#include <ctype.h>
|
||||
|
||||
LayoutText::LayoutText(const Text& text)
|
||||
: LayoutNode(&text)
|
||||
|
@ -8,3 +9,20 @@ LayoutText::LayoutText(const Text& text)
|
|||
LayoutText::~LayoutText()
|
||||
{
|
||||
}
|
||||
|
||||
static bool is_all_whitespace(const String& string)
|
||||
{
|
||||
for (int i = 0; i < string.length(); ++i) {
|
||||
if (!isspace(string[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const String& LayoutText::text() const
|
||||
{
|
||||
static String one_space = " ";
|
||||
if (is_all_whitespace(node().data()))
|
||||
return one_space;
|
||||
return node().data();
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ public:
|
|||
|
||||
const Text& node() const { return static_cast<const Text&>(*LayoutNode::node()); }
|
||||
|
||||
const String& text() const;
|
||||
|
||||
virtual const char* class_name() const override { return "LayoutText"; }
|
||||
virtual bool is_text() const final { return true; }
|
||||
|
||||
|
|
Loading…
Reference in a new issue