Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: Source/core/editing/Position.h

Issue 1305963003: Introduce {next,previous}PositionOf() as replacement of {next,previous}() member functions in Positi (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-22T00:12:04 Rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/editing/Editor.cpp ('k') | Source/core/editing/Position.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 27 matching lines...) Expand all
38 38
39 namespace blink { 39 namespace blink {
40 40
41 class Element; 41 class Element;
42 class Node; 42 class Node;
43 class LayoutObject; 43 class LayoutObject;
44 class Text; 44 class Text;
45 enum class TextAffinity; 45 enum class TextAffinity;
46 class TreeScope; 46 class TreeScope;
47 47
48 enum PositionMoveType { 48 enum class PositionMoveType {
49 CodePoint, // Move by a single code point. 49 CodePoint, // Move by a single code point.
50 Character, // Move to the next Unicode character break. 50 Character, // Move to the next Unicode character break.
51 BackwardDeletion // Subject to platform conventions. 51 BackwardDeletion // Subject to platform conventions.
52 }; 52 };
53 53
54 enum class PositionAnchorType : unsigned { 54 enum class PositionAnchorType : unsigned {
55 OffsetInAnchor, 55 OffsetInAnchor,
56 BeforeAnchor, 56 BeforeAnchor,
57 AfterAnchor, 57 AfterAnchor,
58 BeforeChildren, 58 BeforeChildren,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 142
143 Node* anchorNode() const { return m_anchorNode.get(); } 143 Node* anchorNode() const { return m_anchorNode.get(); }
144 144
145 Document* document() const { return m_anchorNode ? &m_anchorNode->document() : 0; } 145 Document* document() const { return m_anchorNode ? &m_anchorNode->document() : 0; }
146 bool inDocument() const { return m_anchorNode && m_anchorNode->inDocument(); } 146 bool inDocument() const { return m_anchorNode && m_anchorNode->inDocument(); }
147 147
148 bool isNull() const { return !m_anchorNode; } 148 bool isNull() const { return !m_anchorNode; }
149 bool isNotNull() const { return m_anchorNode; } 149 bool isNotNull() const { return m_anchorNode; }
150 bool isOrphan() const { return m_anchorNode && !m_anchorNode->inDocument(); } 150 bool isOrphan() const { return m_anchorNode && !m_anchorNode->inDocument(); }
151 151
152 // Move up or down the DOM by one position.
153 // Offsets are computed using layout text for nodes that have layoutObjects - but note that even when
154 // using composed characters, the result may be inside a single user-visible character if a ligature is formed.
155 PositionAlgorithm<Strategy> previous(PositionMoveType = CodePoint) const;
156 PositionAlgorithm<Strategy> next(PositionMoveType = CodePoint) const;
157
158 int compareTo(const PositionAlgorithm<Strategy>&) const; 152 int compareTo(const PositionAlgorithm<Strategy>&) const;
159 153
160 // These can be either inside or just before/after the node, depending on 154 // These can be either inside or just before/after the node, depending on
161 // if the node is ignored by editing or not. 155 // if the node is ignored by editing or not.
162 // FIXME: These should go away. They only make sense for legacy positions. 156 // FIXME: These should go away. They only make sense for legacy positions.
163 bool atFirstEditingPositionForNode() const; 157 bool atFirstEditingPositionForNode() const;
164 bool atLastEditingPositionForNode() const; 158 bool atLastEditingPositionForNode() const;
165 159
166 bool atStartOfTree() const; 160 bool atStartOfTree() const;
167 bool atEndOfTree() const; 161 bool atEndOfTree() const;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 { 394 {
401 return position; 395 return position;
402 } 396 }
403 397
404 template <> 398 template <>
405 inline PositionInComposedTree fromPositionInDOMTree<EditingInComposedTreeStrateg y>(const Position& position) 399 inline PositionInComposedTree fromPositionInDOMTree<EditingInComposedTreeStrateg y>(const Position& position)
406 { 400 {
407 return toPositionInComposedTree(position); 401 return toPositionInComposedTree(position);
408 } 402 }
409 403
404 // TODO(yosin) We should move |previousPositionOf()| and |nextPositionOf()|
405 // to "EditingUtilities.h" with |uncheckedPreviousOffset()| and
406 // |uncheckedNextOffset()|.
407 // Move up or down the DOM by one position.
408 // Offsets are computed using layout text for nodes that have layoutObjects -
409 // but note that even when using composed characters, the result may be inside
410 // a single user-visible character if a ligature is formed.
411 CORE_EXPORT Position previousPositionOf(const Position&, PositionMoveType);
412 CORE_EXPORT Position nextPositionOf(const Position&, PositionMoveType);
413 CORE_EXPORT PositionInComposedTree previousPositionOf(const PositionInComposedTr ee&, PositionMoveType);
414 CORE_EXPORT PositionInComposedTree nextPositionOf(const PositionInComposedTree&, PositionMoveType);
415
410 CORE_EXPORT int uncheckedPreviousOffset(const Node*, int current); 416 CORE_EXPORT int uncheckedPreviousOffset(const Node*, int current);
411 CORE_EXPORT int uncheckedNextOffset(const Node*, int current); 417 CORE_EXPORT int uncheckedNextOffset(const Node*, int current);
412 418
413 } // namespace blink 419 } // namespace blink
414 420
415 #ifndef NDEBUG 421 #ifndef NDEBUG
416 // Outside the WebCore namespace for ease of invocation from gdb. 422 // Outside the WebCore namespace for ease of invocation from gdb.
417 void showTree(const blink::Position&); 423 void showTree(const blink::Position&);
418 void showTree(const blink::Position*); 424 void showTree(const blink::Position*);
419 #endif 425 #endif
420 426
421 #endif // Position_h 427 #endif // Position_h
OLDNEW
« no previous file with comments | « Source/core/editing/Editor.cpp ('k') | Source/core/editing/Position.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698