Commit Graph

64 Commits

Author SHA1 Message Date
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Andreas Kling
bfd354492e LibWeb: Put most LibWeb GC objects in type-specific heap blocks
With this change, we now have ~1200 CellAllocators across both LibJS and
LibWeb in a normal WebContent instance.

This gives us a minimum heap size of 4.7 MiB in the scenario where we
only have one cell allocated per type. Of course, in practice there will
be many more of each type, so the effective overhead is quite a bit
smaller than that in practice.

I left a few types unconverted to this mechanism because I got tired of
doing this. :^)
2023-11-19 22:00:48 +01:00
Shannon Booth
d312fdc2d3 LibWeb: Port CanvasRenderingContext2D from DeprecatedString to String 2023-09-09 10:47:12 -06:00
Andreas Kling
72c9f56c66 LibJS: Make Heap::allocate<T>() infallible
Stop worrying about tiny OOMs. Work towards #20449.

While going through these, I also changed the function signature in many
places where returning ThrowCompletionOr<T> is no longer necessary.
2023-08-13 15:38:42 +02:00
Bastiaan van der Plaat
bba14f6014 LibWeb: Add Canvas Context2D basic font property support 2023-08-09 05:48:32 +02:00
Andreas Kling
18c54d8d40 LibJS: Make Cell::initialize() return void
Stop worrying about tiny OOMs.

Work towards #20405
2023-08-08 07:39:11 +02:00
Bastiaan van der Plaat
220e34b69d LibWeb: Add Canvas Context2D basic text align and text baseline support
Add the CanvasTextDrawingStyles mixin with the textAlign and
textBaseline attributes. Update fill_text in CanvasRenderingContext2D
to move the text rect by the text align and text baseline attributes.
Wrote a simple HTML example to showcase the new features.
2023-08-05 17:17:08 +02:00
Simon Danner
45f86466bb LibWeb: Add initial implementation of CRC2D.globalAlpha
Works for fills and strokes (using colors, gradients, or patterns),
along with images.

fill_rect() has been updated to use fill_path(), which allows it to
easily transform the rect, and already supports opacity.

Co-authored-by: MacDue <macdue@dueutil.tech>
2023-06-18 20:31:11 +02:00
MacDue
ff5d530aa3 LibWeb: Pass CRC2D fill_rule as enum rather than StringView 2023-06-18 20:31:11 +02:00
MacDue
20e9213cc4 LibWeb: Add initial implementation of CRC2D.clip()
This allows clipping your drawing by any path you like! To do this
all painting has been wrapped around a new draw_clipped() helper
method, which handles the clipping before/after painting.

Note: This clipping is currently missing support for intersecting
clip paths.
2023-04-09 18:42:45 +02:00
Andreas Kling
e77552519e LibWeb: Implement CRC2D.imageSmoothingEnabled
We now select between nearest neighbor and bilinear filtering when
scaling images in CRC2D.drawImage().

This patch also adds CRC2D.imageSmoothingQuality but it's ignored for
now as we don't have a bunch of different quality levels to map it to.

Work towards #17993 (Ruffle Flash Player)
2023-03-29 22:48:04 +02:00
Timothy Flynn
3d7b13ac03 LibWeb: Make canvas text preparation handle multi-code point glyphs 2023-02-24 20:28:23 +01:00
Kenneth Myhra
b7c488e51e LibWeb: Make factory method of HTML::CanvasRenderingContext2D fallible 2023-02-18 00:52:47 +01:00
Timothy Flynn
2692db8699 LibJS+Everywhere: Allow Cell::initialize overrides to throw OOM errors
Note that as of this commit, there aren't any such throwers, and the
call site in Heap::allocate will drop exceptions on the floor. This
commit only serves to change the declaration of the overrides, make sure
they return an empty value, and to propagate OOM errors frm their base
initialize invocations.
2023-01-29 00:02:45 +00:00
Timothy Flynn
834202aeb9 LibWeb: Move setting of Web object prototypes to initialize()
This needs to happen before prototype/constructor intitialization can be
made lazy. Otherwise, GC could run during the C++ constructor and try to
collect the object currently being created.
2023-01-10 16:08:14 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
MacDue
6daef6303a LibWeb: Use AntiAliasingPainter for canvas painting 2022-11-30 07:58:44 +01:00
Andrew Kaster
f0c5f77f99 LibWeb: Remove unecessary dependence on Window from HTML classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct HTML classes.
2022-10-01 21:05:32 +01:00
Linus Groh
ad04d7ac9b LibWeb: Move ExceptionOr from DOM/ to WebIDL/
This is a concept fully defined in the Web IDL spec and doesn't belong
in the DOM directory/namespace - not even DOMException, despite the name
:^)
2022-09-25 19:13:31 +01:00
Linus Groh
4270ede7c4 LibWeb: Remove WRAPPER_HACK() macro
We no longer access Bindings::FooWrapper anywhere for a Foo platform
object, so these can be removed :^)
2022-09-21 21:12:24 +01:00
Andreas Kling
6b7a1d13e9 LibWeb: Make TextMetrics GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
369dd42d67 LibWeb: Make ImageData GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
4452b5ca09 LibWeb: Make 2D and 3D canvas rendering contexts GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
6f433c8656 LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
2022-09-06 00:27:09 +02:00
Sam Atkins
9f71d65005 LibWeb: Extract CanvasPathDrawingStyles class from CRC2D 2022-08-14 11:30:40 +02:00
Sam Atkins
53b9f36413 LibWeb: Extract CanvasImageData class from CRC2D 2022-08-14 11:30:40 +02:00
Sam Atkins
270c60c5e8 LibWeb: Extract CanvasDrawImage class from CRC2D 2022-08-14 11:30:40 +02:00
Sam Atkins
7cf42ede68 LibWeb: Extract CanvasText class from CRC2D 2022-08-14 11:30:40 +02:00
Sam Atkins
62b561e2e1 LibWeb: Extract CanvasDrawPath class from CRC2D
Again, this is an entirely virtual class since the methods involve
direct access to the Painter. Though, maybe I could just expose the
Painter...
2022-08-14 11:30:40 +02:00
Sam Atkins
c0494988ed LibWeb: Extract CanvasRect class from CRC2D
This one requires drawing to the canvas, so it doesn't make so much
sense to move the implementation over.
2022-08-14 11:30:40 +02:00
Sam Atkins
aa3cb8b425 LibWeb: Extract CanvasFillStrokeStyles class from CRC2D 2022-08-14 11:30:40 +02:00
Sam Atkins
afabd613bd LibWeb: Extract CanvasFillStrokeStyles class from CRC2D 2022-08-14 11:30:40 +02:00
Sam Atkins
aa87b9699e LibWeb: Extract CanvasTransform class from CRC2D
The implementation of this got a little funky, because it has to access
methods from CanvasState.
2022-08-14 11:30:40 +02:00
Sam Atkins
08e6071ebb LibWeb: Extract CanvasState class from CRC2D
As with CanvasPath, this is to better match the spec IDL.
2022-08-14 11:30:40 +02:00
Sam Atkins
6644f3ab44 LibWeb: Teach CRC2D to draw Path2Ds :^) 2022-08-14 11:30:40 +02:00
Sam Atkins
a37ab7b9f8 LibWeb: Extract CanvasPath class from CRC2D
This better matches the spec, and makes it possible for things like
Path2D to reuse the same implementation without duplicate code. :^)
2022-08-14 11:30:40 +02:00
Luke Wilde
adf8341c4e LibWeb: Forward CRC2D's ref count to HTMLCanvasElement
This allows HTMLCanvasElement and CRC2D to share their lifetime, as JS
allows them to arbitrarily access them at any time and CRC2D.canvas
expects a non-null return value.
2022-06-27 22:54:41 +01:00
Luke Wilde
89c4e011e4 LibWeb: Stub CanvasRenderingContext2D.clip
This is primarily required by Google Maps Street View, but the map view
works without this.
2022-04-10 19:59:14 +02:00
Luke Wilde
27cc8742ce LibWeb: Implement CanvasRenderingContext2D.resetTransform 2022-04-10 19:59:14 +02:00
Luke Wilde
329e740c85 LibWeb: Implement CanvasRenderingContext2D.setTransform 2022-04-10 19:59:14 +02:00
Luke Wilde
df7a83ac0e LibWeb: Implement CanvasRenderingContext2D.transform 2022-04-10 19:59:14 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Idan Horowitz
bc0fafade9 LibWeb: Add all overloads of CanvasRenderingContext2D::drawImage() 2022-03-05 23:40:08 +01:00
Linus Groh
e890cd5464 LibWeb: Implement CanvasRenderingContext2D.getImageData()
The actual copying of the pixel values into the created ImageData object
is a bit ugly, but Gfx::Painter doesn't like the underlying RGBA8888
bitmap.
2022-03-04 23:03:29 +01:00
Linus Groh
3f3326f1dc LibWeb: Implement CanvasRenderingContext2D.drawImage() closer to spec
Also add support for HTMLCanvasElement for the image parameter, leading
to replacing HTMLImageElement with the CanvasImageSource Variant type.

Also stub out the 'check the usability of the image argument' and 'is
not origin-clean' operations, while taking into consideration that these
can throw (and require DOM::ExceptionOr).
2022-03-04 23:03:29 +01:00
Linus Groh
ed03f37ae9 LibWeb: Add CanvasRenderingContext2D's origin-clean flag 2022-03-04 23:03:29 +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
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