2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-10-17 21:25:38 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Vector.h>
|
2024-03-18 16:22:27 +13:00
|
|
|
#include <LibURL/URL.h>
|
2019-10-17 21:25:38 +02:00
|
|
|
|
2023-08-31 07:07:07 -04:00
|
|
|
namespace WebView {
|
2020-07-07 15:04:05 +02:00
|
|
|
|
|
|
|
|
class History {
|
2019-10-17 21:25:38 +02:00
|
|
|
public:
|
2021-05-26 20:19:35 +02:00
|
|
|
struct URLTitlePair {
|
2024-03-18 16:22:27 +13:00
|
|
|
URL::URL url;
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString title;
|
2021-05-26 20:19:35 +02:00
|
|
|
};
|
2020-07-07 15:04:05 +02:00
|
|
|
void dump() const;
|
2022-12-10 16:50:47 +01:00
|
|
|
Vector<URLTitlePair> get_all_history_entries();
|
2020-07-07 15:04:05 +02:00
|
|
|
|
2024-03-18 16:22:27 +13:00
|
|
|
void push(const URL::URL& url, ByteString const& title);
|
|
|
|
|
void replace_current(const URL::URL& url, ByteString const& title);
|
2023-12-16 17:49:34 +03:30
|
|
|
void update_title(ByteString const& title);
|
2021-05-26 20:19:35 +02:00
|
|
|
URLTitlePair current() const;
|
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
Vector<StringView> const get_back_title_history();
|
|
|
|
|
Vector<StringView> const get_forward_title_history();
|
2019-10-17 21:25:38 +02:00
|
|
|
|
2021-05-24 00:58:00 +02:00
|
|
|
void go_back(int steps = 1);
|
|
|
|
|
void go_forward(int steps = 1);
|
2019-10-17 21:25:38 +02:00
|
|
|
|
2021-05-24 00:58:00 +02:00
|
|
|
bool can_go_back(int steps = 1) { return (m_current - steps) >= 0; }
|
|
|
|
|
bool can_go_forward(int steps = 1) { return (m_current + steps) < static_cast<int>(m_items.size()); }
|
2019-10-17 21:25:38 +02:00
|
|
|
void clear();
|
|
|
|
|
|
2023-08-28 15:54:36 -04:00
|
|
|
bool is_empty() const { return m_items.is_empty(); }
|
|
|
|
|
|
2019-10-17 21:25:38 +02:00
|
|
|
private:
|
2021-05-26 20:19:35 +02:00
|
|
|
Vector<URLTitlePair> m_items;
|
2019-10-17 21:25:38 +02:00
|
|
|
int m_current { -1 };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|