Commit Graph

11234 Commits

Author SHA1 Message Date
sin-ack
e3da0adfe6 LibC: Convert getopt and getopt_long to new StringView usage 2022-07-12 23:11:35 +02:00
sin-ack
828060e631 LibCore: Add convenience templates for System::{unveil,pledge}
These convenience templates allow the following to be written as before:

    TRY(Core::System::pledge("promises..."));
    TRY(Core::System::pledge("promises...", "execpromises..."));
    TRY(Core::System::unveil("path", "permissions"));
    TRY(Core::System::unveil(nullptr, nullptr));

Other uses must now append sv to any literal string passed to pledge and
unveil.
2022-07-12 23:11:35 +02:00
sin-ack
a4c251f858 LibX86: Convert register names to StringViews 2022-07-12 23:11:35 +02:00
sin-ack
a3eeeaa6a1 Userland: Remove erroneous String -> char* -> StringView conversions
These were accidental (or leftover) uses of String::characters() to
construct StringViews through its StringView(char const*) constructor.
Since this constructor is due to be removed, this will no longer work.
Plus this prevents strlen from being run on these strings unnecessarily.
2022-07-12 23:11:35 +02:00
sin-ack
3d656ba600 LibJS: Emit StringViews for ErrorType instances
This removes the need for calculating each string's length during
ErrorType use at the cost of storing it within the binary.
2022-07-12 23:11:35 +02:00
sin-ack
6c46383e23 LibChess: Add convenience constructor for Chess::Square
It didn't feel right to add sv suffixes to 2-character strings, so I
added this convenience constructor.
2022-07-12 23:11:35 +02:00
sin-ack
7456904a39 Meta+Userland: Simplify some formatters
These are mostly minor mistakes I've encountered while working on the
removal of StringView(char const*). The usage of builder.put_string over
Format<FormatString>::format is preferrable as it will avoid the
indirection altogether when there's no formatting to be done. Similarly,
there is no need to do format(builder, "{}", number) when
builder.put_u64(number) works equally well.

Additionally a few Strings where only constant strings were used are
replaced with StringViews.
2022-07-12 23:11:35 +02:00
sin-ack
6eecc65787 AK: Explicitly calculate length of char* when printing
This moves out the calculation of the char* out to the formatter.
Additionally, we now print (null) when a null pointer is passed.
2022-07-12 23:11:35 +02:00
Idan Horowitz
e39514721e LibWeb: Add missing break to avoid fallthrough in FlexFormattingContext
This silences a Clang warning.
2022-07-12 18:11:21 +03:00
Idan Horowitz
c70359ac04 LibWeb: Remove unused variable in FlexFormattingContext 2022-07-12 17:54:55 +03:00
Andreas Kling
dc13ced1a7 LibWeb: Express flex item cross axis alignment as offsets-from-center
This allows us to perform cross axis alignment without knowing the final
cross size of the flex container.
2022-07-12 15:55:43 +02:00
Andreas Kling
5f78e780f5 LibWeb: Actually clamp flex line cross size to min/max-size
We were dropping the result of css_clamp() on the floor, oops!
Let's also mark it [[nodiscard]] so it won't happen again.
2022-07-12 15:55:43 +02:00
Andreas Kling
f1576160d7 LibWeb: Don't crash when failing to create WebGL context on non-Serenity
This makes Ladybird stop panicking on websites that try to use WebGL.
2022-07-12 15:55:43 +02:00
Andreas Kling
31fc1990fa LibWeb: Set up both containing block sizes before intrinsic sizing
When calculating e.g the min-content height of some box, we would only
set its containing block's height to 0 in the temporary formatting
state. The containing block width was not touched at all.

This patch aims to do a bit better by resolving indefinite containing
block sizes to INFINITY before performing intrinsic sizing. We should
probably also find a way to resolve definite containing block sizes,
but I'll leave that for our future selves.
2022-07-12 02:46:21 +02:00
Andreas Kling
c81e5c9d82 LibWeb: Floor scaled flex shrink factor at 1 when spec asks us to 2022-07-12 02:46:21 +02:00
Andreas Kling
6ecf7db87b LibWeb: Take margin box into account when justifying flex items
Before this patch, we were justifying based on the content box only,
which led to misalignments along the main axis when items had non-zero
padding, borders or margins.
2022-07-12 02:46:21 +02:00
Andreas Kling
96c9ca502b LibWeb: Add safety mechanism to guard against non-finite layout sizes
Due to some yet-to-be-found bug(s) in intrinsic sizing, we can sometimes
end up deciding that some box has a non-finite intrinsic size.

This will create unpleasant results, and may lead to some layout
algorithms looping infinitely, so this patch adds a safeguard where
we simply turn non-finite intrinsic sizes into zero (and complain a
little bit in the debug log.)
2022-07-12 02:46:21 +02:00
Andreas Kling
2f0657739b LibWeb: Honor align-self over align-items when non-auto on flex item 2022-07-12 02:46:21 +02:00
Obinna Ikeh
d6d1ae667d LibJS: Add test case for %TypedArray%.prototype.toSpliced 2022-07-12 00:44:34 +01:00
Obinna Ikeh
45d07f648e LibJS: Add %TypedArray%.prototype.toSpliced 2022-07-12 00:44:34 +01:00
Timothy Flynn
f089c11b5b LibJS: Implement Intl.PluralRules.prototype.selectRange 2022-07-12 00:43:34 +01:00
Timothy Flynn
a337b059dd LibUnicode: Parse and generate per-locale plural ranges 2022-07-12 00:43:34 +01:00
Luke Wilde
a718c62c01 LibWeb: Implement all "attributes" mutation records for MutationObserver 2022-07-11 22:35:08 +02:00
Luke Wilde
1ca8782c99 LibWeb: Implement "characterData" mutation record for MutationObserver 2022-07-11 22:35:08 +02:00
Luke Wilde
56cfd5ced8 LibWeb: Implement all "childList" mutation records for MutationObserver 2022-07-11 22:35:08 +02:00
Luke Wilde
c9ba5531e0 LibWeb: Introduce Mutation{Record,Observer} and observer microtasks 2022-07-11 22:35:08 +02:00
Luke Wilde
116a7b74fe LibWeb: Wrap DOM::Attribute in NodeWrapperFactory 2022-07-11 22:35:08 +02:00
Luke Wilde
ee719870c8 LibWeb: Implement CharacterData.{append,insert,delete}Data 2022-07-11 22:35:08 +02:00
Luke Wilde
af5b4ae1c4 LibWeb: Implement CharacterData::set_data in terms of replace_data
This makes it so that it always queues a mutation record, even if
`data` is set to the same value. It also makes it follow the spec
steps.
2022-07-11 22:35:08 +02:00
Luke Wilde
f3650d08cb LibWeb: Allow creating a StaticNodeList without an r-value Vector
It must accept taking a copy for DocumentFragment mutation records and
empty vectors created in-place.
2022-07-11 22:35:08 +02:00
Andreas Kling
4493702fb2 LibWeb: Honor preferred size as intrinsic cross size of flex items
I'm not 100% sure this is on-spec, but it seems to me that flex items
that have a specified non-auto cross size should honor that value in
its min-content and max-contribution.
2022-07-11 18:57:45 +02:00
Andreas Kling
9cae06de09 LibWeb: Implement step 9.2.3 of the flexbox layout algorithm
When sizing the flex container under a min-content or a max-content
constraint, flex items with a used flex basis of "content" should be
sized under the same constraint.
2022-07-11 18:57:45 +02:00
Andreas Kling
0cacaf025d LibWeb: Stop putting the FormattingState nodes in a slow hash map
Instead, put them in a Vector<OwnPtr<NodeState>>. Each layout node
has a unique index into the vector. It's a simple serial ID assigned
during layout tree construction. Every new layout restarts the sequence
at 0 for the next ICB.

This is a huge layout speed improvement on all content.
2022-07-11 18:57:45 +02:00
Andreas Kling
f6a97ff7d5 LibWeb: Tweak padding on button elements match other engines 2022-07-11 18:57:45 +02:00
Andreas Kling
327938c945 LibWeb: Bring sizing of replaced elements closer to spec
We were prematurely resolving the computed size values, which meant
that `auto` values were swallowed before we could resolve them via
the intrinsic aspect ratio (if present)
2022-07-11 18:57:45 +02:00
Andreas Kling
67de1131b9 LibWeb: Match WebKit and Blink re: absence of width/height on <svg> 2022-07-11 18:57:45 +02:00
Andreas Kling
17a6fcfde3 LibWeb: Try to work out the intrinsic size of <svg> elements
If the `width` and `height` attributes are provided, we derive the
intrinsic size and ratio from them.

Otherwise, we trace a rectangle around the geometry elements inside
the SVG and use the size of that as the intrinsic size.

This is definitely far from correct, but is still a much better guess
at the intrinsic size than nothing.
2022-07-11 18:57:45 +02:00
Andreas Kling
7dfd5afd37 LibWeb: Set 1:1 intrinsic aspect ratio for radio buttons 2022-07-11 18:57:45 +02:00
Andreas Kling
557006f5be LibWeb: Cache reference to <svg> element in SVGFormattingContext 2022-07-11 18:57:45 +02:00
Andreas Kling
e1dab7b63d LibWeb: Use the *outer* flex base size in intrinsic size calculation 2022-07-11 18:57:45 +02:00
Andreas Kling
aee3d79ad1 LibWeb: Use the "scaled flex shrink factor" where noted by the spec 2022-07-11 18:57:45 +02:00
Andreas Kling
f7750985fa LibWeb: Treat "flex-basis: 0px" like any other definite basis value 2022-07-11 18:57:45 +02:00
Andreas Kling
61c27815e4 LibWeb: More specialization of intrinsic sizing layout
This patch adds a separate entry point for this kind of layout.
We override it in BFC to set up initial width/height values for the
BFC root block.

Resulting dimensions are assigned as content_width and content_height
at the end of intrinsic sizing, for each axis, if it's either "auto"
or there's a min-content or max-content constraint in effect.
2022-07-11 18:57:45 +02:00
Andreas Kling
28eec22c83 LibWeb: Don't iterate over text content inside replaced elements
This fixes an issue where whitespace inside embedded <svg> elements
would create unexpected whitespace text content on the page.

When combined with something like `white-space: pre-wrap`, it ended
up generating a lot of surprising vertical offsets.
2022-07-11 18:57:45 +02:00
Andreas Kling
7b4a86ab80 LibWeb: Use max-content main size for flex items w/ definite cross size
If the main size is indefinite, that is.
2022-07-11 18:57:45 +02:00
Andreas Kling
e78282aebb LibWeb: Make sure we always apply size constraints in IFC
Pre-compute the effective containing block width in the IFC constructor
and use that throughout.
2022-07-11 18:57:45 +02:00
Andreas Kling
7713198e9c LibWeb: Cache a pointer to the containing block state in IFC 2022-07-11 18:57:45 +02:00
Andreas Kling
9784a567d2 LibWeb: Factor out BFC "layout this block-level box" to a function 2022-07-11 18:57:45 +02:00
Andreas Kling
64959a8504 LibWeb: Express intrinsic size layout via size constraints
Previously, we had three layout modes:

- Normal:
    - Everything uses the computed values from CSS.

- MinContent:
    - Containing blocks act as if they have 0 width.
    - All line breaking opportunities are taken.

- MaxContent:
    - Containing blocks act as if they have infinite width.
    - Only forced line breaks are accepted.

The above was based on a set of misunderstandings of CSS sizing.
A major problem with the above was that *all* containing blocks
behaved differently during intrinsic size layout, not just the
relevant one.

With this patch there are only two layout modes:

- Normal:
    - Everything uses the computed values from CSS.

- IntrinsicSizeDetermination:
    - One or more boxes have size constraints applied.

There are two size constraints per layout box, set here:

- FormattingState::NodeState::width_constraint
- FormattingState::NodeState::height_constraint

They are of type SizeConstraint and can be one of None, MinContent,
or MaxContent. The default is None.

When performing an IntrinsicSizeDetermination layout, we now assign
a size constraint to the box we're trying to determine the intrinsic
size of, which is then honored by using two new helpers to query
the dimensions of containing blocks:

- FormattingContext::containing_block_width_for(Box)
- FormattingContext::containing_block_height_for(Box)

If there's a relevant constraint in effect on the Box, the size of
its containing block is adjusted accordingly.

This is essentially an implementation of the "available space"
constraints from CSS-SIZING-3. I'm sure some things will break from
this, and we'll have to deal with that separately.

Spec: https://drafts.csswg.org/css-sizing-3/#available
2022-07-11 18:57:45 +02:00
Andreas Kling
66d08d2417 LibWeb: Move IFC result measurement from IFC to BFC
Before this change, IFC would first generate all of its line boxes
and then measure them. It would then write some of the values into
the state of the IFC's containing block.

We now move that up to BFC::layout_inline_children() instead, which
is a much more natural place to decide metrics for the block.
2022-07-11 18:57:45 +02:00