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

LibWeb: Only allow editing of elements with contenteditable="true"

We now respect the contenteditable HTML attribute and only let you
edit content inside explicitly editable elements.
This commit is contained in:
Andreas Kling 2020-08-02 16:05:59 +02:00
parent 8b16c61ff8
commit 07e13e9868
9 changed files with 107 additions and 70 deletions

View file

@ -290,4 +290,22 @@ String Element::inner_html() const
return builder.to_string();
}
bool Element::is_editable() const
{
auto contenteditable = attribute(HTML::AttributeNames::contenteditable);
// "true" and the empty string map to the "true" state.
if ((!contenteditable.is_null() && contenteditable.is_empty()) || contenteditable.equals_ignoring_case("true"))
return true;
// "false" maps to the "false" state.
if (contenteditable.equals_ignoring_case("false"))
return false;
// "inherit", an invalid value, and a missing value all map to the "inherit" state.
return parent() && parent()->is_editable();
}
bool Document::is_editable() const
{
return m_editable;
}
}