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 |
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/rendering/HitTestResult.h" | 23 #include "core/rendering/HitTestResult.h" |
24 #include "core/rendering/InlineTextBox.h" | 24 #include "core/rendering/InlineTextBox.h" |
25 #include "core/rendering/PaintInfo.h" | 25 #include "core/rendering/PaintInfo.h" |
26 #include "core/rendering/RenderBlockFlow.h" | 26 #include "core/rendering/RenderBlock.h" |
27 #include "core/rendering/RootInlineBox.h" | 27 #include "core/rendering/RootInlineBox.h" |
| 28 #include "core/rendering/TextRunConstructor.h" |
28 #include "core/rendering/style/ShadowList.h" | 29 #include "core/rendering/style/ShadowList.h" |
29 #include "platform/fonts/Font.h" | 30 #include "platform/fonts/Font.h" |
30 #include "platform/graphics/GraphicsContextStateSaver.h" | 31 #include "platform/graphics/GraphicsContextStateSaver.h" |
31 #include "platform/text/TextRun.h" | 32 #include "platform/text/TextRun.h" |
32 | 33 |
33 namespace WebCore { | 34 namespace WebCore { |
34 | 35 |
35 void EllipsisBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, La
youtUnit lineTop, LayoutUnit lineBottom) | 36 void EllipsisBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, La
youtUnit lineTop, LayoutUnit lineBottom) |
36 { | 37 { |
37 GraphicsContext* context = paintInfo.context; | 38 GraphicsContext* context = paintInfo.context; |
(...skipping 22 matching lines...) Expand all Loading... |
60 if (foreground != styleTextColor) | 61 if (foreground != styleTextColor) |
61 context->setFillColor(foreground); | 62 context->setFillColor(foreground); |
62 } | 63 } |
63 | 64 |
64 // Text shadows are disabled when printing. http://crbug.com/258321 | 65 // Text shadows are disabled when printing. http://crbug.com/258321 |
65 const ShadowList* shadowList = context->printing() ? 0 : style->textShadow()
; | 66 const ShadowList* shadowList = context->printing() ? 0 : style->textShadow()
; |
66 bool hasShadow = shadowList; | 67 bool hasShadow = shadowList; |
67 if (hasShadow) | 68 if (hasShadow) |
68 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S
hadowIgnoresAlpha, isHorizontal())); | 69 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S
hadowIgnoresAlpha, isHorizontal())); |
69 | 70 |
70 TextRun textRun = RenderBlockFlow::constructTextRun(&renderer(), font, m_str
, style, TextRun::AllowTrailingExpansion); | 71 TextRun textRun = constructTextRun(&renderer(), font, m_str, style, TextRun:
:AllowTrailingExpansion); |
71 TextRunPaintInfo textRunPaintInfo(textRun); | 72 TextRunPaintInfo textRunPaintInfo(textRun); |
72 textRunPaintInfo.bounds = boxRect; | 73 textRunPaintInfo.bounds = boxRect; |
73 context->drawText(font, textRunPaintInfo, textOrigin); | 74 context->drawText(font, textRunPaintInfo, textOrigin); |
74 | 75 |
75 // Restore the regular fill color. | 76 // Restore the regular fill color. |
76 if (styleTextColor != context->fillColor()) | 77 if (styleTextColor != context->fillColor()) |
77 context->setFillColor(styleTextColor); | 78 context->setFillColor(styleTextColor); |
78 | 79 |
79 if (hasShadow) | 80 if (hasShadow) |
80 context->clearDrawLooper(); | 81 context->clearDrawLooper(); |
(...skipping 29 matching lines...) Expand all Loading... |
110 LayoutPoint adjustedPaintOffset = paintOffset; | 111 LayoutPoint adjustedPaintOffset = paintOffset; |
111 adjustedPaintOffset.move(x() + m_logicalWidth - markupBox->x(), | 112 adjustedPaintOffset.move(x() + m_logicalWidth - markupBox->x(), |
112 y() + style->fontMetrics().ascent() - (markupBox->y() + markupBox->rende
rer().style(isFirstLineStyle())->fontMetrics().ascent())); | 113 y() + style->fontMetrics().ascent() - (markupBox->y() + markupBox->rende
rer().style(isFirstLineStyle())->fontMetrics().ascent())); |
113 markupBox->paint(paintInfo, adjustedPaintOffset, lineTop, lineBottom); | 114 markupBox->paint(paintInfo, adjustedPaintOffset, lineTop, lineBottom); |
114 } | 115 } |
115 | 116 |
116 IntRect EllipsisBox::selectionRect() | 117 IntRect EllipsisBox::selectionRect() |
117 { | 118 { |
118 RenderStyle* style = renderer().style(isFirstLineStyle()); | 119 RenderStyle* style = renderer().style(isFirstLineStyle()); |
119 const Font& font = style->font(); | 120 const Font& font = style->font(); |
120 return enclosingIntRect(font.selectionRectForText(RenderBlockFlow::construct
TextRun(&renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPo
int(logicalLeft(), logicalTop() + root().selectionTopAdjustedForPrecedingBlock()
), root().selectionHeightAdjustedForPrecedingBlock())); | 121 return enclosingIntRect(font.selectionRectForText(constructTextRun(&renderer
(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(logicalLeft()
, logicalTop() + root().selectionTopAdjustedForPrecedingBlock()), root().selecti
onHeightAdjustedForPrecedingBlock())); |
121 } | 122 } |
122 | 123 |
123 void EllipsisBox::paintSelection(GraphicsContext* context, const FloatPoint& box
Origin, RenderStyle* style, const Font& font) | 124 void EllipsisBox::paintSelection(GraphicsContext* context, const FloatPoint& box
Origin, RenderStyle* style, const Font& font) |
124 { | 125 { |
125 Color textColor = renderer().resolveColor(style, CSSPropertyColor); | 126 Color textColor = renderer().resolveColor(style, CSSPropertyColor); |
126 Color c = renderer().selectionBackgroundColor(); | 127 Color c = renderer().selectionBackgroundColor(); |
127 if (!c.alpha()) | 128 if (!c.alpha()) |
128 return; | 129 return; |
129 | 130 |
130 // If the text color ends up being the same as the selection background, inv
ert the selection | 131 // If the text color ends up being the same as the selection background, inv
ert the selection |
131 // background. | 132 // background. |
132 if (textColor == c) | 133 if (textColor == c) |
133 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); | 134 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); |
134 | 135 |
135 GraphicsContextStateSaver stateSaver(*context); | 136 GraphicsContextStateSaver stateSaver(*context); |
136 LayoutUnit selectionBottom = root().selectionBottom(); | 137 LayoutUnit selectionBottom = root().selectionBottom(); |
137 LayoutUnit top = root().selectionTop(); | 138 LayoutUnit top = root().selectionTop(); |
138 LayoutUnit h = root().selectionHeight(); | 139 LayoutUnit h = root().selectionHeight(); |
139 const int deltaY = roundToInt(renderer().style()->isFlippedLinesWritingMode(
) ? selectionBottom - logicalBottom() : logicalTop() - top); | 140 const int deltaY = roundToInt(renderer().style()->isFlippedLinesWritingMode(
) ? selectionBottom - logicalBottom() : logicalTop() - top); |
140 const FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); | 141 const FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); |
141 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, h.toFloat())); | 142 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, h.toFloat())); |
142 context->clip(clipRect); | 143 context->clip(clipRect); |
143 context->drawHighlightForText(font, RenderBlockFlow::constructTextRun(&rende
rer(), font, m_str, style, TextRun::AllowTrailingExpansion), localOrigin, h, c); | 144 context->drawHighlightForText(font, constructTextRun(&renderer(), font, m_st
r, style, TextRun::AllowTrailingExpansion), localOrigin, h, c); |
144 } | 145 } |
145 | 146 |
146 bool EllipsisBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& resu
lt, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOf
fset, LayoutUnit lineTop, LayoutUnit lineBottom) | 147 bool EllipsisBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& resu
lt, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOf
fset, LayoutUnit lineTop, LayoutUnit lineBottom) |
147 { | 148 { |
148 LayoutPoint adjustedLocation = accumulatedOffset + roundedLayoutPoint(topLef
t()); | 149 LayoutPoint adjustedLocation = accumulatedOffset + roundedLayoutPoint(topLef
t()); |
149 | 150 |
150 // Hit test the markup box. | 151 // Hit test the markup box. |
151 if (InlineBox* markupBox = this->markupBox()) { | 152 if (InlineBox* markupBox = this->markupBox()) { |
152 RenderStyle* style = renderer().style(isFirstLineStyle()); | 153 RenderStyle* style = renderer().style(isFirstLineStyle()); |
153 LayoutUnit mtx = adjustedLocation.x() + m_logicalWidth - markupBox->x(); | 154 LayoutUnit mtx = adjustedLocation.x() + m_logicalWidth - markupBox->x(); |
(...skipping 10 matching lines...) Expand all Loading... |
164 if (visibleToHitTestRequest(request) && boundsRect.intersects(HitTestLocatio
n::rectForPoint(locationInContainer.point(), 0, 0, 0, 0))) { | 165 if (visibleToHitTestRequest(request) && boundsRect.intersects(HitTestLocatio
n::rectForPoint(locationInContainer.point(), 0, 0, 0, 0))) { |
165 renderer().updateHitTestResult(result, locationInContainer.point() - toL
ayoutSize(adjustedLocation)); | 166 renderer().updateHitTestResult(result, locationInContainer.point() - toL
ayoutSize(adjustedLocation)); |
166 if (!result.addNodeToRectBasedTestResult(renderer().node(), request, loc
ationInContainer, boundsRect)) | 167 if (!result.addNodeToRectBasedTestResult(renderer().node(), request, loc
ationInContainer, boundsRect)) |
167 return true; | 168 return true; |
168 } | 169 } |
169 | 170 |
170 return false; | 171 return false; |
171 } | 172 } |
172 | 173 |
173 } // namespace WebCore | 174 } // namespace WebCore |
OLD | NEW |