From e73ad78ba6097884003cafd626063551c390cb68 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 5 May 2020 16:06:22 +0200 Subject: [PATCH] LibWeb: Add support for "display: inline-block" This display type is implemented using a LayoutBlock that is_inline(). Basically it behaves like a block internally, and its children are laid out in the normal block layout fashion. Externally however, it behaves like an atomic inline-level box. Layout of inline-block boxes happens in three stages: 1. The outer dimensions of the block are computed during the recursive normal layout pass. We skip positioning, but lay out children. 2. Later on, during line layout in the *containing block*, the inline block now contributes a linebox fragment. When linebox fragments are positioned, we learn the final position of the inline block. That's when we set the inline block's position. 3. We re-layout the inline block's children once again. This is done to make sure they end up in the right position. The layout tree doesn't use relative offsets, so after we position the inline block in (2), its children will not have its positions updated. Relayout moves all children of inline blocks to the right place. This is a rather naive approach but it does get the basic behavior into place so we can iterate on it. :^) --- Base/home/anon/www/inline-block.html | 20 ++++++++++++++++++++ Base/home/anon/www/welcome.html | 1 + Libraries/LibWeb/DOM/Element.cpp | 7 +++++-- Libraries/LibWeb/Layout/LayoutBlock.cpp | 22 +++++++++++++++++++++- Libraries/LibWeb/Layout/LayoutBlock.h | 2 ++ Libraries/LibWeb/Layout/LayoutNode.h | 2 ++ 6 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 Base/home/anon/www/inline-block.html diff --git a/Base/home/anon/www/inline-block.html b/Base/home/anon/www/inline-block.html new file mode 100644 index 00000000000..72ecf0d0992 --- /dev/null +++ b/Base/home/anon/www/inline-block.html @@ -0,0 +1,20 @@ + + + + display: inline-block + + + +
Hello friends! This div has display: inline-block :^)
+
Hello friends! That means its laid out like a block on the inside.
+
Hello friends! But it acts like an atomic inline box on the outside!
+ + diff --git a/Base/home/anon/www/welcome.html b/Base/home/anon/www/welcome.html index d9ed0eb87ae..2fffcb8f6cc 100644 --- a/Base/home/anon/www/welcome.html +++ b/Base/home/anon/www/welcome.html @@ -28,6 +28,7 @@ span#ua {

Your user agent is:

Some small test pages: