Search in sources :

Example 1 with MouseEvent

use of elemental2.dom.MouseEvent in project kie-wb-common by kiegroup.

the class DragAndDropHelper method onDragAreaMouseDown.

Object onDragAreaMouseDown(final Event e) {
    final MouseEvent event = (MouseEvent) e;
    if (!Objects.isNull(event.target)) {
        final Element grabber = ((Element) event.target).closest(".drag-grabber");
        if (Objects.isNull(grabber)) {
            return this;
        }
        draggingElement = (HTMLElement) grabber.closest(DRAGGABLE_ITEM_CLASS);
        clickedYPosition = (int) event.clientY;
        startYPosition = getTop(getDragging());
    }
    return this;
}
Also used : MouseEvent(elemental2.dom.MouseEvent) Element(elemental2.dom.Element) HTMLElement(elemental2.dom.HTMLElement)

Example 2 with MouseEvent

use of elemental2.dom.MouseEvent in project kie-wb-common by kiegroup.

the class DNDListComponentViewTest method testGetNewDraggingYPosition.

@Test
public void testGetNewDraggingYPosition() {
    final MouseEvent event = mock(MouseEvent.class);
    final HTMLElement draggingElement = mock(HTMLElement.class);
    final DOMRect rect = mock(DOMRect.class);
    event.y = 100;
    rect.top = 25;
    draggingElement.style = mock(CSSStyleDeclaration.class);
    dragArea.offsetHeight = 300;
    when(presenter.getItemHeight()).thenReturn(50);
    when(dragArea.getBoundingClientRect()).thenReturn(rect);
    doReturn(draggingElement).when(view).getDragging();
    final int actualYPosition = view.getNewDraggingYPosition(event);
    final int expectedYPosition = 50;
    assertEquals(expectedYPosition, actualYPosition);
}
Also used : MouseEvent(elemental2.dom.MouseEvent) HTMLElement(elemental2.dom.HTMLElement) DOMRect(elemental2.dom.DOMRect) CSSStyleDeclaration(elemental2.dom.CSSStyleDeclaration) Test(org.junit.Test)

Example 3 with MouseEvent

use of elemental2.dom.MouseEvent in project kie-wb-common by kiegroup.

the class DNDListComponentViewTest method testGetNewDraggingYPositionWhenNewYPositionIsGreaterThanMax.

@Test
public void testGetNewDraggingYPositionWhenNewYPositionIsGreaterThanMax() {
    final MouseEvent event = mock(MouseEvent.class);
    final HTMLElement draggingElement = mock(HTMLElement.class);
    final DOMRect rect = mock(DOMRect.class);
    event.y = 1000;
    rect.top = 25;
    draggingElement.style = mock(CSSStyleDeclaration.class);
    dragArea.offsetHeight = 300;
    when(presenter.getItemHeight()).thenReturn(50);
    when(dragArea.getBoundingClientRect()).thenReturn(rect);
    doReturn(draggingElement).when(view).getDragging();
    final int actualYPosition = view.getNewDraggingYPosition(event);
    final int expectedYPosition = 325;
    assertEquals(expectedYPosition, actualYPosition);
}
Also used : MouseEvent(elemental2.dom.MouseEvent) HTMLElement(elemental2.dom.HTMLElement) DOMRect(elemental2.dom.DOMRect) CSSStyleDeclaration(elemental2.dom.CSSStyleDeclaration) Test(org.junit.Test)

Example 4 with MouseEvent

use of elemental2.dom.MouseEvent in project kie-wb-common by kiegroup.

the class DragAndDropHelperTest method testOnDragAreaMouseMove.

@Test
public void testOnDragAreaMouseMove() {
    final HTMLElement dragging = mock(HTMLElement.class);
    final HTMLElement oldElement = mock(HTMLElement.class);
    final MouseEvent event = mock(MouseEvent.class);
    final int newPosition = 2;
    final int oldPosition = 1;
    final int delta = 444;
    doReturn(dragging).when(helper).getDragging();
    doReturn(delta).when(helper).getDelta(event);
    doReturn(newPosition).when(helper).getNewPosition();
    doReturn(oldPosition).when(helper).position(dragging);
    doReturn(oldElement).when(helper).findElementByPosition(newPosition);
    doNothing().when(helper).swapElements(oldElement, dragging);
    doNothing().when(helper).setTop(dragging, delta);
    helper.onDragAreaMouseMove(event);
    verify(helper).swapElements(oldElement, dragging);
    verify(helper).setTop(dragging, delta);
}
Also used : MouseEvent(elemental2.dom.MouseEvent) HTMLElement(elemental2.dom.HTMLElement) Test(org.junit.Test)

Example 5 with MouseEvent

use of elemental2.dom.MouseEvent in project kie-wb-common by kiegroup.

the class DragAndDropHelper method onDragAreaMouseMove.

Object onDragAreaMouseMove(final Event e) {
    if (Objects.isNull(getDragging())) {
        return this;
    }
    final MouseEvent event = (MouseEvent) e;
    final int delta = getDelta(event);
    final int newPosition = getNewPosition();
    final int oldPosition = position(getDragging());
    if (newPosition != oldPosition) {
        swapElements(findElementByPosition(newPosition), getDragging());
    }
    setTop(getDragging(), startYPosition + delta);
    return this;
}
Also used : MouseEvent(elemental2.dom.MouseEvent)

Aggregations

MouseEvent (elemental2.dom.MouseEvent)10 HTMLElement (elemental2.dom.HTMLElement)8 Test (org.junit.Test)8 CSSStyleDeclaration (elemental2.dom.CSSStyleDeclaration)5 DOMRect (elemental2.dom.DOMRect)5 Element (elemental2.dom.Element)2