Commit Graph

505 Commits

Author SHA1 Message Date
Linus Groh
192f4b0258 LibWeb: Ensure lazy WindowObject creation when activating event handler 2022-03-27 20:14:25 +01:00
Timothy Flynn
5608bc4eaf LibWeb: Remove inheritance of FormAssociatedElement from HTMLElement
HTMLObjectElement will need to be both a FormAssociatedElement and a
BrowsingContextContainer. Currently, both of these classes inherit from
HTMLElement. This can work in C++, but is generally frowned upon, and
doesn't play particularly well with the rest of LibWeb.

Instead, we can essentially revert commit 3bb5c62 to remove HTMLElement
from FormAssociatedElement's hierarchy. This means that objects such as
HTMLObjectElement individually inherit from FormAssociatedElement and
HTMLElement now.

Some caveats are:

* FormAssociatedElement still needs to know when the HTMLElement is
  inserted into and removed from the DOM. This hook is automatically
  injected via a macro now, while still allowing classes like
  HTMLInputElement to also know when the element is inserted.

* Casting from a DOM::Element to a FormAssociatedElement is now a
  sideways cast, rather than directly following an inheritance chain.
  This means static_cast cannot be used here; but we can safely use
  dynamic_cast since the only 2 instances of this already use RTTI to
  verify the cast.
2022-03-24 03:35:11 +01:00
Andreas Kling
e0c7727934 LibWeb: Fill the whole viewport with the correct background color
CSS2 tells us to use the HTML element's background color if not
transparent. Otherwise, the BODY element's background color.
2022-03-23 17:38:00 +01:00
Andreas Kling
fd7a059e09 LibWeb: Make NodeIterator behave like other browser engines
If invoking a NodeFilter ends up deleting a node from the DOM, it's not
enough to only adjust the NodeIterator reference nodes in the
pre-removing steps. We must also adjust the current traversal pointer.

This is not in the spec, but it's how other engines behave, so let's do
the same.

I've encapsulated the Node + before-or-after-flag in a struct called
NodePointer so that we can use the same pre-removing steps for both the
traversal pointer and for the NodeIterator's reference node.

Note that when invoking the NodeFilter, we have to remember the node we
passed to the filter function, so that we can return it if accepted by
the filter.

This gets us another point on Acid3. :^)
2022-03-23 00:22:36 +01:00
Andreas Kling
a0b0b29fa1 LibWeb: Minor cleanups in NodeIterator and TreeWalker
- Use TRY() when invoking the NodeFilter
- Say "nullptr" instead of "RefPtr<Node> {}"
2022-03-23 00:19:57 +01:00
Andreas Kling
2fb9eb5257 LibWeb: Implement Range.deleteContents()
And here's another point on Acid3. :^)
2022-03-22 20:17:52 +01:00
Andreas Kling
e1c71b3f91 LibWeb: Implement Range.cloneContents() 2022-03-22 20:03:09 +01:00
Linus Groh
2219eef250 LibWeb: Convert Text to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
46bb547dd6 LibWeb: Convert ShadowRoot to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
a68d31debd LibWeb: Convert ParentNode to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
8d20fb1e94 LibWeb: Convert NodeOperations to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
3861396fe4 LibWeb: Convert Node to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
3cb7c463a7 LibWeb: Convert Element to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
b6f09aaef2 LibWeb: Convert DOMTokenList to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
91d0088a5b LibWeb: Convert DOMImplementation to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
e758bd303f LibWeb: Convert Document to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
ab0a354bb4 LibWeb: Convert ChildNode to use TRY for error propagation 2022-03-22 18:05:25 +00:00
Linus Groh
70b1f18e58 LibWeb: Explicitly ignore [[nodiscard]] values returned from TRY()
This broke the clang build.
2022-03-22 13:20:06 +00:00
Timothy Flynn
c3f9cd6dbd LibWeb: Convert Range to use TRY for error propagation 2022-03-22 12:09:27 +00:00
Timothy Flynn
2d34216628 LibWeb: Make DOM::ExceptionOr compatible with the TRY macro
This will help reduce the quite repetitive pattern of:

    auto result_or_error = dom_node->do_something();
    if (result_or_error.is_exception())
        return result_or_error.exception();
    auto result = result_or_error.release_value();

Similar to LibJS completions, this adds an alias to the error accessors.
This also removes the requirement on release_value() for ValueType to
not be Empty, which we also had to do for TRY compatibility in LibJS.
2022-03-22 12:09:27 +00:00
Jamie Mansfield
9b9d32dfb2 LibWeb: Fix crash when removing event listeners 2022-03-22 02:35:07 +01:00
Timothy Flynn
5133491714 LibWeb: Expose HTMLCollection's root element to its subclasses
For example, HTMLOptionsCollection will need to access its root
HTMLSelectElement.
2022-03-22 02:08:15 +01:00
Andreas Kling
8ab25f8d8c LibWeb: Implement Range.surroundContents(newParent)
Here goes another Acid3 point :^)
2022-03-21 23:28:46 +01:00
Andreas Kling
68f3feb1d1 LibWeb: Fix two spec transcription mistakes in live range updating
This scores us another point on Acid3. :^)
2022-03-21 21:11:38 +01:00
Andreas Kling
4d49c607f8 LibWeb: Fix spec transcription mistake in Range.extractContents()
The spec text and code didn't match up.

Thanks to Tim for spotting this! :^)
2022-03-21 21:01:47 +01:00
Andreas Kling
ac8a8459d0 LibWeb: Don't allow setting Range start/end to document being destroyed 2022-03-21 20:37:49 +01:00
Andreas Kling
3b6323340a LibWeb: Update live ranges on Node insertion and removal
Taking care of some old FIXMEs :^)
2022-03-21 20:26:35 +01:00
Andreas Kling
1254758b00 LibWeb: Update live DOM ranges on Text and CharacterData mutations
Taking care of the FIXMEs I added in earlier patches. :^)
2022-03-21 20:06:59 +01:00
Andreas Kling
c74b1b6d65 LibWeb: Implement Range.insertNode(node) 2022-03-21 19:14:50 +01:00
Andreas Kling
d2f9f8bd4f LibWeb: Implement Text.splitText(offset)
With FIXMEs about updating live ranges, but still.
2022-03-21 19:14:50 +01:00
Andreas Kling
8bc3f4c186 LibWeb: Fix logic mistakes in Range stringification
We were passing the wrong length argument to substring() when
stringifying a range where start and end are the same text node.

Also, make sure we visit all the contained text nodes when appending
them to the output.

This was caught by an Acid3 subtest.
2022-03-21 19:14:50 +01:00
Andreas Kling
16f4c76da6 LibWeb: Implement Range.extractContents()
Another point on Acid3 coming through! :^)
2022-03-21 18:06:28 +01:00
Andreas Kling
24e25fe3d0 LibWeb: Add CharacterData.replaceData(offset, count, data)
Note that we don't queue mutation records or update live ranges yet,
I've left those as FIXMEs.
2022-03-21 18:05:20 +01:00
Andreas Kling
e50c7de1b2 LibWeb: Add CharacterData.substringData(offset, count) 2022-03-21 17:20:42 +01:00
Andreas Kling
394cd77467 LibWeb: Implement stringifier for DOM Range :^) 2022-03-21 16:29:19 +01:00
Andreas Kling
8c88ee1165 LibWeb: Only invalidate stacking context tree for opacity/z-index change
I came across some websites that change an elements CSS "opacity" in
their :hover selectors. That caused us to relayout on hover, which we'd
like to avoid.

With this patch, we now check if a property only affects the stacking
context tree, and if nothing layout-affecting has changed, we only
invalidate the stacking context tree, causing it to be rebuilt on next
paint or hit test.

This makes :hover { opacity: ... } rules much faster. :^)
2022-03-21 13:03:33 +01:00
Andreas Kling
59afdb959f LibWeb: Build stacking context tree lazily
There's no actual need to build the stacking context tree before
performing layout. Instead, make it lazy and build the tree when it's
actually needed for something.

This avoids a bunch of work in situations where multiple synchronous
layouts are forced (typically by JavaScript) without painting or hit
testing taking place in between.

It also opens up for style invalidations that only target the stacking
context tree.
2022-03-21 13:03:33 +01:00
Simon Wanner
69fc7009bf LibWeb: Grey out invisible nodes in the DOM inspector
This makes it easier to navigate large DOM trees where
some nodes have display: none
2022-03-20 19:57:09 +01:00
Andreas Kling
07a4d590dd LibWeb: Layout browsing context parent before its children
When updating layout inside a nested browsing context, try first to
perform layout in the parent document (the nested browsing context's
container's document).

This ensures that nested browsing contexts have the right viewport
dimensions in case the parent layout changes them somehow.
2022-03-20 19:03:43 +01:00
Andreas Kling
2b7775118d LibWeb: Clear element.style when the "style" attribute is removed
We were hanging on to element inline style, even after the style
attribute was removed. This made inline style sticky and impossible to
remove. This patch fixes that. :^)
2022-03-20 16:31:40 +01:00
Andreas Kling
618b857457 LibWeb: Evaluate @media CSS rules when updating style
In case we have new @media rules, we need to make sure we've evaluated
them before actually recomputing styles for the document.
2022-03-20 16:19:47 +01:00
Andreas Kling
5d672717aa LibWeb: Add a barebones SVGTextContentElement with getNumberOfChars() 2022-03-20 13:36:45 +01:00
Andreas Kling
0b861e0c9d LibWeb: Make document-level style invalidation fast
Add a flag to DOM::Document that means the whole document needs a style
update. This saves us the trouble of traversing the entire DOM to mark
all nodes as needing a style update.
2022-03-19 22:04:43 +01:00
Andreas Kling
c1f0d21bbe LibWeb: Rename the LayoutMode enum values and explain them
The old mode names, while mechanically accurate, didn't really reflect
their relationship to the CSS specifications.

This patch renames them as follows:

    Default => Normal
    AllPossibleLineBreaks => MinContent
    OnlyRequiredLineBreaks => MaxContent

There's also now an explainer comment with the LayoutMode enum about the
specific implications of layout in each mode.
2022-03-19 15:46:15 +01:00
Andreas Kling
3b037726e9 LibWeb: Invalidate layout after setting Element.innerHTML
It's not enough to only relayout here, since the API can substantially
change the DOM. We have to rebuild the layout tree.
2022-03-18 19:54:46 +01:00
Linus Groh
9422ae9bb2 LibJS: Add infallible variant of VM::push_execution_context()
It makes no sense to require passing a global object and doing a stack
space check in some cases where running out of stack is highly unlikely,
we can't recover from errors, and currently ignore the result anyway.

This is most commonly in constructors and when setting things up, rather
than regular function calls.
2022-03-18 01:12:12 +01:00
Lenny Maiorani
c37820b898 Libraries: Use default constructors/destructors in LibWeb
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-17 17:23:49 +00:00
Andreas Kling
d71b0e4638 LibWeb: Don't discard update_style_recursively() return value
This was causing us to miss layout invalidations. With this fixed, we
can remove the invalidation from Element::recompute_style() along with
the associated FIXME.

Thanks to Idan for spotting this! :^)
2022-03-16 21:30:39 +01:00
Andreas Kling
0e8b538e0a LibWeb: Invalidate less style when moving between hovered nodes
Instead of invalidating style for the entire document, we now locate the
nearest common ancestor between the old and new innermost hovered node,
and only invalidate that ancestor and its descendants.

This drastically reduces the amount of style update work when mousing
around on GitHub (and any other pages, really.) It's actually really
really snappy now. Very cool! :^)
2022-03-16 18:06:45 +01:00
Andreas Kling
f1711a562a LibWeb: Avoid layout invalidation for some CSS property changes
Use the new CSS::property_affects_layout() helper to figure out if we
actually need to perform a full relayout after recomputing style.

There are three tiers of required invalidation after an element receives
new style: none, repaint only, or full relayout.

This avoids the need to rebuild the layout tree (and perform layout on
it) when trivial properties like "color" etc are changed.
2022-03-16 18:06:45 +01:00