History.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/URL.h>
  8. #include <AK/Vector.h>
  9. namespace WebView {
  10. class History {
  11. public:
  12. struct URLTitlePair {
  13. URL url;
  14. DeprecatedString title;
  15. };
  16. void dump() const;
  17. Vector<URLTitlePair> get_all_history_entries();
  18. void push(const URL& url, DeprecatedString const& title);
  19. void replace_current(const URL& url, DeprecatedString const& title);
  20. void update_title(DeprecatedString const& title);
  21. URLTitlePair current() const;
  22. Vector<StringView> const get_back_title_history();
  23. Vector<StringView> const get_forward_title_history();
  24. void go_back(int steps = 1);
  25. void go_forward(int steps = 1);
  26. bool can_go_back(int steps = 1) { return (m_current - steps) >= 0; }
  27. bool can_go_forward(int steps = 1) { return (m_current + steps) < static_cast<int>(m_items.size()); }
  28. void clear();
  29. bool is_empty() const { return m_items.is_empty(); }
  30. private:
  31. Vector<URLTitlePair> m_items;
  32. int m_current { -1 };
  33. };
  34. }