ladybird/Userland/Libraries/LibWeb/Layout/AvailableSpace.cpp
Andreas Kling 9c44634ca5 LibWeb: Reorganize layout algorithms around available space
This is a big and messy change, and here's the gist:

- AvaliableSpace is now 2x AvailableSize (width and height)

- Layout algorithms are redesigned around the idea of available space

- When doing layout across nested formatting contexts, the parent
  context tells the child context how much space is available for the
  child's root box in both axes.

- "Available space" replaces "containing block width" in most places.

- The width and height in a box's UsedValues are considered to be
  definite after they're assigned to. Marking something as having
  definite size is no longer a separate step,

This probably introduces various regressions, but the big win here is
that our layout system now works with available space, just like the
specs are written. Fixing issues will be much easier going forward,
since you don't need to do nearly as much conversion from "spec logic"
to "LibWeb logic" as you previously did.
2022-10-02 21:14:02 +02:00

59 lines
1.2 KiB
C++

/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Layout/AvailableSpace.h>
#include <math.h>
namespace Web::Layout {
AvailableSize AvailableSize::make_definite(float value)
{
return AvailableSize { Type::Definite, value };
}
AvailableSize AvailableSize::make_indefinite()
{
return AvailableSize { Type::Indefinite, INFINITY };
}
AvailableSize AvailableSize::make_min_content()
{
return AvailableSize { Type::MinContent, 0 };
}
AvailableSize AvailableSize::make_max_content()
{
return AvailableSize { Type::MaxContent, INFINITY };
}
String AvailableSize::to_string() const
{
switch (m_type) {
case Type::Definite:
return String::formatted("definite({})", m_value);
case Type::Indefinite:
return "indefinite";
case Type::MinContent:
return "min-content";
case Type::MaxContent:
return "max-content";
}
VERIFY_NOT_REACHED();
}
String AvailableSpace::to_string() const
{
return String::formatted("{} x {}", width, height);
}
AvailableSize::AvailableSize(Type type, float value)
: m_type(type)
, m_value(value)
{
}
}