From daa9c4a650990025a7e4258015a31eced272baf8 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 23 Aug 2023 10:27:37 -0600 Subject: [PATCH] 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. --- .../Libraries/LibWeb/HTML/NavigationType.h | 36 +++++++++++++++++++ .../Libraries/LibWeb/HTML/NavigationType.idl | 7 ++++ 2 files changed, 43 insertions(+) create mode 100644 Userland/Libraries/LibWeb/HTML/NavigationType.h create mode 100644 Userland/Libraries/LibWeb/HTML/NavigationType.idl diff --git a/Userland/Libraries/LibWeb/HTML/NavigationType.h b/Userland/Libraries/LibWeb/HTML/NavigationType.h new file mode 100644 index 00000000000..388d0576c00 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/NavigationType.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023, Andrew Kaster + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +// 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 ""_string; + } +} + +} diff --git a/Userland/Libraries/LibWeb/HTML/NavigationType.idl b/Userland/Libraries/LibWeb/HTML/NavigationType.idl new file mode 100644 index 00000000000..8d6f6f321d7 --- /dev/null +++ b/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" +};