| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SelectionTemplate_h |
| 6 #define SelectionTemplate_h |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "core/CoreExport.h" |
| 10 #include "core/editing/EphemeralRange.h" |
| 11 #include "core/editing/Position.h" |
| 12 #include "core/editing/PositionWithAffinity.h" |
| 13 #include "core/editing/TextAffinity.h" |
| 14 #include "core/editing/TextGranularity.h" |
| 15 #include "wtf/Allocator.h" |
| 16 #include <iosfwd> |
| 17 |
| 18 namespace blink { |
| 19 |
| 20 // SelectionTemplate is used for representing a selection in DOM tree or Flat |
| 21 // tree with template parameter |Strategy|. Instances of |SelectionTemplate| |
| 22 // are immutable objects, you can't change them once constructed. |
| 23 // |
| 24 // To construct |SelectionTemplate| object, please use |Builder| class. |
| 25 template <typename Strategy> |
| 26 class CORE_EXPORT SelectionTemplate final { |
| 27 DISALLOW_NEW(); |
| 28 |
| 29 public: |
| 30 // |Builder| is a helper class for constructing |SelectionTemplate| object. |
| 31 class CORE_EXPORT Builder final { |
| 32 DISALLOW_NEW(); |
| 33 |
| 34 public: |
| 35 explicit Builder(const SelectionTemplate&); |
| 36 Builder(); |
| 37 |
| 38 SelectionTemplate build() const; |
| 39 |
| 40 // Move selection to |base|. |base| can't be null. |
| 41 Builder& collapse(const PositionTemplate<Strategy>& base); |
| 42 Builder& collapse(const PositionWithAffinityTemplate<Strategy>& base); |
| 43 |
| 44 // Extend selection to |extent|. It is error if selection is none. |
| 45 Builder& extend(const PositionTemplate<Strategy>& extent); |
| 46 |
| 47 Builder& setBaseAndExtent(const EphemeralRangeTemplate<Strategy>&); |
| 48 |
| 49 // |extent| can not be null if |base| isn't null. |
| 50 Builder& setBaseAndExtent(const PositionTemplate<Strategy>& base, |
| 51 const PositionTemplate<Strategy>& extent); |
| 52 |
| 53 // |extent| can be non-null while |base| is null, which is undesired. |
| 54 Builder& setBaseAndExtentDeprecated( |
| 55 const PositionTemplate<Strategy>& base, |
| 56 const PositionTemplate<Strategy>& extent); |
| 57 |
| 58 Builder& setAffinity(TextAffinity); |
| 59 Builder& setGranularity(TextGranularity); |
| 60 Builder& setHasTrailingWhitespace(bool); |
| 61 Builder& setIsDirectional(bool); |
| 62 |
| 63 private: |
| 64 SelectionTemplate m_selection; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 67 }; |
| 68 |
| 69 SelectionTemplate(const SelectionTemplate& other); |
| 70 SelectionTemplate(); |
| 71 |
| 72 SelectionTemplate& operator=(const SelectionTemplate&) = default; |
| 73 |
| 74 bool operator==(const SelectionTemplate&) const; |
| 75 bool operator!=(const SelectionTemplate&) const; |
| 76 |
| 77 const PositionTemplate<Strategy>& base() const; |
| 78 const PositionTemplate<Strategy>& extent() const; |
| 79 TextAffinity affinity() const { return m_affinity; } |
| 80 TextGranularity granularity() const { return m_granularity; } |
| 81 bool hasTrailingWhitespace() const { return m_hasTrailingWhitespace; } |
| 82 bool isDirectional() const { return m_isDirectional; } |
| 83 bool isNone() const { return m_base.isNull(); } |
| 84 |
| 85 void assertValid() const; |
| 86 void assertValidFor(const Document&) const; |
| 87 |
| 88 DEFINE_INLINE_TRACE() { |
| 89 visitor->trace(m_base); |
| 90 visitor->trace(m_extent); |
| 91 } |
| 92 |
| 93 void printTo(std::ostream*, const char* type) const; |
| 94 |
| 95 private: |
| 96 friend class SelectionEditor; |
| 97 |
| 98 Document* document() const; |
| 99 |
| 100 PositionTemplate<Strategy> m_base; |
| 101 PositionTemplate<Strategy> m_extent; |
| 102 TextAffinity m_affinity = TextAffinity::Downstream; |
| 103 TextGranularity m_granularity = CharacterGranularity; |
| 104 bool m_hasTrailingWhitespace = false; |
| 105 bool m_isDirectional = false; |
| 106 #if DCHECK_IS_ON() |
| 107 uint64_t m_domTreeVersion; |
| 108 #endif |
| 109 }; |
| 110 |
| 111 extern template class CORE_EXTERN_TEMPLATE_EXPORT |
| 112 SelectionTemplate<EditingStrategy>; |
| 113 extern template class CORE_EXTERN_TEMPLATE_EXPORT |
| 114 SelectionTemplate<EditingInFlatTreeStrategy>; |
| 115 |
| 116 using SelectionInDOMTree = SelectionTemplate<EditingStrategy>; |
| 117 using SelectionInFlatTree = SelectionTemplate<EditingInFlatTreeStrategy>; |
| 118 |
| 119 CORE_EXPORT std::ostream& operator<<(std::ostream&, const SelectionInDOMTree&); |
| 120 CORE_EXPORT std::ostream& operator<<(std::ostream&, const SelectionInFlatTree&); |
| 121 |
| 122 } // namespace blink |
| 123 |
| 124 #endif // SelectionTemplate_h |
| OLD | NEW |