| 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 18 matching lines...) Expand all Loading... |
| 29 #include "platform/fonts/Font.h" | 29 #include "platform/fonts/Font.h" |
| 30 #include "platform/graphics/DrawLooperBuilder.h" | 30 #include "platform/graphics/DrawLooperBuilder.h" |
| 31 #include "platform/graphics/GraphicsContextStateSaver.h" | 31 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 32 #include "platform/text/TextRun.h" | 32 #include "platform/text/TextRun.h" |
| 33 | 33 |
| 34 namespace WebCore { | 34 namespace WebCore { |
| 35 | 35 |
| 36 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) |
| 37 { | 37 { |
| 38 GraphicsContext* context = paintInfo.context; | 38 GraphicsContext* context = paintInfo.context; |
| 39 RenderStyle* style = m_renderer->style(isFirstLineStyle()); | 39 RenderStyle* style = renderer().style(isFirstLineStyle()); |
| 40 | 40 |
| 41 const Font& font = style->font(); | 41 const Font& font = style->font(); |
| 42 FloatPoint boxOrigin = locationIncludingFlipping(); | 42 FloatPoint boxOrigin = locationIncludingFlipping(); |
| 43 LayoutPoint adjustedPaintOffset = paintOffset; | 43 LayoutPoint adjustedPaintOffset = paintOffset; |
| 44 if (!isHorizontal()) | 44 if (!isHorizontal()) |
| 45 adjustedPaintOffset.move(0, -virtualLogicalHeight()); | 45 adjustedPaintOffset.move(0, -virtualLogicalHeight()); |
| 46 boxOrigin.move(adjustedPaintOffset.x(), adjustedPaintOffset.y()); | 46 boxOrigin.move(adjustedPaintOffset.x(), adjustedPaintOffset.y()); |
| 47 FloatRect boxRect(boxOrigin, LayoutSize(logicalWidth(), virtualLogicalHeight
())); | 47 FloatRect boxRect(boxOrigin, LayoutSize(logicalWidth(), virtualLogicalHeight
())); |
| 48 GraphicsContextStateSaver stateSaver(*context); | 48 GraphicsContextStateSaver stateSaver(*context); |
| 49 if (!isHorizontal()) | 49 if (!isHorizontal()) |
| 50 context->concatCTM(InlineTextBox::rotation(boxRect, InlineTextBox::Clock
wise)); | 50 context->concatCTM(InlineTextBox::rotation(boxRect, InlineTextBox::Clock
wise)); |
| 51 FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + font.fontM
etrics().ascent()); | 51 FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + font.fontM
etrics().ascent()); |
| 52 | 52 |
| 53 Color styleTextColor = m_renderer->resolveColor(style, CSSPropertyWebkitText
FillColor); | 53 Color styleTextColor = renderer().resolveColor(style, CSSPropertyWebkitTextF
illColor); |
| 54 if (styleTextColor != context->fillColor()) | 54 if (styleTextColor != context->fillColor()) |
| 55 context->setFillColor(styleTextColor); | 55 context->setFillColor(styleTextColor); |
| 56 | 56 |
| 57 if (selectionState() != RenderObject::SelectionNone) { | 57 if (selectionState() != RenderObject::SelectionNone) { |
| 58 paintSelection(context, boxOrigin, style, font); | 58 paintSelection(context, boxOrigin, style, font); |
| 59 | 59 |
| 60 // Select the correct color for painting the text. | 60 // Select the correct color for painting the text. |
| 61 Color foreground = paintInfo.forceBlackText() ? Color::black : renderer(
)->selectionForegroundColor(); | 61 Color foreground = paintInfo.forceBlackText() ? Color::black : renderer(
).selectionForegroundColor(); |
| 62 if (foreground != styleTextColor) | 62 if (foreground != styleTextColor) |
| 63 context->setFillColor(foreground); | 63 context->setFillColor(foreground); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Text shadows are disabled when printing. http://crbug.com/258321 | 66 // Text shadows are disabled when printing. http://crbug.com/258321 |
| 67 const ShadowList* shadowList = context->printing() ? 0 : style->textShadow()
; | 67 const ShadowList* shadowList = context->printing() ? 0 : style->textShadow()
; |
| 68 bool hasShadow = shadowList; | 68 bool hasShadow = shadowList; |
| 69 if (hasShadow) { | 69 if (hasShadow) { |
| 70 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(
); | 70 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(
); |
| 71 for (size_t i = shadowList->shadows().size(); i--; ) { | 71 for (size_t i = shadowList->shadows().size(); i--; ) { |
| 72 const ShadowData& shadow = shadowList->shadows()[i]; | 72 const ShadowData& shadow = shadowList->shadows()[i]; |
| 73 float shadowX = isHorizontal() ? shadow.x() : shadow.y(); | 73 float shadowX = isHorizontal() ? shadow.x() : shadow.y(); |
| 74 float shadowY = isHorizontal() ? shadow.y() : -shadow.x(); | 74 float shadowY = isHorizontal() ? shadow.y() : -shadow.x(); |
| 75 FloatSize offset(shadowX, shadowY); | 75 FloatSize offset(shadowX, shadowY); |
| 76 drawLooperBuilder->addShadow(offset, shadow.blur(), shadow.color(), | 76 drawLooperBuilder->addShadow(offset, shadow.blur(), shadow.color(), |
| 77 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::
ShadowIgnoresAlpha); | 77 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::
ShadowIgnoresAlpha); |
| 78 } | 78 } |
| 79 drawLooperBuilder->addUnmodifiedContent(); | 79 drawLooperBuilder->addUnmodifiedContent(); |
| 80 context->setDrawLooper(drawLooperBuilder.release()); | 80 context->setDrawLooper(drawLooperBuilder.release()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TextRun textRun = RenderBlockFlow::constructTextRun(renderer(), font, m_str,
style, TextRun::AllowTrailingExpansion); | 83 TextRun textRun = RenderBlockFlow::constructTextRun(&renderer(), font, m_str
, style, TextRun::AllowTrailingExpansion); |
| 84 TextRunPaintInfo textRunPaintInfo(textRun); | 84 TextRunPaintInfo textRunPaintInfo(textRun); |
| 85 textRunPaintInfo.bounds = boxRect; | 85 textRunPaintInfo.bounds = boxRect; |
| 86 context->drawText(font, textRunPaintInfo, textOrigin); | 86 context->drawText(font, textRunPaintInfo, textOrigin); |
| 87 | 87 |
| 88 // Restore the regular fill color. | 88 // Restore the regular fill color. |
| 89 if (styleTextColor != context->fillColor()) | 89 if (styleTextColor != context->fillColor()) |
| 90 context->setFillColor(styleTextColor); | 90 context->setFillColor(styleTextColor); |
| 91 | 91 |
| 92 if (hasShadow) | 92 if (hasShadow) |
| 93 context->clearDrawLooper(); | 93 context->clearDrawLooper(); |
| 94 | 94 |
| 95 paintMarkupBox(paintInfo, paintOffset, lineTop, lineBottom, style); | 95 paintMarkupBox(paintInfo, paintOffset, lineTop, lineBottom, style); |
| 96 } | 96 } |
| 97 | 97 |
| 98 InlineBox* EllipsisBox::markupBox() const | 98 InlineBox* EllipsisBox::markupBox() const |
| 99 { | 99 { |
| 100 if (!m_shouldPaintMarkupBox || !m_renderer->isRenderBlock()) | 100 if (!m_shouldPaintMarkupBox || !renderer().isRenderBlock()) |
| 101 return 0; | 101 return 0; |
| 102 | 102 |
| 103 RenderBlock* block = toRenderBlock(m_renderer); | 103 RenderBlock& block = toRenderBlock(renderer()); |
| 104 RootInlineBox* lastLine = block->lineAtIndex(block->lineCount() - 1); | 104 RootInlineBox* lastLine = block.lineAtIndex(block.lineCount() - 1); |
| 105 if (!lastLine) | 105 if (!lastLine) |
| 106 return 0; | 106 return 0; |
| 107 | 107 |
| 108 // If the last line-box on the last line of a block is a link, -webkit-line-
clamp paints that box after the ellipsis. | 108 // If the last line-box on the last line of a block is a link, -webkit-line-
clamp paints that box after the ellipsis. |
| 109 // It does not actually move the link. | 109 // It does not actually move the link. |
| 110 InlineBox* anchorBox = lastLine->lastChild(); | 110 InlineBox* anchorBox = lastLine->lastChild(); |
| 111 if (!anchorBox || !anchorBox->renderer()->style()->isLink()) | 111 if (!anchorBox || !anchorBox->renderer().style()->isLink()) |
| 112 return 0; | 112 return 0; |
| 113 | 113 |
| 114 return anchorBox; | 114 return anchorBox; |
| 115 } | 115 } |
| 116 | 116 |
| 117 void EllipsisBox::paintMarkupBox(PaintInfo& paintInfo, const LayoutPoint& paintO
ffset, LayoutUnit lineTop, LayoutUnit lineBottom, RenderStyle* style) | 117 void EllipsisBox::paintMarkupBox(PaintInfo& paintInfo, const LayoutPoint& paintO
ffset, LayoutUnit lineTop, LayoutUnit lineBottom, RenderStyle* style) |
| 118 { | 118 { |
| 119 InlineBox* markupBox = this->markupBox(); | 119 InlineBox* markupBox = this->markupBox(); |
| 120 if (!markupBox) | 120 if (!markupBox) |
| 121 return; | 121 return; |
| 122 | 122 |
| 123 LayoutPoint adjustedPaintOffset = paintOffset; | 123 LayoutPoint adjustedPaintOffset = paintOffset; |
| 124 adjustedPaintOffset.move(x() + m_logicalWidth - markupBox->x(), | 124 adjustedPaintOffset.move(x() + m_logicalWidth - markupBox->x(), |
| 125 y() + style->fontMetrics().ascent() - (markupBox->y() + markupBox->rende
rer()->style(isFirstLineStyle())->fontMetrics().ascent())); | 125 y() + style->fontMetrics().ascent() - (markupBox->y() + markupBox->rende
rer().style(isFirstLineStyle())->fontMetrics().ascent())); |
| 126 markupBox->paint(paintInfo, adjustedPaintOffset, lineTop, lineBottom); | 126 markupBox->paint(paintInfo, adjustedPaintOffset, lineTop, lineBottom); |
| 127 } | 127 } |
| 128 | 128 |
| 129 IntRect EllipsisBox::selectionRect() | 129 IntRect EllipsisBox::selectionRect() |
| 130 { | 130 { |
| 131 RenderStyle* style = m_renderer->style(isFirstLineStyle()); | 131 RenderStyle* style = renderer().style(isFirstLineStyle()); |
| 132 const Font& font = style->font(); | 132 const Font& font = style->font(); |
| 133 return enclosingIntRect(font.selectionRectForText(RenderBlockFlow::construct
TextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoi
nt(logicalLeft(), logicalTop() + root()->selectionTopAdjustedForPrecedingBlock()
), root()->selectionHeightAdjustedForPrecedingBlock())); | 133 return enclosingIntRect(font.selectionRectForText(RenderBlockFlow::construct
TextRun(&renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPo
int(logicalLeft(), logicalTop() + root()->selectionTopAdjustedForPrecedingBlock(
)), root()->selectionHeightAdjustedForPrecedingBlock())); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void EllipsisBox::paintSelection(GraphicsContext* context, const FloatPoint& box
Origin, RenderStyle* style, const Font& font) | 136 void EllipsisBox::paintSelection(GraphicsContext* context, const FloatPoint& box
Origin, RenderStyle* style, const Font& font) |
| 137 { | 137 { |
| 138 Color textColor = m_renderer->resolveColor(style, CSSPropertyColor); | 138 Color textColor = renderer().resolveColor(style, CSSPropertyColor); |
| 139 Color c = m_renderer->selectionBackgroundColor(); | 139 Color c = renderer().selectionBackgroundColor(); |
| 140 if (!c.alpha()) | 140 if (!c.alpha()) |
| 141 return; | 141 return; |
| 142 | 142 |
| 143 // If the text color ends up being the same as the selection background, inv
ert the selection | 143 // If the text color ends up being the same as the selection background, inv
ert the selection |
| 144 // background. | 144 // background. |
| 145 if (textColor == c) | 145 if (textColor == c) |
| 146 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); | 146 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); |
| 147 | 147 |
| 148 GraphicsContextStateSaver stateSaver(*context); | 148 GraphicsContextStateSaver stateSaver(*context); |
| 149 LayoutUnit selectionBottom = root()->selectionBottom(); | 149 LayoutUnit selectionBottom = root()->selectionBottom(); |
| 150 LayoutUnit top = root()->selectionTop(); | 150 LayoutUnit top = root()->selectionTop(); |
| 151 LayoutUnit h = root()->selectionHeight(); | 151 LayoutUnit h = root()->selectionHeight(); |
| 152 const int deltaY = roundToInt(renderer()->style()->isFlippedLinesWritingMode
() ? selectionBottom - logicalBottom() : logicalTop() - top); | 152 const int deltaY = roundToInt(renderer().style()->isFlippedLinesWritingMode(
) ? selectionBottom - logicalBottom() : logicalTop() - top); |
| 153 const FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); | 153 const FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); |
| 154 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, h)); | 154 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, h)); |
| 155 alignSelectionRectToDevicePixels(clipRect); | 155 alignSelectionRectToDevicePixels(clipRect); |
| 156 context->clip(clipRect); | 156 context->clip(clipRect); |
| 157 context->drawHighlightForText(font, RenderBlockFlow::constructTextRun(render
er(), font, m_str, style, TextRun::AllowTrailingExpansion), localOrigin, h, c); | 157 context->drawHighlightForText(font, RenderBlockFlow::constructTextRun(&rende
rer(), font, m_str, style, TextRun::AllowTrailingExpansion), localOrigin, h, c); |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool EllipsisBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& resu
lt, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOf
fset, LayoutUnit lineTop, LayoutUnit lineBottom) | 160 bool EllipsisBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& resu
lt, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOf
fset, LayoutUnit lineTop, LayoutUnit lineBottom) |
| 161 { | 161 { |
| 162 LayoutPoint adjustedLocation = accumulatedOffset + roundedLayoutPoint(topLef
t()); | 162 LayoutPoint adjustedLocation = accumulatedOffset + roundedLayoutPoint(topLef
t()); |
| 163 | 163 |
| 164 // Hit test the markup box. | 164 // Hit test the markup box. |
| 165 if (InlineBox* markupBox = this->markupBox()) { | 165 if (InlineBox* markupBox = this->markupBox()) { |
| 166 RenderStyle* style = m_renderer->style(isFirstLineStyle()); | 166 RenderStyle* style = renderer().style(isFirstLineStyle()); |
| 167 LayoutUnit mtx = adjustedLocation.x() + m_logicalWidth - markupBox->x(); | 167 LayoutUnit mtx = adjustedLocation.x() + m_logicalWidth - markupBox->x(); |
| 168 LayoutUnit mty = adjustedLocation.y() + style->fontMetrics().ascent() -
(markupBox->y() + markupBox->renderer()->style(isFirstLineStyle())->fontMetrics(
).ascent()); | 168 LayoutUnit mty = adjustedLocation.y() + style->fontMetrics().ascent() -
(markupBox->y() + markupBox->renderer().style(isFirstLineStyle())->fontMetrics()
.ascent()); |
| 169 if (markupBox->nodeAtPoint(request, result, locationInContainer, LayoutP
oint(mtx, mty), lineTop, lineBottom)) { | 169 if (markupBox->nodeAtPoint(request, result, locationInContainer, LayoutP
oint(mtx, mty), lineTop, lineBottom)) { |
| 170 renderer()->updateHitTestResult(result, locationInContainer.point()
- LayoutSize(mtx, mty)); | 170 renderer().updateHitTestResult(result, locationInContainer.point() -
LayoutSize(mtx, mty)); |
| 171 return true; | 171 return true; |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 FloatPoint boxOrigin = locationIncludingFlipping(); | 175 FloatPoint boxOrigin = locationIncludingFlipping(); |
| 176 boxOrigin.moveBy(accumulatedOffset); | 176 boxOrigin.moveBy(accumulatedOffset); |
| 177 FloatRect boundsRect(boxOrigin, size()); | 177 FloatRect boundsRect(boxOrigin, size()); |
| 178 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))) { |
| 179 renderer()->updateHitTestResult(result, locationInContainer.point() - to
LayoutSize(adjustedLocation)); | 179 renderer().updateHitTestResult(result, locationInContainer.point() - toL
ayoutSize(adjustedLocation)); |
| 180 if (!result.addNodeToRectBasedTestResult(renderer()->node(), request, lo
cationInContainer, boundsRect)) | 180 if (!result.addNodeToRectBasedTestResult(renderer().node(), request, loc
ationInContainer, boundsRect)) |
| 181 return true; | 181 return true; |
| 182 } | 182 } |
| 183 | 183 |
| 184 return false; | 184 return false; |
| 185 } | 185 } |
| 186 | 186 |
| 187 } // namespace WebCore | 187 } // namespace WebCore |
| OLD | NEW |