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

Side by Side Diff: Source/core/paint/InlinePainter.cpp

Issue 1163913002: Improve outline bounds estimation in InlinePainter (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Use linesVisualOverflowBoundingBox. Created 5 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/paint/InlinePainter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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 LayoutPoint& paintOffset) const
33 {
34 const ComputedStyle& style = m_layoutInline.styleRef();
35 int outlineOutset;
chrishtr 2015/06/04 17:08:12 Why does linesVisualOverflowBoundingBox() not alre
fs 2015/06/05 10:19:52 Hmm, yes... the inflate(outlineSize) in LayoutInli
36 if (style.outlineStyleIsAuto())
37 outlineOutset = GraphicsContext::focusRingOutsetExtent(style.outlineOffs et(), style.outlineWidth());
38 else
39 outlineOutset = style.outlineSize();
40 LayoutRect outlineRect = m_layoutInline.linesVisualOverflowBoundingBox();
41 outlineRect.inflate(outlineOutset);
42 outlineRect.moveBy(paintOffset);
43 return outlineRect;
44 }
45
32 void InlinePainter::paintOutline(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) 46 void InlinePainter::paintOutline(const PaintInfo& paintInfo, const LayoutPoint& paintOffset)
33 { 47 {
34 const ComputedStyle& styleToUse = m_layoutInline.styleRef(); 48 const ComputedStyle& styleToUse = m_layoutInline.styleRef();
35 if (!styleToUse.hasOutline()) 49 if (!styleToUse.hasOutline())
36 return; 50 return;
37 51
38 if (styleToUse.outlineStyleIsAuto()) { 52 if (styleToUse.outlineStyleIsAuto()) {
39 if (LayoutTheme::theme().shouldDrawDefaultFocusRing(&m_layoutInline)) { 53 if (LayoutTheme::theme().shouldDrawDefaultFocusRing(&m_layoutInline)) {
40 Vector<LayoutRect> focusRingRects; 54 Vector<LayoutRect> focusRingRects;
41 m_layoutInline.addFocusRingRects(focusRingRects, paintOffset); 55 m_layoutInline.addFocusRingRects(focusRingRects, paintOffset);
42 LayoutRect focusRingBoundingRect;
43 for (const auto& rect : focusRingRects)
44 focusRingBoundingRect.unite(rect);
45 56
46 LayoutObjectDrawingRecorder recorder(*paintInfo.context, m_layoutInl ine, paintInfo.phase, focusRingBoundingRect); 57 LayoutObjectDrawingRecorder recorder(*paintInfo.context, m_layoutInl ine, paintInfo.phase, outlinePaintRect(paintOffset));
47 if (recorder.canUseCachedDrawing()) 58 if (recorder.canUseCachedDrawing())
48 return; 59 return;
49 60
50 // Only paint the focus ring by hand if the theme isn't able to draw the focus ring. 61 // 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); 62 ObjectPainter(m_layoutInline).paintFocusRing(paintInfo, styleToUse, focusRingRects);
52 } 63 }
53 return; 64 return;
54 } 65 }
55 66
56 if (styleToUse.outlineStyle() == BNONE) 67 if (styleToUse.outlineStyle() == BNONE)
57 return; 68 return;
58 69
59 Vector<LayoutRect> rects; 70 Vector<LayoutRect> rects;
60 71
61 rects.append(LayoutRect()); 72 rects.append(LayoutRect());
62 for (InlineFlowBox* curr = m_layoutInline.firstLineBox(); curr; curr = curr- >nextLineBox()) { 73 for (InlineFlowBox* curr = m_layoutInline.firstLineBox(); curr; curr = curr- >nextLineBox()) {
63 RootInlineBox& root = curr->root(); 74 RootInlineBox& root = curr->root();
64 LayoutUnit top = std::max<LayoutUnit>(root.lineTop(), curr->logicalTop() ); 75 LayoutUnit top = std::max<LayoutUnit>(root.lineTop(), curr->logicalTop() );
65 LayoutUnit bottom = std::min<LayoutUnit>(root.lineBottom(), curr->logica lBottom()); 76 LayoutUnit bottom = std::min<LayoutUnit>(root.lineBottom(), curr->logica lBottom());
66 rects.append(LayoutRect(curr->x(), top, curr->logicalWidth(), bottom - t op)); 77 rects.append(LayoutRect(curr->x(), top, curr->logicalWidth(), bottom - t op));
67 } 78 }
68 rects.append(LayoutRect()); 79 rects.append(LayoutRect());
69 80
70 Color outlineColor = m_layoutInline.resolveColor(styleToUse, CSSPropertyOutl ineColor); 81 Color outlineColor = m_layoutInline.resolveColor(styleToUse, CSSPropertyOutl ineColor);
71 bool useTransparencyLayer = outlineColor.hasAlpha(); 82 bool useTransparencyLayer = outlineColor.hasAlpha();
72 83
73 int outlineWidth = styleToUse.outlineWidth(); 84 LayoutObjectDrawingRecorder recorder(*paintInfo.context, m_layoutInline, pai ntInfo.phase, outlinePaintRect(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()) 85 if (recorder.canUseCachedDrawing())
84 return; 86 return;
85 87
86 GraphicsContext* graphicsContext = paintInfo.context; 88 GraphicsContext* graphicsContext = paintInfo.context;
87 if (useTransparencyLayer) { 89 if (useTransparencyLayer) {
88 graphicsContext->beginLayer(static_cast<float>(outlineColor.alpha()) / 2 55); 90 graphicsContext->beginLayer(static_cast<float>(outlineColor.alpha()) / 2 55);
89 outlineColor = Color(outlineColor.red(), outlineColor.green(), outlineCo lor.blue()); 91 outlineColor = Color(outlineColor.red(), outlineColor.green(), outlineCo lor.blue());
90 } 92 }
91 93
92 for (unsigned i = 1; i < rects.size() - 1; i++) 94 for (unsigned i = 1; i < rects.size() - 1; i++)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 pixelSnappedBox.maxX() + outlineWidth, 212 pixelSnappedBox.maxX() + outlineWidth,
211 pixelSnappedBox.maxY() + outlineWidth, 213 pixelSnappedBox.maxY() + outlineWidth,
212 BSBottom, outlineColor, outlineStyle, 214 BSBottom, outlineColor, outlineStyle,
213 outlineWidth, 215 outlineWidth,
214 outlineWidth, 216 outlineWidth,
215 antialias); 217 antialias);
216 } 218 }
217 } 219 }
218 220
219 } // namespace blink 221 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/paint/InlinePainter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698