Commit graph

1224 commits

Author SHA1 Message Date
Andreas Kling
19144b753a LibWeb: Make StyleProperties::length_box() default to auto values
Undefined length values can default to auto in all length boxes and
we'll get the values we need. This saves us from having to deal with
undefined lengths later on in layout.

At some point we should break the style application process into
a few more formal steps, but this at least simplifies some things.
2020-12-14 10:53:40 +01:00
Andreas Kling
3c9dcec442 LibWeb: Merge Document::layout() and Document::update_layout()
There is now only Document::update_layout().
2020-12-14 10:39:57 +01:00
Andreas Kling
7b735b55e1 LibWeb: Set the encoding of HTML documents
Now that we attach the document to the frame before parsing, we have
to make sure we set the encoding on the document before parsing, or
things may not turn out well.
2020-12-13 18:21:52 +01:00
Andreas Kling
b73d0bb6c8 LibWeb: Update stale #includes for HTML/TagNames.* move 2020-12-13 17:54:40 +01:00
Andreas Kling
1eee6716e0 LibWeb: Attach DOM::Document to its frame before parsing
FrameLoader now begins by constructing a DOM::Document, and then builds
a document tree inside it based on the MIME type. For text/html we pass
control to the HTMLDocumentParser as before.

This gives us access to things like window.alert() during parsing.

Fixes #3973.
2020-12-13 17:40:48 +01:00
Andreas Kling
22c582a887 LibWeb: Make HTMLDocumentParser take an existing document
We shouldn't really be creating the document objects inside the parser,
since that makes it hard to hook up e.g JavaScript bindings early on.
2020-12-13 16:59:22 +01:00
Andreas Kling
4dbecf0b65 LibWeb: Move DOM/TagNames.* => HTML/TagNames.* 2020-12-13 15:57:09 +01:00
Andreas Kling
59afcddcfe LibWeb: Mark element style dirty on style/id attribute change too 2020-12-13 15:22:41 +01:00
Andreas Kling
294ec3b6a5 LibWeb: Mark element style dirty when class attribute changes
Fixes #4403.
2020-12-13 15:22:22 +01:00
Andreas Kling
6af55a234f LibWeb: Make DOM::Node::set_needs_style_update() schedule the update
After you mark a node as needing new style, there's no situation in
which we don't want a style update to happen, so just take care of
scheduling it automatically.
2020-12-13 15:19:42 +01:00
Andreas Kling
9d442ba606 LibWeb: Store layout box model metrics as floats
Instead of storing them as CSS::Lengths, we now store the resolved
values for margin/padding/border/offset top/right/bottom/left with
each Layout::NodeWithStyleAndBoxModelMetrics.

This simplifies a lot of code since it's no longer necessary to
resolve values before using them.
2020-12-12 21:28:29 +01:00
Andreas Kling
2b8c7faee4 LibWeb: Use the margin box of floating elements for flowing around
Inline content flows around the entire margin box of floating elements,
not just the content box.
2020-12-12 19:59:24 +01:00
Andreas Kling
66e9dde86f LibWeb: Don't place floating boxes before everything else
Instead, just handle them as we go about laying out block-level boxes.
2020-12-12 19:31:46 +01:00
Andreas Kling
ec89302fbe LibWeb: Make the ad-hoc CSS parser a little more tolerant
Just bail when encountering some unexpected character. This makes it
much more tolerable to type a stylesheet into TextEditor with live
HTML preview enabled.
2020-12-12 11:47:11 +01:00
Andreas Kling
b60801a9ba LibWeb: Apply 'min-width' and 'max-width' constraints to replaced boxes
This is definitely not 100% correct but I tried implementing the basic
algorithms described in CSS 2.2. It's good enough to render the penguin
on @linusg's homepage at the right size. :^)
2020-12-12 00:29:49 +01:00
Andreas Kling
552ba1b0a3 LibWeb: Remove some unnecessary is_replaced() checks in BFC
BFC::compute_width() has a short-circuit path for replaced elements.
2020-12-11 22:59:46 +01:00
Andreas Kling
67732df034 LibWeb: Move replaced element layout out of Layout::ReplacedBox
Replaced elements are now laid out by the current formatting context.
Since the logic is almost identical in BFC and IFC, it's implemented
by static helpers in FormattingContext.
2020-12-11 22:59:46 +01:00
Andreas Kling
e8d6691470 LibWeb: Fix inline-block width computation with no specified width
Undefined width should be treated the same as width:auto;
2020-12-11 22:59:46 +01:00
Andreas Kling
350b2c6d9e LibWeb: Use the surrounding text color as the caret color
This way you can always see the cursor as long (as you can see the text
you are editing.)
2020-12-10 11:39:47 +01:00
Linus Groh
5d77a19af5 LibWeb: Replace IDL 'void' return type with 'undefined'
From the Web IDL spec: https://heycam.github.io/webidl/#idl-undefined

[...]
undefined constant values in IDL are represented with the `undefined`
token.
[...]
Note: This value was previously spelled `void`, and more limited in how
it was allowed to be used.
2020-12-10 11:02:46 +01:00
Linus Groh
c1dfb2d883 LibWeb: Expect IDL namespace to end with semicolon
From the Web IDL spec: https://heycam.github.io/webidl/#prod-Namespace

Namespace ::
    namespace identifier { NamespaceMembers } ;
2020-12-10 11:02:46 +01:00
asynts
2981f10a5e LibWeb: Apply suggested fixes. 2020-12-09 21:05:06 +01:00
asynts
1c7a834278 LibWeb: Expose DOM::Range to JavaScript. 2020-12-09 21:05:06 +01:00
asynts
10f9c85090 LibWeb: Make DOM::Range more suitable for JS. 2020-12-09 21:05:06 +01:00
asynts
4df0eeaa3d LibWeb: Join start and end after deleting selection. 2020-12-09 21:05:06 +01:00
asynts
a94a1d9f9e LibWeb: Implement deletion of more complex selections. 2020-12-09 21:05:06 +01:00
asynts
b3d7c5bfbc LibWeb: Fix many bugs with the editing. 2020-12-09 21:05:06 +01:00
asynts
78558c9f30 LibWeb: Add support for cursor movement and delete. 2020-12-09 21:05:06 +01:00
asynts
e96faea1a2 LibWeb: Support range delection accross nodes with shared parent. 2020-12-09 21:05:06 +01:00
asynts
43dc47a494 LibWeb: Add support for range deletion. 2020-12-09 21:05:06 +01:00
asynts
bbcc5a9332 LibWeb: Move editing stuff into EditEventHandler. 2020-12-09 21:05:06 +01:00
asynts
82aac98bea IDL: Produce better error messages when parsing IDL files. 2020-12-09 21:05:06 +01:00
Linus Groh
50b76e4cc7 LibWeb: Don't allocate XMLHttpRequestConstructor twice
add_constructor() will already allocate an XMLHttpRequestConstructor and
update m_xhr_constructor accordingly, we don't have to do it ourselves.
This is now in line with how all the LibJS constructors work. Also make
the XHR constructor responsible for setting its "prototype" property
itself, for consistency and fail-proofing.
Previously we would only set it on the constructor we allocated manually
but which was then thrown away, leading to the property never being set
properly.
2020-12-09 12:49:30 +01:00
Linus Groh
5e9f6f2e2c LibWeb: Disallow construction of XMLHttpRequest without 'new'
The XMLHttpRequest interface only has a constructor and isn't supposed
to be callable as a function.
https://xhr.spec.whatwg.org/#constructors
2020-12-09 12:47:13 +01:00
Andreas Kling
5b7fb92ede LibWeb: Build the DumpLayoutTree subdirectory 2020-12-08 23:41:56 +01:00
Andreas Kling
35ad102595 LibWeb: Add missing license header to DumpLayoutTree 2020-12-08 23:41:45 +01:00
Andreas Kling
baf4c7d3f2 LibWeb: Remove an empty line from OOPWV 2020-12-08 23:40:45 +01:00
Andreas Kling
f52ce49a36 LibWeb: Add a simple DumpLayoutTree program
This loads a page and, dumps the layout tree to stdout, and exits.
2020-12-08 23:36:19 +01:00
Andreas Kling
cf646badfa LibWeb: Allow dumping layout tree into a StringBuilder 2020-12-08 23:36:19 +01:00
Andreas Kling
eda9fb13cc LibWeb+WebContent: Add on_load_finish hook to web views
This isn't entirely symmetrical with on_load_start as it will also fire
on reloads and back/forward navigations. However, it's good enough for
some basic use cases, and we can do more sophisticated notifications
later on when we need them.
2020-12-08 23:36:19 +01:00
Andreas Kling
6496895b16 LibWeb: <iframe src> same-origin check should be based on host document
We were basing the src attribute's cross-origin check on whatever was
currently loaded in the iframe, instead of the surrounding document.

Fixes #4236.
2020-12-08 17:49:02 +01:00
Andreas Kling
3852168c84 LibWeb: Compute final line box width *after* placing all fragments
We were doing this after every fragment instead of after every line.
2020-12-07 21:48:23 +01:00
Andreas Kling
56ff2c112b LibWeb: When adding inline-block fragment to line, use border box width
We were only using the content box width for inline-block fragments,
which caused them to not to claim the space needed for padding+border.
2020-12-07 21:47:13 +01:00
Andreas Kling
05e1ecb3d0 LibWeb: Uhh, scale back the default padding on <ul> and <ol> a bit
40px is a lot of padding in our small-fonted world. :^)
2020-12-07 21:37:00 +01:00
Andreas Kling
5d685c4643 LibWeb: Add padding-left to the default UA style for <ol> and <ul>
This matches what other engines do.
2020-12-07 21:17:59 +01:00
Andreas Kling
a3acbf1db2 LibWeb: Include padding+border in shrink-to-fit preferred min width 2020-12-07 21:13:41 +01:00
Andreas Kling
5a57f618ad LibWeb: Resolve width in relative length units on inline-block properly
Element-relative width units like em, ex, etc. should be resolved
against the inline block itself, not against its containing block.
2020-12-07 20:55:44 +01:00
Andreas Kling
70de5fd056 LibWeb: Simplify final line box width computation
The width of a line box is the distance from the left edge of the first
fragment to the right edge of the last fragment. We don't have to loop
over all the fragments to figure this out. :^)
2020-12-07 20:48:26 +01:00
Andreas Kling
be18ac36b2 LibWeb: Use CSS::Length::resolved_or_zero() in a few places 2020-12-07 20:46:01 +01:00
Andreas Kling
d65bebd8cf LibWeb: Cache parsed inline style of DOM elements
Instead of invoking the CSS parser every time we compute the style for
an element that has a "style" attribute, we now cache the result of
parsing the inline style whenever the "style" attribute is set.

This is a nice boost to relayout performance since we no longer hit the
CSS parser at all.
2020-12-07 20:00:27 +01:00
Andreas Kling
5b0deba49c LibWeb: Make layout tree dumps nicer
This patch removes a bunch of the less generally useful information
from layout tree dumps and puts it behind some optional bool params.
We also show layout units as integers instead of floats for now,
since fractional layout almost never happen anyway (yet) and this makes
it much easier to read.
2020-12-07 19:40:12 +01:00
Andreas Kling
253aa7aa7d LibWeb: Make document.title accessible from JavaScript :^) 2020-12-06 21:39:36 +01:00
Andreas Kling
d22512a024 LibWeb: Strip and collapse whitespace in document.title
I didn't generalize this into a helper since the HTML spec doesn't
seem to use this particular algorithm for anything else.

This makes the ACID1 test title show up correctly. :^)
2020-12-06 21:22:31 +01:00
Andreas Kling
cb04a5c52c LibWeb: Forget floating boxes once we've gone past them
Once we've generated enough lines to make it past all the floating
boxes on either side, just forget those boxes. This simplifies the
available space computation since we don't have to consider boxes
that can't vertically intersect the current line anyway.
2020-12-06 21:11:28 +01:00
Andreas Kling
9470169317 LibWeb: Floating elements should not stack horizontally after clear
After we've cleared past some floating elements, we should not keep
stacking new floats horizontally.

Instead, new floats after the clear should once again start at the
left or right edge of their containing block.
2020-12-06 21:00:04 +01:00
Andreas Kling
c953e5d98a LibWeb: Paint positioned elements after non-positioned ones
Within the same stacking context, positioned elements must be painted
after non-positioned ones.

I added a Layout::Node::for_each_child_in_paint_order() to help with
this since it's also needed for hit testing.
2020-12-06 20:05:04 +01:00
Andreas Kling
85a1bd6803 LibWeb: Add Layout::Node::is_positioned()
Any node that has a CSS position other than "static" is positioned.
2020-12-06 20:05:04 +01:00
Andreas Kling
59de4adb60 LibWeb: Pass current target box to BFC::run()
The BFC "context box" is now the outer box of the block formatting
context. Previously the context box was always the current target box,
which made it hard to reason about who was really the containing block
of whom in various places.

Note that IFC still has the containing block as its context box, this
change only affects BFC. However, to clarify the situation in IFC,
I've added a containing_block() getter than returns the context_box().
2020-12-06 20:05:04 +01:00
Andreas Kling
b638e74b68 LibWeb: Move box floatation out of normal flow layout
Layout of floating children now places the child in the normal flow and
then floats it left or right afterwards.
2020-12-06 20:05:04 +01:00
Andreas Kling
d582828040 LibWeb: Layout floating children per block instead of whole BFC at once
Instead of plowing through all the floating boxes within a BFC and
doing all the layout up front, do the children of each block as we go.
This will allow us to know the vertical position of the containing
block when placing floats.
2020-12-06 20:05:04 +01:00
Andreas Kling
6b4281c3aa LibWeb: Do floating box placement together with other boxes
I realized that we're supposed to float the boxes sideways, but not
always to y=0, so that makes it logical to share the placement logic
with other normal non-replaced blocks.

This is still pretty buggy but we're getting closer. :^)
2020-12-06 01:59:35 +01:00
Andreas Kling
af757a1659 LibWeb: Naively implement the CSS clear property
This is definitely not fully-featured, but basically we now handle
the clear property by forcing the cleared box below the bottom-most
floated box on the relevant side.
2020-12-06 01:45:51 +01:00
Andreas Kling
26a9ab7cd5 LibWeb: Floating boxes with width:auto should be shrink-to-fit 2020-12-06 01:16:45 +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
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
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
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
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
AnotherTest
d1a5b4d906 LibWeb: Complete the URL in href_setter() before trying to load it
Also note that setting an invalid URL here should raise a JS exception
(and not navigate away).
Fixes #4301.
2020-12-02 10:08:29 +01:00
Andreas Kling
7c4c706ebe LibWeb: Implement Document.getElementsByClassName()
Note that we're taking a shortcut here and returning the elements as an
Array instead of HTMLCollection. One day we'll have to bite the bullet
and deal with HTMLCollection, but not today.
2020-12-01 16:53:10 +01:00
Andreas Kling
09da5f7263 LibWeb: Hack the CSS parser to skip over UTF-8 BOM
This is a rather ugly hack that fixes CSS parsing on websites where we
get a stylesheet that starts with a BOM.
2020-12-01 16:53:10 +01:00
Andreas Kling
bbcc71fec4 LibWeb: Parse :before and :after pseudo-elements
Note that this is the old CSS2 syntax, we don't support the CSS3 syntax
just yet. Also we don't actually implement the pseudo-elements, this is
really just to make the selectors distinct from the same ones without
these pseudo-elements.
2020-12-01 16:53:10 +01:00
Linus Groh
48c19cdb06 LibJS: Remove ProxyPrototype
Proxy is an "exotic object" and doesn't have its own prototype. Use the
regular object prototype instead, but most stuff is happening on the
target object anyway. :^)
2020-12-01 09:54:37 +01:00
Andreas Kling
113da74683 LibWeb: Deallocate DOM timer ID's when the timer goes away
I left a page open overnight and it had run out of timer ID's. :^)
2020-11-30 11:40:35 +01:00
Andreas Kling
65eef944ab LibWeb: Auto-size table box height to fit all the rows
This is just a hack until we implement the full 'height' property for
tables. :^)
2020-11-29 22:39:01 +01:00
Andreas Kling
b19f62217f LibWeb: Allow inline-block boxes to have non-inline children
We were incorrectly hoisting non-inline children of inline-block boxes
to the nearest non-inline ancestor.

Since inline-block boxes are only inline on the *outside*, it's fine
for them to have non-inline children.

Eventually we should clarify these relationships by making the inside
and outside display types more explicit.
2020-11-29 22:26:54 +01:00
Andreas Kling
39c7d9f061 LibWeb: Remove margin/border/padding from inline-block available width 2020-11-29 22:00:44 +01:00
Andreas Kling
d0636291fe LibWeb: Resolve percentage width/height of inline-block boxes
Percentage lengths cannot be to_px()'ed directly, we have to resolve
them against a reference (the containing block) first.

Fixes #4248.
2020-11-29 21:27:41 +01:00
Andreas Kling
01c8765519 LibJS+LibWeb: Log JavaScript exceptions raised by web content
Instead of hiding JS exceptions raised on the web, we now print them to
the debug log. This will make it a bit easier to work out why some web
pages aren't working right. :^)
2020-11-29 16:50:32 +01:00
Andreas Kling
2dd03a4200 LibWeb: Abort event handling if underlying layout tree disappears
We didn't notice that the layout tree had disappeared after dispatching
a mousedown event, because we only checked EventHandler::layout_root()
which happily returned the *new* layout tree after a window.reload().

This patch fixes that by verifying that the frame is still showing the
same DOM's layout tree after event dispatch.

Fixes #4224.
2020-11-29 16:43:12 +01:00
Andreas Kling
4ebb57298b LibWeb: Allow building partial layout trees
We can now build partial layout trees (this happens for example when an
element's "display" property is programmatically toggled from "none" to
something else.)
2020-11-29 16:23:12 +01:00
Andreas Kling
127274fd42 LibWeb: Tweak a comment in Layout::TreeBuilder for accuracy 2020-11-29 16:23:12 +01:00
Andreas Kling
e424e4749f LibWeb: Allow <svg> layout boxes to have children
We can't say that "no replaced boxes can have children", since that
breaks SVG. Instead, let each LayoutNode decide whether it's allowed
to have children.

Fixes #4223.
2020-11-29 16:23:12 +01:00
Andreas Kling
d4b2e89875 LibWeb: Blocks can have non-block (but non-inline) parents
We were messing up the box tree for tables by hoisting cells up to
become children of the table row group (instead of the table row.)

Table rows are non-block boxes, and it's fine for them to have cell
(block) children.

Fixes #4225.
2020-11-29 12:51:54 +01:00
Andreas Kling
98f2da9834 LibJS: Rename Cell::visit_children() => Cell::visit_edges()
The GC heap is really a graph of cells, so "children" didn't quite feel
appropriate here.
2020-11-28 17:16:48 +01:00
Andreas Kling
99536449d5 LibWeb: Don't generate layout nodes for DOM inside replaced elements
Before this change, we'd show both a <canvas>, and any fallback content
inside the <canvas> for browsers that don't support <canvas>. :^)
2020-11-28 00:59:26 +01:00
asynts
83f6b8bc9a LibWeb: Two more edge cases for TreeNode::insert_before. 2020-11-27 23:23:33 +01:00
asynts
4eb23abf06 LibWeb: Update m_previous_sibling in TreeNode::insert_before. 2020-11-27 21:29:21 +01:00
Andreas Kling
024b216141 LibWeb: Don't generate a wrap() function for the Event IDL interface
We already have a wrap() in EventWrapperFactory.cpp. It would be nice
to generate that at some point but it will require a lot more work on
the wrapper generator.
2020-11-27 13:54:58 +01:00
Andreas Kling
ddbfd77e2c LibWeb: Don't put block boxes inside inlines
Inline layout nodes cannot have block children (except inline-block,
of course.)

When encountering a block box child of an inline, we now hoist the
block up to the inline's containing block, and also wrap any preceding
inline siblings in an anonymous wrapper block.

This improves the ACID2 situation quite a bit (although we still need
floats to really bring it home.)

I also took this opportunity to move all tree building logic into
Layout::TreeBuilder, to continue the theme of absolving our LayoutNode
objects of responsibilities. :^)
2020-11-26 21:22:42 +01:00
Andreas Kling
d477039abc LibWeb: Rename Layout::LayoutTreeBuilder => Layout::TreeBuilder 2020-11-25 21:27:18 +01:00
Andreas Kling
b1e75437c9 LibWeb: Keep track of the parent of each formatting context
This will allow us to find the containing block formatting context
when needed later on.
2020-11-25 21:26:58 +01:00
Luke
773df8826d LibWeb: Add the submit event to HTMLFormElement
Also adds the ability to submit from JavaScript.
2020-11-22 18:20:56 +01:00
Luke
9950270808 LibWeb: Add HTML::EventNames and UIEvents::EventNames 2020-11-22 18:20:56 +01:00
Luke
c5e15d9282 LibWeb: Expose ParentNode.{first,last}ElementChild
I needed these to write the event dispatcher test.
2020-11-22 18:20:56 +01:00
Luke
e8b3a65581 LibWeb: Make event dispatching spec-compliant
Specification: https://dom.spec.whatwg.org/#concept-event-dispatch

This also introduces shadow roots due to it being a requirement of
the event dispatcher.

However, it does not introduce the full shadow DOM, that can be
left for future work.

This changes some event dispatches which require certain attributes
to be initialised to a value.
2020-11-22 18:20:56 +01:00
Andreas Kling
e07d14f4d9 LibWeb: Fix build with DEBUG_HIGHLIGHT_FOCUSED_FRAME 2020-11-22 16:07:53 +01:00
Andreas Kling
5aeab9878e LibWeb: Rename LayoutNode classes and move them into Layout namespace
Bring the names of various boxes closer to spec language. This should
hopefully make things easier to understand and hack on. :^)

Some notable changes:

- LayoutNode -> Layout::Node
- LayoutBox -> Layout::Box
- LayoutBlock -> Layout::BlockBox
- LayoutReplaced -> Layout::ReplacedBox
- LayoutDocument -> Layout::InitialContainingBlockBox
- LayoutText -> Layout::TextNode
- LayoutInline -> Layout::InlineNode

Note that this is not strictly a "box tree" as we also hang inline/text
nodes in the same tree, and they don't generate boxes. (Instead, they
contribute line box fragments to their containing block!)
2020-11-22 15:56:27 +01:00
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
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
Andreas Kling
10b534849d LibWeb: Remove ancient HTML_DEBUG debug logging 2020-11-19 23:10:21 +01:00
Andreas Kling
adabcf24ec Everywhere: Add missing <AK/ByteBuffer.h> includes
All of these files were getting ByteBuffer.h from someone else and then
using it. Let's include it explicitly.
2020-11-15 13:11:21 +01:00
Luke
ed2689c00a LibWeb: Use standardized encoding names, add encoding attribute to document 2020-11-14 10:14:03 +01:00
Luke
1993ccb456 LibWeb: Add default values of URL and content type in document
As per this line in the specification:
Unless stated otherwise, a document’s encoding is the utf-8 encoding,
content type is "application/xml", URL is "about:blank", origin is an
opaque origin, type is "xml", and its mode is "no-quirks".

https://dom.spec.whatwg.org/#document
2020-11-13 09:51:07 +01:00
Luke
dcb21b0c3a LibWeb: Add initial implementation of document.implementation 2020-11-13 09:51:07 +01:00
Luke
3ec54448f5 LibWeb: Add contentType attribute to Document 2020-11-13 09:51:07 +01:00
Andreas Kling
81add73955 LibWeb: Make Frame point weakly to Page
This patch makes Page weakable and allows page-less frames to exist.

Page is single-owner, and Frame is multiple-owner, so it's not sound
for Frame to assume its containing Page will stick around for its own
entire lifetime.

Fixes #3976.
2020-11-12 18:29:55 +01:00
Luke
3f73b0f896 LibWeb: Add almost all obsolete but required IDL attributes
As according to https://html.spec.whatwg.org/multipage/obsolete.html
Section 16.3 "Requirements for implementations"

Not all of these attributes are included due to requiring a bit more
functionality.
2020-11-12 10:38:26 +01:00
Luke
62a74bf282 LibWeb: Advertise to servers that we support gzip encoding
We've had gzip support for a while now, but it never really got
used because we never advertised it.
2020-11-11 12:15:18 +01:00
Luke
397049aae8 LibWeb: Move innerText from DOM::Element to HTML::HTMLElement 2020-11-11 12:15:05 +01:00
Luke
bb22b04d44 LibWeb+LibJS: Add [LegacyNullToEmptyString] attribute
If specified, to_string() returns an empty string instead of "null" for
null values.
2020-11-11 12:15:05 +01:00
Tom
75f61fe3d9 AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safe
This makes most operations thread safe, especially so that they
can safely be used in the Kernel. This includes obtaining a strong
reference from a weak reference, which now requires an explicit
call to WeakPtr::strong_ref(). Another major change is that
Weakable::make_weak_ref() may require the explicit target type.
Previously we used reinterpret_cast in WeakPtr, assuming that it
can be properly converted. But WeakPtr does not necessarily have
the knowledge to be able to do this. Instead, we now ask the class
itself to deliver a WeakPtr to the type that we want.

Also, WeakLink is no longer specific to a target type. The reason
for this is that we want to be able to safely convert e.g. WeakPtr<T>
to WeakPtr<U>, and before this we just reinterpret_cast the internal
WeakLink<T> to WeakLink<U>, which is a bold assumption that it would
actually produce the correct code. Instead, WeakLink now operates
on just a raw pointer and we only make those constructors/operators
available if we can verify that it can be safely cast.

In order to guarantee thread safety, we now use the least significant
bit in the pointer for locking purposes. This also means that only
properly aligned pointers can be used.
2020-11-10 19:11:52 +01:00
Luke
e2e6b03a45 LibWeb: Add support for reflected boolean values
Also throw in some missing reflected DOMString values
2020-11-09 09:51:22 +01:00
Linus Groh
b97a900595 LibWeb: Don't attempt to create new bitmap for zero-size OOPWV
It's not possible to construct a Gfx::Bitmap with empty size. Let the
client know the new viewport rect and return before even attempting to
create new front and back bitmaps.

Also consider that we might have to paint the widget but not have a
front/back bitmap available (e.g. when only part of a scrollbar is
visible, and the inner rect is empty).
2020-11-08 17:21:11 +01:00
Andreas Kling
2d96a07b26 LibWeb: Don't assume backing store allocation succeeds on OOPWV resize
Backing store allocation can fail if the requested size is too small,
or too large. We should not crash when this happens.

Fixes #3986.
2020-11-08 16:16:03 +01:00
Andreas Kling
a49802558d LibWeb: Use the system theme's button text color for <input> buttons 2020-11-08 01:36:45 +01:00
Brendan Coles
02d6252949 LibWeb: Restrict HTML form submissions to permitted URL protocols
Form submissions to file:// URLs are now permitted only if the
submitting document is also a file:// URL and the form method is "get".

Form submissions to URLs with a http(s):// URL protocol are permitted.

Form submissions for all other URL protocols are rejected.
2020-11-07 17:57:22 +01:00
Brendan Coles
a950d3dd5f LibWeb: Reject iframing file:// URLs if document is not a file:// URL 2020-11-07 10:53:09 +01:00
Brendan Coles
a0130b55d4 LibWeb: Load favicon.ico only for http/https URLs 2020-11-07 10:05:35 +01:00
AnotherTest
060ddd2a7a AK: Really disallow making OwnPtrs from refcounted types
This looks at three things:
- if the type has a typedef `AllowOwnPtr', respect that
- if not, disallow construction if both of `ref()' and `unref()' are
  present.
Note that in the second case, if a type only defines `ref()' or only
defines `unref()', an OwnPtr can be created, as a RefPtr of that type
would be ill-formed.

Also marks a `Performance' to explicitly allow OwnPtrs.
2020-11-03 19:14:34 +01:00
Brendan Coles
3482b9b937 LibWeb: Enforce Same-Origin Policy (SOP) for XMLHttpRequest requests
`DOM::XMLHttpRequest` now checks if the requested URL has the same
`Origin` as the requesting `Document`. If the requested URL is in
violation of SOP the request is rejected and an "error" `DOM::Event`
is dispatched.
2020-11-01 10:23:08 +01:00
Linus Groh
e5ec4d35ea LibWeb: Don't use 'font-weight: lighter' for Csilla in Default.css
Base/res/fonts/CsillaThin7x10.font was renamed to
Base/res/fonts/CsillaRegular10.font in 5abc03d, breaking the default
styles of <code> and <pre>.
The font lookup should still find a font variant when a non-existent
weight is specified, but that's another issue for another day.
2020-10-31 20:52:54 +01:00
Andreas Kling
aef56159a8 LibGUI: Add Widget focus policies
Every widget now has a GUI::FocusPolicy that determines how it can
receive focus:

- NoFocus: The widget is not focusable (default)
- TabFocus: The widget can be focused using the tab key.
- ClickFocus: The widget can be focused by clicking on it.
- StrongFocus: Both of the above.

For widgets that have a focus proxy, getting/setting the focus policy
will affect the proxy instead.
2020-10-30 17:03:28 +01:00
Andreas Kling
5abc03db0d Fonts: Rename font files consistently
Font files are now all named like this:

    <Family><Weight><Size>.font

This will make it much easier/sane to perform font lookup.
2020-10-25 10:12:03 +01:00
asynts
88bca152c9 AK: Eradicate the uses of out(). 2020-10-24 12:56:25 +02:00
Andreas Kling
bf1ed34236 LibWeb: Don't send OOPWV repaint requests for views without backing
This fixes an assertion in TextEditor when changing the system theme,
since that would trigger a repaint request for the HTML preview widget
which may not have backing unless it's actually been used to perform
HTML (or Markdown) preview yet.
2020-10-24 12:30:21 +02:00
Andreas Kling
46c15276e9 LibWeb: Fix Document construction mishap in <template> element
Ref-counted objects must not be stack allocated. Make DOM::Document's
constructor private to avoid this issue. (I wish we could mark classes
as heap-only..)
2020-10-23 08:33:16 +02:00
Andreas Kling
f79e28bd65 LibWeb: Break reference cycles so DOM::Document actually gets deleted
When a document reaches ref_count==0, we will now remove all of the
descendant nodes from the document, and also break all the explicit
links (such as the currently hovered element.)

Basically, DOM nodes will keep the document alive even after the
document reaches ref_count==0. This allows JS wrappers to stay alive
and keep the document alive as well. This matches the behavior of
at least some other browsers.

This patch also adds a bunch of sanity checking assertions around
DOM teardown, to help catch mistakes in the future.

Fixes #3771.
2020-10-22 23:41:32 +02:00
Andreas Kling
018b458962 LibWeb: Make sure nodes are adopted when moving between documents
Otherwise, the "referencing node count" accounting won't be accurate,
and anything that accesses the document will be confused.
2020-10-22 23:37:17 +02:00
Andreas Kling
c67b45aa1f LibWeb: Forget frame selection when changing documents
The old selection is obviously not relevant in the new document.
2020-10-22 23:23:57 +02:00
Andreas Kling
8de743a878 LibWeb: Remove unused TreeNode::donate_all_children_to() 2020-10-22 23:14:23 +02:00
Andreas Kling
385d744989 LibWeb: Use smart pointers between DOM and Layout tree
DOM::Node now points to its LayoutNode with a WeakPtr.
LayoutNode points to its DOM::Node and DOM::Document with RefPtrs.

Layout trees come and go in response to various events, so the DOM tree
already has to deal with that. The DOM should always live at least as
long as the layout tree, so this patch enforces that assumption by
making layout nodes keep their corresponding DOM objects alive.

This may not be optimal, but it removes a lot of ambiguous raw pointer
action which is not worth accomodating.
2020-10-22 20:26:32 +02:00
Andreas Kling
5fdc8c14a6 LibWeb: Make Nodes actually ref/unref their Document
Oops, it seems like I implemented all of the "nodes keep the document
alive" mechanism except the part where the functions are actually
called. :^)

Fixes #3811.
2020-10-22 18:48:01 +02:00
Luke
4e8cb4558b LibWeb: Add initial implementation of foreign content parsing
Plus sneak in a FIXME for the list of active formatting elements
and a test for Element.namespaceURI
2020-10-22 15:24:42 +02:00
Luke
e8a9e8aed5 LibWeb: Add namespace to Element 2020-10-22 15:24:42 +02:00
Luke
efaf03e986 LibWeb: Use modern namespaces and fix clang-format comments in tag names 2020-10-22 15:24:42 +02:00
Tom
6413acd78c AK: Make Utf8View and Utf32View more consistent
This enables use of these classes in templated code.
2020-10-22 15:23:45 +02:00
Andreas Kling
5043c4a3e5 LibCore+WebServer+LibWeb: Make MIME type guesser take a StringView
This reverts my previous commit in WebServer and fixes the whole issue
in a much better way. Instead of having the MIME type guesser take a
URL (which we don't actually have in the WebServer at that point),
just take a path as a StringView.

Also, make use of the case-insensitive StringView::ends_with() :^)
2020-10-21 21:16:20 +02:00
Andreas Kling
0af2795662 LibWeb: Tear down layout trees properly
Instead of just ripping out the root of the layout tree from its RefPtr
in Document, actually go through the DOM and gather up all the layout
nodes. Then destroy them all in one swoop.

Also, make sure to do this when detaching Document from Frame,
to enforce the invariant that layout only occurs in framed documents.
2020-10-20 18:08:37 +02:00
Andreas Kling
24162127ba LibWeb: Dispatch "load" on document and window
These happen right after "DOMContentLoaded" for now, which is incorrect
since they should really wait until subresources have loaded.
However, this makes a bunch of things work already so let's do it.
2020-10-18 13:45:28 +02:00
Andreas Kling
b71c1851b7 LibWeb: Dispatch "load" event on script elements 2020-10-18 13:44:20 +02:00
Andreas Kling
b92bc9c6e5 LibWeb: Make DOM::Window into an EventTarget
This will allow us to dispatch window events.
2020-10-18 13:43:44 +02:00
Linus Groh
ac98a48177 LibWeb: Fix EventDispatcher::dispatch()
We were never wrapping and using the actual DOM::Event but instead
wrapped the *target* twice and passed it to the event listener callback,
as this value and as argument.

This unbreaks "fun demo" and "canvas path quadratic curve test" - and
event dispatching in general, of course :^)

Fixes #3721.
2020-10-15 20:40:35 +02:00
Andreas Kling
f68ed6d25b LibWeb: Make DOM Nodes keep their Document alive
In addition to being reference-counted, all nodes that are part of a
document must also keep the document alive.

This is achieved by adding a second ref-count to the Document object
and incrementing/decrementing it whenever a node is created/destroyed
in that document.

This brings us much closer to a proper DOM lifetime model, although
the JS bindings still need more work.
2020-10-11 21:52:59 +02:00
Andreas Kling
99acbbe86b LibWeb: Remove unused Document::fixup()
This was some naive fixup mechanism we used before implementing a spec
compliant HTML parser.
2020-10-11 21:24:14 +02:00
Matthew Olsson
455ce0b9c3 LibWeb: Create LayoutNodes for each SVG element
This brings the SVG API closer to the rest of LibWeb
2020-10-10 23:28:41 +02:00
Matthew Olsson
f2055bb509 LibWeb: Add a basic SVGContext object, add to PaintContext
This will be used to transmit any svg-relevant data between svg nodes.
This is prep for moving a lot of the SVG logic into Layout nodes.
2020-10-10 23:28:41 +02:00
Matthew Olsson
0b3b6310ec LibWeb: Add {before,after}_children_paint() methods
This allows layout nodes to do some setup before their children paint,
and cleanup after their children paint. This will be used for SVG
components, where their attributes (like stroke width, fill color, etc)
need to be correctly propogated to layout nodes down the line.
2020-10-10 23:28:41 +02:00
Luke
4155de2572 LibWeb: Cache the default font if we fail to find the specified font
This is a hack to stop chewing CPU on sites that use a font we don't
have and have a lot of text or changes text often.

Examples are the Serenity 2nd birthday page and the JS specification.
2020-10-10 23:25:19 +02:00
Andreas Kling
6f74eaed42 LibWeb: Don't collapse blocks into the previous sibling's padding
We were forgetting to account for the padding-bottom of the previous
relevant sibling when placing blocks vertically.
2020-10-09 21:27:34 +02:00
Andreas Kling
0aa74074dd LibWeb: Ignore non-URL values for background-image for now 2020-10-09 21:27:01 +02:00
Nico Weber
f3b4fbf01f LibWeb: In the HTML tokenizer, pretty up ON_WHITESPACE a tiny bit
No behavior change.
2020-10-09 17:40:19 +02:00
Andreas Kling
95077f9a5d LibWeb: Apply the CSS background-image property to elements
Previously we'd only pick up background-image when it was part of the
background shorthand.

CSS property application remains hackish, lots of room for improvement
in this area. :^)
2020-10-08 23:21:39 +02:00
Linus Groh
e6709e3834 LibWeb: Handle theme change event in OutOfProcessWebView 2020-10-08 23:20:52 +02:00
Linus Groh
95a6019ff0 LibWeb: Add OutOfProcessWebView::load_empty_document()
This is cheating a little bit as we don't set the document to a nullptr
as in InProcessWebView, but the observable outcome is the same. :^)
2020-10-08 23:20:52 +02:00
Linus Groh
f6af2d747e TextEditor: Replace InProcessWebView with OutOfProcessWebView 2020-10-08 23:20:52 +02:00
Linus Groh
9f3789cdc7 LibWeb: Register the OutOfProcessWebView widget 2020-10-08 23:20:52 +02:00
Linus Groh
e40135fefd LibWeb: Add OutOfProcessWebView::load_html() 2020-10-08 23:20:52 +02:00
Linus Groh
216ccaf805 LibWeb: Handle PageClient::page_did_change_title() in Frame::set_document() 2020-10-08 23:20:52 +02:00
Linus Groh
a2a603d38a LibWeb: Add FrameLoader::load_html()
This moves responsibility for parsing and loading the document
from InProcessWebView to FrameLoader, so can be re-used easily.
2020-10-08 23:20:52 +02:00
Marcin Gasperowicz
b9316474b7 LibWeb: Make h4, h5 and h6 bold
Some Markdown documents using level 4 and 5 headings were not displayed
in an eye-pleasing manner.
This patch makes those headings bold by default.
2020-10-08 09:55:54 +02:00
Andreas Kling
51dbea3a0e LibWeb: Use RefPtrs more in getElementById() and getElementsByName()
Passing around Vector<Element*> is not a great idea long-term.
2020-10-07 12:47:17 +02:00
Andreas Kling
c6c0a9abcb LibWeb: Fix build after GEMINI_DEBUG oopsie 2020-10-06 17:48:42 +02:00
Nico Weber
fa5217ff4f LibWeb: Add debug toggle for dumping gemini documents 2020-10-06 17:16:16 +02:00
Nico Weber
c8322719c6 LibWeb: Fix variable name for gemini documents 2020-10-06 17:16:16 +02:00
Luke
043b31ad9a LibWeb: Add pc CSS unit 2020-10-05 20:05:40 +02:00
Luke
9dee140a9f LibWeb: Add empty IDL bindings for current SVG elements
Nothing in them right now as the classes don't contain the IDL
methods.
2020-10-03 00:30:49 +02:00
Andreas Kling
91b49dd9d0 LibWeb: Add a PageClient callback for image context menu requests
When the user right-clicks on an image, you might want to show a
special context menu, separate from the regular link context menu.

This patch only implements enough of the functionality to get this
working in a single-process context.
2020-10-02 19:02:47 +02:00
Luke
a9335eea1c LibWeb: Add cm, in, mm and Q CSS units 2020-09-29 20:46:18 +02:00
Andreas Kling
18cff5e0be LibWeb: Implement performance.timeOrigin
This is the origin timestamp of the same monotonic clock used for the
performance.now() timestamp.

I got a little confused while implementing this, since the numbers are
very low. That's because it uses the CLOCK_MONOTONIC system clock,
which we start counting from 0 at boot. :^)
2020-09-29 18:31:07 +02:00
Andreas Kling
97d0acc5b6 LibWeb: Implement performance.now()
This patch introduces the HighResolutionTime namespace which is home to
the Performance object (exposed via window.performance)

performance.now() is currently the only function, and it returns the
number of milliseconds since the window object was constructed. :^)
2020-09-29 18:19:18 +02:00
Andreas Kling
8cb789d061 LibWeb: Remove a bunch of unnecessary <LibJS/Interpreter.h> includes 2020-09-29 17:04:16 +02:00
Andreas Kling
d3d7ea7e75 LibWeb: LoadRequest::operator==() should compare header values
It was only comparing header names. Thanks to @Sponji for noticing!
2020-09-28 17:36:55 +02:00
Andreas Kling
ceda137bf2 LibWeb: Support <form method=POST>
Use the new support for HTTP method and request body to implement basic
support for POST'ed forms. This is pretty cool! :^)
2020-09-28 11:56:26 +02:00
Andreas Kling
2946a684ef ProtocolServer+LibWeb: Support more detailed HTTP requests
This patch adds the ability for ProtocolServer clients to specify which
HTTP method to use, and also to include an optional HTTP request body.
2020-09-28 11:55:26 +02:00
Andreas Kling
cfafd4d52d LibWeb: Expand LoadRequest class to include method, headers and body
This will allow us to create more detailed requests from inside the
web engine.
2020-09-28 11:53:32 +02:00
Benoit Lormeau
f158cb27ea LibC: Remove an unneeded string.h include in ctype.h/cpp
And include string.h in the files that actually needed it
2020-09-27 21:15:25 +02:00
Andreas Kling
700cbc02ec LibWeb: Use JS::VM::call() in timer and RAF callback invocation
This removes assumptions about having an Interpreter, and also unbreaks
requestAnimationFrame which was asserting.
2020-09-27 20:31:13 +02:00
Andreas Kling
2bc5bc64fb LibJS: Remove a whole bunch of includes of <LibJS/Interpreter.h> 2020-09-27 20:26:58 +02:00
Andreas Kling
861815596f LibWeb: Bypass the JS::Interpreter when invoking JS event callbacks
Use VM::call() instead of Interpreter::call().
2020-09-27 20:26:58 +02:00
Andreas Kling
f79d4c7347 LibJS: Remove Interpreter& argument to Function::construct()
This is no longer needed, we can get everything we need from the VM.
2020-09-27 20:26:58 +02:00
Andreas Kling
340a115dfe LibJS: Make native function/property callbacks take VM, not Interpreter
More work on decoupling the general runtime from Interpreter. The goal
is becoming clearer. Interpreter should be one possible way to execute
code inside a VM. In the future we might have other ways :^)
2020-09-27 20:26:58 +02:00
Andreas Kling
1ff9d33131 LibJS: Make Function::call() not require an Interpreter&
This makes a difference inside ScriptFunction::call(), which will now
instantiate a temporary Interpreter if one is not attached to the VM.
2020-09-27 20:26:58 +02:00
Andreas Kling
6861c619c6 LibJS: Move most of Interpreter into VM
This patch moves the exception state, call stack and scope stack from
Interpreter to VM. I'm doing this to help myself discover what the
split between Interpreter and VM should be, by shuffling things around
and seeing what falls where.

With these changes, we no longer have a persistent lexical environment
for the current global object on the Interpreter's call stack. Instead,
we push/pop that environment on Interpreter::run() enter/exit.
Since it should only be used to find the global "this", and not for
variable storage (that goes directly into the global object instead!),
I had to insert some short-circuiting when walking the environment
parent chain during variable lookup.

Note that this is a "stepping stone" commit, not a final design.
2020-09-27 20:26:58 +02:00
Ben Wiederhake
08f9bc26a6 Meta+LibHTTP through LibWeb: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
Andreas Kling
96fc476107 LibWeb: Add a separate UA style sheet for documents in quirks mode
We need to make some additional tweaks to the default UA style when
displaying documents in quirks mode.
2020-09-24 10:33:33 +02:00
Andreas Kling
37c287b1d4 LibWeb: Disallow cross-origin access to <iframe>.contentDocument
With this patch, we now enforce basic same-origin policy for this one
<iframe> attribute.

To make it easier to add more attributes like this, I've added an
extended IDL attribute ("[ReturnNullIfCrossOrigin]") that does exactly
what it sounds like. :^)
2020-09-22 20:10:20 +02:00
Andreas Kling
4c1f317572 LibWeb: Add Origin::is_same(const Origin&)
Getting ready for some extremely basic same-origin policy stuff,
this initial implementation simply checks that two origins have
identical protocol, host and port.
2020-09-22 20:10:20 +02:00
Andreas Kling
b4a3537716 LibWeb: Add WindowObject::origin()
This is a convenience getter to retrieve the security origin of a DOM
window's document.
2020-09-22 20:10:20 +02:00
Andreas Kling
618dcbe405 LibWeb: Dispatch DOM "load" event on <iframe> elements 2020-09-22 20:10:20 +02:00
Andreas Kling
86a4eaca38 LibWeb: Rename HTMLIFrameElement::hosted_frame() => content_frame()
This matches the standard API names contentWindow and contentDocument.
2020-09-22 20:10:20 +02:00
Andreas Kling
4a8bfcdd1c LibJS: Move the current exception from Interpreter to VM
This will allow us to throw exceptions even when there is no active
interpreter in the VM.
2020-09-22 20:10:20 +02:00
Andreas Kling
1c43442be4 LibJS+Clients: Add JS::VM object, separate Heap from Interpreter
Taking a big step towards a world of multiple global object, this patch
adds a new JS::VM object that houses the JS::Heap.

This means that the Heap moves out of Interpreter, and the same Heap
can now be used by multiple Interpreters, and can also outlive them.

The VM keeps a stack of Interpreter pointers. We push/pop on this
stack when entering/exiting execution with a given Interpreter.
This allows us to make this change without disturbing too much of
the existing code.

There is still a 1-to-1 relationship between Interpreter and the
global object. This will change in the future.

Ultimately, the goal here is to make Interpreter a transient object
that only needs to exist while you execute some code. Getting there
will take a lot more work though. :^)

Note that in LibWeb, the global JS::VM is called main_thread_vm(),
to distinguish it from future worker VM's.
2020-09-20 19:24:44 +02:00
Andreas Kling
c6ae0c41d9 LibWeb: Add Bindings::ScriptExecutionContext
This will be inherited by documents and workers, to provide a common
abstraction for script execution. (We don't have workers yet, but we
might as well make this little space for them now to simplify things
down the road.)
2020-09-20 19:22:44 +02:00
Andreas Kling
e2f32b8f9d LibCore: Make Core::Object properties more dynamic
Instead of everyone overriding save_to() and set_property() and doing
a pretty asymmetric job of implementing the various properties, let's
add a bit of structure here.

Object properties are now represented by a Core::Property. Properties
are registered with a getter and setter (optional) in constructors.
I've added some convenience macros for creating and registering
properties, but this does still feel a bit bulky. We'll have to
iterate on this and see where it goes.
2020-09-15 21:46:26 +02:00
Andreas Kling
c7133bf081 LibWeb: Register the InProcessWebView widget 2020-09-14 16:16:36 +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
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
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
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
5872cb398c LibWeb: Use widget override cursors 2020-09-11 14:28:05 +02:00
Andreas Kling
b4f307f982 LibGUI+WindowServer: Rename window "override cursor" to just "cursor"
Let's just say each window has a cursor, there's not really overriding
going on.
2020-09-11 14:26:37 +02:00
Andreas Kling
0f9be82826 LibGfx: Move StandardCursor enum to LibGfx
This enum existed both in LibGUI and WindowServer which was silly and
error-prone.
2020-09-10 19:25:13 +02:00
Jakob-Niklas See
dcc2c8a125
LibWeb: Add support for viewport-relative length units (#3433)
We can now use vh, vw, vmax and vmin as length units in CSS.
2020-09-08 20:39:09 +02:00
Simon Danner
9648bf4ada LibWeb: SVG: implement SmoothQuadraticBezierCurve
For this we need to track the control point of the previous command and
calculate a new control point based on it.
2020-09-08 13:57:18 +02:00
Simon Danner
772fcba814 LibWeb: SVG: draw commands can also be repeated after a comma
Consume comma or whitespace to make it possible to also parse commands
that use comma separation.
2020-09-08 13:57:18 +02:00
Simon Danner
6e61532e06 LibWeb: SVG: T commands only take two coordinates
The shortcut for Bezier curves only takes two coordinates.
2020-09-08 13:57:18 +02:00
Simon Danner
05be6481b7 LibWeb: make it possible to directly load .svg files
Make LibWeb load svg files by guessing the svg mime type from the file
extension and parsing it with the HTML parser.
2020-09-08 13:57:18 +02:00
Andreas Kling
8a6a9a8fb6 LibWeb: Move DOM event dispatch to its own class
For now, the new DOM::EventDispatcher is very simple, it just iterates
over the set of listeners on an EventTarget and invokes the callbacks
as it goes.

This simplifies EventTarget subclasses since they no longer have to
implement the callback mechanism themselves.
2020-09-06 14:48:14 +02:00
Andreas Kling
51146e3075 LibGUI: Make the Clipboard API deal in raw byte buffers a bit more
To open up for putting not just text/plain content on the clipboard,
let's make the GUI::Clipboard API a bit more raw-data-friendly. :^)
2020-09-05 16:16:01 +02:00
Luke
124c52b3b5 LibWeb: Implement document ready state 2020-08-31 23:05:51 +02:00
Luke
8aabec1c94 LibWeb: Expose window.self and window.frames
"self" is a way to refer to the global object that will work in both
a window context and a web worker context.

"frames" apparently used to return a list of frame objects according
to MDN, but it now just returns the window object.
2020-08-31 23:05:10 +02:00
Andreas Kling
a8d52a68f6 LibWeb: Take care of a FIXME in the "in table text" insertion mode 2020-08-31 18:51:34 +02:00
Linus Groh
16da91b7e7 LibWeb: Remove redundant .prettierrc
Now that LibJS's .prettierrc has been moved to the repository root (as
we start having .js files in /res), we don't need to keep a second,
identical copy for the LibWeb tests.
2020-08-30 17:31:08 +02:00
Ben Wiederhake
d8e22fedc3 Libraries: Unbreak building with extra debug macros 2020-08-30 09:43:49 +02:00
Andreas Kling
9f2338a5f5 LibWeb: Turn the <table height> attribute into the CSS height property
This matches what other engines do.
2020-08-26 21:17:05 +02:00
Andreas Kling
e3bfe0b509 LibWeb: Fix sometimes missing text selection highlight
There's no selection if it starts and ends at the same column, but only
if both columns are in the same node. :^)
2020-08-26 21:00:26 +02:00
AnotherTest
394e4c04cd LibJS: Add a helper for calling JS::Function's with arguments
The fact that a `MarkedValueList` had to be created was just annoying,
so here's an alternative.
This patchset also removes some (now) unneeded MarkedValueList.h includes.
2020-08-26 08:45:01 +02:00
Rewi Haar
521e730df1 LibWeb: Calculate selection based on glyph centers
Previously you had to drag all the way to the end of a glyph to select
it; now you just need to drag past the center.  Also fixes #2959.
2020-08-26 08:44:31 +02:00