1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:08:12 +00:00

LibHTML: Add basic keyboard navigation (up/down/pgdn/pgup/home/end/etc)

This commit is contained in:
Andreas Kling 2019-10-17 21:36:22 +02:00
parent 89aaae82a1
commit 775cbbb422
2 changed files with 37 additions and 0 deletions

View file

@ -183,6 +183,40 @@ void HtmlView::mousedown_event(GMouseEvent& event)
event.accept(); 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() void HtmlView::reload()
{ {
load(main_frame().document()->url()); load(main_frame().document()->url());

View file

@ -32,6 +32,8 @@ public:
Function<void(const String&)> on_title_change; Function<void(const String&)> on_title_change;
Function<void(const URL&)> on_load_start; Function<void(const URL&)> on_load_start;
virtual bool accepts_focus() const override { return true; }
protected: protected:
HtmlView(GWidget* parent = nullptr); HtmlView(GWidget* parent = nullptr);
@ -39,6 +41,7 @@ protected:
virtual void paint_event(GPaintEvent&) override; virtual void paint_event(GPaintEvent&) override;
virtual void mousemove_event(GMouseEvent&) override; virtual void mousemove_event(GMouseEvent&) override;
virtual void mousedown_event(GMouseEvent&) override; virtual void mousedown_event(GMouseEvent&) override;
virtual void keydown_event(GKeyEvent&) override;
private: private:
void layout_and_sync_size(); void layout_and_sync_size();