Commit graph

179 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
Idan Horowitz
c5b924b1e6 LibWeb: Dispatch keydown/keyup events on the appropriate target 2021-10-01 20:14:45 +02:00