Ladybird/AppKit: 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-28 22:23:33 -04:00 committed by Tim Flynn
commit 45c4e1c446
Notes: sideshowbarker 2024-07-17 00:25:35 +09:00
5 changed files with 34 additions and 2 deletions

View file

@ -12,6 +12,7 @@
#include <LibWeb/CSS/PreferredColorScheme.h>
#include <LibWeb/HTML/ActivateTab.h>
#include <LibWeb/HTML/AudioPlayState.h>
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
#include <LibWebView/Forward.h>
#import <System/Cocoa.h>
@ -28,6 +29,8 @@
- (void)loadURL:(URL::URL const&)url;
- (void)onLoadStart:(URL::URL const&)url isRedirect:(BOOL)is_redirect;
- (void)onLoadFinish:(URL::URL const&)url;
- (void)onURLUpdated:(URL::URL const&)url
historyBehavior:(Web::HTML::HistoryHandlingBehavior)history_behavior;
- (void)onTitleChange:(ByteString const&)title;
- (void)onFaviconChange:(Gfx::Bitmap const&)bitmap;

View file

@ -282,6 +282,10 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
[self.observer onLoadFinish:url];
};
m_web_view_bridge->on_url_updated = [self](auto const& url, auto history_behavior) {
[self.observer onURLUpdated:url historyBehavior:history_behavior];
};
m_web_view_bridge->on_title_change = [self](auto const& title) {
[self.observer onTitleChange:title];
};

View file

@ -221,12 +221,12 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
- (void)onLoadStart:(URL::URL const&)url isRedirect:(BOOL)is_redirect
{
[[self tabController] onLoadStart:url isRedirect:is_redirect];
self.title = Ladybird::string_to_ns_string(url.serialize());
self.favicon = [Tab defaultFavicon];
[self updateTabTitleAndFavicon];
[[self tabController] onLoadStart:url isRedirect:is_redirect];
if (self.inspector_controller != nil) {
auto* inspector = (Inspector*)[self.inspector_controller window];
[inspector reset];
@ -241,6 +241,12 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
}
}
- (void)onURLUpdated:(URL::URL const&)url
historyBehavior:(Web::HTML::HistoryHandlingBehavior)history_behavior
{
[[self tabController] onURLUpdated:url historyBehavior:history_behavior];
}
- (void)onTitleChange:(ByteString const&)title
{
[[self tabController] onTitleChange:title];

View file

@ -8,6 +8,7 @@
#include <AK/Forward.h>
#include <LibURL/URL.h>
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
#import <System/Cocoa.h>
@ -27,6 +28,8 @@ struct TabSettings {
- (void)loadHTML:(StringView)html url:(URL::URL const&)url;
- (void)onLoadStart:(URL::URL const&)url isRedirect:(BOOL)isRedirect;
- (void)onURLUpdated:(URL::URL const&)url
historyBehavior:(Web::HTML::HistoryHandlingBehavior)history_behavior;
- (void)onTitleChange:(ByteString const&)title;
- (void)navigateBack:(id)sender;

View file

@ -133,6 +133,22 @@ enum class IsHistoryNavigation {
[self updateNavigationButtonStates];
}
- (void)onURLUpdated:(URL::URL const&)url
historyBehavior:(Web::HTML::HistoryHandlingBehavior)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;
}
[self setLocationFieldText:url.serialize()];
[self updateNavigationButtonStates];
}
- (void)onTitleChange:(ByteString const&)title
{
m_title = title;