Browser: 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:
Timothy Flynn 2024-03-29 06:59:09 -04:00 committed by Tim Flynn
parent 8b1ad5c496
commit 245489e68c
Notes: sideshowbarker 2024-07-16 20:39:14 +09:00

View file

@ -43,6 +43,7 @@
#include <LibGUI/Window.h>
#include <LibURL/URL.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
#include <LibWeb/HTML/SelectedFile.h>
#include <LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.h>
#include <LibWeb/Layout/BlockContainer.h>
@ -257,6 +258,23 @@ Tab::Tab(BrowserWindow& window)
m_dom_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);
break;
case Web::HTML::HistoryHandlingBehavior::Replace:
m_history.replace_current(url, m_title);
break;
}
auto url_serialized = url.serialize();
m_location_box->set_text(url_serialized);
update_actions();
update_bookmark_button(url_serialized);
};
view().on_navigate_back = [this]() {
go_back(1);
};