KHtml

dom_positioniterator.cpp
1 /*
2  * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "dom_positioniterator.h"
27 
28 #include "dom_nodeimpl.h"
29 
30 namespace DOM
31 {
32 
33 Position PositionIterator::peekPrevious() const
34 {
35  Position pos = m_current;
36 
37  if (pos.isEmpty()) {
38  return pos;
39  }
40 
41  if (pos.offset() <= 0) {
42  NodeImpl *prevNode = pos.node()->previousLeafNode();
43  if (prevNode) {
44  pos = Position(prevNode, prevNode->maxOffset());
45  }
46  } else {
47  pos = Position(pos.node(), pos.offset() - 1);
48  }
49 
50  return pos;
51 }
52 
53 Position PositionIterator::peekNext() const
54 {
55  Position pos = m_current;
56 
57  if (pos.isEmpty()) {
58  return pos;
59  }
60 
61  if (pos.offset() >= pos.node()->maxOffset()) {
62  NodeImpl *nextNode = pos.node()->nextLeafNode();
63  if (nextNode) {
64  pos = Position(nextNode, 0);
65  }
66  } else {
67  pos = Position(pos.node(), pos.offset() + 1);
68  }
69 
70  return pos;
71 }
72 
73 bool PositionIterator::atStart() const
74 {
75  if (m_current.isEmpty()) {
76  return true;
77  }
78 
79  return m_current.offset() == 0 &&
80  m_current.node()->previousLeafNode() == nullptr;
81 }
82 
83 bool PositionIterator::atEnd() const
84 {
85  if (m_current.isEmpty()) {
86  return true;
87  }
88 
89  return m_current.offset() == m_current.node()->maxOffset() &&
90  m_current.node()->nextLeafNode() == nullptr;
91 }
92 
93 } // namespace DOM
This library provides a full-featured HTML parser and widget.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:47:53 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.