mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
split NavigationType and NavigationKind
This commit is contained in:
@@ -38,8 +38,14 @@ pub const Interfaces = .{
|
|||||||
NavigationHistoryEntry,
|
NavigationHistoryEntry,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const NavigationKind = union(enum) {
|
pub const NavigationType = enum {
|
||||||
initial,
|
push,
|
||||||
|
replace,
|
||||||
|
traverse,
|
||||||
|
reload,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const NavigationKind = union(NavigationType) {
|
||||||
push: ?[]const u8,
|
push: ?[]const u8,
|
||||||
replace,
|
replace,
|
||||||
traverse: usize,
|
traverse: usize,
|
||||||
@@ -191,21 +197,26 @@ pub fn _forward(self: *Navigation, page: *Page) !NavigationReturn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This is for after true navigation processing, where we need to ensure that our entries are up to date.
|
// This is for after true navigation processing, where we need to ensure that our entries are up to date.
|
||||||
pub fn processNavigation(self: *Navigation, url: []const u8, kind: NavigationKind, page: *Page) !void {
|
// This is only really safe to run in the `pageDoneCallback` where we can guarantee that the URL and NavigationKind are correct.
|
||||||
switch (kind) {
|
pub fn processNavigation(self: *Navigation, page: *Page) !void {
|
||||||
.initial => {
|
const url = page.url.raw;
|
||||||
_ = try self.pushEntry(url, null, page);
|
const kind = page.session.navigation_kind;
|
||||||
},
|
|
||||||
.replace => {
|
if (kind) |k| {
|
||||||
// When replacing, we just update the URL but the state is nullified.
|
switch (k) {
|
||||||
const entry = self.currentEntry();
|
.replace => {
|
||||||
entry.url = url;
|
// When replacing, we just update the URL but the state is nullified.
|
||||||
entry.state = null;
|
const entry = self.currentEntry();
|
||||||
},
|
entry.url = url;
|
||||||
.push => |state| {
|
entry.state = null;
|
||||||
_ = try self.pushEntry(url, state, page);
|
},
|
||||||
},
|
.push => |state| {
|
||||||
.traverse, .reload => {},
|
_ = try self.pushEntry(url, state, page);
|
||||||
|
},
|
||||||
|
.traverse, .reload => {},
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_ = try self.pushEntry(url, null, page);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -817,7 +817,7 @@ pub const Page = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We need to handle different navigation types differently.
|
// We need to handle different navigation types differently.
|
||||||
try self.session.navigation.processNavigation(self.url.raw, self.session.navigation_kind, self);
|
try self.session.navigation.processNavigation(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pageErrorCallback(ctx: *anyopaque, err: anyerror) void {
|
fn pageErrorCallback(ctx: *anyopaque, err: anyerror) void {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ pub const Session = struct {
|
|||||||
// https://developer.mozilla.org/en-US/docs/Web/API/History
|
// https://developer.mozilla.org/en-US/docs/Web/API/History
|
||||||
history: History = .{},
|
history: History = .{},
|
||||||
navigation: Navigation = .{},
|
navigation: Navigation = .{},
|
||||||
navigation_kind: NavigationKind = .initial,
|
navigation_kind: ?NavigationKind = null,
|
||||||
|
|
||||||
page: ?Page = null,
|
page: ?Page = null,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user