summaryrefslogtreecommitdiff
path: root/Userland/Applications/Browser/History.h
blob: e7891b29a1dc5453875843db9aa386ae29247f99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/URL.h>
#include <AK/Vector.h>

namespace Browser {

class History {
public:
    struct URLTitlePair {
        URL url;
        String title;
    };
    void dump() const;

    void push(const URL& url, const String& title);
    void update_title(const String& title);
    URLTitlePair current() const;

    const Vector<StringView> get_back_title_history();
    const Vector<StringView> get_forward_title_history();

    void go_back(int steps = 1);
    void go_forward(int steps = 1);

    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()); }
    void clear();

private:
    Vector<URLTitlePair> m_items;
    int m_current { -1 };
};

}