2020-06-08 20:31:49 +02:00
|
|
|
/*
|
2021-02-10 08:25:35 +01:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2020-06-08 20:31:49 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-08 20:31:49 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Noncopyable.h>
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
#include <AK/RefPtr.h>
|
2020-09-28 11:55:26 +02:00
|
|
|
#include <AK/URL.h>
|
2021-02-10 08:25:35 +01:00
|
|
|
#include <AK/WeakPtr.h>
|
|
|
|
#include <AK/Weakable.h>
|
2020-08-02 12:10:01 +02:00
|
|
|
#include <Kernel/API/KeyCode.h>
|
2020-06-08 20:31:49 +02:00
|
|
|
#include <LibGfx/Forward.h>
|
|
|
|
#include <LibGfx/Palette.h>
|
2021-02-10 08:25:35 +01:00
|
|
|
#include <LibGfx/StandardCursor.h>
|
2020-06-08 20:31:49 +02:00
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
|
|
|
namespace Web {
|
|
|
|
|
|
|
|
class PageClient;
|
|
|
|
|
2020-11-12 18:23:05 +01:00
|
|
|
class Page : public Weakable<Page> {
|
2020-06-08 20:31:49 +02:00
|
|
|
AK_MAKE_NONCOPYABLE(Page);
|
|
|
|
AK_MAKE_NONMOVABLE(Page);
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit Page(PageClient&);
|
|
|
|
~Page();
|
|
|
|
|
|
|
|
PageClient& client() { return m_client; }
|
|
|
|
const PageClient& client() const { return m_client; }
|
|
|
|
|
2021-05-30 12:36:53 +02:00
|
|
|
Web::BrowsingContext& top_level_browsing_context() { return *m_top_level_browsing_context; }
|
|
|
|
const Web::BrowsingContext& top_level_browsing_context() const { return *m_top_level_browsing_context; }
|
2020-06-08 20:31:49 +02:00
|
|
|
|
2021-05-30 12:36:53 +02:00
|
|
|
Web::BrowsingContext& focused_context();
|
|
|
|
const Web::BrowsingContext& focused_context() const { return const_cast<Page*>(this)->focused_context(); }
|
2020-08-14 11:33:20 +02:00
|
|
|
|
2021-05-30 12:36:53 +02:00
|
|
|
void set_focused_browsing_context(Badge<EventHandler>, BrowsingContext&);
|
2020-08-14 11:33:20 +02:00
|
|
|
|
2020-06-08 20:31:49 +02:00
|
|
|
void load(const URL&);
|
2020-09-28 11:55:26 +02:00
|
|
|
void load(const LoadRequest&);
|
2020-06-08 20:31:49 +02:00
|
|
|
|
2020-10-08 21:11:01 +01:00
|
|
|
void load_html(const StringView&, const URL&);
|
|
|
|
|
2020-06-10 10:57:59 +02:00
|
|
|
bool handle_mouseup(const Gfx::IntPoint&, unsigned button, unsigned modifiers);
|
|
|
|
bool handle_mousedown(const Gfx::IntPoint&, unsigned button, unsigned modifiers);
|
|
|
|
bool handle_mousemove(const Gfx::IntPoint&, unsigned buttons, unsigned modifiers);
|
2021-02-22 19:45:41 +01:00
|
|
|
bool handle_mousewheel(const Gfx::IntPoint&, unsigned button, unsigned modifiers, int wheel_delta);
|
2020-06-08 20:31:49 +02:00
|
|
|
|
2020-08-02 12:10:01 +02:00
|
|
|
bool handle_keydown(KeyCode, unsigned modifiers, u32 code_point);
|
|
|
|
|
2020-06-08 20:31:49 +02:00
|
|
|
Gfx::Palette palette() const;
|
2021-04-04 00:12:37 +02:00
|
|
|
Gfx::IntRect screen_rect() const;
|
2020-06-08 20:31:49 +02:00
|
|
|
|
2021-09-12 02:10:43 +02:00
|
|
|
bool is_same_origin_policy_enabled() const { return m_same_origin_policy_enabled; }
|
|
|
|
void set_same_origin_policy_enabled(bool b) { m_same_origin_policy_enabled = b; }
|
|
|
|
|
2020-06-08 20:31:49 +02:00
|
|
|
private:
|
|
|
|
PageClient& m_client;
|
|
|
|
|
2021-05-30 12:36:53 +02:00
|
|
|
RefPtr<BrowsingContext> m_top_level_browsing_context;
|
|
|
|
WeakPtr<BrowsingContext> m_focused_context;
|
2021-09-12 02:10:43 +02:00
|
|
|
|
|
|
|
bool m_same_origin_policy_enabled { true };
|
2020-06-08 20:31:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class PageClient {
|
|
|
|
public:
|
2020-06-17 20:26:59 +02:00
|
|
|
virtual Gfx::Palette palette() const = 0;
|
2021-04-04 00:12:37 +02:00
|
|
|
virtual Gfx::IntRect screen_rect() const = 0;
|
2021-05-30 12:36:53 +02:00
|
|
|
virtual void page_did_set_document_in_top_level_browsing_context(DOM::Document*) { }
|
2020-06-08 20:31:49 +02:00
|
|
|
virtual void page_did_change_title(const String&) { }
|
|
|
|
virtual void page_did_start_loading(const URL&) { }
|
2020-12-08 21:44:42 +01:00
|
|
|
virtual void page_did_finish_loading(const URL&) { }
|
2020-06-08 20:31:49 +02:00
|
|
|
virtual void page_did_change_selection() { }
|
2020-09-10 19:25:13 +02:00
|
|
|
virtual void page_did_request_cursor_change(Gfx::StandardCursor) { }
|
2020-06-27 14:21:58 -06:00
|
|
|
virtual void page_did_request_context_menu(const Gfx::IntPoint&) { }
|
2020-07-06 20:00:56 +02:00
|
|
|
virtual void page_did_request_link_context_menu(const Gfx::IntPoint&, const URL&, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { }
|
2020-10-02 19:01:51 +02:00
|
|
|
virtual void page_did_request_image_context_menu(const Gfx::IntPoint&, const URL&, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers, const Gfx::Bitmap*) { }
|
2020-07-06 19:41:10 +02:00
|
|
|
virtual void page_did_click_link(const URL&, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { }
|
|
|
|
virtual void page_did_middle_click_link(const URL&, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers) { }
|
2020-06-10 10:57:59 +02:00
|
|
|
virtual void page_did_enter_tooltip_area(const Gfx::IntPoint&, const String&) { }
|
2020-06-08 20:31:49 +02:00
|
|
|
virtual void page_did_leave_tooltip_area() { }
|
|
|
|
virtual void page_did_hover_link(const URL&) { }
|
|
|
|
virtual void page_did_unhover_link() { }
|
2020-06-10 10:57:59 +02:00
|
|
|
virtual void page_did_invalidate(const Gfx::IntRect&) { }
|
2020-06-08 21:35:31 +02:00
|
|
|
virtual void page_did_change_favicon(const Gfx::Bitmap&) { }
|
2020-06-23 18:02:08 +02:00
|
|
|
virtual void page_did_layout() { }
|
2021-09-08 11:22:44 +01:00
|
|
|
virtual void page_did_request_scroll(i32, i32) { }
|
2021-09-08 11:44:36 +01:00
|
|
|
virtual void page_did_request_scroll_to(Gfx::IntPoint const&) { }
|
2020-07-05 14:50:38 +02:00
|
|
|
virtual void page_did_request_scroll_into_view(const Gfx::IntRect&) { }
|
2020-09-12 11:56:13 +02:00
|
|
|
virtual void page_did_request_alert(const String&) { }
|
2021-02-10 08:37:13 +01:00
|
|
|
virtual bool page_did_request_confirm(const String&) { return false; }
|
2021-02-20 12:05:18 +01:00
|
|
|
virtual String page_did_request_prompt(const String&, const String&) { return {}; }
|
2021-04-13 17:30:41 -04:00
|
|
|
virtual String page_did_request_cookie(const URL&, Cookie::Source) { return {}; }
|
2021-04-15 10:36:20 -04:00
|
|
|
virtual void page_did_set_cookie(const URL&, const Cookie::ParsedCookie&, Cookie::Source) { }
|
2021-04-15 10:43:29 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~PageClient() = default;
|
2020-06-08 20:31:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|