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

Side by Side Diff: Source/core/rendering/EllipsisBox.cpp

Issue 15001034: Improve shadow support in EllipsisBox. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: address alokp's comment Created 7 years, 7 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 | « LayoutTests/fast/css/text-overflow-ellipsis-shadow-alpha-expected.html ('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 /** 1 /**
2 * Copyright (C) 2003, 2006 Apple Computer, Inc. 2 * Copyright (C) 2003, 2006 Apple Computer, Inc.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 12 matching lines...) Expand all
23 #include "core/dom/Document.h" 23 #include "core/dom/Document.h"
24 #include "core/platform/graphics/Font.h" 24 #include "core/platform/graphics/Font.h"
25 #include "core/platform/graphics/GraphicsContextStateSaver.h" 25 #include "core/platform/graphics/GraphicsContextStateSaver.h"
26 #include "core/platform/graphics/TextRun.h" 26 #include "core/platform/graphics/TextRun.h"
27 #include "core/rendering/HitTestResult.h" 27 #include "core/rendering/HitTestResult.h"
28 #include "core/rendering/InlineTextBox.h" 28 #include "core/rendering/InlineTextBox.h"
29 #include "core/rendering/PaintInfo.h" 29 #include "core/rendering/PaintInfo.h"
30 #include "core/rendering/RenderBlock.h" 30 #include "core/rendering/RenderBlock.h"
31 #include "core/rendering/RootInlineBox.h" 31 #include "core/rendering/RootInlineBox.h"
32 32
33 #include <algorithm>
34
33 namespace WebCore { 35 namespace WebCore {
34 36
35 void EllipsisBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, La youtUnit lineTop, LayoutUnit lineBottom) 37 void EllipsisBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, La youtUnit lineTop, LayoutUnit lineBottom)
36 { 38 {
37 GraphicsContext* context = paintInfo.context; 39 GraphicsContext* context = paintInfo.context;
38 RenderStyle* style = m_renderer->style(isFirstLineStyle()); 40 RenderStyle* style = m_renderer->style(isFirstLineStyle());
39 Color textColor = style->visitedDependentColor(CSSPropertyWebkitTextFillColo r); 41 Color textColor = style->visitedDependentColor(CSSPropertyWebkitTextFillColo r);
Stephen Chennney 2013/05/16 17:03:14 Rename this "defaultTextColor".
jbroman 2013/05/16 17:22:47 Changed to "styleTextColor" to be clear that this
40 if (textColor != context->fillColor()) 42 if (textColor != context->fillColor())
41 context->setFillColor(textColor, style->colorSpace()); 43 context->setFillColor(textColor, style->colorSpace());
42 bool setShadow = false;
43 if (style->textShadow()) {
44 context->setShadow(LayoutSize(style->textShadow()->x(), style->textShado w()->y()),
45 style->textShadow()->blur(), style->textShadow()->col or(), style->colorSpace());
46 setShadow = true;
47 }
48 44
45 Color actualTextColor = textColor;
Stephen Chennney 2013/05/16 17:03:14 Then name this "textColor".
jbroman 2013/05/16 17:22:47 Done.
49 const Font& font = style->font(); 46 const Font& font = style->font();
50 if (selectionState() != RenderObject::SelectionNone) { 47 if (selectionState() != RenderObject::SelectionNone) {
51 paintSelection(context, paintOffset, style, font); 48 paintSelection(context, paintOffset, style, font);
52 49
53 // Select the correct color for painting the text. 50 // Select the correct color for painting the text.
54 Color foreground = paintInfo.forceBlackText() ? Color::black : renderer( )->selectionForegroundColor(); 51 Color foreground = paintInfo.forceBlackText() ? Color::black : renderer( )->selectionForegroundColor();
55 if (foreground.isValid() && foreground != textColor) 52 if (foreground.isValid() && foreground != textColor)
56 context->setFillColor(foreground, style->colorSpace()); 53 actualTextColor = foreground;
57 } 54 }
58 55
59 // FIXME: Why is this always LTR? Fix by passing correct text run flags belo w. 56 // FIXME: Why is this always LTR? Fix by passing correct text run flags belo w.
57 const ShadowData* shadow = style->textShadow();
60 FloatPoint boxOrigin(paintOffset); 58 FloatPoint boxOrigin(paintOffset);
61 boxOrigin.move(x(), y()); 59 boxOrigin.move(x(), y());
60 FloatRect boxRect(boxOrigin, LayoutSize(logicalWidth(), logicalHeight()));
62 FloatPoint textOrigin(boxOrigin.x(), boxOrigin.y() + style->fontMetrics().as cent()); 61 FloatPoint textOrigin(boxOrigin.x(), boxOrigin.y() + style->fontMetrics().as cent());
63 TextRun textRun = RenderBlock::constructTextRun(renderer(), font, m_str, sty le, TextRun::AllowTrailingExpansion); 62 TextRun textRun = RenderBlock::constructTextRun(renderer(), font, m_str, sty le, TextRun::AllowTrailingExpansion);
64 TextRunPaintInfo textRunPaintInfo(textRun); 63 TextRunPaintInfo textRunPaintInfo(textRun);
65 textRunPaintInfo.bounds = FloatRect(boxOrigin, FloatSize(logicalWidth(), log icalHeight())); 64 textRunPaintInfo.bounds = boxRect;
66 context->drawText(font, textRunPaintInfo, textOrigin); 65
66 bool opaque = actualTextColor.alpha() == 255;
67 if (!opaque)
68 context->setFillColor(Color::black, style->colorSpace());
69 else
70 context->setFillColor(actualTextColor, style->colorSpace());
71
72 do {
73 IntSize extraOffset;
74 if (shadow) {
75 FloatSize shadowOffset(shadow->x(), shadow->y());
76 if (shadow->next() || !opaque) {
Stephen Chennney 2013/05/16 17:03:14 What the abstract meaning of this? I would prefer
jbroman 2013/05/16 17:22:47 I've tried to mirror paintTextWithShadows from Inl
Stephen Chennney 2013/05/16 17:34:56 Now that I've seen the other patch, it's fine to l
77 FloatRect shadowRect(boxRect);
78 shadowRect.inflate(shadow->blur());
79 shadowRect.move(shadowOffset);
80 context->save();
81 context->clip(shadowRect);
82 extraOffset = IntSize(0, 2 * boxRect.height() + std::max(0.0f, s hadowOffset.height()) + shadow->blur());
83 shadowOffset -= extraOffset;
84 }
85 context->setShadow(shadowOffset, shadow->blur(), shadow->color(), st yle->colorSpace());
86 } else if (!opaque)
87 context->setFillColor(actualTextColor, style->colorSpace());
88
89 context->drawText(font, textRunPaintInfo, textOrigin + extraOffset);
90
91 if (!shadow)
92 break;
93
94 if (shadow->next() || !opaque)
95 context->restore();
96 else
97 context->clearShadow();
98
99 shadow = shadow->next();
100 } while (shadow || !opaque);
67 101
68 // Restore the regular fill color. 102 // Restore the regular fill color.
69 if (textColor != context->fillColor()) 103 if (textColor != context->fillColor())
70 context->setFillColor(textColor, style->colorSpace()); 104 context->setFillColor(textColor, style->colorSpace());
71 105
72 if (setShadow)
73 context->clearShadow();
74
75 paintMarkupBox(paintInfo, paintOffset, lineTop, lineBottom, style); 106 paintMarkupBox(paintInfo, paintOffset, lineTop, lineBottom, style);
76 } 107 }
77 108
78 InlineBox* EllipsisBox::markupBox() const 109 InlineBox* EllipsisBox::markupBox() const
79 { 110 {
80 if (!m_shouldPaintMarkupBox || !m_renderer->isRenderBlock()) 111 if (!m_shouldPaintMarkupBox || !m_renderer->isRenderBlock())
81 return 0; 112 return 0;
82 113
83 RenderBlock* block = toRenderBlock(m_renderer); 114 RenderBlock* block = toRenderBlock(m_renderer);
84 RootInlineBox* lastLine = block->lineAtIndex(block->lineCount() - 1); 115 RootInlineBox* lastLine = block->lineAtIndex(block->lineCount() - 1);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (visibleToHitTestRequest(request) && boundsRect.intersects(HitTestLocatio n::rectForPoint(locationInContainer.point(), 0, 0, 0, 0))) { 186 if (visibleToHitTestRequest(request) && boundsRect.intersects(HitTestLocatio n::rectForPoint(locationInContainer.point(), 0, 0, 0, 0))) {
156 renderer()->updateHitTestResult(result, locationInContainer.point() - to LayoutSize(adjustedLocation)); 187 renderer()->updateHitTestResult(result, locationInContainer.point() - to LayoutSize(adjustedLocation));
157 if (!result.addNodeToRectBasedTestResult(renderer()->node(), request, lo cationInContainer, boundsRect)) 188 if (!result.addNodeToRectBasedTestResult(renderer()->node(), request, lo cationInContainer, boundsRect))
158 return true; 189 return true;
159 } 190 }
160 191
161 return false; 192 return false;
162 } 193 }
163 194
164 } // namespace WebCore 195 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/fast/css/text-overflow-ellipsis-shadow-alpha-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698