2 * Copyright (C) 2003, 2006 Apple Computer, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
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
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include "EllipsisBox.h"
24 #include "GraphicsContext.h"
25 #include "HitTestResult.h"
26 #include "InlineTextBox.h"
27 #include "PaintInfo.h"
28 #include "RenderBlock.h"
29 #include "RootInlineBox.h"
34 void EllipsisBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
36 GraphicsContext* context = paintInfo.context;
37 RenderStyle* style = m_renderer->style(isFirstLineStyle());
38 Color textColor = style->visitedDependentColor(CSSPropertyColor);
39 if (textColor != context->fillColor())
40 context->setFillColor(textColor, style->colorSpace());
41 bool setShadow = false;
42 if (style->textShadow()) {
43 context->setShadow(LayoutSize(style->textShadow()->x(), style->textShadow()->y()),
44 style->textShadow()->blur(), style->textShadow()->color(), style->colorSpace());
48 const Font& font = style->font();
49 if (selectionState() != RenderObject::SelectionNone) {
50 paintSelection(context, paintOffset, style, font);
52 // Select the correct color for painting the text.
53 Color foreground = paintInfo.forceBlackText ? Color::black : renderer()->selectionForegroundColor();
54 if (foreground.isValid() && foreground != textColor)
55 context->setFillColor(foreground, style->colorSpace());
58 // FIXME: Why is this always LTR? Fix by passing correct text run flags below.
59 context->drawText(font, RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), LayoutPoint(x() + paintOffset.x(), y() + paintOffset.y() + style->fontMetrics().ascent()));
61 // Restore the regular fill color.
62 if (textColor != context->fillColor())
63 context->setFillColor(textColor, style->colorSpace());
66 context->clearShadow();
69 // Paint the markup box
70 LayoutPoint adjustedPaintOffset = paintOffset;
71 adjustedPaintOffset.move(x() + m_logicalWidth - m_markupBox->x(),
72 y() + style->fontMetrics().ascent() - (m_markupBox->y() + m_markupBox->renderer()->style(isFirstLineStyle())->fontMetrics().ascent()));
73 m_markupBox->paint(paintInfo, adjustedPaintOffset, lineTop, lineBottom);
77 IntRect EllipsisBox::selectionRect()
79 RenderStyle* style = m_renderer->style(isFirstLineStyle());
80 const Font& font = style->font();
81 // FIXME: Why is this always LTR? Fix by passing correct text run flags below.
82 return enclosingIntRect(font.selectionRectForText(RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), IntPoint(x(), y() + root()->selectionTopAdjustedForPrecedingBlock()), root()->selectionHeightAdjustedForPrecedingBlock()));
85 void EllipsisBox::paintSelection(GraphicsContext* context, const LayoutPoint& paintOffset, RenderStyle* style, const Font& font)
87 Color textColor = style->visitedDependentColor(CSSPropertyColor);
88 Color c = m_renderer->selectionBackgroundColor();
89 if (!c.isValid() || !c.alpha())
92 // If the text color ends up being the same as the selection background, invert the selection
95 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
97 GraphicsContextStateSaver stateSaver(*context);
98 LayoutUnit top = root()->selectionTop();
99 LayoutUnit h = root()->selectionHeight();
100 FloatRect clipRect(x() + paintOffset.x(), top + paintOffset.y(), m_logicalWidth, h);
101 alignSelectionRectToDevicePixels(clipRect);
102 context->clip(clipRect);
103 // FIXME: Why is this always LTR? Fix by passing correct text run flags below.
104 context->drawHighlightForText(font, RenderBlock::constructTextRun(renderer(), font, m_str, style, TextRun::AllowTrailingExpansion), roundedIntPoint(LayoutPoint(x() + paintOffset.x(), y() + paintOffset.y() + top)), h, c, style->colorSpace());
107 bool EllipsisBox::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestPoint&, const LayoutPoint&, LayoutUnit, LayoutUnit)
112 } // namespace WebCore