Commit Graph

1009 Commits

Author SHA1 Message Date
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