Commit graph

4485 commits

Author SHA1 Message Date
Andreas Kling
093de0e323 LibGUI: Use Core::Object::set_property() to handle JSON GUI properties
Piggyback on the existing mechanism to set individual properties.
This doesn't cover layouts or child widgets, but the per-widget own
properties can be set this way.

Any property can now be set in JSON GUI, all you need to do is handle
it in the relevant Core::Object::set_property() override. :^)
2020-09-14 16:16:36 +02:00
Andreas Kling
6fc8dedd28 LibGUI: Allow setting widget visibility from JSON GUI spec 2020-09-14 16:16:36 +02:00
Andreas Kling
6590eb8eb7 LibGUI: Complain about malformed "layout" values in JSON GUI 2020-09-14 16:16:36 +02:00
Andreas Kling
aa3c28957a LibCore: Include object names in Object::dump_tree() output 2020-09-14 16:16:36 +02:00
Andreas Kling
ea17b0cbb6 LibGUI: Start building a way to instantiate GUI from JSON
My original idea for GUI building tools was to have the "VisualBuilder"
app generate C++ code which in turn programmatically instantiated UI.
That never really materialized in any useful way beyond static UIs.

This is a fresh, new approach: using JSON to declare the UI and parsing
and constructing this UI at runtime. This will allow for way more
dynamic and flexible approaches to GUI development (I think.)

The basic idea is that you pass a JSON string to Widget::load_from_json
and it takes care of the rest.

This first version supports basic box layouts and instantiation of
arbitrary widgets, as long as those widgets have been registered.

This code has some pretty rough edges right now as it's evolving and
we need to figure out a lot of things about how it should work.
Nevertheless, it feels pretty cool. :^)
2020-09-14 16:16:36 +02:00
Andreas Kling
c7133bf081 LibWeb: Register the InProcessWebView widget 2020-09-14 16:16:36 +02:00
Andreas Kling
3c580233d1 LibGUI: Improve widget registration mechanism a bit
Allow registering widgets from namespaces other than GUI. :^)
Also add a few widgets.
2020-09-14 16:16:36 +02:00
Andreas Kling
609108f6b3 LibGfx: Remove unused file FloatPoint.h 2020-09-13 21:41:45 +02:00
Andreas Kling
b78e13cf2e LibGUI: Make some GUI event getters return const references
There's no good reason to return rects/sizes/positions by value.
2020-09-13 21:41:45 +02:00
Tom
c8d9f1b9c9 Kernel: Make copy_to/from_user safe and remove unnecessary checks
Since the CPU already does almost all necessary validation steps
for us, we don't really need to attempt to do this. Doing it
ourselves doesn't really work very reliably, because we'd have to
account for other processors modifying virtual memory, and we'd
have to account for e.g. pages not being able to be allocated
due to insufficient resources.

So change the copy_to/from_user (and associated helper functions)
to use the new safe_memcpy, which will return whether it succeeded
or not. The only manual validation step needed (which the CPU
can't perform for us) is making sure the pointers provided by user
mode aren't pointing to kernel mappings.

To make it easier to read/write from/to either kernel or user mode
data add the UserOrKernelBuffer helper class, which will internally
either use copy_from/to_user or directly memcpy, or pass the data
through directly using a temporary buffer on the stack.

Last but not least we need to keep syscall params trivial as we
need to copy them from/to user mode using copy_from/to_user.
2020-09-13 21:19:15 +02:00
Nico Weber
a6734766ec Terminal: Make sure empty hrefs set a null string on Attribute
Else, we store an empty but allocated string for each Attribute after a
href was emitted (since it's ended by a non-null empty string), which
makes Line objects very expensive to destroy and to modify.

Reduces `disasm /bin/id` from 414ms to 380ms (min-of-5). There's
a lot more perf wins to be had with better href handling (most
lines don't have any hrefs, so instead of storing a string per
Attr, maybe we could have a vector of hrefs per line and int offsets
into that in each Attr for example), but this is a simple, obvious,
and effective improvement, so let's start with this.
2020-09-13 11:34:49 +02:00
Peter Nelson
d366e996dd LibGfx: restructure Bitmap ctor to expect an alloc'd backing store
Moves Bitmap backing store creation to the static create() methods.
This backing store is then passed into the Bitmap constructor. This
allows us correctly return nullptr from create() in the event that
memory allocation fails.
2020-09-12 20:26:14 +02:00
Peter Nelson
06eea59a65 LibGfx: return clone from frame() instead of underlying framebuffer
This prevents frame() from modifying the contents of the same bitmap
that was returned from previous calls to frame()
2020-09-12 20:26:14 +02:00
Peter Nelson
9494b03a02 LibWeb: cache in-process decoded images in ImageResource
Otherwise cloned Bitmaps returned by the decoder will be prematurely
freed
2020-09-12 20:26:14 +02:00
Peter Nelson
16ebbde26f LibGfx: add Bitmap::clone() method 2020-09-12 20:26:14 +02:00
Andreas Kling
f470657d57 LibWeb: Fix layout of replaced with width:auto + no intrinsic ratio
We can't compute width based on the intrinsic ratio if we have no
intrinsic ratio! The comment was correct, the code was not.
2020-09-12 18:18:20 +02:00
Andreas Kling
cd5570670c LibWeb: Implement <input type=submit> without using LibGUI
Following in the footsteps of <input type=checkbox>, this patch adds
LayoutButton which implements a basic push button using LibGfx styling
primitives.
2020-09-12 18:18:20 +02:00
Andreas Kling
94c55d9e37 LibWeb: Two mouse event handling fixes
- After letting a LayoutNode handle a mouseup, re-do the hit test
  since things may have changed.
- Make sure we always update the document's hovered node.
2020-09-12 17:55:19 +02:00
redoste
ad031ec5d7 LibWeb: Do not handle mouse events on disabled checkboxes 2020-09-12 15:00:39 +02:00
Andreas Kling
8d574c7363 LibIPC: Remove unused DisconnectedEvent mechanism
This was previously used to defer handling disconnections until the
next event loop iteration. We now achieve the same with simple use
of deferred_invoke(). :^)
2020-09-12 14:49:29 +02:00
Andreas Kling
4873e2bb53 LibIPC: Move notifier handling entirely to IPC::Connection base class 2020-09-12 14:49:29 +02:00
Andreas Kling
54116115a8 LibIPC: Remove debug spam on disconnection 2020-09-12 14:49:29 +02:00
Andreas Kling
d9e39cb82d LibWeb: Support window.alert() in multi-process context
Alerts are now delegated to the embedding GUI process.
2020-09-12 14:49:29 +02:00
Andreas Kling
aba793fb3e LibIPC: Share most of the code between {Client,Server}Connection
This patch introduces IPC::Connection which becomes the new base class
of ClientConnection and ServerConnection. Most of the functionality
has been hoisted up to the base class since almost all of it is useful
on both sides.

This gives us the ability to send synchronous messages in both
directions, which is needed for the WebContent server process.
Unlike other servers, WebContent does not mind blocking on a response
from its client.
2020-09-12 14:49:29 +02:00
Ben Wiederhake
8280dcfb89 LibC: Avoid write-back of unused value
This might make sleep() faster by up to pi nanoseconds, or less.
It's more about avoiding a senseless write than about optimization.
2020-09-12 13:46:15 +02:00
Ben Wiederhake
be1e4f28cc LibC: Don't advertise wrong functions
str{,n}casecmp is supposed to be *only* declared by strings.h, note the
trailing 's' in the filename.

We don't have any implementation for strlcat; using any strcat variants is
a bad idea anyway, given our implementation of AK::String.

TODO: Find a way to lint for declared-but-nowhere-defined functions.
2020-09-12 13:46:15 +02:00
Ben Wiederhake
0d79e57c4d Kernel: Fix various forward declarations
I decided to modify MappedROM.h because all other entried in Forward.h
are also classes, and this is visually more pleasing.

Other than that, it just doesn't make any difference which way we resolve
the conflicts.
2020-09-12 13:46:15 +02:00
Ben Wiederhake
da966ac8d8 LibMarkdown: Make warning messages conditional
This is especially a problem during fuzzing.
2020-09-12 13:46:15 +02:00
Ben Wiederhake
e3101c74c6 LibGUI: Use new Bitmap::minimum_pitch method
Also, make sure that the painter actually draws on a RGB(A) bitmap.

Closes #3460.
2020-09-12 11:35:41 +02:00
Linus Groh
568d53c9b1 LibJS: Check validity of computed_property_name() result before using it
This fixes two cases obj[expr] and obj[expr]() (MemberExpression and
CallExpression respectively) when expr throws an exception and results
in an empty value, causing a crash by passing the invalid PropertyName
created by computed_property_name() to Object::get() without checking it
first.

Fixes #3459.
2020-09-12 11:29:39 +02:00
Linus Groh
75dac35d0e LibJS: Stop unwinding and reset exception for TryStatement finalizer
This fixes two issues with running a TryStatement finalizer:

- Temporarily store and clear the exception, if any, so we can run the
  finalizer block statement without it getting in our way, which could
  have unexpected side effects otherwise (and will likely return early
  somewhere).
- Stop unwinding so more than one child node of the finalizer
  BlockStatement is executed if an exception has been thrown previously
  (which would have called unwind(ScopeType::Try)). Re-throwing as
  described above ensures we still unwind after the finalizer, if
  necessary.

Also add some tests specifically for try/catch/finally blocks, we
didn't have any!
2020-09-12 09:31:16 +02:00
Linus Groh
ec43f73b74 LibJS: Extract most of Interpreter's run() into execute_statement()
Interpreter::run() was so far being used both as the "public API entry
point" for running a JS::Program as well as internally to execute
JS::Statement|s of all kinds - this is now more distinctly separated.
A program as returned by the parser is still going through run(), which
is responsible for creating the initial global call frame, but all other
statements are executed via execute_statement() directly.

Fixes #3437, a regression introduced by adding ASSERT(!exception()) to
run() without considering the effects that would have on internal usage.
2020-09-12 09:31:16 +02:00
Ben Wiederhake
bd6390d8cb LibGfx: Validate size of incoming shared bitmap
Errors like this became more likely due to the 'optimized' memory usage.
Also, this prevents the WindowServer from being killed by a goofy program
sharing an incomplete bitmap, and likely some other scenarios.
2020-09-12 00:13:29 +02:00
Ben Wiederhake
9c3a33762b LibGfx: Saner memory usage of indexed bitmaps
Indexed bitmaps used to allocate four times the required amount of memory.

Also, we should acknowledge that the underlying data is not always RGBA32,
and instead cast it only when the true type is known.
2020-09-12 00:13:29 +02:00
Ben Wiederhake
d6673b384e LibGfx: Remove redundant bits() method
In all circumstances, this returned exactly the same thing as scanline_u8(),
so let's just remove the silly detour.

This does not add any new dependency on Bitmap-internals, because that already existed.
2020-09-12 00:13:29 +02:00
Ben Wiederhake
e550df6467 LibGfx: Don't blindly trust file-internal offset
This also touches the return type of dib_size(), because kjdsfg
2020-09-12 00:13:29 +02:00
Ben Wiederhake
a098046309 LibGfx: Nicer error reporting for bitmap allocation 2020-09-12 00:13:29 +02:00
Ben Wiederhake
52a797afdb LibGfx: Protect against over-large bitmaps 2020-09-12 00:13:29 +02:00
Ben Wiederhake
5d3c437cce LibJS: Fix start position of multi-line tokens
This broke in case of unterminated regular expressions, causing goofy location
numbers, and 'source_location_hint' to eat up all memory:

Unexpected token UnterminatedRegexLiteral. Expected statement (line: 2, column: 4294967292)
2020-09-12 00:13:29 +02:00
Andreas Kling
b62043dbca LibWeb: Protect LayoutCheckBox against crashes after event dispatch
After dispatching a "change" event due to the checked state being
modified, we may have been removed from the layout tree.

Make LayoutCheckBox protect itself to prevent this from crashing.

Also, add a little test page for checkboxes. :^)
2020-09-11 18:42:43 +02:00
Andreas Kling
71092226bd LibWeb: Dispatch a "change" event when <input> checked state changes 2020-09-11 18:42:43 +02:00
Andreas Kling
f2431adf47 LibWeb: Add basic support for <input type=checkbox>
This is implemented entirely inside LibWeb, there is no GUI::CheckBox
widget instantiated, unlike other input types. All input types should
be moved to this new style of implementation.
2020-09-11 18:42:43 +02:00
Andreas Kling
d6889ecf35 LibWeb: Allow layout nodes to receive and track mouse events
To implement form controls internally in LibWeb (necessary for multi
process forms), we'll need the ability to handle events since we can't
rely on LibGUI widgets anymore.

A LayoutNode can now override wants_mouse_events() and if it returns
true, it will now receive mousedown, mousemove and mouseup events. :^)
2020-09-11 18:42:43 +02:00
Andreas Kling
5782099106 LibWeb: Add basic support for boolean IDL attributes :^) 2020-09-11 18:42:43 +02:00
Andreas Kling
e7432efe24 LibWeb: Add the "checked" and "disabled" HTML attributes 2020-09-11 18:42:43 +02:00
Andreas Kling
1a2b626746 LibGUI+LibGfx: Move check box painting to Gfx::StylePainter
This will allow us to render check boxes from other places. :^)
2020-09-11 18:42:43 +02:00
pkotzbach
072e94caa2
LibCore: Fixed DeferredInvoke debug message (#3456) 2020-09-11 18:41:50 +02:00
asynts
5c9c0082a1 LibCompress: Move CanonicalCode out of DeflateDecompressor. 2020-09-11 16:07:45 +02:00
asynts
49e6ff8958 LibCompress: Remove unnecessary InputBitStream. 2020-09-11 16:07:45 +02:00
asynts
4af8eea56f LibCompress: Return Optional from decompress_all method. 2020-09-11 16:07:45 +02:00