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 "core/rendering/svg/SVGInlineFlowBox.h"
26 #include "core/dom/DocumentMarkerController.h"
27 #include "core/dom/RenderedDocumentMarker.h"
28 #include "core/rendering/svg/RenderSVGInlineText.h"
29 #include "core/rendering/svg/SVGInlineTextBox.h"
30 #include "core/rendering/svg/SVGRenderingContext.h"
36 void SVGInlineFlowBox::paintSelectionBackground(PaintInfo& paintInfo)
38 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
39 ASSERT(!paintInfo.context->paintingDisabled());
41 PaintInfo childPaintInfo(paintInfo);
42 for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
43 if (child->isSVGInlineTextBox())
44 toSVGInlineTextBox(child)->paintSelectionBackground(childPaintInfo);
45 else if (child->isSVGInlineFlowBox())
46 toSVGInlineFlowBox(child)->paintSelectionBackground(childPaintInfo);
50 void SVGInlineFlowBox::paint(PaintInfo& paintInfo, const LayoutPoint&, LayoutUnit, LayoutUnit)
52 ASSERT(paintInfo.phase == PaintPhaseForeground || paintInfo.phase == PaintPhaseSelection);
53 ASSERT(!paintInfo.context->paintingDisabled());
55 RenderObject* boxRenderer = renderer();
58 SVGRenderingContext renderingContext(boxRenderer, paintInfo, SVGRenderingContext::SaveGraphicsContext);
59 if (renderingContext.isRenderingPrepared()) {
60 for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
61 if (child->isSVGInlineTextBox())
62 computeTextMatchMarkerRectForRenderer(toRenderSVGInlineText(toSVGInlineTextBox(child)->textRenderer()));
64 child->paint(paintInfo, LayoutPoint(), 0, 0);
69 FloatRect SVGInlineFlowBox::calculateBoundaries() const
72 for (InlineBox* child = firstChild(); child; child = child->nextOnLine()) {
73 if (!child->isSVGInlineTextBox() && !child->isSVGInlineFlowBox())
75 childRect.unite(child->calculateBoundaries());
80 void SVGInlineFlowBox::computeTextMatchMarkerRectForRenderer(RenderSVGInlineText* textRenderer)
84 Node* node = textRenderer->node();
85 if (!node || !node->inDocument())
88 RenderStyle* style = textRenderer->style();
91 AffineTransform fragmentTransform;
92 Document& document = textRenderer->document();
93 Vector<DocumentMarker*> markers = document.markers()->markersFor(textRenderer->node());
95 Vector<DocumentMarker*>::iterator markerEnd = markers.end();
96 for (Vector<DocumentMarker*>::iterator markerIt = markers.begin(); markerIt != markerEnd; ++markerIt) {
97 DocumentMarker* marker = *markerIt;
99 // SVG is only interessted in the TextMatch marker, for now.
100 if (marker->type() != DocumentMarker::TextMatch)
103 FloatRect markerRect;
104 for (InlineTextBox* box = textRenderer->firstTextBox(); box; box = box->nextTextBox()) {
105 if (!box->isSVGInlineTextBox())
108 SVGInlineTextBox* textBox = toSVGInlineTextBox(box);
110 int markerStartPosition = max<int>(marker->startOffset() - textBox->start(), 0);
111 int markerEndPosition = min<int>(marker->endOffset() - textBox->start(), textBox->len());
113 if (markerStartPosition >= markerEndPosition)
116 int fragmentStartPosition = 0;
117 int fragmentEndPosition = 0;
119 const Vector<SVGTextFragment>& fragments = textBox->textFragments();
120 unsigned textFragmentsSize = fragments.size();
121 for (unsigned i = 0; i < textFragmentsSize; ++i) {
122 const SVGTextFragment& fragment = fragments.at(i);
124 fragmentStartPosition = markerStartPosition;
125 fragmentEndPosition = markerEndPosition;
126 if (!textBox->mapStartEndPositionsIntoFragmentCoordinates(fragment, fragmentStartPosition, fragmentEndPosition))
129 FloatRect fragmentRect = textBox->selectionRectForTextFragment(fragment, fragmentStartPosition, fragmentEndPosition, style);
130 fragment.buildFragmentTransform(fragmentTransform);
131 if (!fragmentTransform.isIdentity())
132 fragmentRect = fragmentTransform.mapRect(fragmentRect);
134 markerRect.unite(fragmentRect);
138 toRenderedDocumentMarker(marker)->setRenderedRect(textRenderer->localToAbsoluteQuad(markerRect).enclosingBoundingBox());
142 } // namespace WebCore