2020-11-22 09:38:18 -03:00
|
|
|
/*
|
2022-02-19 16:13:47 -03:00
|
|
|
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
2020-11-22 09:38:18 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-22 09:38:18 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-10-10 10:56:29 -03:00
|
|
|
#include <AK/OwnPtr.h>
|
2020-11-22 09:38:18 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
2022-07-16 18:30:32 -03:00
|
|
|
#include <LibWeb/Layout/LayoutState.h>
|
2020-11-22 09:38:18 -03:00
|
|
|
|
|
|
|
|
namespace Web::Layout {
|
|
|
|
|
|
|
|
|
|
class FormattingContext {
|
|
|
|
|
public:
|
2021-10-17 13:24:07 -03:00
|
|
|
virtual ~FormattingContext();
|
|
|
|
|
|
2021-10-14 20:25:12 -03:00
|
|
|
enum class Type {
|
|
|
|
|
Block,
|
|
|
|
|
Inline,
|
|
|
|
|
Flex,
|
|
|
|
|
Table,
|
|
|
|
|
SVG,
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-20 11:51:24 -03:00
|
|
|
virtual void run(Box const&, LayoutMode) = 0;
|
2020-11-22 09:38:18 -03:00
|
|
|
|
2022-09-24 08:39:43 -03:00
|
|
|
// This function returns the automatic content height of the context's root box.
|
|
|
|
|
virtual float automatic_content_height() const = 0;
|
|
|
|
|
|
2022-02-20 11:51:24 -03:00
|
|
|
Box const& context_box() const { return m_context_box; }
|
2020-11-22 09:38:18 -03:00
|
|
|
|
2020-11-25 16:08:52 -03:00
|
|
|
FormattingContext* parent() { return m_parent; }
|
2022-04-01 14:58:27 -03:00
|
|
|
FormattingContext const* parent() const { return m_parent; }
|
2020-11-25 16:08:52 -03:00
|
|
|
|
2021-10-14 20:25:12 -03:00
|
|
|
Type type() const { return m_type; }
|
|
|
|
|
bool is_block_formatting_context() const { return type() == Type::Block; }
|
|
|
|
|
|
2021-09-15 08:19:42 -03:00
|
|
|
virtual bool inhibits_floating() const { return false; }
|
2020-12-05 16:10:39 -03:00
|
|
|
|
2022-04-01 14:58:27 -03:00
|
|
|
static bool creates_block_formatting_context(Box const&);
|
2020-12-05 16:10:39 -03:00
|
|
|
|
2022-07-16 18:30:32 -03:00
|
|
|
static float compute_width_for_replaced_element(LayoutState const&, ReplacedBox const&);
|
|
|
|
|
static float compute_height_for_replaced_element(LayoutState const&, ReplacedBox const&);
|
2020-12-11 18:27:09 -03:00
|
|
|
|
2022-07-16 18:30:32 -03:00
|
|
|
OwnPtr<FormattingContext> create_independent_formatting_context_if_needed(LayoutState&, Box const& child_box);
|
2021-10-17 13:24:07 -03:00
|
|
|
|
2022-02-12 15:54:09 -03:00
|
|
|
virtual void parent_context_did_dimension_child_root_box() { }
|
|
|
|
|
|
2022-07-07 19:40:53 -03:00
|
|
|
float calculate_min_content_width(Layout::Box const&) const;
|
|
|
|
|
float calculate_max_content_width(Layout::Box const&) const;
|
|
|
|
|
float calculate_min_content_height(Layout::Box const&) const;
|
|
|
|
|
float calculate_max_content_height(Layout::Box const&) const;
|
2022-03-12 10:36:59 -03:00
|
|
|
|
2022-07-20 12:59:46 -03:00
|
|
|
float calculate_fit_content_height(Layout::Box const&, SizeConstraint, Optional<float> available_height) const;
|
|
|
|
|
float calculate_fit_content_width(Layout::Box const&, SizeConstraint, Optional<float> available_width) const;
|
2022-03-12 10:36:59 -03:00
|
|
|
|
2022-03-18 10:44:36 -03:00
|
|
|
virtual float greatest_child_width(Box const&);
|
|
|
|
|
|
2022-07-09 10:17:47 -03:00
|
|
|
float containing_block_width_for(Box const& box) const { return containing_block_width_for(box, m_state); }
|
|
|
|
|
float containing_block_height_for(Box const& box) const { return containing_block_height_for(box, m_state); }
|
|
|
|
|
|
2022-07-16 18:30:32 -03:00
|
|
|
static float containing_block_width_for(Box const&, LayoutState const&);
|
|
|
|
|
static float containing_block_height_for(Box const&, LayoutState const&);
|
2022-07-09 10:17:47 -03:00
|
|
|
|
2022-07-20 13:12:12 -03:00
|
|
|
virtual void run_intrinsic_sizing(Box const&);
|
2022-07-10 17:06:20 -03:00
|
|
|
|
2022-08-10 14:19:44 -03:00
|
|
|
float compute_box_y_position_with_respect_to_siblings(Box const&, LayoutState::UsedValues const&);
|
|
|
|
|
|
2020-11-22 09:38:18 -03:00
|
|
|
protected:
|
2022-07-16 18:30:32 -03:00
|
|
|
FormattingContext(Type, LayoutState&, Box const&, FormattingContext* parent = nullptr);
|
2020-11-22 09:38:18 -03:00
|
|
|
|
2022-07-20 12:59:46 -03:00
|
|
|
float calculate_fit_content_size(float min_content_size, float max_content_size, SizeConstraint, Optional<float> available_space) const;
|
2022-03-12 10:36:59 -03:00
|
|
|
|
2022-02-20 11:51:24 -03:00
|
|
|
OwnPtr<FormattingContext> layout_inside(Box const&, LayoutMode);
|
2022-03-27 10:35:28 -03:00
|
|
|
void compute_inset(Box const& box);
|
2020-11-22 09:38:18 -03:00
|
|
|
|
2022-03-18 10:44:36 -03:00
|
|
|
struct SpaceUsedByFloats {
|
2022-03-17 08:30:30 -03:00
|
|
|
float left { 0 };
|
|
|
|
|
float right { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-22 09:38:18 -03:00
|
|
|
struct ShrinkToFitResult {
|
|
|
|
|
float preferred_width { 0 };
|
|
|
|
|
float preferred_minimum_width { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-16 18:30:32 -03:00
|
|
|
static float tentative_width_for_replaced_element(LayoutState const&, ReplacedBox const&, CSS::LengthPercentage const& computed_width);
|
|
|
|
|
static float tentative_height_for_replaced_element(LayoutState const&, ReplacedBox const&, CSS::LengthPercentage const& computed_height);
|
|
|
|
|
static float compute_auto_height_for_block_formatting_context_root(LayoutState const&, BlockContainer const&);
|
|
|
|
|
static float compute_auto_height_for_block_level_element(LayoutState const&, Box const&);
|
2020-12-11 20:20:31 -03:00
|
|
|
|
2022-02-20 11:51:24 -03:00
|
|
|
ShrinkToFitResult calculate_shrink_to_fit_widths(Box const&);
|
2020-11-22 09:38:18 -03:00
|
|
|
|
2022-02-20 11:51:24 -03:00
|
|
|
void layout_absolutely_positioned_element(Box const&);
|
|
|
|
|
void compute_width_for_absolutely_positioned_element(Box const&);
|
|
|
|
|
void compute_width_for_absolutely_positioned_non_replaced_element(Box const&);
|
|
|
|
|
void compute_width_for_absolutely_positioned_replaced_element(ReplacedBox const&);
|
|
|
|
|
void compute_height_for_absolutely_positioned_element(Box const&);
|
|
|
|
|
void compute_height_for_absolutely_positioned_non_replaced_element(Box const&);
|
|
|
|
|
void compute_height_for_absolutely_positioned_replaced_element(ReplacedBox const&);
|
2021-01-06 14:18:46 -03:00
|
|
|
|
2021-10-14 20:25:12 -03:00
|
|
|
Type m_type {};
|
|
|
|
|
|
2020-11-25 16:08:52 -03:00
|
|
|
FormattingContext* m_parent { nullptr };
|
2022-02-20 11:51:24 -03:00
|
|
|
Box const& m_context_box;
|
2022-02-19 16:13:47 -03:00
|
|
|
|
2022-07-16 18:30:32 -03:00
|
|
|
LayoutState& m_state;
|
2020-11-22 09:38:18 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|