2020-11-22 13:38:18 +01:00
|
|
|
/*
|
2022-02-19 20:13:47 +01:00
|
|
|
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
2020-11-22 13:38:18 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-22 13:38:18 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-10-10 15:56:29 +02:00
|
|
|
#include <AK/OwnPtr.h>
|
2020-11-22 13:38:18 +01:00
|
|
|
#include <LibWeb/Forward.h>
|
2022-02-19 20:13:47 +01:00
|
|
|
#include <LibWeb/Layout/FormattingState.h>
|
2020-11-22 13:38:18 +01:00
|
|
|
|
|
|
|
namespace Web::Layout {
|
|
|
|
|
|
|
|
class FormattingContext {
|
|
|
|
public:
|
2021-10-17 18:24:07 +02:00
|
|
|
virtual ~FormattingContext();
|
|
|
|
|
2021-10-15 01:25:12 +02:00
|
|
|
enum class Type {
|
|
|
|
Block,
|
|
|
|
Inline,
|
|
|
|
Flex,
|
|
|
|
Table,
|
|
|
|
SVG,
|
|
|
|
};
|
|
|
|
|
2020-12-06 19:48:02 +01:00
|
|
|
virtual void run(Box&, LayoutMode) = 0;
|
2020-11-22 13:38:18 +01:00
|
|
|
|
2021-10-15 23:15:12 +02:00
|
|
|
Box& context_box() { return m_context_box; }
|
|
|
|
const Box& context_box() const { return m_context_box; }
|
2020-11-22 13:38:18 +01:00
|
|
|
|
2020-11-25 20:08:52 +01:00
|
|
|
FormattingContext* parent() { return m_parent; }
|
|
|
|
const FormattingContext* parent() const { return m_parent; }
|
|
|
|
|
2021-10-15 01:25:12 +02:00
|
|
|
Type type() const { return m_type; }
|
|
|
|
bool is_block_formatting_context() const { return type() == Type::Block; }
|
|
|
|
|
2021-09-15 12:19:42 +01:00
|
|
|
virtual bool inhibits_floating() const { return false; }
|
2020-12-05 20:10:39 +01:00
|
|
|
|
|
|
|
static bool creates_block_formatting_context(const Box&);
|
|
|
|
|
2020-12-11 22:27:09 +01:00
|
|
|
static float compute_width_for_replaced_element(const ReplacedBox&);
|
|
|
|
static float compute_height_for_replaced_element(const ReplacedBox&);
|
|
|
|
|
2021-10-17 18:24:07 +02:00
|
|
|
OwnPtr<FormattingContext> create_independent_formatting_context_if_needed(Box& child_box);
|
|
|
|
|
2022-02-12 19:54:09 +01:00
|
|
|
virtual void parent_context_did_dimension_child_root_box() { }
|
|
|
|
|
2020-11-22 13:38:18 +01:00
|
|
|
protected:
|
2022-02-19 20:13:47 +01:00
|
|
|
FormattingContext(Type, FormattingState&, Box&, FormattingContext* parent = nullptr);
|
2020-11-22 13:38:18 +01:00
|
|
|
|
2021-10-17 18:24:07 +02:00
|
|
|
OwnPtr<FormattingContext> layout_inside(Box&, LayoutMode);
|
2020-11-22 13:38:18 +01:00
|
|
|
|
|
|
|
struct ShrinkToFitResult {
|
|
|
|
float preferred_width { 0 };
|
|
|
|
float preferred_minimum_width { 0 };
|
|
|
|
};
|
|
|
|
|
2020-12-12 00:20:31 +01:00
|
|
|
static float tentative_width_for_replaced_element(const ReplacedBox&, const CSS::Length& width);
|
2021-10-14 23:15:36 +02:00
|
|
|
static float tentative_height_for_replaced_element(const ReplacedBox&, const CSS::Length& height);
|
2021-10-27 23:48:06 +02:00
|
|
|
enum ConsiderFloats {
|
|
|
|
Yes,
|
|
|
|
No,
|
|
|
|
};
|
|
|
|
static float compute_auto_height_for_block_level_element(Box const&, ConsiderFloats consider_floats = ConsiderFloats::Yes);
|
2020-12-12 00:20:31 +01:00
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
ShrinkToFitResult calculate_shrink_to_fit_widths(Box&);
|
2020-11-22 13:38:18 +01:00
|
|
|
|
2021-01-06 18:18:46 +01:00
|
|
|
void layout_absolutely_positioned_element(Box&);
|
|
|
|
void compute_width_for_absolutely_positioned_element(Box&);
|
|
|
|
void compute_width_for_absolutely_positioned_non_replaced_element(Box&);
|
|
|
|
void compute_width_for_absolutely_positioned_replaced_element(ReplacedBox&);
|
|
|
|
void compute_height_for_absolutely_positioned_element(Box&);
|
|
|
|
void compute_height_for_absolutely_positioned_non_replaced_element(Box&);
|
|
|
|
void compute_height_for_absolutely_positioned_replaced_element(ReplacedBox&);
|
|
|
|
|
2021-10-15 01:25:12 +02:00
|
|
|
Type m_type {};
|
|
|
|
|
2020-11-25 20:08:52 +01:00
|
|
|
FormattingContext* m_parent { nullptr };
|
2021-10-15 23:15:12 +02:00
|
|
|
Box& m_context_box;
|
2022-02-19 20:13:47 +01:00
|
|
|
|
|
|
|
FormattingState& m_state;
|
2020-11-22 13:38:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|