2 * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>
3 * Copyright (C) 2006 Apple Computer Inc.
4 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
5 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #include "SVGInlineFlowBox.h"
27 #include "DocumentMarkerController.h"
28 #include "GraphicsContext.h"
29 #include "RenderSVGInlineText.h"
30 #include "RenderedDocumentMarker.h"
31 #include "SVGInlineTextBox.h"
32 #include "SVGRenderSupport.h"
38 void SVGInlineFlowBox::paintSelectionBackground(PaintInfo& paintInfo)
40 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
41 ASSERT(!paintInfo.context->paintingDisabled());
43 PaintInfo childPaintInfo(paintInfo);
44 for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
45 if (child->isSVGInlineTextBox())
46 static_cast<SVGInlineTextBox*>(child)->paintSelectionBackground(childPaintInfo);
47 else if (child->isSVGInlineFlowBox())
48 static_cast<SVGInlineFlowBox*>(child)->paintSelectionBackground(childPaintInfo);
52 void SVGInlineFlowBox::paint(PaintInfo& paintInfo, const LayoutPoint&, LayoutUnit, LayoutUnit)
54 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
55 ASSERT(!paintInfo.context->paintingDisabled());
57 RenderObject* boxRenderer = renderer();
60 PaintInfo childPaintInfo(paintInfo);
61 GraphicsContextStateSaver stateSaver(*childPaintInfo.context);
63 if (SVGRenderSupport::prepareToRenderSVGContent(boxRenderer, childPaintInfo)) {
64 for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
65 if (child->isSVGInlineTextBox())
66 computeTextMatchMarkerRectForRenderer(toRenderSVGInlineText(static_cast<SVGInlineTextBox*>(child)->textRenderer()));
68 child->paint(childPaintInfo, LayoutPoint(), 0, 0);
72 SVGRenderSupport::finishRenderSVGContent(boxRenderer, childPaintInfo, paintInfo.context);
75 IntRect SVGInlineFlowBox::calculateBoundaries() const
78 for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
79 if (!child->isSVGInlineTextBox() && !child->isSVGInlineFlowBox())
81 childRect.unite(child->calculateBoundaries());
86 void SVGInlineFlowBox::computeTextMatchMarkerRectForRenderer(RenderSVGInlineText* textRenderer)
90 Node* node = textRenderer->node();
91 if (!node || !node->inDocument())
94 RenderStyle* style = textRenderer->style();
97 AffineTransform fragmentTransform;
98 Document* document = textRenderer->document();
99 Vector<DocumentMarker*> markers = document->markers()->markersFor(textRenderer->node());
101 Vector<DocumentMarker*>::iterator markerEnd = markers.end();
102 for (Vector<DocumentMarker*>::iterator markerIt = markers.begin(); markerIt != markerEnd; ++markerIt) {
103 DocumentMarker* marker = *markerIt;
105 // SVG is only interessted in the TextMatch marker, for now.
106 if (marker->type() != DocumentMarker::TextMatch)
109 FloatRect markerRect;
110 for (InlineTextBox* box = textRenderer->firstTextBox(); box; box = box->nextTextBox()) {
111 if (!box->isSVGInlineTextBox())
114 SVGInlineTextBox* textBox = static_cast<SVGInlineTextBox*>(box);
116 int markerStartPosition = max<int>(marker->startOffset() - textBox->start(), 0);
117 int markerEndPosition = min<int>(marker->endOffset() - textBox->start(), textBox->len());
119 if (markerStartPosition >= markerEndPosition)
122 int fragmentStartPosition = 0;
123 int fragmentEndPosition = 0;
125 const Vector<SVGTextFragment>& fragments = textBox->textFragments();
126 unsigned textFragmentsSize = fragments.size();
127 for (unsigned i = 0; i < textFragmentsSize; ++i) {
128 const SVGTextFragment& fragment = fragments.at(i);
130 fragmentStartPosition = markerStartPosition;
131 fragmentEndPosition = markerEndPosition;
132 if (!textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
135 FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style);
136 fragment.buildFragmentTransform(fragmentTransform);
137 if (!fragmentTransform.isIdentity())
138 fragmentRect = fragmentTransform.mapRect(fragmentRect);
140 markerRect.unite(fragmentRect);
144 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer->localToAbsoluteQuad(markerRect).enclosingBoundingBox());
148 } // namespace WebCore
150 #endif // ENABLE(SVG)