Commit Graph

9412 Commits

Author SHA1 Message Date
Andreas Kling
1ca33598da LibWeb: Give DOM::Document some default style properties
Add StyleResolver::create_document_style() to help in creating an
"empty" style with nothing but default values.
2021-09-24 15:01:49 +02:00
Andreas Kling
c5b4928f4a LibWeb: Make ListItemMarkerBox inherit style from ListItemBox 2021-09-24 15:01:49 +02:00
Andreas Kling
ca28a118ae LibWeb: Add tightly-typed DOM node accessors for Layout::ListItemBox
ListItemBox is always constructed with a non-null DOM::Element, so we
can make dom_node() return a DOM::Element&.
2021-09-24 15:01:49 +02:00
Andreas Kling
5a7d3e3cc1 LibWeb: Let <br> elements have style
At the very least, we need to respect `<br style="display: none">`
2021-09-24 15:01:49 +02:00
Andreas Kling
c113c092ee LibWeb: Make HTML::EventLoop::process() a no-op if there are no tasks 2021-09-24 15:01:49 +02:00
Andreas Kling
23a08fd35a LibWeb: Start absolutizing lengths after performing the CSS cascade
Once we've performed the cascade on a set of values for an element,
we should have enough information to resolve/absolutize some lengths.

Basically, any CSS length that isn't "auto" or a percentage can be
turned into an absolute length (in pixels) as long as we have the
following information:

- The viewport rect
- The parent element's font
- The document element's font
- The element's own font

To ensure that we can absolutize lengths relative to the element's own
font, we now do a separate first pass where font-related properties are
defaulted (in the cascade spec sense of the word) and become usable.

There's a lot more work to do here, but this should open up a lot of
simplification in layout code, since it will no longer need to care
about relative lengths. Layout still needs to resolve percentages, since
we can't do that for some properties until the containing block
dimensions are known.
2021-09-24 15:01:49 +02:00
Andreas Kling
30979c1956 LibGfx: Remove debug spam about not having some font installed 2021-09-24 15:01:49 +02:00
Andreas Kling
d7586aff53 LibGfx: Add a simple Gfx::FontMetrics and Gfx::Font::metrics(code_point)
This is used to get a handy set of glyph metrics.
2021-09-24 15:01:49 +02:00
Andreas Kling
3d36e4d944 LibWeb: Rename "Computed" CSSStyleDeclaration => "Resolved"
The original name was based on the window.getComputedStyle() API.
However, "Computed" in "getComputedStyle" is actually a misnomer that
the platform is stuck with due to backwards compatibility.

What getComputedStyle() returns is actually a mix of computed and used
values. The spec calls it the "resolved" values. So let's call this
declaration subclass "ResolvedCSSStyleDeclaration" to match.
2021-09-24 15:01:49 +02:00
Sam Atkins
058d44dcae LibWeb: Replace last couple of StyleValue casts with as_foo() 2021-09-24 15:01:43 +02:00
Sam Atkins
a83b620fa6 LibWeb: Use new StyleValue API in StyleResolver
Less casts, more readable. :^)
2021-09-24 15:01:43 +02:00
Sam Atkins
b0324b7201 LibWeb: Use new StyleValue API in StyleProperties.cpp
This replaces a bunch of casts with `.as_foo()` calls, and adjusts calls
to the old `is_foo()` methods that now are better as `has_foo()`.

Also tidied up some whitespace to be more consistent.
2021-09-24 15:01:43 +02:00
Sam Atkins
48ef5c8e84 LibWeb: Use new StyleValue API in ComputedCSSStyleDeclaration
Why manually cast things when a method can do it for you safely?
2021-09-24 15:01:43 +02:00
Sam Atkins
4b554ba92a LibWeb: Clarify StyleValue API with new naming scheme
This does a few things, that are hard to separate. For a while now, it's
been confuzing what `StyleValue::is_foo()` actually means. It sometimes
was used to check the type, and sometimes to see if it could return a
certain value type. The new naming scheme is:

- `is_length()` - is it a LengthStyleValue?
- `as_length()` - casts it to LengthStyleValue
- `has_length()` - can it return a Length?
- `to_length()` - gets the internal value out (eg, Length)

This also means, no more `static_cast<LengthStyleValue const&>(*this)`
stuff when dealing with StyleValues. :^)

Hopefully this will be a bit clearer going forward. There are lots of
places using the original methods, so I'll be going through them to
hopefully catch any issues.
2021-09-24 15:01:43 +02:00
Sam Atkins
1ae0781ce1 LibWeb: Alphabetically sort StyleValues
The random order keeps confuzing me!
2021-09-24 15:01:43 +02:00
thankyouverycool
4d2f349710 LibGUI: Categorize font families by variant instead of weight
FontPickerWeightModel is no longer necessary as variants contain
weight as part of a complete typeface description. This fixes fonts
not inventorying correctly in picker when they contained more than
bold and regular typefaces. Weight mapping has been moved into
LibGfx/FontStyleMapping.h
2021-09-24 14:59:39 +02:00
thankyouverycool
84ce923850 LibGfx: Make BitmapFont::variant() report a complete typeface 2021-09-24 14:59:39 +02:00
thankyouverycool
39484fc02c LibGfx: Get weight from tables for TrueTypeFonts
First, try to find detailed weight metrics in the OS/2 table;
barring that, fall back to the font header table.
2021-09-24 14:59:39 +02:00
thankyouverycool
fde48f1a7a FontEditor: Allow editing new font header
And make use of mapping functions moved from
LibGUI/FontPickerWeightModel.h => LibGfx/FontStyleMapping.h
2021-09-24 14:59:39 +02:00
thankyouverycool
fff89ad769 LibGfx: Support italic BitmapFonts
BitmapFont header now contains a slope byte. Slope is used to
indicate slant style and is mapped in LibGfx/FontStyleMapping.h
2021-09-24 14:59:39 +02:00
Mustafa Quraish
07419b8931 diff: Only color output when stdout is a tty
If we're redirecting the output somewhere, we likely don't want to
have ANSI codes in the middle of our diff output.
2021-09-24 14:32:52 +02:00
Mustafa Quraish
6f423ed26e LibDiff: Coalesce adjacent changes into the same Hunk
Now we keep track of the "current" hunk, and only create a new one
if there's at least a single unmodified lines between changes.
2021-09-24 14:32:52 +02:00
Mustafa Quraish
35704ba272 LibDiff: Perform diffing-algorithm in reverse order
Previously the algorithm was being performed from the start of the
string to the end, which was a little more convenient when writing
the code, but made it more annoying to be able to properly talk
about the "start" of where the changes were happening, since we
can only re-construct the changes in reverse order of the initial
traversal.

Basically, doing the initial pass in reverse lets us reconstruct
the hunks in the correct order to begin with, and not have to worry
about reversing the hunks / lines within the hunks
2021-09-24 14:32:52 +02:00
Mustafa Quraish
4173f2ffad diff: Show start/end of line ranges in source/target files
This behaves very much like the regular diff command, showing the
start lines and ranges of additions/changes/deletions in both the
source and target files.
2021-09-24 14:32:52 +02:00
Linus Groh
1a7136b37a LibWeb: Return undefined from event handler setters, not an empty value 2021-09-24 13:19:13 +02:00
Linus Groh
32932f83be LibJS: Rename {Abstract,Typed => Loosely,Strictly}{Equals,Inequals}
This affects the AST's BinaryOp enum as well as the Bytecode's
ENUMERATE_BYTECODE_OPS and JS_ENUMERATE_COMMON_BINARY_OPS macros.
2021-09-24 09:13:57 +02:00
Linus Groh
facbe32fcd LibJS: Rename abstract_relation() to is_less_than()
This got turned into a proper AO with a new name recently.

See: https://github.com/tc39/ecma262/commit/587adc0
2021-09-24 09:13:57 +02:00
Linus Groh
580a7e0f7c LibJS: Rename abstract_eq() to is_loosely_equal()
This got turned into a proper AO with a new name recently.

See: https://github.com/tc39/ecma262/commit/c7d6d1c
2021-09-24 09:13:57 +02:00
Linus Groh
c7ff89891c LibJS: Rename strict_eq() to is_strictly_equal()
This got turned into a proper AO with a new name recently.

See: https://github.com/tc39/ecma262/commit/19d7ca4
2021-09-24 09:13:57 +02:00
Idan Horowitz
5f80d8245d LibJS: Close iterator on throw completion in Array.from
This regressed in #10190
2021-09-24 02:28:17 +03:00
Idan Horowitz
99bc429f3f LibJS: Add missing exception checks to {Array, TypedArray}.from() 2021-09-24 02:28:17 +03:00
Idan Horowitz
ee825d6d9e LibJS: Convert get_method to ThrowCompletionOr 2021-09-23 23:59:13 +03:00
Idan Horowitz
ab594e5f2f LibJS: Convert Value::invoke and VM::call to ThrowCompletionOr 2021-09-23 23:59:13 +03:00
Idan Horowitz
a90107b02a LibJS: Convert is_regexp to ThrowCompletionOr 2021-09-23 23:59:13 +03:00
Idan Horowitz
1db7e096e2 LibJS: Switch is_array to ThrowCompletionOr 2021-09-23 23:59:13 +03:00
Jelle Raaijmakers
380c42c405 LibC: Add getpriority() and setpriority() stubs
Expected behavior left as a FIXME is outlined here:
https://pubs.opengroup.org/onlinepubs/7908799/xsh/getpriority.html
2021-09-23 18:51:21 +02:00
Jelle Raaijmakers
a6539cc031 LibC: Add chroot() stub
Expected behavior left as a FIXME is described here:
https://pubs.opengroup.org/onlinepubs/7908799/xsh/chroot.html

It is marked as LEGACY but still used in projects such as PHP.
2021-09-23 18:51:21 +02:00
Tobias Christiansen
0ccde5417b LibWeb: Don't assume the parent is BFC in the IFC 2021-09-23 17:48:11 +02:00
Tobias Christiansen
4560a8b83f LibWeb: Flexbox: Use InlineFormattingContext when needed
Previously any children would be layout using a BlockFormattingContext.
Now we at least differentiate between IFC and BFC if the sizes in
question are not constrained by other things.
2021-09-23 17:48:11 +02:00
Tobias Christiansen
54013ffbe0 LibWeb: Proritize FlexFormattingContext when display: flex is specified
An item with display: flex and overflow: hidden would've caused a
BlockFormattingContext before.
2021-09-23 17:48:11 +02:00
Sam Atkins
e0a727bc76 LibWeb: Remove type checking from set_property_expanding_shorthands()
Now that the Parser checks that StyleValues are valid, we don't need to
do the checks here, since any value here is guaranteed to be acceptable.
2021-09-23 17:47:40 +02:00
Sam Atkins
f574f538d2 LibWeb: Use property_accepts_value() for parsing text-decoration 2021-09-23 17:47:40 +02:00
Sam Atkins
4bc9b9eaaa LibWeb: Use property_accepts_value() for overflow parsing 2021-09-23 17:47:40 +02:00
Sam Atkins
85254ada94 LibWeb: Fix auto conversion to identifier
Calling `is_identifier()` here was wrong, since it just means you can
get an Identifier from it. This meant that an `auto` LengthStyleValue
would return true, then it would get `static_cast` to the wrong class,
and return a garbage value.

Basically, I really need to tidy up the API for StyleValue, so it's
clear whether `is_foo()` means the object is a `FooStyleValue`, or it
can just return a `foo` value.
2021-09-23 17:47:40 +02:00
Sam Atkins
b08094bccc LibWeb: Use property_accepts_value() for list style parsing 2021-09-23 17:47:40 +02:00
Sam Atkins
dcf70ab821 LibWeb: Use property_accepts_value() for font parsing 2021-09-23 17:47:40 +02:00
Sam Atkins
b927972da7 LibWeb: Add range-checking to property_accepts_value()
For `number` and `integer` types, you can add a range afterwards to add
a range check, using similar syntax to that used in the CSS specs. For
example:

```json
"font-weight": {
  ...
  "valid-types": [
    "number [1,1000]"
  ],
  ...
}
```

This limits any numbers to the range `1 <= n <= 1000`.
2021-09-23 17:47:40 +02:00
Sam Atkins
e262596ee1 LibWeb: Use property_accepts_value() for parsing flexbox properties 2021-09-23 17:47:40 +02:00
Sam Atkins
37e69fb286 LibWeb: Use property_accepts_value() when parsing borders 2021-09-23 17:47:40 +02:00
Sam Atkins
5213760e4b LibWeb: Use property_accepts_value() for background parsing
We also get rid of `is_background_{image,repeat}()` since they're no
longer needed. :^)
2021-09-23 17:47:40 +02:00