Fix the issue that Web Audio test case fails on PR3.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / EllipsisBox.cpp
1 /**
2  * Copyright (C) 2003, 2006 Apple Computer, Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "config.h"
21 #include "EllipsisBox.h"
22
23 #include "Document.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"
30 #include "TextRun.h"
31
32 namespace WebCore {
33
34 void EllipsisBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit lineTop, LayoutUnit lineBottom)
35 {
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());
45         setShadow = true;
46     }
47
48     const Font& font = style->font();
49     if (selectionState() != RenderObject::SelectionNone) {
50         paintSelection(context, paintOffset, style, font);
51
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());
56     }
57
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()));
60
61     // Restore the regular fill color.
62     if (textColor != context->fillColor())
63         context->setFillColor(textColor, style->colorSpace());
64
65     if (setShadow)
66         context->clearShadow();
67
68     if (m_markupBox) {
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);
74     }
75 }
76
77 IntRect EllipsisBox::selectionRect()
78 {
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()));
83 }
84
85 void EllipsisBox::paintSelection(GraphicsContext* context, const LayoutPoint& paintOffset, RenderStyle* style, const Font& font)
86 {
87     Color textColor = style->visitedDependentColor(CSSPropertyColor);
88     Color c = m_renderer->selectionBackgroundColor();
89     if (!c.isValid() || !c.alpha())
90         return;
91
92     // If the text color ends up being the same as the selection background, invert the selection
93     // background.
94     if (textColor == c)
95         c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
96
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());
105 }
106
107 bool EllipsisBox::nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestPoint&, const LayoutPoint&, LayoutUnit, LayoutUnit)
108 {
109     return false;
110 }
111
112 } // namespace WebCore