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

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

Issue 1153333005: Fix painting bounds calculations for ellipsis (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 | « no previous file | 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/EllipsisBoxPainter.h" 6 #include "core/paint/EllipsisBoxPainter.h"
7 7
8 #include "core/layout/TextRunConstructor.h" 8 #include "core/layout/TextRunConstructor.h"
9 #include "core/layout/line/EllipsisBox.h" 9 #include "core/layout/line/EllipsisBox.h"
10 #include "core/layout/line/RootInlineBox.h" 10 #include "core/layout/line/RootInlineBox.h"
11 #include "core/paint/LayoutObjectDrawingRecorder.h" 11 #include "core/paint/LayoutObjectDrawingRecorder.h"
12 #include "core/paint/PaintInfo.h" 12 #include "core/paint/PaintInfo.h"
13 #include "core/paint/TextPainter.h" 13 #include "core/paint/TextPainter.h"
14 #include "platform/graphics/GraphicsContextStateSaver.h" 14 #include "platform/graphics/GraphicsContextStateSaver.h"
15 15
16 namespace blink { 16 namespace blink {
17 17
18 void EllipsisBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset, LayoutUnit lineTop, LayoutUnit lineBottom) 18 void EllipsisBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
19 { 19 {
20 const ComputedStyle& style = m_ellipsisBox.layoutObject().styleRef(m_ellipsi sBox.isFirstLineStyle()); 20 const ComputedStyle& style = m_ellipsisBox.layoutObject().styleRef(m_ellipsi sBox.isFirstLineStyle());
21 paintEllipsis(paintInfo, paintOffset, lineTop, lineBottom, style); 21 paintEllipsis(paintInfo, paintOffset, lineTop, lineBottom, style);
22 } 22 }
23 23
24 void EllipsisBoxPainter::paintEllipsis(const PaintInfo& paintInfo, const LayoutP oint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom, const ComputedStyl e& style) 24 void EllipsisBoxPainter::paintEllipsis(const PaintInfo& paintInfo, const LayoutP oint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom, const ComputedStyl e& style)
25 { 25 {
26 bool isPrinting = m_ellipsisBox.layoutObject().document().printing();
chrishtr 2015/06/05 16:46:06 EllipsisBox inherits from InlineBox. Can you lever
fs 2015/06/05 17:14:03 I don't see how I could - InlineBox (this CL) vs.
27 bool haveSelection = !isPrinting && paintInfo.phase != PaintPhaseTextClip && m_ellipsisBox.selectionState() != LayoutObject::SelectionNone;
28
29 LayoutRect paintRect(m_ellipsisBox.logicalFrameRect());
30 if (haveSelection)
31 paintRect.unite(LayoutRect(m_ellipsisBox.selectionRect()));
32 paintRect = m_ellipsisBox.logicalRectToPhysicalRect(paintRect);
33 paintRect.moveBy(paintOffset);
34
26 GraphicsContext* context = paintInfo.context; 35 GraphicsContext* context = paintInfo.context;
36 DrawingRecorder recorder(*context, m_ellipsisBox, DisplayItem::paintPhaseToD rawingType(paintInfo.phase), paintRect);
37 if (recorder.canUseCachedDrawing())
38 return;
39
27 LayoutPoint boxOrigin = m_ellipsisBox.locationIncludingFlipping(); 40 LayoutPoint boxOrigin = m_ellipsisBox.locationIncludingFlipping();
28 boxOrigin.moveBy(paintOffset); 41 boxOrigin.moveBy(paintOffset);
29 LayoutRect boxRect(boxOrigin, LayoutSize(m_ellipsisBox.logicalWidth(), m_ell ipsisBox.virtualLogicalHeight())); 42 LayoutRect boxRect(boxOrigin, LayoutSize(m_ellipsisBox.logicalWidth(), m_ell ipsisBox.virtualLogicalHeight()));
30 43
31 DrawingRecorder recorder(*context, m_ellipsisBox, DisplayItem::paintPhaseToD rawingType(paintInfo.phase), boxRect);
32 if (recorder.canUseCachedDrawing())
33 return;
34
35 GraphicsContextStateSaver stateSaver(*context); 44 GraphicsContextStateSaver stateSaver(*context);
36 if (!m_ellipsisBox.isHorizontal()) 45 if (!m_ellipsisBox.isHorizontal())
37 context->concatCTM(TextPainter::rotation(boxRect, TextPainter::Clockwise )); 46 context->concatCTM(TextPainter::rotation(boxRect, TextPainter::Clockwise ));
47
38 const Font& font = style.font(); 48 const Font& font = style.font();
39 LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().asc ent());
40
41 bool isPrinting = m_ellipsisBox.layoutObject().document().printing();
42 bool haveSelection = !isPrinting && paintInfo.phase != PaintPhaseTextClip && m_ellipsisBox.selectionState() != LayoutObject::SelectionNone;
43 49
44 if (haveSelection) 50 if (haveSelection)
45 paintSelection(context, boxOrigin, style, font); 51 paintSelection(context, boxOrigin, style, font);
46 else if (paintInfo.phase == PaintPhaseSelection) 52 else if (paintInfo.phase == PaintPhaseSelection)
47 return; 53 return;
48 54
49 TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_ellipsisBox. layoutObject(), style, paintInfo.forceBlackText(), isPrinting); 55 TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_ellipsisBox. layoutObject(), style, paintInfo.forceBlackText(), isPrinting);
50 if (haveSelection) 56 if (haveSelection)
51 textStyle = TextPainter::selectionPaintingStyle(m_ellipsisBox.layoutObje ct(), true, paintInfo.forceBlackText(), isPrinting, textStyle); 57 textStyle = TextPainter::selectionPaintingStyle(m_ellipsisBox.layoutObje ct(), true, paintInfo.forceBlackText(), isPrinting, textStyle);
52 58
53 TextRun textRun = constructTextRun(&m_ellipsisBox.layoutObject(), font, m_el lipsisBox.ellipsisStr(), style, TextRun::AllowTrailingExpansion); 59 TextRun textRun = constructTextRun(&m_ellipsisBox.layoutObject(), font, m_el lipsisBox.ellipsisStr(), style, TextRun::AllowTrailingExpansion);
60 LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().asc ent());
54 TextPainter textPainter(context, font, textRun, textOrigin, boxRect, m_ellip sisBox.isHorizontal()); 61 TextPainter textPainter(context, font, textRun, textOrigin, boxRect, m_ellip sisBox.isHorizontal());
55 textPainter.paint(0, m_ellipsisBox.ellipsisStr().length(), m_ellipsisBox.ell ipsisStr().length(), textStyle); 62 textPainter.paint(0, m_ellipsisBox.ellipsisStr().length(), m_ellipsisBox.ell ipsisStr().length(), textStyle);
56 } 63 }
57 64
58 void EllipsisBoxPainter::paintSelection(GraphicsContext* context, const LayoutPo int& boxOrigin, const ComputedStyle& style, const Font& font) 65 void EllipsisBoxPainter::paintSelection(GraphicsContext* context, const LayoutPo int& boxOrigin, const ComputedStyle& style, const Font& font)
59 { 66 {
60 Color textColor = m_ellipsisBox.layoutObject().resolveColor(style, CSSProper tyColor); 67 Color textColor = m_ellipsisBox.layoutObject().resolveColor(style, CSSProper tyColor);
61 Color c = m_ellipsisBox.layoutObject().selectionBackgroundColor(); 68 Color c = m_ellipsisBox.layoutObject().selectionBackgroundColor();
62 if (!c.alpha()) 69 if (!c.alpha())
63 return; 70 return;
64 71
65 // If the text color ends up being the same as the selection background, inv ert the selection 72 // If the text color ends up being the same as the selection background, inv ert the selection
66 // background. 73 // background.
67 if (textColor == c) 74 if (textColor == c)
68 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); 75 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
69 76
70 GraphicsContextStateSaver stateSaver(*context); 77 GraphicsContextStateSaver stateSaver(*context);
71 LayoutUnit selectionBottom = m_ellipsisBox.root().selectionBottom(); 78 LayoutUnit selectionBottom = m_ellipsisBox.root().selectionBottom();
72 LayoutUnit top = m_ellipsisBox.root().selectionTop(); 79 LayoutUnit top = m_ellipsisBox.root().selectionTop();
73 LayoutUnit h = m_ellipsisBox.root().selectionHeight(); 80 LayoutUnit h = m_ellipsisBox.root().selectionHeight();
74 const int deltaY = roundToInt(m_ellipsisBox.layoutObject().styleRef().isFlip pedLinesWritingMode() ? selectionBottom - m_ellipsisBox.logicalBottom() : m_elli psisBox.logicalTop() - top); 81 const int deltaY = roundToInt(m_ellipsisBox.layoutObject().styleRef().isFlip pedLinesWritingMode() ? selectionBottom - m_ellipsisBox.logicalBottom() : m_elli psisBox.logicalTop() - top);
75 const LayoutPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); 82 const LayoutPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
76 LayoutRect clipRect(localOrigin, LayoutSize(m_ellipsisBox.logicalWidth(), h) ); 83 LayoutRect clipRect(localOrigin, LayoutSize(m_ellipsisBox.logicalWidth(), h) );
77 context->clip(clipRect); 84 context->clip(clipRect);
78 context->drawHighlightForText(font, constructTextRun(&m_ellipsisBox.layoutOb ject(), font, m_ellipsisBox.ellipsisStr(), style, TextRun::AllowTrailingExpansio n), FloatPoint(localOrigin), h, c); 85 context->drawHighlightForText(font, constructTextRun(&m_ellipsisBox.layoutOb ject(), font, m_ellipsisBox.ellipsisStr(), style, TextRun::AllowTrailingExpansio n), FloatPoint(localOrigin), h, c);
79 } 86 }
80 87
81 } // namespace blink 88 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698