Commit Graph

301 Commits

Author SHA1 Message Date
Andreas Kling
89cd00b540 LibWeb: Fix broken step 4.3 implementation in run_focus_update_steps()
Some over-eager copy-pasting led to incorrect code for the new chain.
2022-02-07 02:17:49 +01:00
Andreas Kling
a05c07fdcd LibWeb: Use NonnullRefPtrVector<DOM::Node> for focus chains
Let's just use reference-counting pointers for this, even if it seems
safe not to.
2022-02-07 02:17:45 +01:00
Andreas Kling
1ea2467a7a LibWeb: Improve step 3 of "focus chain" from the HTML spec
This function was unnecessarily nested, which created a scenario where
we could get stuck in an infinite loop without advancing the
current_object pointer up the browsing context container chain.
2022-02-07 01:55:06 +01:00
Andreas Kling
086eb1ad7b LibWeb: Fix inverted null check in run_focusing_steps()
Thanks to U9G for catching this! :^)
2022-02-07 01:29:01 +01:00
Andreas Kling
627ad6c37c LibWeb: Add a proper FocusEvent interface for "focus" and "blur" events 2022-02-07 00:04:50 +01:00
Andreas Kling
9391311760 LibWeb: Make HTMLInputElement move cursor into text node when focused
This mechanism feels rather awkward, but it's better than nothing.
2022-02-06 22:13:13 +01:00
Andreas Kling
a062e803c5 LibWeb: Implement (most of) HTMLElement.focus()
The main deviation from the spec is that we don't have a straightforward
representation of the spec's "focusable area" concept.

I've left a bunch of FIXME's around for our future selves. :^)
2022-02-06 22:13:13 +01:00
Andreas Kling
1165a94624 LibWeb: Implement BrowsingContext::currently_focused_area()
This is "currently focused area of a top level browsing context"
from the HTML spec.
2022-02-06 22:13:13 +01:00
Andreas Kling
41fe02e012 LibWeb: Rename "frame" to "browsing_context" in various places
We renamed the Frame class to BrowsingContext a while back, but forgot
to update some variable names.
2022-02-06 16:22:58 +01:00
Andreas Kling
483dce9750 LibWeb: Put ClassicScript debug spam behind HTML_SCRIPT_DEBUG 2022-02-05 22:50:39 +01:00
Andreas Kling
e6f279dada LibWeb: Implement CanvasGradient.addColorStop() according to spec
The object is still not usable for anything, but at least now it behaves
correctly with regards to throwing exceptions.
2022-02-05 22:50:39 +01:00
Andreas Kling
7e1bf4d300 LibWeb: Compute element style in Layout::TreeBuilder
Instead of making each Layout::Node compute style for itself, we now
compute it in TreeBuilder before even calling create_layout_node().

For non-element DOM nodes, we create the style and layout tree node
in TreeBuilder. This allows us to move create_layout_node() from
DOM::Node to DOM::Element.
2022-02-05 22:50:39 +01:00
Andreas Kling
926d5271b4 LibWeb: Forward CanvasRenderingContext.strokeText() to fillText()
This is a hack until we get an actual text stroking implementation.
2022-02-03 22:35:13 +01:00
Andreas Kling
dc3bf32307 LibWeb: Add barebones CanvasGradient object
Also add the CanvasRenderingContext2D APIs to go along with it.
Note that it can't be used for anything yet.
2022-02-03 22:35:13 +01:00
Andreas Kling
90a8744823 LibWeb: Add CanvasRenderingContext2D.bezierCurveTo() 2022-02-03 22:35:13 +01:00
Luke Wilde
631bbcd00a LibJS: Refactor interpreter to use Script and Source Text Modules
This also refactors interpreter creation to follow
InitializeHostDefinedRealm, but I couldn't fit it in the title :^)

This allows us to follow the spec much more closely rather than being
completely ad-hoc with just the parse node instead of having all the
surrounding data such as the realm of the parse node.

The interpreter creation refactor creates the global execution context
once and doesn't take it off the stack. This allows LibWeb to take the
global execution context and manually handle it, following the HTML
spec. The HTML spec calls this the "realm execution context" of the
environment settings object.

It also allows us to specify the globalThis type, as it can be
different from the global object type. For example, on the web, Window
global objects use a WindowProxy global this value to enforce the same
origin policy on operations like [[GetOwnProperty]].

Finally, it allows us to directly call Program::execute in perform_eval
and perform_shadow_realm_eval as this moves
global_declaration_instantiation into Interpreter::run
(ScriptEvaluation) as per the spec.

Note that this doesn't evalulate Source Text Modules yet or refactor
the bytecode interpreter, that's work for future us :^)

This patch was originally build by Luke for the environment settings
object change but was also needed for modules. So I (davidot) have
modified it with the new completion changes and setup for that.

Co-authored-by: davidot <davidot@serenityos.org>
2022-01-22 01:21:18 +00:00
sin-ack
2e1bbcb0fa LibCore+LibIPC+Everywhere: Return Stream::LocalSocket from LocalServer
This change unfortunately cannot be atomically made without a single
commit changing everything.

Most of the important changes are in LibIPC/Connection.cpp,
LibIPC/ServerConnection.cpp and LibCore/LocalServer.cpp.

The notable changes are:
- IPCCompiler now generates the decode and decode_message functions such
  that they take a Core::Stream::LocalSocket instead of the socket fd.
- IPC::Decoder now uses the receive_fd method of LocalSocket instead of
  doing system calls directly on the fd.
- IPC::ConnectionBase and related classes now use the Stream API
  functions.
- IPC::ServerConnection no longer constructs the socket itself; instead,
  a convenience macro, IPC_CLIENT_CONNECTION, is used in place of
  C_OBJECT and will generate a static try_create factory function for
  the ServerConnection subclass. The subclass is now responsible for
  passing the socket constructed in this function to its
  ServerConnection base; the socket is passed as the first argument to
  the constructor (as a NonnullOwnPtr<Core::Stream::LocalServer>) before
  any other arguments.
- The functionality regarding taking over sockets from SystemServer has
  been moved to LibIPC/SystemServerTakeover.cpp. The Core::LocalSocket
  implementation of this functionality hasn't been deleted due to my
  intention of removing this class in the near future and to reduce
  noise on this (already quite noisy) PR.
2022-01-15 13:29:48 +03:30
Linus Groh
eb60d16549 LibJS: Convert Interpreter::run() to ThrowCompletionOr<Value>
Instead of making it a void function, checking for an exception, and
then receiving the relevant result via VM::last_value(), we can
consolidate all of this by using completions.

This allows us to remove more uses of VM::exception(), and all uses of
VM::last_value().
2022-01-08 23:43:03 +01:00
sin-ack
9121cc7cae LibWeb: Implement CanvasRenderingContext2D.measureText
This requires an implementation of the "text preparation algorithm" as
specified here:

html.spec.whatwg.org/multipage/canvas.html#text-preparation-algorithm

However, we're missing a lot of things such as the
CanvasTextDrawingStyles interface, so most of the algorithm was not
implemented. Additionally, we also are not able to use a LineBox like
the algorithm suggests, because our layouting infra is not up to the
task yet. The prepare_text function does nothing other than figuring out
the width of the given text and return glyphs with offsets at the
moment.
2022-01-04 22:41:07 +00:00
Linus Groh
1298c27ca9 LibWeb: Implement CanvasRenderingContext2D.isContextLost()
Note that we don't implement the "context lost steps" yet, so this will
always return the initial value (false).
2021-12-27 16:43:23 +01:00
Linus Groh
2576af5db1 LibWeb: Implement CanvasRenderingContext2D.reset() 2021-12-27 16:43:23 +01:00
Linus Groh
3e0e965f24 LibWeb: Implement CanvasRenderingContext2D.restore() 2021-12-27 16:43:23 +01:00
Linus Groh
7d435b5ada LibWeb: Implement CanvasRenderingContext2D.save() 2021-12-27 16:43:23 +01:00
Linus Groh
6d50ff71de LibWeb: Encapsulate canvas drawing state in a struct
This will allow us to easily add copies of the relevant canvas drawing
state to a stack, and likewise replace the current drawing  state with
an entry from that stack.
2021-12-27 16:43:23 +01:00
Linus Groh
b32893eb54 LibWeb: Let canvas {fill,stroke}Style default to black, not transparent
I don't know if the original author simply missed this or thought the
default color of Gfx::Color is black, but this meant that drawing on a
canvas without explicitly setting a fillStyle or strokeStyle first would
be drawn in transparent color and therefore be invisible.

In the spec this is indicated by a small comment in the IDL definition:

    attribute ... strokeStyle; // (default black)
    attribute ... fillStyle; // (default black)

I'm starting to question whether Gfx::Color actually *should* have a
default constructor.
2021-12-27 16:43:23 +01:00
Linus Groh
6faaee2bc8 LibWeb: Fix copy/paste typo in CanvasRenderingContext2D::stroke_style()
This returned the fill style, not the stroke style!
2021-12-27 16:43:23 +01:00
Luke Wilde
7fae46361b LibWeb: Fix null-deref in <table> delete_row with index = -1 and no rows
This wasn't quite following what the spec says for step 2:
"If index is −1, then remove the last element in the rows collection
from its parent, or do nothing if the rows collection is empty."

It was behaving like:
"If index is −1 and the rows collection is not empty, then remove the
last element in the rows collection from its parent."

Which is not the same, as it will fall into the "Otherwise" if
`index == -1` and the rows collection is empty and try and get the -2nd
element of the rows.

Found with Domato.
2021-12-21 13:51:15 -08:00
Luke Wilde
54454952e0 LibWeb: Capture <script> element's node document on execution
Step 1 of the spec is to capture the <script> element's node document
into a local variable.

When I originally implemented this, I thought this was not necessary.
However, I realised that the script that runs can adopt the current
script element into a different document, meaning step 5.4 and 6 then
operate on the incorrect document.

Covered by this WPT: 7b0ebaccc6/html/semantics/scripting-1/the-script-element/moving-between-documents-during-evaluation.html
2021-12-21 13:50:00 -08:00
Sam Atkins
197759e30f LibWeb: Fix off-by-one error when highlighting unquoted HTML attributes
This fixes #11166
2021-12-10 21:27:13 +01:00
Sam Atkins
7196570f9b LibWeb: Cast unused smart-pointer return values to void 2021-12-05 15:31:03 +01:00
Andreas Kling
108de5dea0 LibWeb: Stop sending "load" event twice to iframes
The "completely finish loading" algorithm (from the HTML spec) is
responsible for sending a "load" event to nested browsing context
containers (iframes).

This patch removes the old mechanism for sending "load" events, which we
had mistakenly kept around, causing two events to be sent instead of
one. :^)
2021-12-04 14:47:24 +01:00
Vyacheslav Pukhanov
3f006d81fe LibWeb: Add JSON serialization for nested browsing contexts
This changes allows for nested browser contexts to be embedded in the
serialized JSON of their container element (like `iframe`) and enables
their inspection in the DOM Inspector.
2021-11-24 19:07:48 +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
60867703c0 LibWeb: Make HTMLLinkElement responsible for its own loading
This is the last use of CSSLoader, which can now be deleted.
2021-11-18 21:11:19 +01:00
Sam Atkins
3d127472ba LibWeb: Remove background_image from NodeWithStyle
We now entirely use the background-layers to check images.
2021-11-17 22:20:01 +01:00
Andreas Kling
778268b1a5 LibWeb: Allow setting the width & height properties on <canvas> elements 2021-11-13 00:55:07 +01:00
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Andreas Kling
0de33b3d6c LibGfx: Use ErrorOr<T> for Bitmap::try_create()
Another one that was used in a fajillion places.
2021-11-08 00:35:27 +01:00
Andreas Kling
83d1460ee8 LibGfx: Use ErrorOr<T> for Bitmap::try_create_wrapper() 2021-11-08 00:35:27 +01:00
Andreas Kling
5c132724ea LibWeb: Properly handle the <td align> attribute
When valid, this attribute needs to result in an IdentifierStyleValue.
Before this change we were turning it into a StringStyleValue, which
then defaulted to left alignment for all values.

For "center" and "middle", we turn it into -libweb-center. All other
values are passed verbatim to the CSS parser.
2021-10-28 12:53:31 +02:00
Andreas Kling
4333d0d639 LibWeb: Add fast_is<T>() for HTML::HTMLHtmlElement
Another one spotted in a scroll-up-and-down profile.
2021-10-27 17:58:57 +02:00
Sam Atkins
6f71516409 LibWeb: Syntax-highlight CSS within HTML :^) 2021-10-23 19:07:44 +02:00
Sam Atkins
0f393771b7 LibWeb: Move image resource request out of ImageStyleValue constructor
This always felt awkward to me, and required a few other hacks to make
it work. Now, the request is only started when `load_bitmap()` is
called, which we do inside `NodeWithStyle::apply_style()`.
2021-10-23 11:42:24 +02:00
Andreas Kling
957f98805a LibWeb: Update <object> style on resource load/failure 2021-10-18 10:40:30 +02:00
Andreas Kling
177320ee9c LibWeb: Update <img> style on resource load/failure 2021-10-18 10:40:30 +02: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
Sam Atkins
e8d4236bbd LibWeb: Use W3C urls for CSSOM spec links
https://www.w3.org/TR/cssom/ is the more permanent home of the CSSOM
specification's latest version, and is up to date with the draft spec.

Also, https://drafts.csswg.org/ has been down multiple times recently
which made looking things up a pain.
2021-10-15 21:05:35 +01:00
Andreas Kling
76ac1b2496 LibWeb: Add missing upcalls in HTMLSelectElement 2021-10-12 12:17:25 +02:00
Andreas Kling
06e54ea916 LibWeb: Add missing upcalls in HTMLInputElement
We need to call the base class in overrides of inserted() and
removed_from(), or things like style invalidation will break.
2021-10-12 12:17:25 +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