
The previous implementation used relative X offsets for both left and right-side floats. This made right-side floats super awkward, since we could only determine their X position once the width of the BFC root was known, and for BFC roots with automatic width, this was not even working at all most of the time. This patch changes the way we deal with floats so that BFC keeps track of the offset-from-edge for each float. The offset is the distance from the BFC root edge (left or right, depending on float direction) to the "innermost" margin edge of the floating box. Floating box are now laid out in two passes: while going through the normal flow layout, we put floats in their *static* position (i.e the position they would have occupied if they weren't floating) and then update the Y position value to the final one. The second pass occurs later on, when the BFC root has had its width assigned by the parent context. Once we know the root width, we can set the X position value of floating boxes. (Because the X position of right-side floats is relative to the right edge of the BFC root.)
38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Types.h>
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/Layout/BlockContainer.h>
|
|
#include <LibWeb/Layout/FormattingContext.h>
|
|
|
|
namespace Web::Layout {
|
|
|
|
class InlineFormattingContext final : public FormattingContext {
|
|
public:
|
|
InlineFormattingContext(FormattingState&, BlockContainer const& containing_block, BlockFormattingContext& parent);
|
|
~InlineFormattingContext();
|
|
|
|
BlockFormattingContext& parent();
|
|
BlockFormattingContext const& parent() const;
|
|
|
|
BlockContainer const& containing_block() const { return static_cast<BlockContainer const&>(context_box()); }
|
|
|
|
virtual void run(Box const&, LayoutMode) override;
|
|
|
|
void dimension_box_on_line(Box const&, LayoutMode);
|
|
|
|
float leftmost_x_offset_at(float y) const;
|
|
float available_space_for_line(float y) const;
|
|
|
|
private:
|
|
void generate_line_boxes(LayoutMode);
|
|
void apply_justification_to_fragments(FormattingState::NodeState const& containing_block_state, CSS::TextJustify, LineBox&, bool is_last_line);
|
|
};
|
|
|
|
}
|