• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • sources
  • kde-4.12
  • kdelibs
  • khtml
  • dom
dom2_range.cpp
Go to the documentation of this file.
1 
26 #include "dom/dom_exception.h"
27 #include "xml/dom_docimpl.h"
28 #include "xml/dom2_rangeimpl.h"
29 
30 using namespace DOM;
31 
32 DOMString RangeException::codeAsString() const
33 {
34  return codeAsString(code);
35 }
36 
37 bool RangeException::isRangeExceptionCode(int exceptioncode)
38 {
39  return exceptioncode >= _EXCEPTION_OFFSET && exceptioncode < _EXCEPTION_MAX;
40 }
41 
42 DOMString RangeException::codeAsString(int code)
43 {
44  switch ( code ) {
45  case BAD_BOUNDARYPOINTS_ERR:
46  return DOMString( "BAD_BOUNDARYPOINTS_ERR" );
47  case INVALID_NODE_TYPE_ERR:
48  return DOMString( "INVALID_NODE_TYPE_ERR" );
49  default:
50  return DOMString( "(unknown exception code)" );
51  }
52 }
53 
54 Range::Range()
55 {
56  // a range can't exist by itself - it must be associated with a document
57  impl = 0;
58 }
59 
60 Range::Range(const Document rootContainer)
61 {
62  if(rootContainer.handle())
63  {
64  impl = new RangeImpl(rootContainer.handle()->docPtr());
65  impl->ref();
66  }
67  else
68  impl = 0;
69 }
70 
71 Range::Range(const Range &other)
72 {
73  impl = other.impl;
74  if (impl) impl->ref();
75 }
76 
77 Range::Range(const Node startContainer, const long startOffset, const Node endContainer, const long endOffset)
78 {
79  if (startContainer.isNull() || endContainer.isNull()) {
80  throw DOMException(DOMException::NOT_FOUND_ERR);
81  }
82 
83  if (!startContainer.handle()->document() ||
84  startContainer.handle()->document() != endContainer.handle()->document()) {
85  throw DOMException(DOMException::WRONG_DOCUMENT_ERR);
86  }
87 
88  impl = new RangeImpl(startContainer.handle()->docPtr(),startContainer.handle(),startOffset,endContainer.handle(),endOffset);
89  impl->ref();
90 }
91 
92 Range::Range(RangeImpl *i)
93 {
94  impl = i;
95  if (impl) impl->ref();
96 }
97 
98 Range &Range::operator = (const Range &other)
99 {
100  if ( impl != other.impl ) {
101  if (impl) impl->deref();
102  impl = other.impl;
103  if (impl) impl->ref();
104  }
105  return *this;
106 }
107 
108 Range::~Range()
109 {
110  if (impl) impl->deref();
111 }
112 
113 Node Range::startContainer() const
114 {
115  if (!impl)
116  throw DOMException(DOMException::INVALID_STATE_ERR);
117 
118  int exceptioncode = 0;
119  NodeImpl *r = impl->startContainer(exceptioncode);
120  throwException(exceptioncode);
121  return r;
122 }
123 
124 long Range::startOffset() const
125 {
126  if (!impl)
127  throw DOMException(DOMException::INVALID_STATE_ERR);
128 
129  int exceptioncode = 0;
130  long r = impl->startOffset(exceptioncode);
131  throwException(exceptioncode);
132  return r;
133 
134 }
135 
136 Node Range::endContainer() const
137 {
138  if (!impl)
139  throw DOMException(DOMException::INVALID_STATE_ERR);
140 
141  int exceptioncode = 0;
142  NodeImpl *r = impl->endContainer(exceptioncode);
143  throwException(exceptioncode);
144  return r;
145 }
146 
147 long Range::endOffset() const
148 {
149  if (!impl)
150  throw DOMException(DOMException::INVALID_STATE_ERR);
151 
152  int exceptioncode = 0;
153  long r = impl->endOffset(exceptioncode);
154  throwException(exceptioncode);
155  return r;
156 }
157 
158 bool Range::collapsed() const
159 {
160  if (!impl)
161  throw DOMException(DOMException::INVALID_STATE_ERR);
162 
163  int exceptioncode = 0;
164  bool r = impl->collapsed(exceptioncode);
165  throwException(exceptioncode);
166  return r;
167 }
168 
169 Node Range::commonAncestorContainer()
170 {
171  if (!impl)
172  throw DOMException(DOMException::INVALID_STATE_ERR);
173 
174  int exceptioncode = 0;
175  NodeImpl *r = impl->commonAncestorContainer(exceptioncode);
176  throwException(exceptioncode);
177  return r;
178 }
179 
180 void Range::setStart( const Node &refNode, long offset )
181 {
182  if (!impl)
183  throw DOMException(DOMException::INVALID_STATE_ERR);
184 
185  int exceptioncode = 0;
186  impl->setStart(refNode.handle(),offset,exceptioncode);
187  throwException(exceptioncode);
188 }
189 
190 void Range::setEnd( const Node &refNode, long offset )
191 {
192  if (!impl)
193  throw DOMException(DOMException::INVALID_STATE_ERR);
194 
195  int exceptioncode = 0;
196  impl->setEnd(refNode.handle(),offset,exceptioncode);
197  throwException(exceptioncode);
198 }
199 
200 void Range::setStartBefore( const Node &refNode )
201 {
202  if (!impl)
203  throw DOMException(DOMException::INVALID_STATE_ERR);
204 
205 
206  int exceptioncode = 0;
207  impl->setStartBefore(refNode.handle(),exceptioncode);
208  throwException(exceptioncode);
209 }
210 
211 void Range::setStartAfter( const Node &refNode )
212 {
213  if (!impl)
214  throw DOMException(DOMException::INVALID_STATE_ERR);
215 
216  int exceptioncode = 0;
217  impl->setStartAfter(refNode.handle(),exceptioncode);
218  throwException(exceptioncode);
219 }
220 
221 void Range::setEndBefore( const Node &refNode )
222 {
223  if (!impl)
224  throw DOMException(DOMException::INVALID_STATE_ERR);
225 
226  int exceptioncode = 0;
227  impl->setEndBefore(refNode.handle(),exceptioncode);
228  throwException(exceptioncode);
229 }
230 
231 void Range::setEndAfter( const Node &refNode )
232 {
233  if (!impl)
234  throw DOMException(DOMException::INVALID_STATE_ERR);
235 
236  int exceptioncode = 0;
237  impl->setEndAfter(refNode.handle(),exceptioncode);
238  throwException(exceptioncode);
239 }
240 
241 void Range::collapse( bool toStart )
242 {
243  if (!impl)
244  throw DOMException(DOMException::INVALID_STATE_ERR);
245 
246  int exceptioncode = 0;
247  impl->collapse(toStart,exceptioncode);
248  throwException(exceptioncode);
249 }
250 
251 void Range::selectNode( const Node &refNode )
252 {
253  if (!impl)
254  throw DOMException(DOMException::INVALID_STATE_ERR);
255 
256  int exceptioncode = 0;
257  impl->selectNode(refNode.handle(),exceptioncode);
258  throwException(exceptioncode);
259 }
260 
261 void Range::selectNodeContents( const Node &refNode )
262 {
263  if (!impl)
264  throw DOMException(DOMException::INVALID_STATE_ERR);
265 
266  int exceptioncode = 0;
267  impl->selectNodeContents(refNode.handle(),exceptioncode);
268  throwException(exceptioncode);
269 }
270 
271 short Range::compareBoundaryPoints( CompareHow how, const Range &sourceRange )
272 {
273  if (!impl)
274  throw DOMException(DOMException::INVALID_STATE_ERR);
275 
276  int exceptioncode = 0;
277  short r = impl->compareBoundaryPoints(how,sourceRange.handle(),exceptioncode);
278  throwException(exceptioncode);
279  return r;
280 }
281 
282 bool Range::boundaryPointsValid( )
283 {
284  if (!impl)
285  throw DOMException(DOMException::INVALID_STATE_ERR);
286 
287  return impl->boundaryPointsValid();
288 }
289 
290 void Range::deleteContents( )
291 {
292  if (!impl)
293  throw DOMException(DOMException::INVALID_STATE_ERR);
294 
295  int exceptioncode = 0;
296  impl->deleteContents(exceptioncode);
297  throwException(exceptioncode);
298 }
299 
300 DocumentFragment Range::extractContents( )
301 {
302  if (!impl)
303  throw DOMException(DOMException::INVALID_STATE_ERR);
304 
305  int exceptioncode = 0;
306  DocumentFragmentImpl *r = impl->extractContents(exceptioncode);
307  throwException(exceptioncode);
308  return r;
309 }
310 
311 DocumentFragment Range::cloneContents( )
312 {
313  if (!impl)
314  throw DOMException(DOMException::INVALID_STATE_ERR);
315 
316  int exceptioncode = 0;
317  DocumentFragmentImpl *r = impl->cloneContents(exceptioncode);
318  throwException(exceptioncode);
319  return r;
320 }
321 
322 void Range::insertNode( const Node &newNode )
323 {
324  if (!impl)
325  throw DOMException(DOMException::INVALID_STATE_ERR);
326 
327  int exceptioncode = 0;
328  impl->insertNode(newNode.handle(),exceptioncode);
329  throwException(exceptioncode);
330 }
331 
332 void Range::surroundContents( const Node &newParent )
333 {
334  if (!impl)
335  throw DOMException(DOMException::INVALID_STATE_ERR);
336 
337  int exceptioncode = 0;
338  impl->surroundContents(newParent.handle(),exceptioncode);
339  throwException(exceptioncode);
340 }
341 
342 Range Range::cloneRange( )
343 {
344  if (!impl)
345  throw DOMException(DOMException::INVALID_STATE_ERR);
346 
347  int exceptioncode = 0;
348  RangeImpl *r = impl->cloneRange(exceptioncode);
349  throwException(exceptioncode);
350  return r;
351 }
352 
353 DOMString Range::toString( )
354 {
355  if (!impl)
356  throw DOMException(DOMException::INVALID_STATE_ERR);
357 
358  int exceptioncode = 0;
359  DOMString r = impl->toString(exceptioncode);
360  throwException(exceptioncode);
361  return r;
362 
363 }
364 
365 DOMString Range::toHTML( )
366 {
367  if (!impl)
368  throw DOMException(DOMException::INVALID_STATE_ERR);
369  int exceptioncode = 0;
370  DOMString r = impl->toHTML(exceptioncode);
371  throwException(exceptioncode);
372  return r;
373 }
374 
375 DocumentFragment Range::createContextualFragment( const DOMString &html )
376 {
377  if (!impl)
378  throw DOMException(DOMException::INVALID_STATE_ERR);
379 
380  int exceptioncode = 0;
381  DocumentFragment r = impl->createContextualFragment(html, exceptioncode);
382  throwException(exceptioncode);
383  return r;
384 }
385 
386 
387 void Range::detach( )
388 {
389  if (!impl)
390  throw DOMException(DOMException::INVALID_STATE_ERR);
391 
392  int exceptioncode = 0;
393  impl->detach(exceptioncode);
394  throwException(exceptioncode);
395 }
396 
397 bool Range::isDetached() const
398 {
399  if (!impl)
400  throw DOMException(DOMException::INVALID_STATE_ERR);
401 
402  return impl->isDetached();
403 }
404 
405 RangeImpl *Range::handle() const
406 {
407  return impl;
408 }
409 
410 bool Range::isNull() const
411 {
412  return (impl == 0);
413 }
414 
415 void Range::throwException(int exceptioncode) const
416 {
417  if (!exceptioncode)
418  return;
419 
420  // ### also check for CSS & other exceptions?
421  if (exceptioncode >= RangeException::_EXCEPTION_OFFSET && exceptioncode <= RangeException::_EXCEPTION_MAX)
422  throw RangeException(static_cast<RangeException::RangeExceptionCode>(exceptioncode-RangeException::_EXCEPTION_OFFSET));
423  else
424  throw DOMException(exceptioncode);
425 }
426 
427 
428 
DOM::DOMException::NOT_FOUND_ERR
Definition: dom_exception.h:80
DOM::Node
The Node interface is the primary datatype for the entire Document Object Model.
Definition: dom_node.h:270
DOM::Range::startOffset
long startOffset() const
Offset within the starting node of the range.
Definition: dom2_range.cpp:124
DOM::RangeException::INVALID_NODE_TYPE_ERR
Definition: dom2_range.h:62
DOM::Range::compareBoundaryPoints
short compareBoundaryPoints(CompareHow how, const Range &sourceRange)
Compare the end-points of two ranges in a document.
Definition: dom2_range.cpp:271
DOM::Range::operator=
Range & operator=(const Range &other)
Definition: dom2_range.cpp:98
DOM::Range::setEndAfter
void setEndAfter(const Node &refNode)
Sets the end of a range to be after a node.
Definition: dom2_range.cpp:231
DOM::RangeException::codeAsString
DOMString codeAsString() const
Returns the name of this error.
Definition: dom2_range.cpp:32
DOM::Range::~Range
~Range()
Definition: dom2_range.cpp:108
DOM::Range::toHTML
DOMString toHTML()
Definition: dom2_range.cpp:365
DOM::Range::setEndBefore
void setEndBefore(const Node &refNode)
Sets the end position to be before a node.
Definition: dom2_range.cpp:221
DOM::Range::endContainer
Node endContainer() const
Node within which the range ends.
Definition: dom2_range.cpp:136
DOM::Range::insertNode
void insertNode(const Node &newNode)
Inserts a node into the document or document fragment at the start of the range.
Definition: dom2_range.cpp:322
DOM::Range::handle
RangeImpl * handle() const
Definition: dom2_range.cpp:405
DOM::DocumentFragment
DocumentFragment is a "lightweight" or "minimal" Document object.
Definition: dom_doc.h:1041
DOM::RangeException::isRangeExceptionCode
static bool isRangeExceptionCode(int exceptioncode)
Definition: dom2_range.cpp:37
DOM::DOMException
DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation is impos...
Definition: dom_exception.h:58
DOM::RangeException::_EXCEPTION_OFFSET
Definition: dom2_range.h:63
DOM::Range::selectNodeContents
void selectNodeContents(const Node &refNode)
Select the contents within a node.
Definition: dom2_range.cpp:261
DOM::Range::toString
DOMString toString()
Returns the contents of a range as a string.
Definition: dom2_range.cpp:353
DOM::Range::isDetached
bool isDetached() const
not part of the DOM true if the range is detached
Definition: dom2_range.cpp:397
DOM::Range::cloneRange
Range cloneRange()
Produces a new range whose end-points are equal to the end-points of the range.
Definition: dom2_range.cpp:342
DOM::Range::CompareHow
CompareHow
Definition: dom2_range.h:281
DOM::RangeException::BAD_BOUNDARYPOINTS_ERR
Definition: dom2_range.h:61
DOM::Range::extractContents
DocumentFragment extractContents()
Moves the contents of a range from the containing document or document fragment to a new DocumentFrag...
Definition: dom2_range.cpp:300
DOM::Range::selectNode
void selectNode(const Node &refNode)
Select a node and its contents.
Definition: dom2_range.cpp:251
DOM::Range::setStartBefore
void setStartBefore(const Node &refNode)
Sets the start position to be before a node.
Definition: dom2_range.cpp:200
DOM::Range::cloneContents
DocumentFragment cloneContents()
Duplicates the contents of a range.
Definition: dom2_range.cpp:311
DOM::Range::Range
Range()
Definition: dom2_range.cpp:54
DOM::Node::isNull
bool isNull() const
tests if this Node is 0.
Definition: dom_node.h:920
DOM::DOMString
This class implements the basic string we use in the DOM.
Definition: dom_string.h:43
DOM::Range::boundaryPointsValid
bool boundaryPointsValid()
Definition: dom2_range.cpp:282
DOM::Document
The Document interface represents the entire HTML or XML document.
Definition: dom_doc.h:245
dom_exception.h
DOM::RangeException::_EXCEPTION_MAX
Definition: dom2_range.h:64
DOM::Range::startContainer
Node startContainer() const
Node within which the range begins.
Definition: dom2_range.cpp:113
DOM::Range::endOffset
long endOffset() const
Offset within the ending node of the range.
Definition: dom2_range.cpp:147
DOM::DOMException::WRONG_DOCUMENT_ERR
Definition: dom_exception.h:76
DOM::Range::impl
RangeImpl * impl
Definition: dom2_range.h:476
DOM::Range::detach
void detach()
Called to indicate that the range is no longer in use and that the implementation may relinquish any ...
Definition: dom2_range.cpp:387
DOM::Range::commonAncestorContainer
Node commonAncestorContainer()
Gets the common ancestor container of the range's two end-points.
Definition: dom2_range.cpp:169
DOM::Range::surroundContents
void surroundContents(const Node &newParent)
Reparents the contents of the range to the given node and inserts the node at the position of the sta...
Definition: dom2_range.cpp:332
DOM::Range::setStart
void setStart(const Node &refNode, long offset)
Sets the attributes describing the start of the range.
Definition: dom2_range.cpp:180
DOM::Range::setEnd
void setEnd(const Node &refNode, long offset)
Sets the attributes describing the end of a range.
Definition: dom2_range.cpp:190
DOM::Range::setStartAfter
void setStartAfter(const Node &refNode)
Sets the start position to be after a node.
Definition: dom2_range.cpp:211
DOM::Range::collapse
void collapse(bool toStart)
Collapse a range onto one of its end-points.
Definition: dom2_range.cpp:241
DOM::Range
Definition: dom2_range.h:79
DOM::Range::isNull
bool isNull() const
Definition: dom2_range.cpp:410
DOM::DOMException::INVALID_STATE_ERR
Definition: dom_exception.h:83
DOM::Range::RangeImpl
friend class RangeImpl
Definition: dom2_range.h:83
DOM::Range::deleteContents
void deleteContents()
Removes the contents of a range from the containing document or document fragment without returning a...
Definition: dom2_range.cpp:290
DOM::Node::handle
NodeImpl * handle() const
Definition: dom_node.h:925
DOM::Range::collapsed
bool collapsed() const
true if the range is collapsed
Definition: dom2_range.cpp:158
DOM::RangeException
Definition: dom2_range.h:47
DOM::Range::createContextualFragment
DocumentFragment createContextualFragment(const DOMString &html)
Definition: dom2_range.cpp:375
DOM::RangeException::code
unsigned short code
Definition: dom2_range.h:66
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal