Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
the browser; a failed `IO.close` is raised to the caller.

### Fixed
- `Mouse#move` with a button held didn't send which button, so Chrome never started a drag. Native HTML5 drag and drop
now works with `down`, `move` and `up`, and `Input.dragIntercepted` fires when drags are intercepted [#635]
- An out-of-process iframe, e.g. Chrome's PDF viewer for an embedded PDF, appearing while a web worker was connected
raised `'Page.enable' wasn't found` in the event thread. Only pages and iframes are now searched for its parent [#640]
- A browser that stopped reading its websocket froze the whole client: a large command blocked in a socket write
Expand Down
6 changes: 6 additions & 0 deletions lib/ferrum/mouse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def move(x:, y:, steps: 1)
from_y = @y
@x = x
@y = y
button = pressed_button

steps.times do |i|
new_x = from_x + ((@x - from_x) * ((i + 1) / steps.to_f))
Expand All @@ -162,6 +163,7 @@ def move(x:, y:, steps: 1)
type: "mouseMoved",
x: new_x,
y: new_y,
button: button,
buttons: @buttons)
end

Expand All @@ -185,6 +187,10 @@ def validate_button(button)
button
end

def pressed_button
BUTTON_MASKS.find { |_name, mask| mask.positive? && @buttons.anybits?(mask) }&.first || "none"
end

def register_event_button(type, button)
case type
when "mousePressed"
Expand Down
2 changes: 2 additions & 0 deletions sig/ferrum/mouse.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module Ferrum

def validate_button: (Symbol button) -> String

def pressed_button: () -> String

def register_event_button: (String type, String button) -> ::Integer
end
end
8 changes: 8 additions & 0 deletions spec/mouse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
end

describe "#move" do
it "drags and drops with a button held" do
browser.go_to("/html5_drag")

browser.mouse.move(x: 10, y: 10).down.move(x: 250, y: 50, steps: 10).up

expect(browser.evaluate("window.events")).to eq(%w[dragstart dragover drop dragend])
end

it "splits into steps" do
browser.go_to("/simple")
browser.mouse.move(x: 100, y: 100)
Expand Down
33 changes: 33 additions & 0 deletions spec/support/views/html5_drag.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title>ferrum html5 drag and drop</title>
<link rel="icon" href="data:,">
<style>
#source, #target { position: fixed; top: 0; width: 100px; height: 100px; }
#source { left: 0; background: red; }
#target { left: 200px; background: blue; }
</style>
<script>
window.events = [];
document.addEventListener("DOMContentLoaded", () => {
const source = document.getElementById("source");
const target = document.getElementById("target");
for (const type of ["dragstart", "dragend"]) {
source.addEventListener(type, () => window.events.push(type));
}
for (const type of ["dragover", "drop"]) {
target.addEventListener(type, event => {
event.preventDefault();
if (!window.events.includes(type)) window.events.push(type);
});
}
});
</script>
</head>
<body>
<div id="source" draggable="true"></div>
<div id="target"></div>
</body>
</html>
Loading