Commit graph

657 commits

Author SHA1 Message Date
Kevin Meyer
7b5ffe67cf LibWeb: Check if layout node is still present after dispatch_event
Fixes https://github.com/SerenityOS/serenity/issues/2638

Dispatching an event can change the document. Therefore another check
for the layout_root needs to be done.
2020-07-11 11:34:59 +02:00
Kevin Meyer
821043d798 LibWeb: Remove some unnecessary casts 2020-07-11 11:34:59 +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
92374fc942 LibWeb: Make context menus work in WebContentView
As usual, this was just a matter of plumbing the PageClient calls from
the WebContent side over to the WebContentView side. :^)
2020-07-07 12:24:29 +02:00
Kevin Meyer
7974279a5d LibWeb: Fix PageView::url() null-check 2020-07-07 11:07:44 +02:00
Andreas Kling
c43afe71b7 LibWeb: Make WebContentView show the hover hand over links :^) 2020-07-06 23:32:12 +02:00
Andreas Kling
56126d7a45 LibWeb: Don't show unnecessary scrollbars in WebContentView
This behaves a little weird right now, and will probably require more
coordination between the widget and the WebContent process.
2020-07-06 22:02:38 +02:00
Andreas Kling
9169c8ca94 LibWeb: Make the WebContentView::on_load_start hook actually work :^) 2020-07-06 21:58:16 +02:00
Andreas Kling
d8be535579 Browser+LibWeb: Pave the way for using WebContentView in Browser
This commit sets everything up, but we still always instantiate a plain
Web::PageView in Browser::Tab..
2020-07-06 21:46:37 +02:00
Andreas Kling
49b9a0a665 LibWeb: Add a shared WebViewHooks base class for both web view widgets
This will make it easier for Browser to share code between both views.
2020-07-06 21:19:03 +02:00
Andreas Kling
7a7e39c7af LibWeb: Move WebContentView from Demos/WebView into LibWeb 2020-07-06 20:36:34 +02:00
Andreas Kling
fd65a24834 LibWeb: Make the link context menu hook include the destination URL 2020-07-06 20:00:56 +02:00
Andreas Kling
02c5e22f06 LibWeb: Make the link click hooks include the destination URL
We have all the context needed for relative URL resolution inside the
engine, so let's not make embedders worry about this.
2020-07-06 19:41:10 +02:00
Nico Weber
e9d18e35d6 LibWeb: Move "Stop parsing!" behind PARSER_DEBUG
This makes SerenityOS's IRC client a lot less chatty.
2020-07-06 17:03:26 +02:00
Andreas Kling
244fe1089c LibWeb: Use LayoutTableRowGroup for display:table-{header,footer}-group 2020-07-05 19:51:49 +02:00
Andreas Kling
d4fe3e8009 LibWeb: Always fire the link hover hooks when moving between links
Some broken logic was preventing us from firing the hover hooks when
the cursor jumped directly from one link to another.
2020-07-05 17:05:23 +02:00
Andreas Kling
63d796312d LibWeb: Tweak PageView::on_link_hover hook
Change: on_link_hover(String) -> on_link_hover(URL)

Also, we now fire the hook when a link is unhovered as well, allowing
the embedder to react to nothing being hovered anymore.
2020-07-05 17:02:44 +02:00
Andreas Kling
56d14d5701 LibWeb: Move fragment link handling to Frame
Activating a "#foo" fragment link will now be handled internally by
the Frame instead of involving the widget layer.

If the viewport needs to be scrolled as a result, we will simply ask
the PageClient to scroll a new rect into view.
2020-07-05 15:57:07 +02:00
Andreas Kling
ca93c22ae2 LibGUI: Turn GUI::Application::the() into a pointer
During app teardown, the Application object may be destroyed before
something else, and so having Application::the() return a reference was
obscuring the truth about its lifetime.

This patch makes the API more honest by returning a pointer. While
this makes call sites look a bit more sketchy, do note that the global
Application pointer only becomes null during app teardown.
2020-07-04 16:54:55 +02:00
Andreas Kling
ccdaa1bea9 LibWeb: Insert newlines at <br> and block boundaries in copied text :^)
To make the plain text we copy out from LibWeb look at least somewhat
like its original form, let's insert newlines at <br> elements and when
we exit a block-level element.

This is far from perfect, but seems to work pretty okay.
2020-07-03 21:34:12 +02:00
Andreas Kling
f7ef6c65b4 LibWeb: Add a "select all" action to the Web::PageView
This works by finding the very first and very last LayoutText nodes
in the layout tree and then setting the selection bounds to those two
nodes. For some reason it gets glitchy if we set the very first and
very last *LayoutNode* as the selection bounds, but I didn't feel like
investigating that too closely right now.
2020-07-03 21:34:12 +02:00
Andreas Kling
f87881e198 LibWeb: Implement basic text copying :^)
You can now press Ctrl+C to copy the selected text in a Web::PageView
to the system clipboard. Very cool!
2020-07-03 21:34:12 +02:00
Andreas Kling
392b055806 LibWeb: Use the StackingContext tree for hit testing
This makes it possible to click links that are above other content due
to stacking context order (e.g via CSS z-index.)
2020-07-01 19:10:58 +02:00
Andreas Kling
f7a900367f LibWeb: StackingContext was sorting the wrong list of children
Oops, we're supposed to sort the *parent's* children, not our own.
2020-07-01 18:35:50 +02:00
Matthew Olsson
bda39ef7ab LibJS: Explicitly pass a "Function& new_target" to Function::construct
This allows the proxy handler to pass the proper new.target to construct
handlers.
2020-07-01 11:16:37 +02:00
Andreas Kling
53573f6fb1 LibWeb: Clamp text fragment selection to the fragment
Also add 1px of width to partial fragment selections, since that ends
up looking nicer during interactive mouse selection.
2020-06-29 12:47:21 +02:00
Andreas Kling
301ac3c7e5 LibWeb: Improve hit testing on the right of line boxes
We now remember the last candidate fragment when hit testing past the
right end of text and use that as the fallback result if nothing else
matches. This makes it possible to drag-select outside the line boxes
in a way that feels mostly natural. :^)
2020-06-29 00:39:51 +02:00
Andreas Kling
9177eea8fe LibWeb: Add LayoutRange::normalized()
We use this to ensure that we're always working with a selection where
the start() is before the end() in document order. That simplifies all
the logic around this.
2020-06-29 00:39:51 +02:00
Andreas Kling
706fc3d1aa LibWeb: Paint the text selection :^)
Text selection currently works at the LayoutNode level. The root of the
layout tree has a LayoutRange selection() which in turn has two
LayoutPosition objects: start() and end().

A LayoutPosition is a LayoutNode + a text offset into that node.

We handle the selection painting in LayoutText::paint_fragment(), after
the normal painting is finished. The basic mechanism is that each
LayoutFragment is queried for its selection_rect(), and if a non-empty
rect is returned, we clip to it and paint the text once more.
2020-06-29 00:39:51 +02:00
Andreas Kling
2762e3d80a LibWeb: Rename LineBoxFragment::render() => paint()
Also LayoutText::render_fragment() => render(). This matches the names
in the rest of LibWeb.
2020-06-28 23:07:44 +02:00
Andreas Kling
dcc25f7d7a LibWeb: Layout table-cell contents once again once final width is known
This makes centered and right-aligned table-cell contents position
itself correctly.
2020-06-28 20:54:45 +02:00
Luke
2df69317f1 LibWeb: Implement almost all missing tokenizer cases 2020-06-28 16:56:26 +02:00
Andreas Kling
f270f1f274 LibWeb: Give the <blockquote> element some margins in the UA style 2020-06-28 15:26:05 +02:00
Andreas Kling
7d3c8d066f LibWeb: Support "pt" length units :^) 2020-06-28 15:25:32 +02:00
Andreas Kling
7fc988b919 LibWeb: Start working on supporting fixed table layouts
Sometimes people make tables with a specific width. In those cases,
we can't just use the auto-sizing algorithm, but instead have to
respect whatever width the content specifies.

This is a bit rickety right now, since we don't implement generation
of anonymous table boxes.

The basic mechanism here is that block layout (which table-cell uses)
now has a virtual way of asking for the width of the logical containing
block. This is necessary as table-row does not produce a block-level
element and so was previously unable to provide a containing block
width for table-cell layout.

If the table has a non-auto specified width, we now interpret that as
a request to use fixed table layout. This will evolve over time. :^)
2020-06-28 15:13:56 +02:00
Andreas Kling
daa88448e1 LibWeb: Add Length::is_undefined_or_auto()
Quite often, we want the same behavior in both cases. This allows us
to express that with a single method.
2020-06-28 15:08:37 +02:00
Andreas Kling
b8dc1fc195 LibWeb: Turn <td width> into a CSS width property 2020-06-28 14:30:37 +02:00
Andreas Kling
38d6cc8598 LibWeb: Convert uppercase selector tag names to lowercase internally
This is necessary for some older content to work correctly. There's
probably a nicer (and correct-er) way to do this. Deferring to the
new CSS parser.
2020-06-28 12:58:04 +02:00
Andreas Kling
fd32f24753 LibWeb: Tweak default style for <hr> to use em units for margin values 2020-06-28 12:57:42 +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
c1acf67715 LibWeb: Use length units and shorthands in the default UA style sheet 2020-06-28 12:12:01 +02:00
Andreas Kling
9576f6b1d4 LibWeb: Collapse top and bottom margin of empty sibling blocks
Margin collapsing is a bit confusing, but if I understand correctly,
when collapsing a box's top margin with the vertically adjacent
sibling box above, we should "skip over" empty (0-height) boxes and
collapse their margin with *their* vertically adjacent sibling box
above, etc. Iterating until we hit the first non-empty in-flow block.

This pulls up the bottom part of the face on ACID2. :^)
2020-06-28 11:20:15 +02:00
Andrew Kaster
cc675cbe24 LibWeb: Add Page context menu request
Pages can request a context menu on right click. This is plumbed
through the PageClient.
2020-06-28 00:05:08 +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
Kevin Meyer
22b20c381f LibWeb: Implement remaining missing tokenizer EOF cases 2020-06-27 13:27:10 +02:00
Hüseyin ASLITÜRK
0f7a651adc LibWeb: Add "image/x‑portable‑graymap" mime type for pgm file extension 2020-06-27 13:01:27 +02:00
Andreas Kling
8e6522d034 LibWeb: Implement some missing tokenizer cases for EOF handling 2020-06-26 22:47:07 +02:00