mirror of
				https://github.com/lightpanda-io/browser.git
				synced 2025-10-30 07:31:47 +00:00 
			
		
		
		
	split NavigationType and NavigationKind
This commit is contained in:
		| @@ -38,8 +38,14 @@ pub const Interfaces = .{ | ||||
|     NavigationHistoryEntry, | ||||
| }; | ||||
|  | ||||
| pub const NavigationKind = union(enum) { | ||||
|     initial, | ||||
| pub const NavigationType = enum { | ||||
|     push, | ||||
|     replace, | ||||
|     traverse, | ||||
|     reload, | ||||
| }; | ||||
|  | ||||
| pub const NavigationKind = union(NavigationType) { | ||||
|     push: ?[]const u8, | ||||
|     replace, | ||||
|     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. | ||||
| pub fn processNavigation(self: *Navigation, url: []const u8, kind: NavigationKind, page: *Page) !void { | ||||
|     switch (kind) { | ||||
|         .initial => { | ||||
|             _ = try self.pushEntry(url, null, page); | ||||
|         }, | ||||
|         .replace => { | ||||
|             // When replacing, we just update the URL but the state is nullified. | ||||
|             const entry = self.currentEntry(); | ||||
|             entry.url = url; | ||||
|             entry.state = null; | ||||
|         }, | ||||
|         .push => |state| { | ||||
|             _ = try self.pushEntry(url, state, page); | ||||
|         }, | ||||
|         .traverse, .reload => {}, | ||||
| // This is only really safe to run in the `pageDoneCallback` where we can guarantee that the URL and NavigationKind are correct. | ||||
| pub fn processNavigation(self: *Navigation, page: *Page) !void { | ||||
|     const url = page.url.raw; | ||||
|     const kind = page.session.navigation_kind; | ||||
|  | ||||
|     if (kind) |k| { | ||||
|         switch (k) { | ||||
|             .replace => { | ||||
|                 // When replacing, we just update the URL but the state is nullified. | ||||
|                 const entry = self.currentEntry(); | ||||
|                 entry.url = url; | ||||
|                 entry.state = null; | ||||
|             }, | ||||
|             .push => |state| { | ||||
|                 _ = 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. | ||||
|         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 { | ||||
|   | ||||
| @@ -60,7 +60,7 @@ pub const Session = struct { | ||||
|     // https://developer.mozilla.org/en-US/docs/Web/API/History | ||||
|     history: History = .{}, | ||||
|     navigation: Navigation = .{}, | ||||
|     navigation_kind: NavigationKind = .initial, | ||||
|     navigation_kind: ?NavigationKind = null, | ||||
|  | ||||
|     page: ?Page = null, | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Muki Kiboigo
					Muki Kiboigo