OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 template <typename Strategy> | 99 template <typename Strategy> |
100 static SelectionType computeSelectionType(const PositionTemplate<Strategy>& star
t, const PositionTemplate<Strategy>& end) | 100 static SelectionType computeSelectionType(const PositionTemplate<Strategy>& star
t, const PositionTemplate<Strategy>& end) |
101 { | 101 { |
102 if (start.isNull()) { | 102 if (start.isNull()) { |
103 DCHECK(end.isNull()); | 103 DCHECK(end.isNull()); |
104 return NoSelection; | 104 return NoSelection; |
105 } | 105 } |
106 if (start == end) | 106 if (start == end) |
107 return CaretSelection; | 107 return CaretSelection; |
108 // TODO(yosin) We should call |Document::updateLayout()| here for | 108 // TODO(yosin) We should call |Document::updateStyleAndLayout()| here for |
109 // |mostBackwardCaretPosition()|. However, we are here during | 109 // |mostBackwardCaretPosition()|. However, we are here during |
110 // |Node::removeChild()|. | 110 // |Node::removeChild()|. |
111 start.anchorNode()->updateDistribution(); | 111 start.anchorNode()->updateDistribution(); |
112 end.anchorNode()->updateDistribution(); | 112 end.anchorNode()->updateDistribution(); |
113 if (mostBackwardCaretPosition(start) == mostBackwardCaretPosition(end)) | 113 if (mostBackwardCaretPosition(start) == mostBackwardCaretPosition(end)) |
114 return CaretSelection; | 114 return CaretSelection; |
115 return RangeSelection; | 115 return RangeSelection; |
116 } | 116 } |
117 | 117 |
118 template <typename Strategy> | 118 template <typename Strategy> |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 template <typename Strategy> | 214 template <typename Strategy> |
215 EphemeralRangeTemplate<Strategy> VisibleSelectionTemplate<Strategy>::toNormalize
dEphemeralRange() const | 215 EphemeralRangeTemplate<Strategy> VisibleSelectionTemplate<Strategy>::toNormalize
dEphemeralRange() const |
216 { | 216 { |
217 if (isNone()) | 217 if (isNone()) |
218 return EphemeralRangeTemplate<Strategy>(); | 218 return EphemeralRangeTemplate<Strategy>(); |
219 | 219 |
220 // Make sure we have an updated layout since this function is called | 220 // Make sure we have an updated layout since this function is called |
221 // in the course of running edit commands which modify the DOM. | 221 // in the course of running edit commands which modify the DOM. |
222 // Failing to call this can result in equivalentXXXPosition calls returning | 222 // Failing to call this can result in equivalentXXXPosition calls returning |
223 // incorrect results. | 223 // incorrect results. |
224 m_start.document()->updateLayout(); | 224 m_start.document()->updateStyleAndLayout(); |
225 | 225 |
226 // Check again, because updating layout can clear the selection. | 226 // Check again, because updating layout can clear the selection. |
227 if (isNone()) | 227 if (isNone()) |
228 return EphemeralRangeTemplate<Strategy>(); | 228 return EphemeralRangeTemplate<Strategy>(); |
229 | 229 |
230 if (isCaret()) { | 230 if (isCaret()) { |
231 // If the selection is a caret, move the range start upstream. This | 231 // If the selection is a caret, move the range start upstream. This |
232 // helps us match the conventions of text editors tested, which make | 232 // helps us match the conventions of text editors tested, which make |
233 // style determinations based on the character before the caret, if any. | 233 // style determinations based on the character before the caret, if any. |
234 const PositionTemplate<Strategy> start = mostBackwardCaretPosition(m_sta
rt).parentAnchoredEquivalent(); | 234 const PositionTemplate<Strategy> start = mostBackwardCaretPosition(m_sta
rt).parentAnchoredEquivalent(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } | 283 } |
284 | 284 |
285 template <typename Strategy> | 285 template <typename Strategy> |
286 void VisibleSelectionTemplate<Strategy>::appendTrailingWhitespace() | 286 void VisibleSelectionTemplate<Strategy>::appendTrailingWhitespace() |
287 { | 287 { |
288 DCHECK_EQ(m_granularity, WordGranularity); | 288 DCHECK_EQ(m_granularity, WordGranularity); |
289 const EphemeralRangeTemplate<Strategy> searchRange = makeSearchRange(end()); | 289 const EphemeralRangeTemplate<Strategy> searchRange = makeSearchRange(end()); |
290 if (searchRange.isNull()) | 290 if (searchRange.isNull()) |
291 return; | 291 return; |
292 | 292 |
293 // TODO(dglazkov): The use of updateLayoutIgnorePendingStylesheets needs to
be audited. | 293 // TODO(dglazkov): The use of updateStyleAndLayoutIgnorePendingStylesheets n
eeds to be audited. |
294 // see http://crbug.com/590369 for more details. | 294 // see http://crbug.com/590369 for more details. |
295 searchRange.startPosition().document()->updateLayoutIgnorePendingStylesheets
(); | 295 searchRange.startPosition().document()->updateStyleAndLayoutIgnorePendingSty
lesheets(); |
296 | 296 |
297 CharacterIteratorAlgorithm<Strategy> charIt(searchRange.startPosition(), sea
rchRange.endPosition(), TextIteratorEmitsCharactersBetweenAllVisiblePositions); | 297 CharacterIteratorAlgorithm<Strategy> charIt(searchRange.startPosition(), sea
rchRange.endPosition(), TextIteratorEmitsCharactersBetweenAllVisiblePositions); |
298 bool changed = false; | 298 bool changed = false; |
299 | 299 |
300 for (; charIt.length(); charIt.advance(1)) { | 300 for (; charIt.length(); charIt.advance(1)) { |
301 UChar c = charIt.characterAt(0); | 301 UChar c = charIt.characterAt(0); |
302 if ((!isSpaceOrNewline(c) && c != noBreakSpaceCharacter) || c == '\n') | 302 if ((!isSpaceOrNewline(c) && c != noBreakSpaceCharacter) || c == '\n') |
303 break; | 303 break; |
304 m_end = charIt.endPosition(); | 304 m_end = charIt.endPosition(); |
305 changed = true; | 305 changed = true; |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 const unsigned nodeLength = position.anchorNode()->lengthOfContents(); | 836 const unsigned nodeLength = position.anchorNode()->lengthOfContents(); |
837 return offset <= nodeLength; | 837 return offset <= nodeLength; |
838 } | 838 } |
839 | 839 |
840 template <typename Strategy> | 840 template <typename Strategy> |
841 void VisibleSelectionTemplate<Strategy>::updateIfNeeded() | 841 void VisibleSelectionTemplate<Strategy>::updateIfNeeded() |
842 { | 842 { |
843 Document* document = m_base.document(); | 843 Document* document = m_base.document(); |
844 if (!document) | 844 if (!document) |
845 return; | 845 return; |
846 document->updateLayoutIgnorePendingStylesheets(); | 846 document->updateStyleAndLayoutIgnorePendingStylesheets(); |
847 const bool hasTrailingWhitespace = m_hasTrailingWhitespace; | 847 const bool hasTrailingWhitespace = m_hasTrailingWhitespace; |
848 validate(m_granularity); | 848 validate(m_granularity); |
849 if (!hasTrailingWhitespace) | 849 if (!hasTrailingWhitespace) |
850 return; | 850 return; |
851 appendTrailingWhitespace(); | 851 appendTrailingWhitespace(); |
852 } | 852 } |
853 | 853 |
854 template <typename Strategy> | 854 template <typename Strategy> |
855 void VisibleSelectionTemplate<Strategy>::validatePositionsIfNeeded() | 855 void VisibleSelectionTemplate<Strategy>::validatePositionsIfNeeded() |
856 { | 856 { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 { | 976 { |
977 sel.showTreeForThis(); | 977 sel.showTreeForThis(); |
978 } | 978 } |
979 | 979 |
980 void showTree(const blink::VisibleSelectionInFlatTree* sel) | 980 void showTree(const blink::VisibleSelectionInFlatTree* sel) |
981 { | 981 { |
982 if (sel) | 982 if (sel) |
983 sel->showTreeForThis(); | 983 sel->showTreeForThis(); |
984 } | 984 } |
985 #endif | 985 #endif |
OLD | NEW |