1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:37:36 +00:00

Browser: Simplify the History class and fix back/forward history push

This code was previously relying on the PageView::on_load_start hook
firing synchronously when calling PageView::load(). This was not
happening with WebContentView, so it broke the back/forward history.

Instead, we now differentiate between history navigations and normal
loads in Tab::load(). History navigations don't push new entries into
history, but instead just move the history pointer.
This commit is contained in:
Andreas Kling 2020-07-07 15:04:05 +02:00
parent b5e04cb070
commit 1493dd9dc6
5 changed files with 119 additions and 76 deletions

View file

@ -26,15 +26,17 @@
#pragma once
#include <AK/Optional.h>
#include <AK/String.h>
#include <AK/URL.h>
#include <AK/Vector.h>
template<typename T>
class History final {
namespace Browser {
class History {
public:
void push(const T& item);
T current() const;
void dump() const;
void push(const URL&);
URL current() const;
void go_back();
void go_forward();
@ -45,43 +47,8 @@ public:
void clear();
private:
Vector<T> m_items;
Vector<URL> m_items;
int m_current { -1 };
};
template<typename T>
inline void History<T>::push(const T& item)
{
m_items.shrink(m_current + 1);
m_items.append(item);
m_current++;
}
template<typename T>
inline T History<T>::current() const
{
if (m_current == -1)
return {};
return m_items[m_current];
}
template<typename T>
inline void History<T>::go_back()
{
ASSERT(can_go_back());
m_current--;
}
template<typename T>
inline void History<T>::go_forward()
{
ASSERT(can_go_forward());
m_current++;
}
template<typename T>
inline void History<T>::clear()
{
m_items = {};
m_current = -1;
}