LibWeb: Implement "get the used step" for traversable navigables

Implements https://html.spec.whatwg.org/multipage/browsing-the-web.html#getting-the-used-step
This commit is contained in:
Aliaksandr Kalenik 2023-06-19 21:08:26 +03:00 committed by Andreas Kling
parent 5b06e43938
commit 9c1087de8c
Notes: sideshowbarker 2024-07-16 20:12:13 +09:00
2 changed files with 20 additions and 0 deletions

View File

@ -171,6 +171,25 @@ TraversableNavigable::HistoryObjectLengthAndIndex TraversableNavigable::get_the_
};
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#getting-the-used-step
int TraversableNavigable::get_the_used_step(int step) const
{
// 1. Let steps be the result of getting all used history steps within traversable.
auto steps = get_all_used_history_steps();
// 2. Return the greatest item in steps that is less than or equal to step.
VERIFY(!steps.is_empty());
Optional<int> result;
for (size_t i = 0; i < steps.size(); i++) {
if (steps[i] <= step) {
if (!result.has_value() || (result.value() < steps[i])) {
result = steps[i];
}
}
}
return result.value();
}
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#clear-the-forward-session-history
void TraversableNavigable::clear_the_forward_session_history()
{

View File

@ -36,6 +36,7 @@ public:
};
HistoryObjectLengthAndIndex get_the_history_object_length_and_index(int) const;
int get_the_used_step(int step) const;
Vector<int> get_all_used_history_steps() const;
void clear_the_forward_session_history();