Commit graph

14270 commits

Author SHA1 Message Date
Andreas Kling
f358f2255f LibWeb: Rename LayoutNode::node() => LayoutNode::dom_node() 2020-11-22 14:46:36 +01:00
Andreas Kling
85859544fa LibWeb: Run clang-format on FormattingContext.h 2020-11-22 14:40:55 +01:00
Andreas Kling
e1a24edfa9 LibWeb: Reorganize layout system in terms of formatting contexts
This is a first (huge) step towards modernizing the layout architecture
and bringing it closer to spec language.

Layout is now performed by a stack of formatting contexts, operating on
the box tree (or layout tree, if you will.)

There are currently three types of formatting context:

- BlockFormattingContext (BFC)
- InlineFormattingContext (IFC)
- TableFormattingContext (TFC)

Document::layout() creates the initial BlockFormattingContext (BFC)
which lays out the initial containing block (ICB), and then we recurse
through the tree, creating BFC, IFC or TFC as appropriate and handing
over control at the context boundaries.

The majority of this patch is just refactoring the old logic spread out
in LayoutBlock and LayoutTableRowGroup, and turning into these context
classes instead. A lot more cleanup will be needed.

There are many architectural wins here, the main one being that layout
is no longer performed by boxes themselves, which gives us much greater
flexibility in the outer/inner layout of a given box.
2020-11-22 14:36:56 +01:00
Andreas Kling
00aac65af5 Base: Unbreak the "images" HTML test page 2020-11-22 13:48:43 +01:00
Andreas Kling
1e92081546 LibWeb: Avoid some heap churn during text splitting
Use Vector capacity while splitting text into chunks (to avoid many
small heap allocations.)
2020-11-22 13:48:43 +01:00
Lenny Maiorani
7d8a9bdb1e AK: Cleanup missing includes and #ifdef evaluation
Problem:
- Several files have missing includes. This results in complaints from
  `clang-tidy`.
- `#ifdef` is followed by `#elif <value>` which evaluates to `0`.

Solution:
- Add missing includes.
- Change to `#elif defined(<value>)`.
2020-11-22 11:35:53 +01:00
Luke
bbc0487ced LibJS: Fix build with VM_DEBUG defined 2020-11-22 11:35:13 +01:00
Lenny Maiorani
840c3b501d NeverDestroyed: Add tests
Problem:
- It is difficult to refactor because there are no tests to bind the
functionality.
- Arguments are not forwarded correctly to the constructor.

Solution:
- Add tests.
- Change constructor to take forwarding references.
2020-11-22 10:54:33 +01:00
Simon Danner
bc5b8223b7 SoundPlayer: Add pledge for thread so file chooser doesn't crash
- Without thread pledge, SoundPlayer crashes when generating thumbnails
- Fixes #4121
2020-11-22 10:53:58 +01:00
Simon Danner
09b095e62a UserspaceEmulator: Add support for watch_file 2020-11-22 10:53:58 +01:00
Lenny Maiorani
178190ab52 MACAddress: Use all_of to implement is_zero
Problem:
- `is_zero()` is implemented by checking each value in the array by
  hand. This is error-prone and less expressive than using an
  algorithm.

Solution:
- Implement `is_zero()` in terms of `all_of`.
2020-11-21 19:25:14 +01:00
Lenny Maiorani
6e7e16a7ed AK: Implement generic all_of algorithm
Problem:
- Raw loops are often written to validate that all values in a
  container meet a predicate, but raw loops are not as expressive as
  functions implementing well-named algorithms and are error-prone.

Solution:
- Implement a very generic form of `all_of`.
2020-11-21 19:25:14 +01:00
Lenny Maiorani
446a19ba51
test-crypto: Remove foo.response file created by testing (#4110)
Problem:
- Test creates a file and leaves it in the source tree.

Solution:
- Remove the creation of the file since it is never checked.
2020-11-20 21:18:43 +01:00
Lenny Maiorani
bdf3baa8ac MACAddress: AK::Array as member variable instead of C-array
Problem:
- C-style arrays do not automatically provide bounds checking and are
  less type safe overall.
- `__builtin_memcmp` is not a constant expression in the current gcc.

Solution:
- Change private m_data to be AK::Array.
- Eliminate constructor from C-style array.
- Change users of the C-style array constructor to use the default
  constructor.
- Change `operator==()` to be a hand-written comparison loop and let
  the optimizer figure out to use `memcmp`.
2020-11-20 21:18:14 +01:00
Nico Weber
700fe315cf LibGfx: Make some GIFLoader magic numbers a bit less magic
No behavior change.
2020-11-20 21:17:58 +01:00
Nico Weber
967c82c1be LibGfx: Put GIFLoader logging behind GIF_DEBUG 2020-11-20 21:17:58 +01:00
Nico Weber
ebfc21509a LibGfx: De-constexpr Gamma.h
__builtin_sqrtf() isn't constexpr in clang.
2020-11-20 21:17:58 +01:00
Nico Weber
f13a38aa4d Lagom: Add a gif loader fuzzer 2020-11-20 21:17:58 +01:00
Andreas Kling
10b534849d LibWeb: Remove ancient HTML_DEBUG debug logging 2020-11-19 23:10:21 +01:00
Zac
6a569bbdd7 TextEditor: Change cursor behaviour when clicking empty space
When clicking empty space (beneath any used lines) in the TextEditor,
the cursor would jump to the start of the last line, rather than the
correct column, or the end of the line where appropriate. This was
because in the for_each_visual_line callback would return
IterationDecision::Continue if the clicked point wasn't in the line's
rect. Thus the callback would continue on each iteration and at the
end, would set the cursor to the default column of 0. To fix this I
added a bool to the callback's signature which tells the callback if
the for_each_visual_line method is on the last visual line. The
callback now does not return IterationDecision:Continue if
for_each_visual_line method is on the last line and the correct column
is then calculated with the line passed.
2020-11-19 21:59:13 +01:00
Andreas Kling
f72f4c5bca LibGUI: Remove AbstractTableView::doubleclick_event()
This work is already done (and more correctly) by the parent class
(AbstractView) if we just let it take care of the event instead.

Fixes the root cause of #4096.
2020-11-19 21:57:05 +01:00
Andreas Kling
da413a464a UserspaceEmulator: Inline some very hot functions
This improves the browser's load time on welcome.html by ~2%.
2020-11-19 21:46:01 +01:00
Sahan Fernando
1b9a85e4f1 LibGfx: Use gamma-corrected interpolation for color gradients
Switch over to gamma-aware interpolation. This causes color gradients
to not look so dark in the middle. SIMD optimized code is provided for
sse1 enabled builds.

Fixes #1342.
2020-11-19 21:24:20 +01:00
Nico Weber
7042490e41 LibGfx: Bounds check component indices before using them in JPGLoader
With this, I don't see any crashes in 10 min of fuzzing (but still
get OOMs).
2020-11-19 21:21:45 +01:00
Nico Weber
a8318b15a7 LibGfx: Check for read failures after every read in jpg loader
This doesn't fix all the issues found by the fuzzer, but it fixes
many of them. When running this

    Meta/Lagom/Fuzzers/FuzzJPGLoader -jobs=24 -workers=24 \
        ../Base/res/html/misc/jpgsuite_files/

for 10 minutes on my machine, the fuzzer foudn 2 crashers, but after
this change it finds just ... 2. But with different stacks!

This just fixes ASSERT()s, so it's not security critical, but
ASSERT()s still crash the programs decoding JPGs, and crashing
less is nice even if it's not a security concern.
2020-11-19 21:21:45 +01:00
Nico Weber
129a0666cb LibGfx: Put remaining jpg logging behind JPG_DEBUG
...except for one happy-case log line which is removed wholesale.
2020-11-19 21:21:45 +01:00
Nico Weber
3749e167b4 LibGfx: Move JPGLoader to a more regular JPG_DEBUG macro as used elsewhere 2020-11-19 21:21:45 +01:00
Nico Weber
812892ef86 Lagom: Add a jpg fuzzer 2020-11-19 21:21:45 +01:00
Nico Weber
3f3a7d128b Lagom: Make fuzzer cmake less repetitive 2020-11-19 21:21:45 +01:00
Nico Weber
f5967c4745 Lagom: Add a PPM fuzzer
It finds the problem fixed in 69518bd178 but nothing else.
2020-11-19 14:04:35 +01:00
Nico Weber
9ea709e1f3 LibGfx: Put PPM logs behind (default-off) PPM_DEBUG 2020-11-19 14:04:35 +01:00
Lenny Maiorani
964d2e0dd0 MACAddress: constexpr support
Problem:
- `MACAddress` class is not usable in a compile-time context.
- `__builtin_memcpy` is not constexpr in gcc.

Solution:
- Decorate functions with `constexpr` keyword.
- Use default constructors and destructors.
- Change `__builtin_memcpy` to a hand-written `for` loop and let the
  compiler's optimizer take care of it.
- Add tests to ensure compile-time capabilities.
2020-11-19 14:03:47 +01:00
Andreas Kling
0e132d345f LibX86: Pack the Instruction data structure
This patch shrinks X86::Instruction from 56 to 28 bytes by packing data
members more tightly and removing some entirely.

There is still some data duplication between Instruction and the
corresponding InstructionDescriptor but it will be a bit tricky to get
much more out of it.

This looks like a 1-2% improvement on general emulation speed. :^)
2020-11-17 17:09:49 +01:00
AnotherTest
4c343c5f26 AK: Fix OOB access in DuplexMemoryStream::offset_of()
This fixes an OOB access when the last read/written chunk is empty (as we _just_
started on a new chunk).
Also adds a test case to TestMemoryStream.
Found via human fuzzing in the shell:
```sh
for $(cat /dev/urandom) {
    clear
    match $it {
        ?* as (x) {
            echo $x
            sleep 1
        }
    }
}
```
would assert at some point.
2020-11-17 17:07:39 +01:00
ry755
b1fb8e3741 LibM: Define some floating point classification macros
This adds a few macros used to determine the category of a floating
point number. This fixes a build error with the jq port due to the
previously missing isnormal() macro.

Co-authored-by: Lua MacDougall <luawhat@gmail.com>
2020-11-17 09:57:06 +01:00
Zac
7ef8835e5a
ClipboardHistoryModel: Prevent duplicate rows (#4073)
Prevents the adding of items to the ClipboardHistoryModel if the raw
data and mime_type of the item being added is the same as another item
already in the list.
2020-11-17 09:50:39 +01:00
Linus Groh
d6a4c0c79e AK: Trim whitespace in StringUtils::convert_to_{int,uint,uint_from_hex}()
Personally I found this unintuitive at first, but it is in line with
strtol(), Python's int() or JavaScript's parseInt(), so I guess it makes
sense.

Fixes #4097.
2020-11-17 09:48:35 +01:00
Lenny Maiorani
0cb16ffe08 Shell: Remove unused private member and includes
Problem:
- Clang reports unused private member warning in the `Shell::Formatter`.
- Vector is not used in the `Shell::Formatter`.

Solution:
- Remove unused private member variable.
- Remove unused includes.
2020-11-17 09:48:02 +01:00
Lenny Maiorani
fd97f23cef MACAddress: Unit testing for basic functionality
Problem:
- There are no unit tests for `MACAddress` class. This makes it
  difficult to refactor and ensure the same behavior.
- `m_data` private member variable is uninitialized leading to undefined
  behavior of `is_zero()`.

Solution:
- Add unit tests to cover basic functionality.
- Initialize `m_data`.
2020-11-17 09:47:50 +01:00
Spencer Dixon
f23d9a73aa Userland: Add -v verbose flag to 'rm' 2020-11-17 09:40:03 +01:00
Spencer Dixon
2dab9d4bac Userland: Add -v verbose flag to 'mv' 2020-11-17 09:40:03 +01:00
Spencer Dixon
7ba28b5b0b Userland: Add -v verbose flag to 'cp' 2020-11-17 09:40:03 +01:00
Andreas Kling
fe79b9ff94 LibC: Notify UE at the start of free() instead of at the end
This way, if we end up deallocating an entire ChunkedBlock, UE doesn't
get confused thinking the freed pointer has never been allocated.
2020-11-16 15:11:02 +01:00
Andreas Kling
1965fc5b98 UserspaceEmulator: Keep Emulator& closer to the action in some places
This avoids the cost of calling Emulator::the() in some very hot paths.
2020-11-16 15:11:02 +01:00
Andreas Kling
d14695f823 UserspaceEmulator: Cache the region we're executing code from
Instead of caching a raw pointer to the next instruction, cache the
region we're fetching instructions from, and a pointer to its base.
This way we don't need to keep invalidating and reloading the cache
whenever the CPU jumps.
2020-11-16 15:11:02 +01:00
Andreas Kling
b4ff85f138 UserspaceEmulator: Reduce malloc thrashing in backtrace capture 2020-11-16 15:11:02 +01:00
Andreas Kling
e1f617950e UserspaceEmulator: Make big malloc block lookup O(1) as well
By passing the Region& to the auditing functions, we know exactly which
block we are hitting. This allows us to track big mallocations the same
way we already do chunked ones.

This gets rid of the O(n) scan in find_mallocation() for allocations
larger than the maximum malloc chunk size. :^)
2020-11-16 15:11:02 +01:00
Andreas Kling
8d9dd4c518 UserspaceEmulator: Make Region a top-level class 2020-11-16 15:11:02 +01:00
AnotherTest
de4061ff94 LibTLS: Count the mac size towards the packet length in CBC mode
This is a regression introduced in 1172746, where the padding would be
done without accounting for the added MAC bytes.
Fixes #4098.
2020-11-16 13:21:18 +01:00
Lenny Maiorani
2a06b026ef Vector: C++20 equality operators
Problem:
- C++20 changes the way equality operators are generated. This results
  in overload ambiguity as reported by clang.

Solution:
- Remove `AK::Vector::operator!=` because it will be automatically
  generated in terms of `AK::Vector::operator==`.
- Change `AK::Vector::operator==` to be a function template so that
  overload resolution is not confused about `a == b` vs `b == a`.
- Add tests to ensure the behavior works.

Notes:
- There is more info available at
  https://brevzin.github.io/c++/2019/07/28/comparisons-cpp20/ for
  deeper discussion about overload resolution, operator rewriting, and
  generated functions.
2020-11-16 10:06:23 +01:00