mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-05 00:21:52 +00:00
We currently create a separate headless-browser application to serve two purposes: 1. Allow headless browsing to take a screenshot of a page or print its layout tree / internal text. 2. Run the LibWeb test framework. This patch migrates (1) to the main Ladybird executable. The --headless flag enables this mode. This matches the behavior of other browsers, and means we have one less executable to ship at distribution time. We want to avoid creating too many AppKit / Qt facilities in headless mode. So this involves some shuffling of application init to ensure we don't create them until after we've parsed the command line arguments. Namely, we avoid creating the NSApp in AppKit and QCoreApplication in Qt. Doing so also requires that we don't create the application event loop until we've parsed the command line as well, because the loop we create depends on whether we're creating those UI facilities.
44 lines
1.5 KiB
C++
44 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2024-2025, Tim Flynn <trflynn89@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibCore/Forward.h>
|
|
#include <LibGfx/Forward.h>
|
|
#include <LibWeb/Page/Page.h>
|
|
#include <LibWeb/PixelUnits.h>
|
|
#include <LibWebView/ViewImplementation.h>
|
|
|
|
namespace WebView {
|
|
|
|
class HeadlessWebView : public WebView::ViewImplementation {
|
|
public:
|
|
static NonnullOwnPtr<HeadlessWebView> create(Core::AnonymousBuffer theme, Web::DevicePixelSize window_size);
|
|
static NonnullOwnPtr<HeadlessWebView> create_child(HeadlessWebView&, u64 page_index);
|
|
|
|
protected:
|
|
HeadlessWebView(Core::AnonymousBuffer theme, Web::DevicePixelSize viewport_size);
|
|
|
|
void initialize_client(CreateNewClient) override;
|
|
void update_zoom() override;
|
|
|
|
virtual Web::DevicePixelSize viewport_size() const override { return m_viewport_size; }
|
|
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override { return widget_position; }
|
|
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override { return content_position; }
|
|
|
|
Core::AnonymousBuffer m_theme;
|
|
Web::DevicePixelSize m_viewport_size;
|
|
|
|
Web::Page::PendingDialog m_pending_dialog { Web::Page::PendingDialog::None };
|
|
Optional<String> m_pending_prompt_text;
|
|
|
|
// FIXME: We should implement UI-agnostic platform APIs to interact with the system clipboard.
|
|
Optional<Web::Clipboard::SystemClipboardItem> m_clipboard;
|
|
|
|
Vector<NonnullOwnPtr<HeadlessWebView>> m_child_web_views;
|
|
};
|
|
|
|
}
|