Commit Graph

30442 Commits

Author SHA1 Message Date
Lucas CHOLLET
2cfca633ca LibGfx/TIFF: Add support for images with UnassociatedAlpha
UnassociatedAlpha is the one used by GIMP when generating TIFF images
with transparency. Support is added for Grayscale and RGB images as it's
the two that we support right now but managing transparency should be
really straightforward for other types as well.
2023-12-22 08:08:47 +00:00
Lucas CHOLLET
796ece7b35 LibGfx/TIFF: Read the ExtraSamples tag 2023-12-22 08:08:47 +00:00
Aliaksandr Kalenik
56658b5354 LibWeb+WebContent: Remove unused page_did_click_link()
Not used since we migrated to navigables.
2023-12-21 19:25:18 +01:00
Aliaksandr Kalenik
d87f3a4101 LibWebView+Ladybird: Remove unused on_scroll_into_view callback
Leftover from 9624eca116
2023-12-21 19:25:18 +01:00
Nico Weber
6032c06f6b Revert "LibPDF: Add basic tiled, coloured pattern rendering"
This reverts commit 8ff87911a3.
2023-12-21 19:24:56 +01:00
Nico Weber
7cb216c95b Revert "LibPDF: Offset PaintStyle when painting so pattern overlaps..."
This reverts commit 8c7fc4fe6c.
2023-12-21 19:24:56 +01:00
Bastiaan van der Plaat
0f37e0ee89 LibWeb: Add basic input range rendering 2023-12-21 13:17:51 +01:00
Aliaksandr Kalenik
d28c400fcb headless-browser: Load test page after callbacks are registered
Eliminates possibility that page will load before callbacks are added.
2023-12-21 10:20:05 +01:00
Aliaksandr Kalenik
2f09bfeff2 headless-browser: Await on_load_finish() while running Text tests
Before this change, it was possible for a text test to finish before
on_load_finish() was triggered, resulting in the subsequent test
receiving the load event from the previous test.
2023-12-21 10:20:05 +01:00
Nicolas Ramz
6ccdb1dc72 LibGfx/ILBMLoader: Add support for 24bit files 2023-12-21 09:19:30 +00:00
Nicolas Ramz
caa13d3960 LibGfx/ILBMLoader: Stop the decoding loop when plane buffer is full
This allows decoding files (eg. 24bit) that may have been badly encoded.
2023-12-21 09:19:30 +00:00
Nico Weber
6de32e5359 LibPDF: Draw inline images
The idea is to massage the inline image data into something that
looks like a regular image, and then use the normal image drawing code:
We translate the inline image abbreviations to the expanded version at
rendering time, then unfilter (i.e. uncompress) the image data at
rendering time, and the go down the usual image drawing path.

Normal streams are unfiltered when they're first accessed, but
inline image streams live in a page's drawing operators, and this
fits the current approach of parsing a page's operators anew
every time the page is rendered.

(We also need to add some special-case handling for color spaces
of inline images: Inline images can use named color spaces, while
regular images always use direct color space objects.)
2023-12-20 12:45:16 -07:00
Andrew Kaster
c0f50b12a4 LibWeb: Post all MessagePort messages over their LocalSockets
This is to allow future changes to do cross-process MessagePorts in an
implementation-agnostic way. Add some tests for this behavior.

Delivering messages that were posted to a MessagePort just before it was
transferred is not yet implemented still.
2023-12-20 12:25:40 -07:00
Andrew Kaster
6e3b816763 LibWeb: Represent transferred objects as an empty object
This matches the behavior of the three major engines.
2023-12-20 12:25:40 -07:00
Aliaksandr Kalenik
cfcec5e18e LibWeb: Scroll to the top after navigating to a new document
This change fixes a bug with running tests where, if one of the
previous tests changes the scroll position, all subsequent tests that
rely on the scroll position will fail. This is because the headless
browser never resets the viewport offset.
2023-12-20 09:48:06 -07:00
Aliaksandr Kalenik
41b065dec9 LibWeb: Do not crash for empty fragment in determine_the_indicated_part
The way this method is used in spec implies it should return
`TopOfTheDocument` if fragment is missing.
2023-12-20 09:48:06 -07:00
Nico Weber
d577d181e3 LibPDF: Clamp linear_srgb values in convert_to_srgb()
This is very crude gamut mapping, but it's better than producing
NaNs when passing negative values to powf(x, 1/2.2).
2023-12-20 12:45:07 +01:00
tetektoza
3ff36855d4 LibGUI: Display commands on CommandPalette's start up
Currently, if we run CommandPalette, it's blank by default and it's not
displaying all available commands for the app in which it has been
opened. User has to enter something and then delete it to see
all commands. This patch makes all available commands being displayed
by default on start of CommandPalette, by allowing incoming empty
string to be invalidated in FilteringProxyModel, instead of returning
instantly.
2023-12-20 12:22:05 +01:00
Lucas CHOLLET
b0e5aadf1a LibGfx/TIFF: Remove an unneeded parameter
This should have been done in f00e9540.
2023-12-20 12:19:30 +01:00
Lucas CHOLLET
caf9f00456 LibGfx/TIFF: Skip channels that we are unable to interpret
As per the specification, TIFF readers should gracefully skip samples
that they are not able to interpret.

This patch allow us to read `strike.tif` from the libtiff test suite as
an RGB image.
2023-12-20 12:19:30 +01:00
Lucas CHOLLET
a443d2955a LibGfx/TIFF: Don't use SamplesPerPixel to infer the "type" of image
The number of samples is not a good measure to deduce the type of image
we are decoding. As per the TIFF spec, the PhotometricInterpretation tag
is required and we should use that instead.
2023-12-20 12:19:30 +01:00
Nico Weber
022fce75a6 LibPDF: Get inline image data from parser to renderer
We create a inline_image_end operator that has all the relevant data
in a synthetic StreamObject.

inline_image_end is still a RENDERER_TODO(), so no real behavior
change. (Previously we'd call only inline_image_begin, so string the
todo message is about is now a bit different. But no interesting
behavior change.)
2023-12-20 12:19:08 +01:00
Nico Weber
3285502ec6 LibPDF: Extract a Parser::unfilter_stream() method
No behavior change.
2023-12-20 12:19:08 +01:00
Nico Weber
b21f867e88 LibPDF: Don't crash on images with empty filter arrays
0000967.pdf page 2 contains a bunch of inline images with empty
filter arrays.
2023-12-20 12:19:08 +01:00
Nico Weber
13641693cb LibPDF: Use make_object<>() to make objects
No behavior change.
2023-12-20 12:19:08 +01:00
MacDue
809c5b0b03 LibWeb: Add initial support for SVG <textPath>
This patch adds basic support for the SVG `<textPath>`, so it supports
placing text along a path, but none of the extra attributes for
controlling the layout of the text. This is enough to correctly display
the MDN example.
2023-12-19 21:29:03 +01:00
MacDue
d327104910 LibGfx: Add Path::place_text_along(text, font)
This method returns a new path with the input text placed along the edge
of the original path.
2023-12-19 21:29:03 +01:00
MacDue
8713968165 LibGfx: Preserve path order while splitting cubic/quadratic beziers
This changes the splitting to use a stack, which ensures the resulting
line segments follow the path in order. This will be important for SVG
`<textPath>`s which place text along a path.
2023-12-19 21:29:03 +01:00
Aliaksandr Kalenik
b2abd1dd05 LibWeb: Resolve box shadow data for paintable boxes during layout
Step towards making the paintable tree independent of the layout tree.
2023-12-19 21:08:51 +01:00
Andrew Kaster
f68c67bf3f LibWeb: Implement MessagePort.postMessage closer to the spec
Use a LocalSocket to represent the connection between two message ports.

The concept of the port message queue is still missing, however. When
that concept is implemented, the "steps" in step 7 of the message port
transfer steps will need to send the serialized data over the connected
socketpair and run in the event loop of the process that holds onto the
other side of the message port. Doing this should allow centralizing the
behavior of postMessage for Window, MessagePorts and Workers.
2023-12-19 21:08:05 +01:00
Andrew Kaster
c7f7ee2c4b headless-browser: Log current test when WebContent crashes 2023-12-19 21:08:05 +01:00
Andrew Kaster
82ec1ea75e LibJS: Provide better assertion for empty execution context stack
When calling `running_execution_context` from other VM APIs, and the
execution context stack is empty, the verification message is inlined
from AK::Vector. Add a specific VERIFY to `running_execution_context` to
help diagnose this issue better.
2023-12-19 21:08:05 +01:00
Lucas CHOLLET
64912d4d02 LibGfx/TIFF: Add support for images with CCITT3 1D compression
This compression (tag Compression=2) is not very popular on its own, but
a base to implement CCITT3 2D and CCITT4 compressions.

As the format has no real benefits, it is quite hard to find an app that
accepts tho encode that for you. So I used the following program that
calls `libtiff` directly:
```cpp
#include <vector>
#include <cstdlib>
#include <iostream>

#include <tiffio.h>

// An array containing 0 and 1 of length width * height.
extern std::vector<uint8_t> array;
int main() {
    // From: https://stackoverflow.com/a/34257789

    TIFF *image = TIFFOpen("input.tif", "w");
    int const width = 400;
    int const height = 300;
    TIFFSetField(image, TIFFTAG_IMAGEWIDTH, width);
    TIFFSetField(image, TIFFTAG_IMAGELENGTH, height);
    TIFFSetField(image, TIFFTAG_PHOTOMETRIC, 0);
    TIFFSetField(image, TIFFTAG_COMPRESSION, COMPRESSION_CCITTRLE);

    TIFFSetField(image, TIFFTAG_BITSPERSAMPLE, 1);
    TIFFSetField(image, TIFFTAG_SAMPLESPERPIXEL, 1);
    TIFFSetField(image, TIFFTAG_ROWSPERSTRIP, 1);

    std::vector<uint8_t> scan_line(width / 8 + 8, 0);
    int count = 0;
    for (int i = 0; i < height; i++) {
        std::fill(scan_line.begin(), scan_line.end(), 0);
        for (int x = 0; x < width; ++x) {
            uint8_t eight_pixels = scan_line.at(x / 8);
            eight_pixels = eight_pixels << 1;
            eight_pixels |= !array.at(i * width + x);
            scan_line.at(x / 8) = eight_pixels;
        }
        int bytes = int(width / 8.0 + 0.5);
        if (TIFFWriteScanline(image, scan_line.data(), i, bytes) != 1)
            std::cerr << "Something went wrong\n";
    }

    TIFFClose(image);
}
```
2023-12-19 21:01:24 +01:00
Lucas CHOLLET
7266d8c35d LibGfx/TIFF: Correctly upscale samples with a resolution lower than 8
As pointed out by @nico, while doing a right-shift to downscale is fine,
a left-shift to upscale gives wrong results. As an example, imagine a 2-
bits value containing 3, left-shifting it would give 192 instead of 255.
2023-12-19 21:01:24 +01:00
Aliaksandr Kalenik
fc9a8c77d5 headless-browser: Update m_viewport_rect after changing scroll offset 2023-12-19 20:59:52 +01:00
Aliaksandr Kalenik
c5d91dce8b LibWeb: Scroll to the "start" in Document::scroll_to_fragment()
Implements spec comment.
2023-12-19 20:59:52 +01:00
Aliaksandr Kalenik
7458c27c4b WebContent: Pre-emptively update viewport offset on request to scroll 2023-12-19 20:59:52 +01:00
Andrew Kaster
d361221657 LibJS+LibWeb: Add JS::Value constructor for `JS::Handle<T>`
Similar to the constructors for ``JS::{Nonnull}GCPtr<T>``, this helper
avoids unnecessary .ptr() clutter when we want to construct Values.
2023-12-19 09:21:55 -07:00
Aliaksandr Kalenik
9624eca116 LibWeb+LibWebView+WebContent: Remove unused request_scroll_into_view
`Element::scroll_into_view()` is supposed to be used instead.
2023-12-19 10:45:07 +01:00
Aliaksandr Kalenik
f6f80a1a72 LibWeb: Scroll to "nearest" instead of "start" in set_focused_element()
Fixes a bug when after clicking on a button/click the page is scrolled
to start of the element.
2023-12-19 10:45:07 +01:00
Aliaksandr Kalenik
cda1d886df LibWeb: Fix not working Element::scroll_an_element_into_view()
Fixes following mistakes:
- "scrolling box" for a document is not `scrollable_overflow_rect()`
   but size of viewport (initial containing block, like spec says).
- comparing edges of "scrolling box" with edges of target element
  does not make any sense because "scrolling box" edges are relative
  to page while result of `get_bounding_client_rect()` is relative
  to viewport.
2023-12-19 10:45:07 +01:00
Aliaksandr Kalenik
a93ab25487 headless-browser: Implement on_scroll_to_point and on_scroll_by_delta
Without these callbacks "scroll" events are not emitted so we can't
write tests for scrolling.
2023-12-19 10:45:07 +01:00
Lucas CHOLLET
5b62d877f2 LibGfx/TIFF: Parse more common tags
These tags are either part of the baseline specification or included by
default by GIMP when exporting TIFF files. Note that we don't add
support for them in the decoder yet. This commit only allows us to parse
the metadata and display it gracefully.
2023-12-18 07:14:11 +01:00
Aliaksandr Kalenik
bd08b1815f LibWeb: Implement border radius corner clipping in GPU painter
It is implemented in the way identical to how it works in CPU painter:
1. SampleUnderCorners command saves pixels within corners into a
   texture.
2. BlitCornerClipping command uses the texture prepared earlier to
   restore pixels within corners.
2023-12-17 23:12:48 +01:00
Aliaksandr Kalenik
177e7df1c5 LibWeb: Move border radius sampling config preparation into a function
In upcoming changes this code is going to be reused in GPU painter.
2023-12-17 23:12:48 +01:00
Bastiaan van der Plaat
a05fd28b7b LibWeb: Move use pseudo element styles from TreeBuilder to StyleComputer
The styling of elements using the `use_pseudo_element()` was only
applied on layout. When an element style was recomputed later that
styling was not overruled with the pseudo element selector styles.
This moves the styling override from `TreeBuilder.cpp` to
`StyleComputer.cpp`. Now the styles are always correctly applied.
I also removed the method `property_id_by_index()` because it was
not needed anymore.

Als some calls to `invalidate_layout()` in the Meter, Progress and
Select elements where not needed anymore because the style values
are update on the changing of the style attribute.

This fixes issue #22278.
2023-12-17 23:12:34 +01:00
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
Aliaksandr Kalenik
38d62563b3 LibAccelGfx: Fix stack use after scope in GlyphAtlas::update() 2023-12-17 14:55:41 +01:00
Ali Mohammad Pur
36f0499cc8 LibLine: Use grapheme clusters for cursor management
This makes using the line editor much nicer when multi-code-point
graphemes are present in the input (e.g. flag emojis, or some cjk
glyphs), and avoids messing up the buffer when deleting text, or
cursoring around.
2023-12-16 22:11:43 +01:00
Ali Mohammad Pur
99cc0514a7 LibLine: Don't compare byte and code point counts of the input text
This commit fixes the odd state after pasting some text containing
multibyte code points.
This also increases the input buffer size, as reading 16 bytes at a time
felt slightly laggy when pasting a large number of emojis :^)
2023-12-16 22:11:43 +01:00