2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2021-09-08 06:27:46 -03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2021-03-07 09:46:20 -03:00
|
|
|
#include <LibGfx/Painter.h>
|
2020-03-07 06:32:51 -03:00
|
|
|
#include <LibWeb/Dump.h>
|
2021-09-08 06:27:46 -03:00
|
|
|
#include <LibWeb/Layout/InitialContainingBlock.h>
|
2021-05-30 07:36:53 -03:00
|
|
|
#include <LibWeb/Page/BrowsingContext.h>
|
2020-06-18 16:39:27 -03:00
|
|
|
#include <LibWeb/Painting/StackingContext.h>
|
2019-06-15 17:49:44 -03:00
|
|
|
|
2020-11-22 11:53:01 -03:00
|
|
|
namespace Web::Layout {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2021-09-08 06:27:46 -03:00
|
|
|
InitialContainingBlock::InitialContainingBlock(DOM::Document& document, NonnullRefPtr<CSS::StyleProperties> style)
|
2020-11-22 11:53:01 -03:00
|
|
|
: BlockBox(document, &document, move(style))
|
2019-06-15 17:49:44 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 06:27:46 -03:00
|
|
|
InitialContainingBlock::~InitialContainingBlock()
|
2019-06-15 17:49:44 -03:00
|
|
|
{
|
|
|
|
|
}
|
2019-06-16 16:35:03 -03:00
|
|
|
|
2021-09-08 06:27:46 -03:00
|
|
|
void InitialContainingBlock::build_stacking_context_tree()
|
2020-06-15 12:29:35 -03:00
|
|
|
{
|
|
|
|
|
if (stacking_context())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
set_stacking_context(make<StackingContext>(*this, nullptr));
|
|
|
|
|
|
2021-04-06 14:38:10 -03:00
|
|
|
for_each_in_inclusive_subtree_of_type<Box>([&](Box& box) {
|
2020-06-15 12:29:35 -03:00
|
|
|
if (&box == this)
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
if (!box.establishes_stacking_context()) {
|
2021-02-23 16:42:32 -03:00
|
|
|
VERIFY(!box.stacking_context());
|
2020-06-15 12:29:35 -03:00
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
}
|
|
|
|
|
auto* parent_context = box.enclosing_stacking_context();
|
2021-02-23 16:42:32 -03:00
|
|
|
VERIFY(parent_context);
|
2020-06-15 12:29:35 -03:00
|
|
|
box.set_stacking_context(make<StackingContext>(box, parent_context));
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 06:27:46 -03:00
|
|
|
void InitialContainingBlock::paint_all_phases(PaintContext& context)
|
2020-06-15 12:29:35 -03:00
|
|
|
{
|
2021-05-13 10:39:30 -03:00
|
|
|
context.painter().translate(-context.viewport_rect().location());
|
2021-05-07 13:03:25 -03:00
|
|
|
stacking_context()->paint(context);
|
2020-06-15 12:29:35 -03:00
|
|
|
}
|
|
|
|
|
|
2021-09-08 06:27:46 -03:00
|
|
|
HitTestResult InitialContainingBlock::hit_test(const Gfx::IntPoint& position, HitTestType type) const
|
2020-07-01 14:02:28 -03:00
|
|
|
{
|
2020-08-05 11:55:56 -03:00
|
|
|
return stacking_context()->hit_test(position, type);
|
2020-07-01 14:02:28 -03:00
|
|
|
}
|
|
|
|
|
|
2021-09-08 06:27:46 -03:00
|
|
|
void InitialContainingBlock::recompute_selection_states()
|
2020-08-21 12:50:41 -03:00
|
|
|
{
|
|
|
|
|
SelectionState state = SelectionState::None;
|
|
|
|
|
|
|
|
|
|
auto selection = this->selection().normalized();
|
|
|
|
|
|
2021-04-06 14:38:10 -03:00
|
|
|
for_each_in_inclusive_subtree([&](auto& layout_node) {
|
2020-08-21 12:50:41 -03:00
|
|
|
if (!selection.is_valid()) {
|
|
|
|
|
// Everything gets SelectionState::None.
|
|
|
|
|
} else if (&layout_node == selection.start().layout_node && &layout_node == selection.end().layout_node) {
|
|
|
|
|
state = SelectionState::StartAndEnd;
|
|
|
|
|
} else if (&layout_node == selection.start().layout_node) {
|
|
|
|
|
state = SelectionState::Start;
|
|
|
|
|
} else if (&layout_node == selection.end().layout_node) {
|
|
|
|
|
state = SelectionState::End;
|
|
|
|
|
} else {
|
|
|
|
|
if (state == SelectionState::Start)
|
|
|
|
|
state = SelectionState::Full;
|
|
|
|
|
else if (state == SelectionState::End || state == SelectionState::StartAndEnd)
|
|
|
|
|
state = SelectionState::None;
|
|
|
|
|
}
|
|
|
|
|
layout_node.set_selection_state(state);
|
|
|
|
|
return IterationDecision::Continue;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 06:27:46 -03:00
|
|
|
void InitialContainingBlock::set_selection(const LayoutRange& selection)
|
2020-08-21 12:54:44 -03:00
|
|
|
{
|
|
|
|
|
m_selection = selection;
|
|
|
|
|
recompute_selection_states();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-08 06:27:46 -03:00
|
|
|
void InitialContainingBlock::set_selection_end(const LayoutPosition& position)
|
2020-08-21 12:54:44 -03:00
|
|
|
{
|
|
|
|
|
m_selection.set_end(position);
|
|
|
|
|
recompute_selection_states();
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-07 06:27:02 -03:00
|
|
|
}
|