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

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

Issue 1512803004: Use refs for GraphicsContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ScrollbarTheme
Patch Set: Created 5 years 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
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/api/SelectionState.h" 9 #include "core/layout/api/SelectionState.h"
10 #include "core/layout/line/EllipsisBox.h" 10 #include "core/layout/line/EllipsisBox.h"
(...skipping 14 matching lines...) Expand all
25 void EllipsisBoxPainter::paintEllipsis(const PaintInfo& paintInfo, const LayoutP oint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom, const ComputedStyl e& style) 25 void EllipsisBoxPainter::paintEllipsis(const PaintInfo& paintInfo, const LayoutP oint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom, const ComputedStyl e& style)
26 { 26 {
27 bool haveSelection = !paintInfo.isPrinting() && paintInfo.phase != PaintPhas eTextClip && m_ellipsisBox.selectionState() != SelectionNone; 27 bool haveSelection = !paintInfo.isPrinting() && paintInfo.phase != PaintPhas eTextClip && m_ellipsisBox.selectionState() != SelectionNone;
28 28
29 LayoutRect paintRect(m_ellipsisBox.logicalFrameRect()); 29 LayoutRect paintRect(m_ellipsisBox.logicalFrameRect());
30 if (haveSelection) 30 if (haveSelection)
31 paintRect.unite(LayoutRect(m_ellipsisBox.selectionRect())); 31 paintRect.unite(LayoutRect(m_ellipsisBox.selectionRect()));
32 m_ellipsisBox.logicalRectToPhysicalRect(paintRect); 32 m_ellipsisBox.logicalRectToPhysicalRect(paintRect);
33 paintRect.moveBy(paintOffset); 33 paintRect.moveBy(paintOffset);
34 34
35 GraphicsContext* context = paintInfo.context; 35 GraphicsContext& context = paintInfo.context;
36 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai ntInfo.phase); 36 DisplayItem::Type displayItemType = DisplayItem::paintPhaseToDrawingType(pai ntInfo.phase);
37 if (DrawingRecorder::useCachedDrawingIfPossible(*context, m_ellipsisBox, dis playItemType)) 37 if (DrawingRecorder::useCachedDrawingIfPossible(context, m_ellipsisBox, disp layItemType))
38 return; 38 return;
39 39
40 DrawingRecorder recorder(*context, m_ellipsisBox, displayItemType, FloatRect (paintRect)); 40 DrawingRecorder recorder(context, m_ellipsisBox, displayItemType, FloatRect( paintRect));
41 41
42 LayoutPoint boxOrigin = m_ellipsisBox.locationIncludingFlipping(); 42 LayoutPoint boxOrigin = m_ellipsisBox.locationIncludingFlipping();
43 boxOrigin.moveBy(paintOffset); 43 boxOrigin.moveBy(paintOffset);
44 LayoutRect boxRect(boxOrigin, LayoutSize(m_ellipsisBox.logicalWidth(), m_ell ipsisBox.virtualLogicalHeight())); 44 LayoutRect boxRect(boxOrigin, LayoutSize(m_ellipsisBox.logicalWidth(), m_ell ipsisBox.virtualLogicalHeight()));
45 45
46 GraphicsContextStateSaver stateSaver(*context); 46 GraphicsContextStateSaver stateSaver(context);
47 if (!m_ellipsisBox.isHorizontal()) 47 if (!m_ellipsisBox.isHorizontal())
48 context->concatCTM(TextPainter::rotation(boxRect, TextPainter::Clockwise )); 48 context.concatCTM(TextPainter::rotation(boxRect, TextPainter::Clockwise) );
49 49
50 const Font& font = style.font(); 50 const Font& font = style.font();
51 51
52 if (haveSelection) 52 if (haveSelection)
53 paintSelection(context, boxOrigin, style, font); 53 paintSelection(context, boxOrigin, style, font);
54 else if (paintInfo.phase == PaintPhaseSelection) 54 else if (paintInfo.phase == PaintPhaseSelection)
55 return; 55 return;
56 56
57 TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_ellipsisBox. layoutObject(), style, paintInfo); 57 TextPainter::Style textStyle = TextPainter::textPaintingStyle(m_ellipsisBox. layoutObject(), style, paintInfo);
58 if (haveSelection) 58 if (haveSelection)
59 textStyle = TextPainter::selectionPaintingStyle(m_ellipsisBox.layoutObje ct(), true, paintInfo, textStyle); 59 textStyle = TextPainter::selectionPaintingStyle(m_ellipsisBox.layoutObje ct(), true, paintInfo, textStyle);
60 60
61 TextRun textRun = constructTextRun(font, m_ellipsisBox.ellipsisStr(), style, TextRun::AllowTrailingExpansion); 61 TextRun textRun = constructTextRun(font, m_ellipsisBox.ellipsisStr(), style, TextRun::AllowTrailingExpansion);
62 LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().asc ent()); 62 LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.fontMetrics().asc ent());
63 TextPainter textPainter(context, font, textRun, textOrigin, boxRect, m_ellip sisBox.isHorizontal()); 63 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); 64 textPainter.paint(0, m_ellipsisBox.ellipsisStr().length(), m_ellipsisBox.ell ipsisStr().length(), textStyle);
65 } 65 }
66 66
67 void EllipsisBoxPainter::paintSelection(GraphicsContext* context, const LayoutPo int& boxOrigin, const ComputedStyle& style, const Font& font) 67 void EllipsisBoxPainter::paintSelection(GraphicsContext& context, const LayoutPo int& boxOrigin, const ComputedStyle& style, const Font& font)
68 { 68 {
69 Color textColor = m_ellipsisBox.layoutObject().resolveColor(style, CSSProper tyColor); 69 Color textColor = m_ellipsisBox.layoutObject().resolveColor(style, CSSProper tyColor);
70 Color c = m_ellipsisBox.lineLayoutItem().selectionBackgroundColor(); 70 Color c = m_ellipsisBox.lineLayoutItem().selectionBackgroundColor();
71 if (!c.alpha()) 71 if (!c.alpha())
72 return; 72 return;
73 73
74 // If the text color ends up being the same as the selection background, inv ert the selection 74 // If the text color ends up being the same as the selection background, inv ert the selection
75 // background. 75 // background.
76 if (textColor == c) 76 if (textColor == c)
77 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); 77 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
78 78
79 GraphicsContextStateSaver stateSaver(*context); 79 GraphicsContextStateSaver stateSaver(context);
80 LayoutUnit selectionBottom = m_ellipsisBox.root().selectionBottom(); 80 LayoutUnit selectionBottom = m_ellipsisBox.root().selectionBottom();
81 LayoutUnit top = m_ellipsisBox.root().selectionTop(); 81 LayoutUnit top = m_ellipsisBox.root().selectionTop();
82 LayoutUnit h = m_ellipsisBox.root().selectionHeight(); 82 LayoutUnit h = m_ellipsisBox.root().selectionHeight();
83 const int deltaY = roundToInt(m_ellipsisBox.lineLayoutItem().styleRef().isFl ippedLinesWritingMode() ? selectionBottom - m_ellipsisBox.logicalBottom() : m_el lipsisBox.logicalTop() - top); 83 const int deltaY = roundToInt(m_ellipsisBox.lineLayoutItem().styleRef().isFl ippedLinesWritingMode() ? selectionBottom - m_ellipsisBox.logicalBottom() : m_el lipsisBox.logicalTop() - top);
84 const FloatPoint localOrigin(LayoutPoint(boxOrigin.x(), boxOrigin.y() - delt aY)); 84 const FloatPoint localOrigin(LayoutPoint(boxOrigin.x(), boxOrigin.y() - delt aY));
85 FloatRect clipRect(localOrigin, FloatSize(LayoutSize(m_ellipsisBox.logicalWi dth(), h))); 85 FloatRect clipRect(localOrigin, FloatSize(LayoutSize(m_ellipsisBox.logicalWi dth(), h)));
86 context->clip(clipRect); 86 context.clip(clipRect);
87 context->drawHighlightForText(font, constructTextRun(font, m_ellipsisBox.ell ipsisStr(), style, TextRun::AllowTrailingExpansion), localOrigin, h, c); 87 context.drawHighlightForText(font, constructTextRun(font, m_ellipsisBox.elli psisStr(), style, TextRun::AllowTrailingExpansion), localOrigin, h, c);
88 } 88 }
89 89
90 } // namespace blink 90 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698