Commit graph

5247 commits

Author SHA1 Message Date
Andreas Kling
70c9cfddc5 LibGfx: Fix font x-height computation
Line indices start from the top, so the baseline is a higher number
than the mean line. :^)
2020-12-06 01:01:15 +01:00
Ben Wiederhake
52a8062084 LibCore: Offer to display a general description 2020-12-06 00:06:53 +01:00
Linus Groh
886b43e999 LibLine: Don't make Editor::load_history() cut off a character per line
For some reason we were not considering the last *two* characters from
the line's ByteBuffer, with the comment next to it talking about \n and
\0. However the buffer doesn't contain a null-byte, so we were
effectively removing the newline and the last character from each
history line!
2020-12-06 00:06:46 +01:00
Ben Wiederhake
ecb16f421d LibGfx: Handle OOM slightly better
When create_with_shared_buffer() is called in the next line, the
RefPtr::operator* asserts that the RefPtr is not null. That can happen when
we're low-ish on memory, and the image is huge.
2020-12-06 00:06:05 +01:00
Andreas Kling
31a3ed70f0 LibWeb: Hit test floats using the top of lines, not middle
I don't know why basing the available space between floats on the y
coordinate in the middle of each line seemed like a good idea. It just
creates situations with a few pixels of floats overlapping text!
2020-12-05 23:54:07 +01:00
Linus Groh
a70aacd7c3 LibJS: Add Float{32,64}Array 2020-12-05 23:52:17 +01:00
Andreas Kling
04e1827864 LibWeb: Run clang-format on ReplacedBox.cpp 2020-12-05 23:41:07 +01:00
Andreas Kling
66a053da77 LibWeb: Don't subtract dubious "line spacing" from line y offsets
I'm not sure what this was trying to achieve, but it was moving all
line fragments upwards and a lot of things look a lot better if we
just stop doing that.
2020-12-05 23:17:23 +01:00
Andreas Kling
65e430eee5 LibWeb: Floating boxes follow normal containing block rules
I had guessed that floating boxes should somehow be hoisted up to the
nearest block ancestor that creates a block formatting context, but
that's just wrong. They move up to the nearest block ancestor like any
other box that's not absolutely (or fixed) positioned. :^)
2020-12-05 23:12:29 +01:00
Andreas Kling
2f38d94c70 LibWeb: Fix off-by-one when computing available space between floats
Whoops, this explains why things were not lining up correctly. :^)
2020-12-05 22:51:03 +01:00
Andreas Kling
615a4d4f71 LibWeb: First slightly naive implementation of CSS floats :^)
Boxes can now be floated left or right, which makes text within the
same block formatting context flow around them.

We were creating way too many block formatting contexts. As it turns
out, we don't need one for every new block, but rather there's a set
of rules that determines whether a given block creates a new block
formatting context.

Each BFC keeps track of the floating boxes within it, and IFC's can
then query it to find the available space for line boxes.

There's a huge hack in here where we assume all lines are the exact
line-height. Making this work with vertically non-uniform lines will
require some architectural changes.
2020-12-05 22:51:03 +01:00
Andreas Kling
11256de366 LibWeb: Add Layout::Node::is_root_element()
This returns true if the layout node corresponds to the <html> element.
2020-12-05 22:51:03 +01:00
Andreas Kling
cc14b5a6d7 LibJS: Implement a very hackish "arguments" object
We now lazily create an "arguments" array inside functions when code
tries to access it.

This doesn't follow the spec at all but still covers a lot of the
basic uses of arguments, i.e "arguments.length" and "arguments[n]"
2020-12-05 16:41:41 +01:00
Andreas Kling
e6dadd9e5b LibJS: Implement parseInt()
Here's a reasonably faithful implementation of ECMAScript 2021 18.2.5.
Some corner cases are not covered, I've left them as FIXME's in the
included unit test.

Also I had to tweak JS::Value::to_i32() to always convert infinity to
zero, which is in accordance with ToInt32 AFAICT.
2020-12-05 13:55:55 +01:00
Linus Groh
909f430612 LibJS: Move is_script_function() to Object
Every Object should be able to tell us if it is a ScriptFunction, not
only Function objects!
2020-12-05 10:05:28 +01:00
Andreas Kling
157896cc0b LibWeb: Block layout should account for vertical border space
We were not accounting for space occupied by borders when computing
the vertical (y) position of blocks. This meant that blocks with wide
top/bottom borders could bleed into each other incorrectly.

Fix this by using the combined padding+border geometry instead of just
the padding when placing blocks on the y axis.
2020-12-04 21:24:35 +01:00
Andreas Kling
c39e29d186 LibWeb: Block layout should resolve relative lengths against each box
We were incorrectly resolving relative length units (ex, em, etc.)
against the containing block in many cases. Fix this to resolve them
against the descendant box we're currently processing.
2020-12-04 21:22:49 +01:00
Andreas Kling
90b12a41c8 LibWeb: Make LineBox take incoming fragment size as floats 2020-12-04 21:06:27 +01:00
Andreas Kling
52d993cfa8 LibWeb: Expose Document.getElementsByName() to JavaScript 2020-12-04 20:47:37 +01:00
Andreas Kling
3eb07d289e LibWeb: Move border painting from Layout::Box to a free function
This will allow us to share some code between inline and non-inline
border painting.
2020-12-04 18:02:21 +01:00
Andreas Kling
169a9150cb LibWeb: Rename LayoutNode::is_root() => is_initial_containing_block()
Let's use spec language for this. :^)
2020-12-04 16:27:07 +01:00
Andreas Kling
e0809f78a9 LibWeb: Call the correct base class in InlineNode::split_into_lines() 2020-12-04 16:21:21 +01:00
Andreas Kling
2cbbab8f73 LibWeb: Compute the final border-style property before painting
Instead of doing a CSS property lookup for the line style of each
border edge during paint, we now cache the final CSS::LineStyle to use
in the Layout::BorderData.
2020-12-04 16:11:55 +01:00
Andreas Kling
88ca932fac LibWeb: Make LineBoxFragment store non-const Layout::Node&
This is more honest, since we actually const_cast these layout nodes
during inline layout anyway.
2020-12-04 15:46:58 +01:00
Julian Offenhäuser
6a83475ec5 LibVT: Auto-scroll the terminal
TerminalWidget will now automatically scroll up or down when the user
drags the mouse out of its bounds while selecting text. This happens
at a fixed speed.
2020-12-04 14:29:39 +01:00
Sahan Fernando
4062add8ed LibGUI: Optimize GUI::Variant move constructor 2020-12-03 21:53:29 +01:00
Julian Offenhäuser
d0812e9019 LibAudio: Fix parsing of WAV files from memory
The WavLoaderPlugin now loads the file header correctly when reading
from a ByteBuffer.
2020-12-03 21:52:10 +01:00
Andreas Kling
f35b406dfb LibWeb: Virtualize Layout::Node::paint_fragment()
LineBoxFragment no longer needs to care what type of layout node a
fragment refers to during paint, it can just call paint_fragment(). :^)
2020-12-03 21:46:01 +01:00
Andreas Kling
c189897e29 LibWeb: Fix wrong forward declaration of LineBox & LineBoxFragment 2020-12-03 21:45:55 +01:00
Andreas Kling
d59ec3ab85 LibWeb: Create "empty" line box fragments for inline elements
In order for inline elements (e.g <span>) to contribute padding etc.
to line boxes, we now create special "leading" and "trailing" fragments
for Layout::InlineNode and size them according to the horizontal
padding values.

The height of these fragments is taken from the tallest fragment on the
line. (Perhaps we should stop having per-fragment heights and just keep
a single height per line box, but that's a separate issue.)

In order to make things look nice, we now also adjust the height of all
fragments on a line so that nobody is shorter than the CSS line-height.
2020-12-03 21:45:51 +01:00
Andreas Kling
311e1039b5 LibWeb: Paint line box fragments during all paint phases
Fragment painting was very limited by only being called during the
foreground paint phase. We now paint fragments as part of every phase
(and the phase is passed to paint_fragment() of course!)
2020-12-03 21:45:46 +01:00
Andreas Kling
d129e68da8 LibWeb: Move PaintPhase enum out of Layout::Node
Now it's just Layout::PaintPhase instead of Layout::Node::PaintPhase.
2020-12-03 21:45:41 +01:00
Andreas Kling
d6c2a61fa1 LibWeb: Add type casting helpers for Layout::InlineNode 2020-12-03 21:45:38 +01:00
Andreas Kling
17e9a5e0c5 LibWeb: Hoist an early return in Layout::BlockBox::paint() 2020-12-03 17:17:11 +01:00
Andreas Kling
194d7d3471 LibWeb: Hack the CSS parser to handle integer values (like z-index)
We were rejecting perfectly valid z-index values like '1000' since we
were passing all CSS values through the length parser and unit-less
lengths are not valid in this context.

It's yet another hack for the ad-hoc CSS parser (its days are numbered)
but this makes the top header links on google.com actually work. :^)
2020-12-03 11:46:10 +01:00
AnotherTest
c1c5225b72 LibRegex: Fix assertion when parsing '(?'
Found by oss-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28186&q=label%3AProj-serenity
2020-12-03 10:51:56 +01:00
Andreas Kling
4fe987ba00 LibWeb: Don't layout twice for every InProcessWebView resize event
Calling Frame::set_size() already triggered a relayout, so calling
layout() again right after meant we did all the work one more time.

Not being dumb like this makes resizing significantly smoother. :^)
2020-12-02 23:50:19 +01:00
Andreas Kling
15e35b0d71 LibWeb: Layout viewport rect was lagging behind when resizing
Layout was using an outdated viewport rect that we set *after* doing
a layout due to resize. That meant that layout-in-response-to-resize
was always lagging behind the current size of the view.

The root of this problem was how Frame kept both a viewport rect
(with both scroll offset and size) and a frame size. To fix this,
only store the viewport scroll offset, and always use the frame size.
This way they can't get out of sync and the problem goes away. :^)

Fixes #4250.
2020-12-02 23:50:19 +01:00
Linus Groh
cc5be96724 LibJS: Use ArrayBuffer for typed array data
This is how the spec describes it, and it allows sharing data between
multiple typed arrays.
Typed arrays now support constructing from an existing ArrayBuffer,
and has been prepared for constructing from another typed array or
iterator as well.
2020-12-02 23:49:00 +01:00
Linus Groh
32571dfa53 LibJS: Add ArrayBuffer 2020-12-02 23:49:00 +01:00
Linus Groh
cf9da66b3e LibJS: Use Value::to_index() in typed array constructors 2020-12-02 23:49:00 +01:00
Linus Groh
eaa85969c4 LibJS: Add Value::to_{index,length,integer_or_infinity} abstract operations
We should pay more attention to using the well-defined abstract
operations from the spec rather than making up our own, often slightly
different rules. This is another step in that direction.
2020-12-02 23:49:00 +01:00
Linus Groh
6de4f1fcb3 LibJS: Add generic InvalidLength error type
We have multiple array types now, so ArrayInvalidLength has been
replaced with a generic InvalidLength.

Also fixes a small issue in the Array constructor, it should throw
RangeError for invalid lengths, not TypeError.
2020-12-02 23:49:00 +01:00
Ben Wiederhake
aec8983819 LibGfx: Accept BMP RLE of 255 repeated bytes
Previously, in the case of RLE4, parsing took suspiciously long.
What happened was that 'pixel_count' was 255, and 'i' was incremented
by *two* in each iteration, so the for-loop continued until the
entire output buffer was full, and then rejected the RLE data
as bogus.

This little diff allows pixel_count to reach 256, be greater than
pixel_count, and thus terminate the loop in the intended way.
2020-12-02 22:51:05 +01:00
Julian Offenhäuser
21977a2188 LibAudio: Allow loading sounds from memory
The Loader and WavLoaderPlugin classes now have methods for loading
from a ByteBuffer, in addition to streaming from disk.
2020-12-02 16:31:30 +01:00
Julian Offenhäuser
dff5983706 LibAudio: Move Audio::Buffer implementation into its own file 2020-12-02 16:31:30 +01:00
Julian Offenhäuser
1f47b01e3b LibAudio: Add generic Audio::Loader class
The Audio::Loader class is able to load different types of audio files
by using a generic plugin interface for all file formats. Every new
loader will have to derive from Audio::LoaderPlugin to provide a common
API.

This makes it easy to add support for more audio file formats in the future.
2020-12-02 16:31:30 +01:00
Linus Groh
0b086c759a LibJS: Move TypedArray length getter to prototype 2020-12-02 14:39:53 +01:00
Tom
f68115aba3 Taskbar: Wait on all waitable children in SIGCHLD handler
We need to call waitpid until no more waitable children are available.
This is necessary because SIGCHLD signals may coalesce into one when
multiple children terminate almost simultaneously.

Also, switch to EventLoop's asynchronous signal handling mechanism,
which allows more complex operations in the signal handler.
2020-12-02 12:57:25 +01:00
Linus Groh
ddaab598a7 LibJS: Add TypedArray.BYTES_PER_ELEMENT 2020-12-02 12:52:31 +01:00