Ver Fonte

LibWeb: Add NavigationType to prep for Navigation API platform objects

This enum is used in many Navigation API classes, so stick it in its own
IDL file. However, we have no way to ask the BindingsGenerator to create
just an enum class that's not defined in an IDL file without an
 ``interface`` class at the top level, so implement the expected enum
 and stringification method manually.
Andrew Kaster há 1 ano atrás
pai
commit
daa9c4a650

+ 36 - 0
Userland/Libraries/LibWeb/HTML/NavigationType.h

@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/String.h>
+
+// FIXME: Generate this from the IDL file that just has an enum in it
+namespace Web::Bindings {
+enum class NavigationType {
+    Push,
+    Replace,
+    Reload,
+    Traverse,
+};
+
+inline String idl_enum_to_string(NavigationType value)
+{
+    switch (value) {
+    case NavigationType::Push:
+        return "Push"_string;
+    case NavigationType::Replace:
+        return "Replace"_string;
+    case NavigationType::Reload:
+        return "Reload"_string;
+    case NavigationType::Traverse:
+        return "Traverse"_string;
+    default:
+        return "<unknown>"_string;
+    }
+}
+
+}

+ 7 - 0
Userland/Libraries/LibWeb/HTML/NavigationType.idl

@@ -0,0 +1,7 @@
+// https://html.spec.whatwg.org/multipage/nav-history-apis.html#navigationtype
+enum NavigationType {
+ "push",
+ "replace",
+ "reload",
+ "traverse"
+};