| 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/InlinePainter.h" | 6 #include "core/paint/InlinePainter.h" |
| 7 | 7 |
| 8 #include "core/layout/LayoutBlock.h" | 8 #include "core/layout/LayoutBlock.h" |
| 9 #include "core/layout/LayoutInline.h" | 9 #include "core/layout/LayoutInline.h" |
| 10 #include "core/layout/LayoutTheme.h" | 10 #include "core/layout/LayoutTheme.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 void InlinePainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOf
fset) | 22 void InlinePainter::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOf
fset) |
| 23 { | 23 { |
| 24 // FIXME: When Skia supports annotation rect covering (https://code.google.c
om/p/skia/issues/detail?id=3872), | 24 // FIXME: When Skia supports annotation rect covering (https://code.google.c
om/p/skia/issues/detail?id=3872), |
| 25 // this rect may be covered by foreground and descendant drawings. Then we m
ay need a dedicated paint phase. | 25 // this rect may be covered by foreground and descendant drawings. Then we m
ay need a dedicated paint phase. |
| 26 if (paintInfo.phase == PaintPhaseForeground && paintInfo.context->printing()
) | 26 if (paintInfo.phase == PaintPhaseForeground && paintInfo.context->printing()
) |
| 27 ObjectPainter(m_layoutInline).addPDFURLRectIfNeeded(paintInfo, paintOffs
et); | 27 ObjectPainter(m_layoutInline).addPDFURLRectIfNeeded(paintInfo, paintOffs
et); |
| 28 | 28 |
| 29 LineBoxListPainter(*m_layoutInline.lineBoxes()).paint(&m_layoutInline, paint
Info, paintOffset); | 29 LineBoxListPainter(*m_layoutInline.lineBoxes()).paint(&m_layoutInline, paint
Info, paintOffset); |
| 30 } | 30 } |
| 31 | 31 |
| 32 LayoutRect InlinePainter::outlinePaintRect(const Vector<LayoutRect>& outlineRect
s, const LayoutPoint& paintOffset) const |
| 33 { |
| 34 const ComputedStyle& style = m_layoutInline.styleRef(); |
| 35 int outlineOutset; |
| 36 if (style.outlineStyleIsAuto()) |
| 37 outlineOutset = GraphicsContext::focusRingOutsetExtent(style.outlineOffs
et(), style.outlineWidth()); |
| 38 else |
| 39 outlineOutset = style.outlineSize(); |
| 40 LayoutRect outlineRect; |
| 41 for (const LayoutRect& rect : outlineRects) { |
| 42 LayoutRect inflatedRect(rect); |
| 43 // Inflate the individual rects instead of the union, to avoid losing |
| 44 // rects which have degenerate width/height (== isEmpty() true.) |
| 45 inflatedRect.inflate(outlineOutset); |
| 46 outlineRect.unite(inflatedRect); |
| 47 } |
| 48 outlineRect.moveBy(paintOffset); |
| 49 return outlineRect; |
| 50 } |
| 51 |
| 32 void InlinePainter::paintOutline(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) | 52 void InlinePainter::paintOutline(const PaintInfo& paintInfo, const LayoutPoint&
paintOffset) |
| 33 { | 53 { |
| 34 const ComputedStyle& styleToUse = m_layoutInline.styleRef(); | 54 const ComputedStyle& styleToUse = m_layoutInline.styleRef(); |
| 35 if (!styleToUse.hasOutline()) | 55 if (!styleToUse.hasOutline()) |
| 36 return; | 56 return; |
| 37 | 57 |
| 38 if (styleToUse.outlineStyleIsAuto()) { | 58 if (styleToUse.outlineStyleIsAuto()) { |
| 39 if (LayoutTheme::theme().shouldDrawDefaultFocusRing(&m_layoutInline)) { | 59 if (LayoutTheme::theme().shouldDrawDefaultFocusRing(&m_layoutInline)) { |
| 40 Vector<LayoutRect> focusRingRects; | 60 Vector<LayoutRect> focusRingRects; |
| 41 m_layoutInline.addFocusRingRects(focusRingRects, paintOffset); | 61 m_layoutInline.addFocusRingRects(focusRingRects, paintOffset); |
| 42 LayoutRect focusRingBoundingRect; | |
| 43 for (const auto& rect : focusRingRects) | |
| 44 focusRingBoundingRect.unite(rect); | |
| 45 | 62 |
| 46 LayoutObjectDrawingRecorder recorder(*paintInfo.context, m_layoutInl
ine, paintInfo.phase, focusRingBoundingRect); | 63 LayoutObjectDrawingRecorder recorder(*paintInfo.context, m_layoutInl
ine, paintInfo.phase, outlinePaintRect(focusRingRects, LayoutPoint())); |
| 47 if (recorder.canUseCachedDrawing()) | 64 if (recorder.canUseCachedDrawing()) |
| 48 return; | 65 return; |
| 49 | 66 |
| 50 // Only paint the focus ring by hand if the theme isn't able to draw
the focus ring. | 67 // Only paint the focus ring by hand if the theme isn't able to draw
the focus ring. |
| 51 ObjectPainter(m_layoutInline).paintFocusRing(paintInfo, styleToUse,
focusRingRects); | 68 ObjectPainter(m_layoutInline).paintFocusRing(paintInfo, styleToUse,
focusRingRects); |
| 52 } | 69 } |
| 53 return; | 70 return; |
| 54 } | 71 } |
| 55 | 72 |
| 56 if (styleToUse.outlineStyle() == BNONE) | 73 if (styleToUse.outlineStyle() == BNONE) |
| 57 return; | 74 return; |
| 58 | 75 |
| 59 Vector<LayoutRect> rects; | 76 Vector<LayoutRect> rects; |
| 60 | 77 |
| 61 rects.append(LayoutRect()); | 78 rects.append(LayoutRect()); |
| 62 for (InlineFlowBox* curr = m_layoutInline.firstLineBox(); curr; curr = curr-
>nextLineBox()) { | 79 for (InlineFlowBox* curr = m_layoutInline.firstLineBox(); curr; curr = curr-
>nextLineBox()) { |
| 63 RootInlineBox& root = curr->root(); | 80 RootInlineBox& root = curr->root(); |
| 64 LayoutUnit top = std::max<LayoutUnit>(root.lineTop(), curr->logicalTop()
); | 81 LayoutUnit top = std::max<LayoutUnit>(root.lineTop(), curr->logicalTop()
); |
| 65 LayoutUnit bottom = std::min<LayoutUnit>(root.lineBottom(), curr->logica
lBottom()); | 82 LayoutUnit bottom = std::min<LayoutUnit>(root.lineBottom(), curr->logica
lBottom()); |
| 66 rects.append(LayoutRect(curr->x(), top, curr->logicalWidth(), bottom - t
op)); | 83 rects.append(LayoutRect(curr->x(), top, curr->logicalWidth(), bottom - t
op)); |
| 67 } | 84 } |
| 68 rects.append(LayoutRect()); | 85 rects.append(LayoutRect()); |
| 69 | 86 |
| 70 Color outlineColor = m_layoutInline.resolveColor(styleToUse, CSSPropertyOutl
ineColor); | 87 Color outlineColor = m_layoutInline.resolveColor(styleToUse, CSSPropertyOutl
ineColor); |
| 71 bool useTransparencyLayer = outlineColor.hasAlpha(); | 88 bool useTransparencyLayer = outlineColor.hasAlpha(); |
| 72 | 89 |
| 73 int outlineWidth = styleToUse.outlineWidth(); | 90 LayoutObjectDrawingRecorder recorder(*paintInfo.context, m_layoutInline, pai
ntInfo.phase, outlinePaintRect(rects, paintOffset)); |
| 74 LayoutRect bounds; | |
| 75 for (const auto& rect : rects) { | |
| 76 LayoutRect rectCopy(rect); | |
| 77 rectCopy.expand(LayoutSize(outlineWidth, outlineWidth)); | |
| 78 bounds.unite(rectCopy); | |
| 79 } | |
| 80 bounds.moveBy(paintOffset); | |
| 81 | |
| 82 LayoutObjectDrawingRecorder recorder(*paintInfo.context, m_layoutInline, pai
ntInfo.phase, bounds); | |
| 83 if (recorder.canUseCachedDrawing()) | 91 if (recorder.canUseCachedDrawing()) |
| 84 return; | 92 return; |
| 85 | 93 |
| 86 GraphicsContext* graphicsContext = paintInfo.context; | 94 GraphicsContext* graphicsContext = paintInfo.context; |
| 87 if (useTransparencyLayer) { | 95 if (useTransparencyLayer) { |
| 88 graphicsContext->beginLayer(static_cast<float>(outlineColor.alpha()) / 2
55); | 96 graphicsContext->beginLayer(static_cast<float>(outlineColor.alpha()) / 2
55); |
| 89 outlineColor = Color(outlineColor.red(), outlineColor.green(), outlineCo
lor.blue()); | 97 outlineColor = Color(outlineColor.red(), outlineColor.green(), outlineCo
lor.blue()); |
| 90 } | 98 } |
| 91 | 99 |
| 92 for (unsigned i = 1; i < rects.size() - 1; i++) | 100 for (unsigned i = 1; i < rects.size() - 1; i++) |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 pixelSnappedBox.maxX() + outlineWidth, | 218 pixelSnappedBox.maxX() + outlineWidth, |
| 211 pixelSnappedBox.maxY() + outlineWidth, | 219 pixelSnappedBox.maxY() + outlineWidth, |
| 212 BSBottom, outlineColor, outlineStyle, | 220 BSBottom, outlineColor, outlineStyle, |
| 213 outlineWidth, | 221 outlineWidth, |
| 214 outlineWidth, | 222 outlineWidth, |
| 215 antialias); | 223 antialias); |
| 216 } | 224 } |
| 217 } | 225 } |
| 218 | 226 |
| 219 } // namespace blink | 227 } // namespace blink |
| OLD | NEW |