Ejemplo n.º 1
0
void PinchViewport::setupScrollbar(WebScrollbar::Orientation orientation)
{
    bool isHorizontal = orientation == WebScrollbar::Horizontal;
    GraphicsLayer* scrollbarGraphicsLayer = isHorizontal ?
        m_overlayScrollbarHorizontal.get() : m_overlayScrollbarVertical.get();
    OwnPtr<WebScrollbarLayer>& webScrollbarLayer = isHorizontal ?
        m_webOverlayScrollbarHorizontal : m_webOverlayScrollbarVertical;

    const int overlayScrollbarThickness = m_frameHost.settings().pinchOverlayScrollbarThickness();

    if (!webScrollbarLayer) {
        ScrollingCoordinator* coordinator = m_frameHost.page().scrollingCoordinator();
        ASSERT(coordinator);
        ScrollbarOrientation webcoreOrientation = isHorizontal ? HorizontalScrollbar : VerticalScrollbar;
        webScrollbarLayer = coordinator->createSolidColorScrollbarLayer(webcoreOrientation, overlayScrollbarThickness, 0, false);

        webScrollbarLayer->setClipLayer(m_innerViewportContainerLayer->platformLayer());
        scrollbarGraphicsLayer->setContentsToPlatformLayer(webScrollbarLayer->layer());
        scrollbarGraphicsLayer->setDrawsContent(false);
    }

    int xPosition = isHorizontal ? 0 : m_innerViewportContainerLayer->size().width() - overlayScrollbarThickness;
    int yPosition = isHorizontal ? m_innerViewportContainerLayer->size().height() - overlayScrollbarThickness : 0;
    int width = isHorizontal ? m_innerViewportContainerLayer->size().width() - overlayScrollbarThickness : overlayScrollbarThickness;
    int height = isHorizontal ? overlayScrollbarThickness : m_innerViewportContainerLayer->size().height() - overlayScrollbarThickness;

    // Use the GraphicsLayer to position the scrollbars.
    scrollbarGraphicsLayer->setPosition(IntPoint(xPosition, yPosition));
    scrollbarGraphicsLayer->setSize(IntSize(width, height));
    scrollbarGraphicsLayer->setContentsRect(IntRect(0, 0, width, height));
}
// Modifies the top of the graphics layer tree to add layers needed to support
// the inner/outer viewport fixed-position model for pinch zoom. When finished,
// the tree will look like this (with * denoting added layers):
//
// *rootTransformLayer
//  +- *innerViewportContainerLayer (fixed pos container)
//  |   +- *overscrollElasticityLayer
//  |       +- *pageScaleLayer
//  |           +- *innerViewportScrollLayer
//  |               +-- overflowControlsHostLayer (root layer)
//  |                   +-- outerViewportContainerLayer (fixed pos container) [frame container layer in PaintLayerCompositor]
//  |                   |   +-- outerViewportScrollLayer [frame scroll layer in PaintLayerCompositor]
//  |                   |       +-- content layers ...
//  +- horizontalScrollbarLayer
//  +- verticalScrollbarLayer
//  +- scroll corner (non-overlay only)
//
void VisualViewport::attachToLayerTree(GraphicsLayer* currentLayerTreeRoot, GraphicsLayerFactory* graphicsLayerFactory)
{
    TRACE_EVENT1("blink", "VisualViewport::attachToLayerTree", "currentLayerTreeRoot", (bool)currentLayerTreeRoot);
    if (!currentLayerTreeRoot) {
        if (m_innerViewportScrollLayer)
            m_innerViewportScrollLayer->removeAllChildren();
        return;
    }

    if (currentLayerTreeRoot->parent() && currentLayerTreeRoot->parent() == m_innerViewportScrollLayer)
        return;

    if (!m_innerViewportScrollLayer) {
        ASSERT(!m_overlayScrollbarHorizontal
            && !m_overlayScrollbarVertical
            && !m_overscrollElasticityLayer
            && !m_pageScaleLayer
            && !m_innerViewportContainerLayer);

        // FIXME: The root transform layer should only be created on demand.
        m_rootTransformLayer = GraphicsLayer::create(graphicsLayerFactory, this);
        m_innerViewportContainerLayer = GraphicsLayer::create(graphicsLayerFactory, this);
        m_overscrollElasticityLayer = GraphicsLayer::create(graphicsLayerFactory, this);
        m_pageScaleLayer = GraphicsLayer::create(graphicsLayerFactory, this);
        m_innerViewportScrollLayer = GraphicsLayer::create(graphicsLayerFactory, this);
        m_overlayScrollbarHorizontal = GraphicsLayer::create(graphicsLayerFactory, this);
        m_overlayScrollbarVertical = GraphicsLayer::create(graphicsLayerFactory, this);

        ScrollingCoordinator* coordinator = frameHost().page().scrollingCoordinator();
        ASSERT(coordinator);
        coordinator->setLayerIsContainerForFixedPositionLayers(m_innerViewportScrollLayer.get(), true);

        // Set masks to bounds so the compositor doesn't clobber a manually
        // set inner viewport container layer size.
        m_innerViewportContainerLayer->setMasksToBounds(frameHost().settings().mainFrameClipsContent());
        m_innerViewportContainerLayer->setSize(m_size);

        m_innerViewportScrollLayer->platformLayer()->setScrollClipLayer(
            m_innerViewportContainerLayer->platformLayer());
        m_innerViewportScrollLayer->platformLayer()->setUserScrollable(true, true);

        m_rootTransformLayer->addChild(m_innerViewportContainerLayer.get());
        m_innerViewportContainerLayer->addChild(m_overscrollElasticityLayer.get());
        m_overscrollElasticityLayer->addChild(m_pageScaleLayer.get());
        m_pageScaleLayer->addChild(m_innerViewportScrollLayer.get());

        // Ensure this class is set as the scroll layer's ScrollableArea.
        coordinator->scrollableAreaScrollLayerDidChange(this);

        initializeScrollbars();
    }

    m_innerViewportScrollLayer->removeAllChildren();
    m_innerViewportScrollLayer->addChild(currentLayerTreeRoot);
}
Ejemplo n.º 3
0
void VisualViewport::setupScrollbar(WebScrollbar::Orientation orientation) {
  bool isHorizontal = orientation == WebScrollbar::Horizontal;
  GraphicsLayer* scrollbarGraphicsLayer =
      isHorizontal ? m_overlayScrollbarHorizontal.get()
                   : m_overlayScrollbarVertical.get();
  std::unique_ptr<WebScrollbarLayer>& webScrollbarLayer =
      isHorizontal ? m_webOverlayScrollbarHorizontal
                   : m_webOverlayScrollbarVertical;

  ScrollbarThemeOverlay& theme = ScrollbarThemeOverlay::mobileTheme();
  int thumbThickness = theme.thumbThickness();
  int scrollbarThickness = theme.scrollbarThickness(RegularScrollbar);
  int scrollbarMargin = theme.scrollbarMargin();

  if (!webScrollbarLayer) {
    ScrollingCoordinator* coordinator =
        frameHost().page().scrollingCoordinator();
    ASSERT(coordinator);
    ScrollbarOrientation webcoreOrientation =
        isHorizontal ? HorizontalScrollbar : VerticalScrollbar;
    webScrollbarLayer = coordinator->createSolidColorScrollbarLayer(
        webcoreOrientation, thumbThickness, scrollbarMargin, false);

    // The compositor will control the scrollbar's visibility. Set to invisible
    // by default so scrollbars don't show up in layout tests.
    webScrollbarLayer->layer()->setOpacity(0);
    scrollbarGraphicsLayer->setContentsToPlatformLayer(
        webScrollbarLayer->layer());
    scrollbarGraphicsLayer->setDrawsContent(false);
  }

  int xPosition = isHorizontal ? 0
                               : m_innerViewportContainerLayer->size().width() -
                                     scrollbarThickness;
  int yPosition =
      isHorizontal
          ? m_innerViewportContainerLayer->size().height() - scrollbarThickness
          : 0;
  int width =
      isHorizontal
          ? m_innerViewportContainerLayer->size().width() - scrollbarThickness
          : scrollbarThickness;
  int height = isHorizontal ? scrollbarThickness
                            : m_innerViewportContainerLayer->size().height() -
                                  scrollbarThickness;

  // Use the GraphicsLayer to position the scrollbars.
  scrollbarGraphicsLayer->setPosition(IntPoint(xPosition, yPosition));
  scrollbarGraphicsLayer->setSize(FloatSize(width, height));
  scrollbarGraphicsLayer->setContentsRect(IntRect(0, 0, width, height));
}
Ejemplo n.º 4
0
void PinchViewport::setLocation(const FloatPoint& newLocation)
{
    FloatPoint clampedOffset(clampOffsetToBoundaries(newLocation));

    if (clampedOffset == m_offset)
        return;

    m_offset = clampedOffset;

    ScrollingCoordinator* coordinator = m_frameHost.page().scrollingCoordinator();
    ASSERT(coordinator);
    coordinator->scrollableAreaScrollLayerDidChange(this);

    mainFrame()->loader().saveScrollState();
}
Ejemplo n.º 5
0
void ScrollingTreeIOS::invalidate()
{
    // Invalidate is dispatched by the ScrollingCoordinator class on the ScrollingThread
    // to break the reference cycle between ScrollingTree and ScrollingCoordinator when the
    // ScrollingCoordinator's page is destroyed.
    ASSERT(ScrollingThread::isCurrentThread());

    // Since this can potentially be the last reference to the scrolling coordinator,
    // we need to release it on the main thread since it has member variables (such as timers)
    // that expect to be destroyed from the main thread.
    ScrollingCoordinator* scrollingCoordinator = m_scrollingCoordinator.release().leakRef();
    callOnMainThread([scrollingCoordinator] {
        scrollingCoordinator->deref();
    });
}
void EventHandlerRegistry::notifyHasHandlersChanged(EventHandlerClass handlerClass, bool hasActiveHandlers)
{
    ScrollingCoordinator* scrollingCoordinator = m_frameHost.page().scrollingCoordinator();

    switch (handlerClass) {
    case ScrollEvent:
        if (scrollingCoordinator)
            scrollingCoordinator->updateHaveScrollEventHandlers();
        break;
    case WheelEvent:
        if (scrollingCoordinator)
            scrollingCoordinator->updateHaveWheelEventHandlers();
        break;
#if ASSERT_ENABLED
    case EventsForTesting:
        break;
#endif
    default:
        ASSERT_NOT_REACHED();
        break;
    }
}
Ejemplo n.º 7
0
CompositorAnimationTimeline* VisualViewport::compositorAnimationTimeline()
    const {
  ScrollingCoordinator* c = frameHost().page().scrollingCoordinator();
  return c ? c->compositorAnimationTimeline() : nullptr;
}