OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "core/editing/EphemeralRange.h" | 5 #include "core/editing/EphemeralRange.h" |
6 | 6 |
7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
8 #include "core/dom/Element.h" | 8 #include "core/dom/Element.h" |
9 #include "core/dom/Range.h" | 9 #include "core/dom/Range.h" |
10 #include "core/dom/Text.h" | 10 #include "core/dom/Text.h" |
| 11 #include "core/layout/LayoutObject.h" |
| 12 #include "core/layout/LayoutText.h" |
11 | 13 |
12 namespace blink { | 14 namespace blink { |
13 | 15 |
14 namespace { | 16 namespace { |
15 template <typename Strategy> | 17 template <typename Strategy> |
16 Node* commonAncestorContainerNode(const Node* containerA, | 18 Node* commonAncestorContainerNode(const Node* containerA, |
17 const Node* containerB) { | 19 const Node* containerB) { |
18 if (!containerA || !containerB) | 20 if (!containerA || !containerB) |
19 return nullptr; | 21 return nullptr; |
20 return Strategy::commonAncestor(*containerA, *containerB); | 22 return Strategy::commonAncestor(*containerA, *containerB); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 114 } |
113 | 115 |
114 template <typename Strategy> | 116 template <typename Strategy> |
115 PositionTemplate<Strategy> EphemeralRangeTemplate<Strategy>::endPosition() | 117 PositionTemplate<Strategy> EphemeralRangeTemplate<Strategy>::endPosition() |
116 const { | 118 const { |
117 DCHECK(isValid()); | 119 DCHECK(isValid()); |
118 return m_endPosition; | 120 return m_endPosition; |
119 } | 121 } |
120 | 122 |
121 template <typename Strategy> | 123 template <typename Strategy> |
| 124 IntRect EphemeralRangeTemplate<Strategy>::boundingBox() const { |
| 125 IntRect result; |
| 126 Vector<IntRect> rects; |
| 127 textRects(rects); |
| 128 for (const IntRect& rect : rects) |
| 129 result.unite(rect); |
| 130 return result; |
| 131 } |
| 132 |
| 133 template <typename Strategy> |
| 134 void EphemeralRangeTemplate<Strategy>::textRects( |
| 135 Vector<IntRect>& rects, |
| 136 bool useSelectionHeight) const { |
| 137 Node* startContainer = m_startPosition.computeContainerNode(); |
| 138 DCHECK(startContainer); |
| 139 Node* endContainer = m_endPosition.computeContainerNode(); |
| 140 DCHECK(endContainer); |
| 141 |
| 142 for (Node& node : nodes()) { |
| 143 LayoutObject* layoutObject = node.layoutObject(); |
| 144 if (!layoutObject || !layoutObject->isText()) |
| 145 continue; |
| 146 LayoutText* layoutText = toLayoutText(layoutObject); |
| 147 unsigned startOffset = |
| 148 node == startContainer ? m_startPosition.offsetInContainerNode() : 0; |
| 149 unsigned endOffset = node == endContainer |
| 150 ? m_endPosition.offsetInContainerNode() |
| 151 : std::numeric_limits<unsigned>::max(); |
| 152 layoutText->absoluteRectsForRange(rects, startOffset, endOffset, |
| 153 useSelectionHeight); |
| 154 } |
| 155 } |
| 156 |
| 157 template <typename Strategy> |
122 Node* EphemeralRangeTemplate<Strategy>::commonAncestorContainer() const { | 158 Node* EphemeralRangeTemplate<Strategy>::commonAncestorContainer() const { |
123 return commonAncestorContainerNode<Strategy>( | 159 return commonAncestorContainerNode<Strategy>( |
124 m_startPosition.computeContainerNode(), | 160 m_startPosition.computeContainerNode(), |
125 m_endPosition.computeContainerNode()); | 161 m_endPosition.computeContainerNode()); |
126 } | 162 } |
127 | 163 |
128 template <typename Strategy> | 164 template <typename Strategy> |
129 bool EphemeralRangeTemplate<Strategy>::isCollapsed() const { | 165 bool EphemeralRangeTemplate<Strategy>::isCollapsed() const { |
130 DCHECK(isValid()); | 166 DCHECK(isValid()); |
131 return m_startPosition == m_endPosition; | 167 return m_startPosition == m_endPosition; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 return nullptr; | 200 return nullptr; |
165 return Range::create(range.document(), range.startPosition(), | 201 return Range::create(range.document(), range.startPosition(), |
166 range.endPosition()); | 202 range.endPosition()); |
167 } | 203 } |
168 | 204 |
169 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingStrategy>; | 205 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingStrategy>; |
170 template class CORE_TEMPLATE_EXPORT | 206 template class CORE_TEMPLATE_EXPORT |
171 EphemeralRangeTemplate<EditingInFlatTreeStrategy>; | 207 EphemeralRangeTemplate<EditingInFlatTreeStrategy>; |
172 | 208 |
173 } // namespace blink | 209 } // namespace blink |
OLD | NEW |