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

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

Issue 15137009: Refactor shadow rendering logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase 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
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to 15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 */ 18 */
19 19
20 #include "config.h" 20 #include "config.h"
21 #include "core/rendering/EllipsisBox.h" 21 #include "core/rendering/EllipsisBox.h"
22 22
23 #include "core/dom/Document.h" 23 #include "core/dom/Document.h"
24 #include "core/platform/graphics/DrawLooper.h"
24 #include "core/platform/graphics/Font.h" 25 #include "core/platform/graphics/Font.h"
25 #include "core/platform/graphics/GraphicsContextStateSaver.h" 26 #include "core/platform/graphics/GraphicsContextStateSaver.h"
26 #include "core/platform/graphics/TextRun.h" 27 #include "core/platform/graphics/TextRun.h"
27 #include "core/rendering/HitTestResult.h" 28 #include "core/rendering/HitTestResult.h"
28 #include "core/rendering/InlineTextBox.h" 29 #include "core/rendering/InlineTextBox.h"
29 #include "core/rendering/PaintInfo.h" 30 #include "core/rendering/PaintInfo.h"
30 #include "core/rendering/RenderBlock.h" 31 #include "core/rendering/RenderBlock.h"
31 #include "core/rendering/RootInlineBox.h" 32 #include "core/rendering/RootInlineBox.h"
33 #include "core/rendering/style/ShadowData.h"
34 #include "wtf/Vector.h"
32 35
33 #include <algorithm> 36 #include <algorithm>
34 37
35 namespace WebCore { 38 namespace WebCore {
36 39
37 void EllipsisBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, La youtUnit lineTop, LayoutUnit lineBottom) 40 void EllipsisBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, La youtUnit lineTop, LayoutUnit lineBottom)
38 { 41 {
39 GraphicsContext* context = paintInfo.context; 42 GraphicsContext* context = paintInfo.context;
40 RenderStyle* style = m_renderer->style(isFirstLineStyle()); 43 RenderStyle* style = m_renderer->style(isFirstLineStyle());
41 Color textColor = style->visitedDependentColor(CSSPropertyWebkitTextFillColo r); 44 Color textColor = style->visitedDependentColor(CSSPropertyWebkitTextFillColo r);
42 if (textColor != context->fillColor()) 45 if (textColor != context->fillColor())
43 context->setFillColor(textColor, style->colorSpace()); 46 context->setFillColor(textColor, style->colorSpace());
44 47
45 Color actualTextColor = textColor; 48 Color actualTextColor = textColor;
46 const Font& font = style->font(); 49 const Font& font = style->font();
47 if (selectionState() != RenderObject::SelectionNone) { 50 if (selectionState() != RenderObject::SelectionNone) {
48 paintSelection(context, paintOffset, style, font); 51 paintSelection(context, paintOffset, style, font);
49 52
50 // Select the correct color for painting the text. 53 // Select the correct color for painting the text.
51 Color foreground = paintInfo.forceBlackText() ? Color::black : renderer( )->selectionForegroundColor(); 54 Color foreground = paintInfo.forceBlackText() ? Color::black : renderer( )->selectionForegroundColor();
52 if (foreground.isValid() && foreground != textColor) 55 if (foreground.isValid() && foreground != textColor)
53 actualTextColor = foreground; 56 actualTextColor = foreground;
54 } 57 }
55 58
59 const ShadowData* shadow = style->textShadow();
60 bool hasShadow = !!shadow;
61 if (hasShadow) {
62 // FIXME: it would be better if we could get the shadows top-to-bottom f rom the style.
63 Vector<const ShadowData*, 4> shadows;
64 do {
65 shadows.append(shadow);
66 } while (shadow = shadow->next());
67
68 DrawLooper drawLooper;
69 drawLooper.addUnmodifiedContent();
70 for (int i = shadows.size() - 1; i >= 0; i--) {
71 shadow = shadows[i];
72 int shadowX = isHorizontal() ? shadow->x() : shadow->y();
73 int shadowY = isHorizontal() ? shadow->y() : -shadow->x();
74 FloatSize offset(shadowX, shadowY);
75 drawLooper.addShadow(offset, shadow->blur(), shadow->color(),
76 DrawLooper::ShadowRespectsTransforms, DrawLooper::ShadowIgnoresA lpha);
77 }
78 context->setDrawLooper(drawLooper);
79 }
80
56 // FIXME: Why is this always LTR? Fix by passing correct text run flags belo w. 81 // FIXME: Why is this always LTR? Fix by passing correct text run flags belo w.
57 const ShadowData* shadow = style->textShadow();
58 FloatPoint boxOrigin(paintOffset); 82 FloatPoint boxOrigin(paintOffset);
59 boxOrigin.move(x(), y()); 83 boxOrigin.move(x(), y());
60 FloatRect boxRect(boxOrigin, LayoutSize(logicalWidth(), logicalHeight())); 84 FloatRect boxRect(boxOrigin, LayoutSize(logicalWidth(), logicalHeight()));
61 FloatPoint textOrigin(boxOrigin.x(), boxOrigin.y() + style->fontMetrics().as cent()); 85 FloatPoint textOrigin(boxOrigin.x(), boxOrigin.y() + style->fontMetrics().as cent());
62 TextRun textRun = RenderBlock::constructTextRun(renderer(), font, m_str, sty le, TextRun::AllowTrailingExpansion); 86 TextRun textRun = RenderBlock::constructTextRun(renderer(), font, m_str, sty le, TextRun::AllowTrailingExpansion);
63 TextRunPaintInfo textRunPaintInfo(textRun); 87 TextRunPaintInfo textRunPaintInfo(textRun);
64 textRunPaintInfo.bounds = FloatRect(boxOrigin, FloatSize(logicalWidth(), log icalHeight())); 88 textRunPaintInfo.bounds = FloatRect(boxOrigin, FloatSize(logicalWidth(), log icalHeight()));
65 89 context->drawText(font, textRunPaintInfo, textOrigin);
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) {
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);
101 90
102 // Restore the regular fill color. 91 // Restore the regular fill color.
103 if (textColor != context->fillColor()) 92 if (textColor != context->fillColor())
104 context->setFillColor(textColor, style->colorSpace()); 93 context->setFillColor(textColor, style->colorSpace());
105 94
95 if (hasShadow)
96 context->clearDrawLooper();
97
106 paintMarkupBox(paintInfo, paintOffset, lineTop, lineBottom, style); 98 paintMarkupBox(paintInfo, paintOffset, lineTop, lineBottom, style);
107 } 99 }
108 100
109 InlineBox* EllipsisBox::markupBox() const 101 InlineBox* EllipsisBox::markupBox() const
110 { 102 {
111 if (!m_shouldPaintMarkupBox || !m_renderer->isRenderBlock()) 103 if (!m_shouldPaintMarkupBox || !m_renderer->isRenderBlock())
112 return 0; 104 return 0;
113 105
114 RenderBlock* block = toRenderBlock(m_renderer); 106 RenderBlock* block = toRenderBlock(m_renderer);
115 RootInlineBox* lastLine = block->lineAtIndex(block->lineCount() - 1); 107 RootInlineBox* lastLine = block->lineAtIndex(block->lineCount() - 1);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if (visibleToHitTestRequest(request) && boundsRect.intersects(HitTestLocatio n::rectForPoint(locationInContainer.point(), 0, 0, 0, 0))) { 178 if (visibleToHitTestRequest(request) && boundsRect.intersects(HitTestLocatio n::rectForPoint(locationInContainer.point(), 0, 0, 0, 0))) {
187 renderer()->updateHitTestResult(result, locationInContainer.point() - to LayoutSize(adjustedLocation)); 179 renderer()->updateHitTestResult(result, locationInContainer.point() - to LayoutSize(adjustedLocation));
188 if (!result.addNodeToRectBasedTestResult(renderer()->node(), request, lo cationInContainer, boundsRect)) 180 if (!result.addNodeToRectBasedTestResult(renderer()->node(), request, lo cationInContainer, boundsRect))
189 return true; 181 return true;
190 } 182 }
191 183
192 return false; 184 return false;
193 } 185 }
194 186
195 } // namespace WebCore 187 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/GraphicsContextState.h ('k') | Source/core/rendering/InlineTextBox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698