Chromium Code Reviews| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 } | 141 } |
| 140 | 142 |
| 141 template <typename Strategy> | 143 template <typename Strategy> |
| 142 EphemeralRangeTemplate<Strategy> | 144 EphemeralRangeTemplate<Strategy> |
| 143 EphemeralRangeTemplate<Strategy>::rangeOfContents(const Node& node) { | 145 EphemeralRangeTemplate<Strategy>::rangeOfContents(const Node& node) { |
| 144 return EphemeralRangeTemplate<Strategy>( | 146 return EphemeralRangeTemplate<Strategy>( |
| 145 PositionTemplate<Strategy>::firstPositionInNode(&const_cast<Node&>(node)), | 147 PositionTemplate<Strategy>::firstPositionInNode(&const_cast<Node&>(node)), |
| 146 PositionTemplate<Strategy>::lastPositionInNode(&const_cast<Node&>(node))); | 148 PositionTemplate<Strategy>::lastPositionInNode(&const_cast<Node&>(node))); |
| 147 } | 149 } |
| 148 | 150 |
| 151 template <typename Strategy> | |
| 152 void EphemeralRangeTemplate<Strategy>::textQuads( | |
|
Xiaocheng
2017/03/24 18:19:26
I'm shocked by that we currently don't have unit t
yoichio
2017/03/27 05:24:46
We want EphemeralRange to be independent from Layo
tanvir
2017/03/28 13:39:08
Done.
tanvir
2017/03/28 13:39:08
Done.
| |
| 153 Vector<FloatQuad>& quads) const { | |
| 154 Node* startContainer = m_startPosition.computeContainerNode(); | |
| 155 DCHECK(startContainer); | |
| 156 Node* endContainer = m_endPosition.computeContainerNode(); | |
| 157 DCHECK(endContainer); | |
| 158 | |
| 159 for (Node& node : nodes()) { | |
| 160 LayoutObject* r = node.layoutObject(); | |
|
yosin_UTC9
2017/03/27 05:43:14
Please avoid to use one letter variable name.
BTW,
tanvir
2017/03/28 13:39:08
Done.
| |
| 161 if (!r || !r->isText()) | |
| 162 continue; | |
| 163 LayoutText* layoutText = toLayoutText(r); | |
| 164 unsigned startOffset = | |
| 165 node == startContainer ? m_startPosition.offsetInContainerNode() : 0; | |
| 166 unsigned endOffset = node == endContainer | |
| 167 ? m_endPosition.offsetInContainerNode() | |
| 168 : std::numeric_limits<unsigned>::max(); | |
| 169 layoutText->absoluteQuadsForRange(quads, startOffset, endOffset); | |
| 170 } | |
| 171 } | |
| 172 | |
| 149 #if DCHECK_IS_ON() | 173 #if DCHECK_IS_ON() |
| 150 template <typename Strategy> | 174 template <typename Strategy> |
| 151 bool EphemeralRangeTemplate<Strategy>::isValid() const { | 175 bool EphemeralRangeTemplate<Strategy>::isValid() const { |
| 152 return m_startPosition.isNull() || | 176 return m_startPosition.isNull() || |
| 153 m_domTreeVersion == m_startPosition.document()->domTreeVersion(); | 177 m_domTreeVersion == m_startPosition.document()->domTreeVersion(); |
| 154 } | 178 } |
| 155 #else | 179 #else |
| 156 template <typename Strategy> | 180 template <typename Strategy> |
| 157 bool EphemeralRangeTemplate<Strategy>::isValid() const { | 181 bool EphemeralRangeTemplate<Strategy>::isValid() const { |
| 158 return true; | 182 return true; |
| 159 } | 183 } |
| 160 #endif | 184 #endif |
| 161 | 185 |
| 162 Range* createRange(const EphemeralRange& range) { | 186 Range* createRange(const EphemeralRange& range) { |
| 163 if (range.isNull()) | 187 if (range.isNull()) |
| 164 return nullptr; | 188 return nullptr; |
| 165 return Range::create(range.document(), range.startPosition(), | 189 return Range::create(range.document(), range.startPosition(), |
| 166 range.endPosition()); | 190 range.endPosition()); |
| 167 } | 191 } |
| 168 | 192 |
| 169 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingStrategy>; | 193 template class CORE_TEMPLATE_EXPORT EphemeralRangeTemplate<EditingStrategy>; |
| 170 template class CORE_TEMPLATE_EXPORT | 194 template class CORE_TEMPLATE_EXPORT |
| 171 EphemeralRangeTemplate<EditingInFlatTreeStrategy>; | 195 EphemeralRangeTemplate<EditingInFlatTreeStrategy>; |
| 172 | 196 |
| 173 } // namespace blink | 197 } // namespace blink |
| OLD | NEW |