2020-06-08 20:31:49 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-08 20:31:49 +02:00
|
|
|
*/
|
|
|
|
|
2021-11-18 15:01:28 +01:00
|
|
|
#include <LibWeb/HTML/BrowsingContext.h>
|
2020-07-28 19:27:41 +02:00
|
|
|
#include <LibWeb/Page/Page.h>
|
2020-06-08 20:31:49 +02:00
|
|
|
|
|
|
|
namespace Web {
|
|
|
|
|
|
|
|
Page::Page(PageClient& client)
|
|
|
|
: m_client(client)
|
|
|
|
{
|
2021-11-18 15:01:28 +01:00
|
|
|
m_top_level_browsing_context = HTML::BrowsingContext::create(*this);
|
2020-06-08 20:31:49 +02:00
|
|
|
}
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
Page::~Page() = default;
|
2020-06-08 20:31:49 +02:00
|
|
|
|
2021-11-18 15:01:28 +01:00
|
|
|
HTML::BrowsingContext& Page::focused_context()
|
2020-08-14 11:33:20 +02:00
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
if (m_focused_context)
|
|
|
|
return *m_focused_context;
|
|
|
|
return top_level_browsing_context();
|
2020-08-14 11:33:20 +02:00
|
|
|
}
|
|
|
|
|
2021-11-18 15:01:28 +01:00
|
|
|
void Page::set_focused_browsing_context(Badge<EventHandler>, HTML::BrowsingContext& browsing_context)
|
2020-08-14 11:33:20 +02:00
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
m_focused_context = browsing_context.make_weak_ptr();
|
2020-08-14 11:33:20 +02:00
|
|
|
}
|
|
|
|
|
2021-09-13 00:33:23 +03:00
|
|
|
void Page::load(const AK::URL& url)
|
2020-06-08 20:31:49 +02:00
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
top_level_browsing_context().loader().load(url, FrameLoader::Type::Navigation);
|
2020-06-08 20:31:49 +02:00
|
|
|
}
|
|
|
|
|
2021-09-11 21:15:15 -07:00
|
|
|
void Page::load(LoadRequest& request)
|
2020-09-28 11:55:26 +02:00
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
top_level_browsing_context().loader().load(request, FrameLoader::Type::Navigation);
|
2020-09-28 11:55:26 +02:00
|
|
|
}
|
|
|
|
|
2021-11-11 00:55:02 +01:00
|
|
|
void Page::load_html(StringView html, const AK::URL& url)
|
2020-10-08 21:11:01 +01:00
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
top_level_browsing_context().loader().load_html(html, url);
|
2020-10-08 21:11:01 +01:00
|
|
|
}
|
|
|
|
|
2020-06-08 20:31:49 +02:00
|
|
|
Gfx::Palette Page::palette() const
|
|
|
|
{
|
2020-06-17 20:26:59 +02:00
|
|
|
return m_client.palette();
|
2020-06-08 20:31:49 +02:00
|
|
|
}
|
|
|
|
|
2021-04-04 00:12:37 +02:00
|
|
|
Gfx::IntRect Page::screen_rect() const
|
|
|
|
{
|
|
|
|
return m_client.screen_rect();
|
|
|
|
}
|
|
|
|
|
2021-10-26 17:00:10 +01:00
|
|
|
CSS::PreferredColorScheme Page::preferred_color_scheme() const
|
|
|
|
{
|
|
|
|
return m_client.preferred_color_scheme();
|
|
|
|
}
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
bool Page::handle_mousewheel(Gfx::IntPoint const& position, unsigned button, unsigned modifiers, int wheel_delta_x, int wheel_delta_y)
|
2021-02-22 19:45:41 +01:00
|
|
|
{
|
2021-12-13 23:22:28 +01:00
|
|
|
return top_level_browsing_context().event_handler().handle_mousewheel(position, button, modifiers, wheel_delta_x, wheel_delta_y);
|
2021-02-22 19:45:41 +01:00
|
|
|
}
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
bool Page::handle_mouseup(Gfx::IntPoint const& position, unsigned button, unsigned modifiers)
|
2020-06-08 20:31:49 +02:00
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
return top_level_browsing_context().event_handler().handle_mouseup(position, button, modifiers);
|
2020-06-08 20:31:49 +02:00
|
|
|
}
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
bool Page::handle_mousedown(Gfx::IntPoint const& position, unsigned button, unsigned modifiers)
|
2020-06-08 20:31:49 +02:00
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
return top_level_browsing_context().event_handler().handle_mousedown(position, button, modifiers);
|
2020-06-08 20:31:49 +02:00
|
|
|
}
|
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
bool Page::handle_mousemove(Gfx::IntPoint const& position, unsigned buttons, unsigned modifiers)
|
2020-06-08 20:31:49 +02:00
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
return top_level_browsing_context().event_handler().handle_mousemove(position, buttons, modifiers);
|
2020-06-08 20:31:49 +02:00
|
|
|
}
|
|
|
|
|
2022-06-14 19:38:32 +02:00
|
|
|
bool Page::handle_doubleclick(Gfx::IntPoint const& position, unsigned button, unsigned modifiers)
|
|
|
|
{
|
|
|
|
return top_level_browsing_context().event_handler().handle_doubleclick(position, button, modifiers);
|
|
|
|
}
|
|
|
|
|
2020-08-02 12:10:01 +02:00
|
|
|
bool Page::handle_keydown(KeyCode key, unsigned modifiers, u32 code_point)
|
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
return focused_context().event_handler().handle_keydown(key, modifiers, code_point);
|
2020-08-02 12:10:01 +02:00
|
|
|
}
|
|
|
|
|
2021-09-28 15:39:35 +02:00
|
|
|
bool Page::handle_keyup(KeyCode key, unsigned modifiers, u32 code_point)
|
|
|
|
{
|
|
|
|
return focused_context().event_handler().handle_keyup(key, modifiers, code_point);
|
|
|
|
}
|
|
|
|
|
2020-06-08 20:31:49 +02:00
|
|
|
}
|