Commit graph

626 commits

Author SHA1 Message Date
Calvin Buckley
bbee1c5b98 LibC: syslog and lots of compat stuff for it
This is an implementation of syslog with some OpenBSD extensions.
There is no syslogd support (so it only logs to dbgprintf/stderr),
but otherwise is functional.

Many weird defines are always present, because some syslog users in
the wild check for their existence.
2019-10-15 09:52:55 +02:00
Andreas Kling
7dbc13ac88 LibCore: Don't crash in IPC client/server on EAGAIN
Instead, just sched_yield() and try again. This makes the WindowServer
not fall apart whenever clients take a bit too long to respond.

Fixes #656.
2019-10-14 21:49:33 +02:00
Andreas Kling
735f02900b LibHTML: Implement basic partial style invalidation
This patch makes it possible to call Node::invalidate_style() and have
that node and all of its ancestors recompute their style.

We then figure out if the new style is visually different from the old
style, and if so do a paint invalidation with set_needs_display().
Note that the "are they visually different" code is very incomplete!

Use this to make hover effects a lot more efficient. They no longer
cause a full relayout+repaint, but only a style invalidation.
Style invalidations are still quite heavy though, and there's a lot of
room for improvement there. :^)
2019-10-14 18:33:23 +02:00
Andreas Kling
667b31746a LibHTML: Rename Document's invalidate_{style,layout}() to update_foo() 2019-10-14 17:57:06 +02:00
Andreas Kling
61ef17b87a LibHTML: Implement basic :hover pseudo-class support
This is currently very aggressive. Whenever the Document's hovered node
changes, we invalidate all style and do a full relayout.

It does look cool though. So cool that I'm adding it to the default
stylesheet. :^)
2019-10-14 17:55:04 +02:00
Andreas Kling
605a225b53 LibHTML: Parse the :link and :hover CSS pseudo-classes
We don't actually do anything with these yet, but now the values will
be there for the selector engine to look at when it feels ready. :^)
2019-10-14 17:31:52 +02:00
Andreas Kling
3309bdf722 LibHTML: Add some convenient geometry getters on LayoutNode
Add x(), y(), size() and position() and use them around the codebase.
2019-10-13 18:47:16 +02:00
Andreas Kling
aefc7f9b22 LibHTML: Use LayoutBlock::add_line_box() in LayoutBreak 2019-10-13 18:47:16 +02:00
Andreas Kling
44979ad7a5 LibHTML: Fix broken line splitting behavior in LayoutReplaced
Replaced elements will now properly create line breaks when they use up
the available horizontal space.

This fixes an issue with <img>'s lining up instead of breaking.
2019-10-13 18:47:16 +02:00
Calvin Buckley
5050f7b5ee Kernel: Use word-sized entropy as much as possible in syscall 2019-10-13 18:03:21 +02:00
Calvin Buckley
aa42f56210 LibC: add arc4random* using new getrandom syscall
Serenity is really not production ready; I shouldn't have to warn
you not to trust the RNG here. This is for compatibility with
software expecting the interface.

arc4random does expose an annoying flaw with the syscall I want
to discuss with Kling though.
2019-10-13 18:03:21 +02:00
Andreas Kling
0e61d84749 LibHTML: Run second layout pass if first layout adds/removes scrollbars
If you do a layout and it turns out that the page contents don't fit in
the viewport vertically, we add a vertical scrollbar. Since the
scrollbar takes up some horizontal space, this reduces the amount of
space available to the page. So we have to do a second layout pass. :^)

Fixes #650.
2019-10-13 16:31:31 +02:00
Andreas Kling
517e78a7e2 LibMarkdown: Emit properly formed HTML documents 2019-10-13 12:58:56 +02:00
Andreas Kling
2c035f5072 LibHTML: Split layout invalidation into style and layout invalidation
When style is invalidated (for example when an external stylesheet
finishes loading) we delete the whole layout tree and build a new one.
This is necessary since the new style information may result in a
different layout tree.

When layout is invalidated (window resized, image dimensions learned,
etc..) we keep the existing layout tree but run the layout algorithm
once again.

There's obviously lots of room for improvement here. :^)
2019-10-13 12:51:16 +02:00
Andreas Kling
49ac0c2e24 LibHTML: Move layout root from HtmlView to Document
The layout root is now kept alive via Document::m_layout_root.
This will allow us to do more layout-related things inside the inner
layer of LibHTML without reaching out to the HtmlView.

I'd like to keep HtmlView at a slightly higher level, to prevent it
from getting too complex.

This patch also fixes accidental disconnection of the layout tree from
the DOM after doing a layout tree rebuild. ~LayoutNode() now only
unsets the DOM node's layout_node() if it's itself.
2019-10-13 12:43:31 +02:00
Brandon Scott
efc2fc6888 LibGUI: Fix GMenu submenu shortcut bug.
I was encountering an entire system crash when the window server
attempted to do something with the shortcut text on a submenu. This
bug only seemed to appear when I had a lone submenu inside of a menu.
2019-10-13 08:45:49 +02:00
Calvin Buckley
ef40ebbe6d LibC: Add some wchar functions
These are basically copy and pasted from the regular string version.
Also add some more multi-byte/wide conversion stub.

libarchive wanted these. There's a lot more, but we can add them
one at a time.
2019-10-13 08:44:47 +02:00
Calvin Buckley
92953ba2f3 LibC: Add missing u_* typedefs (u_char/u_short) 2019-10-13 08:44:24 +02:00
Andreas Kling
08209cc665 LibHTML: Handle comments in the CSS parser
Turn consume_whitespace() into consume_whitespace_or_comments() and
have it swallow /* comments */ as well.
2019-10-13 00:28:15 +02:00
Andreas Kling
b083a233d8 LibHTML: Add Comment and CharacterData nodes and improve HTML parsing
This patch adds the CharacterData subclass of Node, which is now the
parent class of Text and a new Comment class.

A Comment node is one of these in HTML: <!--hello friends-->
Since these occur somewhat frequently on the web, we need to be able
to parse them.

This patch also adds a child rejection mechanism to the DOM tree.
Nodes can now override is_child_allowed(Node) and return false if they
don't want a particular Node to become a child of theirs. This is used
to prevent Document from taking on unwanted children.
2019-10-12 23:34:05 +02:00
Calvin Buckley
6d150df58a LibC: Add readdir_r for re-entrant directory reading (#648)
This is popular and in POSIX. Some duplicated code between readdir
is also unified into some static functions.
2019-10-12 22:35:23 +02:00
Tom
b0773a8ea6 AK: Add Atomic.h
Use gcc built-in atomics
2019-10-12 19:30:59 +02:00
Andreas Kling
2530378f59 LibHTML+Browser: Add debug option to draw borders around line boxes
This will be very useful when debugging line layout.
2019-10-12 15:02:53 +02:00
Andreas Kling
14f0a5943b LibC: Have perror() show the input string on the debugger as well 2019-10-12 14:47:06 +02:00
Andreas Kling
6242459c0f LibHTML: Implement the <br> element for line breaking
The <br> element will produce a special LayoutBreak node in the layout
tree, which forces a break in the line layout whenever encountered.

This patch also makes LayoutBlock use the current line-height as the
minimum effective height for each line box. This ensures that having
multiple <br> elements in a row doesn't create 0-height line boxes.
2019-10-12 13:47:49 +02:00
Andreas Kling
92b6a7a18f LibHTML: Add StyleProperties::line_height()
We currently hard-code the line height to 140% of the font glyph height
and this patch doesn't fix the hard-coding, but at least moves it out
of LayoutText and into StyleProperties where it can be re-used until
the day we go and do a proper implementation of CSS line-height. :^)
2019-10-12 13:42:58 +02:00
Andreas Kling
3cef6a5cac LibHTML: Make all element tag names lowercase for now
This is not the correct-est way of doing this, but it does make a bunch
of things simpler for now. We can revisit tag name case later on. :^)
2019-10-12 13:04:06 +02:00
Andreas Kling
35def88c8b LibHTML: Move Element construction to a separate file
We now have create_element(document, tag_name) in ElementFactory.
This will be useful for constructing new elements outside of parsing.
2019-10-12 13:02:38 +02:00
Andreas Kling
1f9c4ffd21 LibHTML: Make sure the marker has the same inline state as siblings
Or LayoutBlock will assert when trying to layout its children since
they have inconsistent inline state.
2019-10-11 23:26:25 +02:00
Andreas Kling
724754e39a LibHTML: LayoutBlock::children_are_inline() should check is_inline()
Instead of asking if the first child is not a block, ask if it thinks
it's inline.
2019-10-11 23:23:48 +02:00
Andreas Kling
f5bf8f6380 LibHTML: Add LayoutNode classes for "display: list-item" and its marker
This patch removes the hard-coded hack for "display: list-item" from
LayoutBlock and adds LayoutListItem and LayoutListItemMarker.

Elements with "display: list-item" now generate a LayoutListItem, which
may then also generate a LayoutListItemMarker if appropriate. :^)
2019-10-11 23:16:53 +02:00
Vincent Sanders
904bd3b441 Libc: make library internal includes come from private include namespace 2019-10-11 12:17:05 +02:00
Andreas Kling
06113b4ffe LibHTML+Browser: Show the number of pending resource loads
For now this is simply a counter+hook exposed by ResourceLoader and
shown in the Browser status bar.

This is not very nuanced, and it would be nice to expose more info so
we could eventually do something like a progress bar.
2019-10-10 22:07:08 +02:00
Andreas Kling
c294c97cdf LibHTML: Show a hand cursor when hovering over a clickable link :^) 2019-10-10 21:35:50 +02:00
Andreas Kling
76266862d1 LibGUI+WindowServer: Add a "Hand" cursor to the standard cursors 2019-10-10 21:35:12 +02:00
Andreas Kling
ebacef36ee LibHTML: Fix relative URL completion when document URL ends in a slash 2019-10-10 11:35:38 +02:00
Andreas Kling
796e63b34c LibHTML: Have TreeNode deref its children before deleting itself
This is definitely not the ideal ownership model here, but it's
something we'll have to iterate on as the engine grows.

At least this prevents us from leaking the entire world. :^)
2019-10-09 21:58:38 +02:00
Andreas Kling
c458327429 LibHTML: Tear down the layout tree before changing the Frame's document
We don't want to deal with document().frame() being null inside layout
tree code, so this makes sure we tear it down before the frame has a
chance to get nulled out.
2019-10-09 21:53:39 +02:00
Andreas Kling
a259832266 LibHTML: Document::detach_from_frame() should actually detach 2019-10-09 21:52:38 +02:00
Andreas Kling
159507f2a6 LibHTML: Move is_ancestor_of() from LayoutNode to TreeNode
This way it becomes available to all the different TreeNode subclasses.
2019-10-09 21:33:34 +02:00
Andreas Kling
fdbad6284c LibHTML: Implement the <blink> element
Just in time for Serenity's 1st birthday, here is the <blink> element!

This patch adds a bunch of different mechanisms to enable partial
repaints of the layout tree (LayoutNode::set_needs_display()))
It also adds LayoutNode::is_visible(), which can be toggled to prevent
a LayoutNode from rendering anything (it still takes up space though.)
2019-10-09 21:25:29 +02:00
Andreas Kling
33043941f9 LibGUI: Add GScrollableWidget::to_widget_position()
This is a complement to to_content_position() :^)
2019-10-09 21:16:49 +02:00
Andreas Kling
fc53867937 LibHTML: Add basic <!DOCTYPE> parsing and a DocumentType class
Plus, Document::fixup() will now make sure that the document always
starts with a doctype node, followed by an <html> element.
2019-10-09 20:17:01 +02:00
Andreas Kling
850955053f LibHTML: Rename Document::normalize() to fixup() and always do it
Node.normalize() is a standard DOM API that coalesces Text nodes.
To avoid clashing with that, rename it to fixup().

This patch also makes it happen automagically as part of parsing.
2019-10-09 18:54:34 +02:00
Andreas Kling
59795aab41 LibHTML: Handle CSS declarations that don't end in ';' 2019-10-09 18:42:08 +02:00
Andreas Kling
2ac190dc5f LibHTML: Collapse whitespace in LayoutText unless white-space: pre;
Before breaking the Text node contents into words, collapse all of the
whitespace into single space (' ') characters. This fixes broken
rendering of paragraphs with newlines in them. :^)
2019-10-09 16:29:35 +02:00
Sergey Bugaev
b4389ca4b0 LibC: Add a missing mbstowcs() declaration
This ensures it gets a C linkage, and so fixes the binutils build.
2019-10-09 15:06:25 +02:00
Andreas Kling
475c6d7112 LibHTML: Use ResourceLoader in HTMLLinkElement
This makes loading external stylesheets from http:// URLs work. :^)
2019-10-09 10:39:28 +02:00
Andreas Kling
75b5638f1c LibGUI: Let's say that Alt+Home is the "go home" keyboard shortcut 2019-10-08 21:45:29 +02:00
Andreas Kling
a1c8c754eb LibHTML: Fire the file:// load completion callback asynchronously
This makes it consistent with how http:// callbacks are fired.
It would probably be fine to have file:// be synchronous, but at the
same time it's nice to have consistency.
2019-10-08 19:40:48 +02:00