2020-06-17 17:31:42 +02:00
|
|
|
/*
|
2021-04-11 16:49:25 +02:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2020-06-17 17:31:42 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-17 17:31:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "PageHost.h"
|
2020-06-17 18:00:18 +02:00
|
|
|
#include "ClientConnection.h"
|
2020-06-17 17:31:42 +02:00
|
|
|
#include <LibGfx/Painter.h>
|
|
|
|
|
#include <LibGfx/SystemTheme.h>
|
2021-04-15 10:36:20 -04:00
|
|
|
#include <LibWeb/Cookie/ParsedCookie.h>
|
2021-09-08 11:27:46 +02:00
|
|
|
#include <LibWeb/Layout/InitialContainingBlock.h>
|
2021-05-30 12:36:53 +02:00
|
|
|
#include <LibWeb/Page/BrowsingContext.h>
|
2020-06-17 18:00:18 +02:00
|
|
|
#include <WebContent/WebContentClientEndpoint.h>
|
2020-06-17 17:31:42 +02:00
|
|
|
|
|
|
|
|
namespace WebContent {
|
|
|
|
|
|
2020-06-17 18:00:18 +02:00
|
|
|
PageHost::PageHost(ClientConnection& client)
|
|
|
|
|
: m_client(client)
|
|
|
|
|
, m_page(make<Web::Page>(*this))
|
2020-06-17 17:31:42 +02:00
|
|
|
{
|
|
|
|
|
setup_palette();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PageHost::~PageHost()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageHost::setup_palette()
|
|
|
|
|
{
|
|
|
|
|
// FIXME: Get the proper palette from our peer somehow
|
2021-01-16 17:22:35 +01:00
|
|
|
auto buffer = Core::AnonymousBuffer::create_with_size(sizeof(Gfx::SystemTheme));
|
|
|
|
|
auto* theme = buffer.data<Gfx::SystemTheme>();
|
2020-06-17 17:31:42 +02:00
|
|
|
theme->color[(int)Gfx::ColorRole::Window] = Color::Magenta;
|
|
|
|
|
theme->color[(int)Gfx::ColorRole::WindowText] = Color::Cyan;
|
2021-01-16 17:22:35 +01:00
|
|
|
m_palette_impl = Gfx::PaletteImpl::create_with_anonymous_buffer(buffer);
|
2020-06-17 17:31:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Gfx::Palette PageHost::palette() const
|
|
|
|
|
{
|
|
|
|
|
return Gfx::Palette(*m_palette_impl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageHost::set_palette_impl(const Gfx::PaletteImpl& impl)
|
|
|
|
|
{
|
|
|
|
|
m_palette_impl = impl;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 11:27:46 +02:00
|
|
|
Web::Layout::InitialContainingBlock* PageHost::layout_root()
|
2020-06-17 17:31:42 +02:00
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
auto* document = page().top_level_browsing_context().document();
|
2020-06-17 17:31:42 +02:00
|
|
|
if (!document)
|
2020-07-04 23:19:32 +02:00
|
|
|
return nullptr;
|
|
|
|
|
return document->layout_node();
|
|
|
|
|
}
|
2020-06-17 17:31:42 +02:00
|
|
|
|
2020-07-04 23:19:32 +02:00
|
|
|
void PageHost::paint(const Gfx::IntRect& content_rect, Gfx::Bitmap& target)
|
|
|
|
|
{
|
|
|
|
|
Gfx::Painter painter(target);
|
|
|
|
|
Gfx::IntRect bitmap_rect { {}, content_rect.size() };
|
|
|
|
|
|
|
|
|
|
auto* layout_root = this->layout_root();
|
2020-06-17 17:31:42 +02:00
|
|
|
if (!layout_root) {
|
2020-07-04 23:19:32 +02:00
|
|
|
painter.fill_rect(bitmap_rect, Color::White);
|
2020-06-17 17:31:42 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-06 02:29:18 +02:00
|
|
|
Web::PaintContext context(painter, palette(), content_rect.top_left());
|
2021-01-31 09:06:25 +01:00
|
|
|
context.set_should_show_line_box_borders(m_should_show_line_box_borders);
|
2020-06-17 17:31:42 +02:00
|
|
|
context.set_viewport_rect(content_rect);
|
2020-06-18 18:57:35 +02:00
|
|
|
layout_root->paint_all_phases(context);
|
2020-06-17 17:31:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageHost::set_viewport_rect(const Gfx::IntRect& rect)
|
|
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
page().top_level_browsing_context().set_viewport_rect(rect);
|
2020-06-17 17:31:42 +02:00
|
|
|
}
|
|
|
|
|
|
2020-06-17 18:00:18 +02:00
|
|
|
void PageHost::page_did_invalidate(const Gfx::IntRect& content_rect)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_invalidate_content_rect(content_rect);
|
2020-06-17 18:00:18 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-04 20:57:57 +02:00
|
|
|
void PageHost::page_did_change_selection()
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_change_selection();
|
2020-07-04 20:57:57 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-27 21:12:12 +00:00
|
|
|
void PageHost::page_did_request_cursor_change(Gfx::StandardCursor cursor)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_request_cursor_change((u32)cursor);
|
2021-02-27 21:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-04 23:19:32 +02:00
|
|
|
void PageHost::page_did_layout()
|
|
|
|
|
{
|
|
|
|
|
auto* layout_root = this->layout_root();
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(layout_root);
|
2020-07-04 23:19:32 +02:00
|
|
|
auto content_size = enclosing_int_rect(layout_root->absolute_rect()).size();
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_layout(content_size);
|
2020-07-04 23:19:32 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-04 23:40:17 +02:00
|
|
|
void PageHost::page_did_change_title(const String& title)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_change_title(title);
|
2020-07-04 23:40:17 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 08:39:07 +11:00
|
|
|
void PageHost::page_did_request_scroll(int wheel_delta)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_request_scroll(wheel_delta);
|
2021-03-02 08:39:07 +11:00
|
|
|
}
|
|
|
|
|
|
2020-07-05 15:43:43 +02:00
|
|
|
void PageHost::page_did_request_scroll_into_view(const Gfx::IntRect& rect)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_request_scroll_into_view(rect);
|
2020-07-05 15:43:43 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-30 12:10:06 -04:00
|
|
|
void PageHost::page_did_enter_tooltip_area(const Gfx::IntPoint& content_position, const String& title)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_enter_tooltip_area(content_position, title);
|
2021-03-30 12:10:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageHost::page_did_leave_tooltip_area()
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_leave_tooltip_area();
|
2021-03-30 12:10:06 -04:00
|
|
|
}
|
|
|
|
|
|
2020-07-05 16:59:20 +02:00
|
|
|
void PageHost::page_did_hover_link(const URL& url)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_hover_link(url);
|
2020-07-05 16:59:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageHost::page_did_unhover_link()
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_unhover_link();
|
2020-07-05 16:59:20 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-06 20:01:46 +02:00
|
|
|
void PageHost::page_did_click_link(const URL& url, const String& target, unsigned modifiers)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_click_link(url, target, modifiers);
|
2020-07-06 20:01:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageHost::page_did_middle_click_link(const URL& url, [[maybe_unused]] const String& target, [[maybe_unused]] unsigned modifiers)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_middle_click_link(url, target, modifiers);
|
2020-07-06 20:01:46 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-06 21:58:16 +02:00
|
|
|
void PageHost::page_did_start_loading(const URL& url)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_start_loading(url);
|
2020-07-06 21:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
2020-12-08 21:44:42 +01:00
|
|
|
void PageHost::page_did_finish_loading(const URL& url)
|
|
|
|
|
{
|
2021-09-04 12:18:22 +01:00
|
|
|
// FIXME: This is called after the page has finished loading, which means any log messages
|
|
|
|
|
// that happen *while* it is loading (such as inline <script>s) will be lost.
|
|
|
|
|
m_client.initialize_js_console({});
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_finish_loading(url);
|
2020-12-08 21:44:42 +01:00
|
|
|
}
|
|
|
|
|
|
2020-07-07 12:24:29 +02:00
|
|
|
void PageHost::page_did_request_context_menu(const Gfx::IntPoint& content_position)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_request_context_menu(content_position);
|
2020-07-07 12:24:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PageHost::page_did_request_link_context_menu(const Gfx::IntPoint& content_position, const URL& url, const String& target, unsigned modifiers)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_request_link_context_menu(content_position, url, target, modifiers);
|
2020-07-07 12:24:29 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-12 11:56:13 +02:00
|
|
|
void PageHost::page_did_request_alert(const String& message)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.did_request_alert(message);
|
2020-09-12 11:56:13 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-10 08:48:28 +01:00
|
|
|
bool PageHost::page_did_request_confirm(const String& message)
|
|
|
|
|
{
|
2021-05-03 13:55:29 +02:00
|
|
|
return m_client.did_request_confirm(message);
|
2021-02-10 08:48:28 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-20 12:05:18 +01:00
|
|
|
String PageHost::page_did_request_prompt(const String& message, const String& default_)
|
|
|
|
|
{
|
2021-05-03 13:55:29 +02:00
|
|
|
return m_client.did_request_prompt(message, default_);
|
2021-02-20 12:05:18 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-26 10:41:25 -04:00
|
|
|
void PageHost::page_did_change_favicon(const Gfx::Bitmap& favicon)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_change_favicon(favicon.to_shareable_bitmap());
|
2021-03-26 10:41:25 -04:00
|
|
|
}
|
|
|
|
|
|
2021-04-11 16:49:25 +02:00
|
|
|
void PageHost::page_did_request_image_context_menu(const Gfx::IntPoint& content_position, const URL& url, const String& target, unsigned modifiers, const Gfx::Bitmap* bitmap)
|
|
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_request_image_context_menu(content_position, url, target, modifiers, bitmap->to_shareable_bitmap());
|
2021-04-11 16:49:25 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-13 17:30:41 -04:00
|
|
|
String PageHost::page_did_request_cookie(const URL& url, Web::Cookie::Source source)
|
2021-04-11 10:54:11 -04:00
|
|
|
{
|
2021-05-03 13:55:29 +02:00
|
|
|
return m_client.did_request_cookie(url, static_cast<u8>(source));
|
2021-04-11 10:54:11 -04:00
|
|
|
}
|
|
|
|
|
|
2021-04-15 10:36:20 -04:00
|
|
|
void PageHost::page_did_set_cookie(const URL& url, const Web::Cookie::ParsedCookie& cookie, Web::Cookie::Source source)
|
2021-04-11 10:54:11 -04:00
|
|
|
{
|
2021-05-03 13:33:59 +02:00
|
|
|
m_client.async_did_set_cookie(url, cookie, static_cast<u8>(source));
|
2021-04-11 10:54:11 -04:00
|
|
|
}
|
|
|
|
|
|
2020-06-17 17:31:42 +02:00
|
|
|
}
|