mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:58:12 +00:00
LibWeb: Make HTMLInputElement move cursor into text node when focused
This mechanism feels rather awkward, but it's better than nothing.
This commit is contained in:
parent
65bd4477db
commit
9391311760
4 changed files with 29 additions and 0 deletions
|
@ -894,8 +894,14 @@ void Document::set_focused_element(Element* element)
|
||||||
if (m_focused_element == element)
|
if (m_focused_element == element)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (m_focused_element)
|
||||||
|
m_focused_element->did_lose_focus();
|
||||||
|
|
||||||
m_focused_element = element;
|
m_focused_element = element;
|
||||||
|
|
||||||
|
if (m_focused_element)
|
||||||
|
m_focused_element->did_receive_focus();
|
||||||
|
|
||||||
if (m_layout_root)
|
if (m_layout_root)
|
||||||
m_layout_root->set_needs_display();
|
m_layout_root->set_needs_display();
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,9 @@ public:
|
||||||
|
|
||||||
virtual RefPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>);
|
virtual RefPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>);
|
||||||
|
|
||||||
|
virtual void did_receive_focus() { }
|
||||||
|
virtual void did_lose_focus() { }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void children_changed() override;
|
virtual void children_changed() override;
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,21 @@ void HTMLInputElement::create_shadow_tree_if_needed()
|
||||||
set_shadow_root(move(shadow_root));
|
set_shadow_root(move(shadow_root));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HTMLInputElement::did_receive_focus()
|
||||||
|
{
|
||||||
|
auto* browsing_context = document().browsing_context();
|
||||||
|
if (!browsing_context)
|
||||||
|
return;
|
||||||
|
if (!m_text_node)
|
||||||
|
return;
|
||||||
|
browsing_context->set_cursor_position(DOM::Position { *m_text_node, 0 });
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HTMLInputElement::is_focusable() const
|
||||||
|
{
|
||||||
|
return m_text_node;
|
||||||
|
}
|
||||||
|
|
||||||
void HTMLInputElement::inserted()
|
void HTMLInputElement::inserted()
|
||||||
{
|
{
|
||||||
HTMLElement::inserted();
|
HTMLElement::inserted();
|
||||||
|
|
|
@ -36,6 +36,8 @@ public:
|
||||||
|
|
||||||
void did_click_button(Badge<Layout::ButtonBox>);
|
void did_click_button(Badge<Layout::ButtonBox>);
|
||||||
|
|
||||||
|
virtual bool is_focusable() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^DOM::Node
|
// ^DOM::Node
|
||||||
virtual void inserted() override;
|
virtual void inserted() override;
|
||||||
|
@ -44,6 +46,9 @@ private:
|
||||||
// ^HTML::FormAssociatedElement
|
// ^HTML::FormAssociatedElement
|
||||||
virtual HTMLElement& form_associated_element_to_html_element() override { return *this; }
|
virtual HTMLElement& form_associated_element_to_html_element() override { return *this; }
|
||||||
|
|
||||||
|
// ^DOM::EventTarget
|
||||||
|
virtual void did_receive_focus() override;
|
||||||
|
|
||||||
void create_shadow_tree_if_needed();
|
void create_shadow_tree_if_needed();
|
||||||
|
|
||||||
RefPtr<DOM::Text> m_text_node;
|
RefPtr<DOM::Text> m_text_node;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue