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

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: merge upstream changes 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"
32 33 #include "core/rendering/style/ShadowData.h"
33 #include <algorithm> 34 #include "wtf/Vector.h"
34 35
35 namespace WebCore { 36 namespace WebCore {
36 37
37 void EllipsisBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, La youtUnit lineTop, LayoutUnit lineBottom) 38 void EllipsisBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, La youtUnit lineTop, LayoutUnit lineBottom)
38 { 39 {
39 GraphicsContext* context = paintInfo.context; 40 GraphicsContext* context = paintInfo.context;
40 RenderStyle* style = m_renderer->style(isFirstLineStyle()); 41 RenderStyle* style = m_renderer->style(isFirstLineStyle());
41 Color styleTextColor = style->visitedDependentColor(CSSPropertyWebkitTextFil lColor); 42 Color styleTextColor = style->visitedDependentColor(CSSPropertyWebkitTextFil lColor);
42 if (styleTextColor != context->fillColor()) 43 if (styleTextColor != context->fillColor())
43 context->setFillColor(styleTextColor, style->colorSpace()); 44 context->setFillColor(styleTextColor, style->colorSpace());
44 45
45 Color textColor = styleTextColor; 46 Color textColor = styleTextColor;
46 const Font& font = style->font(); 47 const Font& font = style->font();
47 if (selectionState() != RenderObject::SelectionNone) { 48 if (selectionState() != RenderObject::SelectionNone) {
48 paintSelection(context, paintOffset, style, font); 49 paintSelection(context, paintOffset, style, font);
49 50
50 // Select the correct color for painting the text. 51 // Select the correct color for painting the text.
51 Color foreground = paintInfo.forceBlackText() ? Color::black : renderer( )->selectionForegroundColor(); 52 Color foreground = paintInfo.forceBlackText() ? Color::black : renderer( )->selectionForegroundColor();
52 if (foreground.isValid() && foreground != styleTextColor) 53 if (foreground.isValid() && foreground != styleTextColor)
53 textColor = foreground; 54 context->setFillColor(foreground, style->colorSpace());
55 }
56
57 const ShadowData* shadow = style->textShadow();
58 bool hasShadow = shadow;
59 if (hasShadow) {
60 // FIXME: it would be better if we could get the shadows top-to-bottom f rom the style.
61 Vector<const ShadowData*, 4> shadows;
62 do {
63 shadows.append(shadow);
64 } while ((shadow = shadow->next()));
65
66 DrawLooper drawLooper;
67 drawLooper.addUnmodifiedContent();
68 for (int i = shadows.size() - 1; i >= 0; i--) {
69 shadow = shadows[i];
70 int shadowX = isHorizontal() ? shadow->x() : shadow->y();
71 int shadowY = isHorizontal() ? shadow->y() : -shadow->x();
72 FloatSize offset(shadowX, shadowY);
73 drawLooper.addShadow(offset, shadow->blur(), shadow->color(),
74 DrawLooper::ShadowRespectsTransforms, DrawLooper::ShadowIgnoresA lpha);
75 }
76 context->setDrawLooper(drawLooper);
54 } 77 }
55 78
56 // FIXME: Why is this always LTR? Fix by passing correct text run flags belo w. 79 // 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); 80 FloatPoint boxOrigin(paintOffset);
59 boxOrigin.move(x(), y()); 81 boxOrigin.move(x(), y());
60 FloatRect boxRect(boxOrigin, LayoutSize(logicalWidth(), logicalHeight())); 82 FloatRect boxRect(boxOrigin, LayoutSize(logicalWidth(), logicalHeight()));
61 FloatPoint textOrigin(boxOrigin.x(), boxOrigin.y() + style->fontMetrics().as cent()); 83 FloatPoint textOrigin(boxOrigin.x(), boxOrigin.y() + style->fontMetrics().as cent());
62 TextRun textRun = RenderBlock::constructTextRun(renderer(), font, m_str, sty le, TextRun::AllowTrailingExpansion); 84 TextRun textRun = RenderBlock::constructTextRun(renderer(), font, m_str, sty le, TextRun::AllowTrailingExpansion);
63 TextRunPaintInfo textRunPaintInfo(textRun); 85 TextRunPaintInfo textRunPaintInfo(textRun);
64 textRunPaintInfo.bounds = boxRect; 86 textRunPaintInfo.bounds = boxRect;
65 87 context->drawText(font, textRunPaintInfo, textOrigin);
66 bool opaque = textColor.alpha() == 255;
67 if (!opaque)
68 context->setFillColor(Color::black, style->colorSpace());
69 else
70 context->setFillColor(textColor, 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(textColor, 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 88
102 // Restore the regular fill color. 89 // Restore the regular fill color.
103 if (styleTextColor != context->fillColor()) 90 if (styleTextColor != context->fillColor())
104 context->setFillColor(styleTextColor, style->colorSpace()); 91 context->setFillColor(styleTextColor, style->colorSpace());
105 92
93 if (hasShadow)
94 context->clearDrawLooper();
95
106 paintMarkupBox(paintInfo, paintOffset, lineTop, lineBottom, style); 96 paintMarkupBox(paintInfo, paintOffset, lineTop, lineBottom, style);
107 } 97 }
108 98
109 InlineBox* EllipsisBox::markupBox() const 99 InlineBox* EllipsisBox::markupBox() const
110 { 100 {
111 if (!m_shouldPaintMarkupBox || !m_renderer->isRenderBlock()) 101 if (!m_shouldPaintMarkupBox || !m_renderer->isRenderBlock())
112 return 0; 102 return 0;
113 103
114 RenderBlock* block = toRenderBlock(m_renderer); 104 RenderBlock* block = toRenderBlock(m_renderer);
115 RootInlineBox* lastLine = block->lineAtIndex(block->lineCount() - 1); 105 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))) { 176 if (visibleToHitTestRequest(request) && boundsRect.intersects(HitTestLocatio n::rectForPoint(locationInContainer.point(), 0, 0, 0, 0))) {
187 renderer()->updateHitTestResult(result, locationInContainer.point() - to LayoutSize(adjustedLocation)); 177 renderer()->updateHitTestResult(result, locationInContainer.point() - to LayoutSize(adjustedLocation));
188 if (!result.addNodeToRectBasedTestResult(renderer()->node(), request, lo cationInContainer, boundsRect)) 178 if (!result.addNodeToRectBasedTestResult(renderer()->node(), request, lo cationInContainer, boundsRect))
189 return true; 179 return true;
190 } 180 }
191 181
192 return false; 182 return false;
193 } 183 }
194 184
195 } // namespace WebCore 185 } // 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