| 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 "core/paint/BlockPainter.h" | 5 #include "core/paint/BlockPainter.h" |
| 6 | 6 |
| 7 #include "core/editing/DragCaretController.h" | 7 #include "core/editing/DragCaretController.h" |
| 8 #include "core/editing/FrameSelection.h" | 8 #include "core/editing/FrameSelection.h" |
| 9 #include "core/layout/LayoutFlexibleBox.h" | 9 #include "core/layout/LayoutFlexibleBox.h" |
| 10 #include "core/layout/LayoutInline.h" | 10 #include "core/layout/LayoutInline.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 void BlockPainter::paint(const PaintInfo& paintInfo, | 30 void BlockPainter::paint(const PaintInfo& paintInfo, |
| 31 const LayoutPoint& paintOffset) { | 31 const LayoutPoint& paintOffset) { |
| 32 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutBlock.location(); | 32 LayoutPoint adjustedPaintOffset = paintOffset + m_layoutBlock.location(); |
| 33 if (!intersectsPaintRect(paintInfo, adjustedPaintOffset)) | 33 if (!intersectsPaintRect(paintInfo, adjustedPaintOffset)) |
| 34 return; | 34 return; |
| 35 | 35 |
| 36 PaintInfo localPaintInfo(paintInfo); | 36 PaintInfo localPaintInfo(paintInfo); |
| 37 PaintPhase originalPhase = localPaintInfo.phase; | 37 PaintPhase originalPhase = localPaintInfo.phase; |
| 38 | 38 |
| 39 // There are some cases where not all clipped visual overflow is accounted for
. | 39 // There are some cases where not all clipped visual overflow is accounted |
| 40 // for. |
| 40 // FIXME: reduce the number of such cases. | 41 // FIXME: reduce the number of such cases. |
| 41 ContentsClipBehavior contentsClipBehavior = ForceContentsClip; | 42 ContentsClipBehavior contentsClipBehavior = ForceContentsClip; |
| 42 if (m_layoutBlock.hasOverflowClip() && !m_layoutBlock.hasControlClip() && | 43 if (m_layoutBlock.hasOverflowClip() && !m_layoutBlock.hasControlClip() && |
| 43 !m_layoutBlock.hasCaret()) | 44 !m_layoutBlock.hasCaret()) |
| 44 contentsClipBehavior = SkipContentsClipIfPossible; | 45 contentsClipBehavior = SkipContentsClipIfPossible; |
| 45 | 46 |
| 46 if (originalPhase == PaintPhaseOutline) { | 47 if (originalPhase == PaintPhaseOutline) { |
| 47 localPaintInfo.phase = PaintPhaseDescendantOutlinesOnly; | 48 localPaintInfo.phase = PaintPhaseDescendantOutlinesOnly; |
| 48 } else if (shouldPaintSelfBlockBackground(originalPhase)) { | 49 } else if (shouldPaintSelfBlockBackground(originalPhase)) { |
| 49 localPaintInfo.phase = PaintPhaseSelfBlockBackgroundOnly; | 50 localPaintInfo.phase = PaintPhaseSelfBlockBackgroundOnly; |
| 50 m_layoutBlock.paintObject(localPaintInfo, adjustedPaintOffset); | 51 m_layoutBlock.paintObject(localPaintInfo, adjustedPaintOffset); |
| 51 if (shouldPaintDescendantBlockBackgrounds(originalPhase)) | 52 if (shouldPaintDescendantBlockBackgrounds(originalPhase)) |
| 52 localPaintInfo.phase = PaintPhaseDescendantBlockBackgroundsOnly; | 53 localPaintInfo.phase = PaintPhaseDescendantBlockBackgroundsOnly; |
| 53 } | 54 } |
| 54 | 55 |
| 55 if (originalPhase != PaintPhaseSelfBlockBackgroundOnly && | 56 if (originalPhase != PaintPhaseSelfBlockBackgroundOnly && |
| 56 originalPhase != PaintPhaseSelfOutlineOnly) { | 57 originalPhase != PaintPhaseSelfOutlineOnly) { |
| 57 BoxClipper boxClipper(m_layoutBlock, localPaintInfo, adjustedPaintOffset, | 58 BoxClipper boxClipper(m_layoutBlock, localPaintInfo, adjustedPaintOffset, |
| 58 contentsClipBehavior); | 59 contentsClipBehavior); |
| 59 m_layoutBlock.paintObject(localPaintInfo, adjustedPaintOffset); | 60 m_layoutBlock.paintObject(localPaintInfo, adjustedPaintOffset); |
| 60 } | 61 } |
| 61 | 62 |
| 62 if (shouldPaintSelfOutline(originalPhase)) { | 63 if (shouldPaintSelfOutline(originalPhase)) { |
| 63 localPaintInfo.phase = PaintPhaseSelfOutlineOnly; | 64 localPaintInfo.phase = PaintPhaseSelfOutlineOnly; |
| 64 m_layoutBlock.paintObject(localPaintInfo, adjustedPaintOffset); | 65 m_layoutBlock.paintObject(localPaintInfo, adjustedPaintOffset); |
| 65 } | 66 } |
| 66 | 67 |
| 67 // Our scrollbar widgets paint exactly when we tell them to, so that they work
properly with | 68 // Our scrollbar widgets paint exactly when we tell them to, so that they work |
| 68 // z-index. We paint after we painted the background/border, so that the scrol
lbars will | 69 // properly with z-index. We paint after we painted the background/border, so |
| 69 // sit above the background/border. | 70 // that the scrollbars will sit above the background/border. |
| 70 localPaintInfo.phase = originalPhase; | 71 localPaintInfo.phase = originalPhase; |
| 71 paintOverflowControlsIfNeeded(localPaintInfo, adjustedPaintOffset); | 72 paintOverflowControlsIfNeeded(localPaintInfo, adjustedPaintOffset); |
| 72 } | 73 } |
| 73 | 74 |
| 74 void BlockPainter::paintOverflowControlsIfNeeded( | 75 void BlockPainter::paintOverflowControlsIfNeeded( |
| 75 const PaintInfo& paintInfo, | 76 const PaintInfo& paintInfo, |
| 76 const LayoutPoint& paintOffset) { | 77 const LayoutPoint& paintOffset) { |
| 77 if (m_layoutBlock.hasOverflowClip() && | 78 if (m_layoutBlock.hasOverflowClip() && |
| 78 m_layoutBlock.style()->visibility() == EVisibility::Visible && | 79 m_layoutBlock.style()->visibility() == EVisibility::Visible && |
| 79 shouldPaintSelfBlockBackground(paintInfo.phase) && | 80 shouldPaintSelfBlockBackground(paintInfo.phase) && |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 ObjectPainter(child).paintAllPhasesAtomically(paintInfo, childPoint); | 131 ObjectPainter(child).paintAllPhasesAtomically(paintInfo, childPoint); |
| 131 } | 132 } |
| 132 | 133 |
| 133 void BlockPainter::paintInlineBox(const InlineBox& inlineBox, | 134 void BlockPainter::paintInlineBox(const InlineBox& inlineBox, |
| 134 const PaintInfo& paintInfo, | 135 const PaintInfo& paintInfo, |
| 135 const LayoutPoint& paintOffset) { | 136 const LayoutPoint& paintOffset) { |
| 136 if (paintInfo.phase != PaintPhaseForeground && | 137 if (paintInfo.phase != PaintPhaseForeground && |
| 137 paintInfo.phase != PaintPhaseSelection) | 138 paintInfo.phase != PaintPhaseSelection) |
| 138 return; | 139 return; |
| 139 | 140 |
| 140 // Text clips are painted only for the direct inline children of the object th
at has a text clip style on it, not block children. | 141 // Text clips are painted only for the direct inline children of the object |
| 142 // that has a text clip style on it, not block children. |
| 141 ASSERT(paintInfo.phase != PaintPhaseTextClip); | 143 ASSERT(paintInfo.phase != PaintPhaseTextClip); |
| 142 | 144 |
| 143 LayoutPoint childPoint = paintOffset; | 145 LayoutPoint childPoint = paintOffset; |
| 144 if (inlineBox.parent() | 146 if (inlineBox.parent() |
| 145 ->getLineLayoutItem() | 147 ->getLineLayoutItem() |
| 146 .style() | 148 .style() |
| 147 ->isFlippedBlocksWritingMode()) // Faster than calling containingBloc
k(). | 149 ->isFlippedBlocksWritingMode()) { |
| 150 // Faster than calling containingBlock(). |
| 148 childPoint = | 151 childPoint = |
| 149 LineLayoutAPIShim::layoutObjectFrom(inlineBox.getLineLayoutItem()) | 152 LineLayoutAPIShim::layoutObjectFrom(inlineBox.getLineLayoutItem()) |
| 150 ->containingBlock() | 153 ->containingBlock() |
| 151 ->flipForWritingModeForChild( | 154 ->flipForWritingModeForChild( |
| 152 toLayoutBox(LineLayoutAPIShim::layoutObjectFrom( | 155 toLayoutBox(LineLayoutAPIShim::layoutObjectFrom( |
| 153 inlineBox.getLineLayoutItem())), | 156 inlineBox.getLineLayoutItem())), |
| 154 childPoint); | 157 childPoint); |
| 158 } |
| 155 | 159 |
| 156 ObjectPainter( | 160 ObjectPainter( |
| 157 *LineLayoutAPIShim::constLayoutObjectFrom(inlineBox.getLineLayoutItem())) | 161 *LineLayoutAPIShim::constLayoutObjectFrom(inlineBox.getLineLayoutItem())) |
| 158 .paintAllPhasesAtomically(paintInfo, childPoint); | 162 .paintAllPhasesAtomically(paintInfo, childPoint); |
| 159 } | 163 } |
| 160 | 164 |
| 161 void BlockPainter::paintObject(const PaintInfo& paintInfo, | 165 void BlockPainter::paintObject(const PaintInfo& paintInfo, |
| 162 const LayoutPoint& paintOffset) { | 166 const LayoutPoint& paintOffset) { |
| 163 const PaintPhase paintPhase = paintInfo.phase; | 167 const PaintPhase paintPhase = paintInfo.phase; |
| 164 | 168 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 paintPhase == PaintPhaseTextClip) | 236 paintPhase == PaintPhaseTextClip) |
| 233 blockFlowPainter.paintFloats(contentsPaintInfo, paintOffset); | 237 blockFlowPainter.paintFloats(contentsPaintInfo, paintOffset); |
| 234 } else { | 238 } else { |
| 235 paintContents(contentsPaintInfo, paintOffset); | 239 paintContents(contentsPaintInfo, paintOffset); |
| 236 } | 240 } |
| 237 } | 241 } |
| 238 | 242 |
| 239 if (shouldPaintSelfOutline(paintPhase)) | 243 if (shouldPaintSelfOutline(paintPhase)) |
| 240 ObjectPainter(m_layoutBlock).paintOutline(paintInfo, paintOffset); | 244 ObjectPainter(m_layoutBlock).paintOutline(paintInfo, paintOffset); |
| 241 | 245 |
| 242 // If the caret's node's layout object's containing block is this block, and t
he paint action is PaintPhaseForeground, | 246 // If the caret's node's layout object's containing block is this block, and |
| 243 // then paint the caret. | 247 // the paint action is PaintPhaseForeground, then paint the caret. |
| 244 if (paintPhase == PaintPhaseForeground && m_layoutBlock.hasCaret()) | 248 if (paintPhase == PaintPhaseForeground && m_layoutBlock.hasCaret()) |
| 245 paintCarets(paintInfo, paintOffset); | 249 paintCarets(paintInfo, paintOffset); |
| 246 } | 250 } |
| 247 | 251 |
| 248 void BlockPainter::paintCarets(const PaintInfo& paintInfo, | 252 void BlockPainter::paintCarets(const PaintInfo& paintInfo, |
| 249 const LayoutPoint& paintOffset) { | 253 const LayoutPoint& paintOffset) { |
| 250 LocalFrame* frame = m_layoutBlock.frame(); | 254 LocalFrame* frame = m_layoutBlock.frame(); |
| 251 | 255 |
| 252 if (m_layoutBlock.hasCursorCaret()) | 256 if (m_layoutBlock.hasCursorCaret()) |
| 253 frame->selection().paintCaret(paintInfo.context, paintOffset); | 257 frame->selection().paintCaret(paintInfo.context, paintOffset); |
| 254 | 258 |
| 255 if (m_layoutBlock.hasDragCaret()) | 259 if (m_layoutBlock.hasDragCaret()) |
| 256 frame->page()->dragCaretController().paintDragCaret( | 260 frame->page()->dragCaretController().paintDragCaret( |
| 257 frame, paintInfo.context, paintOffset); | 261 frame, paintInfo.context, paintOffset); |
| 258 } | 262 } |
| 259 | 263 |
| 260 bool BlockPainter::intersectsPaintRect( | 264 bool BlockPainter::intersectsPaintRect( |
| 261 const PaintInfo& paintInfo, | 265 const PaintInfo& paintInfo, |
| 262 const LayoutPoint& adjustedPaintOffset) const { | 266 const LayoutPoint& adjustedPaintOffset) const { |
| 263 LayoutRect overflowRect; | 267 LayoutRect overflowRect; |
| 264 if (paintInfo.isPrinting() && m_layoutBlock.isAnonymousBlock() && | 268 if (paintInfo.isPrinting() && m_layoutBlock.isAnonymousBlock() && |
| 265 m_layoutBlock.childrenInline()) { | 269 m_layoutBlock.childrenInline()) { |
| 266 // For case <a href="..."><div>...</div></a>, when m_layoutBlock is the anon
ymous container | 270 // For case <a href="..."><div>...</div></a>, when m_layoutBlock is the |
| 267 // of <a>, the anonymous container's visual overflow is empty, but we need t
o continue | 271 // anonymous container of <a>, the anonymous container's visual overflow is |
| 268 // painting to output <a>'s PDF URL rect which covers the continuations, as
if we included | 272 // empty, but we need to continue painting to output <a>'s PDF URL rect |
| 269 // <a>'s PDF URL rect into m_layoutBlock's visual overflow. | 273 // which covers the continuations, as if we included <a>'s PDF URL rect into |
| 274 // m_layoutBlock's visual overflow. |
| 270 Vector<LayoutRect> rects; | 275 Vector<LayoutRect> rects; |
| 271 m_layoutBlock.addElementVisualOverflowRects(rects, LayoutPoint()); | 276 m_layoutBlock.addElementVisualOverflowRects(rects, LayoutPoint()); |
| 272 overflowRect = unionRect(rects); | 277 overflowRect = unionRect(rects); |
| 273 } | 278 } |
| 274 overflowRect.unite(m_layoutBlock.visualOverflowRect()); | 279 overflowRect.unite(m_layoutBlock.visualOverflowRect()); |
| 275 | 280 |
| 276 bool usesCompositedScrolling = m_layoutBlock.hasOverflowModel() && | 281 bool usesCompositedScrolling = m_layoutBlock.hasOverflowModel() && |
| 277 m_layoutBlock.usesCompositedScrolling(); | 282 m_layoutBlock.usesCompositedScrolling(); |
| 278 | 283 |
| 279 if (usesCompositedScrolling) { | 284 if (usesCompositedScrolling) { |
| 280 LayoutRect layoutOverflowRect = m_layoutBlock.layoutOverflowRect(); | 285 LayoutRect layoutOverflowRect = m_layoutBlock.layoutOverflowRect(); |
| 281 overflowRect.unite(layoutOverflowRect); | 286 overflowRect.unite(layoutOverflowRect); |
| 282 } | 287 } |
| 283 m_layoutBlock.flipForWritingMode(overflowRect); | 288 m_layoutBlock.flipForWritingMode(overflowRect); |
| 284 | 289 |
| 285 // Scrolling is applied in physical space, which is why it is after the flip a
bove. | 290 // Scrolling is applied in physical space, which is why it is after the flip |
| 291 // above. |
| 286 if (usesCompositedScrolling) { | 292 if (usesCompositedScrolling) { |
| 287 overflowRect.move(-m_layoutBlock.scrolledContentOffset()); | 293 overflowRect.move(-m_layoutBlock.scrolledContentOffset()); |
| 288 } | 294 } |
| 289 | 295 |
| 290 overflowRect.moveBy(adjustedPaintOffset); | 296 overflowRect.moveBy(adjustedPaintOffset); |
| 291 return paintInfo.cullRect().intersectsCullRect(overflowRect); | 297 return paintInfo.cullRect().intersectsCullRect(overflowRect); |
| 292 } | 298 } |
| 293 | 299 |
| 294 void BlockPainter::paintContents(const PaintInfo& paintInfo, | 300 void BlockPainter::paintContents(const PaintInfo& paintInfo, |
| 295 const LayoutPoint& paintOffset) { | 301 const LayoutPoint& paintOffset) { |
| 296 DCHECK(!m_layoutBlock.childrenInline()); | 302 DCHECK(!m_layoutBlock.childrenInline()); |
| 297 PaintInfo paintInfoForDescendants = paintInfo.forDescendants(); | 303 PaintInfo paintInfoForDescendants = paintInfo.forDescendants(); |
| 298 m_layoutBlock.paintChildren(paintInfoForDescendants, paintOffset); | 304 m_layoutBlock.paintChildren(paintInfoForDescendants, paintOffset); |
| 299 } | 305 } |
| 300 | 306 |
| 301 } // namespace blink | 307 } // namespace blink |
| OLD | NEW |