| 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 pos, PositionTemplate<Strategy>::lastPositionInNode(boundary)); | 196 pos, PositionTemplate<Strategy>::lastPositionInNode(boundary)); |
| 197 } | 197 } |
| 198 | 198 |
| 199 template <typename Strategy> | 199 template <typename Strategy> |
| 200 void VisibleSelectionTemplate<Strategy>::appendTrailingWhitespace() { | 200 void VisibleSelectionTemplate<Strategy>::appendTrailingWhitespace() { |
| 201 if (isNone()) | 201 if (isNone()) |
| 202 return; | 202 return; |
| 203 DCHECK_EQ(m_granularity, WordGranularity); | 203 DCHECK_EQ(m_granularity, WordGranularity); |
| 204 if (!isRange()) | 204 if (!isRange()) |
| 205 return; | 205 return; |
| 206 const EphemeralRangeTemplate<Strategy> searchRange = makeSearchRange(end()); | 206 const PositionTemplate<Strategy>& newEnd = skipWhitespace(m_end); |
| 207 if (m_end == newEnd) |
| 208 return; |
| 209 m_hasTrailingWhitespace = true; |
| 210 m_end = newEnd; |
| 211 } |
| 212 |
| 213 // TODO(yosin): We should move |skipWhitespaceAlgorithm| to "VisibleUnits.cpp" |
| 214 template <typename Strategy> |
| 215 static PositionTemplate<Strategy> skipWhitespaceAlgorithm( |
| 216 const PositionTemplate<Strategy>& position) { |
| 217 const EphemeralRangeTemplate<Strategy>& searchRange = |
| 218 makeSearchRange(position); |
| 207 if (searchRange.isNull()) | 219 if (searchRange.isNull()) |
| 208 return; | 220 return position; |
| 209 | 221 |
| 210 CharacterIteratorAlgorithm<Strategy> charIt( | 222 CharacterIteratorAlgorithm<Strategy> charIt( |
| 211 searchRange.startPosition(), searchRange.endPosition(), | 223 searchRange.startPosition(), searchRange.endPosition(), |
| 212 TextIteratorBehavior::Builder() | 224 TextIteratorBehavior::Builder() |
| 213 .setEmitsCharactersBetweenAllVisiblePositions(true) | 225 .setEmitsCharactersBetweenAllVisiblePositions(true) |
| 214 .build()); | 226 .build()); |
| 215 bool changed = false; | 227 PositionTemplate<Strategy> runner = position; |
| 216 | |
| 217 for (; charIt.length(); charIt.advance(1)) { | 228 for (; charIt.length(); charIt.advance(1)) { |
| 218 UChar c = charIt.characterAt(0); | 229 UChar c = charIt.characterAt(0); |
| 219 if ((!isSpaceOrNewline(c) && c != noBreakSpaceCharacter) || c == '\n') | 230 if ((!isSpaceOrNewline(c) && c != noBreakSpaceCharacter) || c == '\n') |
| 220 break; | 231 return runner; |
| 221 m_end = charIt.endPosition(); | 232 runner = charIt.endPosition(); |
| 222 changed = true; | |
| 223 } | 233 } |
| 224 if (!changed) | 234 return runner; |
| 225 return; | 235 } |
| 226 m_hasTrailingWhitespace = true; | 236 |
| 237 // TODO(yosin): We should move |skipWhitespace| to "VisibleUnits.cpp" |
| 238 Position skipWhitespace(const Position& position) { |
| 239 return skipWhitespaceAlgorithm(position); |
| 240 } |
| 241 |
| 242 // TODO(yosin): We should move |skipWhitespace| to "VisibleUnits.cpp" |
| 243 PositionInFlatTree skipWhitespace(const PositionInFlatTree& position) { |
| 244 return skipWhitespaceAlgorithm(position); |
| 227 } | 245 } |
| 228 | 246 |
| 229 template <typename Strategy> | 247 template <typename Strategy> |
| 230 void VisibleSelectionTemplate<Strategy>::setBaseAndExtentToDeepEquivalents() { | 248 void VisibleSelectionTemplate<Strategy>::setBaseAndExtentToDeepEquivalents() { |
| 231 // Move the selection to rendered positions, if possible. | 249 // Move the selection to rendered positions, if possible. |
| 232 bool baseAndExtentEqual = m_base == m_extent; | 250 bool baseAndExtentEqual = m_base == m_extent; |
| 233 if (m_base.isNotNull()) { | 251 if (m_base.isNotNull()) { |
| 234 m_base = createVisiblePosition(m_base, m_affinity).deepEquivalent(); | 252 m_base = createVisiblePosition(m_base, m_affinity).deepEquivalent(); |
| 235 if (baseAndExtentEqual) | 253 if (baseAndExtentEqual) |
| 236 m_extent = m_base; | 254 m_extent = m_base; |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 | 818 |
| 801 void showTree(const blink::VisibleSelectionInFlatTree& sel) { | 819 void showTree(const blink::VisibleSelectionInFlatTree& sel) { |
| 802 sel.showTreeForThis(); | 820 sel.showTreeForThis(); |
| 803 } | 821 } |
| 804 | 822 |
| 805 void showTree(const blink::VisibleSelectionInFlatTree* sel) { | 823 void showTree(const blink::VisibleSelectionInFlatTree* sel) { |
| 806 if (sel) | 824 if (sel) |
| 807 sel->showTreeForThis(); | 825 sel->showTreeForThis(); |
| 808 } | 826 } |
| 809 #endif | 827 #endif |
| OLD | NEW |