OLD | NEW |
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 Loading... |
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 styleTextColor = style->visitedDependentColor(CSSPropertyWebkitTextFil
lColor); |
40 if (textColor != context->fillColor()) | 42 if (styleTextColor != context->fillColor()) |
41 context->setFillColor(textColor, style->colorSpace()); | 43 context->setFillColor(styleTextColor, 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 textColor = styleTextColor; |
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 != styleTextColor) |
56 context->setFillColor(foreground, style->colorSpace()); | 53 textColor = 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 = 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); |
67 | 101 |
68 // Restore the regular fill color. | 102 // Restore the regular fill color. |
69 if (textColor != context->fillColor()) | 103 if (styleTextColor != context->fillColor()) |
70 context->setFillColor(textColor, style->colorSpace()); | 104 context->setFillColor(styleTextColor, style->colorSpace()); |
71 | |
72 if (setShadow) | |
73 context->clearShadow(); | |
74 | 105 |
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); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |