2 * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef __dom_position_h__
27 #define __dom_position_h__
29 #include "text_affinity.h"
33 class CSSComputedStyleDeclarationImpl;
39 enum EStayInBlock { DoNotStayInBlock = false, StayInBlock = true };
40 enum EUsingComposedCharacters { NotUsingComposedCharacters = false, UsingComposedCharacters = true };
45 Position() : m_node(0), m_offset(0) { }
46 Position(NodeImpl *node, long offset);
47 Position(const Position &);
50 Position &operator=(const Position &o);
54 NodeImpl *node() const { return m_node; }
55 long offset() const { return m_offset; }
57 bool isNull() const { return m_node == 0; }
58 bool isNotNull() const { return m_node != 0; }
60 ElementImpl *element() const;
61 CSSComputedStyleDeclarationImpl *computedStyle() const;
63 // Move up or down the DOM by one position
64 Position previous(EUsingComposedCharacters usingComposedCharacters=NotUsingComposedCharacters) const;
65 Position next(EUsingComposedCharacters usingComposedCharacters=NotUsingComposedCharacters) const;
69 // FIXME: Make these non-member functions and put them somewhere in the editing directory.
70 // These aren't really basic "position" operations. More high level editing helper functions.
71 Position leadingWhitespacePosition(khtml::EAffinity affinity, bool considerNonCollapsibleWhitespace = false) const;
72 Position trailingWhitespacePosition(khtml::EAffinity affinity, bool considerNonCollapsibleWhitespace = false) const;
74 // These functions only consider leaf nodes, and if stayInBlock is true, blocks.
75 // Hence, the results from these functions are idiosyncratic, and until you
76 // become familiar with the results, you may find using these functions confusing.
77 // I have hopes to make the results of these functions less ambiguous in the near
78 // future, and have them consider all nodes, and have the Positions that are
79 // returned follow a simple rule: The upstream position is the position
80 // earliest in document order that will make the insertion point render in the
81 // same position as the caller's position. The same goes for downstream position
82 // except that it is the latest position for earliest position in the above
84 Position upstream(EStayInBlock stayInBlock) const;
85 Position downstream(EStayInBlock stayInBlock) const;
87 Position equivalentRangeCompliantPosition() const;
88 Position equivalentDeepPosition() const;
89 bool inRenderedContent() const;
90 bool isRenderedCharacter() const;
91 bool rendersInDifferentPosition(const Position &pos) const;
93 void debugPosition(const char *msg="") const;
96 void formatForDebugger(char *buffer, unsigned length) const;
100 long renderedOffset() const;
102 bool inRenderedText() const;
104 Position previousCharacterPosition(khtml::EAffinity affinity) const;
105 Position nextCharacterPosition(khtml::EAffinity affinity) const;
111 inline bool operator==(const Position &a, const Position &b)
113 return a.node() == b.node() && a.offset() == b.offset();
116 inline bool operator!=(const Position &a, const Position &b)
121 Position startPosition(const Range &);
122 Position startPosition(const RangeImpl *);
123 Position endPosition(const Range &);
124 Position endPosition(const RangeImpl *);
128 #endif // __dom_position_h__