Commit Graph

354 Commits

Author SHA1 Message Date
Luke Wilde
11ede565a8 LibWeb: Fire a keypress event after firing a keydown event
In Google Docs with our user agent string, this is the event it listens
for to insert characters into the document.
2022-11-07 14:10:41 +01:00
Luke Wilde
e4688fedd5 LibWeb: Make keyboard events properly fire into a focused iframe
Google Docs focuses a "text event target" iframe using Window.focus on
the iframe's contentWindow. Doing so makes the iframe's document the
focused element we have to fire text events at. However, in the top
level browsing context, the focused element is still the iframe, so we
have to repeat the keyboard event steps but with the iframe's nested
browsing context instead.
2022-11-07 14:10:41 +01:00
Luke Wilde
a10204133a LibWeb: Use the focus steps instead of set_focused_element on user click
This makes clicking properly fire focus/blur events alongside setting
the focused element.
2022-11-07 14:10:41 +01:00
Gunnar Beutner
02186e2ee9 LibWeb: Skip anonymous layout nodes while finding the event target
This makes the links on nitter.net clickable, e.g. "preferences" in the
upper right corner.
2022-11-07 12:19:42 +00:00
Gunnar Beutner
e7a7895114 LibWeb: Move code for finding the parent element into a helper function
This exact same loop is repeated a couple of times.
2022-11-07 12:19:42 +00:00
Timothy Flynn
6aea60e6ee LibWeb+LibWebView+WebContent: Add IPC to receive window position/size
This information will have to come from the Browser application. This
adds IPCs to receive that information when it is available or changes.
2022-11-01 21:16:50 +00:00
Andreas Kling
29c6aabf49 LibWeb: Try harder to find a suitable DOM node for mouse event dispatch
Since our hit testing mechanism gives you the Paintable under the mouse
cursor, we can't just give up if that paintable doesn't have a
corresponding DOM node. That meant that generated content like pseudo-
elements didn't generate mouse events at all.

Fix this by making a dom_node_for_event_dispatch() helper function that
finds a suitable DOM node when given a paintable. This first cut is very
naive, and there's probably more we should do, but we have to start
somewhere. :^)
2022-10-23 23:32:42 +02:00
Aliaksandr Kalenik
9cbf031b6d LibWeb: Add button property in MouseEvent 2022-10-23 15:58:16 +02:00
Aliaksandr Kalenik
501fb1cccb LibWeb: Dispatch "wheel" event 2022-10-23 15:58:16 +02:00
Andreas Kling
268b9c5d90 LibWeb: Make the layout tree GC-allocated
This removes a set of complex reference cycles between DOM, layout tree
and browsing context.

It also makes lifetimes much easier to reason about, as the DOM and
layout trees are now free to keep each other alive.
2022-10-20 15:16:23 +02:00
Andreas Kling
83c5ff57d8 LibWeb: Make BrowsingContext GC-allocated
(And BrowsingContextGroup had to come along for the ride as well.)
This solves a number of nasty reference cycles between browsing
contexts, history items, and their documents.
2022-10-20 15:16:23 +02:00
Aliaksandr Kalenik
dfc3a4772b LibWeb: Ignore "pointer-events: none" elements in hit_test 2022-10-19 16:11:15 +02:00
Linus Groh
3f24a444f9 LibWeb+WebContent: Add plumbing for 'webdriver-active flag' 2022-10-13 11:14:45 +02:00
Andrew Kaster
636602a54e LibWeb: Implement <input type=file> behavior
This includes punting on the actual file picker implementation all the
way out to the PageClient. It's likely that some of the real details
should be implemented somewhere closer, like the BrowsingContext or the
Page, but we'll get there.

For now, this allows https://copy.sh/v86 to load the emulation of the
preselected images all the way until it hits a call to
URL.createObjectURL.
2022-10-04 22:05:14 +02:00
Andrew Kaster
56b381aac0 LibWeb: Cleanup unecessary uses and includes of HTML::Window
The big global refactor left some stragglers behind for atomicity.

Clean up the rest, and remove a ton of includes of LibWeb/HTML/Window.h
2022-10-01 21:05:32 +01:00
Andrew Kaster
4bb6345b2f LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
2022-10-01 21:05:32 +01:00
Sam Atkins
28a591ce7b LibWeb: Use zoom cursor for CSS zoom-in/zoom-out cursors
Ideally we'd use a different one for each, but this is fine.
2022-09-28 23:58:26 +01:00
davidot
4912b22e3b LibWeb+WebContent: Setup the js console client earlier
This allows us to print messages in inline scripts. Also add an example
of this in the welcome page to test this.
2022-09-21 17:34:32 +01:00
Andreas Kling
6c33dea6a6 LibWeb: Implement the "close" algorithm for browsing contexts
This is used by window.close() programmatically, but of course the user
can also decide to close a top-level browsing context at any time by
closing the tab.
2022-09-21 11:51:18 +02:00
Andreas Kling
8ead228202 LibWeb: Implement "browsing context group" concept from the HTML spec 2022-09-20 10:32:12 +02:00
Andreas Kling
54e7359243 LibWeb: Repaint the page immediately when using the mouse to select
Otherwise we'd repaint the next time our "caret blink" timer would fire
(or something else caused a repaint). This made selection feel sluggish.
2022-09-16 15:15:50 +02:00
Andreas Kling
6f433c8656 LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
2022-09-06 00:27:09 +02:00
Andreas Kling
bb547ce1c4 LibWeb: Make AbstractRange and subclasses GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
7c3db526b0 LibWeb: Make DOM::Event and all its subclasses GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
2a7924f96c LibWeb: Bring browsing context creation closer to spec
This patch implements the "create a new browsing context" function from
the HTML spec and replaces our existing logic with it.

The big difference is that browsing contexts now initially navigate to
"about:blank" instead of starting out in a strange "empty" state.
This makes it possible for websites to create a new iframe and start
scripting inside it right away, without having to load an URL into it.
2022-08-05 12:46:42 +02:00
Andreas Kling
69a45adfbe LibWeb: Remove page_did_set_document_in_top_level_browsing_context()
This PageClient callback was never used for anything.
2022-08-05 12:42:46 +02:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
Andreas Kling
7a7043f821 LibWeb: Simplify some WeakPtr assignments
We can assign a raw pointer directly to a WeakPtr without null-checking
it first.
2022-07-04 22:30:59 +02:00
Lucas CHOLLET
662711fa26 Browser+LibWeb+WebContent: Allow Browser to load local files
To achieve this goal:
 - The Browser unveils "/tmp/portal/filesystemaccess"
 - Pass the page through LoadRequest => ResourceLoader
 - ResourceLoader requests a file to the FileSystemAccessServer via IPC
 - OutOfProcessWebView handles it and sends a file descriptor back to
 the Page.
2022-06-27 20:22:15 +01:00
Karol Kosek
c6eaa39b99 LibWeb: Make doubleclicking select the nearest word 2022-06-20 12:55:50 +01:00
Karol Kosek
237a5bedd2 LibWeb: Dispatch dblclick UI Events on double click 2022-06-20 12:55:50 +01:00
Karol Kosek
03cda8a013 LibWeb+LibWebView+WebContent: Get doubleclick events from LibGUI 2022-06-20 12:55:50 +01:00
Karol Kosek
0e04532623 LibWeb: Add stub implementation for handling doubleclicks 2022-06-20 12:55:50 +01:00
kleines Filmröllchen
a7a5721149 LibWeb: Dispatch mouse events to topmost element instead of hit target
This improves our spec compliance by allowing the user to click
non-element nodes (like text) and having the click be registered with
the parent element (like a div or button). This makes Fandom's cookie
accept button work if you click the text. Additionally, the events test
page contains a test to check the target element, which would previously
not exist when we fired the event at a non-element.
2022-06-05 22:31:06 +01:00
Igor Pissolati
1b94b4c593 LibWeb: Bring MouseEvent a bit closer to spec 2022-04-09 18:27:24 +02:00
Igor Pissolati
a2bc97a9c2 LibWeb: Skip anchor activation behavior if the click event was cancelled 2022-04-09 18:27:24 +02:00
Oliver Wales
382eacc08e LibWeb: Select correct context menu when right clicking image 2022-04-08 07:59:01 -04:00
Rob Ryan
c1b311835b LibWeb: Not dispatching page_did_click_link event breaks page refresh
The WebView url wouldn't update so reload in Tab would still use the
previous URL before any left click navigation.

I am unsure if there was any good reason not to dispatch the event when
there are no modifiers.
2022-04-03 12:41:48 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Linus Groh
7bdbac7fd9 LibWeb: Add 'is scripting enabled' concept to EnvironmentSettingsObject
This is now the source of truth for 'user enabled/disabled scripting',
but it has to ask the window's page, which actually stores the setting.

Also use this new functionality in two places where it was previously
marked as a FIXME.
2022-03-31 17:08:38 +02:00
sin-ack
51df97e799 LibWeb: Consolidate mouse handling + only trigger event on left click
This commit moves a couple more special cases in mouse event handling to
handle_mouseup. Additionally, it gets rid of the special casing with
should_dispatch_event and only fires a click event to the EventTarget
when the left mouse button is clicked. Finally it restores the link
context menu callback that was lost during 0fc8c65.
2022-03-30 21:17:04 +02:00
sin-ack
aaa954f900 LibWeb: Bring handling of anchor elements closer to spec
This commit moves the regular handling of links to the anchor elements'
activation behavior, and implements a few auxiliary algorithms as
defined by the HTML specification.

Note that certain things such as javascript links, fragments and opening
a new tab are still handled directly in EventHandler, but they have been
moved to handle_mouseup so that it behaves closer to how it would if it
was entirely up-to-spec.
2022-03-26 14:01:17 +01:00
Andreas Kling
f7cfd47b48 LibWeb: Add Paintable::dom_node() convenience accessor 2022-03-21 13:03:33 +01:00
Andreas Kling
b64b5fa8bd LibWeb: Add Painting::HitTestResult::dom_node()
This is a convenience accessor to avoid having to say this everywhere:

    result.paintable->layout_node().dom_node()

Instead, you can now do:

    result.dom_node()
2022-03-21 13:03:33 +01:00
Andreas Kling
0ba785894c LibWeb: Make hit testing functions return Optional<HitTestResult>
Using "HitTestResult with null paintable" as a way to signal misses was
unnecessarily confusing. Let's use Optional instead. :^)
2022-03-21 13:03:33 +01:00
Simon Wanner
48efdaa8c4 LibWeb: Update hit_test for CSS Transforms
This now also takes a FloatPoint instead of an IntPoint to avoid
excessive rounding when multiple transforms apply on top of each other.
2022-03-18 18:51:42 +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
910fded482 LibWeb: Flush any pending layout updates before processing mouse events
We want to make sure the layout and paint trees are up-to-date before
handling any mouse events.
2022-03-16 18:50:56 +01:00
sin-ack
29583104d2 LibWeb: Refactor all LabelableNode subclasses + input event handling :^)
This commit is messy due to the Paintable and Layout classes being
tangled together.

The RadioButton, CheckBox and ButtonBox classes are now subclasses of
FormAssociatedLabelableNode. This subclass separates these layout nodes
from LabelableNode, which is also the superclass of non-form associated
labelable nodes (Progress).

ButtonPaintable, CheckBoxPaintable and RadioButtonPaintable no longer
call events on DOM nodes directly from their mouse event handlers;
instead, all the functionality is now directly in EventHandler, which
dispatches the related events. handle_mousedown and related methods
return a bool indicating whether the event handling should proceed.

Paintable classes can now return an alternative DOM::Node which should
be the target of the mouse event. Labels use this to indicate that the
labeled control should be the target of the mouse events.

HTMLInputElement put its activation behavior on run_activation_behavior,
which wasn't actually called anywhere and had to be manually called by
other places. We now use activation_behavior which is used by
EventDispatcher.

This commit also brings HTMLInputElement closer to spec by removing the
did_foo functions that did ad-hoc event dispatching and unifies the
behavior under run_input_activation_behavior.
2022-03-16 00:38:31 +01:00
Andreas Kling
5779a910e5 LibWeb: Move hit testing to the painting tree 2022-03-11 00:21:49 +01:00
Andreas Kling
ba606d9057 LibWeb: Move PaintingBox to its own .cpp and .h files 2022-03-11 00:21:49 +01:00
Andreas Kling
f017c1c064 LibWeb: Make hit testing return a { paintable, offset }
Everything related to hit testing is better off using the painting tree.
The thing being mousemoved over is a paintable, so let's hand that out
directly instead of the corresponding layout node.
2022-03-11 00:21:49 +01:00
Andreas Kling
cb0c5390ff LibWeb: Move mouse event and label logic from layout to painting tree
Input events have nothing to do with layout, so let's not send them to
layout nodes.

The job of Paintable starts to become clear. It represents a paintable
item that can be rendered into the viewport, which means it can also
be targeted by the mouse cursor.
2022-03-11 00:21:49 +01:00
Ben Abraham
7594350376 Browser: Show currently loading host and remaining resource count 2022-03-10 00:51:05 +01:00
Linus Groh
1422bd45eb LibWeb: Move Window from DOM directory & namespace to HTML
The Window object is part of the HTML spec. :^)
https://html.spec.whatwg.org/multipage/window-object.html
2022-03-08 00:30:30 +01:00
Kenneth Myhra
fde9c1bfb2 LibWeb: Add key code 'Esc' to ignored Keydown Events in EventHandler
This filters out the key code 'Esc' so it won't be printed to editable
text nodes, e.g. text <input> elements.
2022-02-20 10:57:30 +01:00
Kenneth Myhra
8a168b2bc0 LibWeb: Add support for navigating text <input> with End key 2022-02-20 10:57:30 +01:00
Kenneth Myhra
939c10b201 LibWeb: Add support for navigating text <input> with Home key 2022-02-20 10:57:30 +01:00
Kenneth Myhra
4877e7593c LibWeb: Refresh text-<input> contents when pressing backspace or delete
Make sure to refresh the contents of text-<input> when pressing
backspace or delete key.

The methods 'handle_insert()' and 'handle_delete()' already had the call
to 'm_browsing_context.active_document()->force_layout()' so let us also
add it to 'handle_delete_character_after()'.
2022-02-19 11:28:59 +01:00
Adam Plumb
7a035558e1 LibWeb: Set cursor on mousemove for non-text elements 2022-02-16 15:16:39 +00:00
Andreas Kling
1b2e1c19e1 LibWeb: Don't trigger page load for fragment navigation within same URL 2022-02-15 13:51:17 +01:00
Kenneth Myhra
bf7f6a9e98 LibWeb: Implement EventHandler::focus_previous_element()
This implements EventHandler::focus_previous_element() so we can cycle
backwards through focusable elements on a web page with Shift+Tab.
2022-02-08 22:15:10 +00:00
Sam Atkins
48c6cf92e3 LibWeb: Add pointer-events: all
This is basically the same as `auto` in the spec, so let's just treat
them as identical for now. Gets rid of some Discord CSS parser
spam. :^)
2022-02-07 21:55:12 +01:00
Andreas Kling
fbd58f9615 LibWeb: Dispatch a click event after mousedown+mouseup on same target 2022-02-07 13:28:59 +01:00
Andreas Kling
3e6aaa3520 LibWeb: Update focus target when handling mousedown events
If the mousedown event hits something with is_focusable()==true,
we now update the document's focused element *instead* of placing the
text cursor at the focusable element.

This allows you to begin editing input elements by clicking them.

This feels very hackish and we'll need to come up with something nicer.
2022-02-06 22:13:13 +01:00
Andreas Kling
41fe02e012 LibWeb: Rename "frame" to "browsing_context" in various places
We renamed the Frame class to BrowsingContext a while back, but forgot
to update some variable names.
2022-02-06 16:22:58 +01:00
Dmitry Petrov
2616b61eee WebContent: Switch scroll direction on shift modifier 2022-01-29 21:48:57 +02:00
Dmitry Petrov
1662213737 Userland: Add horizontal mouse scroll support 2022-01-20 10:37:52 +01:00
Andreas Kling
7c57961c61 LibWeb: Move BrowsingContext into HTML/
Browsing contexts are defined by the HTML specification, so let's move
them into the HTML directory. :^)
2021-11-18 21:11:30 +01:00
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Sam Atkins
53edaa3b26 LibWeb+WebContent: Add set_preferred_color_scheme IPC call
This allows the owner of a WebView to override whether to use a dark
theme or not, instead of just using the system theme's IsDark property.
2021-10-31 18:39:13 +01:00
Filiph Sandström
d6a0726302 Everywhere: Rename left/right-click to primary/secondary
This resolves #10641.
2021-10-27 22:05:58 +03:00
Andreas Kling
fcff6b7160 LibWeb: Don't assume we hit a layout node when handling mousedown events
Regression from the introduction of CSS pointer-events in
ec43f7a2b0.
2021-10-19 12:53:22 +02:00
Andreas Kling
f9e814826f LibWeb: Only update layout if actually needed when scrolling to anchor 2021-10-18 10:40:30 +02:00
Andreas Kling
959b18bde3 LibWeb: Remove a bunch of pointless "else" in EventHandler 2021-10-12 14:44:52 +02:00
Andreas Kling
d90be22a73 LibWeb: Use strong pointers and null checks in handle_keydown() 2021-10-12 14:44:00 +02:00
Andreas Kling
dcb409a112 LibWeb: Use strong pointers and null checks in handle_keyup() 2021-10-12 14:39:09 +02:00
huwdp
ec43f7a2b0 LibWeb: Add initial version of pointer-events CSS property 2021-10-09 14:48:30 +01:00
Andreas Kling
c4826eae4f LibWeb: Rename Layout::BlockBox => BlockContainer
There's a subtle difference here. A "block box" in the spec is a
block-level box, while a "block container" is a box whose children are
either all inline-level boxes in an IFC, or all block-level boxes
participating in a BFC.

Notably, an "inline-block" box is a "block container" but not a "block
box" since it is itself inline-level.
2021-10-06 20:10:36 +02:00
Andreas Kling
0264ae23bc LibWeb: Make CSS layout lazier
Instead of doing layout synchronously whenever something changes,
we now use a basic event loop timer to defer and coalesce relayouts.

If you did something that requires a relayout of the page, make sure
to call Document::set_needs_layout() and it will get coalesced with all
the other layout updates.

There's lots of room for improvement here, but this already makes many
web pages significantly snappier. :^)

Also, note that this exposes a number of layout bugs where we have been
relying on multiple relayouts to calculate the correct dimensions for
things. Now that we only do a single layout in many cases, these kind of
problems are much more noticeable. That should also make them easier to
figure out and fix. :^)
2021-10-06 17:14:22 +02:00
Andreas Kling
f8354c5503 LibWeb+Browser: Disable Same-Origin Policy by default for now
Until we have CORS preflight checks working, this is only getting in the
way of testing and I have to disable it manually all the time.
2021-10-03 23:39:07 +02:00
Andreas Kling
962298b040 LibWeb: Don't update rendering in BrowsingContexts without opportunity
This patch adds the "has a rendering opportunity" concept from the spec
to BrowsingContext and uses it to filter out contexts that are unable
to render right now when doing the event loop's rendering updates.

Note that we actually consider all contexts to have a rendering
opportunity at all times right now. Coming up with reasons to avoid
rendering is left as a FIXME. :^)
2021-10-03 17:39:13 +02:00
Andreas Kling
6e341cd696 LibWeb: Let HTML::EventLoop drive the firing of resize events 2021-10-03 16:42:34 +02:00
Idan Horowitz
c5b924b1e6 LibWeb: Dispatch keydown/keyup events on the appropriate target 2021-10-01 20:14:45 +02:00
Andreas Kling
0af0ee4293 LibWeb: Fire "keyup" events as well :^)
This was easy, now that we have KeyboardEvent.
2021-09-28 16:56:24 +02:00
Andreas Kling
554c344ffe LibWeb: Add a basic KeyboardEvent and fire "keydown" events :^) 2021-09-28 16:56:24 +02:00
Idan Horowitz
4629f2e4ad LibWeb: Add the Web::URL namespace and move URLEncoder to it
This namespace will be used for all interfaces defined in the URL
specification, like URL and URLSearchParams.

This has the unfortunate side-effect of requiring us to use the fully
qualified AK::URL name whenever we want to refer to the AK class, so
this commit also fixes all such references.
2021-09-13 01:43:10 +02:00
Brian Gianforcaro
bca8707e15 LibWeb: Start tracking elapsed time when a resource is loaded 2021-09-12 16:39:23 +02:00
Andreas Kling
19de6bb1cc LibWeb+Browser: Add Debug menu action for toggling Same-Origin Policy
Sometimes it's useful to turn off the SOP for testing purposes.
Let's make that easy by having a Debug menu item for it. :^)
2021-09-12 02:13:28 +02:00
Sam Atkins
9588a377ec LibWeb: Implement Window.scroll{X,Y} JS properties
...and pageXOffset/pageYOffset too, since those are just aliases for the
same thing.
2021-09-11 15:51:05 +01:00
Sam Atkins
83414af9f3 LibWeb+WebContent: Add WebContentClient::did_request_scroll_to() call
This call sets the absolute scroll position for the window.
2021-09-11 15:51:05 +01:00
Sam Atkins
a09219159c LibWeb+WebContent: Modify did_request_scroll() IPC to take x&y deltas
This is in preparation for implementing JS scrolling functions, which
specify both x and y scrolling deltas. The visible behavior has not
changed.

Also, moved the "mouse wheel delta * 20" calculation to the
`EventHandler` since the JS calls will want to work directly in pixels.
2021-09-11 15:51:05 +01:00
Andreas Kling
5514f41f25 LibWeb: Ignore keydown events when there is no layout tree 2021-09-11 02:13:06 +02:00
Andreas Kling
8fabaaa2a8 LibWeb: Make "top-level browsing context" concept more spec-compliant
Any browsing context that doesn't have a parent browsing context is now
considered a top-level browsing context. This matches the HTML spec.

This means we no longer keep a pointer to the top-level context, since
we can simply walk the parent chain until we find the topmost ancestor.
2021-09-10 03:02:55 +02:00
Andreas Kling
e1fb8bef09 LibWeb: Rename Document::complete_url() => parse_url()
This better matches the spec nomenclature.
2021-09-09 21:25:10 +02:00
Andreas Kling
84fcf879f9 LibWeb: Rename BrowsingContext::document() => active_document()
This better matches the spec nomenclature. Note that we don't yet
*retrieve* the active document according to spec.
2021-09-09 21:25:10 +02:00
Andreas Kling
71d7c8a353 LibWeb: Add BrowsingContext::container_document()
This is the "browsing context container document" from the spec.
2021-09-09 02:30:54 +02:00
Andreas Kling
d1100dd6bc LibWeb: Add BrowsingContext::container() to align with the spec
We already have a base class for frame elements that we call
BrowsingContextContainer. This patch makes BrowsingContext::container()
actually return one of those.

This makes us match the spec names, and also solves a FIXME about having
a shared base for <frame> and <iframe>. (We already had the shared base,
but the pointer we had there wasn't tightly typed enough.)
2021-09-09 02:30:54 +02:00
Andreas Kling
e91edcaa28 LibWeb: Rename InitialContainingBlockBox => InitialContainingBlock
The "Box" suffix added nothing here.
2021-09-08 11:27:46 +02:00
Andreas Kling
e90ccf6a20 LibWeb: Make BrowsingContext::m_top_level_browsing_context a WeakPtr
At the moment, nested browsing contexts expect that there's always a
top-level browsing context at some higher level. That's okay, but let's
keep the top-level pointer in a WeakPtr to make it easier to catch
mistakes (as this turns UAF into a null dereference.)
2021-09-08 11:19:27 +02:00
Andreas Kling
3a7e26ef28 LibWeb: Rename frame_did_set_viewport_rect() => browsing_context_*()
Names are still catching up after the Frame => BrowsingContext rename.
2021-09-08 11:12:22 +02:00
Andreas Kling
9d9500989a LibWeb: Remove unused PageClient::is_multi_process() 2021-09-08 11:07:14 +02:00
Andreas Kling
76b0253b6b LibWeb: Convert BrowsingContext to east-const style 2021-09-08 11:07:14 +02:00
Andreas Kling
57fbeff925 LibWeb: Use delegating constructors in BrowsingContext
This avoids having two nearly-identical initializer lists and and an
awkward setup() function that every constructor must call.
2021-09-08 11:07:14 +02:00
Andreas Kling
dfa9dcca98 LibWeb+Browser: Remove unnecessary InProcessWebView.h includes 2021-08-24 16:37:28 +02:00
Timothy Flynn
f7acd6aca5 LibWeb: Handle when the last selected node does not contain text
If the text-for-rendering of the last selected node is empty, the select
all implementation would end up setting the index to -1. This value is
used directly for a substring length in the copy text implementation,
thus would cause a failed assertion.
2021-07-14 17:16:39 +02:00
Timothy Flynn
fea7e84b26 LibWeb: Move select-all implementation to BrowsingContext 2021-07-14 17:16:39 +02:00
Andreas Kling
f670adb298 LibWeb: Avoid HashMap copy in BrowsingContext::set_frame_nesting_levels 2021-07-10 13:24:46 +02:00
Paul Irwin
5eb65286b6 LibWeb: Support :active pseudo-class for hyperlinks, :focus possibly
Adds support for the :active pseudo-class for hyperlinks (<a> tags
only).

Also, since it was very similar to :focus and an element having a
focused state was already implemented, I went ahead and implemented
that pseudo-class too, although I cannot come up with a working
example to validate it.
2021-06-25 01:02:29 +02:00
Andreas Kling
ee3a73ddbb AK: Rename downcast<T> => verify_cast<T>
This makes it much clearer what this cast actually does: it will
VERIFY that the thing we're casting is a T (using is<T>()).
2021-06-24 19:57:01 +02:00
DexesTTP
e01f1c949f AK: Do not VERIFY on invalid code point bytes in UTF8View
The previous behavior was to always VERIFY that the UTF-8 bytes were
valid when iterating over the code points of an UTF8View. This change
makes it so we instead output the 0xFFFD 'REPLACEMENT CHARACTER'
code point when encountering invalid bytes, and keep iterating the
view after skipping one byte.

Leaving the decision to the consumer would break symmetry with the
UTF32View API, which would in turn require heavy refactoring and/or
code duplication in generic code such as the one found in
Gfx::Painter and the Shell.

To make it easier for the consumers to detect the original bytes, we
provide a new method on the iterator that returns a Span over the
data that has been decoded. This method is immediately used in the
TextNode::compute_text_for_rendering method, which previously did
this in a ad-hoc waay.

This also add tests for the new behavior in TestUtf8.cpp, as well
as reinforcements to the existing tests to check if the underlying
bytes match up with their expected values.
2021-06-03 18:28:27 +04:30
Andreas Kling
12a42edd13 Everywhere: codepoint => code point 2021-06-01 10:01:11 +02:00
Andreas Kling
4190fd2199 LibWeb: Rename Web::Frame to Web::BrowsingContext
Our "frame" concept very closely matches what the web specs call a
"browsing context", so let's rename it to that. :^)

The "main frame" becomes the "top-level browsing context",
and "sub-frames" are now "nested browsing contexts".
2021-05-30 12:39:53 +02:00
Max Wipfli
9440a3c280 LibWeb: Improve Unicode compatibility of HTML contenteditable
This patch updates the Page::keydown_event event handler to implement
crude Unicode support. It implements new method in EditEventHandler to
more easily handle deleting a single character after the cursor.
Furthermore, it makes use of the previously implemented methods to
increment and decrement the cursor position, which take into account
that Unicode codepoint may be multiple bytes wide.

This means it is now possible to mostly edit Unicode in editable DOM
nodes without any crashes. :^)
2021-05-21 21:57:03 +02:00
Max Wipfli
7181cb3a9c LibWeb: Frame/Position: Implement cursor increment/decrement methods
This introduces methods to increment and decrement the cursor position.
This is non-trivial as the cursor position is specified in bytes rather
than codepoints. Thus, it sometimes needs to be incremented or
decremented by more than one, depending on the codepoint to "jump over".

Because the cursor blink cycle needs to be reset after moving the
cursor, methods calling the ones in DOM::Position are implemented in
Frame. Furthermore, this allows the cursor_position() getter to stay
const. :^)

Additionally, it adds a offset_is_at_end_of_node() method which checks
if the current offset points to the end of the node.
2021-05-21 21:57:03 +02:00
Max Wipfli
08d09c4afb LibWeb: Improving cursor behavior in editable DOM nodes
This patch makes two modifications to improve the behavior of cursors in
editable DOM nodes, such as HTML tags with the contenteditable
attribute.

When the cursor blink cycle is reset in an editable DOM node, a repaint
should be initiated. For this, set_needs_display() needs to be called on
the layout node. Previously, the cursor blink cycle would not reset
properly and moving the cursor with the arrow keys did not feel
intuitive.

Furthermore, this modifies one of the conditions necessary to actually
paint the cursor, which previously prevented it from being painted when
at the end of a text node, after all the text present.
2021-05-21 21:57:03 +02:00
Max Wipfli
d7df6de6a6 LibWeb: Do nothing when pressing modifier keys in HTML contenteditable
Before this patch, pressing modifier keys such as Ctrl would insert
whitespace into editable DOM nodes. This patch crudely fixes that
behavior by checking if the codepoint associated with the event is
non-zero.
2021-05-21 21:57:03 +02:00
Max Wipfli
157f72e9d7 LibWeb: Replace some TODO() calls with FIXME comments in EventHandler
This patch downgrades some TODO() calls when the cursor in an editable
DOM node should move to the previous or next node. Previously, the
process would crash, whereas now, the cursor will just stay where it
was.

This seems more sensible for now, as there is no reason to crash just
because of this.
2021-05-21 21:57:03 +02:00
Tobias Christiansen
1b6824d296 LibWeb: Make frames nesting-aware and disallow deep nesting
A Frame now knows about its nesting-level.

The FrameLoader checks whether the recursion level of the current
frame allows it to be displayed and if not doesn't even load the
requested resource.

The nesting-check is done on a per-URL-basis, so there can be many many
nested Frames as long as they have different URLs.
If there are however Frames with the same URL nested inside each other
we only allow this to happen 3 times.

This mitigates infinetely recursing <iframe>s in an HTML-document
crashing the browser with an OOM.
2021-05-07 22:34:34 +02:00
Matthew Olsson
88cfaf7bf0 LibGfx: Unify Rect, Point, and Size
This commit unifies methods and method/param names between the above
classes, as well as adds [[nodiscard]] and ALWAYS_INLINE where
appropriate. It also renamed the various move_by methods to
translate_by, as that more closely matches the transformation
terminology.
2021-05-02 22:48:06 +02:00
Andreas Kling
b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Andreas Kling
e4df1b223f LibWeb: Implement a slow but functional HTMLCollection :^)
HTMLCollection is an awkward legacy interface from the DOM spec.

It provides a live view of a DOM subtree, with some kind of filtering
that determines which elements are part of the collection.

We now return HTMLCollection objects from these APIs:

- getElementsByClassName()
- getElementsByName()
- getElementsByTagName()

This initial implementation does not do any kind of caching, since that
is quite a tricky problem, and there will be plenty of time for tricky
problems later on when the engine is more mature.
2021-04-22 21:21:46 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Timothy Flynn
2381b19719 Browser+LibWeb+WebContent: Parse cookies in the OOP tab
To protect the main Browser process against nefarious cookies, parse the
cookies out-of-process and then send the parsed result over IPC to the
main process. This way, if the cookie parser blows up, only that tab
will be affected.
2021-04-16 19:19:31 +02:00
Nicholas-Baron
c4ede38542 Everything: Add -Wnon-virtual-dtor flag
This flag warns on classes which have `virtual` functions but do not
have a `virtual` destructor.

This patch adds both the flag and missing destructors. The access level
of the destructors was determined by a two rules of thumb:
1. A destructor should have a similar or lower access level to that of a
   constructor.
2. Having a `private` destructor implicitly deletes the default
   constructor, which is probably undesirable for "interface" types
   (classes with only virtual functions and no data).

In short, most of the added destructors are `protected`, unless the
compiler complained about access.
2021-04-15 20:57:13 +02:00
Idan Horowitz
ad8e2f481d LibWeb: Expose the MouseEvent::{clientX, clientY} attributes
These provide the cursor coordinate within the viewport at which the
event occurred (as opposed to the page relative coordinates exposed via
offsetX, offsetY).
2021-04-15 20:22:08 +02:00
Timothy Flynn
c00760c5f9 Browser+LibWeb+WebContent: Track the source of document.cookie requests
To implement the HttpOnly attribute, the CookieJar needs to know where a
request originated from. Namely, it needs to distinguish between HTTP /
non-HTTP (i.e. JavaScript) requests. When the HttpOnly attribute is set,
requests from JavaScript are to be blocked.
2021-04-14 16:07:46 +02:00
Timothy Flynn
1ef48d50ff LibWeb+WebContent: Hook document.cookie to the backend cookie storage 2021-04-11 18:24:34 +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
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
Timothy Flynn
c503047c71 LibWeb: Get the first DOM node with a 'title' attribute for tooltip area
Rather than expecting the first parent to have a 'title' attribute,
search all ancestors.
2021-03-30 21:21:17 +02:00
Linus Groh
c183ebc723 LibWeb: Only call page_did_change_title() from main frame
Otherwise an embedded iframe will override the page title in the
browser, for example.
2021-03-21 09:36:37 +01:00
Andreas Kling
efc6060df0 LibWeb: Dispatch "resize" events on the Window object
It's a little awkward that we do this in two places, but IPWV and OOPWV
currently implement resizing a little differently from each other so we
need to cover both paths.
2021-03-16 18:10:21 +01:00
Angus Gibson
0e881bc5d7 LibWeb: Handle scrolling an OutOfProcessWebView
When a mousewheel scroll event isn't handled by the web content
itself (e.g. an overflowed box or similar), the event needs to get
passed back up to the OutOfProcessWebView.
2021-03-02 13:20:03 +01:00
Angus Gibson
e9c1d9c89a LibWeb: Return whether handle_mousewheel was handled
We try scrolling a Node with the handle_mousewheel event, but if it
isn't scrollable, the event should be passed back up to the page
host. This is the first step in that process.
2021-03-02 13:20:03 +01:00
Adam Hodgen
fc9225db33 LibWeb: Call page_did_request_cursor_change with CSS cursor 2021-02-28 18:19:52 +01:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
cd79b807dd LibWeb: Allow scrolling overflowed content with the mouse wheel :^)
This is rather crude, but you can now use the mouse wheel to scroll up
and down in block-level boxes with clipped overflowing content.
There's no limit to how far you can scroll in either direction, since
we don't yet track how much overflow there is. But it's a start. :^)
2021-02-22 21:47:00 +01:00
Andreas Kling
ded8c728d2 LibWeb: Plumb wheel events from widget layer to EventHandler 2021-02-22 21:46:54 +01:00
Linus Groh
5e07c27e25 LibWeb: Implement Window.prompt() 2021-02-20 12:19:46 +01:00
Andreas Kling
2323b6fb74 LibWeb: Use the correct DOM node when moving text cursor with mouse
We should use the DOM node returned by the TextCursor hit test,
and not the one we got from the earlier Exact hit test.
2021-02-15 23:25:29 +01:00
Andreas Kling
c51209a06a LibWeb: Move cursor along when drag-selecting in editable content 2021-02-15 18:12:14 +01:00
Andreas Kling
5e91e61900 LibWeb: Remove WidgetBox layout node
The approach of attaching sub-widgets to the web view widget was only
ever going to work in single-process mode, and that's not what we're
about anymore, so let's just get rid of WidgetBox so we don't have the
dead-end architecture hanging over us.

The next step here is to re-implement <input type=text> using LibWeb
primitives.
2021-02-10 09:13:30 +01:00
Andreas Kling
abf7c02acb LibWeb: Move window.confirm() to using a PageClient callback
This allows us to move the GUI::MessageBox out of DOM::Window and up to
the widget layer.
2021-02-10 09:13:30 +01:00
Andreas Kling
794ebb699c LibWeb: Remove low-hanging LibGUI fruit from LibWeb
We'll want to remove the LibGUI dependency from the WebContent process.
This is the first basic step of removing unnecessary LibGUI includes
and swapping out GUI::Painter for Gfx::Painter.
2021-02-10 09:13:29 +01:00
Andreas Kling
9de1253f44 LibWeb: Remove a whole bunch of unnecessary #includes 2021-02-10 09:13:29 +01:00
Andreas Kling
f24b674d7a LibWeb+WebContent: Don't relayout page on every scroll event
The WebContent process was redoing page layout every time you scrolled
the page. This was a huge CPU hog for no reason. Fix this by only doing
a relayout when the viewport is resized, not when it moves around.
2021-02-09 22:40:16 +01:00
Andreas Kling
ace1b34798 LibWeb: Reset the HTML editing cursor blink cycle on arrow key movement
Also stop exposing the DOM cursor as a mutable reference on Frame,
since event handling code was using that to mess with the text offset
directly. Setting the cursor now always goes through the Frame where
we can reset the blink cycle appropriately.

This makes cursor movement look a lot more natural. :^)
2021-02-09 21:25:38 +01:00
Andreas Kling
2c4829cb14 LibWeb: Remove duplicated locals in EventHandler::handle_mousedown() 2021-02-09 20:49:37 +01:00
Andreas Kling
74c8490acd LibWeb: Don't try to create GUI::TextBox inside multi-process web views
This is a workaround until we can implement a proper <input type=text>
in terms of LibWeb primitives.

This makes google.com not crash in multi-process mode (but there is no
search box.)
2021-01-30 23:16:41 +01:00
Andreas Kling
9b0ca75f84 LibWeb: Add Frame::ViewportClient and use it for Layout::ImageBox
Image boxes want to know whether they are inside the visible viewport.
This is used to pause/resume animations, and to update the purgeable
memory volatility state.

Previously we would traverse the entire layout tree on every resize,
calling a helper on each ImageBox. Make those boxes register with the
frame they are interested in instead, saving us all that traversal.

This also makes it easier for other parts of the code to learn about
viewport changes in the future. :^)
2021-01-30 12:29:11 +01:00
Andreas Kling
0324144e2a LibWeb: Update the ICB's idea of the viewport rect after Frame resize
This makes animations start if they are uncovered by a resize.
2021-01-29 22:03:04 +01:00
Ben Wiederhake
67cda61b7f Libraries: Add missing headers
A C++ source file containing just
    #include <LibFoo/Bar.h>
should always compile cleanly.

This patch adds missing header inclusions that could have caused weird error
messages if they were used in a different context. Also, this confused QtCreator.
2021-01-22 21:49:54 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00