KHtml

RenderSVGInlineText.cpp
1 /*
2  * This file is part of the WebKit project.
3  *
4  * Copyright (C) 2006 Oliver Hunt <[email protected]>
5  * (C) 2006 Apple Computer Inc.
6  * (C) 2007 Nikolas Zimmermann <[email protected]>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB. If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24 
25 #include "wtf/Platform.h"
26 
27 #if ENABLE(SVG)
28 #include "RenderSVGInlineText.h"
29 
30 #include "FloatConversion.h"
31 //#include "RenderBlock.h"
32 #include "render_block.h" // khtml
33 #include "RenderSVGRoot.h"
34 #include "SVGInlineTextBox.h"
35 #include "SVGRootInlineBox.h"
36 
37 namespace WebCore
38 {
39 using namespace khtml;
40 
41 static inline bool isChildOfHiddenContainer(RenderObject *start)
42 {
43  while (start) {
44  if (start->isSVGHiddenContainer()) {
45  return true;
46  }
47 
48  start = start->parent();
49  }
50 
51  return false;
52 }
53 
54 RenderSVGInlineText::RenderSVGInlineText(Node *n, DOMStringImpl *str)
55  : RenderText(n, str)
56 {
57 }
58 
59 void RenderSVGInlineText::absoluteRects(Vector<IntRect> &rects, int, int, bool)
60 {
61  rects.append(computeAbsoluteRectForRange(0, stringLength()));
62 }
63 
64 IntRect RenderSVGInlineText::selectionRect(bool)
65 {
66  ASSERT(!needsLayout());
67 
68  IntRect rect;
69  if (selectionState() == SelectionNone) {
70  return rect;
71  }
72 
73  // Early exit if we're ie. a <text> within a <defs> section.
74  if (isChildOfHiddenContainer(this)) {
75  return rect;
76  }
77 
78  // Now calculate startPos and endPos for painting selection.
79  // We include a selection while endPos > 0
80  int startPos, endPos;
81  if (selectionState() == SelectionInside) {
82  // We are fully selected.
83  startPos = 0;
84  endPos = stringLength();
85  } else {
86  selectionStartEnd(startPos, endPos);
87  if (selectionState() == SelectionStart) {
88  endPos = stringLength();
89  } else if (selectionState() == SelectionEnd) {
90  startPos = 0;
91  }
92  }
93 
94  if (startPos == endPos) {
95  return rect;
96  }
97 
98  return computeAbsoluteRectForRange(startPos, endPos);
99 }
100 
101 IntRect RenderSVGInlineText::computeAbsoluteRectForRange(int startPos, int endPos)
102 {
103  Q_UNUSED(startPos);
104  Q_UNUSED(endPos);
105  IntRect rect;
106 
107  RenderBlock *cb = containingBlock();
108  if (!cb || !cb->container()) {
109  return rect;
110  }
111 
112  RenderSVGRoot *root = findSVGRootObject(parent());
113  if (!root) {
114  return rect;
115  }
116 
117  /*FIXME khtml for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox())
118  rect.unite(box->selectionRect(0, 0, startPos, endPos));*/
119 
120  // Mimic RenderBox::computeAbsoluteRepaintRect() functionality. But only the subset needed for SVG and respecting SVG transformations.
121  int x, y;
122  cb->container()->absolutePosition(x, y);
123 
124  // Remove HTML parent translation offsets here! These need to be retrieved from the RenderSVGRoot object.
125  // But do take the containingBlocks's container position into account, ie. SVG text in scrollable <div>.
126  AffineTransform htmlParentCtm = root->RenderContainer::absoluteTransform();
127 
128  FloatRect fixedRect(narrowPrecisionToFloat(rect.x() + x - xPos() - htmlParentCtm.e()), narrowPrecisionToFloat(rect.y() + y - yPos() - htmlParentCtm.f()), rect.width(), rect.height());
129  return enclosingIntRect(absoluteTransform().mapRect(fixedRect));
130 }
131 
132 InlineTextBox *RenderSVGInlineText::createInlineTextBox()
133 {
134  // qCDebug(KHTML_LOG) << "allocate";
135  return new(renderArena()) SVGInlineTextBox(this);
136 }
137 
138 /*IntRect RenderSVGInlineText::caretRect(int offset, EAffinity affinity, int* extraWidthToEndOfLine)
139 {
140  // SVG doesn't have any editable content where a caret rect would be needed
141  return IntRect();
142 }*/
143 
144 /*VisiblePosition RenderSVGInlineText::positionForCoordinates(int x, int y)
145 {
146  SVGInlineTextBox* textBox = static_cast<SVGInlineTextBox*>(firstTextBox());
147 
148  if (!textBox || textLength() == 0)
149  return VisiblePosition(element(), 0, DOWNSTREAM);
150 
151  SVGRootInlineBox* rootBox = textBox->svgRootInlineBox();
152  RenderObject* object = rootBox ? rootBox->object() : 0;
153 
154  if (!object)
155  return VisiblePosition(element(), 0, DOWNSTREAM);
156 
157  int offset = 0;
158 
159  for (SVGInlineTextBox* box = textBox; box; box = static_cast<SVGInlineTextBox*>(box->nextTextBox())) {
160  if (box->svgCharacterHitsPosition(x + object->xPos(), y + object->yPos(), offset)) {
161  // If we're not at the end/start of the box, stop looking for other selected boxes.
162  if (!box->m_reversed) {
163  if (offset <= (int) box->end() + 1)
164  break;
165  } else {
166  if (offset > (int) box->start())
167  break;
168  }
169  }
170  }
171 
172  return VisiblePosition(element(), offset, DOWNSTREAM);
173 }*/
174 
175 }
176 
177 #endif // ENABLE(SVG)
This file is part of the HTML rendering engine for KDE.
Base Class for all rendering tree objects.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:48:01 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.