OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SelectionTemplate_h | 5 #ifndef SelectionTemplate_h |
6 #define SelectionTemplate_h | 6 #define SelectionTemplate_h |
7 | 7 |
| 8 #include <iosfwd> |
8 #include "base/macros.h" | 9 #include "base/macros.h" |
9 #include "core/CoreExport.h" | 10 #include "core/CoreExport.h" |
10 #include "core/editing/EphemeralRange.h" | 11 #include "core/editing/EphemeralRange.h" |
11 #include "core/editing/Position.h" | 12 #include "core/editing/Position.h" |
12 #include "core/editing/PositionWithAffinity.h" | 13 #include "core/editing/PositionWithAffinity.h" |
| 14 #include "core/editing/SelectionType.h" |
13 #include "core/editing/TextAffinity.h" | 15 #include "core/editing/TextAffinity.h" |
14 #include "core/editing/TextGranularity.h" | 16 #include "core/editing/TextGranularity.h" |
15 #include "wtf/Allocator.h" | 17 #include "wtf/Allocator.h" |
16 #include <iosfwd> | |
17 | 18 |
18 namespace blink { | 19 namespace blink { |
19 | 20 |
20 // SelectionTemplate is used for representing a selection in DOM tree or Flat | 21 // SelectionTemplate is used for representing a selection in DOM tree or Flat |
21 // tree with template parameter |Strategy|. Instances of |SelectionTemplate| | 22 // tree with template parameter |Strategy|. Instances of |SelectionTemplate| |
22 // are immutable objects, you can't change them once constructed. | 23 // are immutable objects, you can't change them once constructed. |
23 // | 24 // |
24 // To construct |SelectionTemplate| object, please use |Builder| class. | 25 // To construct |SelectionTemplate| object, please use |Builder| class. |
25 template <typename Strategy> | 26 template <typename Strategy> |
26 class CORE_EXPORT SelectionTemplate final { | 27 class CORE_EXPORT SelectionTemplate final { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 SelectionTemplate& operator=(const SelectionTemplate&) = default; | 81 SelectionTemplate& operator=(const SelectionTemplate&) = default; |
81 | 82 |
82 bool operator==(const SelectionTemplate&) const; | 83 bool operator==(const SelectionTemplate&) const; |
83 bool operator!=(const SelectionTemplate&) const; | 84 bool operator!=(const SelectionTemplate&) const; |
84 | 85 |
85 const PositionTemplate<Strategy>& base() const; | 86 const PositionTemplate<Strategy>& base() const; |
86 const PositionTemplate<Strategy>& extent() const; | 87 const PositionTemplate<Strategy>& extent() const; |
87 TextAffinity affinity() const { return m_affinity; } | 88 TextAffinity affinity() const { return m_affinity; } |
88 TextGranularity granularity() const { return m_granularity; } | 89 TextGranularity granularity() const { return m_granularity; } |
89 bool hasTrailingWhitespace() const { return m_hasTrailingWhitespace; } | 90 bool hasTrailingWhitespace() const { return m_hasTrailingWhitespace; } |
| 91 bool isCaret() const { return m_base.isNotNull() && m_base == m_extent; } |
90 bool isDirectional() const { return m_isDirectional; } | 92 bool isDirectional() const { return m_isDirectional; } |
91 bool isHandleVisible() const { return m_isHandleVisible; } | 93 bool isHandleVisible() const { return m_isHandleVisible; } |
92 bool isNone() const { return m_base.isNull(); } | 94 bool isNone() const { return m_base.isNull(); } |
| 95 bool isRange() const { return m_base != m_extent; } |
93 | 96 |
94 // Returns true if |this| selection holds valid values otherwise it causes | 97 // Returns true if |this| selection holds valid values otherwise it causes |
95 // assertion failure. | 98 // assertion failure. |
96 bool assertValid() const; | 99 bool assertValid() const; |
97 bool assertValidFor(const Document&) const; | 100 bool assertValidFor(const Document&) const; |
98 | 101 |
| 102 const PositionTemplate<Strategy>& computeEndPosition() const; |
| 103 const PositionTemplate<Strategy>& computeStartPosition() const; |
| 104 |
| 105 // Returns |SelectionType| for |this| based on |m_base| and |m_extent| |
| 106 // If |m_granularity| is |CharacterGranularity|, otherwise this function |
| 107 // returns |RangeSelection| event if |m_base| == |m_extent|. |
| 108 // Note: |m_granularity| will be removed, using this function is not |
| 109 // encouraged. |
| 110 SelectionType selectionTypeWithLegacyGranularity() const; |
| 111 |
99 DECLARE_TRACE(); | 112 DECLARE_TRACE(); |
100 | 113 |
101 void printTo(std::ostream*, const char* type) const; | 114 void printTo(std::ostream*, const char* type) const; |
102 #ifndef NDEBUG | 115 #ifndef NDEBUG |
103 void showTreeForThis() const; | 116 void showTreeForThis() const; |
104 #endif | 117 #endif |
105 | 118 |
106 private: | 119 private: |
107 friend class SelectionEditor; | 120 friend class SelectionEditor; |
108 | 121 |
(...skipping 18 matching lines...) Expand all Loading... |
127 | 140 |
128 using SelectionInDOMTree = SelectionTemplate<EditingStrategy>; | 141 using SelectionInDOMTree = SelectionTemplate<EditingStrategy>; |
129 using SelectionInFlatTree = SelectionTemplate<EditingInFlatTreeStrategy>; | 142 using SelectionInFlatTree = SelectionTemplate<EditingInFlatTreeStrategy>; |
130 | 143 |
131 CORE_EXPORT std::ostream& operator<<(std::ostream&, const SelectionInDOMTree&); | 144 CORE_EXPORT std::ostream& operator<<(std::ostream&, const SelectionInDOMTree&); |
132 CORE_EXPORT std::ostream& operator<<(std::ostream&, const SelectionInFlatTree&); | 145 CORE_EXPORT std::ostream& operator<<(std::ostream&, const SelectionInFlatTree&); |
133 | 146 |
134 } // namespace blink | 147 } // namespace blink |
135 | 148 |
136 #endif // SelectionTemplate_h | 149 #endif // SelectionTemplate_h |
OLD | NEW |