mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:17:44 +00:00
LibWeb: Basic support for display:inline-block with width:auto
We now implement the somewhat fuzzy shrink-to-fit algorithm when laying out inline-block elements with both block and inline children. Shrink-to-fit works by doing two speculative layouts of the entire subtree inside the current block, to compute two things: 1. Preferred minimum width: If we made a line break at every chance we had, how wide would the widest line be? 2. Preferred width: We break only when explicitly told to (e.g "<br>") How wide would the widest line be? We then shrink the width of the inline-block element to an appropriate value based on the above, taking the available width in the containing block into consideration (sans all the box model fluff.) To make the speculative layouts possible, plumb a LayoutMode enum throughout the layout system since it needs to be respected in various places. Note that this is quite hackish and I'm sure there are smarter ways to do a lot of this. But it does kinda work! :^)
This commit is contained in:
parent
4e8bcda4d1
commit
f01af62313
24 changed files with 184 additions and 97 deletions
|
@ -99,7 +99,13 @@ public:
|
|||
|
||||
bool is_inline_block() const { return is_inline() && is_block(); }
|
||||
|
||||
virtual void layout();
|
||||
enum class LayoutMode {
|
||||
Default,
|
||||
AllPossibleLineBreaks,
|
||||
OnlyRequiredLineBreaks,
|
||||
};
|
||||
|
||||
virtual void layout(LayoutMode);
|
||||
virtual void render(RenderingContext&);
|
||||
|
||||
const LayoutBlock* containing_block() const;
|
||||
|
@ -111,11 +117,11 @@ public:
|
|||
LayoutNodeWithStyle* parent();
|
||||
const LayoutNodeWithStyle* parent() const;
|
||||
|
||||
void inserted_into(LayoutNode&) {}
|
||||
void removed_from(LayoutNode&) {}
|
||||
void children_changed() {}
|
||||
void inserted_into(LayoutNode&) { }
|
||||
void removed_from(LayoutNode&) { }
|
||||
void children_changed() { }
|
||||
|
||||
virtual void split_into_lines(LayoutBlock& container);
|
||||
virtual void split_into_lines(LayoutBlock& container, LayoutMode);
|
||||
|
||||
bool is_visible() const { return m_visible; }
|
||||
void set_visible(bool visible) { m_visible = visible; }
|
||||
|
@ -161,7 +167,7 @@ private:
|
|||
|
||||
class LayoutNodeWithStyle : public LayoutNode {
|
||||
public:
|
||||
virtual ~LayoutNodeWithStyle() override {}
|
||||
virtual ~LayoutNodeWithStyle() override { }
|
||||
|
||||
const StyleProperties& style() const { return m_style; }
|
||||
void set_style(const StyleProperties& style) { m_style = style; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue