mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:37:35 +00:00
LibWeb: Render text inside <input type=password> as asterisks (*
)
This makes it possible to enter passwords while recording YouTube videos. :^)
This commit is contained in:
parent
b33a2eb9b1
commit
5839ef2ed8
3 changed files with 14 additions and 0 deletions
|
@ -31,6 +31,9 @@ public:
|
||||||
|
|
||||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> split_text(size_t offset);
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> split_text(size_t offset);
|
||||||
|
|
||||||
|
bool is_password_input() const { return m_is_password_input; }
|
||||||
|
void set_is_password_input(Badge<HTML::HTMLInputElement>, bool b) { m_is_password_input = b; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Text(Document&, String const&);
|
Text(Document&, String const&);
|
||||||
Text(Document&, NodeType, String const&);
|
Text(Document&, NodeType, String const&);
|
||||||
|
@ -41,6 +44,7 @@ private:
|
||||||
JS::GCPtr<HTML::HTMLInputElement> m_owner_input_element;
|
JS::GCPtr<HTML::HTMLInputElement> m_owner_input_element;
|
||||||
|
|
||||||
bool m_always_editable { false };
|
bool m_always_editable { false };
|
||||||
|
bool m_is_password_input { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
|
@ -344,6 +344,10 @@ void HTMLInputElement::create_shadow_tree_if_needed()
|
||||||
m_text_node = heap().allocate<DOM::Text>(realm(), document(), initial_value);
|
m_text_node = heap().allocate<DOM::Text>(realm(), document(), initial_value);
|
||||||
m_text_node->set_always_editable(m_type != TypeAttributeState::FileUpload);
|
m_text_node->set_always_editable(m_type != TypeAttributeState::FileUpload);
|
||||||
m_text_node->set_owner_input_element({}, *this);
|
m_text_node->set_owner_input_element({}, *this);
|
||||||
|
|
||||||
|
if (m_type == TypeAttributeState::Password)
|
||||||
|
m_text_node->set_is_password_input({}, true);
|
||||||
|
|
||||||
MUST(element->append_child(*m_text_node));
|
MUST(element->append_child(*m_text_node));
|
||||||
MUST(shadow_root->append_child(move(element)));
|
MUST(shadow_root->append_child(move(element)));
|
||||||
set_shadow_root(move(shadow_root));
|
set_shadow_root(move(shadow_root));
|
||||||
|
|
|
@ -35,6 +35,12 @@ static bool is_all_whitespace(StringView string)
|
||||||
void TextNode::compute_text_for_rendering(bool collapse)
|
void TextNode::compute_text_for_rendering(bool collapse)
|
||||||
{
|
{
|
||||||
auto& data = dom_node().data();
|
auto& data = dom_node().data();
|
||||||
|
|
||||||
|
if (dom_node().is_password_input()) {
|
||||||
|
m_text_for_rendering = String::repeated('*', data.length());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!collapse || data.is_empty()) {
|
if (!collapse || data.is_empty()) {
|
||||||
m_text_for_rendering = data;
|
m_text_for_rendering = data;
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue