ScrollingCoordinatorChromium.cpp [plain text]
#include "config.h"
#include "ScrollingCoordinator.h"
#include "Frame.h"
#include "FrameView.h"
#include "LayerChromium.h"
#include "Region.h"
#include "RenderLayerCompositor.h"
#include "RenderView.h"
#include "ScrollbarLayerChromium.h"
#include "ScrollbarTheme.h"
#include "cc/CCProxy.h"
namespace WebCore {
class ScrollingCoordinatorPrivate {
WTF_MAKE_NONCOPYABLE(ScrollingCoordinatorPrivate);
public:
ScrollingCoordinatorPrivate() { }
~ScrollingCoordinatorPrivate() { }
void setScrollLayer(LayerChromium* layer) { m_scrollLayer = layer; }
LayerChromium* scrollLayer() const { return m_scrollLayer.get(); }
private:
RefPtr<LayerChromium> m_scrollLayer;
};
PassRefPtr<ScrollingCoordinator> ScrollingCoordinator::create(Page* page)
{
RefPtr<ScrollingCoordinator> coordinator(adoptRef(new ScrollingCoordinator(page)));
coordinator->m_private = new ScrollingCoordinatorPrivate;
return coordinator.release();
}
ScrollingCoordinator::~ScrollingCoordinator()
{
ASSERT(!m_page);
delete m_private;
}
static GraphicsLayer* scrollLayerForFrameView(FrameView* frameView)
{
#if USE(ACCELERATED_COMPOSITING)
Frame* frame = frameView->frame();
if (!frame)
return 0;
RenderView* renderView = frame->contentRenderer();
if (!renderView)
return 0;
return renderView->compositor()->scrollLayer();
#else
return 0;
#endif
}
static void scrollbarLayerDidChange(Scrollbar* scrollbar, LayerChromium* scrollLayer, GraphicsLayer* scrollbarGraphicsLayer, FrameView* frameView)
{
ASSERT(scrollbar);
ASSERT(scrollbarGraphicsLayer);
if (!scrollLayer) {
scrollLayer = scrollLayerForFrameView(frameView)->platformLayer();
ASSERT(scrollLayer);
}
bool isOpaqueRootScrollbar = !frameView->parent() && !scrollbar->isOverlayScrollbar();
if (!scrollbarGraphicsLayer->contentsOpaque())
scrollbarGraphicsLayer->setContentsOpaque(isOpaqueRootScrollbar);
bool platformSupported = false;
#if OS(LINUX)
platformSupported = true;
#endif
if (scrollbar->isCustomScrollbar() || !CCProxy::hasImplThread() || !platformSupported) {
scrollbarGraphicsLayer->setContentsToMedia(0);
scrollbarGraphicsLayer->setDrawsContent(true);
return;
}
RefPtr<ScrollbarLayerChromium> scrollbarLayer = ScrollbarLayerChromium::create(scrollbar, scrollLayer->id());
scrollbarGraphicsLayer->setContentsToMedia(scrollbarLayer.get());
scrollbarGraphicsLayer->setDrawsContent(false);
scrollbarLayer->setOpaque(scrollbarGraphicsLayer->contentsOpaque());
}
void ScrollingCoordinator::frameViewHorizontalScrollbarLayerDidChange(FrameView* frameView, GraphicsLayer* horizontalScrollbarLayer)
{
if (!horizontalScrollbarLayer || !coordinatesScrollingForFrameView(frameView))
return;
scrollbarLayerDidChange(frameView->horizontalScrollbar(), m_private->scrollLayer(), horizontalScrollbarLayer, frameView);
}
void ScrollingCoordinator::frameViewVerticalScrollbarLayerDidChange(FrameView* frameView, GraphicsLayer* verticalScrollbarLayer)
{
if (!verticalScrollbarLayer || !coordinatesScrollingForFrameView(frameView))
return;
scrollbarLayerDidChange(frameView->verticalScrollbar(), m_private->scrollLayer(), verticalScrollbarLayer, frameView);
}
void ScrollingCoordinator::setScrollLayer(GraphicsLayer* scrollLayer)
{
m_private->setScrollLayer(scrollLayer ? scrollLayer->platformLayer() : 0);
}
void ScrollingCoordinator::setNonFastScrollableRegion(const Region& region)
{
if (LayerChromium* layer = m_private->scrollLayer())
layer->setNonFastScrollableRegion(region);
}
void ScrollingCoordinator::setScrollParameters(const ScrollParameters&)
{
}
void ScrollingCoordinator::setWheelEventHandlerCount(unsigned wheelEventHandlerCount)
{
if (LayerChromium* layer = m_private->scrollLayer())
layer->setHaveWheelEventHandlers(wheelEventHandlerCount > 0);
}
void ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread(bool should)
{
if (LayerChromium* layer = m_private->scrollLayer())
layer->setShouldScrollOnMainThread(should);
}
}