OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/paint/FramePainter.h" | 6 #include "core/paint/FramePainter.h" |
7 | 7 |
8 #include "core/dom/DocumentMarkerController.h" | 8 #include "core/dom/DocumentMarkerController.h" |
9 #include "core/fetch/MemoryCache.h" | 9 #include "core/fetch/MemoryCache.h" |
10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "platform/graphics/GraphicsContext.h" | 22 #include "platform/graphics/GraphicsContext.h" |
23 #include "platform/graphics/paint/ClipRecorder.h" | 23 #include "platform/graphics/paint/ClipRecorder.h" |
24 #include "platform/scroll/ScrollbarTheme.h" | 24 #include "platform/scroll/ScrollbarTheme.h" |
25 | 25 |
26 namespace blink { | 26 namespace blink { |
27 | 27 |
28 bool FramePainter::s_inPaintContents = false; | 28 bool FramePainter::s_inPaintContents = false; |
29 | 29 |
30 void FramePainter::paint(GraphicsContext* context, const GlobalPaintFlags global
PaintFlags, const IntRect& rect) | 30 void FramePainter::paint(GraphicsContext* context, const GlobalPaintFlags global
PaintFlags, const IntRect& rect) |
31 { | 31 { |
32 m_frameView.notifyPageThatContentAreaWillPaint(); | 32 frameView().notifyPageThatContentAreaWillPaint(); |
33 | 33 |
34 IntRect documentDirtyRect = rect; | 34 IntRect documentDirtyRect = rect; |
35 IntRect visibleAreaWithoutScrollbars(m_frameView.location(), m_frameView.vis
ibleContentRect().size()); | 35 IntRect visibleAreaWithoutScrollbars(frameView().location(), frameView().vis
ibleContentRect().size()); |
36 documentDirtyRect.intersect(visibleAreaWithoutScrollbars); | 36 documentDirtyRect.intersect(visibleAreaWithoutScrollbars); |
37 | 37 |
38 if (!documentDirtyRect.isEmpty()) { | 38 if (!documentDirtyRect.isEmpty()) { |
39 TransformRecorder transformRecorder(*context, *m_frameView.layoutView(), | 39 TransformRecorder transformRecorder(*context, *frameView().layoutView(), |
40 AffineTransform::translation(m_frameView.x() - m_frameView.scrollX()
, m_frameView.y() - m_frameView.scrollY())); | 40 AffineTransform::translation(frameView().x() - frameView().scrollX()
, frameView().y() - frameView().scrollY())); |
41 | 41 |
42 ClipRecorder recorder(*context, *m_frameView.layoutView(), DisplayItem::
ClipFrameToVisibleContentRect, LayoutRect(m_frameView.visibleContentRect())); | 42 ClipRecorder recorder(*context, *frameView().layoutView(), DisplayItem::
ClipFrameToVisibleContentRect, LayoutRect(frameView().visibleContentRect())); |
43 | 43 |
44 documentDirtyRect.moveBy(-m_frameView.location() + m_frameView.scrollPos
ition()); | 44 documentDirtyRect.moveBy(-frameView().location() + frameView().scrollPos
ition()); |
45 paintContents(context, globalPaintFlags, documentDirtyRect); | 45 paintContents(context, globalPaintFlags, documentDirtyRect); |
46 } | 46 } |
47 | 47 |
48 // Now paint the scrollbars. | 48 // Now paint the scrollbars. |
49 if (!m_frameView.scrollbarsSuppressed() && (m_frameView.horizontalScrollbar(
) || m_frameView.verticalScrollbar())) { | 49 if (!frameView().scrollbarsSuppressed() && (frameView().horizontalScrollbar(
) || frameView().verticalScrollbar())) { |
50 IntRect scrollViewDirtyRect = rect; | 50 IntRect scrollViewDirtyRect = rect; |
51 IntRect visibleAreaWithScrollbars(m_frameView.location(), m_frameView.vi
sibleContentRect(IncludeScrollbars).size()); | 51 IntRect visibleAreaWithScrollbars(frameView().location(), frameView().vi
sibleContentRect(IncludeScrollbars).size()); |
52 scrollViewDirtyRect.intersect(visibleAreaWithScrollbars); | 52 scrollViewDirtyRect.intersect(visibleAreaWithScrollbars); |
53 scrollViewDirtyRect.moveBy(-m_frameView.location()); | 53 scrollViewDirtyRect.moveBy(-frameView().location()); |
54 | 54 |
55 TransformRecorder transformRecorder(*context, *m_frameView.layoutView(), | 55 TransformRecorder transformRecorder(*context, *frameView().layoutView(), |
56 AffineTransform::translation(m_frameView.x(), m_frameView.y())); | 56 AffineTransform::translation(frameView().x(), frameView().y())); |
57 | 57 |
58 ClipRecorder recorder(*context, *m_frameView.layoutView(), DisplayItem::
ClipFrameScrollbars, LayoutRect(IntPoint(), visibleAreaWithScrollbars.size())); | 58 ClipRecorder recorder(*context, *frameView().layoutView(), DisplayItem::
ClipFrameScrollbars, LayoutRect(IntPoint(), visibleAreaWithScrollbars.size())); |
59 | 59 |
60 paintScrollbars(context, scrollViewDirtyRect); | 60 paintScrollbars(context, scrollViewDirtyRect); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 void FramePainter::paintContents(GraphicsContext* context, const GlobalPaintFlag
s globalPaintFlags, const IntRect& rect) | 64 void FramePainter::paintContents(GraphicsContext* context, const GlobalPaintFlag
s globalPaintFlags, const IntRect& rect) |
65 { | 65 { |
66 Document* document = m_frameView.frame().document(); | 66 Document* document = frameView().frame().document(); |
67 | 67 |
68 #ifndef NDEBUG | 68 #ifndef NDEBUG |
69 bool fillWithRed; | 69 bool fillWithRed; |
70 if (document->printing()) | 70 if (document->printing()) |
71 fillWithRed = false; // Printing, don't fill with red (can't remember wh
y). | 71 fillWithRed = false; // Printing, don't fill with red (can't remember wh
y). |
72 else if (m_frameView.frame().owner()) | 72 else if (frameView().frame().owner()) |
73 fillWithRed = false; // Subframe, don't fill with red. | 73 fillWithRed = false; // Subframe, don't fill with red. |
74 else if (m_frameView.isTransparent()) | 74 else if (frameView().isTransparent()) |
75 fillWithRed = false; // Transparent, don't fill with red. | 75 fillWithRed = false; // Transparent, don't fill with red. |
76 else if (globalPaintFlags & GlobalPaintSelectionOnly) | 76 else if (globalPaintFlags & GlobalPaintSelectionOnly) |
77 fillWithRed = false; // Selections are transparent, don't fill with red. | 77 fillWithRed = false; // Selections are transparent, don't fill with red. |
78 else if (m_frameView.nodeToDraw()) | 78 else if (frameView().nodeToDraw()) |
79 fillWithRed = false; // Element images are transparent, don't fill with
red. | 79 fillWithRed = false; // Element images are transparent, don't fill with
red. |
80 else | 80 else |
81 fillWithRed = true; | 81 fillWithRed = true; |
82 | 82 |
83 if (fillWithRed && !LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(
*context, *m_frameView.layoutView(), DisplayItem::DebugRedFill)) { | 83 if (fillWithRed && !LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(
*context, *frameView().layoutView(), DisplayItem::DebugRedFill)) { |
84 IntRect contentRect(IntPoint(), m_frameView.contentsSize()); | 84 IntRect contentRect(IntPoint(), frameView().contentsSize()); |
85 LayoutObjectDrawingRecorder drawingRecorder(*context, *m_frameView.layou
tView(), DisplayItem::DebugRedFill, contentRect); | 85 LayoutObjectDrawingRecorder drawingRecorder(*context, *frameView().layou
tView(), DisplayItem::DebugRedFill, contentRect); |
86 } | 86 } |
87 #endif | 87 #endif |
88 | 88 |
89 LayoutView* layoutView = m_frameView.layoutView(); | 89 LayoutView* layoutView = frameView().layoutView(); |
90 if (!layoutView) { | 90 if (!layoutView) { |
91 WTF_LOG_ERROR("called FramePainter::paint with nil layoutObject"); | 91 WTF_LOG_ERROR("called FramePainter::paint with nil layoutObject"); |
92 return; | 92 return; |
93 } | 93 } |
94 | 94 |
95 RELEASE_ASSERT(!m_frameView.needsLayout()); | 95 RELEASE_ASSERT(!frameView().needsLayout()); |
96 ASSERT(document->lifecycle().state() >= DocumentLifecycle::CompositingClean)
; | 96 ASSERT(document->lifecycle().state() >= DocumentLifecycle::CompositingClean)
; |
97 | 97 |
98 TRACE_EVENT1("devtools.timeline", "Paint", "data", InspectorPaintEvent::data
(layoutView, LayoutRect(rect), 0)); | 98 TRACE_EVENT1("devtools.timeline", "Paint", "data", InspectorPaintEvent::data
(layoutView, LayoutRect(rect), 0)); |
99 | 99 |
100 bool isTopLevelPainter = !s_inPaintContents; | 100 bool isTopLevelPainter = !s_inPaintContents; |
101 s_inPaintContents = true; | 101 s_inPaintContents = true; |
102 | 102 |
103 FontCachePurgePreventer fontCachePurgePreventer; | 103 FontCachePurgePreventer fontCachePurgePreventer; |
104 | 104 |
105 // TODO(jchaffraix): GlobalPaintFlags should be const during a paint | 105 // TODO(jchaffraix): GlobalPaintFlags should be const during a paint |
106 // phase. Thus we should set this flag upfront (crbug.com/510280). | 106 // phase. Thus we should set this flag upfront (crbug.com/510280). |
107 GlobalPaintFlags localPaintFlags = globalPaintFlags; | 107 GlobalPaintFlags localPaintFlags = globalPaintFlags; |
108 if (document->printing()) | 108 if (document->printing()) |
109 localPaintFlags |= GlobalPaintFlattenCompositingLayers | GlobalPaintPrin
ting; | 109 localPaintFlags |= GlobalPaintFlattenCompositingLayers | GlobalPaintPrin
ting; |
110 | 110 |
111 ASSERT(!m_frameView.isPainting()); | 111 ASSERT(!frameView().isPainting()); |
112 m_frameView.setIsPainting(true); | 112 frameView().setIsPainting(true); |
113 | 113 |
114 // m_frameView.nodeToDraw() is used to draw only one element (and its descen
dants) | 114 // frameView().nodeToDraw() is used to draw only one element (and its descen
dants) |
115 LayoutObject* layoutObject = m_frameView.nodeToDraw() ? m_frameView.nodeToDr
aw()->layoutObject() : 0; | 115 LayoutObject* layoutObject = frameView().nodeToDraw() ? frameView().nodeToDr
aw()->layoutObject() : 0; |
116 DeprecatedPaintLayer* rootLayer = layoutView->layer(); | 116 DeprecatedPaintLayer* rootLayer = layoutView->layer(); |
117 | 117 |
118 #if ENABLE(ASSERT) | 118 #if ENABLE(ASSERT) |
119 layoutView->assertSubtreeIsLaidOut(); | 119 layoutView->assertSubtreeIsLaidOut(); |
120 LayoutObject::SetLayoutNeededForbiddenScope forbidSetNeedsLayout(*rootLayer-
>layoutObject()); | 120 LayoutObject::SetLayoutNeededForbiddenScope forbidSetNeedsLayout(*rootLayer-
>layoutObject()); |
121 #endif | 121 #endif |
122 | 122 |
123 DeprecatedPaintLayerPainter layerPainter(*rootLayer); | 123 DeprecatedPaintLayerPainter layerPainter(*rootLayer); |
124 | 124 |
125 float deviceScaleFactor = blink::deviceScaleFactor(rootLayer->layoutObject()
->frame()); | 125 float deviceScaleFactor = blink::deviceScaleFactor(rootLayer->layoutObject()
->frame()); |
126 context->setDeviceScaleFactor(deviceScaleFactor); | 126 context->setDeviceScaleFactor(deviceScaleFactor); |
127 | 127 |
128 layerPainter.paint(context, LayoutRect(rect), localPaintFlags, layoutObject)
; | 128 layerPainter.paint(context, LayoutRect(rect), localPaintFlags, layoutObject)
; |
129 | 129 |
130 if (rootLayer->containsDirtyOverlayScrollbars()) | 130 if (rootLayer->containsDirtyOverlayScrollbars()) |
131 layerPainter.paintOverlayScrollbars(context, LayoutRect(rect), localPain
tFlags, layoutObject); | 131 layerPainter.paintOverlayScrollbars(context, LayoutRect(rect), localPain
tFlags, layoutObject); |
132 | 132 |
133 m_frameView.setIsPainting(false); | 133 frameView().setIsPainting(false); |
134 | 134 |
135 m_frameView.setLastPaintTime(currentTime()); | 135 frameView().setLastPaintTime(currentTime()); |
136 | 136 |
137 // Regions may have changed as a result of the visibility/z-index of element
changing. | 137 // Regions may have changed as a result of the visibility/z-index of element
changing. |
138 if (document->annotatedRegionsDirty()) | 138 if (document->annotatedRegionsDirty()) |
139 m_frameView.updateAnnotatedRegions(); | 139 frameView().updateAnnotatedRegions(); |
140 | 140 |
141 if (isTopLevelPainter) { | 141 if (isTopLevelPainter) { |
142 // Everything that happens after paintContents completions is considered | 142 // Everything that happens after paintContents completions is considered |
143 // to be part of the next frame. | 143 // to be part of the next frame. |
144 memoryCache()->updateFramePaintTimestamp(); | 144 memoryCache()->updateFramePaintTimestamp(); |
145 s_inPaintContents = false; | 145 s_inPaintContents = false; |
146 } | 146 } |
147 | 147 |
148 InspectorInstrumentation::didPaint(layoutView, 0, context, LayoutRect(rect))
; | 148 InspectorInstrumentation::didPaint(layoutView, 0, context, LayoutRect(rect))
; |
149 } | 149 } |
150 | 150 |
151 void FramePainter::paintScrollbars(GraphicsContext* context, const IntRect& rect
) | 151 void FramePainter::paintScrollbars(GraphicsContext* context, const IntRect& rect
) |
152 { | 152 { |
153 if (m_frameView.horizontalScrollbar() && !m_frameView.layerForHorizontalScro
llbar()) | 153 if (frameView().horizontalScrollbar() && !frameView().layerForHorizontalScro
llbar()) |
154 paintScrollbar(context, m_frameView.horizontalScrollbar(), rect); | 154 paintScrollbar(context, frameView().horizontalScrollbar(), rect); |
155 if (m_frameView.verticalScrollbar() && !m_frameView.layerForVerticalScrollba
r()) | 155 if (frameView().verticalScrollbar() && !frameView().layerForVerticalScrollba
r()) |
156 paintScrollbar(context, m_frameView.verticalScrollbar(), rect); | 156 paintScrollbar(context, frameView().verticalScrollbar(), rect); |
157 | 157 |
158 if (m_frameView.layerForScrollCorner()) | 158 if (frameView().layerForScrollCorner()) |
159 return; | 159 return; |
160 | 160 |
161 paintScrollCorner(context, m_frameView.scrollCornerRect()); | 161 paintScrollCorner(context, frameView().scrollCornerRect()); |
162 } | 162 } |
163 | 163 |
164 void FramePainter::paintScrollCorner(GraphicsContext* context, const IntRect& co
rnerRect) | 164 void FramePainter::paintScrollCorner(GraphicsContext* context, const IntRect& co
rnerRect) |
165 { | 165 { |
166 if (m_frameView.scrollCorner()) { | 166 if (frameView().scrollCorner()) { |
167 bool needsBackground = m_frameView.frame().isMainFrame(); | 167 bool needsBackground = frameView().frame().isMainFrame(); |
168 if (needsBackground && !LayoutObjectDrawingRecorder::useCachedDrawingIfP
ossible(*context, *m_frameView.layoutView(), DisplayItem::ScrollbarCorner)) { | 168 if (needsBackground && !LayoutObjectDrawingRecorder::useCachedDrawingIfP
ossible(*context, *frameView().layoutView(), DisplayItem::ScrollbarCorner)) { |
169 LayoutObjectDrawingRecorder drawingRecorder(*context, *m_frameView.l
ayoutView(), DisplayItem::ScrollbarCorner, cornerRect); | 169 LayoutObjectDrawingRecorder drawingRecorder(*context, *frameView().l
ayoutView(), DisplayItem::ScrollbarCorner, cornerRect); |
170 context->fillRect(cornerRect, m_frameView.baseBackgroundColor()); | 170 context->fillRect(cornerRect, frameView().baseBackgroundColor()); |
171 | 171 |
172 } | 172 } |
173 ScrollbarPainter::paintIntoRect(m_frameView.scrollCorner(), context, cor
nerRect.location(), LayoutRect(cornerRect)); | 173 ScrollbarPainter::paintIntoRect(frameView().scrollCorner(), context, cor
nerRect.location(), LayoutRect(cornerRect)); |
174 return; | 174 return; |
175 } | 175 } |
176 | 176 |
177 ScrollbarTheme::theme()->paintScrollCorner(context, *m_frameView.layoutView(
), cornerRect); | 177 ScrollbarTheme::theme()->paintScrollCorner(context, *frameView().layoutView(
), cornerRect); |
178 } | 178 } |
179 | 179 |
180 void FramePainter::paintScrollbar(GraphicsContext* context, Scrollbar* bar, cons
t IntRect& rect) | 180 void FramePainter::paintScrollbar(GraphicsContext* context, Scrollbar* bar, cons
t IntRect& rect) |
181 { | 181 { |
182 bool needsBackground = bar->isCustomScrollbar() && m_frameView.frame().isMai
nFrame(); | 182 bool needsBackground = bar->isCustomScrollbar() && frameView().frame().isMai
nFrame(); |
183 if (needsBackground) { | 183 if (needsBackground) { |
184 IntRect toFill = bar->frameRect(); | 184 IntRect toFill = bar->frameRect(); |
185 toFill.intersect(rect); | 185 toFill.intersect(rect); |
186 context->fillRect(toFill, m_frameView.baseBackgroundColor()); | 186 context->fillRect(toFill, frameView().baseBackgroundColor()); |
187 } | 187 } |
188 | 188 |
189 bar->paint(context, rect); | 189 bar->paint(context, rect); |
190 } | 190 } |
191 | 191 |
| 192 FrameView& FramePainter::frameView() |
| 193 { |
| 194 return *m_frameView; |
| 195 } |
| 196 |
192 } // namespace blink | 197 } // namespace blink |
OLD | NEW |