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

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

Issue 2340533002: Don't paint ellipsis selection (Closed)
Patch Set: bug 642460 Created 4 years, 3 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
« no previous file with comments | « third_party/WebKit/Source/core/paint/EllipsisBoxPainter.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 "core/paint/EllipsisBoxPainter.h" 5 #include "core/paint/EllipsisBoxPainter.h"
6 6
7 #include "core/layout/TextRunConstructor.h" 7 #include "core/layout/TextRunConstructor.h"
8 #include "core/layout/api/LineLayoutItem.h" 8 #include "core/layout/api/LineLayoutItem.h"
9 #include "core/layout/api/SelectionState.h" 9 #include "core/layout/api/SelectionState.h"
10 #include "core/layout/line/EllipsisBox.h" 10 #include "core/layout/line/EllipsisBox.h"
11 #include "core/layout/line/RootInlineBox.h" 11 #include "core/layout/line/RootInlineBox.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 #include "platform/graphics/paint/DrawingRecorder.h" 15 #include "platform/graphics/paint/DrawingRecorder.h"
16 16
17 namespace blink { 17 namespace blink {
18 18
19 void EllipsisBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset, LayoutUnit lineTop, LayoutUnit lineBottom) 19 void EllipsisBoxPainter::paint(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
20 { 20 {
21 if (paintInfo.phase == PaintPhaseSelection)
22 return;
23
21 const ComputedStyle& style = m_ellipsisBox.getLineLayoutItem().styleRef(m_el lipsisBox.isFirstLineStyle()); 24 const ComputedStyle& style = m_ellipsisBox.getLineLayoutItem().styleRef(m_el lipsisBox.isFirstLineStyle());
22 paintEllipsis(paintInfo, paintOffset, lineTop, lineBottom, style); 25 paintEllipsis(paintInfo, paintOffset, lineTop, lineBottom, style);
23 } 26 }
24 27
25 void EllipsisBoxPainter::paintEllipsis(const PaintInfo& paintInfo, const LayoutP oint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom, const ComputedStyl e& style) 28 void EllipsisBoxPainter::paintEllipsis(const PaintInfo& paintInfo, const LayoutP oint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom, const ComputedStyl e& style)
26 { 29 {
27 bool haveSelection = !paintInfo.isPrinting() && paintInfo.phase != PaintPhas eTextClip && m_ellipsisBox.getSelectionState() != SelectionNone;
28
29 LayoutRect paintRect(m_ellipsisBox.logicalFrameRect()); 30 LayoutRect paintRect(m_ellipsisBox.logicalFrameRect());
30 if (haveSelection)
31 paintRect.unite(LayoutRect(m_ellipsisBox.selectionRect()));
32 m_ellipsisBox.logicalRectToPhysicalRect(paintRect); 31 m_ellipsisBox.logicalRectToPhysicalRect(paintRect);
33 paintRect.moveBy(paintOffset); 32 paintRect.moveBy(paintOffset);
34 33
35 GraphicsContext& context = paintInfo.context; 34 GraphicsContext& context = paintInfo.context;
36 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai ntInfo.phase); 35 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai ntInfo.phase);
37 if (DrawingRecorder::useCachedDrawingIfPossible(context, m_ellipsisBox, disp layItemType)) 36 if (DrawingRecorder::useCachedDrawingIfPossible(context, m_ellipsisBox, disp layItemType))
38 return; 37 return;
39 38
40 DrawingRecorder recorder(context, m_ellipsisBox, displayItemType, FloatRect( paintRect)); 39 DrawingRecorder recorder(context, m_ellipsisBox, displayItemType, FloatRect( paintRect));
41 40
42 LayoutPoint boxOrigin = m_ellipsisBox.locationIncludingFlipping(); 41 LayoutPoint boxOrigin = m_ellipsisBox.locationIncludingFlipping();
43 boxOrigin.moveBy(paintOffset); 42 boxOrigin.moveBy(paintOffset);
44 LayoutRect boxRect(boxOrigin, LayoutSize(m_ellipsisBox.logicalWidth(), m_ell ipsisBox.virtualLogicalHeight())); 43 LayoutRect boxRect(boxOrigin, LayoutSize(m_ellipsisBox.logicalWidth(), m_ell ipsisBox.virtualLogicalHeight()));
45 44
46 GraphicsContextStateSaver stateSaver(context); 45 GraphicsContextStateSaver stateSaver(context);
47 if (!m_ellipsisBox.isHorizontal()) 46 if (!m_ellipsisBox.isHorizontal())
48 context.concatCTM(TextPainter::rotation(boxRect, TextPainter::Clockwise) ); 47 context.concatCTM(TextPainter::rotation(boxRect, TextPainter::Clockwise) );
49 48
50 const Font& font = style.font(); 49 const Font& font = style.font();
51 50
52 if (haveSelection)
53 paintSelection(context, boxOrigin, style, font);
54 else if (paintInfo.phase == PaintPhaseSelection)
55 return;
56
57 TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_ellipsisBox. getLineLayoutItem(), style, paintInfo); 51 TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_ellipsisBox. getLineLayoutItem(), style, paintInfo);
58 if (haveSelection)
59 textStyle = TextPainter::selectionPaintingStyle(m_ellipsisBox.getLineLay outItem(), true, paintInfo, textStyle);
60
61 TextRun textRun = constructTextRun(font, m_ellipsisBox.ellipsisStr(), style, TextRun::AllowTrailingExpansion); 52 TextRun textRun = constructTextRun(font, m_ellipsisBox.ellipsisStr(), style, TextRun::AllowTrailingExpansion);
62 LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.getFontMetrics(). ascent()); 53 LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.getFontMetrics(). ascent());
63 TextPainter textPainter(context, font, textRun, textOrigin, boxRect, m_ellip sisBox.isHorizontal()); 54 TextPainter textPainter(context, font, textRun, textOrigin, boxRect, m_ellip sisBox.isHorizontal());
64 textPainter.paint(0, m_ellipsisBox.ellipsisStr().length(), m_ellipsisBox.ell ipsisStr().length(), textStyle); 55 textPainter.paint(0, m_ellipsisBox.ellipsisStr().length(), m_ellipsisBox.ell ipsisStr().length(), textStyle);
65 } 56 }
66 57
67 void EllipsisBoxPainter::paintSelection(GraphicsContext& context, const LayoutPo int& boxOrigin, const ComputedStyle& style, const Font& font)
68 {
69 Color textColor = m_ellipsisBox.getLineLayoutItem().resolveColor(style, CSSP ropertyColor);
70 Color c = m_ellipsisBox.getLineLayoutItem().selectionBackgroundColor();
71 if (!c.alpha())
72 return;
73
74 // If the text color ends up being the same as the selection background, inv ert the selection
75 // background.
76 if (textColor == c)
77 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
78
79 GraphicsContextStateSaver stateSaver(context);
80 LayoutUnit selectionBottom = m_ellipsisBox.root().selectionBottom();
81 LayoutUnit top = m_ellipsisBox.root().selectionTop();
82 LayoutUnit h = m_ellipsisBox.root().selectionHeight();
83 const int deltaY = roundToInt(m_ellipsisBox.getLineLayoutItem().styleRef().i sFlippedLinesWritingMode() ? selectionBottom - m_ellipsisBox.logicalBottom() : m _ellipsisBox.logicalTop() - top);
84 const FloatPoint localOrigin(LayoutPoint(boxOrigin.x(), boxOrigin.y() - delt aY));
85 FloatRect clipRect(localOrigin, FloatSize(LayoutSize(m_ellipsisBox.logicalWi dth(), h)));
86 context.clip(clipRect);
87 context.drawHighlightForText(font, constructTextRun(font, m_ellipsisBox.elli psisStr(), style, TextRun::AllowTrailingExpansion), localOrigin, h.toInt(), c);
88 }
89
90 } // namespace blink 58 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/EllipsisBoxPainter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698