2020-06-05 23:36:02 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-06-05 23:36:02 +02:00
|
|
|
*/
|
|
|
|
|
2021-01-24 15:28:26 +01:00
|
|
|
#include <AK/Debug.h>
|
2021-02-10 08:25:35 +01:00
|
|
|
#include <LibGfx/Painter.h>
|
2020-06-05 23:36:02 +02:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
2021-11-18 15:01:28 +01:00
|
|
|
#include <LibWeb/HTML/BrowsingContext.h>
|
2020-11-22 15:53:01 +01:00
|
|
|
#include <LibWeb/Layout/FrameBox.h>
|
2021-09-08 11:27:46 +02:00
|
|
|
#include <LibWeb/Layout/InitialContainingBlock.h>
|
2022-03-10 11:26:01 +01:00
|
|
|
#include <LibWeb/Painting/Paintable.h>
|
2020-06-05 23:36:02 +02:00
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
namespace Web::Layout {
|
2020-06-05 23:36:02 +02:00
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
FrameBox::FrameBox(DOM::Document& document, DOM::Element& element, NonnullRefPtr<CSS::StyleProperties> style)
|
|
|
|
: ReplacedBox(document, element, move(style))
|
2020-06-05 23:36:02 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
FrameBox::~FrameBox()
|
2020-06-05 23:36:02 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
void FrameBox::prepare_for_replaced_layout()
|
2020-06-05 23:36:02 +02:00
|
|
|
{
|
2021-05-30 12:36:53 +02:00
|
|
|
VERIFY(dom_node().nested_browsing_context());
|
2020-06-06 13:10:11 +02:00
|
|
|
|
2020-06-05 23:36:02 +02:00
|
|
|
// FIXME: Do proper error checking, etc.
|
2020-11-22 14:46:36 +01:00
|
|
|
set_intrinsic_width(dom_node().attribute(HTML::AttributeNames::width).to_int().value_or(300));
|
|
|
|
set_intrinsic_height(dom_node().attribute(HTML::AttributeNames::height).to_int().value_or(150));
|
2020-06-05 23:36:02 +02:00
|
|
|
}
|
|
|
|
|
2022-03-10 02:13:28 +01:00
|
|
|
void FrameBox::paint(PaintContext& context, Painting::PaintPhase phase)
|
2020-06-05 23:36:02 +02:00
|
|
|
{
|
2020-11-22 15:53:01 +01:00
|
|
|
ReplacedBox::paint(context, phase);
|
2020-06-05 23:36:02 +02:00
|
|
|
|
2022-03-10 02:13:28 +01:00
|
|
|
if (phase == Painting::PaintPhase::Foreground) {
|
2022-02-16 22:51:25 +00:00
|
|
|
auto* hosted_document = dom_node().content_document_without_origin_check();
|
2020-06-18 18:57:35 +02:00
|
|
|
if (!hosted_document)
|
|
|
|
return;
|
|
|
|
auto* hosted_layout_tree = hosted_document->layout_node();
|
|
|
|
if (!hosted_layout_tree)
|
|
|
|
return;
|
2020-06-14 15:31:47 +02:00
|
|
|
|
2020-06-18 18:57:35 +02:00
|
|
|
context.painter().save();
|
|
|
|
auto old_viewport_rect = context.viewport_rect();
|
2020-06-05 23:36:02 +02:00
|
|
|
|
2022-03-09 23:53:41 +01:00
|
|
|
context.painter().add_clip_rect(enclosing_int_rect(m_paint_box->absolute_rect()));
|
|
|
|
context.painter().translate(m_paint_box->absolute_x(), m_paint_box->absolute_y());
|
2020-06-05 23:36:02 +02:00
|
|
|
|
2021-05-30 12:36:53 +02:00
|
|
|
context.set_viewport_rect({ {}, dom_node().nested_browsing_context()->size() });
|
2021-09-08 11:27:46 +02:00
|
|
|
const_cast<Layout::InitialContainingBlock*>(hosted_layout_tree)->paint_all_phases(context);
|
2020-06-05 23:36:02 +02:00
|
|
|
|
2020-06-18 18:57:35 +02:00
|
|
|
context.set_viewport_rect(old_viewport_rect);
|
|
|
|
context.painter().restore();
|
2020-08-14 11:33:20 +02:00
|
|
|
|
2021-05-01 21:10:08 +02:00
|
|
|
if constexpr (HIGHLIGHT_FOCUSED_FRAME_DEBUG) {
|
2021-05-30 12:36:53 +02:00
|
|
|
if (dom_node().nested_browsing_context()->is_focused_context()) {
|
2022-03-09 23:53:41 +01:00
|
|
|
context.painter().draw_rect(m_paint_box->absolute_rect().to_type<int>(), Color::Cyan);
|
2021-05-01 21:10:08 +02:00
|
|
|
}
|
2020-08-14 11:33:20 +02:00
|
|
|
}
|
2020-06-18 18:57:35 +02:00
|
|
|
}
|
2020-06-05 23:36:02 +02:00
|
|
|
}
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
void FrameBox::did_set_rect()
|
2020-06-05 23:36:02 +02:00
|
|
|
{
|
2020-11-22 15:53:01 +01:00
|
|
|
ReplacedBox::did_set_rect();
|
2020-06-05 23:36:02 +02:00
|
|
|
|
2021-05-30 12:36:53 +02:00
|
|
|
VERIFY(dom_node().nested_browsing_context());
|
2022-03-09 23:53:41 +01:00
|
|
|
dom_node().nested_browsing_context()->set_size(m_paint_box->content_size().to_type<int>());
|
2020-06-05 23:36:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|