2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2021-02-09 21:23:50 +01:00
|
|
|
* Copyright (c) 2018-2021, 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>
|
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
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
namespace Web {
|
|
|
|
|
|
2021-05-30 12:36:53 +02:00
|
|
|
class BrowsingContext : public TreeNode<BrowsingContext> {
|
2019-10-04 15:50:04 +02:00
|
|
|
public:
|
2021-05-30 12:36:53 +02:00
|
|
|
static NonnullRefPtr<BrowsingContext> create_nested(DOM::Element& host_element, BrowsingContext& top_level_browsing_context) { return adopt_ref(*new BrowsingContext(host_element, top_level_browsing_context)); }
|
|
|
|
|
static NonnullRefPtr<BrowsingContext> create(Page& page) { return adopt_ref(*new BrowsingContext(page)); }
|
|
|
|
|
~BrowsingContext();
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2021-01-30 12:25:33 +01:00
|
|
|
class ViewportClient {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~ViewportClient() { }
|
|
|
|
|
virtual void frame_did_set_viewport_rect(const Gfx::IntRect&) = 0;
|
|
|
|
|
};
|
|
|
|
|
void register_viewport_client(ViewportClient&);
|
|
|
|
|
void unregister_viewport_client(ViewportClient&);
|
|
|
|
|
|
2021-05-30 12:36:53 +02:00
|
|
|
bool is_top_level() const { return this == &m_top_level_browsing_context; }
|
|
|
|
|
bool is_focused_context() const;
|
2020-06-06 16:33:04 +02:00
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
const DOM::Document* document() const { return m_document; }
|
|
|
|
|
DOM::Document* document() { return m_document; }
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
void set_document(DOM::Document*);
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2020-11-12 18:23:05 +01:00
|
|
|
Page* page() { return m_page; }
|
|
|
|
|
const Page* page() const { return m_page; }
|
2019-11-25 21:19:03 +01:00
|
|
|
|
2020-06-10 10:57:59 +02:00
|
|
|
const Gfx::IntSize& size() const { return m_size; }
|
|
|
|
|
void set_size(const Gfx::IntSize&);
|
2019-10-04 15:50:04 +02:00
|
|
|
|
2020-06-10 10:57:59 +02:00
|
|
|
void set_needs_display(const Gfx::IntRect&);
|
2020-06-06 13:02:44 +02:00
|
|
|
|
2020-12-02 23:40:57 +01:00
|
|
|
void set_viewport_scroll_offset(const Gfx::IntPoint&);
|
|
|
|
|
Gfx::IntRect viewport_rect() const { return { m_viewport_scroll_offset, m_size }; }
|
2021-02-09 22:40:16 +01:00
|
|
|
void set_viewport_rect(const Gfx::IntRect&);
|
2019-12-18 20:54:23 +01:00
|
|
|
|
2020-06-06 13:02:44 +02:00
|
|
|
FrameLoader& loader() { return m_loader; }
|
|
|
|
|
const FrameLoader& loader() const { return m_loader; }
|
|
|
|
|
|
2020-06-07 14:40:38 +02:00
|
|
|
EventHandler& event_handler() { return m_event_handler; }
|
|
|
|
|
const EventHandler& event_handler() const { return m_event_handler; }
|
|
|
|
|
|
2020-06-06 13:02:44 +02:00
|
|
|
void scroll_to_anchor(const String&);
|
|
|
|
|
|
2021-05-30 12:36:53 +02:00
|
|
|
BrowsingContext& top_level_browsing_context() { return m_top_level_browsing_context; }
|
|
|
|
|
BrowsingContext const& top_level_browsing_context() const { return m_top_level_browsing_context; }
|
2020-06-06 15:08:36 +02:00
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
DOM::Element* host_element() { return m_host_element; }
|
|
|
|
|
const DOM::Element* host_element() const { return m_host_element; }
|
2020-06-06 15:08:36 +02:00
|
|
|
|
2021-05-30 12:36:53 +02:00
|
|
|
Gfx::IntPoint to_top_level_position(const Gfx::IntPoint&);
|
|
|
|
|
Gfx::IntRect to_top_level_rect(const Gfx::IntRect&);
|
2020-06-08 20:31:49 +02:00
|
|
|
|
2020-08-02 11:52:35 +02:00
|
|
|
const DOM::Position& 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-04-19 14:30:08 +02:00
|
|
|
void register_frame_nesting(URL const&);
|
|
|
|
|
bool is_frame_nesting_allowed(URL const&) const;
|
|
|
|
|
|
2021-07-10 01:44:02 +02:00
|
|
|
void set_frame_nesting_levels(HashMap<URL, size_t> frame_nesting_levels) { m_frame_nesting_levels = move(frame_nesting_levels); };
|
2021-04-19 14:30:08 +02:00
|
|
|
HashMap<URL, size_t> const& frame_nesting_levels() const { return m_frame_nesting_levels; }
|
|
|
|
|
|
2019-10-04 15:50:04 +02:00
|
|
|
private:
|
2021-09-08 02:07:39 +02:00
|
|
|
explicit BrowsingContext(Page&, DOM::Element* host_element, BrowsingContext& top_level_browsing_context);
|
2021-05-30 12:36:53 +02:00
|
|
|
explicit BrowsingContext(DOM::Element& host_element, BrowsingContext& top_level_browsing_context);
|
|
|
|
|
explicit BrowsingContext(Page&);
|
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-05-30 12:36:53 +02:00
|
|
|
BrowsingContext& m_top_level_browsing_context;
|
2020-06-06 15:08:36 +02:00
|
|
|
|
2020-06-06 13:02:44 +02:00
|
|
|
FrameLoader m_loader;
|
2020-06-07 14:40:38 +02:00
|
|
|
EventHandler m_event_handler;
|
2020-06-06 13:02:44 +02:00
|
|
|
|
2020-07-26 19:37:56 +02:00
|
|
|
WeakPtr<DOM::Element> m_host_element;
|
|
|
|
|
RefPtr<DOM::Document> m_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
|
|
|
|
|
|
|
|
HashMap<URL, size_t> m_frame_nesting_levels;
|
2019-10-04 15:50:04 +02:00
|
|
|
};
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
|
|
|
}
|