Commit Graph

8686 Commits

Author SHA1 Message Date
MacDue
344eb98b3c LibWeb: Add helper to convert CSS LengthPercentage to SVGLength 2024-03-04 10:50:32 +01:00
MacDue
4f78ddd6a2 LibWeb: Setup computed values for SVG geometry properties 2024-03-04 10:50:32 +01:00
MacDue
b9afea40e6 LibWeb: Update SVG get_path() API to take a viewport size
This will allow resolving paths that use sizes that are relative to the
viewport. This necessarily removes the on element caching, which has
been redundant for a while as computed paths are stored on the
paintable.
2024-03-04 10:50:32 +01:00
MacDue
1fbf1073ab LibWeb: Define the rest of the SVG geometry properties
This defines all the (remaining) geometry properties from
https://svgwg.org/svg2-draft/geometry.html#Sizing.
2024-03-04 10:50:32 +01:00
Filiph Siitam Sandström
fd694e8672 AK+Lagom: Make it possible to build for iOS
This commit makes it possible to build AK and most of Lagom for iOS,
based on the work for the Ladybird build demoed on discord:
https://discord.com/channels/830522505605283862/830525031720943627/1211987732646068314
2024-03-03 13:13:42 -07:00
Matthew Olsson
ae321b2cdf LibWeb: Add interpolation for shadow values 2024-03-03 19:50:25 +01:00
Matthew Olsson
3c21dd4d2b LibWeb: Move color interpolation into a helper function
This will be needed for other interpolations
2024-03-03 19:50:25 +01:00
Matthew Olsson
8502b7ee9f LibWeb: Properly serialize shadow colors 2024-03-03 19:50:25 +01:00
Matthew Olsson
da18957063 LibWeb: Limit color alpha values to 4 decimal places when serializing
The spec explicitly mentions that these values need to round-trip, and
4 decimal places is enough for 8-bit values
2024-03-03 19:50:25 +01:00
Matthew Olsson
0487485fb1 LibWeb: Limit length values to 5 decimal places when serializing 2024-03-03 19:50:25 +01:00
Matthew Olsson
7dcf060927 LibWeb: Limit ratio parts to 5 decimal places when printing
Printing 15 or so decimal places for each value is a bit excessive
2024-03-03 19:50:25 +01:00
Matthew Olsson
4d9f2bf5f1 LibWeb: Add interpolation for ratio values 2024-03-03 19:50:25 +01:00
Matthew Olsson
f02cd4d0b0 LibWeb: Add a spec comment for color interpolation 2024-03-03 19:50:25 +01:00
Matthew Olsson
1f88ca2a03 LibWeb: Remove transform interpolation optimization
The property values here will always be StyleValueLists and not
TransformationStyleValues. The handling of interpolation in this case
gets quite a bit more complex, so let's just remove the dead code for
now and attempt this optimization again in the future if it's needed.
2024-03-03 19:50:25 +01:00
Aliaksandr Kalenik
ee1d8a534d LibWeb: Remove wrappers for gradient painting command recording
These were adding unnecessary indirection, whereas recording painter
could be called directly.
2024-03-03 18:19:20 +01:00
Bastiaan van der Plaat
a2f101c10b LibWeb: Add input and textarea minlength and maxlength support 2024-03-03 10:02:30 -05:00
Bastiaan van der Plaat
9b645d20b9 LibWeb: Refactor input range sanitization code use min and max getters 2024-03-03 10:02:30 -05:00
Zac Brannelly
9165faca5e LibWeb: Support CSS property background-clip: text
From https://drafts.csswg.org/css-backgrounds-4/#background-clip
"The background is painted within (clipped to) the intersection of the
border box and the geometry of the text in the element and its in-flow
and floated descendants"

This change implements it in the following way:
1. Traverse the descendants of the element, collecting the Gfx::Path of
   glyphs into a vector.
2. The vector of collected paths is saved in the background painting
   command.
3. The painting commands executor uses the list of glyphs to paint a
   mask for background clipping.

Co-authored-by: Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
2024-03-03 15:33:12 +01:00
Zac Brannelly
4a3680cafc LibWeb/CSS: Add "text" into list of possible "background-box" values 2024-03-03 15:33:12 +01:00
circl
3e3a200eee LibWeb: Do not issue change event for every update of color input
Per spec, the change event shall only be issued once the change is
finally committed by the user, IE by closing the color picker window.
2024-03-03 08:42:41 +01:00
Johannes Røsvik
d89e617a42 LibWeb: Make SubtleCrypto use the correct algorithm name for SHA-1
The spec defines "SHA-1" as a recognized algorithm name, not "SHA1".

This makes SHA-1 hash values show up on string.248.no.
2024-03-03 08:41:32 +01:00
Aliaksandr Kalenik
d5e74b1bdc LibWeb: Use a precalculated list of positioned descendants for painting
This allows us to avoid the need for costly traversals to gather
boxes that have been saved during the construction of the stacking
context tree.

No behavior change intended.
2024-03-03 08:40:46 +01:00
Kenneth Myhra
cd0302426f LibWeb: Move serialization of serializable object's interface name
To be consistent with the deserialization steps, move serialization of
the serializable object's interface name out of the serialization steps.
2024-03-02 17:04:09 -07:00
Kenneth Myhra
4751ab9f0b LibWeb: Add convenience methods {,de}serialize_{u,i}64()
To avoid differing logic for serializing and deserializing similar
types, move the logic into separate helpers.

Also, adds security checks like VERIFY to avoid reading past the end of
the serialized data. If we try to read past the end of the serialized
data, either our program logic is wrong or our serialized data has
somehow been corrupted. Therefore, at least currently, it is better to
crash by VERIFYing.
2024-03-02 17:04:09 -07:00
Kenneth Myhra
79978063b9 LibWeb: Extract deserialization logic for {,object} primitives
To avoid differing logic for deserializing similar types, move the logic
into separate helpers.

Also, adds security checks like VERIFY to avoid reading past the end of
the serialized data. If we try to read past the end of the serialized
data, either our program logic is wrong or our serialized data has
somehow been corrupted. Therefore, at least currently, it is better to
crash by VERIFYing.
2024-03-02 17:04:09 -07:00
Kenneth Myhra
c384f22d67 LibWeb: Extract serialization logic for primitives and object primitives
To avoid differing logic for serializing similar types, move the logic
into separate helpers.
2024-03-02 17:04:09 -07:00
Matthew Olsson
c1ab6ca6b4 LibWeb: Do not invalidate elements with animations in the CSS cascade
See the note added to Animation::cancel for more info
2024-03-02 19:58:12 +01:00
Matthew Olsson
ec766e8669 LibWeb: Correctly set @keyframe rule's effect target 2024-03-02 15:36:48 +01:00
Aliaksandr Kalenik
1bd20a4595 LibWeb: Skip large stacking context in gpu painter only if it allocates
Skipping all stacking contexts with a size larger than 10000px in one
dimension was a mistake because it also affects pages that are simply
tall due to having a lot of content. Instead, we only need to skip if
the stacking context requires the allocation of a framebuffer that
could possibly fail.

Fixes https://github.com/SerenityOS/serenity/issues/23397
2024-03-02 14:36:33 +01:00
Andreas Kling
d8e8293b7e LibWeb: Add PercentageOr<Length>::to_px() fast path for absolute lengths
We can avoid round-tripping through a temporary Length in the simple
case here.
2024-03-02 13:00:09 +01:00
Andreas Kling
1e14264d13 LibWeb: Avoid repeated layout lookups in resolve_paint_only_properties()
By caching the layout node and its computed values in locals, we can
avoid the small amount of redundant work needed to look them up every
single time.
2024-03-02 13:00:09 +01:00
Andreas Kling
8303e61912 LibWeb: Pass BorderRadiusData const& to normalize_border_radii_data()
This avoids making a bunch of temporary copies for no reason.
2024-03-02 13:00:09 +01:00
Andreas Kling
3ff5beb229 LibWeb: Add fast_is<T>() for SVGPaintable 2024-03-02 13:00:09 +01:00
Andreas Kling
b66033720a LibWeb: Let Length::to_px(Layout::Node) be inline for absolute lengths 2024-03-02 13:00:09 +01:00
Andreas Kling
881e7fcee1 LibWeb: Copy various flags from layout node to paintable
This removes indirection when asking if a paintable is positioned,
floating, etc.

Removes a bunch of 1-1.5% items in the profile when hovering links
on ziglang.org.
2024-03-02 13:00:09 +01:00
Andreas Kling
20ff69cd41 LibWeb: Add fast_is<T>() for InlinePaintable
dynamic_cast<InlinePaintable> was showing up in profiles when hovering
links on ziglang.org.
2024-03-02 13:00:09 +01:00
Andreas Kling
c4403fd28c LibWeb: Fix bogus ReplacedBox type check in StackingContext
We should be asking if the layout node is a ReplacedBox, not the
paintable.
2024-03-02 13:00:09 +01:00
Matthew Olsson
6d0672eec0 LibWeb: Implement complex transform interpolation
With this commit, we can interpolate between transforms whose functions
don't match. For example:
    translate(100px) -> scale(2) translateX(50px)
2024-03-02 12:25:53 +01:00
Matthew Olsson
892f407d75 LibWeb: Do not abort interpolation if the StyleValue types differ
This can be perfectly valid, and depends on the property being animated.
For example, interpolating between the StyleValue "none" (an identifier)
and a TransformationStyleValue is perfectly defined.
2024-03-02 12:25:53 +01:00
Matthew Olsson
15942b4262 LibWeb: Revert changing transform's animation-type to by-computed-value
In the upcoming commits where we properly handle transformation
interpolation, it actually becomes easier to change this back to custom,
so lets do that since its more correct anyways.
2024-03-02 12:25:53 +01:00
Aliaksandr Kalenik
06c176bbfb LibGfx+LibWeb: Use ref-counted object to store glyph run
...to avoid allocating a copy of glyph run for painting commands. We
can't simply save pointers to a glyph run in layout/paintable tree
because it should be safe to deallocate layout and paintable trees
after painting commands are recorded, if in the future we decide to
move command execution to a separate thread.
2024-03-02 09:09:10 +01:00
Aliaksandr Kalenik
cf6999f5f3 LibWeb: Remove glyph run allocation in paint_text_fragment()
Instead of allocating a new glyph run to scale glyph positions and
fonts, a scale factor could be encoded in a paint command and applied
later during command execution.
2024-03-02 09:09:10 +01:00
Aliaksandr Kalenik
aeb5a0d9e8 LibWeb: Remove glyph run allocation in RecordingPainter::draw_text_run
Instead of allocating a new glyph run solely to shift each glyph by the
painter's offset, this offset could be encoded in a paint command and
applied later during command execution.
2024-03-02 09:09:10 +01:00
Hendiadyoin1
fe0fde2154 Userland+Tests: Remove unused <AK/Tuple.h> includes 2024-03-01 14:05:53 -07:00
Andreas Kling
d1b5f55f91 LibWeb: Make Paintable::containing_block() return a PaintableBox*
Every single client of this function was immediately calling paintable()
on the result anyway, so there was no need to return a layout node!

This automatically leverages the cached containing block pointer we
already have in Paintable, which melts away a bunch of unnecessary
traversal in hit testing and painting. :^)
2024-03-01 17:57:10 +01:00
Aliaksandr Kalenik
2764966ccc LibWeb: Reduce paintable tree traversals during hit-testing
By storing a list of positioned and floating descendants within the
stacking context tree node, we can eliminate the need for costly
paintable tree traversals during hit-testing.

This optimization results in hit-testing being 2 to 2.5 times faster
on https://ziglang.org/documentation/master/
2024-03-01 13:03:53 +01:00
Luke Wilde
48e11a1f12 LibWeb: Empty CE reaction queue instead of destroying it on exception
If an exception occurs in a custom element constructor, we clear the
reaction queue by destroying it, instead of emptying the Vector.
3da6916383/Userland/Libraries/LibWeb/DOM/Element.cpp (L2033)

This causes a UAF here, as async upgrades (i.e. custom elements not
created by document.createElement) are performed in this loop:
3da6916383/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp (L657)

Fixes crash when loading https://github.com/SerenityOS/serenity
2024-02-29 21:58:01 -05:00
Tim Ledbetter
5b4533cab8 LibWeb: Don't crash in offset_parent() if no ancestor element found
The specification says the final step of this algorithm is to return
null. Previously, the browser would crash if the content of an iframe
was appended to the document before its offsetParent property was
queried.
2024-02-29 21:54:53 -05:00
Aliaksandr Kalenik
90879a07ba LibWeb: Skip page scrolling for wheel events consumed by scrollable box
Fixes the bug when we scroll both scrollable box and page.
2024-02-29 13:18:57 +01:00
Tim Ledbetter
4646a87eba LibWeb: Make CSSConditionRule.conditionText read-only
Previously @media rule conditions could be updated by assigning to
`conditionText`. This change aligns our implementation with the CSSOM
specification, which says `CSSConditionRule.conditionText` should be
read-only.
2024-02-28 22:14:58 +01:00
implicitfield
b08fd1b9ae LibWeb: Improve support for 'vertical-align: middle'
This rebaselines a few table-related layout tests since our default
stylesheet applies 'vertical-align: middle' to a few table-related
elements.
2024-02-28 16:11:05 -05:00
Aliaksandr Kalenik
b821f7b283 LibWeb: Implement scrollbar painting
Introduces the rendering of scroll thumbs in vertical and horizontal
directions. Currently, the thumbs are purely graphical elements that
do not respond to mouse events. Nevertheless, this is beneficial as it
makes it easier to identify elements that should respond to scrolling
events.

Painting of scrollbars uncovers numerous bugs in the calculation of
scrollable overflow rectangles highlighting all the places where
elements are made scrollable whey they shouldn't be. Positively, this
issue might motivate us to pay more attention to this problem to
eliminate unnecessary scrollbars.

Currently, the scrollbar style is uniform across all platforms: a
semi-transparent gray rectangle with rounded corners.

Also here we add `scrollbar-width: none` to all existing scrolling
ref-tests, so they keep working with this change.
2024-02-28 07:51:13 -05:00
Aliaksandr Kalenik
8d9e20cb03 LibWeb: Parse the CSS scrollbar-width property 2024-02-28 07:51:13 -05:00
Aliaksandr Kalenik
c74fc4c171 LibWeb: Clean previous border radii clips in refresh_clip_state()
The list of border radii clips needs to be reset before being populated
with new clips that have refreshed positions. Besides fixing painting,
this also improves performance because the number of sample/blit
commands does not increase as we scroll.
2024-02-28 07:44:12 -05:00
Aliaksandr Kalenik
91378ded96 LibWeb: Apply scroll offset after clip in PaintableBox::before_paint()
The order is important because clip rectangles are calculated with the
scroll offset taken into account. Therefore, they need to be applied
before the scroll offset is changed, to avoid accounting for the scroll
offset twice.
2024-02-28 07:44:12 -05:00
Tim Ledbetter
ae42c6ed80 LibWeb: Implement AbortSignal.timeout()
This method returns a signal that will automatically abort after a
given number of milliseconds.
2024-02-28 07:42:43 -05:00
Tim Ledbetter
3c288c96e6 LibWeb: Extract run_steps_after_a_timeout() into a separate function 2024-02-28 07:42:43 -05:00
Matthew Olsson
aca32e298d LibWeb: Expand shorthand properties in CSS @keyframes 2024-02-28 08:05:41 +00:00
Bastiaan van der Plaat
05e78dabdb LibWeb: Add textarea readonly support 2024-02-27 18:03:20 -05:00
Timothy Flynn
6656f70387 LibWeb: Use TypedArray as a forward-declaration where appropriate
This reduces the number of files needed to be recompiled when TypedArray
changes from ~1000 to ~600. The remaining ~600 are almost all generated
constructors and prototypes.
2024-02-27 20:02:07 +01:00
Aliaksandr Kalenik
a0dc9584de LibWeb: Add "object-position" CSS property into ComputedValues 2024-02-27 16:53:13 +01:00
Aliaksandr Kalenik
677a00ed92 LibWeb: Add "object-fit" CSS property into ComputedValues 2024-02-27 16:53:13 +01:00
Aliaksandr Kalenik
22da83c295 LibWeb: Resolve "object-position" without unwrapping raw percentage
Use `to_px()` that accepts reference value instead.

No behaviour change intended.
2024-02-27 16:53:13 +01:00
Aliaksandr Kalenik
6f5a0bd5de LibWeb: Save image provider in ImagePaintable
Refactoring towards making paintable be independant from layout nodes.

No behaviour change intended.
2024-02-27 16:53:13 +01:00
Aliaksandr Kalenik
ef01c735cd LibWeb: Visit ImageProvider from Layout::ImageBox
Adds missing visit of HTMLElement that serves as image provider of
image layout node.
2024-02-27 16:53:13 +01:00
Aliaksandr Kalenik
9fa22b60cf LibWeb: Save alt text in ImagePaintable
By saving string with alt text, image paintable no longer need to reach
into layout and DOM nodes while painting commands recording.

No behaviour change intended.
2024-02-27 16:53:13 +01:00
Tim Ledbetter
ee765e241e LibWeb: Allow performance timestamps to have sub-millisecond precision
Rather than returning the number of whole elapsed milliseconds, we now
return the number of elapsed nanoseconds divided by one million. This
allows us to make use of the fractional part of the double that is
returned.
2024-02-26 16:12:20 -07:00
Tim Ledbetter
05c571bf9b LibWeb: Use a precise timer for performance timestamps 2024-02-26 16:12:20 -07:00
Kenneth Myhra
0b64a71603 LibWeb: Make File a Serializable object 2024-02-26 16:10:20 -07:00
Kenneth Myhra
27445f3132 LibWeb: Add ability to {,de}serialize platform objects
This adds the ability to serialize and deserialize serializable platform
object in structured_serialize() and structured_deserialize().
2024-02-26 16:10:20 -07:00
Kenneth Myhra
394c38729f LibWeb: Make Blob a Serializable object 2024-02-26 16:10:20 -07:00
Kenneth Myhra
fc12402b49 LibWeb: Add abstract class Serializable
This adds the abstract class Serializable which platform objects defined
as Serializable objects can implement to support their appropriate
serialization and deserialization steps.
2024-02-26 16:10:20 -07:00
Kenneth Myhra
dcf5ff5178 LibWeb: Move serialize_* methods outside scope of Serializer class
These methods are useful independent of the class Serializer, so let's
move their declarations to the header file and and outside the scope of
the Serializer class.
2024-02-26 16:10:20 -07:00
Kenneth Myhra
985d0dd270 LibWeb: Move deserialize_* methods outside scope of Deserializer class
These methods are useful independent of the class Deserializer, so let's
move their declarations to the header file and and outside the scope of
the Deserializer class.
2024-02-26 16:10:20 -07:00
Bastiaan van der Plaat
c41b359ca5 LibWeb: Use WebIDL types where possible instead of C types 2024-02-26 19:26:13 +00:00
Timothy Flynn
108521a566 LibWeb+LibWebView+WebContent: Implement more <input type=file> behavior
We had previous implemented some plumbing for file input elements in
commit 636602a54e.

This implements the return path for chromes to inform WebContent of the
file(s) the user selected. This patch includes a dummy implementation
for headless-browser to enable testing.
2024-02-26 14:18:49 +01:00
Timothy Flynn
435c2c24d1 LibWeb: Create a shadow tree for <input type=file> elements
This creates a button to prompt users to select a file, and a label to
show information about the selected file(s). Clicking either shadow
element will activate the input element.
2024-02-26 14:18:49 +01:00
Timothy Flynn
8319c7cfb8 LibWeb: Move code to update HTMLInputElement's shadow tree to a helper
We currently copy-paste a series of if statements to selectively update
the shadow tree elements for some <input> types. This will soon become
longer as more shadow trees are implemented for other types.

This patch just moves those checks to a single location to make adding
more shadow trees easier.
2024-02-26 14:18:49 +01:00
Aliaksandr Kalenik
18d26142f0 LibWeb: Skip StackingContext with erroneously large rect in GPU painter
If the GPU painter encounters a stacking context that requires the
allocation of a framebuffer so large, it is likely due to a layout
mistake, for now, we can skip it instead of crashing because of a
failed allocation.

Fixes https://github.com/SerenityOS/serenity/issues/22608
2024-02-26 07:40:42 +01:00
Matthew Olsson
0f54d797d2 LibWeb: Handle pre-existing animations when considering animation-name
If a DOM::Element has an animation-name property, then in addition to
remembering where it came from, it will also remember the
Animations::Animation object that was created for it. This allows
StyleComputer to cancel that animation if the animation-name property
changes as well as to apply any changes required (for example, if
animation-play-state changes from "running" to "paused", it needs to
call .pause() on the animation).
2024-02-25 21:12:42 +00:00
Matthew Olsson
b235620315 LibWeb: Pause keyframe animations during creation when necessary 2024-02-25 21:12:42 +00:00
Matthew Olsson
2ee022dead LibWeb: Set KeyframeEffect's pseudo-element if applicable 2024-02-25 21:12:42 +00:00
Matthew Olsson
921f6c1e78 LibWeb: Run play tasks before pause tasks
The logic of play() and pause() assumes this to be the case
2024-02-25 21:12:42 +00:00
Timothy Flynn
090dbac5a3 Revert "LibWeb: Allow bypassing transient activation checks for tests"
This reverts commit e52c30cbd5.

It's highly possible that this test was flaky on CI due to mixing units
of seconds and milliseconds in the transient activation calculation.
Revert the workaround for that commit in an attempt to avoid needless
ad-hoc behavior.
2024-02-25 12:35:49 -05:00
Timothy Flynn
8d7a5afe58 LibWeb: Increase the transient activation duration from 5ms to 5s
It seems we were errantly mixing seconds and milliseconds in this
transient activation timeout. Increase it to 5 seconds, and be explicit
about its type - DOMHighResTimeStamp is by definition milliseconds.
2024-02-25 12:35:49 -05:00
Andreas Kling
a61f09a010 LibWeb: Stretch-fit flex items with aspect ratio but no fixed sizes
This solves a particular issue with SVG as flex items, where the SVG has
an intrinsic aspect ratio via its viewBox, but no explicit natural width
or height.

Makes all corporate sponsor logos show up on https://ziglang.org/ :^)
2024-02-25 14:06:06 +01:00
Andreas Kling
b7f80e7081 LibWeb: Put debug spam about failed favicon decodes behind a flag 2024-02-25 13:34:21 +01:00
Aliaksandr Kalenik
bc640b72b1 LibWeb: Remove spammy dbgln about unsupported SVG mask content units
This one was annoying because it was printed before each repaint on
pages where this FIXME is relevant.
2024-02-25 11:11:25 +01:00
Aliaksandr Kalenik
e3c75d7b6f LibWeb: Add HTMLElement::is_content_editable() 2024-02-25 10:17:25 +01:00
Aliaksandr Kalenik
934aa6af6a LibWeb: Emit "focusin" and "focusout" events 2024-02-25 10:17:25 +01:00
Aliaksandr Kalenik
cd7b5b18e4 LibWeb: Emit "selectionchange" event on document 2024-02-25 10:17:25 +01:00
Shannon Booth
9ce8189f21 Everywhere: Use unqualified AK::URL
Now possible in LibWeb now that there is no longer a Web::URL.
2024-02-25 08:54:31 +01:00
Shannon Booth
f9e5b43b7a LibWeb: Rename URL platform object to DOMURL
Along with putting functions in the URL namespace into a DOMURL
namespace.

This is done as LibWeb is in an awkward situation where it needs
two URL classes. AK::URL is the general purpose URL class which
is all that is needed in 95% of cases. URL in the Web namespace
is needed predominantly for interfacing with the javascript
interfaces.

Because of two URLs in the same namespace, AK::URL has had to be
used throughout LibWeb. If we move AK::URL into a URL namespace,
this becomes more painful - where ::URL::URL is required to
specify the constructor (and something like
::URL::create_with_url_or_path in other places).

To fix this problem - rename the class in LibWeb implementing the
URL IDL interface to DOMURL, along with moving the other Web URL
related classes into this DOMURL folder.

One could argue that this name also makes the situation a little
more clear in LibWeb for why these two URL classes need be used
in the first place.
2024-02-25 08:54:31 +01:00
Matthew Olsson
62f62a0e52 LibWeb: Correctly set timing function in AnimationEffect::update_timing
Also pulls out the parse_easing_string function out since it will be
needed elsewhere
2024-02-25 08:51:50 +01:00
Matthew Olsson
b33bb0997a LibWeb: Move easing parsing code out into a dedicated function
This will be used outside of StyleComputer
2024-02-25 08:51:50 +01:00
Matthew Olsson
c8b9c137a1 LibWeb: Handle discrete properties
This also changes transform's animation-type to by-computed-value. It is
far easier to handle since we switch on StyleValue::type(), and it might
be the case that this applies to all custom animated properties and we
don't need "custom" at all, but let's wait until we get to those
properties to make that decision.
2024-02-25 08:51:50 +01:00
Matthew Olsson
ee63c729e5 LibWeb: Expand shorthand properties in KeyframeEffect 2024-02-25 08:51:50 +01:00
Matthew Olsson
9e0ff9c140 LibWeb: Expose CSS shorthand -> longhand conversion
This conversion needs to be done by KeyframEffect as well
2024-02-25 08:51:50 +01:00
Matthew Olsson
af1f0c673e LibWeb: Remove old animation-direction handling from StyleComputer
This is now handled by Web Animations, so if the animation was ever
running backwards, this logic would re-reverse it so that it played
forwards again.
2024-02-25 08:51:50 +01:00
Matthew Olsson
70ded2ef42 LibGfx: Add Oklab support to Gfx::Color
Interpolation of color on the web is done via the oklab colorspace
2024-02-25 08:51:50 +01:00
Bastiaan van der Plaat
089a98607c LibWeb: Add HTMLPreElement width property 2024-02-24 16:35:11 -07:00
Tim Ledbetter
1d825f17c0 LibWeb: Remove first rule if no argument is given for remove_rule()
While this isn't explicitly mentioned in the specification, there is a
WPT test that checks for this behavior.
2024-02-24 21:59:28 +01:00
Tim Ledbetter
3ea318ca8b LibWeb: Implement CSSStyleSheet.addRule()
This is a legacy method that has been superseded by `insertRule()`,
although it is supported by all modern browser engines.
2024-02-24 21:59:28 +01:00
Tim Ledbetter
87b52a1816 LibWeb: Implement CSSStyleSheet.replaceSync()
This method behaves the same as `CSSStyleSheet.replace()` but the
operation is performed synchronously.
2024-02-24 21:59:28 +01:00
Tim Ledbetter
81c67d34eb LibWeb: Implement CSSStyleSheet.replace()
This method asynchronously replaces the content of the given stylesheet
with the content passed to it.

An exception is thrown if this method is used by a stylesheet not
created with the `CSSStyleSheet()` constructor.
2024-02-24 21:59:28 +01:00
Tim Ledbetter
d209d5a84f LibWeb: Ensure CSSStyleSheet::css_rules() always returns the same object
Instead of having a method that replaces the stylesheet's CSSRuleList,
we now have a method on CSSRuleList to modify it's underlying CSSRules.
2024-02-24 21:59:28 +01:00
Tim Ledbetter
811033ec19 LibWeb: Disallow inserting @import rules into a constructed stylesheet 2024-02-24 21:59:28 +01:00
Tim Ledbetter
b0f57a2785 LibWeb: Add CSSStyleSheet constructor binding 2024-02-24 21:59:28 +01:00
Tim Ledbetter
f303905875 LibWeb: Add the CSSStyleSheet.rules alias for CSSStyleSheet.cssRules 2024-02-24 21:59:28 +01:00
Tim Ledbetter
9b1ea4e2fc LibWeb: Add CSSStyleSheet.ownerRule attribute
This returns the `CSSImportRule` corresponding to the `@import` at-rule
that imported the stylesheet into the document. If the stylesheet
wasn't imported then this property is null.
2024-02-24 21:59:28 +01:00
Tim Ledbetter
588a031e2d LibWeb: Clamp calculated border width values to zero
Previously, a calculated CSS border-width property with a resolved
value of less than zero pixels would cause a crash.
2024-02-24 21:57:24 +01:00
Andreas Kling
8addfc14af LibWeb: Implement IntersectionObserver "intersection roots" per spec
In particular, get the implicit root correctly for intersection
observers that don't have an explicit root specified.

This makes it possible to load the Terminal app on https://puter.com/
2024-02-24 19:56:08 +01:00
Andreas Kling
9759f44faf LibWeb: Allow SVGDecodedImageData to cache bitmaps at different sizes
This avoids constantly re-rendering the same SVG image over and over
during painting when it's being used at a couple of different sizes
(for example when used as a CSS background).
2024-02-24 19:56:08 +01:00
Andreas Kling
11b4216e65 LibWeb: Run IntersectionObserver steps only when needed
Instead of updating IOs in every iteration of the HTML event loop,
we now only do it after a relayout, or after the viewport changes.
2024-02-24 19:56:08 +01:00
Aliaksandr Kalenik
d3f8d24abb LibWeb+WebContent: Remove PageClient::page_did_invalidate()
...and schedule repainting directly from Navigable::set_needs_display()
bypassing PageClient.
2024-02-24 16:54:55 +01:00
Aliaksandr Kalenik
c3f5dbb101 LibWeb: Paint page only if something that requires repaint happened
Resolves a performance regression from
8ba18dfd40, where moving paint scheduling
to `EventLoop::process()` led to unnecessary repaints.

This update introduces a flag to trigger repaints only when necessary,
addressing the issue where repaints previously occurred with each event
loop process, irrespective of actual changes.
2024-02-24 16:54:55 +01:00
Aliaksandr Kalenik
906ac71eca LibWeb: Fix crashing after input into empty contenteditable
Change `EventHandler::handle_keydown()` to no longer assume the cursor
position's node is always a `DOM::Text`. While this assumption holds
for `HTMLInputElement` that has a shadow DOM with a text node, an empty
`contenteditable` might not have any children. With this change,
`handle_keydown()` creates a new text node if the cursor position's
node is not a text node.
2024-02-24 08:09:01 +01:00
Aliaksandr Kalenik
5d76fa72e9 LibWeb: Add HTMLElement::did_receive_focus() 2024-02-24 08:09:01 +01:00
Aliaksandr Kalenik
6b17ab77f3 LibWeb: Do not delete empty range in EventHandler::handle_keydown()
Fixes a crash that occurs when inputting into an empty contenteditable
element (`EditEventHandler::handle_delete()` assumes the cursor
position's node is always `DOM::Text`, which is not the case for an
empty `contenteditable`).
2024-02-24 08:09:01 +01:00
Aliaksandr Kalenik
05d5e11966 LibWeb: Allow HTMLElement with contenteditable=true to be focusable 2024-02-24 00:19:55 +01:00
Matthew Olsson
d2cfea5acc LibWeb: Add Animation event handler attributes 2024-02-23 21:23:57 +01:00
Matthew Olsson
2dd5d0c310 LibWeb: Implement Animation.reverse() 2024-02-23 21:23:57 +01:00
Matthew Olsson
9ab73f2675 LibWeb: Implement Animation.updatePlaybackRate() 2024-02-23 21:23:57 +01:00
Matthew Olsson
d351389d72 LibWeb: Implement Animation.persist() 2024-02-23 21:23:57 +01:00
Matthew Olsson
3c055ff76d LibWeb: Implement Animation.cancel() 2024-02-23 21:23:57 +01:00
Matthew Olsson
9abe472928 LibWeb: Implement Animation.finish() 2024-02-23 21:23:57 +01:00
Matthew Olsson
c0b9179d9a LibWeb: Implement Animation.pause() 2024-02-23 21:23:57 +01:00
Matthew Olsson
fc62989f1a LibWeb: Add missing visits for Document's pending animation event queue 2024-02-23 20:52:37 +01:00
Matthew Olsson
4e27d07ff2 LibWeb: Use initial value for animation start if it does not exist
This fixes an issue where a property could not be animated unless the
element had a specified value for that property somewhere in its
styling.
2024-02-23 20:52:37 +01:00
Matthew Olsson
65858154de LibWeb: Dispatch Animation events 2024-02-23 20:52:37 +01:00
Matthew Olsson
ae3326a447 LibWeb: Transition StyleComputer to Web Animations
With this commit, we are finally running animations off of the web
animations spec! A lot of the work StyleComputer is doing is now done
elsewhere. For example, fill-forward animations are handled by
Animation::is_relevant() returning true in the after phase, meaning the
"active_state_if_fill_forward" map is no longer needed.
2024-02-23 20:52:37 +01:00
Tim Ledbetter
b073fdd570 LibWeb: Invert return value from EventHandler key event handling methods
`EventHandler::handle_keyup()` and `EventHandler::handle_keydown()`
return true if the event has been handled and false otherwise. This is
the opposite behavior to `EventHandler::fire_keyboard_event()`.
This change inverts the return value from `fire_keyboard_event` in
these methods, allowing shortcut keys to be propagated to the Serenity
Browser UI as expected.
2024-02-23 09:53:00 +01:00
Aliaksandr Kalenik
9968c9f7a6 LibWeb: Fix hit-testing by excluding CSS transform from clip rect check
Transforms are applied to both clip rectangle and position, so we need
to remove the transform from clip rectangle before checking if position
falls within the clip rectangle.

In this change, the removal of transform is moved into
`Paintable::clip_rect()` that is shared between hit-testing and
painting.

This change fixes hit-testing in Discord's multifactor authentication
form.
2024-02-22 07:36:20 +01:00
Aliaksandr Kalenik
309259aeb6 LibWeb: Clamp scroll offset into valid range after relayout
If the layout has been recalculated and the sizes of scrollable
overflow rectangles could have changed, we need to ensure that scroll
offsets remain within the valid range.
2024-02-22 07:35:30 +01:00
Aliaksandr Kalenik
155070cfd8 LibWeb: Clamp scroll offset to valid range in set_scroll_offset()
By moving scroll offset clamp from `PaintableBox::scroll_by()` to
`PaintableBox::set_scroll_offset()`, we ensure that updates from
`Element::set_scroll_top()` and `Element::set_scroll_left()` are
constrained to a valid range.
2024-02-22 07:35:30 +01:00
Matthew Olsson
ee4abacde6 LibWeb: Add AnimationEffect::target_properties() 2024-02-22 07:31:54 +01:00
Matthew Olsson
10fddb99fc LibWeb: Implement Document::remove_replaced_animations() 2024-02-22 07:31:54 +01:00
Matthew Olsson
fe848487db LibWeb: Add Document::update_animations_and_send_events 2024-02-22 07:31:54 +01:00
Matthew Olsson
9bab1a95a5 LibWeb: Keep track of AnimationEffect's previous phase and iteration
This will be required for detecting transitions in StyleComputer
2024-02-22 07:31:54 +01:00
Matthew Olsson
35859c0467 LibWeb: Add helpers to convert between FillMode and Direction enums 2024-02-22 07:31:54 +01:00
Dan Klishch
56d355a15e LibWeb: Properly round CSSPixels values in device_to_css_rect
Ceiling width or height of a chrome viewport (this function is only used
when a chrome notifies LibWeb about a new viewport size) is never
correct. If we do that, PageClient::page_did_layout will set content
size to be 1 larger than an actual physical width or height respectively
(it always ceils) and thus a spurious scrollbar will appear.

This prevents occasional scrollbar flickering in Ladybird/Qt on Wayland
with fractional scaling enabled on compositors supporting
wp-fractional-scale-v1.
2024-02-21 20:08:25 +01:00
Timothy Flynn
7bee1c9897 LibWeb: Store the input image button's selected coordinates as integers
The spec has prose which states, e.g., "The x-component must be a valid
integer".
2024-02-21 19:52:59 +01:00
Timothy Flynn
3f3db34587 LibWeb: Support setting dimensions on input image buttons
Users are allowed to specify the height and width of an image button
directly in the HTML.
2024-02-21 19:52:59 +01:00
Matthew Olsson
3ea26327c7 LibWeb: Implement Animatable::get_animations() 2024-02-21 19:52:35 +01:00
Matthew Olsson
145ae54718 LibWeb: Add a few Animation/AnimationEffect getters 2024-02-21 19:52:35 +01:00
Matthew Olsson
06a8674eec LibWeb: Simplify Animation::update_finished_state a bit
This removes the two boolean hack in favor of using the existing
mechanism to remove queued tasks. It also exposes the element
invalidation behavior for call sites that don't necessarily want to
update the finished state, but still need to invalidate the associated
target.
2024-02-21 19:52:35 +01:00
Matthew Olsson
1e37ba5515 LibWeb: Expose Animation::is_finished()
This will be required to handle forward-fill state in StyleComputer
2024-02-21 19:52:35 +01:00
Matthew Olsson
5eea53f27a LibWeb: Keep track of associated AnimationEffects in Animatable 2024-02-21 19:52:35 +01:00
Matthew Olsson
2ade834655 LibWeb: Add Animation::is_replaceable() 2024-02-21 19:52:35 +01:00
Matthew Olsson
4e6c74dcf6 LibWeb: Define the composite order between two animations 2024-02-21 19:52:35 +01:00
Matthew Olsson
ceb9d0f8dc LibWeb: Record position of Animations in global animation list
"position of an Animation in the global animation list" is a fancy way
of saying "which animation object was created first"
2024-02-21 19:52:35 +01:00
Matthew Olsson
c3b689488e LibWeb: Implement animation class-specific composite order
This is a part of determining the composite order of two animations
2024-02-21 19:52:35 +01:00
Tim Ledbetter
1560bfc6c9 LibWeb: Ensure DOMRect top, bottom, left and right handle NaN correctly 2024-02-21 19:38:17 +01:00
Tim Ledbetter
fe66aeb225 LibWeb: Validate arguments when creating DOMPoint from matrix transform
Previously, it was possible to create a DOMPoint from a matrix
transform with inconsistent arguments. A TypeError is now thrown in
this case.
2024-02-21 19:38:17 +01:00
Tim Ledbetter
c5d1ec4dea LibWeb/CSS: Ensure length is absolute before converting to pixels
Previously, creating a DOMMatrix with a transform that contained
non-absolute units would cause a crash.
2024-02-21 19:38:17 +01:00
Tim Ledbetter
5136b495a6 LibWeb: Use NaN safe min() and max() functions to compute DOMQuad bounds 2024-02-21 19:38:17 +01:00
Nico Weber
24a469f521 Everywhere: Prefer {:#x} over 0x{:x} in format strings
The former automatically adapts the prefix to binary and octal
output, and is what we already use in the majority of cases.

Patch generated by:

    rg -l '0x\{' | xargs sed -i '' -e 's/0x{:/{:#/'

I ran it 4 times (until it stopped changing things) since each
invocation only converted one instance per line.

No behavior change.
2024-02-21 17:54:38 +01:00
Andreas Kling
f963bb4f36 LibWeb: Don't mark heights as definite in set_content_height()
Height definiteness is now preserved as intended by CSS-SIZING-3
(assuming I've understood it correctly) and not implicitly granted by
layout algorithms when they assign height.

For the specific special/magical cases where some sizes become definite
during layout, the preceding commits have made them explicit in code.

This fixes a number of flex layout issues where we were previously
resolving percentage values against post-layout flex container heights,
but other browsers don't.
2024-02-21 17:54:05 +01:00
Andreas Kling
0dd8458683 LibWeb: Add FIXME about definiteness to UsedValues::set_content_width()
Fixing this function will be quite an undertaking since a *lot* of code
relies on set_content_width() implicitly flipping the definiteness of
the width. It is wrong though, so we do need to fix it eventually.
2024-02-21 17:54:05 +01:00
Andreas Kling
221650f3cd LibWeb: Mark fixed-length abspos element sizes as definite
In particular, these two interesting cases:

- The containing block of an abspos box is always definite from the
  perspective of the abspos box.

- When resolving abspos box sizes from two opposing fixed insets,
  we now mark those sizes as definite (since no layout was required
  to resolve them).
2024-02-21 17:54:05 +01:00
Andreas Kling
70ce77fc72 LibWeb: Make SVGFormattingContext treat all sizes as definite for now
The whole way we lay out SVG content is ad-hoc, so this doesn't follow
any particular spec. However, our viewport transform logic depends on
having definite sizes, so let's just mark them as such for now.
2024-02-21 17:54:05 +01:00
Andreas Kling
f0269b0a94 LibWeb: Mark root element height as definite when affected by quirk
This will be required for percentages to resolve against it correctly
after we make set_content_height() not automatically mark heights as
definite sizes.
2024-02-21 17:54:05 +01:00
Andreas Kling
b079f4d590 LibWeb: Make flexbox special definite size cases explicit
The CSS-FLEXBOX-1 spec has a bunch of special cases where sizes are
considered definite after reaching a specific point of the layout
algorithm.

Before this change, we were relying on set_content_width/height also
implicitly marking those content sizes as definite.

To prepare for that implicit behavior going away, this patch makes
the special cases explicit.
2024-02-21 17:54:05 +01:00
Andreas Kling
5a995e95e3 LibWeb: Add UsedValues::set_has_definite_width/height()
These will be used to explicitly mark some box geometry as definite
at various stages of layout. It's gonna get finicky.
2024-02-21 17:54:05 +01:00
Andreas Kling
b83e41c9b5 LibWeb: Only assign block container heights during BFC intrinsic sizing
Before this change, we were always assigning the calculated height to
each block container after laying it out in BFC.

This should really only happen during intrinsic sizing, since that is
how measurements are communicated to the client there.
2024-02-21 17:54:05 +01:00
auipc
6a662e0d43 LibWeb: Add various window transformation methods 2024-02-21 15:53:27 +00:00
Tim Ledbetter
3b7c252175 LibWeb: Implement AbortSignal.abort()
This returns an AbortSignal that is already set as aborted.
2024-02-21 10:34:44 +01:00
Andrew Kaster
0dde88d714 LibWeb: Treat global as EventTarget in notify_about_rejected_promises
We only need to know that the Global Object of the environment is an
event target in order to dispatch an event on it. This resolves a FIXME
where we assumed that the only type of Global in LibWeb is HTML::Window.
2024-02-21 10:11:59 +01:00
Andrew Kaster
cb68c6eaf1 LibWeb: Set size of canvas used to take WebDriver screenshots explicitly
The default canvas size is 300x150 pixels. If the element or document
we are trying to screenshot for the WebDriver is not at least that size,
then we will create a canvas that is wider or taller than the actual
element we are painting, resulting in a bunch of transparent pixels
falling off the end.

This fixes 14 WPT css/CSS2/floats tests that we run in CI, and
presumably a ton of other reftests in the WPT test suite.
2024-02-21 10:10:44 +01:00
Aliaksandr Kalenik
aee5120078 LibWeb: Fix infinite recursion when grid has "max-width: max-content"
With this change "max-width: max-content" is treated as "none" when
the available width is also "max-content". This fix prevents a stack
overflow in the grid track size maximization algorithm by avoiding
recursive calls to calculate_max_width() when determining the maximum
grid container size.
2024-02-21 10:06:19 +01:00
Timothy Flynn
e52c30cbd5 LibWeb: Allow bypassing transient activation checks for tests
We have a 5 second timeout between a user-activated event occurring and
an activation-gated API being invoked in order for that API to succeed.
This is quite fine in normal circumstances, but the machines used in CI
often exceed that limit (we see upwards of 10 seconds passing between
generating the user-activated event and the API call running).

So instead of generating a user-activated event, add a hook to allow
tests to bypass the very next activation check.
2024-02-20 18:53:59 -05:00
Aliaksandr Kalenik
c4f49e343a LibWeb: Fix division by zero in solve_replaced_size_constraint()
Fixes crashes that occur in Discord after clicking on a direct messages
conversation.
2024-02-20 20:35:34 +01:00
Timothy Flynn
af57bd5cca LibWeb: Stop parsing after document.write at the insertion point
If a call to `document.write` inserts an incomplete HTML tag, e.g.:

    document.write("<p");

we would previously continue parsing the document until we reached a
closing angle bracket. However, the spec states we should stop once we
reach the new insertion point.
2024-02-20 17:04:36 +01:00
Timothy Flynn
64dcd3f1f4 LibWeb: Restore the previous tokenizer iterator after inserting input
Otherwise, m_prev_utf8_iterator still points at the old source.
2024-02-20 17:04:36 +01:00
Timothy Flynn
fcf83a8ed0 LibWeb: Allocate fewer strings during document.write 2024-02-20 17:04:36 +01:00
Timothy Flynn
f07f5a2622 LibWeb+WebContent: Do not embed attributes as data in the Inspector HTML
Attribute values may contain HTML, and may contain invalid HTML at that.
If the latter occurs, let's not generate invalid Inspector HTML when we
embed the attribute values as data attributes. Instead, cache the values
in the InspectorClient, and embed just a lookup index into the HTML.

This also nicely reduces the size of the generated HTML. The Inspector
on https://github.com/SerenityOS/serenity reduces from 2.3MB to 1.9MB
(about 318KB, or 13.8%).
2024-02-20 17:04:36 +01:00
Aliaksandr Kalenik
036cd9b2dd LibWeb: Null layout and paintable pointers of removed DOM::Node
When a node is removed from the DOM tree, its paintable needs to be
removed to ensure that it is not used to obtain sizes that are no
longer valid.

This change enables the ResizeObserver to send a notification if a node
is removed, as it should, because a removed node now has a size of zero

It should be okay to nullify pointers without concerning
parent/sibling/child relationships because the layout and paintable
trees will be rebuilt following any DOM mutation anyway.
2024-02-20 10:55:10 +01:00
Aliaksandr Kalenik
2b7e7cc1ad LibWeb: Implement ResizeObserver::disconnect() 2024-02-20 10:55:10 +01:00
Aliaksandr Kalenik
70a0f07732 LibWeb: Implement ResizeObserver::unobserve() 2024-02-20 10:55:10 +01:00
Aliaksandr Kalenik
fcf293a8df LibWeb: Implement gathering and broadcasting of resize observations
Extends event loop processing steps to include gathering and
broadcasting resize observations.

Moves layout updates from Navigable::paint() to event loop processing
steps. This ensures resize observation processing occurs between layout
updates and painting.
2024-02-20 10:55:10 +01:00
Aliaksandr Kalenik
8ba18dfd40 LibWeb: Schedule repainting from EventLoop::process()
In this change, updating layout and painting are moved to the EventLoop
processing steps. This modification allows the addition of resize
observation dispatching that needs to happen in event loop processing
steps and must occur in the following order relative to layout and
painting:

1. Update layout.
2. Gather and broadcast resize observations.
3. Paint.
2024-02-20 10:55:10 +01:00
Aliaksandr Kalenik
fb8edcea00 LibWeb: Flesh out implementation of ResizeObserver interfaces
Adds the initial implementation for interfaces defined in the
ResizeObserver specification. These interfaces will be used to
construct and send observation events in the upcoming changes.
2024-02-20 10:55:10 +01:00
Matthew Olsson
cac11ac891 LibWeb: Use [ExplicitNull] in Animation.idl 2024-02-19 14:51:56 -05:00
Aliaksandr Kalenik
591c8d2b68 LibWeb: Return overflow rect height from Element::scroll_height()
Spec says that this function has to return "height of the element
scrolling area" which is height of "scrolling overflow rect" in our
model.
2024-02-19 20:07:12 +01:00
Aliaksandr Kalenik
9f581d0bc9 LibWeb: Return overflow rect width from Element::scroll_width()
Spec says that this function has to return "width of the element
scrolling area" which is width of "scrolling overflow rect" in our
model.
2024-02-19 20:07:12 +01:00
Aliaksandr Kalenik
89319cd0c9 LibWeb: Make sure layout is up to date in Element::scroll_height() 2024-02-19 20:07:12 +01:00
Aliaksandr Kalenik
639e9b5012 LibWeb: Make sure layout is up to date in Element::scroll_width() 2024-02-19 20:07:12 +01:00
Matthew Olsson
1d98f812af LibWeb: Generate KeyframeSet in KeyframeEffect::set_keyframes
This is similar to the logic used in StyleComputer (except a bit closer
to the spec), and will eventually be shared between the two.
2024-02-19 12:21:48 +01:00
Matthew Olsson
1735f3d9aa LibWeb: Add keyframe state to KeyframeEffect
This was taken from StyleComputer, and will eventually be removed from
StyleComputer once we transition to using Web animations.
2024-02-19 12:21:48 +01:00
Matthew Olsson
7d5e17eddd LibWeb: Implement Animatable::animate() 2024-02-19 12:21:48 +01:00
Matthew Olsson
dd1fd5fe47 LibWeb: Add Animatable interface to Element 2024-02-19 12:21:48 +01:00
Timothy Flynn
94c67c364d LibWeb: Implement HTMLInputElement's selected coordinates
When an <input type=image> button is clicked, we now send the (x,y)
coordinates of the click event (relative to the image) along with the
form submission data.

Regarding the text test, we can currently only test this feature with
dialogs. The headless-browser test infrastructure cannot yet handle the
resulting navigation that would occur if we were to test with normal
form submission.
2024-02-19 11:07:30 +01:00
Timothy Flynn
36302388a3 LibWeb: Allow submitting forms whose submission URL is a file:// URL
In particular, this will allow us to test form submission on such URLs.
2024-02-19 11:07:30 +01:00
Timothy Flynn
986811d2aa LibWeb: Do not use HTMLFormElement::elements to get submittable elements
HTMLFormElement::elements is not the correct filter for submittable
elements. It includes non-submittable elements (HTMLObjectElement) and
also excludes submittable elements (HTMLInputElements in the "image"
type state, "for historical reasons").
2024-02-19 11:07:30 +01:00
Timothy Flynn
debb5690ce LibWeb: Begin implementing the HTMLInputElement 'image' type state
This implements enough to represent <input type=image> with its loaded
source image (or fallback to its alt text, if applicable). This does not
implement acquring coordinates from user-activated click events on the
image.
2024-02-19 11:07:30 +01:00
Timothy Flynn
45a47cb32b LibWeb: Generalize ImageBox and ImagePaintable for any ImageProvider
They currently assume the DOM node is an HTMLImageElement with respect
to handling the alt attribute. The HTMLInputElement will require the
same behavior.
2024-02-19 11:07:30 +01:00
Timothy Flynn
c4295edc81 LibWeb: Add ImageBox to forwarding header 2024-02-19 11:07:30 +01:00
Tim Ledbetter
02c2b1e67e LibWeb: Implement document.createCDATASection() 2024-02-19 10:42:56 +01:00
Tim Ledbetter
ee6b0e144a LibWeb: Make the default XML namespace an empty Optional
Previously, when constructing an XML document, the default namespace
was the empty string. This led to XML documents having empty xmlns
attributes when serialized.
2024-02-19 10:42:56 +01:00
Tim Ledbetter
1a249f9d85 LibWeb: Add ad-hoc method for serializing CDATASection nodes to string
Previously, CDATASection nodes were being serialized as if they were
text, which meant they were missing their start and end delimiters.
Occurrences of the '&', '<' and '>' characters were also being replaced
with their entity names.
2024-02-19 10:42:56 +01:00
Tim Ledbetter
70b9cddc48 LibWeb: Align Document::document_type() default with the specification
The DOM specification states that: "Unless stated otherwise, a
document’s [...] type is 'xml'".

Previously, calls to `Document::document_type()` were returning the
incorrect value for non-HTML documents.
2024-02-19 10:42:56 +01:00
Tim Ledbetter
f18ea096e0 LibWeb: Set correct document type when parsing XML with DOMParser 2024-02-19 10:42:56 +01:00
Tim Ledbetter
ea9bc8ed6b LibWeb: Set cursor: default for button and select elements
This prevents an IBeam cursor being shown when these elements are
moused over.
2024-02-18 15:44:49 -05:00
Aliaksandr Kalenik
cb97eef2cf LibWeb+WebContent: Remove "Painting" prefix from command executor names
Painting command executors are defined within the "Painting" namespace,
allowing us to remove this prefix from their names.

This commit performs the following renamings:

- Painting::PaintingCommandExecutor to Painting::CommandExecutor
- Painting::PaintingCommandExecutorCPU to Painting::CommandExecutorCPU
- Painting::PaintingCommandExecutorGPU to Painting::CommandExecutorGPU
2024-02-18 18:45:25 +01:00
Aliaksandr Kalenik
11d746a67f LibWeb+WebContent: Separate painting command list from RecordingPainter
Separating the recorder list from the painter will allow us to save it
for later execution without carrying along the painter's state. This
will be useful once we have a separate thread for executing painting
commands, to which we will have to transfer commands from the main
thread.

Preparation for https://github.com/SerenityOS/serenity/pull/23108
2024-02-18 18:45:25 +01:00
Timothy Flynn
ce9ad3a236 LibWeb: Fully implement the HTMLInputElement value setter and getter
The setter was missing an implementation for the default and default/on
value attribute modes. This patch adds a method to get the current value
attribute mode, and implements the value setter and getter based on that
mode according to the spec.
2024-02-18 18:44:45 +01:00
MacDue
cfb9c5bb0e LibWeb: Fix checks for elements in XMLDocumentBuilder
Previously, this just checked the tag names. For elements that exist in
different namespaces (like HTMLScriptElement vs SVGScriptElement) this
could lead to invalid casts, as the namespace was not checked.

This switches to using the safer helpers on the DOM::Node.
2024-02-18 18:33:11 +01:00
MacDue
4843100650 LibWeb: Run scripts in XML SVG documents
This will be needed to add a hit testing test for #22305.
2024-02-18 18:33:11 +01:00
MacDue
957c20b676 LibWeb: Avoid infinite recursion when hit testing SVGs
Previously, step 5 of the stacking context hit testing would just call
`hit_test()` on the stacking context's paintable box. Which (at least
for SVGs) is just indirect infinite recursion (it'll end up right back
where it started after going through a few functions).

This now explicitly hit tests the descendants, which seems more correct,
and avoids the crash for SVGs, but nothing really seems to depend on
this step. Another solution (which I've done for a while working on
SVGs) is just to delete step 5 entirely, and nothing seems to break.

Fixes #22305
2024-02-18 18:33:11 +01:00
Andrew Kaster
5d2a36f244 LibWeb: Stub out all the functions from the execCommand spec
Per the specification, it's ok if we say that nothing is supported.

It's not ok if we say something is supported but do nothing, apparently.
2024-02-16 19:31:54 -05:00
Tim Ledbetter
816d24f647 LibWeb: Implement HTMLFormElement.requestSubmit()
This can be used to submit a form using a specific submit button.
2024-02-16 17:21:48 -05:00
Andrew Kaster
94149db073 LibWeb: Implement Document named properties with light caching
We now cache potentially named elements on the Document when elements
are inserted and removed. This allows us to do lookup of what names are
supported much faster than if we had to iterate the tree every time.

This first cut doesn't implement the rules for 'exposed' object and
embed elements.
2024-02-16 16:18:31 -05:00
Matthew Olsson
faaf5b9652 LibWeb: Add the AnimationEvent IDL objects 2024-02-16 12:02:11 -07:00
Matthew Olsson
3a87c000c4 LibWeb: Add the CSSAnimation IDL object 2024-02-16 12:02:11 -07:00
Matthew Olsson
3721a1a81c LibWeb: Run update_finished_state when setting AnimationEffect's timing
This will need to a necessary style invalidation
2024-02-16 12:02:11 -07:00
Matthew Olsson
6d25bf3aac LibWeb: Invalidate element when setting AnimationEffect's animation 2024-02-16 12:02:11 -07:00
Matthew Olsson
ce99636cd0 LibWeb: Fix check for missing argument in Animation constructor
Receiving a null argument has a different result than not passing an
argument at all.
2024-02-16 12:02:11 -07:00
Tim Ledbetter
c24652bd2e LibWeb: Implement document.scrollingElement
This returns a reference to the element that scrolls the document. In
standards mode it is equivalent to `document.documentElement`.
2024-02-15 22:51:15 -05:00
Matthew Olsson
14200de80b LibWeb: Set DocumentTimeline origin time to zero
The current time should be used to set the timeline's new current time,
not its origin time
2024-02-15 12:34:19 +01:00
Matthew Olsson
727a9a6472 LibWeb: Run pending play tasks when the timeline time changes
Note that the timeline time changes every animation frame when the
Document sends out animation events
2024-02-15 12:34:19 +01:00
Matthew Olsson
daaaaec2d0 LibWeb: Add the Animatable IDL object 2024-02-15 12:34:19 +01:00
Matthew Olsson
4792dc294b LibWeb: Implement Animation::play 2024-02-15 12:34:19 +01:00
Matthew Olsson
88518c29ca LibWeb: Combine "pending" and "ASAP" animation task states
It seems that the difference between pending and ASAP in the spec is
only to allow the implementation to perform implementation-defined
operations between the two states. We don't need to distinguish the two
states, so lets just combine them for now.
2024-02-15 12:34:19 +01:00
Tim Ledbetter
0ecbdc4627 LibWeb: Add support for form submission method 'dialog' 2024-02-14 22:20:44 -05:00
Tim Ledbetter
151cd11b5b LibWeb: Implement HTMLDialogElement::show() 2024-02-14 22:20:44 -05:00
Tim Ledbetter
8042558805 LibWeb: Implement HTMLDialogElement::close() for non-modal dialogs 2024-02-14 22:20:44 -05:00
Aliaksandr Kalenik
88ad871e2b LibWeb: Do paint-order traversal in Document::element_from_point()
Specify callback for hit-test function to identify closest DOM element,
excluding text nodes. Add a previously failing test case.
2024-02-14 06:56:22 +01:00
Aliaksandr Kalenik
9d2809146f LibWeb: Do paint-order traversal in Document::elements_from_point()
Elements are now collected according to paint order as spec says,
replacing the depth-first traversal of the paint tree with hit-testing
on each box.

This change resolves a FIXME in an existing test and adds a new
previously non-working test.
2024-02-14 06:56:22 +01:00
Aliaksandr Kalenik
9c99182b1e LibWeb: Change StackingContext::hit_test() to accept callback
This change modifies hit_test() to no longer return the first paintable
encountered at a specified position. Instead, this function accepts a
callback that is invoked for each paintable located at a position, in
hit-testing order.

This modification will allow us to reuse this call for
`Document.elementsFromPoint()` in upcoming changes.
2024-02-14 06:56:22 +01:00
Tim Ledbetter
877641f626 LibWeb: Display an IBeam cursor by default when mousing over a text node
We now check the type of the layout node at the current mouse position
when determining which cursor to display during a mouse move event.
2024-02-13 19:47:39 +01:00
Andrew Kaster
2b3bc2654f LibWeb: Mark Navigable as destroyed in destroy_top_level_traversable AO
Without this, a top level traversable might show up in settings we don't
want it to when accessing all_navigables, such as choose a navigable.
2024-02-13 19:46:10 +01:00
Andrew Kaster
a0e7af0cd9 LibWeb: Don't choose destroyed navigables in choose a navigable AO
There's a chance that we try to choose a navigable before a previously
destroyed navigable is fully destroyed and GC'd. Investigating why this
can happen is a separate endeavor, let's just not crash for now.
2024-02-13 19:46:10 +01:00
Matthew Olsson
3c9c134d71 LibWeb: Implement KeyframeEffect::{get,set}_keyframes 2024-02-13 19:44:44 +01:00
Matthew Olsson
38c67ba17c LibWeb: Implement parsing a monolithic keyframes-like argument
See the last commit for a more in-depth explanation
2024-02-13 19:44:44 +01:00
Matthew Olsson
7d69fa0ccf LibWeb: Partially implement the "process a keyframes argument" procedure
Keyframes can be given in two separate forms:

- As an array of separate keyframe objects, where the keys of each
  keyframe represent CSS properties, and their values represents the
  values that those CSS properties should take

  e.x.:
  [{ color: 'red', offset: 0.3 }, { color: 'blue', offset: 0.7 }]

- As a single monolithic keyframe object, where the keys of each
  keyframe represent CSS properties, and their values are arrays of
  values, where each index k represents the value of the given
  property at the k'th frame.

  e.x.:
  { color: ['red', 'blue'], offset: [0.3, 0.7] }

This commit only implements the first option, as it is much simpler. See
the next commit for the implementation of the second option.
2024-02-13 19:44:44 +01:00
Matthew Olsson
9f404ed9c1 LibWeb: Implement the "compute missing keyframe offsets" procedure 2024-02-13 19:44:44 +01:00
Matthew Olsson
38153b47d6 LibWeb: Implement the "process a keyframe-like object" procedure 2024-02-13 19:44:44 +01:00
Matthew Olsson
212a139292 LibWeb: Add a way to test if a CSS::PropertyID is animatable 2024-02-13 19:44:44 +01:00
Aliaksandr Kalenik
edab67d5e8 LibWeb: Fix hit-testing for button element
Change 'dom_node_for_event_dispatch' to locate the closest layout node
with a DOM node instead of only checking the direct ancestor.

This fixes hit-testing for buttons because they are wrapped into
multiple anonymous layout nodes (internally we use flex formatting for
them).
2024-02-13 14:22:14 +01:00
Andrew Kaster
6a0fe08604 LibWeb: Implement document.elementsFromPoint
This API seems to be used by WPT for sending synthetic input events.

Implementing the naive translation of elementFromPoint to the spec steps
for this algorithm turns 4 'tests had errors unexpectedly' and 3 'tests
had timeouts unexpectedly' into 1 pass and 7 'tests had unexpected
subtest results' on the infrastructure/ subdirectory of WPT.
2024-02-12 11:43:22 -07:00
Andrew Kaster
e7daa02bf2 LibWeb: Unblock port 9000
This was blocked because it can be used for cross-protocol attacks on
some network printers. However, it's also used by the web platform
tests. One can argue that getting WPT working is more important than
theoretical attacks on poorly configured printers.
2024-02-12 11:43:22 -07:00
Andrew Kaster
deb11a669a LibWeb: Stub out WebDriver deserialize as a proxy capability AO
This prevents us from returning an 'unrecognized capability' error when
a WebDriver client sends us a proxy capability. We still don't actually
support setting or returning a non-empty proxy capability, though.

We just don't choke on the input capability request from the server.

This patch also doesn't actually validate the input proxy requests.
2024-02-12 11:43:22 -07:00
Aliaksandr Kalenik
95d91a37d2 LibWeb: Resolve outline CSS property before paint commands recording
Refactor to resolve paint-only properties before painting, aiming to
stop using layout nodes during recording of painting commands.

Also adds a test, as we have not had any for outlines yet.
2024-02-12 13:38:24 +01:00
MacDue
f19b17e089 LibWeb: Use paths for text in CRC2D (if possible)
This allows for:

  * Transformed text (e.g. rotated text)
  * Stroked text
  * Filling/stroking text with PaintStyles (e.g. gradients)
  * Squashed/condensed text (via maxWidth parameter)

Fixes part of #22817
2024-02-12 13:38:10 +01:00
Tim Ledbetter
774119bb57 LibWeb: Implement document.designMode
Setting this attribute to "on" makes the entire document editable.
2024-02-12 07:35:14 +01:00
Tommy van der Vorst
1c7ec9c770 LibWeb: Ignore repeat(auto-fit/auto-fill, auto) as it is not allowed 2024-02-11 17:51:50 +01:00
Tim Ledbetter
7f2582fca9 LibWeb: Update the cursor position when an editable element is clicked
With this change, clicking on an editable element, such as an `input`
or `textarea` causes the cursor position to be updated to the current
mouse position.
2024-02-11 08:15:38 +01:00
Aliaksandr Kalenik
d4932196cc LibWeb: Account for all clipped border radii in containing block chain
With this change, instead of applying only the border-radius clipping
from the closest containing block with hidden overflow, we now collect
all boxes within the containing block chain and apply the clipping from
all of them.
2024-02-11 08:12:31 +01:00
Aliaksandr Kalenik
1ae416fa94 LibWeb: Add compute_combined_css_transform() for PaintableBox
This prepares for upcoming changes where the code that finds combined
CSS transform will be reused in `clear_clip_overflow_rect()`.
2024-02-11 08:12:31 +01:00
MacDue
080d9ec246 LibWeb: Invalidate layout after setting SVG transform attribute 2024-02-11 08:10:45 +01:00