Commit graph

14687 commits

Author SHA1 Message Date
Andreas Kling ab9d9709b9 LibWeb: Give flex containers with percentage cross size some dimensions
Instead of making them zero-sized on the cross axis, just treat
percentage sizes like auto for now. Better to have *some* size than none
at all.
2022-03-13 00:04:51 +01:00
Andreas Kling bd94f2c4c8 LibWeb: Add a debug helper to dump current state of an FFC 2022-03-13 00:04:51 +01:00
Andreas Kling 201afb50c7 LibWeb: Make Element::recompute_style() really compare properties
It's not enough to compare StyleProperties pointers to see if something
changed, we have to do a deep compare.
2022-03-13 00:04:51 +01:00
Andreas Kling 1223c88e68 LibWeb: Mark input elements for style update in set_checked()
When the checkedness changes, :checked selectors may yield different
results, so we have to update style.
2022-03-13 00:04:51 +01:00
Andreas Kling 630f2e0ee9 LibWeb: Make StyleProperties::operator==(StyleProperties) actually work
It was comparing against itself, oopsie!
2022-03-13 00:04:51 +01:00
Andreas Kling ad8d65fd6e LibWeb: Fix calculation of hypothetical cross size in column flex layout
Simplify automatic cross sizing of items in flex-direction:column by
using the fit-content width directly.

There's obviously a lot more nuance to this, but for now this makes
flex items with both width:auto and height:auto actually get some height
in column flex layouts.
2022-03-13 00:04:51 +01:00
Andreas Kling 2f3d7a7c36 LibWeb: Swap min-content and max-content intrinsic sizes if needed
I'm a little confused about intrinsic heights *really* work, and I'm
struggling to extract that information from the spec. In the meantime,
let's ensure that min-content is always smaller than (or equal to)
max-content so that other math works as expected.
2022-03-13 00:04:51 +01:00
Andreas Kling 4a14c4dae8 LibWeb: Support the CSS 'unset' value
This works as 'inherit' for inherited properties and 'initial' for
everything else.
2022-03-13 00:04:51 +01:00
Andreas Kling 515db5fc1b LibWeb: Make Layout::FormattingState copies shallow
Previously, each NodeState in a FormattingState was shared with the
parent FormattingState, but the HashMap of NodeState had to be copied
when making FormattingState copies.

This patch makes copying instant by keeping a pointer to the parent
FormattingState instead. When fetching immutable state via get(), we may
now return a reference to a NodeState owned by a parent FormattingState.

get_mutable() will copy any NodeState found in the ancestor chain before
making a brand new one.
2022-03-13 00:04:51 +01:00
Andreas Kling b6097cf724 LibWeb: Add fast_is<SVG::SVGSVGElement>() 2022-03-13 00:04:51 +01:00
Andreas Kling 8c91e8016c LibWeb: Handle many more cases with intrinsic/auto sizing in flex layout
The flexbox specification barely even handwaves about automatically
sized items, but there's actually a lot of work to do in order for them
to get the correct size.

This patch is messy, but does make significant progress on supporting
flex items with indefinite width and/or height.

There's a fair amount of nested layout going on here, but do note that
we'll be hitting the intrinsic sizes cache whenever possible.
2022-03-13 00:04:51 +01:00
Andreas Kling 3f2b17f602 LibWeb: Add functions for calculating intrinsic sizes of a Layout::Box
FormattingContext can now calculate the intrinsic sizes (min-content and
max-content in both axes) for a given Layout::Box.

This is a rather expensive operation, as it necessitates performing two
throwaway layouts of the subtree rooted at the box. Fortunately, we can
cache the results of these calculations, as intrinsic sizes don't change
based on other context around the box. They are intrinsic after all. :^)
2022-03-13 00:04:51 +01:00
Andreas Kling aa969cc591 LibWeb: Make Layout::SVGBox a BlockContainer again
This wasn't worth the headache of trying to make SVG boxes work together
with BFC right now. Let's just make it a block container once again, and
have its corresponding SVGPaintable inherit from PaintableWithLines.

We'll have to revisit this as SVG support improves.
2022-03-13 00:04:51 +01:00
Andreas Kling e4eb6d4f1f LibWeb: Add FFC helpers for resolving definite main/cross sizes
Although something has a definite size, we may still have to "resolve"
it, since FFC is quite liberal in what it considers to be definite.

Let's put that logic in a set of helper functions.
2022-03-13 00:04:51 +01:00
Andreas Kling 5c8e7217f7 LibWeb: Remove ad-hoc setup step from FFC layout algorithm
This step will not be necessary when we implement indefinite size
calculations more correctly.
2022-03-13 00:04:51 +01:00
Andreas Kling 12ac6861e3 LibWeb: Improve how layout nodes decide whether they have definite sizes
1. Make this decision *after* we've inserted the layout node into the
   layout tree. Otherwise, we can't reach its containing block!
2. Per css-sizing-3, consider auto-sized blocks whose sizes resolve
   solely against other definite sizes as definite themselves.

In particular, (2) makes us consider width:auto block children of a
definite-size containing block as having definite size. This becomes
very important in flex layout.
2022-03-13 00:04:51 +01:00
Andreas Kling d201378750 LibWeb: Apply non-CSS presentational hints before author styles
According to css-cascade-4, we should apply presentational hints from
content attributes *before* author styles.
2022-03-13 00:04:51 +01:00
Andreas Kling 6de10858b9 LibWeb: Only collapse vertical margin between BlockContainer siblings
If there's some non-block-level box (like an SVG element of some kind)
between to blocks, just skip over the non-block for purposes of margin
collapsing. This is basically a hack, and something we'll need to
improve as part of our general SVG support.
2022-03-13 00:04:51 +01:00
Andreas Kling 43b8f65d82 LibWeb: Support indefinite flex container cross sizes
Instead of assuming that any indefinite cross size must be "auto", check
what is actually is, and resolve it accordingly.
2022-03-13 00:04:51 +01:00
Andreas Kling a3a10b2379 LibWeb: Fix flex line alignment in single-line flex containers
For single-line flex containers, center the only flex line along the
cross axis. Alignment of multi-line flex containers are left as a FIXME.

This patch also moves out the assignment of final metrics to the
FormattingState from align_all_flex_lines() to a separate function.
2022-03-13 00:04:51 +01:00
Andreas Kling 1dfb3d555c LibWeb: Remove FFC::cross_size_is_absolute_or_resolved_nicely()
This is now answered authoritatively by Layout::Box itself.
2022-03-13 00:04:51 +01:00
Andreas Kling 1ce1af5d8b LibWeb: Improve FFC step 7 (hypothetical cross size)
- Avoid performing inside layout on definite-size flex items (since
  their computed size can be used as-is.)

- Use FormattingState::clone() to generate a throwaway layout instead of
  mutating the tree in-place.

- Update spec link & comments based on current CSSWG draft. The latest
  version is quite a bit clearer on how this should work.
2022-03-13 00:04:51 +01:00
Andreas Kling b904bff838 LibWeb: Put available space information in an FFC member
This makes it easier for each step of the flex layout algorithm to
access this information.
2022-03-13 00:04:51 +01:00
Andreas Kling 88302b0dca LibWeb: Layout inside of flex items at the end of FFC layout
Instead of doing internal child layout incrementally as we go, save it
for the end of flex layout. The code will become simpler if we can focus
on simply computing the dimensions of each flex item while we're doing
the main FFC algorithm.
2022-03-13 00:04:51 +01:00
Andreas Kling 7c5b578df9 LibWeb: Move unrelated things out of FFC step 1
Setting some initial width and height on the flex container is totally
unrelated to the "generate anonymous flex items" step.
2022-03-13 00:04:51 +01:00
Andreas Kling 3506a91349 LibWeb: Avoid unnecessary layout_inside() in FFC step 1
We don't need to perform inside layout here. The only information we
need in this step is whether an anonymous block container has nothing
but empty-or-whitespace text children.

This information is already accurate after the initial layout tree
construction. Performing a layout does not change the answer. It does
however have many other side effects, so let's defer those.
2022-03-13 00:04:51 +01:00
Idan Horowitz cc2e08d9e9 LibWeb: Implement HTMLTableSectionElement::deleteRow() 2022-03-12 23:49:50 +01:00
Idan Horowitz 009588eb28 LibWeb: Implement HTMLTableSectionElement::insertRow() 2022-03-12 23:49:50 +01:00
Idan Horowitz 57090f75ae LibWeb: Correct invalid index check in HTMLTableElement::insertRow()
As well as change the matching error message in deleteRow(), which
likely caused this mistake in the first place.
2022-03-12 23:49:50 +01:00
Lenny Maiorani fe3b846ac8 Libraries: Use default constructors/destructors in LibGUI
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-12 14:44:43 -08:00
sin-ack b801ddf73d LibWeb: Apply the current text-justify value when justifying
This implements at least some of the specification. inter-character is
not yet handled. However as our current algorithm only considers
whitespace as word breaks, inter-word could technically be considered to
be handled. :^)
2022-03-12 21:51:38 +01:00
sin-ack 0679eadd62 LibWeb: Add support for the text-justify property
This commit adds the text-justify property as defined in:
https://drafts.csswg.org/css-text/#propdef-text-justify
2022-03-12 21:51:38 +01:00
sin-ack 7fe3f2d970 LibWeb: Refactor text justification code + only justify below threshold
All the justification-related code is now in
InlineFormattingContext::apply_justification_to_fragments and is
performed after all the line boxes have been added.

Text justification now only happens on the last line if the excess space
including whitespace is below a certain threshold. 10% seemed reasonable
since it prevents the "over-justification" of text. Note that fragments
in line boxes before the last one are always justified.
2022-03-12 21:51:38 +01:00
Simon Danner f0a1ab6f84 LibWeb: Keep SVG elliptical arc shape when applying viewbox
When doing viewbox transforms, elliptical always had large arc and
sweep flag set to false. Preserve these flags so they can be set
correctly when applying viewbox transformations.
2022-03-12 15:38:55 +01:00
Andreas Kling b14c6eaef3 LibWeb: Let paintables cache their containing block and absolute rect
The absolute rect of a paintable is somewhat expensive to compute. This
is because all coordinates are relative to the nearest containing block,
so we have to traverse the containing block chain and apply each offset
to get the final rect.

Paintables will never move between containing blocks, nor will their
absolute rect change. If anything changes, we'll simpl make a new
paintable and replace the old one.

Take advantage of this by caching the containing block and absolute rect
after first access.
2022-03-12 00:39:31 +01:00
Luke Wilde a54fdd5212 LibJS: Apply source's byte offset in TA#set when both TAs have same type
On the code path where we are setting a TypedArray from another
TypedArray of the same type, we forgo the spec text and simply do a
memmove between the two ArrayBuffers. However, we forgot to apply
source's byte offset on this code path.

This meant if we tried setting a TypedArray from a TypedArray we got
from .subarray(), we would still copy from the start of the subarray's
ArrayBuffer.

This is because .subarray() returns a new TypedArray with the same
ArrayBuffer but the new TypedArray has a smaller length and a byte
offset that the rest of the codebase is responsible for applying.

This affected pako when it was decompressing a zlib stream that has
multiple zlib chunks in it. To read from the second chunk, it would
set the zlib window TypedArray from the .subarray() of the chunk offset
in the stream's TypedArray. This effectively made the decompressed data
from the second chunk a mis-mash of old data that looked completely
scrambled. It would also cause all future decompression using the same
pako Inflate instance to also appear scrambled.

As a pako comment aptly puts it:
> Call updatewindow() to create and/or update the window state.
> Note: a memory error from inflate() is non-recoverable.

This allows us to properly decompress the large compressed payloads
that Discord Gateway sends down to the Discord client. For example,
for an account that's only in the Serenity Discord, one of the payloads
is a 20 KB zlib compressed blob that has two chunks in it.

Surprisingly, this is not covered by test262! I imagine this would have
been caught earlier if there was such a test :^)
2022-03-11 22:20:23 +01:00
Sam Atkins 38bb9afea8 Browser: Don't crash when selecting nothing in the Inspector DOM tree 2022-03-11 19:31:59 +01:00
Sam Atkins 332799fbcb LibWeb: Stub getting the initial font instead of the root one
Previously this queried the root layout-node's font, which was both
wrong and could crash if the layout wasn't ready yet. Now, it's just
wrong. But at least all the font-related wrongness is grouped together
in StyleComputer. :^)
2022-03-11 15:53:35 +01:00
Jelle Raaijmakers 870b835115 LibGfx+LibSoftGPU: Allow indexed reads into Gfx::Vector 2022-03-11 12:30:43 +01:00
Jelle Raaijmakers 20a5a4363c LibSoftGPU: Remove unused vector types from Device 2022-03-11 12:30:43 +01:00
Joe Petrus 2632f6ae65 LibGfx: Abort draw_circle_arc_intersecting with 0 radius
In testing a particular website (https://www.icpms.com), WebContent
was crashing with infinite recursion in draw_circle_arc_intersecting.
Presumably, radius must be > 0 to paint something, so this trivial
patch simply returns if radius <= 0. The website in question no longer
crashes WebContent.
2022-03-11 10:54:06 +01:00
Tim Schumacher 83609adbdf Shell: Stop parsing options after the script name 2022-03-11 08:41:21 +03:30
javabird25 1770534d94 LibCore: Verify that EventLoop is initialized in its static API 2022-03-10 18:09:27 -08:00
Lenny Maiorani 4660b99ab7 Libraries: Use default constructors/destructors in LibGL
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-10 18:04:26 -08:00
Lenny Maiorani 271d82e23f Libraries: Use default constructors/destructors in LibELF
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-10 18:04:26 -08:00
Lenny Maiorani 8f20c3334b Libraries: Use default constructors/destructors in LibDl
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-10 18:04:26 -08:00
Lenny Maiorani 983716cbeb Libraries: Use default constructors/destructors in LibDesktop
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-10 18:04:26 -08:00
Lenny Maiorani d5d795b55e Libraries: Use default constructors/destructors in LibDebug
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-10 18:04:26 -08:00
Lenny Maiorani f1c452059c Libraries: Use default constructors/destructors in LibCrypto
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-10 18:04:26 -08:00
Lenny Maiorani 59b7e6a213 Libraries: Use default constructors/destructors in LibCpp
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-10 18:04:26 -08:00