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