2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2022-08-01 16:34:56 +02:00
|
|
|
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-10-04 15:50:04 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-10-09 21:25:29 +02:00
|
|
|
#include <AK/Function.h>
|
2019-10-04 15:50:04 +02:00
|
|
|
#include <AK/Noncopyable.h>
|
|
|
|
#include <AK/RefPtr.h>
|
2019-11-25 21:19:03 +01:00
|
|
|
#include <AK/WeakPtr.h>
|
2020-08-02 11:52:35 +02:00
|
|
|
#include <LibCore/Timer.h>
|
2020-06-06 13:02:44 +02:00
|
|
|
#include <LibGfx/Bitmap.h>
|
2020-02-06 12:04:00 +01:00
|
|
|
#include <LibGfx/Rect.h>
|
|
|
|
#include <LibGfx/Size.h>
|
2020-08-02 11:52:35 +02:00
|
|
|
#include <LibWeb/DOM/Position.h>
|
2021-09-09 02:07:32 +02:00
|
|
|
#include <LibWeb/HTML/BrowsingContextContainer.h>
|
2022-08-01 16:34:56 +02:00
|
|
|
#include <LibWeb/HTML/SessionHistoryEntry.h>
|
2020-06-06 13:02:44 +02:00
|
|
|
#include <LibWeb/Loader/FrameLoader.h>
|
2020-07-28 19:27:41 +02:00
|
|
|
#include <LibWeb/Page/EventHandler.h>
|
2020-03-07 10:32:51 +01:00
|
|
|
#include <LibWeb/TreeNode.h>
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2021-11-18 15:01:28 +01:00
|
|
|
namespace Web::HTML {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2021-05-30 12:36:53 +02:00
|
|
|
class BrowsingContext : public TreeNode<BrowsingContext> {
|
2019-10-04 15:50:04 +02:00
|
|
|
public:
|
2021-09-10 01:51:09 +02:00
|
|
|
static NonnullRefPtr<BrowsingContext> create_nested(Page& page, HTML::BrowsingContextContainer& container) { return adopt_ref(*new BrowsingContext(page, &container)); }
|
|
|
|
static NonnullRefPtr<BrowsingContext> create(Page& page) { return adopt_ref(*new BrowsingContext(page, nullptr)); }
|
2021-05-30 12:36:53 +02:00
|
|
|
~BrowsingContext();
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2021-01-30 12:25:33 +01:00
|
|
|
class ViewportClient {
|
|
|
|
public:
|
2022-03-14 13:21:51 -06:00
|
|
|
virtual ~ViewportClient() = default;
|
2021-09-08 11:12:22 +02:00
|
|
|
virtual void browsing_context_did_set_viewport_rect(Gfx::IntRect const&) = 0;
|
2021-01-30 12:25:33 +01:00
|
|
|
};
|
|
|
|
void register_viewport_client(ViewportClient&);
|
|
|
|
void unregister_viewport_client(ViewportClient&);
|
|
|
|
|
2022-03-01 21:17:53 +00:00
|
|
|
bool is_top_level() const;
|
2021-05-30 12:36:53 +02:00
|
|
|
bool is_focused_context() const;
|
2020-06-06 16:33:04 +02:00
|
|
|
|
2021-09-09 13:14:32 +02:00
|
|
|
DOM::Document const* active_document() const { return m_active_document; }
|
|
|
|
DOM::Document* active_document() { return m_active_document; }
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2021-09-09 13:14:32 +02:00
|
|
|
void set_active_document(DOM::Document*);
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2020-11-12 18:23:05 +01:00
|
|
|
Page* page() { return m_page; }
|
2021-09-08 10:43:20 +02:00
|
|
|
Page const* page() const { return m_page; }
|
2019-11-25 21:19:03 +01:00
|
|
|
|
2021-09-08 10:43:20 +02:00
|
|
|
Gfx::IntSize const& size() const { return m_size; }
|
|
|
|
void set_size(Gfx::IntSize const&);
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2022-02-15 13:01:48 +01:00
|
|
|
void set_needs_display();
|
2021-09-08 10:43:20 +02:00
|
|
|
void set_needs_display(Gfx::IntRect const&);
|
2020-06-06 13:02:44 +02:00
|
|
|
|
2021-09-08 12:22:28 +01:00
|
|
|
Gfx::IntPoint const& viewport_scroll_offset() const { return m_viewport_scroll_offset; }
|
2020-12-02 23:40:57 +01:00
|
|
|
Gfx::IntRect viewport_rect() const { return { m_viewport_scroll_offset, m_size }; }
|
2021-09-08 10:43:20 +02:00
|
|
|
void set_viewport_rect(Gfx::IntRect const&);
|
2019-12-18 20:54:23 +01:00
|
|
|
|
2020-06-06 13:02:44 +02:00
|
|
|
FrameLoader& loader() { return m_loader; }
|
2021-09-08 10:43:20 +02:00
|
|
|
FrameLoader const& loader() const { return m_loader; }
|
2020-06-06 13:02:44 +02:00
|
|
|
|
2021-11-18 15:01:28 +01:00
|
|
|
Web::EventHandler& event_handler() { return m_event_handler; }
|
|
|
|
Web::EventHandler const& event_handler() const { return m_event_handler; }
|
2020-06-07 14:40:38 +02:00
|
|
|
|
2022-04-06 15:32:38 +02:00
|
|
|
void scroll_to(Gfx::IntPoint const&);
|
2021-09-08 10:43:20 +02:00
|
|
|
void scroll_to_anchor(String const&);
|
2020-06-06 13:02:44 +02:00
|
|
|
|
2021-09-10 01:51:09 +02:00
|
|
|
BrowsingContext& top_level_browsing_context()
|
|
|
|
{
|
|
|
|
BrowsingContext* context = this;
|
|
|
|
while (context->parent())
|
|
|
|
context = context->parent();
|
|
|
|
return *context;
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowsingContext const& top_level_browsing_context() const { return const_cast<BrowsingContext*>(this)->top_level_browsing_context(); }
|
2020-06-06 15:08:36 +02:00
|
|
|
|
2022-03-15 14:37:58 +00:00
|
|
|
BrowsingContext* choose_a_browsing_context(StringView name, bool noopener);
|
|
|
|
|
2021-09-09 02:07:32 +02:00
|
|
|
HTML::BrowsingContextContainer* container() { return m_container; }
|
|
|
|
HTML::BrowsingContextContainer const* container() const { return m_container; }
|
2020-06-06 15:08:36 +02:00
|
|
|
|
2021-09-08 10:43:20 +02:00
|
|
|
Gfx::IntPoint to_top_level_position(Gfx::IntPoint const&);
|
|
|
|
Gfx::IntRect to_top_level_rect(Gfx::IntRect const&);
|
2020-06-08 20:31:49 +02:00
|
|
|
|
2021-09-08 10:43:20 +02:00
|
|
|
DOM::Position const& cursor_position() const { return m_cursor_position; }
|
2021-02-09 21:23:50 +01:00
|
|
|
void set_cursor_position(DOM::Position);
|
2021-05-18 22:01:12 +02:00
|
|
|
bool increment_cursor_position_offset();
|
|
|
|
bool decrement_cursor_position_offset();
|
2020-08-02 11:52:35 +02:00
|
|
|
|
|
|
|
bool cursor_blink_state() const { return m_cursor_blink_state; }
|
|
|
|
|
2020-08-06 19:21:59 +02:00
|
|
|
String selected_text() const;
|
2021-07-14 08:38:10 -04:00
|
|
|
void select_all();
|
2020-08-06 19:21:59 +02:00
|
|
|
|
2021-01-04 20:48:27 +01:00
|
|
|
void did_edit(Badge<EditEventHandler>);
|
|
|
|
|
2021-09-13 00:33:23 +03:00
|
|
|
void register_frame_nesting(AK::URL const&);
|
|
|
|
bool is_frame_nesting_allowed(AK::URL const&) const;
|
2021-04-19 14:30:08 +02:00
|
|
|
|
2021-09-13 00:33:23 +03:00
|
|
|
void set_frame_nesting_levels(HashMap<AK::URL, size_t> frame_nesting_levels) { m_frame_nesting_levels = move(frame_nesting_levels); };
|
|
|
|
HashMap<AK::URL, size_t> const& frame_nesting_levels() const { return m_frame_nesting_levels; }
|
2021-04-19 14:30:08 +02:00
|
|
|
|
2021-09-09 02:10:05 +02:00
|
|
|
DOM::Document* container_document();
|
|
|
|
DOM::Document const* container_document() const;
|
|
|
|
|
2021-10-03 17:05:58 +02:00
|
|
|
bool has_a_rendering_opportunity() const;
|
|
|
|
|
2022-02-06 18:45:29 +01:00
|
|
|
RefPtr<DOM::Node> currently_focused_area();
|
|
|
|
|
2022-03-16 17:15:11 +01:00
|
|
|
String const& name() const { return m_name; }
|
|
|
|
void set_name(String const& name) { m_name = name; }
|
|
|
|
|
2022-08-01 16:34:56 +02:00
|
|
|
Vector<SessionHistoryEntry>& session_history() { return m_session_history; }
|
|
|
|
Vector<SessionHistoryEntry> const& session_history() const { return m_session_history; }
|
|
|
|
|
2019-10-04 15:50:04 +02:00
|
|
|
private:
|
2021-09-10 01:51:09 +02:00
|
|
|
explicit BrowsingContext(Page&, HTML::BrowsingContextContainer*);
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2021-02-09 21:23:50 +01:00
|
|
|
void reset_cursor_blink_cycle();
|
|
|
|
|
2020-11-12 18:23:05 +01:00
|
|
|
WeakPtr<Page> m_page;
|
2021-09-08 11:17:43 +02:00
|
|
|
|
2020-06-06 13:02:44 +02:00
|
|
|
FrameLoader m_loader;
|
2021-11-18 15:01:28 +01:00
|
|
|
Web::EventHandler m_event_handler;
|
2020-06-06 13:02:44 +02:00
|
|
|
|
2022-08-01 16:34:56 +02:00
|
|
|
// https://html.spec.whatwg.org/multipage/history.html#session-history
|
|
|
|
Vector<SessionHistoryEntry> m_session_history;
|
|
|
|
|
2021-09-09 02:07:32 +02:00
|
|
|
WeakPtr<HTML::BrowsingContextContainer> m_container;
|
2021-09-09 13:14:32 +02:00
|
|
|
RefPtr<DOM::Document> m_active_document;
|
2020-06-10 10:57:59 +02:00
|
|
|
Gfx::IntSize m_size;
|
2020-12-02 23:40:57 +01:00
|
|
|
Gfx::IntPoint m_viewport_scroll_offset;
|
2020-08-02 11:52:35 +02:00
|
|
|
|
|
|
|
DOM::Position m_cursor_position;
|
|
|
|
RefPtr<Core::Timer> m_cursor_blink_timer;
|
|
|
|
bool m_cursor_blink_state { false };
|
2021-01-30 12:25:33 +01:00
|
|
|
|
|
|
|
HashTable<ViewportClient*> m_viewport_clients;
|
2021-04-19 14:30:08 +02:00
|
|
|
|
2021-09-13 00:33:23 +03:00
|
|
|
HashMap<AK::URL, size_t> m_frame_nesting_levels;
|
2022-03-16 17:15:11 +01:00
|
|
|
String m_name;
|
2019-10-04 15:50:04 +02:00
|
|
|
};
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
|
|
}
|