/** * Get a location translated by the specified amount. * * @param amount The amount to offset. * @return A location translated by the specified amount. */ public Location offset(Location amount) { return offset(amount.getX(), amount.getY()); }
/** * Get a location translated by the specified amount. * * @param amount The amount to offset. * @return A location translated by the specified amount. */ public Location offset(Location amount) { return offset(amount.getX(), amount.getY()); }
/** * @return The location of the current frame in the page. */ public Location getCurrentFrameOffset() { Location result = new Location(0, 0); for (Frame frame : frames) { result = result.offset(frame.getLocation()); } return result; }
/** * 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()); }
/** * 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()); }
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; result = result.offset(-frameLocationInScreenshot.getX(),
/** * Returns a location based on the given location. * @param logger The logger to use. * @param element The element for which we want to find the content's * location. * @param location The location of the element. * @return The location of the content of the element. */ public static Location getLocation(Logger logger, WebElement element, Location location) { ArgumentGuard.notNull(logger, "logger"); ArgumentGuard.notNull(element, "element"); ArgumentGuard.notNull(location, "location"); logger.verbose(String.format( "BordersAdditionFrameLocationProvider(logger, element, %s)", location)); // Frame borders also have effect on the frame's location. int leftBorderWidth = getPropertyValue(logger, element, "border-left-width"); int topBorderWidth = getPropertyValue(logger, element, "border-top-width"); Location contentLocation = new Location(location).offset(leftBorderWidth, topBorderWidth); logger.verbose("Done!"); return contentLocation; }
@Override protected Location convertLocation(Location location, CoordinatesType from, CoordinatesType to) { ArgumentGuard.notNull(location, "location"); ArgumentGuard.notNull(from, "from"); ArgumentGuard.notNull(to, "to"); Location result = new Location(location); if (from == to) { return result; } switch (from) { case SCREENSHOT_AS_IS: if (to == CoordinatesType.CONTEXT_RELATIVE) { result.offset(bounds.getLeft(), bounds.getTop()); } else { throw new CoordinatesTypeConversionException(from, to); } break; case CONTEXT_RELATIVE: if (to == CoordinatesType.SCREENSHOT_AS_IS) { result.offset(-bounds.getLeft(), -bounds.getTop()); } else { throw new CoordinatesTypeConversionException(from, to); } break; default: throw new CoordinatesTypeConversionException(from, to); } return result; }
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; }
case SCREENSHOT_AS_IS: if (to == CoordinatesType.CONTEXT_RELATIVE) { result.offset(bounds.getLeft(), bounds.getTop()); } else { throw new CoordinatesTypeConversionException(from, to); result.offset(-bounds.getLeft(), -bounds.getTop()); } else { throw new CoordinatesTypeConversionException(from, to);
Location targetPosition = originPosition.offset(-fullArea.getLeft(), -fullArea.getTop()); logger.verbose(String.format("Origin Position is set to %s", originPosition)); logger.verbose(String.format("Target Position is %s", targetPosition));