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,
|
|
|
|
};
|
|
|
|
|
2022-02-20 15:51:24 +01:00
|
|
|
virtual void run(Box const&, LayoutMode) = 0;
|
2020-11-22 13:38:18 +01:00
|
|
|
|
2022-02-20 15:51:24 +01:00
|
|
|
Box const& 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; }
|
2022-04-01 20:58:27 +03:00
|
|
|
FormattingContext const* parent() const { return m_parent; }
|
2020-11-25 20:08:52 +01:00
|
|
|
|
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
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
static bool creates_block_formatting_context(Box const&);
|
2020-12-05 20:10:39 +01:00
|
|
|
|
2022-02-20 15:51:24 +01:00
|
|
|
static float compute_width_for_replaced_element(FormattingState const&, ReplacedBox const&);
|
|
|
|
static float compute_height_for_replaced_element(FormattingState const&, ReplacedBox const&);
|
2020-12-11 22:27:09 +01:00
|
|
|
|
2022-02-27 10:10:45 +01:00
|
|
|
OwnPtr<FormattingContext> create_independent_formatting_context_if_needed(FormattingState&, Box const& child_box);
|
2021-10-17 18:24:07 +02:00
|
|
|
|
2022-02-12 19:54:09 +01:00
|
|
|
virtual void parent_context_did_dimension_child_root_box() { }
|
|
|
|
|
2022-07-08 00:40:53 +02: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 14:36:59 +01:00
|
|
|
|
|
|
|
float calculate_fit_content_height(Layout::Box const&, Optional<float> available_height) const;
|
|
|
|
float calculate_fit_content_width(Layout::Box const&, Optional<float> available_width) const;
|
|
|
|
|
2022-03-18 14:44:36 +01:00
|
|
|
virtual float greatest_child_width(Box const&);
|
|
|
|
|
2020-11-22 13:38:18 +01:00
|
|
|
protected:
|
2022-02-20 15:51:24 +01:00
|
|
|
FormattingContext(Type, FormattingState&, Box const&, FormattingContext* parent = nullptr);
|
2020-11-22 13:38:18 +01:00
|
|
|
|
2022-03-12 14:36:59 +01:00
|
|
|
float calculate_fit_content_size(float min_content_size, float max_content_size, Optional<float> available_space) const;
|
|
|
|
|
2022-02-20 15:51:24 +01:00
|
|
|
OwnPtr<FormattingContext> layout_inside(Box const&, LayoutMode);
|
2022-03-27 15:35:28 +02:00
|
|
|
void compute_inset(Box const& box);
|
2020-11-22 13:38:18 +01:00
|
|
|
|
2022-03-18 14:44:36 +01:00
|
|
|
struct SpaceUsedByFloats {
|
2022-03-17 12:30:30 +01:00
|
|
|
float left { 0 };
|
|
|
|
float right { 0 };
|
|
|
|
};
|
|
|
|
|
2020-11-22 13:38:18 +01:00
|
|
|
struct ShrinkToFitResult {
|
|
|
|
float preferred_width { 0 };
|
|
|
|
float preferred_minimum_width { 0 };
|
|
|
|
};
|
|
|
|
|
2022-02-20 15:51:24 +01:00
|
|
|
static float tentative_width_for_replaced_element(FormattingState const&, ReplacedBox const&, CSS::Length const& width);
|
|
|
|
static float tentative_height_for_replaced_element(FormattingState const&, ReplacedBox const&, CSS::Length const& height);
|
2022-03-01 23:21:24 +01:00
|
|
|
static float compute_auto_height_for_block_formatting_context_root(FormattingState const&, BlockContainer const&);
|
2022-03-01 18:51:25 +01:00
|
|
|
static float compute_auto_height_for_block_level_element(FormattingState const&, Box const&);
|
2022-04-06 14:18:33 +02:00
|
|
|
static float calculate_auto_height(FormattingState const& state, Box const& box);
|
2020-12-12 00:20:31 +01:00
|
|
|
|
2022-02-20 15:51:24 +01:00
|
|
|
ShrinkToFitResult calculate_shrink_to_fit_widths(Box const&);
|
2020-11-22 13:38:18 +01:00
|
|
|
|
2022-02-20 15:51:24 +01: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 18:18:46 +01:00
|
|
|
|
2021-10-15 01:25:12 +02:00
|
|
|
Type m_type {};
|
|
|
|
|
2020-11-25 20:08:52 +01:00
|
|
|
FormattingContext* m_parent { nullptr };
|
2022-02-20 15:51:24 +01:00
|
|
|
Box const& m_context_box;
|
2022-02-19 20:13:47 +01:00
|
|
|
|
|
|
|
FormattingState& m_state;
|
2020-11-22 13:38:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|