Commit Graph

28088 Commits

Author SHA1 Message Date
Andreas Kling
b1529e3202 LibWeb: Remove some unused includes and a member in HTMLScriptElement 2021-09-26 01:03:17 +02:00
Andreas Kling
e7af6af626 LibWeb: Implement more of HTMLParser::the_end() and bring closer to spec 2021-09-26 00:52:19 +02:00
Andreas Kling
c772134e25 LibWeb: Make update_style() a no-op if there's no browsing context
Style is needed to lay out and paint a document, but we can't do either
those when the document isn't attached to a browsing context.
2021-09-26 00:48:30 +02:00
Andreas Kling
e452550fda LibWeb: Split out "The end" from the HTML parsing spec to a function
Also add a spec link and some comments.
2021-09-26 00:04:33 +02:00
Andreas Kling
f67648f872 LibWeb: Rename HTMLDocumentParser => HTMLParser 2021-09-25 23:36:43 +02:00
Andreas Kling
0ee457dfdf LibWeb: Provide a default DOM::EventTarget::dispatch_event()
All EventTarget subclasses except Window do the same exact thing in
their overrides, so let's just share an implementation in the base.
2021-09-25 23:36:43 +02:00
Idan Horowitz
8dcf4e0346 LibWeb: Return undefined from generated EventHandler setters
Returning an empty value without throwing an exception is no longer
valid.
2021-09-25 23:35:54 +02:00
Karol Kosek
5a5f6d11ef PixelPaint: Close image tabs on middle click 2021-09-25 23:34:02 +02:00
Karol Kosek
df195188bc PixelPaint: Close New Image dialog after pressing return key
13e526de43 added the feature to new Layer
dialog. This patch adds it to Image dialog to stay consistent across
the app. :^)
2021-09-25 23:34:02 +02:00
Andreas Kling
926a49cd81 LibWeb: Use Core::EventLoop::spin_until() for the ad-hoc loop spinning
The ideal solution here is to implement a more spec-compliant event
loop, but while we get all the pieces in place for that, this at least
makes the HTML event loop a bit more responsive since it never has to
wait for a 16ms timer to fire.
2021-09-25 19:34:21 +02:00
Andreas Kling
f2b9ec9f8a LibCore: Add Core::EventLoop::spin_until(Function<bool()>)
This function spins the event loop until a goal condition is met.
2021-09-25 19:32:14 +02:00
Andreas Kling
2c0987c93b LibWeb: Move window.scroll{X,Y} from wrapper into DOM::Window
The less we do in WindowObject, the easier it will be to eventually
auto-generate the entire thing.
2021-09-25 18:47:19 +02:00
Linus Groh
38157a6093 LibJS: Move has_constructor() from NativeFunction to FunctionObject
At a later point this will indicate whether some FunctionObject "has a
[[Construct]] internal method" (separate from the current FunctionObject
call() / construct()), to help with a more spec-compliant implementation
of [[Call]] and [[Construct]].
This means that it is no longer relevant to just NativeFunction.
2021-09-25 17:51:30 +02:00
Linus Groh
e14f420a44 LibJS: Add const Value::as_function() 2021-09-25 17:51:30 +02:00
Linus Groh
2dba048146 LibJS: Remove unused FunctionObject::environment()
ECMAScriptFunctionObject::environment() can just be non-virtual.
2021-09-25 17:51:30 +02:00
Linus Groh
9043041dd3 LibJS: Move [[BoundThis]] and [[BoundArguments]] to BoundFunction 2021-09-25 17:51:30 +02:00
Linus Groh
4566472ed6 LibJS: Rename BoundFunction::m_target_function to match spec name 2021-09-25 17:51:30 +02:00
Linus Groh
a08292d76c LibJS: Move has_simple_parameter_list to ECMAScriptFunctionObject 2021-09-25 17:51:30 +02:00
Linus Groh
76eb8fe717 LibJS: Move [[Fields]] to ECMAScriptFunctionObject 2021-09-25 17:51:30 +02:00
Linus Groh
136451c3af LibJS: Move [[HomeObject]] to ECMAScriptFunctionObject 2021-09-25 17:51:30 +02:00
Linus Groh
06726d41ac LibJS: Move [[ConstructorKind]] to ECMAScriptFunctionObject 2021-09-25 17:51:30 +02:00
Linus Groh
1e97a85095 LibJS: Move [[ThisMode]] to ECMAScriptFunctionObject 2021-09-25 17:51:30 +02:00
Linus Groh
ce946dd656 LibJS: Add ECMAScriptFunctionObject forward declaration 2021-09-25 17:51:30 +02:00
Linus Groh
d5f90cf187 LibJS: Rename ECMAScriptFunctionObject members to match spec names
Also add the internal slot names as comments, and separate them into
groups of spec and non-spec members.
This will make it easier to compare the implementation code with the
spec, as well as identify internal slots currently missing or only
present on FunctionObject.
2021-09-25 17:51:30 +02:00
Linus Groh
e37cf73300 LibJS: Rename OrdinaryFunctionObject to ECMAScriptFunctionObject
The old name is the result of the perhaps somewhat confusingly named
abstract operation OrdinaryFunctionCreate(), which creates an "ordinary
object" (https://tc39.es/ecma262/#ordinary-object) in contrast to an
"exotic object" (https://tc39.es/ecma262/#exotic-object).

However, the term "Ordinary Function" is not used anywhere in the spec,
instead the created object is referred to as an "ECMAScript Function
Object" (https://tc39.es/ecma262/#sec-ecmascript-function-objects), so
let's call it that.

The "ordinary" vs. "exotic" distinction is important because there are
also "Built-in Function Objects", which can be either implemented as
ordinary ECMAScript function objects, or as exotic objects (our
NativeFunction).

More work needs to be done to move a lot of infrastructure to
ECMAScriptFunctionObject in order to make FunctionObject nothing more
than an interface for objects that implement [[Call]] and optionally
[[Construct]].
2021-09-25 17:51:30 +02:00
Mandar Kulkarni
d787775806 LibWeb: Skip decoding favicon.ico if downloaded data is empty
Some sites don't have favicon.ico, so we may get 404 response.
In such cases, ResourceLoader still calls success_callback.
For favicon loading, we are not checking response headers or payload
size.
This will ultimately fail in Gfx::ImageDecoder::try_create().

So avoid unnecessary work by returning early, if data is empty.
2021-09-24 19:29:04 +02:00
Andreas Kling
73fe6c541a LibGfx: Forward declare Gfx::FontMetrics as a struct 2021-09-24 19:03:46 +02:00
Andreas Kling
71f371f6b1 LibWeb: Ignore font-size: calc(...) for now
This doesn't work correctly in the new world where fonts are resolved
during the CSS cascade. Let's patch it out with a FIXME and get back to
it once everything has fallen into place.
2021-09-24 15:49:04 +02:00
Andreas Kling
f8dd3e14ba LibWeb: Rename CSS::StyleResolver => StyleComputer
Resolved style is a spec concept that refers to the weird mix of
computed style and used style reflected by getComputedStyle().

The purpose of this class is to produce the *computed* style for a given
element, so let's call it StyleComputer.
2021-09-24 15:12:15 +02:00
Andreas Kling
3dc6f0bc47 LibWeb: Absolutize internal lengths in all StyleValues
StyleValue now has a virtual visit_lengths() that allows us to update
all CSS lengths during the absolutization phase.
2021-09-24 15:12:15 +02:00
Andreas Kling
785ace4fc2 LibWeb: Remove on-demand font resolution
Fonts are now resolved as part of the CSS cascade.
2021-09-24 15:12:15 +02:00
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