Sha256: 10bf58c5312d5c06594d7025c3e0a2f0fea0f56d442a9d1c0778e6b953cb0afd

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

module Watir
  module DragAndDropHelper

    def drag_and_drop_on(target)
      perform_action do
        assert_target target
        drop_x, drop_y = target.send :source_x_y
        drag_to drop_x, drop_y
      end
    end

    def drag_and_drop_by(distance_x, distance_y)
      perform_action do
        drag_x, drag_y = source_x_y
        drag_to drag_x + distance_x, drag_y + distance_y
      end
    end

    private

    def drag_to(drop_x, drop_y)
      drag_x, drag_y = source_x_y
      mouse = page_container.rautomation.mouse
      mouse.move :x => drag_x , :y => drag_y
      mouse.press
      mouse.move :x => drop_x, :y => drop_y
      mouse.release
    end

    def source_x_y
      center_x_y_absolute left_edge_absolute, top_edge_absolute
    end

    def assert_target(target)
      target.assert_exists
      target.assert_enabled
    end

    def top_edge
      ole_object.getBoundingClientRect(0).top.to_i
    end

    def top_edge_absolute
      top_edge + page_container.document.parentWindow.screenTop.to_i
    end

    def left_edge
      ole_object.getBoundingClientRect(0).left.to_i
    end

    def left_edge_absolute
      left_edge + page_container.document.parentWindow.screenLeft.to_i
    end

    def right_edge
      ole_object.getBoundingClientRect(0).right.to_i
    end

    def bottom_edge
      ole_object.getBoundingClientRect(0).bottom.to_i
    end

    def center_x_y_absolute x, y
      return (right_edge - left_edge) / 2 + x, (bottom_edge - top_edge) / 2 + y
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
watir-classic-3.0.0 lib/watir-classic/drag_and_drop_helper.rb