Commit Graph

14803 Commits

Author SHA1 Message Date
Andreas Kling
afc5fade05 LibWeb: Add some fast_is<T> helpers for hot classes on GitHub :^) 2022-03-13 18:09:43 +01:00
Andreas Kling
39389b5704 LibWeb: Don't make deep copy of custom properties for every element
Previously we were making a copy of the full set of custom properties
that applied to a DOM element. This was very costly and dominated the
profile when mousing around on GitHub.

Note that this may break custom properties on pseudo elements a little
bit, and that's something we'll have to look into.
2022-03-13 18:09:43 +01:00
Andreas Kling
f88d65d9cb LibWeb: Cache CSS::Selector's pseudo element at construction time
Computing the pseudo element of a CSS::Selector was very hot when
mousing around on GitHub in Browser. A profile had it at ~10%.
After these changes, it's totally gone from the profile. :^)
2022-03-13 18:09:43 +01:00
Andreas Kling
f5c2e87965 LibWeb: Sort stacking context tree once, after fully building it
Instead of calling quick_sort() every time a StackingContext child
is added to a parent, we now do a single pass of sorting work after the
full StackingContext tree has been built.

Before this change, the quick_sort() was ~13.5% of the profile while
hovering links on GitHub in the Browser. After the change, it's down to
~0.6%. Pretty good! :^)
2022-03-13 18:09:43 +01:00
Timothy Flynn
0dfb9714fe LibCore: Use altzone for the current time zone offset during DST
Also use the daylight global to determine the current time zone name,
i.e. tzname[0] is standard time, tzname[1] is daylight savings time.

Note that altzone isn't required to be defined on all systems, so we
have to #ifdef to check if it exists in order for Lagom to build.
2022-03-13 17:50:49 +01:00
Timothy Flynn
7fceb909a5 LibC: Use altzone for the current time zone offset during DST 2022-03-13 17:50:49 +01:00
Ali Mohammad Pur
2000251333 LibJS: Implement bytecode generation for WithStatement 2022-03-13 17:50:21 +01:00
Ali Mohammad Pur
57386ca839 LibJS: Initialize 'var' bindings to undefined on declaration
This is what CreateGlobalVarBinding does, so do the same thing in BC.
2022-03-13 17:50:21 +01:00
Ali Mohammad Pur
ba9c4959d6 LibJS: Leave the unwind context on break/continue/return in bytecode
Otherwise we'd keep the old unwind context, and end up never invoking
the other handlers up the stack.
2022-03-13 17:50:21 +01:00
Ali Mohammad Pur
41184c960d LibJS: Propagate abrupt completions in Bytecode::Op::Call
This was not handling the nullary call case correctly, remove the whole
nullary check as there's nothing particularly expensive in the catch-all
case anyway.
2022-03-13 17:50:21 +01:00
mjz19910
fd8a56cdde LibJS: Add some tests for TypedArray.prototype.set 2022-03-13 16:49:25 +01:00
Andreas Kling
13c253d2ee LibWeb: Fix serialization of selectors with universal subject (*)
For seletors whose subject is unversal (i.e selectors that end in "*")
we were not serializing the asterisk. Instead "foo bar *" came out as
"foo bar foo". This patch fixes that by correctly serializing the last
simple selector if it's universal.
2022-03-13 15:41:54 +01:00
MacDue
8fbe96af45 LibVT: Use coarse scrolling animation in TerminalWidget
The smooth scrolling looks slightly off in the terminal as the
scrollbar animation lasts longer than the actual scroll.

This behaviour is also consistent with other terminal emulators.
2022-03-13 11:45:07 +01:00
MacDue
91fff3f1ae LibGUI: Allow setting smooth/coarse scrolling animation on ScrollBar 2022-03-13 11:45:07 +01:00
MacDue
9ab3ab86cb LibGUI: Add m_ prefix to gutter_click_state in ScrollBar
Quick fix, this member did not seem to follow the conventions.
2022-03-13 11:45:07 +01:00
Andrew Smith
297e095755 PixelPaint: Correctly apply flip/rotate/crop to layers' alpha mask
-Layer now has methods for flip/rotate/crop, which are responsible
for handling the alpha mask.
-Fixed crash when the display image size is out of sync with
the content image size.
-Changed API for setting content and mask image in Layer. Now, both
must be set at the same time, and it can result in an error if
you provide mismatched dimensions.
2022-03-13 10:34:38 +01:00
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
Lenny Maiorani
cb87d13dd5 Libraries: Use default constructors/destructors in LibCoredump
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
ea58b8d927 Libraries: Use default constructors/destructors in LibCore
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
c6dcb12b00 Libraries: Use default constructors/destructors in LibCompress
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
7030a9b496 Libraries: Use default constructors/destructors in LibChess
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
11b28c88fc Libraries: Use default constructors/destructors in LibCards
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
2200eb761d Libraries: Use default constructors/destructors in LibAudio
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
Ali Mohammad Pur
7eafa58af8 Revert "LibPthread: Partially implement pthread_cleanup_(push pop)"
This reverts commit 5d51e26caf.
The threadlocal Vector was somehow misaligned, causing UBSAN to be sad
about calling a misaligned method (either the dtor or .is_empty()) on
it.
For now, let's revert this and avoid the CI flake.
Fixes #12957.
2022-03-11 04:12:21 +03:30
Andreas Kling
e099960e4d LibWeb: Remove a bunch of no-longer needed #includes 2022-03-11 00:21:49 +01:00
Andreas Kling
5779a910e5 LibWeb: Move hit testing to the painting tree 2022-03-11 00:21:49 +01:00
Andreas Kling
ba606d9057 LibWeb: Move PaintingBox to its own .cpp and .h files 2022-03-11 00:21:49 +01:00
Andreas Kling
f017c1c064 LibWeb: Make hit testing return a { paintable, offset }
Everything related to hit testing is better off using the painting tree.
The thing being mousemoved over is a paintable, so let's hand that out
directly instead of the corresponding layout node.
2022-03-11 00:21:49 +01:00
Andreas Kling
cb0c5390ff LibWeb: Move mouse event and label logic from layout to painting tree
Input events have nothing to do with layout, so let's not send them to
layout nodes.

The job of Paintable starts to become clear. It represents a paintable
item that can be rendered into the viewport, which means it can also
be targeted by the mouse cursor.
2022-03-11 00:21:49 +01:00
Andreas Kling
ed84fbce47 LibWeb: Make Paintable ref-counted
This will allow us to use a protective NonnullRefPtr to keep paintables
alive while running arbitrary JavaScript in response to events.
2022-03-11 00:21:49 +01:00
Andreas Kling
702cee3d7c LibWeb: Make Layout::SVGBox inherit from Layout::Box
This doesn't need anything from Layout::BlockContainer, so let's not
inherit from that.
2022-03-11 00:21:49 +01:00
Andreas Kling
4d98851aea LibWeb: Generate a TextPaintable for every Layout::TextNode
This is prep work for moving event handling over to the painting tree.
2022-03-11 00:21:49 +01:00
Andreas Kling
aae356baf1 LibWeb: Port inline elements to the new Paintable system
This patch adds InlinePaintable which corresponds to Layout::InlineNode.
2022-03-11 00:21:49 +01:00
Andreas Kling
053766d79c LibWeb: Split Paintable into Paintable and PaintableBox
To prepare for paintable inline content, we take the basic painting
functionality and hoist it into a base class.
2022-03-11 00:21:49 +01:00
Andreas Kling
0500dbc3f6 LibWeb: Add Paintable::layout_box() accessor
Let's move away from accessing the m_layout_box member directly.
2022-03-11 00:21:49 +01:00
Andreas Kling
9461e44afa LibWeb: Use Layout::Box::paint_box() accessor in more places 2022-03-11 00:21:49 +01:00
Andreas Kling
02b316fd5c LibWeb: Let Paintable perform the painting
This patch adds a bunch of Paintable subclasses, each corresponding to
the Layout::Node subclasses that had a paint() override. All painting
logic is moved from layout nodes into their corresponding paintables.

Paintables are now created by asking a Layout::Box to produce one:

    static NonnullOwnPtr<Paintable> Layout::Box::create_paintable()

Note that inline nodes still have their painting logic. Since they
are not boxes, and all paintables have a corresponding box, we'll need
to come up with some other solution for them.
2022-03-11 00:21:49 +01:00
Andreas Kling
f6497b64ac LibWeb: Rename Painting::Box => Paintable
Calling this "Box" made it very confusing to look at code that used both
Layout::Box and Painting::Box. Let's try calling it Paintable instead.
2022-03-11 00:21:49 +01:00
Andreas Kling
7af03df4c3 LibWeb: Make Painting::Box virtual and add Painting::BoxWithLines
BlockContainer paint boxes are the only ones that have line boxes
associated, so let's not waste memory on line boxes in all the other
types of boxes.

This also adds Layout::Box::paint_box() and the more tightly typed
Layout::BlockContainer::paint_box() to get at the paint box from the
corresponding layout box.
2022-03-11 00:21:49 +01:00
Andreas Kling
9f5cbcaad3 LibWeb: Hang StackingContext off of the paint boxes
Stacking contexts have nothing to do with layout and everything with
painting, so let's keep them in Painting::Box.
2022-03-11 00:21:49 +01:00
Andreas Kling
cc8e429126 LibWeb: Make StackingContext paint functions const 2022-03-11 00:21:49 +01:00
Andreas Kling
f0d833a3d7 LibWeb: Move StackingContext and PaintPhase into the Painting namespace 2022-03-11 00:21:49 +01:00
Andreas Kling
a4d51b3dc2 LibWeb: Add Painting::Box and move things from Layout::Box into it
The "paintable" state in Layout::Box was actually not safe to access
until after layout had been performed.

As a first step towards making this harder to mess up accidentally,
this patch moves painting information from Layout::Box to a new class:
Painting::Box. Every layout can have a corresponding paint box, and
it holds the final used metrics determined by layout.

The paint box is created and populated by FormattingState::commit().

I've also added DOM::Node::paint_box() as a convenient way to access
the paint box (if available) of a given DOM node.

Going forward, I believe this will allow us to better separate data
that belongs to layout vs painting, and also open up opportunities
for naturally invalidating caches in the paint box (since it's
reconstituted by every layout.)
2022-03-11 00:21:49 +01:00
Linus Groh
251f5e8885 LibJS: Use CreateTemporalCalendar in GetBuiltinCalendar
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/f6b3a10
2022-03-10 23:20:39 +01:00
Linus Groh
7f5b4842f2 LibJS: Replace dead code in ParseTimeZoneOffsetString with an assertion
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/a29c40b
2022-03-10 23:20:39 +01:00
Linus Groh
55f9733316 LibJS: Add missing check in ParseTemporalInstant
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/baead4d
2022-03-10 23:20:39 +01:00
Linus Groh
f75052ff7c LibJS: Assert CreateTemporalDuration does not throw given correct input
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/881dd22
2022-03-10 23:20:39 +01:00
Linus Groh
d2c2a9bcbf LibJS: Assert CreateTemporalDuration does not throw in Record cases
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/43e954c
2022-03-10 23:20:39 +01:00
Linus Groh
4553512321 LibJS: Assert CreateTemporalDuration does not throw in trivial cases
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/685e20e
2022-03-10 23:20:39 +01:00
Linus Groh
54af3a5396 LibJS: Adjust grammar for DateExtendedYear to exclude -000000
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/fb3e656

We lose the custom error message, but it's not the end of the world.
2022-03-10 23:20:39 +01:00
Linus Groh
68af8649fb LibJS: Follow rules for consuming completion records
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/1c19b96
2022-03-10 23:20:39 +01:00
Linus Groh
2bae040bc9 LibJS: Remove Sign abstract operation
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/bbc1ebc
2022-03-10 23:20:39 +01:00
Linus Groh
0d06f3655f LibJS: Move string-parsing code into ToTemporalDurationRecord
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/a68b97b
2022-03-10 23:20:39 +01:00
Linus Groh
87fb005a8d LibJS: Move IsValidDuration check into ToTemporalDurationRecord
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/00958d0
2022-03-10 23:20:39 +01:00
Linus Groh
34371b9b61 LibJS: Fix numeric type confusion in ToTemporalRoundingIncrement
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/6e59366
2022-03-10 23:20:39 +01:00
Linus Groh
4ceff91893 LibJS: Use different variable name in DifferenceISODateTime
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/c32cc4d
2022-03-10 23:20:39 +01:00
Linus Groh
a009e834dc LibJS: Add clarifying assertion to BalanceDurationRelative
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/9a3477a
2022-03-10 23:20:39 +01:00
Linus Groh
17da627b4c LibJS: Fix "set it to" language to be more explicit
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/de58241
2022-03-10 23:20:39 +01:00
Linus Groh
4722045e28 LibJS: Do not expose mathematical values to script in Duration methods
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/26a4c4f

No behavioral change as we already did this correctly, but I changed
some implicit JS::Value creations to explicit ones.
2022-03-10 23:20:39 +01:00
Linus Groh
a496868ee5 LibJS: Create Duration Records with their own abstract operations
This is an editorial change in the Temporal spec.

See:
- https://github.com/tc39/proposal-temporal/commit/387c405
- https://github.com/tc39/proposal-temporal/commit/b203e26
- https://github.com/tc39/proposal-temporal/commit/387c405
2022-03-10 23:20:39 +01:00
Linus Groh
64e43c89bc LibJS: Remove assertions that are now part of structured headers
This is an editorial change in the Temporal spec.

See:
- https://github.com/tc39/proposal-temporal/commit/7fbdd28
- https://github.com/tc39/proposal-temporal/commit/f666243
- https://github.com/tc39/proposal-temporal/commit/8c7d066
- https://github.com/tc39/proposal-temporal/commit/307d108
- https://github.com/tc39/proposal-temporal/commit/d9ca402

In practical terms this means we can now get rid of a couple of awkward
assertion steps that were no-ops anyway, since the types are enforced
by the compiler.
2022-03-10 23:20:39 +01:00
Linus Groh
97bd4cebab LibJS: Refactor return value of RoundDuration
This is an editorial change in the Temporal spec.

See:
- https://github.com/tc39/proposal-temporal/commit/3641adf
- https://github.com/tc39/proposal-temporal/commit/8ea590c
2022-03-10 23:20:39 +01:00
Linus Groh
bdb13a74b0 LibJS: Describe various kinds of "Duration Records"
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/983902e

We already had these defined as structs, but now they're properly
defined in the spec (opposed to the previous anonymous records), and we
don't have to make up our own names anymore :^)

Note that while we're usually not including 'record' in the name, in
this case the 'Duration Record' has a name clash with the Duration
object. Additionally, later editorial changes introduce CreateFooRecord
AOs, so let's just go with FooRecord structs here.
2022-03-10 23:20:39 +01:00
Jelle Raaijmakers
2ac415f728 LibGL: Keep track of active matrix and stack
This simplifies a lot of code in `GLContext` and prevents potential
errors when testing against the current matrix mode.
2022-03-10 20:20:05 +01:00
Jelle Raaijmakers
5d0a64bfde LibGL: Only normalize in glRotate* if possible
Vectors of length 0 cannot be normalized, so prevent dividing by zero
in the `glRotate*` API. This fixes the skybox rendering of Quake2.
2022-03-10 20:20:05 +01:00
Sam Atkins
cc874f2b82 LibTest: Port JavaScriptTestRunner to Core::Stream 2022-03-10 12:04:22 -05:00
Sam Atkins
10429e1043 WebContent: Return empty JSON object if element has no box model
The blank string "" does not parse as JSON, and so the InspectorWidget
would fail to update the box-model information when inspecting elements
with no box, (for example, `<head>`) showing stale values instead. Now,
they show all 0s.

You could argue that InspectorWidget should be more resilient when given
invalid JSON strings, but making sure we only pass valid ones works
too.
2022-03-10 17:30:09 +01:00
Sam Atkins
b5ea14b884 WebContent: Show box-model metrics for (some) pseudo-elements
This only applies to pseudo-elements which have a Layout::Box, so this
excludes any that are InlineNodes.
2022-03-10 17:30:09 +01:00
Sam Atkins
0326ad34df Browser+LibWeb+WebContent: Show style for pseudo-elements :^)
This expands the InspectorWidget::Selection to include an optional
PseudoElement, which is then passed over IPC to request style
information for it.

As noted, this has some pretty big limitations because pseudo-elements
don't have DOM nodes:
- Declared style has to be recalculated when it's requested.
- We don't display the computed style.
- We don't display custom properties.
2022-03-10 17:30:09 +01:00
Sam Atkins
2c970b9516 Browser: Replace inspector's dom_node_id with a Selection struct 2022-03-10 17:30:09 +01:00
Sam Atkins
6de2b62906 LibWeb: Display pseudo-elements in the DOM inspector
This patch only makes them appear in the tree - they are not yet
inspectable themselves.
2022-03-10 17:30:09 +01:00
Sam Atkins
1c18bb13a2 LibWeb: Move pseudo-element-from-string code into Selector 2022-03-10 17:30:09 +01:00
Sam Atkins
adc08d0646 LibWeb: Move pseudo-class/element names into the header
These are constexpr, meaning that while the implementations were in the
cpp file, nobody outside that file could actually call them.
2022-03-10 17:30:09 +01:00
Paul Wratt
83eb5ac8fd LibWeb: Add window.sessionStorage 2022-03-10 10:02:51 +01:00
Luke Wilde
1535fe0324 LibWebSocket: Add to the total read in bytes instead of subtracting
read_length in WebSocket::read_frame is used to track how many bytes we
have read in from the network. However, we was subtracting the number
of read in bytes instead of adding, underflowing it to about the 64-bit
unsigned integer limit.

This effectively limited us to only doing one read from the network.
This was only an issue if the server stalled when sending data,
which is especially common for large payloads. This would also cause us
to go out of sync. This meant when a new frame came in, we would read
the payload data of the previous frame as if it was the frame header
and payload of the next frame.

This allows us to read in the initial payload from Discord Gateway
that describes to the client the servers we are in, the emotes the
server has, the channels it has, etc. For an account that's only in
the Serenity Discord, this was about 20 KB (compressed!)
2022-03-10 01:15:00 +01:00
Ben Abraham
7594350376 Browser: Show currently loading host and remaining resource count 2022-03-10 00:51:05 +01:00
Linus Groh
fb6c8781a2 LibJS: Update RoundDuration after DRY refactor in spec
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/4ef2748

Apparently I missed this in December! :^)
2022-03-10 00:42:49 +01:00
Sam Atkins
56a36da44e LibWeb: Only try parsing valid types of media-feature values
This resolves the ambiguity between whether a single number is a number
or a ratio. :^)

Also removed the "no more tokens" checks from
deea129b8c - that logic was completely
wrong, since there are always tokens after a value in the `(123 < foo <
456)` syntax.
2022-03-09 23:06:30 +01:00
Sam Atkins
fd47460141 LibWeb: Use ValueID for media-query identifiers 2022-03-09 23:06:30 +01:00
Sam Atkins
0371d33132 LibWeb+Meta: Stop discrete media-features from parsing as ranges
Only "range" type media-features are allowed to appear in range syntax,
or have a `min-/max-` prefix.
2022-03-09 23:06:30 +01:00
Sam Atkins
12561327d6 LibWeb: Use MediaFeatureIDs instead of Strings :^) 2022-03-09 23:06:30 +01:00
Sam Atkins
b7bb86462b Meta: Generate CSS::MediaFeatureID enum
This works largely the same as the PropertyID and ValueID generators,
but using LibMain, Core::Stream, and TRY().

Rather than have a MediaFeatureID::Invalid, I decided to return an
Optional. We'll see if that turns out better or not. :^)
2022-03-09 23:06:30 +01:00
Sam Atkins
f5fe75f12c LibWeb: Add MediaFeatures.json file, and associated identifiers
This data will be used to generate code for parsing media-queries. So
far, it includes all MEDIAQUERIES-4 features, and
`prefers-color-scheme` from MEDIAQUERIES-5 since we support that.
2022-03-09 23:06:30 +01:00
Stephan Unverwerth
096e44285a LibGL: Merge GLContext and SoftwareGLContext
This merges GLContext and SoftwareGLContext into a single GLContext
class. Since the hardware abstraction is handled via the GPU device
interface we do not need the virtual base of GLContext anymore. All
context handling functionality from the old GLContext has been moved
into the new version. All methods in GLContext are now non virtual and
the class is marked as final.
2022-03-09 22:51:01 +01:00
Linus Groh
2434d34644 LibJS/Tests: Add tests for '−000000' (U+2212) DateExtendedYear
I noticed we only have coverage for this with the ASCII minus sign in
our own test suite.
2022-03-09 22:08:15 +01:00
Andreas Kling
a13079f757 LibWeb: Invalidate style after CSSStyleSheet.{insert,remove}Rule()
When rules are inserted or removed via the CSSOM API, we now invalidate
document style to ensure that any changes made are reflected.

1% progression on ACID3. :^)
2022-03-09 19:58:14 +01:00
Andreas Kling
0e758b4da8 LibWeb: Add the StyleSheet.href attribute
This is only ever null at the moment, as we only set it on <style>
elements to begin with.
2022-03-09 19:56:08 +01:00
Andreas Kling
45f717cfad LibWeb: Respect inline-axis margins between line box fragments :^)
This makes the buckets on ACID3 space out nicely.
2022-03-09 18:47:32 +01:00
davidot
bfedec6a98 LibJS: Keep PrivateEnvironment through NativeFunction calls
Previously the variable and lexical environments were already kept in a
NativeFunction call. However when we (try to) call a private method from
within an async function we go through async_block_start which sets up
a NativeFunction to call.
This is technically not exactly as the spec describes it, as that
requires you to actually "continue" the context. Since we don't have
that concept (yet) we use this as an implementation detail to access the
private environment from within a native function.

Note that this not allow general private environment access since most
things get blocked by the parser already.
2022-03-09 18:35:27 +01:00
Andreas Kling
1e53cc3f5b LibWeb: Establish parent/child relationship between BrowsingContexts
When an iframe is inserted or removed from a document, we now take it in
and out of the BrowsingContext tree.
2022-03-09 18:14:24 +01:00
Andreas Kling
6499cf4d28 LibWeb: Always relayout document on element style change
Let's get this right before trying to make it fast. This patch removes
the code that tried to do less work when an element's style changes,
and instead simply invalidates the entire document.

Note that invalidations are still coalesced, and will not be
synchronized until update_style() and/or update_layout() is used.
2022-03-09 18:14:24 +01:00
Andreas Kling
bca3c2a443 LibWeb: Always call update_style() in update_layout()
If the style is dirty, update_style() may cause layout to become dirty.
Therefore we must always update style when updating layout, to ensure
up-to-date results.
2022-03-09 18:14:24 +01:00
Andreas Kling
c988cbb8b1 LibWeb: Invalidate document style when a node is removed
This forces us to recompute style everywhere, since all kinds of
selectors may produce different results now.

In the future, we should look at narrowing down the invalidation that
occurs here, but for now let's just invalidate everything and make the
results correct before worrying about performance.
2022-03-09 18:14:24 +01:00
Andreas Kling
04311ca7f1 LibWeb: Flush pending layouts when accessing element resolved style
We were handing out stale values from window.getComputedStyle() objects
after the first layout.

Fix this by always updating layout on property access. This is not
necessary for all properties, but for now let's go with the simplest
approach to make it work correctly.
2022-03-09 18:14:24 +01:00
Andreas Kling
3259b17a6a LibWeb: Add StyleValue::equals() override for PositionStyleValue 2022-03-09 18:14:24 +01:00
Federico Guerinoni
43d5257619 LibWeb: Use reverse iterator for reverse loop into NonnullRefPtrVector 2022-03-09 17:16:28 +01:00
Tobias Christiansen
51be2283f5 PixelPaint: Support saving/loading masks to project file 2022-03-09 17:15:17 +01:00
Tobias Christiansen
0dd5f5672c PixelPaint: Rename typo'ed BMPWriter in serialize_as_json() 2022-03-09 17:15:17 +01:00
Tobias Christiansen
937785f6c1 PixelPaint: Fix saving project
Some json objects didn't get finished, so it crashed.
2022-03-09 17:15:17 +01:00
Andreas Kling
9c6999ecf2 LibWeb: Implement "NodeIterator pre-removing steps"
These steps run when a node is about to be removed from its parent,
and adjust the position of any live NodeIterators so that they don't
point at a now-removed node.

Note that while this commit implements what's in the DOM specification,
the specification doesn't fully match what other browsers do.

Spec bug: https://github.com/whatwg/dom/issues/907
2022-03-09 16:43:56 +01:00
Andreas Kling
acbdb95b0a LibWeb: Add support for DOM's TreeWalker
This patch adds TreeWalker (created via Document.createTreeWalker())
which allows you to traverse a filtered view of the DOM in all
directions.
2022-03-09 16:43:55 +01:00