mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibHTML: Add basic keyboard navigation (up/down/pgdn/pgup/home/end/etc)
This commit is contained in:
parent
89aaae82a1
commit
775cbbb422
Notes:
sideshowbarker
2024-07-19 11:39:38 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/775cbbb422e
2 changed files with 37 additions and 0 deletions
|
@ -183,6 +183,40 @@ void HtmlView::mousedown_event(GMouseEvent& event)
|
|||
event.accept();
|
||||
}
|
||||
|
||||
void HtmlView::keydown_event(GKeyEvent& event)
|
||||
{
|
||||
if (event.modifiers() == 0) {
|
||||
switch (event.key()) {
|
||||
case Key_Home:
|
||||
vertical_scrollbar().set_value(0);
|
||||
break;
|
||||
case Key_End:
|
||||
vertical_scrollbar().set_value(vertical_scrollbar().max());
|
||||
break;
|
||||
case Key_Down:
|
||||
vertical_scrollbar().set_value(vertical_scrollbar().value() + vertical_scrollbar().step());
|
||||
break;
|
||||
case Key_Up:
|
||||
vertical_scrollbar().set_value(vertical_scrollbar().value() - vertical_scrollbar().step());
|
||||
break;
|
||||
case Key_Left:
|
||||
horizontal_scrollbar().set_value(horizontal_scrollbar().value() + horizontal_scrollbar().step());
|
||||
break;
|
||||
case Key_Right:
|
||||
horizontal_scrollbar().set_value(horizontal_scrollbar().value() - horizontal_scrollbar().step());
|
||||
break;
|
||||
case Key_PageDown:
|
||||
vertical_scrollbar().set_value(vertical_scrollbar().value() + frame_inner_rect().height());
|
||||
break;
|
||||
case Key_PageUp:
|
||||
vertical_scrollbar().set_value(vertical_scrollbar().value() - frame_inner_rect().height());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
event.accept();
|
||||
}
|
||||
|
||||
void HtmlView::reload()
|
||||
{
|
||||
load(main_frame().document()->url());
|
||||
|
|
|
@ -32,6 +32,8 @@ public:
|
|||
Function<void(const String&)> on_title_change;
|
||||
Function<void(const URL&)> on_load_start;
|
||||
|
||||
virtual bool accepts_focus() const override { return true; }
|
||||
|
||||
protected:
|
||||
HtmlView(GWidget* parent = nullptr);
|
||||
|
||||
|
@ -39,6 +41,7 @@ protected:
|
|||
virtual void paint_event(GPaintEvent&) override;
|
||||
virtual void mousemove_event(GMouseEvent&) override;
|
||||
virtual void mousedown_event(GMouseEvent&) override;
|
||||
virtual void keydown_event(GKeyEvent&) override;
|
||||
|
||||
private:
|
||||
void layout_and_sync_size();
|
||||
|
|
Loading…
Add table
Reference in a new issue