OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // abc| UPSTREAM |VisiblePosition| | 65 // abc| UPSTREAM |VisiblePosition| |
66 // |def DOWNSTREAM |VisiblePosition| | 66 // |def DOWNSTREAM |VisiblePosition| |
67 // | 67 // |
68 // NOTE: UPSTREAM affinity will be used only if pos is at end of a wrapped line, | 68 // NOTE: UPSTREAM affinity will be used only if pos is at end of a wrapped line, |
69 // otherwise it will be converted to DOWNSTREAM. | 69 // otherwise it will be converted to DOWNSTREAM. |
70 class CORE_EXPORT VisiblePosition final { | 70 class CORE_EXPORT VisiblePosition final { |
71 DISALLOW_ALLOCATION(); | 71 DISALLOW_ALLOCATION(); |
72 public: | 72 public: |
73 VisiblePosition() : m_affinity(VP_DEFAULT_AFFINITY) { } | 73 VisiblePosition() : m_affinity(VP_DEFAULT_AFFINITY) { } |
74 | 74 |
75 // TODO(yosin) We should use |createVisiblePosition()| instead of | |
76 // constructor, and make constructors to have private accessibility, since | |
77 // constructors aren't simple, e.g. they update layout tree. | |
78 explicit VisiblePosition(const Position&, TextAffinity = VP_DEFAULT_AFFINITY
); | |
79 | |
80 // Node: Other than |createVisiblePosition()|, we should not use | 75 // Node: Other than |createVisiblePosition()|, we should not use |
81 // |createWithoutCanonicalization()|. | 76 // |createWithoutCanonicalization()|. |
82 static VisiblePosition createWithoutCanonicalization(const PositionWithAffin
ity& canonicalized); | 77 static VisiblePosition createWithoutCanonicalization(const PositionWithAffin
ity& canonicalized); |
83 | 78 |
84 // Intentionally delete |operator==()| and |operator!=()| for reducing | 79 // Intentionally delete |operator==()| and |operator!=()| for reducing |
85 // compilation error message. | 80 // compilation error message. |
86 // TODO(yosin) We'll have |equals()| when we have use cases of checking | 81 // TODO(yosin) We'll have |equals()| when we have use cases of checking |
87 // equality of both position and affinity. | 82 // equality of both position and affinity. |
88 bool operator==(const VisiblePosition&) const = delete; | 83 bool operator==(const VisiblePosition&) const = delete; |
89 bool operator!=(const VisiblePosition&) const = delete; | 84 bool operator!=(const VisiblePosition&) const = delete; |
90 | 85 |
91 bool isNull() const { return m_deepPosition.isNull(); } | 86 bool isNull() const { return m_deepPosition.isNull(); } |
92 bool isNotNull() const { return m_deepPosition.isNotNull(); } | 87 bool isNotNull() const { return m_deepPosition.isNotNull(); } |
93 bool isOrphan() const { return m_deepPosition.isOrphan(); } | 88 bool isOrphan() const { return m_deepPosition.isOrphan(); } |
94 | 89 |
95 Position deepEquivalent() const { return m_deepPosition; } | 90 Position deepEquivalent() const { return m_deepPosition; } |
96 Position toParentAnchoredPosition() const { return deepEquivalent().parentAn
choredEquivalent(); } | 91 Position toParentAnchoredPosition() const { return deepEquivalent().parentAn
choredEquivalent(); } |
97 PositionWithAffinity toPositionWithAffinity() const { return PositionWithAff
inity(m_deepPosition, m_affinity); } | 92 PositionWithAffinity toPositionWithAffinity() const { return PositionWithAff
inity(m_deepPosition, m_affinity); } |
98 TextAffinity affinity() const { return m_affinity; } | 93 TextAffinity affinity() const { return m_affinity; } |
99 | 94 |
100 DECLARE_TRACE(); | 95 DECLARE_TRACE(); |
101 | 96 |
102 #ifndef NDEBUG | 97 #ifndef NDEBUG |
103 void debugPosition(const char* msg = "") const; | 98 void debugPosition(const char* msg = "") const; |
104 void formatForDebugger(char* buffer, unsigned length) const; | 99 void formatForDebugger(char* buffer, unsigned length) const; |
105 void showTreeForThis() const; | 100 void showTreeForThis() const; |
106 #endif | 101 #endif |
107 | 102 |
108 private: | 103 private: |
| 104 explicit VisiblePosition(const Position&, TextAffinity); |
| 105 |
109 // TODO(yosin) We should use |PositionWithAffinity| to make | 106 // TODO(yosin) We should use |PositionWithAffinity| to make |
110 // |toPositionWithAffinity()| simpler. | 107 // |toPositionWithAffinity()| simpler. |
111 Position m_deepPosition; | 108 Position m_deepPosition; |
112 TextAffinity m_affinity; | 109 TextAffinity m_affinity; |
113 }; | 110 }; |
114 | 111 |
115 // TODO(yosin) We should move |honorEditingBoundaryAtOr{Before,After} to | 112 // TODO(yosin) We should move |honorEditingBoundaryAtOr{Before,After} to |
116 // "VisibleUnits.cpp" as static function. | 113 // "VisibleUnits.cpp" as static function. |
117 // next() and previous() will increment/decrement by a character cluster. | 114 // next() and previous() will increment/decrement by a character cluster. |
118 VisiblePosition honorEditingBoundaryAtOrBefore(const VisiblePosition&, const Pos
ition& anchor); | 115 VisiblePosition honorEditingBoundaryAtOrBefore(const VisiblePosition&, const Pos
ition& anchor); |
119 PositionWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionWithAffinity
&, const Position& anchor); | 116 PositionWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionWithAffinity
&, const Position& anchor); |
120 PositionInComposedTreeWithAffinity honorEditingBoundaryAtOrBeforeOf(const Positi
onInComposedTreeWithAffinity&, const PositionInComposedTree& anchor); | 117 PositionInComposedTreeWithAffinity honorEditingBoundaryAtOrBeforeOf(const Positi
onInComposedTreeWithAffinity&, const PositionInComposedTree& anchor); |
121 VisiblePosition honorEditingBoundaryAtOrAfter(const VisiblePosition&, const Posi
tion& anchor); | 118 VisiblePosition honorEditingBoundaryAtOrAfter(const VisiblePosition&, const Posi
tion& anchor); |
122 | 119 |
123 CORE_EXPORT VisiblePosition createVisiblePosition(const Position&, TextAffinity
= VP_DEFAULT_AFFINITY); | 120 CORE_EXPORT VisiblePosition createVisiblePosition(const Position&, TextAffinity
= VP_DEFAULT_AFFINITY); |
124 CORE_EXPORT VisiblePosition createVisiblePosition(const PositionWithAffinity&); | 121 CORE_EXPORT VisiblePosition createVisiblePosition(const PositionWithAffinity&); |
125 CORE_EXPORT VisiblePosition createVisiblePosition(const PositionInComposedTree&,
TextAffinity = VP_DEFAULT_AFFINITY); | 122 CORE_EXPORT VisiblePosition createVisiblePosition(const PositionInComposedTree&,
TextAffinity = VP_DEFAULT_AFFINITY); |
126 | 123 |
127 } // namespace blink | 124 } // namespace blink |
128 | 125 |
129 #ifndef NDEBUG | 126 #ifndef NDEBUG |
130 // Outside the WebCore namespace for ease of invocation from gdb. | 127 // Outside the WebCore namespace for ease of invocation from gdb. |
131 void showTree(const blink::VisiblePosition*); | 128 void showTree(const blink::VisiblePosition*); |
132 void showTree(const blink::VisiblePosition&); | 129 void showTree(const blink::VisiblePosition&); |
133 #endif | 130 #endif |
134 | 131 |
135 #endif // VisiblePosition_h | 132 #endif // VisiblePosition_h |
OLD | NEW |