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

KHTML

  • 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 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jun 1 2013 20:22:25 by doxygen 1.8.3.1 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-4.10.4 API Reference

Skip menu "kdelibs-4.10.4 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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