Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(213)

Side by Side Diff: third_party/WebKit/Source/core/paint/FramePainter.cpp

Issue 1511003003: Use refs for non-null GraphicsContext, Scrollbar, etc. in scrollbar related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ScrollbarRemove
Patch Set: yet another mac fix Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/editing/markers/DocumentMarkerController.h" 8 #include "core/editing/markers/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"
11 #include "core/inspector/InspectorInstrumentation.h" 11 #include "core/inspector/InspectorInstrumentation.h"
12 #include "core/inspector/InspectorTraceEvents.h" 12 #include "core/inspector/InspectorTraceEvents.h"
13 #include "core/layout/LayoutView.h" 13 #include "core/layout/LayoutView.h"
14 #include "core/page/Page.h" 14 #include "core/page/Page.h"
15 #include "core/paint/LayoutObjectDrawingRecorder.h" 15 #include "core/paint/LayoutObjectDrawingRecorder.h"
16 #include "core/paint/PaintInfo.h" 16 #include "core/paint/PaintInfo.h"
17 #include "core/paint/PaintLayer.h" 17 #include "core/paint/PaintLayer.h"
18 #include "core/paint/PaintLayerPainter.h" 18 #include "core/paint/PaintLayerPainter.h"
19 #include "core/paint/ScrollbarPainter.h" 19 #include "core/paint/ScrollbarPainter.h"
20 #include "core/paint/TransformRecorder.h" 20 #include "core/paint/TransformRecorder.h"
21 #include "platform/fonts/FontCache.h" 21 #include "platform/fonts/FontCache.h"
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 CullRect& rect) 30 void FramePainter::paint(GraphicsContext& context, const GlobalPaintFlags global PaintFlags, const CullRect& rect)
31 { 31 {
32 frameView().notifyPageThatContentAreaWillPaint(); 32 frameView().notifyPageThatContentAreaWillPaint();
33 33
34 IntRect documentDirtyRect = rect.m_rect; 34 IntRect documentDirtyRect = rect.m_rect;
35 IntRect visibleAreaWithoutScrollbars(frameView().location(), 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, *frameView().layoutView(), 39 TransformRecorder transformRecorder(context, *frameView().layoutView(),
40 AffineTransform::translation(frameView().x() - frameView().scrollX() , frameView().y() - frameView().scrollY())); 40 AffineTransform::translation(frameView().x() - frameView().scrollX() , frameView().y() - frameView().scrollY()));
41 41
42 ClipRecorder recorder(*context, *frameView().layoutView(), DisplayItem:: ClipFrameToVisibleContentRect, LayoutRect(frameView().visibleContentRect())); 42 ClipRecorder recorder(context, *frameView().layoutView(), DisplayItem::C lipFrameToVisibleContentRect, LayoutRect(frameView().visibleContentRect()));
43 43
44 documentDirtyRect.moveBy(-frameView().location() + 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 (!frameView().scrollbarsSuppressed() && (frameView().horizontalScrollbar( ) || frameView().verticalScrollbar())) { 49 if (!frameView().scrollbarsSuppressed() && (frameView().horizontalScrollbar( ) || frameView().verticalScrollbar())) {
50 IntRect scrollViewDirtyRect = rect.m_rect; 50 IntRect scrollViewDirtyRect = rect.m_rect;
51 IntRect visibleAreaWithScrollbars(frameView().location(), 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(-frameView().location()); 53 scrollViewDirtyRect.moveBy(-frameView().location());
54 54
55 TransformRecorder transformRecorder(*context, *frameView().layoutView(), 55 TransformRecorder transformRecorder(context, *frameView().layoutView(),
56 AffineTransform::translation(frameView().x(), frameView().y())); 56 AffineTransform::translation(frameView().x(), frameView().y()));
57 57
58 ClipRecorder recorder(*context, *frameView().layoutView(), DisplayItem:: ClipFrameScrollbars, LayoutRect(IntPoint(), visibleAreaWithScrollbars.size())); 58 ClipRecorder recorder(context, *frameView().layoutView(), DisplayItem::C lipFrameScrollbars, 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 = 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 (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 (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 (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, *frameView().layoutView(), DisplayItem::DebugRedFill, LayoutPoint())) { 83 if (fillWithRed && !LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( context, *frameView().layoutView(), DisplayItem::DebugRedFill, LayoutPoint())) {
84 IntRect contentRect(IntPoint(), frameView().contentsSize()); 84 IntRect contentRect(IntPoint(), frameView().contentsSize());
85 LayoutObjectDrawingRecorder drawingRecorder(*context, *frameView().layou tView(), DisplayItem::DebugRedFill, contentRect, LayoutPoint()); 85 LayoutObjectDrawingRecorder drawingRecorder(context, *frameView().layout View(), DisplayItem::DebugRedFill, contentRect, LayoutPoint());
86 } 86 }
87 #endif 87 #endif
88 88
89 LayoutView* layoutView = 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(!frameView().needsLayout()); 95 RELEASE_ASSERT(!frameView().needsLayout());
(...skipping 20 matching lines...) Expand all
116 PaintLayer* rootLayer = layoutView->layer(); 116 PaintLayer* 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 PaintLayerPainter layerPainter(*rootLayer); 123 PaintLayerPainter 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), localPai ntFlags, layoutObject);
132 132
133 frameView().setIsPainting(false); 133 frameView().setIsPainting(false);
134 134
135 // Regions may have changed as a result of the visibility/z-index of element changing. 135 // Regions may have changed as a result of the visibility/z-index of element changing.
136 if (document->annotatedRegionsDirty()) 136 if (document->annotatedRegionsDirty())
137 frameView().updateDocumentAnnotatedRegions(); 137 frameView().updateDocumentAnnotatedRegions();
138 138
139 if (isTopLevelPainter) { 139 if (isTopLevelPainter) {
140 // Everything that happens after paintContents completions is considered 140 // Everything that happens after paintContents completions is considered
141 // to be part of the next frame. 141 // to be part of the next frame.
142 memoryCache()->updateFramePaintTimestamp(); 142 memoryCache()->updateFramePaintTimestamp();
143 s_inPaintContents = false; 143 s_inPaintContents = false;
144 } 144 }
145 145
146 InspectorInstrumentation::didPaint(layoutView, 0, context, LayoutRect(rect)) ; 146 InspectorInstrumentation::didPaint(layoutView, 0, &context, LayoutRect(rect) );
147 } 147 }
148 148
149 void FramePainter::paintScrollbars(GraphicsContext* context, const IntRect& rect ) 149 void FramePainter::paintScrollbars(GraphicsContext& context, const IntRect& rect )
150 { 150 {
151 if (frameView().horizontalScrollbar() && !frameView().layerForHorizontalScro llbar()) 151 if (frameView().horizontalScrollbar() && !frameView().layerForHorizontalScro llbar())
152 paintScrollbar(context, frameView().horizontalScrollbar(), rect); 152 paintScrollbar(context, *frameView().horizontalScrollbar(), rect);
153 if (frameView().verticalScrollbar() && !frameView().layerForVerticalScrollba r()) 153 if (frameView().verticalScrollbar() && !frameView().layerForVerticalScrollba r())
154 paintScrollbar(context, frameView().verticalScrollbar(), rect); 154 paintScrollbar(context, *frameView().verticalScrollbar(), rect);
155 155
156 if (frameView().layerForScrollCorner()) 156 if (frameView().layerForScrollCorner())
157 return; 157 return;
158 158
159 paintScrollCorner(context, frameView().scrollCornerRect()); 159 paintScrollCorner(context, frameView().scrollCornerRect());
160 } 160 }
161 161
162 void FramePainter::paintScrollCorner(GraphicsContext* context, const IntRect& co rnerRect) 162 void FramePainter::paintScrollCorner(GraphicsContext& context, const IntRect& co rnerRect)
163 { 163 {
164 if (frameView().scrollCorner()) { 164 if (frameView().scrollCorner()) {
165 bool needsBackground = frameView().frame().isMainFrame(); 165 bool needsBackground = frameView().frame().isMainFrame();
166 if (needsBackground && !LayoutObjectDrawingRecorder::useCachedDrawingIfP ossible(*context, *frameView().layoutView(), DisplayItem::ScrollbarCorner, Layou tPoint())) { 166 if (needsBackground && !LayoutObjectDrawingRecorder::useCachedDrawingIfP ossible(context, *frameView().layoutView(), DisplayItem::ScrollbarCorner, Layout Point())) {
167 LayoutObjectDrawingRecorder drawingRecorder(*context, *frameView().l ayoutView(), DisplayItem::ScrollbarCorner, FloatRect(cornerRect), LayoutPoint()) ; 167 LayoutObjectDrawingRecorder drawingRecorder(context, *frameView().la youtView(), DisplayItem::ScrollbarCorner, FloatRect(cornerRect), LayoutPoint());
168 context->fillRect(cornerRect, frameView().baseBackgroundColor()); 168 context.fillRect(cornerRect, frameView().baseBackgroundColor());
169 169
170 } 170 }
171 ScrollbarPainter::paintIntoRect(*frameView().scrollCorner(), context, co rnerRect.location(), LayoutRect(cornerRect)); 171 ScrollbarPainter::paintIntoRect(*frameView().scrollCorner(), context, co rnerRect.location(), LayoutRect(cornerRect));
172 return; 172 return;
173 } 173 }
174 174
175 ScrollbarTheme::theme()->paintScrollCorner(context, *frameView().layoutView( ), cornerRect); 175 ScrollbarTheme::theme().paintScrollCorner(context, *frameView().layoutView() , cornerRect);
176 } 176 }
177 177
178 void FramePainter::paintScrollbar(GraphicsContext* context, Scrollbar* bar, cons t IntRect& rect) 178 void FramePainter::paintScrollbar(GraphicsContext& context, Scrollbar& bar, cons t IntRect& rect)
179 { 179 {
180 bool needsBackground = bar->isCustomScrollbar() && frameView().frame().isMai nFrame(); 180 bool needsBackground = bar.isCustomScrollbar() && frameView().frame().isMain Frame();
181 if (needsBackground) { 181 if (needsBackground) {
182 IntRect toFill = bar->frameRect(); 182 IntRect toFill = bar.frameRect();
183 toFill.intersect(rect); 183 toFill.intersect(rect);
184 context->fillRect(toFill, frameView().baseBackgroundColor()); 184 context.fillRect(toFill, frameView().baseBackgroundColor());
185 } 185 }
186 186
187 bar->paint(context, CullRect(rect)); 187 bar.paint(context, CullRect(rect));
188 } 188 }
189 189
190 const FrameView& FramePainter::frameView() 190 const FrameView& FramePainter::frameView()
191 { 191 {
192 ASSERT(m_frameView); 192 ASSERT(m_frameView);
193 return *m_frameView; 193 return *m_frameView;
194 } 194 }
195 195
196 } // namespace blink 196 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698