mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
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:
parent
5b06e43938
commit
9c1087de8c
Notes:
sideshowbarker
2024-07-16 20:12:13 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/9c1087de8c Pull-request: https://github.com/SerenityOS/serenity/pull/19490
@ -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()
|
||||
{
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user