Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / editing / VisibleUnits.h
blob5f2486b24fa7c61424cba7360f31edf5be4eec45
1 /*
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
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.
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 VisibleUnits_h
27 #define VisibleUnits_h
29 #include "core/CoreExport.h"
30 #include "core/editing/EditingBoundary.h"
31 #include "core/editing/PositionWithAffinity.h"
32 #include "core/editing/VisiblePosition.h"
33 #include "platform/text/TextDirection.h"
35 namespace blink {
37 class LayoutRect;
38 class LayoutUnit;
39 class LayoutObject;
40 class Node;
41 class IntPoint;
42 class InlineBox;
43 class LocalFrame;
45 enum EWordSide { RightWordIfOnBoundary = false, LeftWordIfOnBoundary = true };
47 struct InlineBoxPosition {
48 InlineBox* inlineBox;
49 int offsetInBox;
51 InlineBoxPosition()
52 : inlineBox(nullptr), offsetInBox(0)
56 InlineBoxPosition(InlineBox* inlineBox, int offsetInBox)
57 : inlineBox(inlineBox), offsetInBox(offsetInBox)
61 bool operator==(const InlineBoxPosition& other) const
63 return inlineBox == other.inlineBox && offsetInBox == other.offsetInBox;
66 bool operator!=(const InlineBoxPosition& other) const
68 return !operator==(other);
72 // The print for |InlineBoxPosition| is available only for testing
73 // in "webkit_unit_tests", and implemented in
74 // "core/editing/VisibleUnitsTest.cpp".
75 std::ostream& operator<<(std::ostream&, const InlineBoxPosition&);
77 // Position
78 // mostForward/BackwardCaretPosition are used for moving back and forth between
79 // visually equivalent candidates.
80 // For example, for the text node "foo bar" where whitespace is
81 // collapsible, there are two candidates that map to the VisiblePosition
82 // between 'b' and the space, after first space and before last space.
84 // mostBackwardCaretPosition returns the left candidate and also returs
85 // [boundary, 0] for any of the positions from [boundary, 0] to the first
86 // candidate in boundary, where
87 // endsOfNodeAreVisuallyDistinctPositions(boundary) is true.
89 // mostForwardCaretPosition() returns the right one and also returns the
90 // last position in the last atomic node in boundary for all of the positions
91 // in boundary after the last candidate, where
92 // endsOfNodeAreVisuallyDistinctPositions(boundary).
93 // FIXME: This function should never be called when the line box tree is dirty.
94 // See https://bugs.webkit.org/show_bug.cgi?id=97264
95 CORE_EXPORT Position mostBackwardCaretPosition(const Position&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
96 CORE_EXPORT PositionInComposedTree mostBackwardCaretPosition(const PositionInComposedTree&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
97 CORE_EXPORT Position mostForwardCaretPosition(const Position&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
98 CORE_EXPORT PositionInComposedTree mostForwardCaretPosition(const PositionInComposedTree&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
100 CORE_EXPORT bool isVisuallyEquivalentCandidate(const Position&);
101 CORE_EXPORT bool isVisuallyEquivalentCandidate(const PositionInComposedTree&);
103 CORE_EXPORT Position canonicalPositionOf(const Position&);
104 CORE_EXPORT PositionInComposedTree canonicalPositionOf(const PositionInComposedTree&);
106 // Bounds of (possibly transformed) caret in absolute coords
107 CORE_EXPORT IntRect absoluteCaretBoundsOf(const VisiblePosition&);
108 CORE_EXPORT IntRect absoluteCaretBoundsOf(const VisiblePositionInComposedTree&);
110 CORE_EXPORT UChar32 characterAfter(const VisiblePosition&);
111 CORE_EXPORT UChar32 characterAfter(const VisiblePositionInComposedTree&);
112 CORE_EXPORT UChar32 characterBefore(const VisiblePosition&);
113 CORE_EXPORT UChar32 characterBefore(const VisiblePositionInComposedTree&);
115 // TODO(yosin) Since return value of |leftPositionOf()| with |VisiblePosition|
116 // isn't defined well on composed tree, we should not use it for a position in
117 // composed tree.
118 CORE_EXPORT VisiblePosition leftPositionOf(const VisiblePosition&);
119 CORE_EXPORT VisiblePositionInComposedTree leftPositionOf(const VisiblePositionInComposedTree&);
120 // TODO(yosin) Since return value of |rightPositionOf()| with |VisiblePosition|
121 // isn't defined well on composed tree, we should not use it for a position in
122 // composed tree.
123 CORE_EXPORT VisiblePosition rightPositionOf(const VisiblePosition&);
124 CORE_EXPORT VisiblePositionInComposedTree rightPositionOf(const VisiblePositionInComposedTree&);
126 CORE_EXPORT VisiblePosition nextPositionOf(const VisiblePosition&, EditingBoundaryCrossingRule = CanCrossEditingBoundary);
127 CORE_EXPORT VisiblePositionInComposedTree nextPositionOf(const VisiblePositionInComposedTree&, EditingBoundaryCrossingRule = CanCrossEditingBoundary);
128 CORE_EXPORT VisiblePosition previousPositionOf(const VisiblePosition&, EditingBoundaryCrossingRule = CanCrossEditingBoundary);
129 CORE_EXPORT VisiblePositionInComposedTree previousPositionOf(const VisiblePositionInComposedTree&, EditingBoundaryCrossingRule = CanCrossEditingBoundary);
131 // words
132 CORE_EXPORT VisiblePosition startOfWord(const VisiblePosition&, EWordSide = RightWordIfOnBoundary);
133 CORE_EXPORT VisiblePositionInComposedTree startOfWord(const VisiblePositionInComposedTree&, EWordSide = RightWordIfOnBoundary);
134 CORE_EXPORT VisiblePosition endOfWord(const VisiblePosition&, EWordSide = RightWordIfOnBoundary);
135 CORE_EXPORT VisiblePositionInComposedTree endOfWord(const VisiblePositionInComposedTree&, EWordSide = RightWordIfOnBoundary);
136 VisiblePosition previousWordPosition(const VisiblePosition&);
137 VisiblePosition nextWordPosition(const VisiblePosition&);
138 VisiblePosition rightWordPosition(const VisiblePosition&, bool skipsSpaceWhenMovingRight);
139 VisiblePosition leftWordPosition(const VisiblePosition&, bool skipsSpaceWhenMovingRight);
141 // sentences
142 CORE_EXPORT VisiblePosition startOfSentence(const VisiblePosition&);
143 CORE_EXPORT VisiblePositionInComposedTree startOfSentence(const VisiblePositionInComposedTree&);
144 CORE_EXPORT VisiblePosition endOfSentence(const VisiblePosition&);
145 CORE_EXPORT VisiblePositionInComposedTree endOfSentence(const VisiblePositionInComposedTree&);
146 VisiblePosition previousSentencePosition(const VisiblePosition&);
147 VisiblePosition nextSentencePosition(const VisiblePosition&);
149 // lines
150 // TODO(yosin) Return values of |VisiblePosition| version of |startOfLine()|
151 // with shadow tree isn't defined well. We should not use it for shadow tree.
152 CORE_EXPORT VisiblePosition startOfLine(const VisiblePosition&);
153 CORE_EXPORT VisiblePositionInComposedTree startOfLine(const VisiblePositionInComposedTree&);
154 // TODO(yosin) Return values of |VisiblePosition| version of |endOfLine()| with
155 // shadow tree isn't defined well. We should not use it for shadow tree.
156 CORE_EXPORT VisiblePosition endOfLine(const VisiblePosition&);
157 CORE_EXPORT VisiblePositionInComposedTree endOfLine(const VisiblePositionInComposedTree&);
158 CORE_EXPORT VisiblePosition previousLinePosition(const VisiblePosition&, LayoutUnit lineDirectionPoint, EditableType = ContentIsEditable);
159 CORE_EXPORT VisiblePosition nextLinePosition(const VisiblePosition&, LayoutUnit lineDirectionPoint, EditableType = ContentIsEditable);
160 CORE_EXPORT bool inSameLine(const VisiblePosition&, const VisiblePosition&);
161 CORE_EXPORT bool inSameLine(const VisiblePositionInComposedTree&, const VisiblePositionInComposedTree&);
162 CORE_EXPORT bool inSameLine(const PositionWithAffinity&, const PositionWithAffinity&);
163 CORE_EXPORT bool inSameLine(const PositionInComposedTreeWithAffinity&, const PositionInComposedTreeWithAffinity&);
164 CORE_EXPORT bool isStartOfLine(const VisiblePosition&);
165 CORE_EXPORT bool isStartOfLine(const VisiblePositionInComposedTree&);
166 CORE_EXPORT bool isEndOfLine(const VisiblePosition&);
167 CORE_EXPORT bool isEndOfLine(const VisiblePositionInComposedTree&);
168 // TODO(yosin) Return values of |VisiblePosition| version of
169 // |logicalStartOfLine()| with shadow tree isn't defined well. We should not use
170 // it for shadow tree.
171 CORE_EXPORT VisiblePosition logicalStartOfLine(const VisiblePosition&);
172 CORE_EXPORT VisiblePositionInComposedTree logicalStartOfLine(const VisiblePositionInComposedTree&);
173 // TODO(yosin) Return values of |VisiblePosition| version of
174 // |logicalEndOfLine()| with shadow tree isn't defined well. We should not use
175 // it for shadow tree.
176 CORE_EXPORT VisiblePosition logicalEndOfLine(const VisiblePosition&);
177 CORE_EXPORT VisiblePositionInComposedTree logicalEndOfLine(const VisiblePositionInComposedTree&);
178 CORE_EXPORT bool isLogicalEndOfLine(const VisiblePosition&);
179 CORE_EXPORT bool isLogicalEndOfLine(const VisiblePositionInComposedTree&);
180 VisiblePosition leftBoundaryOfLine(const VisiblePosition&, TextDirection);
181 VisiblePosition rightBoundaryOfLine(const VisiblePosition&, TextDirection);
183 // paragraphs (perhaps a misnomer, can be divided by line break elements)
184 // TODO(yosin) Since return value of |startOfParagraph()| with |VisiblePosition|
185 // isn't defined well on composed tree, we should not use it for a position in
186 // composed tree.
187 CORE_EXPORT VisiblePosition startOfParagraph(const VisiblePosition&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
188 CORE_EXPORT VisiblePositionInComposedTree startOfParagraph(const VisiblePositionInComposedTree&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
189 CORE_EXPORT VisiblePosition endOfParagraph(const VisiblePosition&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
190 CORE_EXPORT VisiblePositionInComposedTree endOfParagraph(const VisiblePositionInComposedTree&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
191 VisiblePosition startOfNextParagraph(const VisiblePosition&);
192 VisiblePosition previousParagraphPosition(const VisiblePosition&, LayoutUnit x);
193 VisiblePosition nextParagraphPosition(const VisiblePosition&, LayoutUnit x);
194 CORE_EXPORT bool isStartOfParagraph(const VisiblePosition&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
195 CORE_EXPORT bool isStartOfParagraph(const VisiblePositionInComposedTree&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
196 CORE_EXPORT bool isEndOfParagraph(const VisiblePosition&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
197 CORE_EXPORT bool isEndOfParagraph(const VisiblePositionInComposedTree&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
198 bool inSameParagraph(const VisiblePosition&, const VisiblePosition&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
200 // blocks (true paragraphs; line break elements don't break blocks)
201 VisiblePosition startOfBlock(const VisiblePosition&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
202 VisiblePosition endOfBlock(const VisiblePosition&, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
203 bool inSameBlock(const VisiblePosition&, const VisiblePosition&);
204 bool isStartOfBlock(const VisiblePosition&);
205 bool isEndOfBlock(const VisiblePosition&);
207 // document
208 CORE_EXPORT VisiblePosition startOfDocument(const VisiblePosition&);
209 CORE_EXPORT VisiblePositionInComposedTree startOfDocument(const VisiblePositionInComposedTree&);
210 CORE_EXPORT VisiblePosition endOfDocument(const VisiblePosition&);
211 CORE_EXPORT VisiblePositionInComposedTree endOfDocument(const VisiblePositionInComposedTree&);
212 bool isStartOfDocument(const VisiblePosition&);
213 bool isEndOfDocument(const VisiblePosition&);
215 // editable content
216 VisiblePosition startOfEditableContent(const VisiblePosition&);
217 VisiblePosition endOfEditableContent(const VisiblePosition&);
218 CORE_EXPORT bool isEndOfEditableOrNonEditableContent(const VisiblePosition&);
219 CORE_EXPORT bool isEndOfEditableOrNonEditableContent(const VisiblePositionInComposedTree&);
221 CORE_EXPORT InlineBoxPosition computeInlineBoxPosition(const Position&, TextAffinity);
222 CORE_EXPORT InlineBoxPosition computeInlineBoxPosition(const Position&, TextAffinity, TextDirection primaryDirection);
223 CORE_EXPORT InlineBoxPosition computeInlineBoxPosition(const PositionInComposedTree&, TextAffinity);
224 CORE_EXPORT InlineBoxPosition computeInlineBoxPosition(const PositionInComposedTree&, TextAffinity, TextDirection primaryDirection);
225 CORE_EXPORT InlineBoxPosition computeInlineBoxPosition(const VisiblePosition&);
226 CORE_EXPORT InlineBoxPosition computeInlineBoxPosition(const VisiblePositionInComposedTree&);
228 // Rect is local to the returned layoutObject
229 CORE_EXPORT LayoutRect localCaretRectOfPosition(const PositionWithAffinity&, LayoutObject*&);
230 CORE_EXPORT LayoutRect localCaretRectOfPosition(const PositionInComposedTreeWithAffinity&, LayoutObject*&);
231 bool hasRenderedNonAnonymousDescendantsWithHeight(LayoutObject*);
233 // Returns a hit-tested VisiblePosition for the given point in contents-space
234 // coordinates.
235 CORE_EXPORT VisiblePosition visiblePositionForContentsPoint(const IntPoint&, LocalFrame*);
237 CORE_EXPORT bool rendersInDifferentPosition(const Position&, const Position&);
239 } // namespace blink
241 #endif // VisibleUnits_h