Commit Graph

128 Commits

Author SHA1 Message Date
Linus Groh
f37d00c07b LibWeb: Implement TextEncoder.prototype.encode() 2021-12-12 20:58:36 +01:00
Linus Groh
35d3a1e77b LibWeb: Add the TextEncoder interface
This is from the Encoding Standard (https://encoding.spec.whatwg.org),
and therefore gets its own namespace and subdirectory within LibWeb :^)
2021-12-12 20:58:36 +01:00
Andreas Kling
e017fe92e6 LibWeb: Move ImageDecoder client connection singleton to its own file
This will allow us to use it in more places around LibWeb.
2021-11-20 10:56:31 +01:00
Andreas Kling
7c57961c61 LibWeb: Move BrowsingContext into HTML/
Browsing contexts are defined by the HTML specification, so let's move
them into the HTML directory. :^)
2021-11-18 21:11:30 +01:00
Sam Atkins
d106f20a73 LibWeb: Delete CSSLoader
All CSS loading is now done by the relevant classes:
- CSSImportRule, which loads its linked stylesheet
- HTMLStyleElement, which "loads" its contents
- HTMLLinkElement, which loads its linked stylesheet
2021-11-18 21:11:19 +01:00
Sam Atkins
c8550da9c5 LibWeb: Add Web::CSS::PreferredColorScheme enum 2021-10-31 18:39:13 +01:00
Sam Atkins
38f6140159 LibWeb: Implement first draft of CSS syntax highlighting :^)
This works at the Token level, which is quick and easy but has
drawbacks: We don't know when something is a property name or a value,
or if something is part of a selector. But, this works for now.
2021-10-23 19:07:44 +02:00
Timothy Flynn
d24ae8063b LibWeb: Implement DOMTokenList for managing space-separated tokens lists
DOMTokenList is used as the return type of, e.g., the Element.classList
property.
2021-10-18 23:33:56 +02:00
Timothy Flynn
2a3ac02ef1 LibWeb: Implement (most of) NamedNodeMap to store attributes 2021-10-17 13:51:10 +01:00
Timothy Flynn
e01dfaac9a LibWeb: Implement Attribute closer to the spec and with an IDL file
Note our Attribute class is what the spec refers to as just "Attr". The
main differences between the existing implementation and the spec are
just that the spec defines more fields.

Attributes can contain namespace URIs and prefixes. However, note that
these are not parsed in HTML documents unless the document content-type
is XML. So for now, these are initialized to null. Web pages are able to
set the namespace via JavaScript (setAttributeNS), so these fields may
be filled in when the corresponding APIs are implemented.

The main change to be aware of is that an attribute is a node. This has
implications on how attributes are stored in the Element class. Nodes
are non-copyable and non-movable because these constructors are deleted
by the EventTarget base class. This means attributes cannot be stored in
a Vector or HashMap as these containers assume copyability / movability.
So for now, the Vector holding attributes is changed to hold RefPtrs to
attributes instead. This might change when attribute storage is
implemented according to the spec (by way of NamedNodeMap).
2021-10-17 13:51:10 +01:00
Timothy Flynn
8d27292fac LibWeb: Alphabetize LibWeb's forward and JS wrapper declarations 2021-10-17 13:51:10 +01:00
Timothy Flynn
ebe704a03d LibWeb: Stub out a basic IntersectionObserver interface
Note there are a couple of type differences between the spec and the IDL
file added in this commit. For example, we will need to support a type
of Variant to handle spec types such as "(double or sequence<double>)".
But for now, this allows web pages to construct an IntersectionObserver
with any valid type.
2021-10-14 10:32:51 +02:00
Linus Groh
f952db1a1f LibWeb: Implement PromiseRejectionEvent
This paves the way for the rejectionhandled and unhandledrejection
events.

It's also used by core-js (in browsers, at least) to check whether
Promise needs to be polyfilled, so adding it should allow more websites
to leverage LibJS's native Promise implementation :^)
2021-10-11 13:30:17 +01:00
Andreas Kling
fdc1c15064 LibWeb: Stub out a basic ResizeObserver interface
This patch establishes scaffolding for the ResizeObserver API.
2021-10-11 00:54:01 +02:00
Andreas Kling
5c9ca5c2dc LibWeb: Stub out a basic Selection interface
This patch establishes scaffolding for the Selection API.
2021-10-11 00:32:19 +02:00
Sam Atkins
57a25139a5 LibWeb: Implement @supports rule :^)
The main thing missing is that we don't serialize the supports clause,
but for actually using a `@supports (something: cool) {}` rule in CSS,
it works!
2021-10-08 23:02:57 +02:00
Sam Atkins
87a30418bf LibWeb: Add CSS 'Supports' class
The name is a little awkward, but this corresponds to the condition of a
`@supports` rule or the `CSS.supports("")` function.

A supports query only gets evaluated once, since its condition cannot
change during runtime. (We either support something or we don't, and the
spec specifically mentions that user preferences that disable features
do not affect the result here.) We keep a representation of it around
though, so that it can be serialized if needed. This is a little awkward
since we hold onto a `StyleDeclarationRule` which should be an internal
Parser class. This means making some Parser functions more public.

Potentially we could evaluate the Supports inside the Parser, and have
it only store a String representation of itself. But this works for now.
:^)
2021-10-08 23:02:57 +02:00
Sam Atkins
575ce04148 LibWeb: Add CSS.escape() JS function
This is the `CSS` namespace defined in IDL here:
https://www.w3.org/TR/cssom-1/#namespacedef-css , not to be confused
with our `Web::CSS` namespace. Words are hard.

`CSS.escape()` lets you escape identifiers that can then be used to
create a CSS string.

I've also stubbed out the `CSS.supports()` function.
2021-10-08 23:02:57 +02:00
Andreas Kling
3c0b55c284 LibWeb: Add DOMRectReadOnly and make DOMRect inherit from it
This matches the class hierarchy of the CSS Geometry Interfaces Module.
2021-10-08 23:00:49 +02:00
Ben Wiederhake
7619dbdbb4 LibWeb: Clean up static function in header
'static' for a function means that the symbol shall not be made public
for the result of the current compilation unit. This does not make sense
in a header, especially not if it's a large function that is used in
more than one place and not that performance-sensitive.
2021-10-06 23:52:40 +01:00
Andreas Kling
c4826eae4f LibWeb: Rename Layout::BlockBox => BlockContainer
There's a subtle difference here. A "block box" in the spec is a
block-level box, while a "block container" is a box whose children are
either all inline-level boxes in an IFC, or all block-level boxes
participating in a BFC.

Notably, an "inline-block" box is a "block container" but not a "block
box" since it is itself inline-level.
2021-10-06 20:10:36 +02:00
Sam Atkins
050823bea7 LibWeb: Fire MediaQueryListEvents when an MQL's match-state changes
The HTML event loop does a check for MQL match-state changes and
dispatches the events. This requires us to keep a list of MQLs on the
Document.
2021-10-05 18:51:39 +02:00
Andreas Kling
a7a3f41f67 LibWeb: Implement the HTMLHyperlinkElementUtils mixin
This is used by HTMLAnchorElement and HTMLAreaElement to share
functionality related to their href attribute.
2021-10-03 21:31:46 +02:00
Luke Wilde
8d6db36cbb LibWeb: Add support for NodeList
This introduces 3 classes: NodeList, StaticNodeList and LiveNodeList.
NodeList is the base of the static and live versions. Static is a
snapshot whereas live acts on the underlying data and thus inhibits
the same issues we have currently with HTMLCollection.

They were split into separate classes to not have them weirdly
mis-mashed together.

The create functions for static and live both return a NNRP to the base
class. This is to prevent having to do awkward casting at creation
and/or return, as the bindings expect to see the base NodeList only.
2021-10-03 00:18:52 +02:00
Idan Horowitz
1e8ba0d9d3 LibWeb: Add the missing SubmitEvent IDL constructor
This commit also removes the SubmitEvent.cpp file, as all of the method
implementations were trivial and could be inlined into the header file.
2021-10-01 20:14:45 +02:00
Idan Horowitz
7f551d7f6a LibWeb: Use the LibWeb source directory as the IDL #import base path
This allows us to include IDL files from other base LibWeb directories
wihout using relative `../foo.idl` references.
2021-10-01 20:14:45 +02:00
Sam Atkins
3e74c194f9 LibWeb: Add CSSMediaRule
This is the class corresponding to a `@media` rule. It contains a list
of media queries and a list of child css rules.
2021-10-01 20:03:03 +02:00
Sam Atkins
8ac622f056 LibWeb: Add MediaList
This is a list of MediaQuery objects. Not to be confused with
`MediaQueryList`, which is concerned with firing events when a media
query's match-state changes.
2021-10-01 20:03:03 +02:00
Sam Atkins
0a4d9c6d31 LibWeb: Partially implement MediaQuery class :^)
The main thing that's missing is the actual matching, but this is enough
to get started.
2021-10-01 20:03:03 +02:00
Idan Horowitz
2c6c9b73c8 LibWeb: Add the Web::Crypto namespace, built-in, and getRandomValues
Since we don't support IDL typedefs or unions yet, the responsibility
of verifying the type of the argument is temporarily moved from the
generated Wrapper to the implementation.
2021-09-30 20:02:09 +02:00
Andreas Kling
6cda24097b LibWeb: Add the CSSStyleRule interface with some limited functionality 2021-09-30 00:00:55 +02:00
Andreas Kling
3a4565beec LibWeb: Make CSSRule and CSSRuleList available to JavaScript :^)
This patch makes both of these classes inherit from RefCounted and
Bindings::Wrappable, plus some minimal rejigging to allow us to keep
using them internally while also exposing them to web content.
2021-09-29 21:21:57 +02:00
Sam Atkins
0b23a20ad5 LibWeb: Add CSSConditionRule
https://www.w3.org/TR/css-conditional-3/#the-cssconditionrule-interface

This simply exposes a condition string, which is implemented differently
in each sub-class.
2021-09-29 18:57:48 +02:00
Sam Atkins
06f9395056 LibWeb: Add CSSGroupingRule
This is an abstract base class for CSSRules that hold a CSSRuleList.
2021-09-29 18:57:48 +02:00
Sam Atkins
97a78cdd28 LibWeb: Add CSSRuleList
"The CSSRuleList interface represents an ordered collection of CSS style
rules." - https://www.w3.org/TR/cssom-1/#the-cssrulelist-interface
2021-09-29 18:57:48 +02:00
Andreas Kling
554c344ffe LibWeb: Add a basic KeyboardEvent and fire "keydown" events :^) 2021-09-28 16:56:24 +02:00
Idan Horowitz
01417c82c5 LibWeb: Make URLSearchParams iterable
This uses the new support for the iterable IDL property.
2021-09-28 16:51:27 +02:00
Idan Horowitz
cdde3ba5c5 LibWeb: Add partial support for IDL Iterable declarations
This currently only supports pair iterables (i.e. iterable<key, value>)
support for value iterables (i.e. iterable<value>) is left as TODO().

Since currently our cmake setup calls the WrapperGenerator separately
and unconditionally for each (hard-coded) output file iterable wrappers
have to be explicitly marked so in the CMakeLists.txt declaration, we
could likely improve this in the future by querying WrapperGenerator
for the outputs based on the IDL.
2021-09-28 16:51:27 +02:00
Luke Wilde
f7ac3545cc LibWeb: Add initial support for CustomEvent
This is used surprisingly often. For example, it is used by a core
YouTube library called Structured Page Fragments.

It allows you to manually dispatch an event with arbitrary data
attached to it.

The only thing missing from this implementation is the constructor.
This is because WrapperGenerator is currently missing dictionary
capabilities.
2021-09-27 18:45:45 +02:00
Andreas Kling
43d378940f LibWeb: Add DOMRect and Element.getBoundingClientRect()
This marks our entry into the Web::Geometry namespace, based on the
"Geometry" spec at https://drafts.fxtf.org/geometry/
2021-09-27 01:01:29 +02:00
Luke Wilde
f6b24a72ee LibWeb: Add support for HTMLOrSVGElement.dataset 2021-09-26 18:59:56 +02:00
Luke Wilde
37347cbcb6 LibWeb: Convert HTMLCollection to use IDL special operations 2021-09-26 18:59:56 +02:00
Luke Wilde
41ae0c0216 LibWeb: Add support for IDL legacy platform objects
A legacy platform object is a non-global platform object that
implements a special operation. A special operation is a getter, setter
and/or deleter. This is particularly used for old collection types,
such as HTMLCollection, NodeList, etc.

This will be used to make these spec-compliant and remove their custom
wrappers. Additionally, it will be used to implement collections that
we don't have yet, such as DOMStringMap.
2021-09-26 18:59:56 +02:00
Andreas Kling
831fdcaabc LibWeb: Add the PageTransitionEvent interface and fire "pageshow" events
We now fire "pageshow" events at the appropriate time during document
loading (done by the parser.)

Note that there are no corresponding "pagehide" events yet.
2021-09-26 12:47:51 +02:00
Andreas Kling
dbba0a520f LibWeb: Allow HTML parser to delay delivery of the document "load" event
We will now spin in "the end" until there are no more "things delaying
the load event". Of course, nothing actually uses this yet, and there
are a lot of things that need to.
2021-09-26 02:00:00 +02:00
Andreas Kling
f67648f872 LibWeb: Rename HTMLDocumentParser => HTMLParser 2021-09-25 23:36:43 +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
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
abc22b727c LibWeb: Move background painting from Box to its own file
This makes the code accessible to things that aren't a Box, such as
InlineNode.
2021-09-19 22:53:35 +02:00
Sam Atkins
b047c1bc97 LibWeb: Move box-shadow painting out of Box to its own file
This makes the code accessible to things that aren't a Box, such as
InlineNode.
2021-09-19 22:53:35 +02:00