diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a97178d..b325992f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/ferrum/mouse.rb b/lib/ferrum/mouse.rb index 6e5a8f9e..f34985e5 100644 --- a/lib/ferrum/mouse.rb +++ b/lib/ferrum/mouse.rb @@ -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)) @@ -162,6 +163,7 @@ def move(x:, y:, steps: 1) type: "mouseMoved", x: new_x, y: new_y, + button: button, buttons: @buttons) end @@ -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" diff --git a/sig/ferrum/mouse.rbs b/sig/ferrum/mouse.rbs index 45d57253..7d87eeeb 100644 --- a/sig/ferrum/mouse.rbs +++ b/sig/ferrum/mouse.rbs @@ -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 diff --git a/spec/mouse_spec.rb b/spec/mouse_spec.rb index e823bbbc..df683516 100644 --- a/spec/mouse_spec.rb +++ b/spec/mouse_spec.rb @@ -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) diff --git a/spec/support/views/html5_drag.erb b/spec/support/views/html5_drag.erb new file mode 100644 index 00000000..34d7869f --- /dev/null +++ b/spec/support/views/html5_drag.erb @@ -0,0 +1,33 @@ + + +
+ +