Commit Graph

9559 Commits

Author SHA1 Message Date
Andreas Kling
3b037726e9 LibWeb: Invalidate layout after setting Element.innerHTML
It's not enough to only relayout here, since the API can substantially
change the DOM. We have to rebuild the layout tree.
2022-03-18 19:54:46 +01:00
Andreas Kling
a19b9b727d LibWeb: Place right-side floats relative to their containing block
We were incorrectly placing them relative to the BFC root, but CSS2
says they are relative to their own containing block.
2022-03-18 19:28:58 +01:00
Simon Wanner
48efdaa8c4 LibWeb: Update hit_test for CSS Transforms
This now also takes a FloatPoint instead of an IntPoint to avoid
excessive rounding when multiple transforms apply on top of each other.
2022-03-18 18:51:42 +01:00
Simon Wanner
a2331e8dd3 LibWeb: Implement CSS transforms on stacking contexts
Since there is currently no easy way to handle rotations and skews
with LibGfx this only implements translation and scaling by first
constructing a general 4x4 transformation matrix like outlined in
the css-transforms-1 specification. This is then downgraded to a
Gfx::AffineTransform in order to transform the destination rectangle
used with draw_scaled_bitmap()

While rotation would be nice this already looks pretty good :^)
2022-03-18 18:51:42 +01:00
Simon Wanner
7c79fc209f LibWeb: Establish a new stacking context for elements with transform 2022-03-18 18:51:42 +01:00
Simon Wanner
9c97bd0de4 LibGfx: Add AffineTransform::inverse 2022-03-18 18:51:42 +01:00
Simon Wanner
a3c80f05ba LibWeb: Apply the 'transform' presentational attribute to SVG elements 2022-03-18 18:51:42 +01:00
Simon Wanner
c4f46893f6 LibWeb: Add parsing support for the remaining transform functions 2022-03-18 18:51:42 +01:00
Sam Atkins
ad4f35ff37 LibWeb: Mark more CSS properties as not affecting layout
- background properties
- box-shadow
- cursor
- SVG fill/stroke properties
- image-rendering
- outline properties
- pointer-events
- user-select

This should be basically all of them. I skipped `opacity` and
`transform` since establishing a stacking context feels like a
layout-affecting thing, but I could be very wrong on that!
2022-03-18 18:49:08 +01:00
Andreas Kling
39b7fbfeb9 LibWeb: Rewrite CSS float implementation to use offset-from-edge
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.)
2022-03-18 15:18:48 +01:00
Andreas Kling
28642de6ed LibWeb: Make LineBuilder aware of the current LayoutMode
This will allow us to override the available space correctly when doing
intrinsic sizing.
2022-03-18 15:18:48 +01:00
Andreas Kling
915ee66bd6 LibWeb: Implement shrink-to-fit layout on top of intrinsic size cache
Using the intrinsic size cache means we only perform the nested layout
to determine intrinsic size *once* per root layout pass.

Furthermore, by using a throwaway FormattingState, details of the nested
layout can't leak into and mutate the outer layout.
2022-03-18 15:18:48 +01:00
Andreas Kling
39ca39204b LibWeb: Cache intrinsic sizes on the root FormattingState
Instead of caching them with the current state, we can cache them at the
root of the state tree. Since intrinsic sizes are immutable during the
same layout, this allows layout to take advantage of intrinsic sizes
discovered during nested layout (and avoids a *lot* of duplicate work.)
2022-03-18 15:18:48 +01:00
Andreas Kling
d3932b5880 LibWeb: Give FormattingState a reference to its root state
FormattingStates can have parents, in case we're performing nested
layouts to determine something's intrinsic size. In those cases, it will
soon be useful to find the outermost (root) state.
2022-03-18 15:18:48 +01:00
Andreas Kling
60c781ebc7 LibWeb: Simplify Layout::Node::containing_block()
Use first_ancestor_of_type<BlockContainer>() instead of implementing a
custom traversal lambda.
2022-03-18 15:18:48 +01:00
Andreas Kling
15dc48b431 LibWeb: Make PaintableBox::enclosing_stacking_context() cheaper
No need to call the expensive establishes_stacking_context() here, as
we've already built the stacking context tree and can simply test for
the presence of existing stacking contexts.
2022-03-18 15:18:48 +01:00
Andreas Kling
ef8a72ff3f LibWeb: Move available_space_for_line() from IFC to BFC
This is preparation for allowing blocks with their own internal BFC to
flow around floating boxes in the parent BFC.

Note that IFC still has the available_space_for_line() API, which
returns space available within the IFC's own containing block, while the
BFC available_space_for_line() returns space available within its root.
2022-03-18 15:18:48 +01:00
Sam Atkins
174a25db5b LibWeb: Combine identical relative/regular selector parsing functions 2022-03-18 11:34:02 +01:00
Sam Atkins
5b0187477b LibWeb: Implement :nth-[last-]child(n of foo) syntax
In Selectors level 4, `:nth-child()` and `:nth-last-child()` can both
optionally take a selector-list argument. This selector-list acts as a
filter, so that only elements matching the list are counted. For
example, this means that the following are equivalent:

```css
:nth-child(2n+1 of p) {}
p:nth-of-type(2n+1) {}
```
2022-03-18 11:34:02 +01:00
Sam Atkins
f241827f6a LibWeb: Calculate specificity for special pseudo-classes
This fixes the specificity for :not(), :is() and :where(). Also, we now
clamp the specificity numbers instead of letting them overflow, and I
sprinkled in some spec comments for good measure.
2022-03-18 11:34:02 +01:00
Sam Atkins
993653317c LibWeb: Implement the :where() selector
This is identical to :is() except for specificity, so we can use the
same code paths. :^)
2022-03-18 11:34:02 +01:00
Sam Atkins
c148ed50bb LibWeb: Implement the :is() selector
This lets us finally get rid of a FIXME in the default style sheet. :^)
2022-03-18 11:34:02 +01:00
Sam Atkins
5319e2ba8e LibWeb: Parse forgiving selector-lists
`<forgiving-selector-list>` and `<forgiving-relative-selector-list>` are
the same as regular selector-lists, except that an invalid selector
does not make the whole list invalid. The former is used by the `:is()`
pseudo-class.

For example:

```css
/* This entire selector-list is invalid */
.foo, .bar, !?invalid { }

/* This is valid, but the "!?invalid" selector is removed */
:is(.foo, .bar, !?invalid) { }
```

Also as part of this, I've removed the `parse_a_selector(TokenStream)`
and `parse_a_relative_selector(TokenStream)` methods as they don't add
anything useful.
2022-03-18 11:34:02 +01:00
MacDue
7628f1f233 LibGfx: Draw window frame border radii antialiased
I think this now looks very nice :^)
2022-03-18 11:31:33 +01:00
MacDue
51e54ab1ba LibGfx: AntiAliasingPainter::draw_circle/fill_rect_with_rounded_corners
Follows the efficient algorithm from this paper:
https://cs.uwaterloo.ca/research/tr/1984/CS-84-38.pdf

Can be extended ellipses in future.
2022-03-18 11:31:33 +01:00
Brian Gianforcaro
913374163c LibVT/Kernel: Make VT::Attribute::Flags enum class, use AK EnumBits
Noticed the TODO in `Attribute.h` and realized we have as solution
to this problem already. :^)
2022-03-18 11:29:43 +01:00
Lenny Maiorani
2844f7c333 Everywhere: Switch from EnableIf to requires
C++20 provides the `requires` clause which simplifies the ability to
limit overload resolution. Prefer it over `EnableIf`

With all uses of `EnableIf` being removed, also remove the
implementation so future devs are not tempted.
2022-03-17 22:15:42 -07:00
Michiel Visser
8f7219c6fa LibCrypto: Implement the SECP256r1 elliptic curve
This implementation of the secp256r1 elliptic curve uses two techniques
to improve the performance of the operations.

1. All coordinates are stored in Jacobian form, (X/Z^2, Y/Z^3, Z), which
   removes the need for division operations during point addition or
   doubling. The points are converted at the start of the computation,
   and converted back at the end.

2. All values are transformed to Montgomery form, to allow for faster
   modular multiplication using the Montgomery modular multiplication
   method. This means that all coordinates have to be converted into
   this form, and back out of this form before returning them.
2022-03-18 07:56:47 +03:30
thankyouverycool
3d1591a822 LibGfx: Add accessors for BitmapFont's rows and widths 2022-03-18 01:12:26 +01:00
Linus Groh
599b2bee4a LibJS: Tweak Interpreter::create() for more spec-likeness
Store a reference to the newly created execution context in an aptly
named variable, rename global_this_value to just this_value, and only
call set_global_object() in a single place.
2022-03-18 01:12:12 +01:00
Linus Groh
29964dc152 LibJS: Use TRY(push_execution_context()) in places where we can recover 2022-03-18 01:12:12 +01:00
Linus Groh
9422ae9bb2 LibJS: Add infallible variant of VM::push_execution_context()
It makes no sense to require passing a global object and doing a stack
space check in some cases where running out of stack is highly unlikely,
we can't recover from errors, and currently ignore the result anyway.

This is most commonly in constructors and when setting things up, rather
than regular function calls.
2022-03-18 01:12:12 +01:00
Tobias Christiansen
64cc482f8a LibGfx: Allow for different {x,y}-radii in FastBoxBlurFilter
Use different specified radii for the two seperate passes.

The gaussian approximation is not changed to accept two parameters since
the math is not exactly straight forward and therefore something for a
later patch. For now, let's progress!
2022-03-17 20:03:05 +01:00
Tobias Christiansen
5f063e832e LibGfx: Make FastBoxBlurFilter::apply_single_pass's argument unsigned
It isn't sensible to have a negative radius for blurring, so an unsigned
value is the right thing to do here.
Now we have to cast the radius to int a few times when actually doing
the calculations but I'm sure that can be done more intelligently, but
that optimization is a thing for the future.

It looked very goofy for the two different ways of invoking the Filter
to have differently signed arguments.
2022-03-17 20:03:05 +01:00
Lenny Maiorani
9c56a83b76 Libraries: Use default constructors/destructors in LibGfx
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-17 17:23:49 +00:00
Lenny Maiorani
c37820b898 Libraries: Use default constructors/destructors in LibWeb
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-17 17:23:49 +00:00
Maciej
a95794a356 LibGUI: Clamp selection when drag-selecting over out of range area 2022-03-17 17:05:56 +01:00
Maciej
bee9cd2113 LibGUI: Update active glyph when drag-selecting in GlyphMapWidget
This matches behavior of text selecting
2022-03-17 17:05:56 +01:00
Maciej
d3836f982a LibGUI: Use different color for GlyphMapWidget background
This patch makes background a bit darkened so that it is possible to
distinguish out of range area from glyphs that are just not drawn.

The default background color is also changed to Window so that it looks
good in more themes.
2022-03-17 17:05:56 +01:00
Timothy Flynn
157d16f049 LibJS: Update specification steps for RegExp Match Indices
This proposal was implemented in Stage 3 in commit:
6c67de8186

It is now Stage 4 and has been merged into the main ECMA-262 spec:
https://github.com/tc39/ecma262/commit/0209d85
2022-03-17 11:29:51 -04:00
Andreas Kling
68f75ab98e LibWeb: :checked should only match inputs in checkbox/radio type state
We were erroneously allowing :checked to match any input element.
2022-03-16 23:29:17 +01:00
Andreas Kling
a403086940 LibWeb: Schedule a relayout after <image> and <object> elements load
Otherwise we'll be stuck with the intrinsic dimensions of the
replacement content.
2022-03-16 23:13:05 +01:00
Andreas Kling
be5f0b5ac4 LibWeb: Move text fragment painting to PaintableWithLines
All the other painting code has moved to paintables already.
2022-03-16 23:13:05 +01:00
Simon Wanner
7969161f07 LibWeb: Implement window.name
Right now the only functionality supported is getting/setting via JS
and resetting when browsing cross origin.

The HTML Specification (7.11 Browsing the web) also specifies how the
name should be restored from history entries, but we don't have those
yet.
2022-03-16 21:49:54 +00:00
Linus Groh
619794dfa7 LibJS: Fix fraction substring in ParseTimeZoneOffsetString
This is a normative change in the Temporal spec.

See:
- https://github.com/tc39/proposal-temporal/commit/97d553c
- https://github.com/tc39/proposal-temporal/commit/d53af7f

Note that we already implemented this correctly, so the only change is
updating the spec comment.
2022-03-16 21:49:38 +00:00
Linus Groh
356fa2dca1 LibJS: Remove unused code in DifferenceISODate
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/056f695
2022-03-16 21:49:38 +00:00
Linus Groh
2ad69d789b LibJS: Remove the ConstrainToRange AO
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/537b3e6
2022-03-16 21:49:38 +00:00
Linus Groh
1521c5f55c LibJS: Remove argument type assertion from ParseTemporalDurationString
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/8615b41
2022-03-16 21:49:38 +00:00
Linus Groh
0c22a7f822 LibJS: Assume Get() on the result of PrepareTemporalFields can't fail
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/980e168
2022-03-16 21:49:38 +00:00
Sam Atkins
7c4402ba92 LibWeb: Evaluate no-preference media-features as false
As noted, this is not 100% to the spec, but effectively the same -
`no-preference` is only allowed to appear in features that evaluate it
as false in a boolean context. This is also the only identifier besides
`none` that evaluates to false. If other identifiers gain this property
in the future, we can make it more robust then.
2022-03-16 22:07:53 +01:00