Skip to content

Commit

Permalink
LibWeb: Add internals.wheel() to siulate mouse wheel events
Browse files Browse the repository at this point in the history
This function allows us to write tests for scrolling scenarios where
the events are processed by the EventHandler.
  • Loading branch information
kalenikaliaksandr committed Feb 9, 2024
1 parent 76d1536 commit 8bbdff3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Tests/LibWeb/Ref/reference/scroll-using-mousewheel-event-ref.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<style>
.item {
width: 100px;
height: 100px;
box-sizing: border-box;
border: 1px solid black;
}
</style>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
28 changes: 28 additions & 0 deletions Tests/LibWeb/Ref/scroll-using-mousewheel-event.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<link rel="match" href="reference/scroll-using-mousewheel-event-ref.html" />
<style>
.scrollable {
overflow-y: scroll;
width: 100px;
height: 300px;
}

.item {
width: 100px;
height: 100px;
box-sizing: border-box;
border: 1px solid black;
}
</style>
<div class="scrollable">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
</div>
<script>
internals.wheel(10, 10, 0, 100);
</script>
6 changes: 6 additions & 0 deletions Userland/Libraries/LibWeb/Internals/Internals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ void Internals::click(double x, double y)
page.handle_mouseup({ x, y }, { x, y }, 1, 0, 0);
}

void Internals::wheel(double x, double y, double delta_x, double delta_y)
{
auto& page = global_object().browsing_context()->page();
page.handle_mousewheel({ x, y }, { x, y }, 0, 0, 0, delta_x, delta_y);
}

WebIDL::ExceptionOr<bool> Internals::dispatch_user_activated_event(DOM::EventTarget& target, DOM::Event& event)
{
event.set_is_trusted(true);
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/Internals/Internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Internals final : public Bindings::PlatformObject {
void commit_text();

void click(double x, double y);
void wheel(double x, double y, double delta_x, double delta_y);

WebIDL::ExceptionOr<bool> dispatch_user_activated_event(DOM::EventTarget&, DOM::Event& event);

Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibWeb/Internals/Internals.idl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
undefined commitText();

undefined click(double x, double y);
undefined wheel(double x, double y, double deltaX, double deltaY);

boolean dispatchUserActivatedEvent(EventTarget target, Event event);

Expand Down

0 comments on commit 8bbdff3

Please sign in to comment.