void RootFrameViewport::setScrollOffset(const DoublePoint& offset, ScrollType scrollType)
{
    // Make sure we use the scroll positions as reported by each viewport's ScrollAnimator, since its
    // ScrollableArea's position may have the fractional part truncated off.
    DoublePoint oldPosition = scrollOffsetFromScrollAnimators();

    DoubleSize delta = offset - oldPosition;

    if (delta.isZero())
        return;

    ScrollableArea& primary = !m_invertScrollOrder ? layoutViewport() : visualViewport();
    ScrollableArea& secondary = !m_invertScrollOrder ? visualViewport() : layoutViewport();

    DoublePoint targetPosition = primary.clampScrollPosition(primary.scrollAnimator()->currentPosition() + delta);
    primary.setScrollPosition(targetPosition, scrollType);

    DoubleSize applied = scrollOffsetFromScrollAnimators() - oldPosition;
    delta -= applied;

    if (delta.isZero())
        return;

    targetPosition = secondary.clampScrollPosition(secondary.scrollAnimator()->currentPosition() + delta);
    secondary.setScrollPosition(targetPosition, scrollType);
}
Example #2
0
LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent,
                                             const ScrollAlignment& alignX,
                                             const ScrollAlignment& alignY,
                                             ScrollType scrollType) {
  // We want to move the rect into the viewport that excludes the scrollbars so
  // we intersect the visual viewport with the scrollbar-excluded frameView
  // content rect. However, we don't use visibleContentRect directly since it
  // floors the scroll offset. Instead, we use ScrollAnimatorBase::currentOffset
  // and construct a LayoutRect from that.
  LayoutRect frameRectInContent =
      LayoutRect(FloatPoint(layoutViewport().scrollAnimator().currentOffset()),
                 FloatSize(layoutViewport().visibleContentRect().size()));
  LayoutRect visualRectInContent =
      LayoutRect(FloatPoint(scrollOffsetFromScrollAnimators()),
                 FloatSize(visualViewport().visibleContentRect().size()));

  // Intersect layout and visual rects to exclude the scrollbar from the view
  // rect.
  LayoutRect viewRectInContent =
      intersection(visualRectInContent, frameRectInContent);
  LayoutRect targetViewport = ScrollAlignment::getRectToExpose(
      viewRectInContent, rectInContent, alignX, alignY);
  if (targetViewport != viewRectInContent) {
    setScrollOffset(ScrollOffset(targetViewport.x(), targetViewport.y()),
                    scrollType);
  }

  // RootFrameViewport only changes the viewport relative to the document so we
  // can't change the input rect's location relative to the document origin.
  return rectInContent;
}
void RootFrameViewport::distributeScrollBetweenViewports(const DoublePoint& offset, ScrollType scrollType, ScrollBehavior behavior)
{
    // Make sure we use the scroll positions as reported by each viewport's ScrollAnimatorBase, since its
    // ScrollableArea's position may have the fractional part truncated off.
    DoublePoint oldPosition = scrollOffsetFromScrollAnimators();

    DoubleSize delta = offset - oldPosition;

    if (delta.isZero())
        return;

    DoublePoint targetPosition = visualViewport().clampScrollPosition(
        visualViewport().scrollAnimator().currentPosition() + delta);

    visualViewport().setScrollPosition(targetPosition, scrollType, behavior);

    // Scroll the secondary viewport if all of the scroll was not applied to the
    // primary viewport.
    DoublePoint updatedPosition = layoutViewport().scrollAnimator().currentPosition() + FloatPoint(targetPosition);
    DoubleSize applied = updatedPosition - oldPosition;
    delta -= applied;

    if (delta.isZero())
        return;

    targetPosition = layoutViewport().clampScrollPosition(layoutViewport().scrollAnimator().currentPosition() + delta);
    layoutViewport().setScrollPosition(targetPosition, scrollType, behavior);
}
Example #4
0
void RootFrameViewport::distributeScrollBetweenViewports(
    const ScrollOffset& offset,
    ScrollType scrollType,
    ScrollBehavior behavior,
    ViewportToScrollFirst scrollFirst) {
  // Make sure we use the scroll offsets as reported by each viewport's
  // ScrollAnimatorBase, since its ScrollableArea's offset may have the
  // fractional part truncated off.
  // TODO(szager): Now that scroll offsets are stored as floats, can we take the
  // scroll offset directly from the ScrollableArea's rather than the animators?
  ScrollOffset oldOffset = scrollOffsetFromScrollAnimators();

  ScrollOffset delta = offset - oldOffset;

  if (delta.isZero())
    return;

  ScrollableArea& primary =
      scrollFirst == VisualViewport ? visualViewport() : layoutViewport();
  ScrollableArea& secondary =
      scrollFirst == VisualViewport ? layoutViewport() : visualViewport();

  ScrollOffset targetOffset = primary.clampScrollOffset(
      primary.scrollAnimator().currentOffset() + delta);

  primary.setScrollOffset(targetOffset, scrollType, behavior);

  // Scroll the secondary viewport if all of the scroll was not applied to the
  // primary viewport.
  ScrollOffset updatedOffset =
      secondary.scrollAnimator().currentOffset() + FloatSize(targetOffset);
  ScrollOffset applied = updatedOffset - oldOffset;
  delta -= applied;

  if (delta.isZero())
    return;

  targetOffset = secondary.clampScrollOffset(
      secondary.scrollAnimator().currentOffset() + delta);
  secondary.setScrollOffset(targetOffset, scrollType, behavior);
}
Example #5
0
void RootFrameViewport::updateScrollAnimator() {
  scrollAnimator().setCurrentOffset(
      toFloatSize(scrollOffsetFromScrollAnimators()));
}
void RootFrameViewport::updateScrollAnimator()
{
    scrollAnimator()->setCurrentPosition(toFloatPoint(scrollOffsetFromScrollAnimators()));
}