mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 07:03:29 +00:00
Merge pull request #355 from lightpanda-io/history
Some checks failed
wpt / web platform tests (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / zig build release (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
zig-test / demo-puppeteer (push) Has been cancelled
Some checks failed
wpt / web platform tests (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / zig build release (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
zig-test / demo-puppeteer (push) Has been cancelled
dom: history placeholder
This commit is contained in:
@@ -28,62 +28,70 @@ const checkCases = jsruntime.test_utils.checkCases;
|
|||||||
pub const History = struct {
|
pub const History = struct {
|
||||||
pub const mem_guarantied = true;
|
pub const mem_guarantied = true;
|
||||||
|
|
||||||
const ScrollRestaurationMode = enum {
|
const ScrollRestorationMode = enum {
|
||||||
auto,
|
auto,
|
||||||
manual,
|
manual,
|
||||||
};
|
};
|
||||||
|
|
||||||
scrollRestauration: ScrollRestaurationMode = .audio,
|
scrollRestoration: ScrollRestorationMode = .auto,
|
||||||
|
state: std.json.Value = .null,
|
||||||
|
|
||||||
pub fn get_length(_: *History) u64 {
|
// count tracks the history length until we implement correctly pushstate.
|
||||||
return 0;
|
count: u32 = 0,
|
||||||
|
|
||||||
|
pub fn get_length(self: *History) u32 {
|
||||||
|
// TODO return the real history length value.
|
||||||
|
return self.count;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_appCodeName(_: *Navigator) []const u8 {
|
pub fn get_scrollRestoration(self: *History) []const u8 {
|
||||||
return "Mozilla";
|
return switch (self.scrollRestoration) {
|
||||||
|
.auto => "auto",
|
||||||
|
.manual => "manual",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
pub fn get_appName(_: *Navigator) []const u8 {
|
|
||||||
return "Netscape";
|
pub fn set_scrollRestoration(self: *History, mode: []const u8) void {
|
||||||
|
if (std.mem.eql(u8, "manual", mode)) self.scrollRestoration = .manual;
|
||||||
|
if (std.mem.eql(u8, "auto", mode)) self.scrollRestoration = .auto;
|
||||||
}
|
}
|
||||||
pub fn get_appVersion(self: *Navigator) []const u8 {
|
|
||||||
return self.version;
|
pub fn get_state(self: *History) std.json.Value {
|
||||||
|
return self.state;
|
||||||
}
|
}
|
||||||
pub fn get_platform(self: *Navigator) []const u8 {
|
|
||||||
return self.platform;
|
// TODO implement the function
|
||||||
}
|
// data must handle any argument. We could expect a std.json.Value but
|
||||||
pub fn get_product(_: *Navigator) []const u8 {
|
// https://github.com/lightpanda-io/zig-js-runtime/issues/267 is missing.
|
||||||
return "Gecko";
|
pub fn _pushState(self: *History, data: []const u8, _: ?[]const u8, url: ?[]const u8) void {
|
||||||
}
|
self.count += 1;
|
||||||
pub fn get_productSub(_: *Navigator) []const u8 {
|
|
||||||
return "20030107";
|
|
||||||
}
|
|
||||||
pub fn get_vendor(self: *Navigator) []const u8 {
|
|
||||||
return self.vendor;
|
|
||||||
}
|
|
||||||
pub fn get_vendorSub(_: *Navigator) []const u8 {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
pub fn get_language(self: *Navigator) []const u8 {
|
|
||||||
return self.language;
|
|
||||||
}
|
|
||||||
// TODO wait for arrays.
|
|
||||||
//pub fn get_languages(self: *Navigator) [][]const u8 {
|
|
||||||
// return .{self.language};
|
|
||||||
//}
|
|
||||||
pub fn get_online(_: *Navigator) bool {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
pub fn _registerProtocolHandler(_: *Navigator, scheme: []const u8, url: []const u8) void {
|
|
||||||
_ = scheme;
|
|
||||||
_ = url;
|
|
||||||
}
|
|
||||||
pub fn _unregisterProtocolHandler(_: *Navigator, scheme: []const u8, url: []const u8) void {
|
|
||||||
_ = scheme;
|
|
||||||
_ = url;
|
_ = url;
|
||||||
|
_ = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cookieEnabled(_: *Navigator) bool {
|
// TODO implement the function
|
||||||
return true;
|
// data must handle any argument. We could expect a std.json.Value but
|
||||||
|
// https://github.com/lightpanda-io/zig-js-runtime/issues/267 is missing.
|
||||||
|
pub fn _replaceState(self: *History, data: []const u8, _: ?[]const u8, url: ?[]const u8) void {
|
||||||
|
_ = self;
|
||||||
|
_ = url;
|
||||||
|
_ = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO implement the function
|
||||||
|
pub fn _go(self: *History, delta: ?i32) void {
|
||||||
|
_ = self;
|
||||||
|
_ = delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO implement the function
|
||||||
|
pub fn _back(self: *History) void {
|
||||||
|
_ = self;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO implement the function
|
||||||
|
pub fn _forward(self: *History) void {
|
||||||
|
_ = self;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -94,11 +102,27 @@ pub fn testExecFn(
|
|||||||
_: std.mem.Allocator,
|
_: std.mem.Allocator,
|
||||||
js_env: *jsruntime.Env,
|
js_env: *jsruntime.Env,
|
||||||
) anyerror!void {
|
) anyerror!void {
|
||||||
var navigator = [_]Case{
|
var history = [_]Case{
|
||||||
.{ .src = "navigator.userAgent", .ex = "Lightpanda/1.0" },
|
.{ .src = "history.scrollRestoration", .ex = "auto" },
|
||||||
.{ .src = "navigator.appVersion", .ex = "1.0" },
|
.{ .src = "history.scrollRestoration = 'manual'", .ex = "manual" },
|
||||||
.{ .src = "navigator.language", .ex = "en-US" },
|
.{ .src = "history.scrollRestoration = 'foo'", .ex = "foo" },
|
||||||
};
|
.{ .src = "history.scrollRestoration", .ex = "manual" },
|
||||||
try checkCases(js_env, &navigator);
|
.{ .src = "history.scrollRestoration = 'auto'", .ex = "auto" },
|
||||||
}
|
.{ .src = "history.scrollRestoration", .ex = "auto" },
|
||||||
|
|
||||||
|
.{ .src = "history.state", .ex = "null" },
|
||||||
|
|
||||||
|
.{ .src = "history.pushState({}, null, '')", .ex = "undefined" },
|
||||||
|
|
||||||
|
.{ .src = "history.replaceState({}, null, '')", .ex = "undefined" },
|
||||||
|
|
||||||
|
.{ .src = "history.go()", .ex = "undefined" },
|
||||||
|
.{ .src = "history.go(1)", .ex = "undefined" },
|
||||||
|
.{ .src = "history.go(-1)", .ex = "undefined" },
|
||||||
|
|
||||||
|
.{ .src = "history.forward()", .ex = "undefined" },
|
||||||
|
|
||||||
|
.{ .src = "history.back()", .ex = "undefined" },
|
||||||
|
};
|
||||||
|
try checkCases(js_env, &history);
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ const HTMLDocument = @import("document.zig").HTMLDocument;
|
|||||||
const HTMLElem = @import("elements.zig");
|
const HTMLElem = @import("elements.zig");
|
||||||
const Window = @import("window.zig").Window;
|
const Window = @import("window.zig").Window;
|
||||||
const Navigator = @import("navigator.zig").Navigator;
|
const Navigator = @import("navigator.zig").Navigator;
|
||||||
|
const History = @import("history.zig").History;
|
||||||
|
|
||||||
pub const Interfaces = generate.Tuple(.{
|
pub const Interfaces = generate.Tuple(.{
|
||||||
HTMLDocument,
|
HTMLDocument,
|
||||||
@@ -30,4 +31,5 @@ pub const Interfaces = generate.Tuple(.{
|
|||||||
HTMLElem.Interfaces,
|
HTMLElem.Interfaces,
|
||||||
Window,
|
Window,
|
||||||
Navigator,
|
Navigator,
|
||||||
|
History,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const Loop = jsruntime.Loop;
|
|||||||
|
|
||||||
const EventTarget = @import("../dom/event_target.zig").EventTarget;
|
const EventTarget = @import("../dom/event_target.zig").EventTarget;
|
||||||
const Navigator = @import("navigator.zig").Navigator;
|
const Navigator = @import("navigator.zig").Navigator;
|
||||||
|
const History = @import("history.zig").History;
|
||||||
|
|
||||||
const storage = @import("../storage/storage.zig");
|
const storage = @import("../storage/storage.zig");
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ pub const Window = struct {
|
|||||||
|
|
||||||
document: ?*parser.DocumentHTML = null,
|
document: ?*parser.DocumentHTML = null,
|
||||||
target: []const u8,
|
target: []const u8,
|
||||||
|
history: History = .{},
|
||||||
|
|
||||||
storageShelf: ?*storage.Shelf = null,
|
storageShelf: ?*storage.Shelf = null,
|
||||||
|
|
||||||
@@ -86,6 +88,10 @@ pub const Window = struct {
|
|||||||
return self.document;
|
return self.document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_history(self: *Window) *History {
|
||||||
|
return &self.history;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_name(self: *Window) []const u8 {
|
pub fn get_name(self: *Window) []const u8 {
|
||||||
return self.target;
|
return self.target;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ fn testsAllExecFn(
|
|||||||
MutationObserverTestExecFn,
|
MutationObserverTestExecFn,
|
||||||
@import("polyfill/fetch.zig").testExecFn,
|
@import("polyfill/fetch.zig").testExecFn,
|
||||||
@import("html/navigator.zig").testExecFn,
|
@import("html/navigator.zig").testExecFn,
|
||||||
|
@import("html/history.zig").testExecFn,
|
||||||
};
|
};
|
||||||
|
|
||||||
inline for (testFns) |testFn| {
|
inline for (testFns) |testFn| {
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ pub const Bottle = struct {
|
|||||||
// > context of another document.
|
// > context of another document.
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event
|
// https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event
|
||||||
//
|
//
|
||||||
// So for now, we won't impement the feature.
|
// So for now, we won't implement the feature.
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _removeItem(self: *Bottle, k: []const u8) !void {
|
pub fn _removeItem(self: *Bottle, k: []const u8) !void {
|
||||||
|
|||||||
Reference in New Issue
Block a user