当前位置: 首页>>代码示例>>C++>>正文


C++ ScrollableArea::scrollIntoView方法代码示例

本文整理汇总了C++中ScrollableArea::scrollIntoView方法的典型用法代码示例。如果您正苦于以下问题:C++ ScrollableArea::scrollIntoView方法的具体用法?C++ ScrollableArea::scrollIntoView怎么用?C++ ScrollableArea::scrollIntoView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScrollableArea的用法示例。


在下文中一共展示了ScrollableArea::scrollIntoView方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: viewportSize

// Test that the scrollIntoView correctly scrolls the main frame
// and visual viewport such that the given rect is centered in the viewport.
TEST_F(RootFrameViewportTest, ScrollIntoView) {
  IntSize viewportSize(100, 150);
  RootFrameViewStub* layoutViewport =
      RootFrameViewStub::create(viewportSize, IntSize(200, 300));
  VisualViewportStub* visualViewport =
      VisualViewportStub::create(viewportSize, viewportSize);

  ScrollableArea* rootFrameViewport =
      RootFrameViewport::create(*visualViewport, *layoutViewport);

  // Test that the visual viewport is scrolled if the viewport has been
  // resized (as is the case when the ChromeOS keyboard comes up) but not
  // scaled.
  visualViewport->setViewportSize(IntSize(100, 100));
  rootFrameViewport->scrollIntoView(LayoutRect(100, 250, 50, 50),
                                    ScrollAlignment::alignToEdgeIfNeeded,
                                    ScrollAlignment::alignToEdgeIfNeeded);
  EXPECT_SIZE_EQ(ScrollOffset(50, 150), layoutViewport->getScrollOffset());
  EXPECT_SIZE_EQ(ScrollOffset(0, 50), visualViewport->getScrollOffset());

  rootFrameViewport->scrollIntoView(LayoutRect(25, 75, 50, 50),
                                    ScrollAlignment::alignToEdgeIfNeeded,
                                    ScrollAlignment::alignToEdgeIfNeeded);
  EXPECT_SIZE_EQ(ScrollOffset(25, 75), layoutViewport->getScrollOffset());
  EXPECT_SIZE_EQ(ScrollOffset(0, 0), visualViewport->getScrollOffset());

  // Reset the visual viewport's size, scale the page, and repeat the test
  visualViewport->setViewportSize(IntSize(100, 150));
  visualViewport->setScale(2);
  rootFrameViewport->setScrollOffset(ScrollOffset(), ProgrammaticScroll);

  rootFrameViewport->scrollIntoView(LayoutRect(50, 75, 50, 75),
                                    ScrollAlignment::alignToEdgeIfNeeded,
                                    ScrollAlignment::alignToEdgeIfNeeded);
  EXPECT_SIZE_EQ(ScrollOffset(0, 0), layoutViewport->getScrollOffset());
  EXPECT_SIZE_EQ(ScrollOffset(50, 75), visualViewport->getScrollOffset());

  rootFrameViewport->scrollIntoView(LayoutRect(190, 290, 10, 10),
                                    ScrollAlignment::alignToEdgeIfNeeded,
                                    ScrollAlignment::alignToEdgeIfNeeded);
  EXPECT_SIZE_EQ(ScrollOffset(100, 150), layoutViewport->getScrollOffset());
  EXPECT_SIZE_EQ(ScrollOffset(50, 75), visualViewport->getScrollOffset());

  // Scrolling into view the viewport rect itself should be a no-op.
  visualViewport->setViewportSize(IntSize(100, 100));
  visualViewport->setScale(1.5f);
  visualViewport->setScrollOffset(ScrollOffset(0, 10), ProgrammaticScroll);
  layoutViewport->setScrollOffset(ScrollOffset(50, 50), ProgrammaticScroll);
  rootFrameViewport->setScrollOffset(rootFrameViewport->getScrollOffset(),
                                     ProgrammaticScroll);

  rootFrameViewport->scrollIntoView(
      LayoutRect(rootFrameViewport->visibleContentRect(ExcludeScrollbars)),
      ScrollAlignment::alignToEdgeIfNeeded,
      ScrollAlignment::alignToEdgeIfNeeded);
  EXPECT_SIZE_EQ(ScrollOffset(50, 50), layoutViewport->getScrollOffset());
  EXPECT_SIZE_EQ(ScrollOffset(0, 10), visualViewport->getScrollOffset());

  rootFrameViewport->scrollIntoView(
      LayoutRect(rootFrameViewport->visibleContentRect(ExcludeScrollbars)),
      ScrollAlignment::alignCenterAlways, ScrollAlignment::alignCenterAlways);
  EXPECT_SIZE_EQ(ScrollOffset(50, 50), layoutViewport->getScrollOffset());
  EXPECT_SIZE_EQ(ScrollOffset(0, 10), visualViewport->getScrollOffset());

  rootFrameViewport->scrollIntoView(
      LayoutRect(rootFrameViewport->visibleContentRect(ExcludeScrollbars)),
      ScrollAlignment::alignTopAlways, ScrollAlignment::alignTopAlways);
  EXPECT_SIZE_EQ(ScrollOffset(50, 50), layoutViewport->getScrollOffset());
  EXPECT_SIZE_EQ(ScrollOffset(0, 10), visualViewport->getScrollOffset());
}
开发者ID:,项目名称:,代码行数:72,代码来源:


注:本文中的ScrollableArea::scrollIntoView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。