mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 12:27:35 +00: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
2 changed files with 20 additions and 0 deletions
|
@ -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
|
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#clear-the-forward-session-history
|
||||||
void TraversableNavigable::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;
|
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;
|
Vector<int> get_all_used_history_steps() const;
|
||||||
void clear_the_forward_session_history();
|
void clear_the_forward_session_history();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue