Commit graph

41097 commits

Author SHA1 Message Date
Andreas Kling d1dac8695c LibWeb: Don't set initial font+color on both HTML and BODY elements
It's enough to set it on the HTML element. That way, it doesn't get
reset in content that sets its own font on HTML but not on BODY.
2022-09-15 16:16:56 +02:00
Andreas Kling 1dd4e2dc87 LibWeb: Cache lowercased names in SimpleSelector
When matching selectors in HTML documents, we know that all the elements
have lowercase local names already (the parser makes sure of this.)

Style sheets still need to remember the original name strings, in case
we want to match against non-HTML content like XML/SVG. To make the
common HTML case faster, we now cache a lowercase version of the name
with each type/class/id SimpleSelector.

This makes tag type checks O(1) instead of O(n).
2022-09-15 16:16:56 +02:00
Andreas Kling d9c64ee876 LibWeb: Hoist case sensitivity check out of loop in Element::has_class() 2022-09-15 16:16:56 +02:00
Ben Wiederhake 8deced39a8 LibWeb: Resolve cyclic declaration/definitions involving Length
This remained undetected for a long time as HeaderCheck is disabled by
default. This commit makes the following file compile again:

    // file: compile_me.cpp
    #include <LibWeb/CSS/GridTrackSize.h>
    // That's it, this was enough to cause a compilation error.
2022-09-15 14:45:38 +01:00
Lucas CHOLLET 53eb35caba Calculator: Change internal representation to support perfect division
The purpose of this patch is to support addition, subtraction,
multiplication and division without using conversion to double. To this
end, we use the BigFraction class of LibCrypto. With this solution, we
can store values without any losses and forward rounding as the last
step before displaying.
2022-09-15 14:08:21 +01:00
Lucas CHOLLET 4ab8ad2ed2 LibCrypto: Fix -0 and 0 non-equality
SignedBigInteger::operator==(const UnsignedBigInteger&) was rejecting
all negative value before testing for equality. It now accepts negative
zero and test for a value equality with the UnsignedBigInteger.
2022-09-15 14:08:21 +01:00
Lucas CHOLLET 6a937312b3 LibCrypto: Add BigFraction
This new abstraction allows the user to store rational numbers with
infinite precision.
2022-09-15 14:08:21 +01:00
Lucas CHOLLET 62b8ccaffc StringBuilder: Add try_append_repeated() and append_repeated()
This two methods add the character as many times as specified by the
second parameter.
2022-09-15 14:08:21 +01:00
Lucas CHOLLET d589898f5b LibCrypto: Add SignedBigInteger::negated_value()
Return the negated value of the current number.
2022-09-15 14:08:21 +01:00
Ben Wiederhake 42db468ef5 Meta: Revise lint-commit.sh regex for the title
This mainly changes two aspects:
- The category can now be a single letter, such as 'w' to indicate the
  file Utilities/w.cpp
- Spaces in the category (or list) are no longer allowed. This follows
  the lived practice of writing category lists as "Foo+Bar: Quux"

Closes #15243.
2022-09-15 13:55:32 +01:00
Andreas Kling a60c5166c6 LibWeb: Don't ignore data: URLs in @font-face src
Since data: URLs don't have a path, we shouldn't be checking for a TTF
or WOFF extension.

Thanks Timon for pointing this out! :^)
2022-09-15 12:45:00 +02:00
Andreas Kling 4910cc1879 LibGfx: Cache vector fonts by family name
Instead of just keeping them in an unsorted Vector, which led to
increasingly noticeable O(n) lookups, we now cache a list of Typefaces
per family name.
2022-09-15 12:45:00 +02:00
sin-ack a192095594 LibCore: Rewrite Core::Stream::read_all_impl
The previous version relied on manually setting the amount of data to
read for the next chunk and was overall unclear. The new version uses
the Bytes API to vastly improve readability, and fixes a bug where
reading from files where a single read that wasn't of equal size to the
block size would cause the byte buffer to be incorrectly resized causing
corrupted output.
2022-09-15 12:01:16 +02:00
sin-ack d3979b0bbd LibCore: Add documentation to Stream functions + make parameter clearer
file_size was not very clear about what it was being used for, so I
switched it to say expected_file_size to make it clear that it's just a
heuristic.
2022-09-15 12:01:16 +02:00
Luke Wilde 6a4934a030 LibWeb: Implement document.domain getter
The document.domain setter is currently stubbed as that is a doozy to
implement, given how much restrictions there are in place to try and
prevent use of it and potential multi-process implications.

This was the only thing preventing us from being able to start
displaying ads delivered via Google Syndication.
2022-09-15 09:46:04 +02:00
Timothy Flynn 6290a25224 Meta: Enable vptr sanitation by default for Lagom UBSAN builds 2022-09-15 09:45:13 +02:00
Timothy Flynn 85e313077a LibJS: Do not invoke Cell::vm in constructors before Cell is constructed
In a subclass of Cell, we cannot use Cell::vm() before the base Cell
object itself is constructed. Use the Realm's VM instead.

This was caught by UBSAN with vptr sanitation enabled.
2022-09-15 09:45:13 +02:00
Timothy Flynn 3efe611dbf LibJS: Do not assume that IsArray means the object type is an Array
IsArray returns true if the object is an Array *or* if it is a
ProxyObject whose target is an Array. Therefore, we cannot downcast to
an Array based on IsArray.

Luckily, we don't actually need an Array here; SerializeJSONArray only
needs an Object.

This was caught by UBSAN with vptr sanitation enabled.
2022-09-15 09:45:13 +02:00
Timothy Flynn 98a6f962a0 LibJS: Use correct include + object class for Function{Object,Prototype}
Not causing any real issue, just noticed while debugging vptr sanitation
errors.
2022-09-15 09:45:13 +02:00
Andreas Kling 1c0fc75cb6 LibWeb: Fix bogus condition when checking CSS font file extensions
Thanks Idan for pointing this out! :^)
2022-09-15 01:20:35 +02:00
Andreas Kling 6d92c1d231 LibWeb: Be slightly better at @font-face rules with multiple sources
This patch improves @font-face loading when there are multiple src
values in two ways:

- Invalid/empty URLs are ignored
- Fonts with unsupported file extensions are ignored

This makes us load and display the emblem font on modern Reddit,
which is pretty neat! :^)
2022-09-14 21:46:34 +02:00
Andreas Kling c5a19a4d55 LibWeb: Allow CSS at-rules to have an empty prelude
I don't see any indication in the spec that an empty prelude should be
disallowed. This fixes rules like `@font-face{...}` (note the absence
of whitespace before the `{`.)
2022-09-14 21:37:19 +02:00
Andreas Kling f64c175960 LibWeb: Invalidate layout whenever a CSS font is loaded
It's not enough to invalidate only the style, we have to do a full
layout invalidation since new fonts might mean new metrics, etc.
2022-09-14 21:24:31 +02:00
Andreas Kling df49a6ae9b LibWeb: Schedule a layout update in Document::invalidate_layout()
Otherwise, nothing will repaint until someone else decides to trigger
an update.
2022-09-14 21:23:39 +02:00
Andreas Kling 463355d1eb LibWeb: Allow data: URLs with font/ MIME type in @font-face CSS rules 2022-09-14 21:14:16 +02:00
Andreas Kling 34025442ff LibWeb: Account for float's container offsets in BFC root auto height
When calculating the automatic height of a BFC root, we stretch it to
contain the bottommost margin edge of floating boxes.

Before this change, we assumed that floating boxes had coordinates
relative to the BFC root, when they're actually relative to the floating
box's containing block. This may or may not be the BFC root, so we have
to use margin_box_in_ancestor_coordinate_space() to apply offsets from
all boxes in the containing block chain (up to the BFC root).
2022-09-14 20:18:49 +02:00
Jelle Raaijmakers 8ff7c52cf4 LibSoftGPU: Return a const& texel in Image to prevent copying
On every texel access, some floating point instructions involved in
copying 4 floats popped up. Let `Image::texel() const` return a
`FloatVector4 const&` to prevent these operations.

This results in a ~7% FPS increase in GLQuake on my machine.
2022-09-14 17:17:36 +02:00
Jelle Raaijmakers e9d2f9a95e LibSoftGPU: Use memcpy instead of a loop to blit the color buffer
Looking at `Tubes` before and after this change, comparing the original
loop to the one using `memcpy`, including the time for `memcpy` itself,
resulted in ~15% fewer samples in profiles on my machine.
2022-09-14 17:17:19 +02:00
Jelle Raaijmakers bfb4e08612 LibGfx: Use memcpy instead of fast_u32_copy for blitting
In some artificial full screen blitting profiling, I've seen `memcpy`
take up about 4% fewer samples each time I measure. It seems like
`fast_u32_copy` is not as fast as it'd like to believe.
2022-09-14 17:17:19 +02:00
Andreas Kling 57ad99ef16 LibWeb: Don't show pointer (hand) cursor over non-linked a elements
This is already handled by the :link and :visited style.
2022-09-14 15:05:10 +02:00
Andreas Kling 35a9a2fbb2 LibWeb: Account for containing block padding when placing abspos boxes
Unlike the other positioning schemes, absolute positioning is relative
to the *padding* edge of the containing block.
2022-09-14 14:43:17 +02:00
Andreas Kling d27136fcb0 LibWeb: Replace most of our default UA stylesheet with spec rules
The HTML spec provides a set of suitable default CSS rules for our UA
stylesheet, so let's use those instead of inventing our own. :^)

Note that I had to replace "foo-block-start" properties with "foo-top"
since we don't support the block/inline direction based properties yet.
2022-09-14 14:43:17 +02:00
Andreas Kling 4b9c5635b3 LibWeb: Make :link selector behave according to spec
It should match any `a` or `area` element that has an `href` attribute,
not any element *inside* an enclosing linked element.
2022-09-14 14:43:17 +02:00
Andreas Kling f25203f245 LibWeb: Don't re-resolve "auto" flex item sizes after definitizing them
This is rather subtle and points to our architecture around definite
sizes not being exactly right, but...

At some points during flexbox layout, the spec tells us that the sizes
of certain flex items are considered definite from this point on.
We implement this by marking each item's associated UsedValues as
"has-definite-width/height".

However, this breaks code that tries to resolve computed "auto" sizes
by taking the corresponding size from the containing block. The end
result was that the 1st sizing pass in flexbox would find the right size
for an "auto" sized item, but the 2nd pass would override the correct
size with the containing block's content size in that axis instead.

To work around the issue, FFC now remembers when it "definitizes" an
item, and future attempts to resolve an "auto" computed size for that
value will bypass the computed-auto-is-resolved-against-containing-block
step of the algorithm. It's not perfect, and we'll need to think more
about how to really represent these intermediate states relating to
box sizes being definite..
2022-09-14 14:43:17 +02:00
Andreas Kling b8aa6a4453 LibWeb: Use PercentageOr<T>::contains_percentage() in CSS layout
By asking if the value *contains* a percentage rather than whether it
*is* one, we cover many more cases where e.g `width: calc(100% - 10px)`
should be "treated as auto" etc.
2022-09-14 14:43:17 +02:00
Andreas Kling c4050fe675 LibWeb: Treat unimplemented grid-track-size syntax as "auto" for now
Note that there's a FIXME just above the previous case. That applies to
this workaround as well.
2022-09-14 14:43:17 +02:00
Andreas Kling 55ad9591df LibWeb: Add a way to ask if a PercentageOr<T> value contains percentages
Values that contain percentages require special treatment in various
parts of layout. Previously we had no way of peeking into calc() values
to see if their expression contains one or more percentages. That's the
bulk of what we're adding here.
2022-09-14 14:43:17 +02:00
Timothy Flynn 3dd11a007f CI: Fix typo preventing the CLDR cache from being pulled 2022-09-14 08:21:03 -04:00
electrikmilk 154fb144f5 Base: Tweak Source font
This does many tweaks to the Source font. The tweaks mainly apply to
the bold weight, but tweaks small things about the Regular weight.

This mainly corrects inconsistencies or the placement of pixels in
a glyph.

I tried to pay a lot of attention to how different code looks in this
font and adapt it to that since that is its main purpose.
2022-09-14 06:56:27 -04:00
electrikmilk fdd202259d LibWeb: Add partial serialization for CSSFontFaceRule
This partially adds serialization code for
`CSSFontFaceRule::serialized()` to spec. This is only partially
implemented as some parts of the `@font-face` rule are not implemented
yet.
2022-09-14 10:50:33 +01:00
electrikmilk b0f9ad0000 Base: Add existing @font-face test to welcome page
This adds the existing `@font-face` test page to the welcome page.
2022-09-14 10:50:33 +01:00
Brian Gianforcaro d0a1775369 Everywhere: Fix a variety of typos
Spelling fixes found by `codespell`.
2022-09-14 04:46:49 +00:00
Andreas Kling 63c727a4a3 LibWeb: Don't clip to containing block when painting abspos descendants 2022-09-14 00:09:49 +02:00
Andreas Kling f941b7aefe LibWeb: Create stacking context for flex/grid items with z-index != auto 2022-09-14 00:09:49 +02:00
Andreas Kling fb5879fdcc LibWeb: Don't include abspos children in containing block's auto width 2022-09-14 00:09:49 +02:00
martinfalisse df22f38feb LibWeb: Inform the parent context of the grid's size 2022-09-14 00:09:14 +02:00
martinfalisse 214329b81c LibWeb: Layout grid items after calculation
Now that the positions of each grid item have been calculated, and the
sizes of the individual rows and columns ascertained, can actually
layout the different items.
2022-09-14 00:09:14 +02:00
martinfalisse 58078c1f40 LibWeb: Calculate sizes of Auto grid tracks 2022-09-14 00:09:14 +02:00
martinfalisse f558fd93b7 LibWeb: Calculate sizes of FlexibleLength grid tracks 2022-09-14 00:09:14 +02:00
martinfalisse fbe703e2bd LibWeb: Follow spec for calculating intrinsic track sizes 2022-09-14 00:09:14 +02:00