Commit Graph

281 Commits

Author SHA1 Message Date
Luke
bc15144972 LibWeb: Move contentEditable from Element to HTMLElement
HTMLElement is the only interface that includes ElementContentEditable
in the HTML specification. This makes sense, as Element is also a base
class for elements in other specifications such as SVG,
which definitely shouldn't be editable.

Also adds a test for the attribute based on what Andreas did in the
video that added it.
2020-08-03 12:47:58 +02:00
Andreas Kling
7811cf3520 LibWeb: Implement the Element.contentEditable IDL attribute 2020-08-02 17:34:50 +02:00
Andreas Kling
07e13e9868 LibWeb: Only allow editing of elements with contenteditable="true"
We now respect the contenteditable HTML attribute and only let you
edit content inside explicitly editable elements.
2020-08-02 17:34:50 +02:00
Andreas Kling
bc299754f6 LibWeb: Allow inserting text at the cursor by typing characters :^)
This works everywhere right now, but it's obviously not going to stay
that way forever. :^)

Note that this does not advance the cursor correctly for whitespace
since the cursor is DOM-based and doesn't take whitespace collapsing
into account yet.
2020-08-02 17:34:50 +02:00
Andreas Kling
e496a74bb3 LibWeb: Add a basic DOM::Position class
This will be used for editable content. :^)
2020-08-02 17:34:50 +02:00
Andreas Kling
c95a1fe3a3 LibWeb: Add UIEvent class (base of MouseEvent, and others) 2020-07-28 19:39:17 +02:00
Andreas Kling
ef711f501e LibWeb: Move the Page/Frame/EventHandler classes into Page/ 2020-07-28 19:28:29 +02:00
Andreas Kling
7daeddb9e9 LibWeb: Move the CSS parser into CSS/Parser/ 2020-07-28 19:23:18 +02:00
Andreas Kling
cc4109c03b LibWeb: Move the HTML parser into HTML/Parser/ 2020-07-28 19:23:18 +02:00
Andreas Kling
c46439f240 LibWeb: Move HTML classes into the Web::HTML namespace 2020-07-28 18:55:48 +02:00
Andreas Kling
8b55d3d86e LibWeb: Move MouseEvent into the UIEvents namespace
Named after the UIEvents specification that houses MouseEvent.
2020-07-28 18:55:47 +02:00
Luke
a2b40de0cc LibWeb: Add a whole bunch of HTML DOM bindings
Note that these aren't full implementations of the bindings. This
mostly implements the low hanging fruit (namely, basic reflections)

There are some attributes that should be USVString instead of
DOMString. However, USVString is a slightly different definition
of DOMString, so it should suffice for now.
2020-07-27 19:51:45 +02:00
Andreas Kling
1f008c95b6 LibWeb: Move CSS classes into the Web::CSS namespace 2020-07-26 20:05:15 +02:00
Andreas Kling
11ff9d0f17 LibWeb: Move DOM classes into the Web::DOM namespace
LibWeb keeps growing and the Web namespace is filling up fast.
Let's put DOM stuff into Web::DOM, just like we already started doing
with SVG stuff in Web::SVG.
2020-07-26 20:05:15 +02:00
Andreas Kling
1b1537c5a6 LibWeb: Simplify type traits for SVGGraphicsElement 2020-07-26 17:51:00 +02:00
Andreas Kling
71556e39a4 LibWeb: Switch to using AK::is and AK::downcast 2020-07-26 17:51:00 +02:00
Andreas Kling
a565121793 LibWeb: Move HTML object model stuff into LibWeb/HTML/
Take a hint from SVG and more all the HTML classes into HTML instead of
mixing them with the DOM classes.
2020-07-26 17:51:00 +02:00
Matthew Olsson
b1299f972c LibWeb: Refactor SVG files into their own directory; follow spec layout 2020-07-26 14:53:43 +02:00
Matthew Olsson
943e4f8bf1 LibWeb: Abstract common operations of graphical SVG elements 2020-07-26 14:53:43 +02:00
Matthew Olsson
9cce7f57dd LibGfx: Add FloatPoint methods
Adds some conversion constructors, as well as the missing arithmetic
operations.
2020-07-26 14:53:43 +02:00
Matthew Olsson
5985eac81d LibWeb: Add elliptical curve support to svg path elements 2020-07-26 14:53:43 +02:00
Matthew Olsson
22f0953fe2 LibWeb: Begin SVG element support
This commit starts adding a basic SVG element. Currently, svg elements
have support for the width and height properties, as well as the stroke,
stroke-width, and fill properties. The only child element supported
is the path element, as most other graphical elements are just shorthand
for paths.
2020-07-26 14:53:43 +02:00
Andreas Kling
d1fdc1a2cf LibWeb: Use [Reflect] for Element.id and Element.className :^) 2020-07-24 13:25:42 +02:00
Andreas Kling
cb35a8ea83 LibWeb: Add HTMLElement.lang (and make HTMLElement.title reflecting) 2020-07-24 13:16:11 +02:00
Andreas Kling
ea451cea6a LibWeb: Add HTMLImageElement.src and HTMLImageElement.alt
These are reflecting attributes! :^)
2020-07-24 13:12:14 +02:00
Andreas Kling
3cb50a4714 LibWeb: Rename Element::tag_name() => local_name()
To prepare for fully qualified tag names, let's call this local_name.
Note that we still keep an Element::tag_name() around since that's what
the JS bindings end up calling into for the Element.tagName property.
2020-07-23 18:18:13 +02:00
Andreas Kling
a3feb46ad7 LibWeb: Parse "width" and "height" presentation attributes on <img>
These are HTML lengths that map to CSS width and height respectively.
2020-07-22 01:16:27 +02:00
Andreas Kling
5a7e57457e LibWeb: Add a dedicated function for parsing HTML length values
Presentation attribute lengths (width, height, etc.) can always be
unit-less (e.g "400") so going via the normal CSS parsing path only
works when the document is in quirks mode.

Add a separate parse_html_length() that always allows unit-less values.
2020-07-22 01:13:18 +02:00
Luke
19d6884529 LibWeb: Implement quirks mode detection
This allows us to determine which mode to render the page in.

Exposes "doctype" and "compatMode" on Document.
Exposes "name", "publicId" and "systemId" on DocumentType.
2020-07-21 01:08:32 +02:00
Tom
27bd2eab22 LibWeb: Require parent window argument for MessageBox
Since the vast majority of message boxes should be modal, require
the parent window to be passed in, which can be nullptr for the
rare case that they don't. By it being the first argument, the
default arguments also don't need to be explicitly stated in most
cases, and it encourages passing in a parent window handle.

Fix up several message boxes that should have been modal.
2020-07-16 16:10:21 +02:00
Kevin Meyer
d5d732cc87 LibWeb: Fix EVENT_DEBUG dump compilation 2020-07-11 11:34:59 +02:00
Kevin Meyer
5b6920a18a LibWeb: Don't call did_layout in non-main frame documents
Fixes https://github.com/SerenityOS/serenity/issues/2649

Loading a page with iframes could lead to a scenario, where the iframe
document finished layout prior to the main frame beeing laid out
initially. This caused a crash/assertion of the browser.
2020-07-08 23:45:12 +02:00
Kevin Meyer
a5b8cc2d0b LibWeb: Add type for FrameLoader::load
This should enable to destinguish between IFrame, Reload and Navigation
motivated loads in order to call the appropriate hooks.

This change is motivated as loading the IFrame test page causes the
IFrame url to be added to the history and shows up as the current
browser location bar.
2020-07-08 23:45:12 +02:00
Andreas Kling
5975a425bd LibWeb: Turn floated display:inline elements into block-level elements 2020-07-07 17:10:12 +02:00
Andreas Kling
244fe1089c LibWeb: Use LayoutTableRowGroup for display:table-{header,footer}-group 2020-07-05 19:51:49 +02:00
Andreas Kling
b8dc1fc195 LibWeb: Turn <td width> into a CSS width property 2020-06-28 14:30:37 +02:00
Andreas Kling
9e642827fc LibWeb: Don't tolerate unit-less lengths (except 0) in standards mode
"width: 500" is not a valid CSS property in standards mode and should
be ignored.

To plumb the quirks-mode flag into CSS parsing, this patch adds a new
CSS::ParsingContext object that must be passed to the CSS parser.
Currently it only allows you to check the quirks-mode flag. In the
future it will be a good place to put additional information needed
for things like relative URL resolution, etc.

This narrows <div class=parser> on ACID2 to the correct width. :^)
2020-06-28 12:46:40 +02:00
Andreas Kling
8d2194bdbd LibWeb: Make DOM timers cancellable and stop leaking them
This patch adds a Web::Timer object that represents a single timer
registration made with window.setTimeout() or window.setInterval().
All live timers are owned by the DOM Window object.

The timers can be stopped via clearTimeout() or clearInterval().
Note that those API's are actually interchangeable, but we have to
support both.
2020-06-27 20:02:04 +02:00
Andreas Kling
9d8565cf9a LibWeb: Add CanvasRenderingContext2D.rotate()
This is pretty limited since we don't have wholesale mapping through
the context transform, but we have to start somewhere. :^)
2020-06-26 18:27:12 +02:00
Andreas Kling
92d831c25b LibWeb: Implement fragment parsing and use it for Element.innerHTML
This patch implements most of the HTML fragment parsing algorithm and
ports Element::set_inner_html() to it. This was the last remaining user
of the old HTML parser. :^)
2020-06-26 00:53:25 +02:00
Andreas Kling
edf0aacda4 LibWeb: Add Document.getElementsByTagName() 2020-06-26 00:53:25 +02:00
Andreas Kling
440b4ece22 LibWeb: Move border width and color into LayoutStyle
To make this possible, I also had to give each LayoutNode a Document&
so it can resolve document-specific colors correctly. There's probably
ways to avoid having this extra member by resolving colors later, but
this works for now.
2020-06-24 19:43:27 +02:00
Andreas Kling
bc178ee743 LibWeb: Add CSS::Display enum and StyleProperties::display()
The display property is not interesting after we've built the layout
tree, so we don't have to move it into LayoutStyle.
2020-06-24 18:06:21 +02:00
Andreas Kling
5e83a97fa2 LibWeb: Rename LayoutNode::style() => specified_style()
Let's make way for a slightly-more-cooked style() that will eventually
replace the raw specified_style() for layout and paint purposes.
2020-06-24 13:54:31 +02:00
Andreas Kling
78f10942ba LibWeb: Update PageView content size on page relayout
If the layout changes and the page becomes taller or shorter for some
reason, we need to update the PageView's scrollable content size.
2020-06-23 18:02:08 +02:00
Andreas Kling
fc4ed8d444 LibWeb: Make wrapper factory functions take JS::GlobalObject&
Instead of taking the JS::Heap&. This allows us to get rid of some
calls to JS::Interpreter::global_object(). We're getting closer and
closer to multiple global objects. :^)
2020-06-23 16:57:39 +02:00
Andreas Kling
c24f5585b2 LibWeb: Let HTMLScriptElement call Document::run_javascript()
The fewer places we invoke the JS parser the better. Unless we have
some specific reason to parse manually, we can just call Document.
2020-06-23 16:45:01 +02:00
Andreas Kling
3a5af6ef61 LibWeb: Remove hacky old ways of running <script> element contents
Now that we're using the new HTML parser, we don't have to do the weird
"run the script when inserted into the document, uhh, or when the text
content of the script element changes" dance.

Instead, we just follow the spec, and scripts run the way they should.
2020-06-23 16:45:01 +02:00
Andreas Kling
9ef5d46277 LibWeb: Use ImageLoader::has_image() in HTMLObjectElement
This makes ACID2 load the eyes image again. :^)
2020-06-23 14:28:45 +02:00
Andreas Kling
10255bc5c6 LibWeb+Browser: Decode non-animated images out-of-process :^)
We now use the ImageDecoder service in LibWeb for everything except
GIF images (we'll have to deal with them later, ofc.)

This has a little bit of overhead but we should be able to optimize
it until it becomes negligible.
2020-06-22 21:47:01 +02:00
Andreas Kling
9ce25bbf1d LibWeb: Generate CanvasRenderingContext2D bindings from IDL :^)
We're still missing optional argument support, so this implementation
doesn't support fill(), only fill(fill_rule).

Still it's really nice to get rid of so much hand-written wrapper code.
2020-06-22 19:07:25 +02:00
Andreas Kling
213e2793bd LibWeb: Add Node.insertBefore(Node node, Node? child) 2020-06-21 17:42:00 +02:00
Andreas Kling
e1bd815a6a LibWeb: Generate Event and MouseEvent bindings from IDL :^)
We still have to hand-write a function to turn an Event& into a wrapper
but this is still a hue improvement. Eventually we'll find a way to
auto-generate that function as well.
2020-06-21 16:12:28 +02:00
Andreas Kling
dd29ff884f LibWeb: Generate ImageData bindings from IDL :^) 2020-06-21 15:57:10 +02:00
Andreas Kling
b959d06ace LibWeb: Generate HTMLCanvasElement bindings from IDL :^) 2020-06-21 15:37:13 +02:00
Andreas Kling
119dd2c541 LibWeb: Generate HTMLImageElement bindings from IDL :^) 2020-06-21 15:26:09 +02:00
Andreas Kling
1914f52371 LibWeb: Add HTMLElement wrapper
Expose the "title" attribute just to expose something. :^)
2020-06-21 14:39:15 +02:00
Andreas Kling
244b243d22 LibWeb: Add EventTarget.removeEventListener() 2020-06-21 12:37:34 +02:00
Andreas Kling
d724a12732 LibWeb: Generate EventTarget bindings from IDL :^) 2020-06-21 12:31:42 +02:00
Andreas Kling
a014b2930e LibWeb: Add Element.tagName and Element.className 2020-06-21 12:01:13 +02:00
Andreas Kling
a64033e581 LibWeb: Generate Element bindings from IDL :^)
Had to do a bunch more hacking on WrapperGenerator to support this.
We now support attribute setters as well.
2020-06-21 11:39:32 +02:00
stelar7
5eb39a5f61 LibWeb: Update parser with more insertion modes :^)
Implements handling of InHeadNoScript, InSelectInTable, InTemplate,
InFrameset, AfterFrameset, and AfterAfterFrameset.
2020-06-21 10:13:31 +02:00
Maciej Sobaczewski
a4fbc78f25 LibWeb: Respect display:none on <input> elements 2020-06-21 09:59:06 +02:00
Andreas Kling
bc4fa7a3c9 LibWeb: Expose Node.appendChild() to the web
This is a very barebones implementation of appendChild() that doesn't
take any of the idiosyncratic DOM behaviors into account yet.

Also teach the wrapper generator how to turn an Interpreter argument
into a Node&.
2020-06-21 01:01:50 +02:00
Andreas Kling
faff557400 LibWeb: Expose Document.body to the web
Also, make it return a HTMLElement since Document.body should actually
return the frameset element in a frame-based document.
2020-06-21 01:00:30 +02:00
Andreas Kling
319ef8aa86 LibWeb: Expose Document.createElement() to the web 2020-06-21 00:58:55 +02:00
Andreas Kling
94cf1f08ec LibWeb: Add Node.parentNode and Node.parentElement to DOM API :^) 2020-06-21 00:58:55 +02:00
Andreas Kling
1ffffa0053 LibWeb: Start generating JS wrappers from (simplified) WebIDL :^)
This patch introduces a hackish but functional IDL parser and uses it
to generate the JS bindings for Node and Document.

We'll see how far this simple parser takes us. The important thing
right now is generating code, not being a perfect IDL parser. :^)
2020-06-21 00:58:55 +02:00
Andreas Kling
cc5cba90db LibWeb: Give the DOM Window object a (weak) pointer to its JS wrapper 2020-06-20 17:50:48 +02:00
Andreas Kling
6242e029ed LibWeb: Make Element::tag_name() return a const FlyString&
The more generic virtual variant is renamed to node_name() and now only
Element has tag_name(). This removes a huge amount of String ctor/dtor
churn in selector matching.
2020-06-16 19:09:14 +02:00
Andreas Kling
9bb4020195 LibWeb: Don't load stylesheets with rel="alternate"
We're not supposed to load these by default. Alternate stylesheets can
be offered in a menu or something, if the user is interested.
2020-06-15 20:31:18 +02:00
Andreas Kling
17d26b92f8 LibWeb: Just ignore <script> elements that failed to load the script
We're never gonna be able to run them if we can't load them so just
let it go.
2020-06-15 18:37:48 +02:00
Andreas Kling
84f8c91a6f LibWeb: Use the URL encoder from AK instead of rolling a custom one 2020-06-15 17:56:00 +02:00
Andreas Kling
d883607e8f LibWeb: Force a full relayout if an element's CSS display changes
Not doing this was causing the wrong kind of LayoutNode to stay around
even though we had the final "display" value.
2020-06-15 17:56:00 +02:00
Andreas Kling
73c9f7ebf4 LibWeb: Move "visible in viewport" state tracking to ImageLoader
This should technically apply to any LayoutImage, so let's just move
it to ImageLoader.
2020-06-14 19:32:23 +02:00
Andreas Kling
c45615128b LibWeb: Move bitmap animation from HTMLImageElement to ImageLoader
Since ImageLoader manages the image decoder anyway, let it manage
animation as well.
2020-06-14 19:26:25 +02:00
Andreas Kling
ec39f419e5 LibWeb: Remove some unused functions from HTMLImageElement 2020-06-14 19:05:36 +02:00
Andreas Kling
a93fb7299f LibWeb: Don't choke when trying to render a document-less <iframe>
Just paint it like an empty box if there's no document in the frame.
2020-06-14 15:32:38 +02:00
Andreas Kling
3cc0c477db LibWeb: Add basic <object> element support
This patch implements a simple <object> element with fallback content.
If the URL from the data attribute fails to load (including 404),
we render the DOM tree inside the <object> as fallback content.

This works by generating a different layout tree for the <object>
depending on the state and success of the data load. Since we cannot
currently do incremental layout tree updates, we have to force a
complete layout tree rebuild when the resource load finishes/fails.
2020-06-13 22:24:49 +02:00
Andreas Kling
95d70addd8 LibWeb: Split out image loading logic from HTMLImageElement
Since more DOM nodes are going to want to load images (<object>, ...)
this patch splits out the image loading logic into an ImageLoader class
and then HTMLImageElement simply has an ImageLoader.

LayoutImage is then given a const ImageLoader& at construction and can
then provide layout and rendering for many kinds of DOM nodes.
2020-06-13 22:22:54 +02:00
Andreas Kling
d6d248c328 LibWeb: Add "data" to HTML::AttributeNames 2020-06-13 22:21:25 +02:00
Andreas Kling
502b5b76c8 LibWeb: Have DOM nodes start out in "needs style update" state
Otherwise we won't get the first fully styled look until you interact
with the page (e.g via hovering an element.)
2020-06-13 20:10:43 +02:00
Andreas Kling
2650005af8 LibWeb: <link rel> is actually a space-separated list of tokens
...so when we check for rel=stylesheet, we have to split it up into
parts first. :^)
2020-06-13 20:02:36 +02:00
Andreas Kling
7e8945601a LibWeb: Turn <td align> into CSS text-align
Note that align=center and align=middle both behave like the <center>
element, and not like text-align:center.
2020-06-13 15:16:56 +02:00
Andreas Kling
6de937a689 LibWeb: Turn <table bgcolor> into CSS background-color
More presentational attribute stuff. HN looking more and more like it's
supposed to. :^)
2020-06-13 12:49:20 +02:00
Andreas Kling
256898431c LibWeb: Simplify Node::is_link()
No need to check for presence of the href attribute as that is already
checked by enclosing_link_element().
2020-06-13 00:23:32 +02:00
Andreas Kling
0306ada1ff LibWeb: Add "colspan" to HTML::AttributeNames 2020-06-13 00:11:14 +02:00
Andreas Kling
c5a3d99dd5 LibWeb: Turn <table width> into the CSS width property 2020-06-12 22:52:38 +02:00
Andreas Kling
ca41c2e4a0 LibWeb: Turn <td bgcolor> into background-color 2020-06-12 22:47:51 +02:00
Andreas Kling
e9e2226544 LibWeb: Add "bgcolor" to HTML::AttributeNames 2020-06-12 22:47:41 +02:00
Andreas Kling
fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
Andreas Kling
ff2c949d70 LibWeb: Include class names in layout tree dumps
This makes it a lot easier to see which layout node is which DOM node.
2020-06-12 13:23:07 +02:00
Andreas Kling
116cf92156 LibGfx: Rename Rect,Point,Size => IntRect,IntPoint,IntSize
This fits nicer with FloatRect,FloatPoint,FloatSize and gives a much
better visual clue about what type of metric is being used.
2020-06-10 10:59:04 +02:00
Andreas Kling
28dcef4757 LibWeb: Add LayoutTableRowGroup to implement display: table-row-group 2020-06-09 21:53:16 +02:00
Andreas Kling
5042e560ef LibJS: Make more Interpreter functions take a GlobalObject& 2020-06-08 21:25:16 +02:00
Andreas Kling
92392398a2 LibWeb: Add Page abstraction between PageView and main Frame
* A PageView is a view onto a Page object.
* A Page always has a main Frame (root of Frame tree.)
* Page has a PageClient. PageView is a PageClient.

The goal here is to allow building another kind of view onto
a Page while keeping the rest of LibWeb intact.
2020-06-08 21:12:20 +02:00
Andreas Kling
9b17bf3dcd LibWeb: Use HTML::TagNames globals in the new HTML parser 2020-06-07 23:53:16 +02:00
Andreas Kling
992697d99f LibWeb: Add HTML::TagNames namespace for global tag name FlyStrings
Instead of "iframe", we can now say HTML::TagNames::iframe and avoid
a FlyString lookup.
2020-06-07 23:27:03 +02:00
Andreas Kling
10851d87a2 LibWeb: Add (stub) HTMLTable{,Cell,Row}Element C++ classes
We'll need a place to implement the various presentational attributes
for table parts, and more stuff.
2020-06-07 23:10:45 +02:00
Andreas Kling
3ae3729b4e LibWeb: Let subframes propagate paint invalidations via host element
When a paint invalidation occurs inside a subframe, it bubbles up to
Frame::set_needs_display(). From there, we call PageView if this is
the main frame, or otherwise invalidate the subframe host element.
2020-06-07 14:56:29 +02:00