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

Unified 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: textColor rename per schenney 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/EllipsisBox.cpp
diff --git a/Source/core/rendering/EllipsisBox.cpp b/Source/core/rendering/EllipsisBox.cpp
index b7611c1d20d834f490d213870c7eaa4336dc4bd0..e42366390ddebae0f2cd9d3acc3460ab679c3de4 100644
--- a/Source/core/rendering/EllipsisBox.cpp
+++ b/Source/core/rendering/EllipsisBox.cpp
@@ -30,47 +30,78 @@
#include "core/rendering/RenderBlock.h"
#include "core/rendering/RootInlineBox.h"
+#include <algorithm>
+
namespace WebCore {
void EllipsisBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
{
GraphicsContext* context = paintInfo.context;
RenderStyle* style = m_renderer->style(isFirstLineStyle());
- Color textColor = style->visitedDependentColor(CSSPropertyWebkitTextFillColor);
- if (textColor != context->fillColor())
- context->setFillColor(textColor, style->colorSpace());
- bool setShadow = false;
- if (style->textShadow()) {
- context->setShadow(LayoutSize(style->textShadow()->x(), style->textShadow()->y()),
- style->textShadow()->blur(), style->textShadow()->color(), style->colorSpace());
- setShadow = true;
- }
+ Color styleTextColor = style->visitedDependentColor(CSSPropertyWebkitTextFillColor);
+ if (styleTextColor != context->fillColor())
+ context->setFillColor(styleTextColor, style->colorSpace());
+ Color textColor = styleTextColor;
const Font& font = style->font();
if (selectionState() != RenderObject::SelectionNone) {
paintSelection(context, paintOffset, style, font);
// Select the correct color for painting the text.
Color foreground = paintInfo.forceBlackText() ? Color::black : renderer()->selectionForegroundColor();
- if (foreground.isValid() && foreground != textColor)
- context->setFillColor(foreground, style->colorSpace());
+ if (foreground.isValid() && foreground != styleTextColor)
+ textColor = foreground;
}
// FIXME: Why is this always LTR? Fix by passing correct text run flags below.
+ const ShadowData* shadow = style->textShadow();
FloatPoint boxOrigin(paintOffset);
boxOrigin.move(x(), y());
+ FloatRect boxRect(boxOrigin, LayoutSize(logicalWidth(), logicalHeight()));
FloatPoint textOrigin(boxOrigin.x(), boxOrigin.y() + style->fontMetrics().ascent());
TextRun textRun = RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion);
TextRunPaintInfo textRunPaintInfo(textRun);
- textRunPaintInfo.bounds = FloatRect(boxOrigin, FloatSize(logicalWidth(), logicalHeight()));
- context->drawText(font, textRunPaintInfo, textOrigin);
+ textRunPaintInfo.bounds = boxRect;
- // Restore the regular fill color.
- if (textColor != context->fillColor())
+ bool opaque = textColor.alpha() == 255;
+ if (!opaque)
+ context->setFillColor(Color::black, style->colorSpace());
+ else
context->setFillColor(textColor, style->colorSpace());
- if (setShadow)
- context->clearShadow();
+ do {
+ IntSize extraOffset;
+ if (shadow) {
+ FloatSize shadowOffset(shadow->x(), shadow->y());
+ if (shadow->next() || !opaque) {
+ FloatRect shadowRect(boxRect);
+ shadowRect.inflate(shadow->blur());
+ shadowRect.move(shadowOffset);
+ context->save();
+ context->clip(shadowRect);
+ extraOffset = IntSize(0, 2 * boxRect.height() + std::max(0.0f, shadowOffset.height()) + shadow->blur());
+ shadowOffset -= extraOffset;
+ }
+ context->setShadow(shadowOffset, shadow->blur(), shadow->color(), style->colorSpace());
+ } else if (!opaque)
+ context->setFillColor(textColor, style->colorSpace());
+
+ context->drawText(font, textRunPaintInfo, textOrigin + extraOffset);
+
+ if (!shadow)
+ break;
+
+ if (shadow->next() || !opaque)
+ context->restore();
+ else
+ context->clearShadow();
+
+ shadow = shadow->next();
+ } while (shadow || !opaque);
+
+ // Restore the regular fill color.
+ if (styleTextColor != context->fillColor())
+ context->setFillColor(styleTextColor, style->colorSpace());
paintMarkupBox(paintInfo, paintOffset, lineTop, lineBottom, style);
}
« 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