/** * @return The (-left, -top) position of the current region. */ public Location getNegativeLocation() { return new Location(-left, -top); }
Location result = new Location(location); result = result.offset(frameLocationInScreenshot.getX(), frameLocationInScreenshot.getY()); result = result.offset(-regionWindow.getLeft(), -regionWindow.getTop()); result = result.offset(-frameLocationInScreenshot.getX(), -frameLocationInScreenshot.getY()); switch (to) { case CONTEXT_RELATIVE: result = result.offset(currentFrameScrollPosition.getX(), currentFrameScrollPosition.getY()); break; result = result.offset(frameLocationInScreenshot.getX(), frameLocationInScreenshot.getY()); break; result = result.offset(-currentFrameScrollPosition.getX(), -currentFrameScrollPosition.getY()); result = result.offset(frameLocationInScreenshot.getX(), frameLocationInScreenshot.getY()); result = result.offset(-currentFrameScrollPosition.getX(), -currentFrameScrollPosition.getY()); break;
/** * Scrolls to the specified location inside the element. * @param location The location to scroll to. */ public Location scrollTo(Location location) { Object position = eyesDriver.executeScript(String.format(JS_SCROLL_TO_FORMATTED_STR, location.getX(), location.getY()) + JS_GET_SCROLL_POSITION, this); String[] xy = position.toString().split(";"); if (xy.length != 2) { throw new EyesException("Could not get scroll position!"); } float x = Float.parseFloat(xy[0]); float y = Float.parseFloat(xy[1]); return new Location((int) Math.ceil(x), (int) Math.ceil(y)); }
/** * Get an offset region. * @param dx The X axis offset. * @param dy The Y axis offset. * @return A region with an offset location. */ public Region offset(int dx, int dy) { return new Region(getLocation().offset(dx, dy), getSize(), getCoordinatesType()); }
public int getY() { return position.getY(); } }
public int getX() { return position.getX(); }
/** * Get a region which is a scaled version of the current region. * IMPORTANT: This also scales the LOCATION(!!) of the region (not just its size). * @param scaleRatio The ratio by which to scale the region. * @return A new region which is a scaled version of the current region. */ public Region scale(double scaleRatio) { return new Region(getLocation().scale(scaleRatio), getSize().scale(scaleRatio), getCoordinatesType()); }
public static Location calcFrameLocationInScreenshot(Logger logger, EyesWebDriver driver, FrameChain frameChain, ScreenshotType screenshotType) { Location windowScroll = getDefaultContentScrollPosition(logger, frameChain, driver); logger.verbose("Getting first frame..."); Iterator<Frame> frameIterator = frameChain.iterator(); Frame firstFrame = frameIterator.next(); logger.verbose("Done!"); Location locationInScreenshot = new Location(firstFrame.getLocation()); // We only consider scroll of the default content if this is a viewport screenshot. if (screenshotType == ScreenshotType.VIEWPORT) { locationInScreenshot = locationInScreenshot.offset(-windowScroll.getX(), -windowScroll.getY()); } logger.verbose("Iterating over frames..."); Frame frame; while (frameIterator.hasNext()) { logger.verbose("Getting next frame..."); frame = frameIterator.next(); logger.verbose("Done!"); Location frameLocation = frame.getLocation(); // For inner frames we must consider the scroll Location frameOriginalLocation = frame.getOriginalLocation(); // Offsetting the location in the screenshot locationInScreenshot = locationInScreenshot.offset( frameLocation.getX() - frameOriginalLocation.getX(), frameLocation.getY() - frameOriginalLocation.getY()); } logger.verbose("Done!"); return locationInScreenshot; }
public void mouseMove(Coordinates where, long xOffset, long yOffset) { Location location = EyesSeleniumUtils.getPageLocation(where); logger.verbose("mouseMove(" + location + ", " + xOffset + ", " + yOffset + ")"); int newX, newY; if (location != null) { newX = (int)(location.getX() + xOffset); newY = (int)(location.getY() + yOffset); } else { newX = (int)(mouseLocation.getX() + xOffset); newY = (int)(mouseLocation.getY() + yOffset); } if (newX < 0) { newX = 0; } if (newY < 0) { newY = 0; } mouseLocation = new Location(newX, newY); addMouseTrigger(MouseAction.Move); mouse.mouseMove(where, xOffset, yOffset); }
/** * Get an offset region. * @param dx The X axis offset. * @param dy The Y axis offset. * @return A region with an offset location. */ public Region offset(int dx, int dy) { return new Region(getLocation().offset(dx, dy), getSize(), getCoordinatesType()); }
public int getY() { return position.getY(); } }
public int getX() { return position.getX(); }
/** * Get a region which is a scaled version of the current region. * IMPORTANT: This also scales the LOCATION(!!) of the region (not just its size). * @param scaleRatio The ratio by which to scale the region. * @return A new region which is a scaled version of the current region. */ public Region scale(double scaleRatio) { return new Region(getLocation().scale(scaleRatio), getSize().scale(scaleRatio), getCoordinatesType()); }
public void mouseMove(Coordinates where) { Location location = EyesSeleniumUtils.getPageLocation(where); logger.verbose("mouseMove(" + location + ")"); if (location != null) { int newX = Math.max(0, location.getX()); int newY = Math.max(0, location.getY()); mouseLocation = new Location(newX, newY); addMouseTrigger(MouseAction.Move); } mouse.mouseMove(where); }