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;
}
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);
}
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);
}
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);
}
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;
}
Aggregations