| 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 SelectionType computeSelectionTypeConsideringGranularity() const; |
| 105 |
| 99 DECLARE_TRACE(); | 106 DECLARE_TRACE(); |
| 100 | 107 |
| 101 void printTo(std::ostream*, const char* type) const; | 108 void printTo(std::ostream*, const char* type) const; |
| 102 #ifndef NDEBUG | 109 #ifndef NDEBUG |
| 103 void showTreeForThis() const; | 110 void showTreeForThis() const; |
| 104 #endif | 111 #endif |
| 105 | 112 |
| 106 private: | 113 private: |
| 107 friend class SelectionEditor; | 114 friend class SelectionEditor; |
| 108 | 115 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 127 | 134 |
| 128 using SelectionInDOMTree = SelectionTemplate<EditingStrategy>; | 135 using SelectionInDOMTree = SelectionTemplate<EditingStrategy>; |
| 129 using SelectionInFlatTree = SelectionTemplate<EditingInFlatTreeStrategy>; | 136 using SelectionInFlatTree = SelectionTemplate<EditingInFlatTreeStrategy>; |
| 130 | 137 |
| 131 CORE_EXPORT std::ostream& operator<<(std::ostream&, const SelectionInDOMTree&); | 138 CORE_EXPORT std::ostream& operator<<(std::ostream&, const SelectionInDOMTree&); |
| 132 CORE_EXPORT std::ostream& operator<<(std::ostream&, const SelectionInFlatTree&); | 139 CORE_EXPORT std::ostream& operator<<(std::ostream&, const SelectionInFlatTree&); |
| 133 | 140 |
| 134 } // namespace blink | 141 } // namespace blink |
| 135 | 142 |
| 136 #endif // SelectionTemplate_h | 143 #endif // SelectionTemplate_h |
| OLD | NEW |