mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
Ladybird/Qt: Implement history state change mechanics
We now appropriately update the current history item or create a new history item in the chrome process.
This commit is contained in:
parent
245489e68c
commit
2830bdf04a
Notes:
sideshowbarker
2024-07-17 01:12:07 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/2830bdf04a Pull-request: https://github.com/SerenityOS/serenity/pull/23758 Reviewed-by: https://github.com/kalenikaliaksandr ✅
2 changed files with 24 additions and 3 deletions
|
@ -14,6 +14,7 @@
|
|||
#include <AK/TemporaryChange.h>
|
||||
#include <LibGfx/ImageFormats/BMPWriter.h>
|
||||
#include <LibGfx/Painter.h>
|
||||
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
|
||||
#include <LibWeb/HTML/SelectedFile.h>
|
||||
#include <LibWebView/SearchEngine.h>
|
||||
#include <LibWebView/SourceHighlighter.h>
|
||||
|
@ -144,9 +145,7 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
|
|||
}
|
||||
m_is_history_navigation = false;
|
||||
|
||||
m_window->go_back_action().setEnabled(m_history.can_go_back());
|
||||
m_window->go_forward_action().setEnabled(m_history.can_go_forward());
|
||||
m_window->reload_action().setEnabled(!m_history.is_empty());
|
||||
update_navigation_button_states();
|
||||
|
||||
if (m_inspector_widget)
|
||||
m_inspector_widget->reset();
|
||||
|
@ -157,6 +156,20 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
|
|||
m_inspector_widget->inspect();
|
||||
};
|
||||
|
||||
view().on_url_updated = [this](auto const& url, auto history_behavior) {
|
||||
switch (history_behavior) {
|
||||
case Web::HTML::HistoryHandlingBehavior::Push:
|
||||
m_history.push(url, m_title.toUtf8().data());
|
||||
break;
|
||||
case Web::HTML::HistoryHandlingBehavior::Replace:
|
||||
m_history.replace_current(url, m_title.toUtf8().data());
|
||||
break;
|
||||
}
|
||||
|
||||
m_location_edit->setText(qstring_from_ak_string(url.serialize()));
|
||||
update_navigation_button_states();
|
||||
};
|
||||
|
||||
QObject::connect(m_location_edit, &QLineEdit::returnPressed, this, &Tab::location_edit_return_pressed);
|
||||
|
||||
view().on_title_change = [this](auto const& title) {
|
||||
|
@ -842,6 +855,13 @@ void Tab::update_hover_label()
|
|||
m_hover_label->raise();
|
||||
}
|
||||
|
||||
void Tab::update_navigation_button_states()
|
||||
{
|
||||
m_window->go_back_action().setEnabled(m_history.can_go_back());
|
||||
m_window->go_forward_action().setEnabled(m_history.can_go_forward());
|
||||
m_window->reload_action().setEnabled(!m_history.is_empty());
|
||||
}
|
||||
|
||||
bool Tab::event(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::PaletteChange) {
|
||||
|
|
|
@ -72,6 +72,7 @@ private:
|
|||
|
||||
void recreate_toolbar_icons();
|
||||
void update_hover_label();
|
||||
void update_navigation_button_states();
|
||||
|
||||
void open_link(URL::URL const&);
|
||||
void open_link_in_new_tab(URL::URL const&);
|
||||
|
|
Loading…
Reference in a new issue