Commit Graph

258 Commits

Author SHA1 Message Date
Egor Ananyin
fe544feb17 LibWeb: Start parsing font property 2021-04-13 22:04:25 +02:00
Linus Groh
e4b3591ac4 LibWeb: Fix a TODO in the adoption agency algorithm
There's still a much bigger one at the end of the function though. :^)
2021-04-13 21:59:55 +02:00
Andreas Kling
a2baab38fd Everywhere: It's now "Foobar", not "FooBar", and not "foo bar"
I hereby declare these to be full nouns that we don't split,
neither by space, nor by underscore:

- Breadcrumbbar
- Coolbar
- Menubar
- Progressbar
- Scrollbar
- Statusbar
- Taskbar
- Toolbar

This patch makes everything consistent by replacing every other variant
of these with the proper one. :^)
2021-04-13 16:58:15 +02:00
Egor Ananyin
86290c0e4e LibWeb: Set border width to zero if style is none 2021-04-12 17:47:59 +02:00
Egor Ananyin
d5eb09adc2 LibWeb: Parse border-style correctly 2021-04-12 17:47:59 +02:00
Linus Groh
da177c6517 LibJS: Make Errors fully spec compliant
The previous handling of the name and message properties specifically
was breaking websites that created their own error types and relied on
the error prototype working correctly - not assuming an JS::Error this
object, that is.

The way it works now, and it is supposed to work, is:

- Error.prototype.name and Error.prototype.message just have initial
  string values and are no longer getters/setters
- When constructing an error with a message, we create a regular
  property on the newly created object, so a lookup of the message
  property will either get it from the object directly or go though the
  prototype chain
- Internal m_name/m_message properties are no longer needed and removed

This makes printing errors slightly more complicated, as we can no
longer rely on the (safe) internal properties, and cannot trust a
property lookup either - get_without_side_effects() is used to solve
this, it's not perfect but something we can revisit later.

I did some refactoring along the way, there was some really old stuff in
there - accessing vm.call_frame().arguments[0] is not something we (have
to) do anymore :^)

Fixes #6245.
2021-04-12 09:38:57 +02:00
Luke
9ec4defdd2 LibWeb: Add Window.parent and fix Window.top attributes
This returns the parent frame of the current frame. If it's the
main frame, it returns itself.

Also fixes the attributes of Window.top, as they were accidentally
being passed in as the setter.

Required by Web Platform Tests.
2021-04-12 09:01:08 +02:00
Luke
83d2c3f2f5 LibWeb: Move element_child_count to ParentNode and add its IDL attribute
I initially had it in Node just because, but then saw it was part of
ParentNode in the spec.
2021-04-11 18:32:42 +02:00
Luke
fc9abee84b LibWeb: Add Event.initEvent
Used by YouTube after creating an event with Document.createEvent
2021-04-11 18:27:52 +02:00
Luke
8da14bf880 LibWeb: Add support for optional default values and optional bools in IDL
Fixed the DOMException constructor as it had the default value version
commented out.
2021-04-11 18:27:52 +02:00
Timothy Flynn
4152f807bc LibWeb: Store cookies sent via the Set-Cookie HTTP header
Note: HTTP response headers are currently stored in a hash map, so the
Set-Cookie entry will only appear once here.
2021-04-11 18:24:34 +02:00
Timothy Flynn
1ef48d50ff LibWeb+WebContent: Hook document.cookie to the backend cookie storage 2021-04-11 18:24:34 +02:00
Timothy Flynn
e54837add5 Browser+LibWeb: Add hooks for getting and setting cookies 2021-04-11 18:24:34 +02:00
Andreas Kling
54cd8dfc4d LibWeb+WebContent: Support image context menus in OOPWV
You can now right-click images in web content and get a context menu.
2021-04-11 16:49:25 +02:00
Brian Gianforcaro
c4226ca646 LibWeb: Remove trailing ';' from WrapperGenerator functions. 2021-04-11 12:50:33 +02:00
Brian Gianforcaro
988c23fff0 LibWeb: Add implementation of Node.compareDocumentPosition()
While looking into getting Duck Duck Go loading further in the
Browser, I noticed that it was complaining about the missing
method Node.compareDocumentPosition.

This change implements as much of the DOM spec as possible
with the current implementation of the DOM to date. The
implementation is validated by new tests in the Node.js.
2021-04-11 09:40:06 +02:00
Brian Gianforcaro
0f8932d7ab LibWeb: Connect existing implementation of Node::is_connected to JS.
I was looking at implementing something else, and saw this was low
hanging fruit, that brings the browser closer to standards conformance.

Add a basic test as well to validate it's implementation.
2021-04-11 09:40:06 +02:00
AnotherTest
a6e4482080 AK+Everywhere: Make StdLibExtras templates less wrapper-y
This commit makes the user-facing StdLibExtras templates and utilities
arguably more nice-looking by removing the need to reach into the
wrapper structs generated by them to get the value/type needed.
The C++ standard library had to invent `_v` and `_t` variants (likely
because of backwards compat), but we don't need to cater to any codebase
except our own, so might as well have good things for free. :^)
2021-04-10 21:01:31 +02:00
Linus Groh
d8d16dea95 LibWeb: Add a basic implementation of Document.createEvent()
This is a legacy function providing a way of constructing events without
using their constructors exposed on the global object.
We don't have many of the events it supports yet, nor can we throw a
DOMException from it, so that's two FIXMEs for later.
2021-04-10 21:00:04 +02:00
Linus Groh
9d2635d94b LibWeb: Support nullable EventListener parameters in WrapperGenerator
The internal C++ function will now receive a RefPtr<EventListener> for
'EventListener?' and a NonnullRefPtr<EventListener> for 'EventListener'.

Examples of this are addEventListener() and removeEventListener(), which
both have nullable callback parameters.
2021-04-10 21:00:04 +02:00
Andreas Kling
2f9321a0d4 LibWeb: Implement window.top
This simply returns the main frame's window object. If accessed inside
the main frame, it will return itself.
2021-04-07 11:19:51 +02:00
Luke
d215578f55 LibWeb: Implement "select" portion of reset_the_insertion_mode_appropriately
Required by Dromaeo. With this, it no longer crashes.
2021-04-06 23:47:05 +02:00
Luke
b82a00d657 LibWeb: Use the new "ensure_pre_insertion_validity" in the HTML document parser
Previously we didn't check if we could insert the element in the
adjusted insertion location's parent.

Also makes the return type NonnullRefPtr, as that's what element is.
2021-04-06 21:42:00 +02:00
Luke
5beacf08a2 LibWeb: Make the node mutation algorithms more spec compliant
The mutation algorithms now more closely follow the spec and
fixes some assertion failures in tests such as Acid3 and Dromaeo.

The main thing that is missing right now is passing exceptions to the
bindings layer. This is because of issue #6075. I spent a while trying
to work it out and got so frustrated I just left it as a FIXME. Besides
that, the algorithms bail at the appropriate points.

This also makes the adopting steps in the document more spec compliant
as it's needed by the insertion algorithm. While I was at it, I added
the adoptNode IDL binding.

This adds a bunch of ancestor/descendant checks to TreeNode as well.
I moved the "remove_all_children" function to Node as it needs to use
the full remove algorithm instead of simply removing it from
the child list.
2021-04-06 21:42:00 +02:00
Luke
5b5d7857e3 LibWeb: Support the "ImplementedAs" IDL attribute on functions 2021-04-06 21:42:00 +02:00
Luke
e56c56128b LibWeb: Add non-inclusive variants of subtree traversal 2021-04-06 21:42:00 +02:00
Luke
ca71ac484b LibWeb: Rename "for_each_in_subtree(_of_type)" to "for_each_in_inclusive_subtree(_of_type)"
This is because it includes the initial node that the function was
called on, which makes it "inclusive" as according to the spec.

This is important as there are non-inclusive variants, particularly
used in the node mutation algorithms.
2021-04-06 21:42:00 +02:00
Luke
f482628fe5 LibWeb: Strip out the mutation event logic from TreeNode
This will instead be done by Node, as they need to occur at precise
steps of the mutation algorithms. Additionally, some of the events
may need to be run multiple times. For example, the removal steps
is run for all the shadow-including descendants of the node that
just got removed.
2021-04-06 21:42:00 +02:00
Luke
be47a94876 LibWeb: Only prepare scripts on insertion if they're not parser inserted
Also updates the "inserted_into" function as per the previous commit.

Changes the FIXME, as according to the spec there is no notification
system to be notified of things such as the node becoming connected.

Instead, "becomes connected" means when the insertion steps are run,
the element is now connected when it previously wasn't.

https://html.spec.whatwg.org/multipage/infrastructure.html#becomes-connected

This is done in this PR because the insertion steps are run when the
start tag is inserted. This made it try to prepare the script too early
for inline scripts.

The order of operations in the HTML document parser ensures that
the parser document is set before the insertion steps are run.
2021-04-06 21:42:00 +02:00
Luke
e3d01c5e10 LibWeb: Make the node mutation event functions spec compliant
This particularly affects the insertion steps and the removed steps.

The insertion steps no longer take into the parent that the node
was inserted to, as per the spec. Due to this, I have renamed the
function from "inserted_into" to simply "inserted". None of the
users of the insertion steps was using it anyway.

The removed steps now take a pointer to the old parent instead of
a reference. This is because it is optional according to the spec
and old parent is null when running the removal steps for the
descendants of a node that just got removed.

This commit does not affect HTMLScriptElement as there is a bit
more to that, which is better suited for a separate commit.

Also adds in the adopted steps as they will be used later.
2021-04-06 21:42:00 +02:00
Luke
9e338a2be2 LibWeb: Add ProcessingInstruction node
Not particuarly useful right now, but is used in
ensure_pre_insertion_validity.

I'm not totally sure on the constructor arguments.
2021-04-06 21:42:00 +02:00
Andreas Kling
380e688123 LibWeb: Remove nodes from their old parent in appendChild/insertBefore 2021-04-06 15:52:09 +02:00
Andreas Kling
c70e0a4f29 LibWeb: Sever parent/child connections in ~TreeNode()
Also make sure to unref the children if there are any. Without this
it was very easy to leak TreeNodes.
2021-04-06 15:51:55 +02:00
Andreas Kling
41e5a0fe02 LibWeb: Remove duplicated code in TreeNode::remove_child()
We were assigning to m_first_child twice.
2021-04-06 14:27:44 +02:00
Andreas Kling
1d065aa51b LibWeb: Support the :last-of-type CSS selector :^) 2021-04-06 13:06:42 +02:00
Andreas Kling
0eb9a9dd13 LibWeb: Support the :first-of-type CSS selector :^) 2021-04-06 13:06:42 +02:00
Timothy Flynn
5de0e0068c LibWeb: Support two-value background-repeat
The background-repeat value may be specified as either one- or two-value
identifiers (to be interpreted as horizontal and vertical repeat). This
adds two pseudo-properties, background-repeat-x and background-repeat-y,
to handle this. One-value identifiers are mapped to two-value in
accordance with the spec.
2021-04-05 18:49:04 +02:00
Timothy Flynn
3ba338dec3 LibWeb: Support "pseudo" CSS properties
These are properties that may used internally by LibWeb when resolving
style values, but may not be set by external stylesheets. For example,
'background-repeat' may be a two-value CSS property that internally
translates to 'background-repeat-x' and 'background-repeat-y'.
2021-04-05 18:49:04 +02:00
Timothy Flynn
735829f694 LibWeb: Move painting of background images to common location
For now, painting of background color is kept separate. The ICB needs to
perform a "translate" call between painting the color and background,
whereas other divs must not make that call.
2021-04-05 18:49:04 +02:00
Timothy Flynn
1b2123af80 LibWeb: Convert ButtonBox to be a LabelableNode
This also adds an API to Label to determine if the Label itself or its
child TextNode is hovered. This allows ButtonBox to render in a hovered
state when the label is hovered.
2021-04-04 18:30:15 +02:00
Timothy Flynn
e074fc70e1 LibWeb: Convert CheckBox to be a LabelableNode 2021-04-04 18:30:15 +02:00
Timothy Flynn
1380dbeef3 LibWeb: Protect RadioButton and TextNode against mutating DOM
RadioButton had some protection, but also needed to be protected against
click events originating from its associated label.
2021-04-04 18:30:15 +02:00
Luke
4fa59baafe LibWeb: Remove document_setter from Window.document
It is readonly: https://html.spec.whatwg.org/multipage/window-object.html#the-window-object:dom-document-2
2021-04-04 16:13:38 +02:00
Timothy Flynn
e193cb0f11 LibWeb: Convert RadioButton to be a LabelableNode 2021-04-04 16:13:25 +02:00
Timothy Flynn
e1b5613142 LibWeb: Defer mouse events from TextNode to Label
A label's format is: <label>Label text</label>

So, a TextNode is created as a child of the Label node, and EventHandler
will send events to the TextNode. This changes TextNode to accept mouse
events if its parent is a Label, and to forward those events upward.
2021-04-04 16:13:25 +02:00
Timothy Flynn
d8106dda73 LibWeb: Add "Label" to be the layout node for HTMLLabelElement
The HTML <label> element is special in that it may be associated with
some other <input> element. When the label element is clicked, the input
element should be activated.

To achieve this, a LableableNode base class is introduced to provide an
interface for "labelable" elements to handle mouse events on their
associated labels. This not only allows clicking the label to activate
the input, but dragging the mouse from the label to the input (and vice-
versa) while the mouse is clicked will also active the label.

As of this commit, this infrastructure is not hooked up to any elements.
2021-04-04 16:13:25 +02:00
Timothy Flynn
4f9e9c0715 LibWeb: Do not assume grouped radio buttons have the same parent
For example:

    <div>
        <input type=radio name=group value=item1 />
    </div>
    <div>
        <input type=radio name=group value=item2 />
    </div>

Is a valid DOM and clicking on of these radio buttons should uncheck
the other.
2021-04-04 16:13:25 +02:00
Linus Groh
340e1f4b28 LibWeb: Implement the Screen interface
https://drafts.csswg.org/cssom-view/#the-screen-interface
2021-04-04 00:37:54 +02:00
Linus Groh
e8739ddab7 LibWeb+WebContent: Keep track of screen rect
It is now possible to get the up-to-date screen rect from a Web::Page.
2021-04-04 00:37:54 +02:00
Andreas Kling
5c67b2cb8f LibWeb: Defer creation of subframes until host element is connected
This allows parsing of document fragments with "<iframe>" to construct
the iframe element without requiring that the fragment have a frame.
2021-04-03 16:54:33 +02:00