Commit 1ce3e437 authored by chrishtr@chromium.org's avatar chrishtr@chromium.org

Move painting code from FrameView to FramePainter.

BUG=412088

Review URL: https://codereview.chromium.org/648423002

git-svn-id: svn://svn.chromium.org/blink/trunk@183709 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 8c4db617
......@@ -1502,6 +1502,8 @@
'paint/EllipsisBoxPainter.h',
'paint/FileUploadControlPainter.cpp',
'paint/FileUploadControlPainter.h',
'paint/FramePainter.cpp',
'paint/FramePainter.h',
'paint/GridPainter.cpp',
'paint/GridPainter.h',
'paint/HTMLCanvasPainter.cpp',
......
......@@ -204,20 +204,19 @@ public:
void addPartToUpdate(RenderEmbeddedObject&);
void paintContents(GraphicsContext*, const IntRect& damageRect);
void setPaintBehavior(PaintBehavior);
PaintBehavior paintBehavior() const;
void setIsPainting(bool val) { m_isPainting = val; }
bool isPainting() const;
void setLastPaintTime(double val) { m_lastPaintTime = val; }
bool hasEverPainted() const { return m_lastPaintTime; }
void setNodeToDraw(Node*);
void paintOverhangAreas(GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect);
void paintScrollbar(GraphicsContext*, Scrollbar*, const IntRect&);
Node* nodeToDraw() { return m_nodeToDraw.get(); }
Color documentBackgroundColor() const;
static double currentFrameTimeStamp() { return s_currentFrameTimeStamp; }
void setCurrentFrameTimeStamp(double val) { s_currentFrameTimeStamp = val; }
void updateLayoutAndStyleForPainting();
void updateLayoutAndStyleIfNeededRecursive();
......@@ -362,6 +361,7 @@ public:
// can be used to obtain those scrollbars.
virtual Scrollbar* horizontalScrollbar() const override { return m_horizontalScrollbar.get(); }
virtual Scrollbar* verticalScrollbar() const override { return m_verticalScrollbar.get(); }
RenderScrollbarPart* scrollCorner() { return m_scrollCorner; }
void positionScrollbarLayers();
......@@ -455,6 +455,8 @@ public:
void setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppress = false);
bool scrollbarsSuppressed() const { return m_scrollbarsSuppressed; }
bool drawPanScrollIcon() { return m_shouldDrawPanScrollIcon; }
IntPoint rootViewToContents(const IntPoint&) const;
IntPoint contentsToRootView(const IntPoint&) const;
IntRect rootViewToContents(const IntRect&) const;
......@@ -511,7 +513,7 @@ public:
// Widget override. Handles painting of the contents of the view as well as the scrollbars.
virtual void paint(GraphicsContext*, const IntRect&) override;
void paintScrollbars(GraphicsContext*, const IntRect&);
void paintContents(GraphicsContext*, const IntRect& damageRect);
// Widget overrides to ensure that our children's visibility status is kept up to date when we get shown and hidden.
virtual void show() override;
......@@ -527,20 +529,19 @@ public:
bool isPointInScrollbarCorner(const IntPoint&);
bool scrollbarCornerPresent() const;
virtual IntRect scrollCornerRect() const override;
void paintScrollCornerInternal(GraphicsContext*, const IntRect& cornerRect);
void paintScrollbarInternal(GraphicsContext*, Scrollbar*, const IntRect&);
virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const override;
virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const override;
virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const override;
virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const override;
void calculateAndPaintOverhangAreas(GraphicsContext*, const IntRect& dirtyRect);
void calculateAndPaintOverhangBackground(GraphicsContext*, const IntRect& dirtyRect);
virtual bool isFrameView() const override { return true; }
virtual void trace(Visitor*) override;
void notifyPageThatContentAreaWillPaint() const;
FrameView* parentFrameView() const;
void calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntRect& verticalOverhangRect);
protected:
bool scrollContentsFastPath(const IntSize& scrollDelta);
......@@ -558,8 +559,6 @@ protected:
void contentRectangleForPaintInvalidationInternal(const IntRect&);
void paintOverhangAreasInternal(GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
// These functions are used to create/destroy scrollbars.
void setHasHorizontalScrollbar(bool);
void setHasVerticalScrollbar(bool);
......@@ -650,8 +649,6 @@ private:
void updateScrollableAreaSet();
void notifyPageThatContentAreaWillPaint() const;
void scheduleUpdateWidgetsIfNecessary();
void updateWidgetsTimerFired(Timer<FrameView>*);
bool updateWidgets();
......@@ -670,8 +667,6 @@ private:
void updateScrollCorner();
FrameView* parentFrameView() const;
AXObjectCache* axObjectCache() const;
void removeFromAXObjectCache();
......@@ -693,13 +688,11 @@ private:
IntRect rectToCopyOnScroll() const;
void calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntRect& verticalOverhangRect);
void updateOverhangAreas();
bool isFrameViewScrollbar(const Widget* child) const { return horizontalScrollbar() == child || verticalScrollbar() == child; }
static double s_currentFrameTimeStamp; // used for detecting decoded resource thrash in the cache
static bool s_inPaintContents;
LayoutSize m_size;
......@@ -820,7 +813,7 @@ private:
bool m_inUpdateScrollbars;
IntPoint m_panScrollIconPoint;
bool m_drawPanScrollIcon;
bool m_shouldDrawPanScrollIcon;
bool m_clipsRepaints;
};
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "core/paint/FramePainter.h"
#include "core/dom/DocumentMarkerController.h"
#include "core/frame/FrameView.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/inspector/InspectorTraceEvents.h"
#include "core/page/Chrome.h"
#include "core/page/ChromeClient.h"
#include "core/page/Page.h"
#include "core/paint/LayerPainter.h"
#include "core/paint/ScrollbarPainter.h"
#include "core/rendering/RenderLayer.h"
#include "core/rendering/RenderView.h"
#include "platform/fonts/FontCache.h"
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/GraphicsContextStateSaver.h"
#include "platform/scroll/ScrollbarTheme.h"
namespace blink {
bool FramePainter::s_inPaintContents = false;
void FramePainter::paint(GraphicsContext* context, const IntRect& rect)
{
m_frameView.notifyPageThatContentAreaWillPaint();
IntRect documentDirtyRect = rect;
IntRect visibleAreaWithoutScrollbars(m_frameView.location(), m_frameView.visibleContentRect().size());
documentDirtyRect.intersect(visibleAreaWithoutScrollbars);
if (!documentDirtyRect.isEmpty()) {
GraphicsContextStateSaver stateSaver(*context);
context->translate(m_frameView.x() - m_frameView.scrollX(), m_frameView.y() - m_frameView.scrollY());
context->clip(m_frameView.visibleContentRect());
documentDirtyRect.moveBy(-m_frameView.location() + m_frameView.scrollPosition());
paintContents(context, documentDirtyRect);
}
calculateAndPaintOverhangAreas(context, rect);
// Now paint the scrollbars.
if (!m_frameView.scrollbarsSuppressed() && (m_frameView.horizontalScrollbar() || m_frameView.verticalScrollbar())) {
GraphicsContextStateSaver stateSaver(*context);
IntRect scrollViewDirtyRect = rect;
IntRect visibleAreaWithScrollbars(m_frameView.location(), m_frameView.visibleContentRect(IncludeScrollbars).size());
scrollViewDirtyRect.intersect(visibleAreaWithScrollbars);
context->translate(m_frameView.x(), m_frameView.y());
scrollViewDirtyRect.moveBy(-m_frameView.location());
context->clip(IntRect(IntPoint(), visibleAreaWithScrollbars.size()));
paintScrollbars(context, scrollViewDirtyRect);
}
// Paint the panScroll Icon
if (m_frameView.drawPanScrollIcon())
m_frameView.paintPanScrollIcon(context);
}
void FramePainter::paintContents(GraphicsContext* p, const IntRect& rect)
{
Document* document = m_frameView.frame().document();
#ifndef NDEBUG
bool fillWithRed;
if (document->printing())
fillWithRed = false; // Printing, don't fill with red (can't remember why).
else if (m_frameView.frame().owner())
fillWithRed = false; // Subframe, don't fill with red.
else if (m_frameView.isTransparent())
fillWithRed = false; // Transparent, don't fill with red.
else if (m_frameView.paintBehavior() & PaintBehaviorSelectionOnly)
fillWithRed = false; // Selections are transparent, don't fill with red.
else if (m_frameView.nodeToDraw())
fillWithRed = false; // Element images are transparent, don't fill with red.
else
fillWithRed = true;
if (fillWithRed)
p->fillRect(rect, Color(0xFF, 0, 0));
#endif
RenderView* renderView = m_frameView.renderView();
if (!renderView) {
WTF_LOG_ERROR("called FramePainter::paint with nil renderer");
return;
}
RELEASE_ASSERT(!m_frameView.needsLayout());
ASSERT(document->lifecycle().state() >= DocumentLifecycle::CompositingClean);
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Paint", "data", InspectorPaintEvent::data(renderView, rect, 0));
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"), "CallStack", "stack", InspectorCallStackEvent::currentCallStack());
// FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeline migrates to tracing.
InspectorInstrumentation::willPaint(renderView, 0);
bool isTopLevelPainter = !s_inPaintContents;
s_inPaintContents = true;
FontCachePurgePreventer fontCachePurgePreventer;
PaintBehavior oldPaintBehavior = m_frameView.paintBehavior();
if (FrameView* parentView = m_frameView.parentFrameView()) {
if (parentView->paintBehavior() & PaintBehaviorFlattenCompositingLayers)
m_frameView.setPaintBehavior(m_frameView.paintBehavior() | PaintBehaviorFlattenCompositingLayers);
}
if (m_frameView.paintBehavior() == PaintBehaviorNormal)
document->markers().invalidateRenderedRectsForMarkersInRect(rect);
if (document->printing())
m_frameView.setPaintBehavior(m_frameView.paintBehavior() | PaintBehaviorFlattenCompositingLayers);
ASSERT(!m_frameView.isPainting());
m_frameView.setIsPainting(true);
// m_frameView.nodeToDraw() is used to draw only one element (and its descendants)
RenderObject* renderer = m_frameView.nodeToDraw() ? m_frameView.nodeToDraw()->renderer() : 0;
RenderLayer* rootLayer = renderView->layer();
#if ENABLE(ASSERT)
renderView->assertSubtreeIsLaidOut();
RenderObject::SetLayoutNeededForbiddenScope forbidSetNeedsLayout(*rootLayer->renderer());
#endif
LayerPainter layerPainter(*rootLayer);
layerPainter.paint(p, rect, m_frameView.paintBehavior(), renderer);
if (rootLayer->containsDirtyOverlayScrollbars())
layerPainter.paintOverlayScrollbars(p, rect, m_frameView.paintBehavior(), renderer);
m_frameView.setIsPainting(false);
m_frameView.setPaintBehavior(oldPaintBehavior);
m_frameView.setLastPaintTime(currentTime());
// Regions may have changed as a result of the visibility/z-index of element changing.
if (document->annotatedRegionsDirty())
m_frameView.updateAnnotatedRegions();
if (isTopLevelPainter) {
// Everything that happens after paintContents completions is considered
// to be part of the next frame.
m_frameView.setCurrentFrameTimeStamp(currentTime());
s_inPaintContents = false;
}
InspectorInstrumentation::didPaint(renderView, 0, p, rect);
}
void FramePainter::paintScrollbars(GraphicsContext* context, const IntRect& rect)
{
if (m_frameView.horizontalScrollbar() && !m_frameView.layerForHorizontalScrollbar())
paintScrollbar(context, m_frameView.horizontalScrollbar(), rect);
if (m_frameView.verticalScrollbar() && !m_frameView.layerForVerticalScrollbar())
paintScrollbar(context, m_frameView.verticalScrollbar(), rect);
if (m_frameView.layerForScrollCorner())
return;
paintScrollCorner(context, m_frameView.scrollCornerRect());
}
void FramePainter::paintScrollCorner(GraphicsContext* context, const IntRect& cornerRect)
{
if (m_frameView.scrollCorner()) {
bool needsBackground = m_frameView.frame().isMainFrame();
if (needsBackground)
context->fillRect(cornerRect, m_frameView.baseBackgroundColor());
ScrollbarPainter::paintIntoRect(m_frameView.scrollCorner(), context, cornerRect.location(), cornerRect);
return;
}
ScrollbarTheme::theme()->paintScrollCorner(context, cornerRect);
}
void FramePainter::paintScrollbar(GraphicsContext* context, Scrollbar* bar, const IntRect& rect)
{
bool needsBackground = bar->isCustomScrollbar() && m_frameView.frame().isMainFrame();
if (needsBackground) {
IntRect toFill = bar->frameRect();
toFill.intersect(rect);
context->fillRect(toFill, m_frameView.baseBackgroundColor());
}
bar->paint(context, rect);
}
void FramePainter::paintOverhangAreas(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
{
if (m_frameView.frame().document()->printing())
return;
if (m_frameView.frame().isMainFrame()) {
if (m_frameView.frame().page()->chrome().client().paintCustomOverhangArea(context, horizontalOverhangArea, verticalOverhangArea, dirtyRect))
return;
}
paintOverhangAreasInternal(context, horizontalOverhangArea, verticalOverhangArea, dirtyRect);
}
void FramePainter::paintOverhangAreasInternal(GraphicsContext* context, const IntRect& horizontalOverhangRect, const IntRect& verticalOverhangRect, const IntRect& dirtyRect)
{
ScrollbarTheme::theme()->paintOverhangBackground(context, horizontalOverhangRect, verticalOverhangRect, dirtyRect);
ScrollbarTheme::theme()->paintOverhangShadows(context, m_frameView.scrollOffset(), horizontalOverhangRect, verticalOverhangRect, dirtyRect);
}
void FramePainter::calculateAndPaintOverhangAreas(GraphicsContext* context, const IntRect& dirtyRect)
{
IntRect horizontalOverhangRect;
IntRect verticalOverhangRect;
m_frameView.calculateOverhangAreasForPainting(horizontalOverhangRect, verticalOverhangRect);
if (dirtyRect.intersects(horizontalOverhangRect) || dirtyRect.intersects(verticalOverhangRect))
paintOverhangAreas(context, horizontalOverhangRect, verticalOverhangRect, dirtyRect);
}
} // namespace blink
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FramePainter_h
#define FramePainter_h
namespace blink {
class FrameView;
class GraphicsContext;
class IntRect;
class Scrollbar;
class FramePainter {
public:
FramePainter(FrameView& frameView) : m_frameView(frameView) { }
void paint(GraphicsContext*, const IntRect&);
void paintScrollbars(GraphicsContext*, const IntRect&);
void paintContents(GraphicsContext*, const IntRect& damageRect);
void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect);
private:
void paintScrollbar(GraphicsContext*, Scrollbar*, const IntRect&);
void paintOverhangAreas(GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
void calculateAndPaintOverhangAreas(GraphicsContext*, const IntRect& dirtyRect);
void paintOverhangAreasInternal(GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect);
FrameView& m_frameView;
static bool s_inPaintContents;
};
} // namespace blink
#endif // FramePainter_h
......@@ -39,6 +39,7 @@
#include "core/page/ChromeClient.h"
#include "core/page/Page.h"
#include "core/page/scrolling/ScrollingCoordinator.h"
#include "core/paint/FramePainter.h"
#include "core/rendering/RenderEmbeddedObject.h"
#include "core/rendering/RenderLayerStackingNode.h"
#include "core/rendering/RenderLayerStackingNodeIterator.h"
......@@ -803,7 +804,7 @@ void RenderLayerCompositor::paintContents(const GraphicsLayer* graphicsLayer, Gr
context.translate(-scrollCorner.x(), -scrollCorner.y());
IntRect transformedClip = clip;
transformedClip.moveBy(scrollCorner.location());
m_renderView.frameView()->paintScrollCorner(&context, transformedClip);
FramePainter(*m_renderView.frameView()).paintScrollCorner(&context, transformedClip);
context.restore();
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment