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/BlockPainter.h" | 6 #include "core/paint/BlockPainter.h" |
7 | 7 |
8 #include "core/editing/FrameSelection.h" | 8 #include "core/editing/FrameSelection.h" |
9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
10 #include "core/layout/LayoutFlexibleBox.h" | 10 #include "core/layout/LayoutFlexibleBox.h" |
11 #include "core/layout/LayoutInline.h" | 11 #include "core/layout/LayoutInline.h" |
12 #include "core/page/Page.h" | 12 #include "core/page/Page.h" |
13 #include "core/paint/BoxClipper.h" | 13 #include "core/paint/BoxClipper.h" |
14 #include "core/paint/BoxPainter.h" | 14 #include "core/paint/BoxPainter.h" |
15 #include "core/paint/DeprecatedPaintLayer.h" | 15 #include "core/paint/DeprecatedPaintLayer.h" |
16 #include "core/paint/InlinePainter.h" | 16 #include "core/paint/InlinePainter.h" |
17 #include "core/paint/LayoutObjectDrawingRecorder.h" | 17 #include "core/paint/LayoutObjectDrawingRecorder.h" |
18 #include "core/paint/LineBoxListPainter.h" | 18 #include "core/paint/LineBoxListPainter.h" |
| 19 #include "core/paint/PaintDataCache.h" |
19 #include "core/paint/PaintInfo.h" | 20 #include "core/paint/PaintInfo.h" |
20 #include "core/paint/ScopeRecorder.h" | 21 #include "core/paint/ScopeRecorder.h" |
21 #include "core/paint/ScrollRecorder.h" | 22 #include "core/paint/ScrollRecorder.h" |
22 #include "core/paint/ScrollableAreaPainter.h" | 23 #include "core/paint/ScrollableAreaPainter.h" |
23 #include "platform/graphics/paint/ClipRecorder.h" | 24 #include "platform/graphics/paint/ClipRecorder.h" |
24 #include "wtf/Optional.h" | 25 #include "wtf/Optional.h" |
25 | 26 |
26 namespace blink { | 27 namespace blink { |
27 | 28 |
28 void BlockPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOff
set) | 29 void BlockPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOff
set) |
(...skipping 17 matching lines...) Expand all Loading... |
46 if (!overflowBox.intersects(LayoutRect(localPaintInfo.rect))) | 47 if (!overflowBox.intersects(LayoutRect(localPaintInfo.rect))) |
47 return; | 48 return; |
48 } | 49 } |
49 } else { | 50 } else { |
50 RELEASE_ASSERT(!m_layoutBlock.isDocumentElement()); | 51 RELEASE_ASSERT(!m_layoutBlock.isDocumentElement()); |
51 } | 52 } |
52 | 53 |
53 // There are some cases where not all clipped visual overflow is accounted f
or. | 54 // There are some cases where not all clipped visual overflow is accounted f
or. |
54 // FIXME: reduce the number of such cases. | 55 // FIXME: reduce the number of such cases. |
55 ContentsClipBehavior contentsClipBehavior = ForceContentsClip; | 56 ContentsClipBehavior contentsClipBehavior = ForceContentsClip; |
56 if (m_layoutBlock.hasOverflowClip() && !m_layoutBlock.hasControlClip() && !(
m_layoutBlock.shouldPaintSelectionGaps() && originalPhase == PaintPhaseForegroun
d) && !hasCaret()) | 57 if (m_layoutBlock.hasOverflowClip() |
| 58 && !m_layoutBlock.hasControlClip() |
| 59 && !(m_layoutBlock.shouldPaintSelectionGaps() && originalPhase == PaintP
haseForeground) |
| 60 && !hasCaret(paintInfo.paintDataCache())) |
57 contentsClipBehavior = SkipContentsClipIfPossible; | 61 contentsClipBehavior = SkipContentsClipIfPossible; |
58 | 62 |
59 if (localPaintInfo.phase == PaintPhaseOutline) { | 63 if (localPaintInfo.phase == PaintPhaseOutline) { |
60 localPaintInfo.phase = PaintPhaseChildOutlines; | 64 localPaintInfo.phase = PaintPhaseChildOutlines; |
61 } else if (localPaintInfo.phase == PaintPhaseChildBlockBackground) { | 65 } else if (localPaintInfo.phase == PaintPhaseChildBlockBackground) { |
62 localPaintInfo.phase = PaintPhaseBlockBackground; | 66 localPaintInfo.phase = PaintPhaseBlockBackground; |
63 m_layoutBlock.paintObject(localPaintInfo, adjustedPaintOffset); | 67 m_layoutBlock.paintObject(localPaintInfo, adjustedPaintOffset); |
64 localPaintInfo.phase = PaintPhaseChildBlockBackgrounds; | 68 localPaintInfo.phase = PaintPhaseChildBlockBackgrounds; |
65 } | 69 } |
66 | 70 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 // inline element having outline-style:auto paints the whole focus ring. | 221 // inline element having outline-style:auto paints the whole focus ring. |
218 if (!m_layoutBlock.style()->outlineStyleIsAuto() || !m_layoutBlock.isAno
nymousBlockContinuation()) | 222 if (!m_layoutBlock.style()->outlineStyleIsAuto() || !m_layoutBlock.isAno
nymousBlockContinuation()) |
219 ObjectPainter(m_layoutBlock).paintOutline(paintInfo, LayoutRect(pain
tOffset, m_layoutBlock.size()), visualOverflowRectWithPaintOffset(m_layoutBlock,
paintOffset)); | 223 ObjectPainter(m_layoutBlock).paintOutline(paintInfo, LayoutRect(pain
tOffset, m_layoutBlock.size()), visualOverflowRectWithPaintOffset(m_layoutBlock,
paintOffset)); |
220 } | 224 } |
221 | 225 |
222 if (paintPhase == PaintPhaseOutline || paintPhase == PaintPhaseChildOutlines
) | 226 if (paintPhase == PaintPhaseOutline || paintPhase == PaintPhaseChildOutlines
) |
223 paintContinuationOutlines(paintInfo, paintOffset); | 227 paintContinuationOutlines(paintInfo, paintOffset); |
224 | 228 |
225 // If the caret's node's layout object's containing block is this block, and
the paint action is PaintPhaseForeground, | 229 // If the caret's node's layout object's containing block is this block, and
the paint action is PaintPhaseForeground, |
226 // then paint the caret. | 230 // then paint the caret. |
227 if (paintPhase == PaintPhaseForeground && hasCaret()) { | 231 if (paintPhase == PaintPhaseForeground && hasCaret(paintInfo.paintDataCache(
))) { |
228 LayoutObjectDrawingRecorder recorder(*paintInfo.context, m_layoutBlock,
DisplayItem::Caret, visualOverflowRectWithPaintOffset(m_layoutBlock, paintOffset
)); | 232 LayoutObjectDrawingRecorder recorder(*paintInfo.context, m_layoutBlock,
DisplayItem::Caret, visualOverflowRectWithPaintOffset(m_layoutBlock, paintOffset
)); |
229 if (!recorder.canUseCachedDrawing()) | 233 if (!recorder.canUseCachedDrawing()) |
230 paintCarets(paintInfo, paintOffset); | 234 paintCarets(paintInfo, paintOffset); |
231 } | 235 } |
232 } | 236 } |
233 | 237 |
234 static inline bool caretBrowsingEnabled(const Frame* frame) | |
235 { | |
236 Settings* settings = frame->settings(); | |
237 return settings && settings->caretBrowsingEnabled(); | |
238 } | |
239 | |
240 static inline bool hasCursorCaret(const FrameSelection& selection, const LayoutB
lock* block, bool caretBrowsing) | |
241 { | |
242 return selection.caretLayoutObject() == block && (selection.hasEditableStyle
() || caretBrowsing); | |
243 } | |
244 | |
245 static inline bool hasDragCaret(const DragCaretController& dragCaretController,
const LayoutBlock* block, bool caretBrowsing) | |
246 { | |
247 return dragCaretController.caretLayoutObject() == block && (dragCaretControl
ler.isContentEditable() || caretBrowsing); | |
248 } | |
249 | |
250 void BlockPainter::paintCarets(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) | 238 void BlockPainter::paintCarets(const PaintInfo& paintInfo, const LayoutPoint& pa
intOffset) |
251 { | 239 { |
252 bool caretBrowsing = caretBrowsingEnabled(m_layoutBlock.frame()); | 240 bool hasCursorCaret = false; |
| 241 bool hasDragCaret = false; |
| 242 PaintDataCache localCache; |
| 243 PaintDataCache* paintDataCache = paintInfo.paintDataCache() ? paintInfo.pain
tDataCache() : &localCache; |
| 244 paintDataCache->getLayoutBlockCarets(m_layoutBlock, &hasCursorCaret, &hasDra
gCaret); |
| 245 LocalFrame* frame = m_layoutBlock.frame(); |
253 | 246 |
254 FrameSelection& selection = m_layoutBlock.frame()->selection(); | 247 if (hasCursorCaret) |
255 if (hasCursorCaret(selection, &m_layoutBlock, caretBrowsing)) { | 248 frame->selection().paintCaret(paintInfo.context, paintOffset, LayoutRect
(paintInfo.rect)); |
256 selection.paintCaret(paintInfo.context, paintOffset, LayoutRect(paintInf
o.rect)); | 249 if (hasDragCaret) |
257 } | 250 frame->page()->dragCaretController().paintDragCaret(frame, paintInfo.con
text, paintOffset, LayoutRect(paintInfo.rect)); |
258 | |
259 DragCaretController& dragCaretController = m_layoutBlock.frame()->page()->dr
agCaretController(); | |
260 if (hasDragCaret(dragCaretController, &m_layoutBlock, caretBrowsing)) { | |
261 dragCaretController.paintDragCaret(m_layoutBlock.frame(), paintInfo.cont
ext, paintOffset, LayoutRect(paintInfo.rect)); | |
262 } | |
263 } | 251 } |
264 | 252 |
265 LayoutRect BlockPainter::overflowRectForPaintRejection() const | 253 LayoutRect BlockPainter::overflowRectForPaintRejection() const |
266 { | 254 { |
267 LayoutRect overflowRect = m_layoutBlock.visualOverflowRect(); | 255 LayoutRect overflowRect = m_layoutBlock.visualOverflowRect(); |
268 if (!m_layoutBlock.hasOverflowModel() || !m_layoutBlock.usesCompositedScroll
ing()) | 256 if (!m_layoutBlock.hasOverflowModel() || !m_layoutBlock.usesCompositedScroll
ing()) |
269 return overflowRect; | 257 return overflowRect; |
270 | 258 |
271 overflowRect.unite(m_layoutBlock.layoutOverflowRect()); | 259 overflowRect.unite(m_layoutBlock.layoutOverflowRect()); |
272 overflowRect.move(-m_layoutBlock.scrolledContentOffset()); | 260 overflowRect.move(-m_layoutBlock.scrolledContentOffset()); |
273 return overflowRect; | 261 return overflowRect; |
274 } | 262 } |
275 | 263 |
276 bool BlockPainter::hasCaret() const | 264 bool BlockPainter::hasCaret(PaintDataCache* paintDataCache) const |
277 { | 265 { |
278 bool caretBrowsing = caretBrowsingEnabled(m_layoutBlock.frame()); | 266 if (paintDataCache) |
279 return hasCursorCaret(m_layoutBlock.frame()->selection(), &m_layoutBlock, ca
retBrowsing) | 267 return paintDataCache->layoutBlockHasCaret(m_layoutBlock); |
280 || hasDragCaret(m_layoutBlock.frame()->page()->dragCaretController(), &m
_layoutBlock, caretBrowsing); | 268 return PaintDataCache().layoutBlockHasCaret(m_layoutBlock); |
281 } | 269 } |
282 | 270 |
283 void BlockPainter::paintContents(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) | 271 void BlockPainter::paintContents(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) |
284 { | 272 { |
285 // Avoid painting descendants of the root element when stylesheets haven't l
oaded. This eliminates FOUC. | 273 // Avoid painting descendants of the root element when stylesheets haven't l
oaded. This eliminates FOUC. |
286 // It's ok not to draw, because later on, when all the stylesheets do load,
styleResolverChanged() on the Document | 274 // It's ok not to draw, because later on, when all the stylesheets do load,
styleResolverChanged() on the Document |
287 // will do a full paint invalidation. | 275 // will do a full paint invalidation. |
288 if (m_layoutBlock.document().didLayoutWithPendingStylesheets() && !m_layoutB
lock.isLayoutView()) | 276 if (m_layoutBlock.document().didLayoutWithPendingStylesheets() && !m_layoutB
lock.isLayoutView()) |
289 return; | 277 return; |
290 | 278 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 LayoutBlock* block = flow->containingBlock(); | 334 LayoutBlock* block = flow->containingBlock(); |
347 for ( ; block && block != &m_layoutBlock; block = block->containingBlock
()) | 335 for ( ; block && block != &m_layoutBlock; block = block->containingBlock
()) |
348 accumulatedPaintOffset.moveBy(block->location()); | 336 accumulatedPaintOffset.moveBy(block->location()); |
349 ASSERT(block); | 337 ASSERT(block); |
350 InlinePainter(*flow).paintOutline(info, accumulatedPaintOffset); | 338 InlinePainter(*flow).paintOutline(info, accumulatedPaintOffset); |
351 } | 339 } |
352 } | 340 } |
353 | 341 |
354 | 342 |
355 } // namespace blink | 343 } // namespace blink |
OLD | NEW |