| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 template <typename Strategy> | 93 template <typename Strategy> |
| 94 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const EphemeralRang
eTemplate<Strategy>& range, TextAffinity affinity, bool isDirectional) | 94 VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(const EphemeralRang
eTemplate<Strategy>& range, TextAffinity affinity, bool isDirectional) |
| 95 : VisibleSelectionTemplate(range.startPosition(), range.endPosition(), affin
ity, isDirectional) | 95 : VisibleSelectionTemplate(range.startPosition(), range.endPosition(), affin
ity, isDirectional) |
| 96 { | 96 { |
| 97 } | 97 } |
| 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 ASSERT(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::updateLayout()| 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)) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 template <typename Strategy> | 154 template <typename Strategy> |
| 155 VisibleSelectionTemplate<Strategy>::~VisibleSelectionTemplate() | 155 VisibleSelectionTemplate<Strategy>::~VisibleSelectionTemplate() |
| 156 { | 156 { |
| 157 didChange(); | 157 didChange(); |
| 158 } | 158 } |
| 159 #endif | 159 #endif |
| 160 | 160 |
| 161 template <typename Strategy> | 161 template <typename Strategy> |
| 162 VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::selection
FromContentsOfNode(Node* node) | 162 VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::selection
FromContentsOfNode(Node* node) |
| 163 { | 163 { |
| 164 ASSERT(!Strategy::editingIgnoresContent(node)); | 164 DCHECK(!Strategy::editingIgnoresContent(node)); |
| 165 return VisibleSelectionTemplate(PositionTemplate<Strategy>::firstPositionInN
ode(node), PositionTemplate<Strategy>::lastPositionInNode(node)); | 165 return VisibleSelectionTemplate(PositionTemplate<Strategy>::firstPositionInN
ode(node), PositionTemplate<Strategy>::lastPositionInNode(node)); |
| 166 } | 166 } |
| 167 | 167 |
| 168 template <typename Strategy> | 168 template <typename Strategy> |
| 169 void VisibleSelectionTemplate<Strategy>::setBase(const PositionTemplate<Strategy
>& position) | 169 void VisibleSelectionTemplate<Strategy>::setBase(const PositionTemplate<Strategy
>& position) |
| 170 { | 170 { |
| 171 const PositionTemplate<Strategy> oldBase = m_base; | 171 const PositionTemplate<Strategy> oldBase = m_base; |
| 172 m_base = position; | 172 m_base = position; |
| 173 validate(); | 173 validate(); |
| 174 if (m_base != oldBase) | 174 if (m_base != oldBase) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 // the selection. Again, this is to match the conventions of text editors | 246 // the selection. Again, this is to match the conventions of text editors |
| 247 // tested, which make style determinations based on the first character of | 247 // tested, which make style determinations based on the first character of |
| 248 // the selection. For instance, this operation helps to make sure that the | 248 // the selection. For instance, this operation helps to make sure that the |
| 249 // "X" selected below is the only thing selected. The range should not be | 249 // "X" selected below is the only thing selected. The range should not be |
| 250 // allowed to "leak" out to the end of the previous text node, or to the | 250 // allowed to "leak" out to the end of the previous text node, or to the |
| 251 // beginning of the next text node, each of which has a different style. | 251 // beginning of the next text node, each of which has a different style. |
| 252 // | 252 // |
| 253 // On a treasure map, <b>X</b> marks the spot. | 253 // On a treasure map, <b>X</b> marks the spot. |
| 254 // ^ selected | 254 // ^ selected |
| 255 // | 255 // |
| 256 ASSERT(isRange()); | 256 DCHECK(isRange()); |
| 257 return normalizeRange(EphemeralRangeTemplate<Strategy>(m_start, m_end)); | 257 return normalizeRange(EphemeralRangeTemplate<Strategy>(m_start, m_end)); |
| 258 } | 258 } |
| 259 | 259 |
| 260 template <typename Strategy> | 260 template <typename Strategy> |
| 261 bool VisibleSelectionTemplate<Strategy>::expandUsingGranularity(TextGranularity
granularity) | 261 bool VisibleSelectionTemplate<Strategy>::expandUsingGranularity(TextGranularity
granularity) |
| 262 { | 262 { |
| 263 if (isNone()) | 263 if (isNone()) |
| 264 return false; | 264 return false; |
| 265 | 265 |
| 266 // TODO(yosin) Do we need to check all of them? | 266 // TODO(yosin) Do we need to check all of them? |
| (...skipping 19 matching lines...) Expand all Loading... |
| 286 Element* boundary = enclosingBlockFlowElement(*node); | 286 Element* boundary = enclosingBlockFlowElement(*node); |
| 287 if (!boundary) | 287 if (!boundary) |
| 288 return EphemeralRangeTemplate<Strategy>(); | 288 return EphemeralRangeTemplate<Strategy>(); |
| 289 | 289 |
| 290 return EphemeralRangeTemplate<Strategy>(pos, PositionTemplate<Strategy>::las
tPositionInNode(boundary)); | 290 return EphemeralRangeTemplate<Strategy>(pos, PositionTemplate<Strategy>::las
tPositionInNode(boundary)); |
| 291 } | 291 } |
| 292 | 292 |
| 293 template <typename Strategy> | 293 template <typename Strategy> |
| 294 void VisibleSelectionTemplate<Strategy>::appendTrailingWhitespace() | 294 void VisibleSelectionTemplate<Strategy>::appendTrailingWhitespace() |
| 295 { | 295 { |
| 296 ASSERT(m_granularity == WordGranularity); | 296 DCHECK_EQ(m_granularity, WordGranularity); |
| 297 const EphemeralRangeTemplate<Strategy> searchRange = makeSearchRange(end()); | 297 const EphemeralRangeTemplate<Strategy> searchRange = makeSearchRange(end()); |
| 298 if (searchRange.isNull()) | 298 if (searchRange.isNull()) |
| 299 return; | 299 return; |
| 300 | 300 |
| 301 CharacterIteratorAlgorithm<Strategy> charIt(searchRange.startPosition(), sea
rchRange.endPosition(), TextIteratorEmitsCharactersBetweenAllVisiblePositions); | 301 CharacterIteratorAlgorithm<Strategy> charIt(searchRange.startPosition(), sea
rchRange.endPosition(), TextIteratorEmitsCharactersBetweenAllVisiblePositions); |
| 302 bool changed = false; | 302 bool changed = false; |
| 303 | 303 |
| 304 for (; charIt.length(); charIt.advance(1)) { | 304 for (; charIt.length(); charIt.advance(1)) { |
| 305 UChar c = charIt.characterAt(0); | 305 UChar c = charIt.characterAt(0); |
| 306 if ((!isSpaceOrNewline(c) && c != noBreakSpaceCharacter) || c == '\n') | 306 if ((!isSpaceOrNewline(c) && c != noBreakSpaceCharacter) || c == '\n') |
| (...skipping 30 matching lines...) Expand all Loading... |
| 337 m_extent = m_base; | 337 m_extent = m_base; |
| 338 m_baseIsFirst = true; | 338 m_baseIsFirst = true; |
| 339 } else { | 339 } else { |
| 340 m_baseIsFirst = m_base.compareTo(m_extent) <= 0; | 340 m_baseIsFirst = m_base.compareTo(m_extent) <= 0; |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 | 343 |
| 344 template <typename Strategy> | 344 template <typename Strategy> |
| 345 void VisibleSelectionTemplate<Strategy>::setStartRespectingGranularity(TextGranu
larity granularity, EWordSide wordSide) | 345 void VisibleSelectionTemplate<Strategy>::setStartRespectingGranularity(TextGranu
larity granularity, EWordSide wordSide) |
| 346 { | 346 { |
| 347 ASSERT(m_base.isNotNull()); | 347 DCHECK(m_base.isNotNull()); |
| 348 ASSERT(m_extent.isNotNull()); | 348 DCHECK(m_extent.isNotNull()); |
| 349 | 349 |
| 350 m_start = m_baseIsFirst ? m_base : m_extent; | 350 m_start = m_baseIsFirst ? m_base : m_extent; |
| 351 | 351 |
| 352 switch (granularity) { | 352 switch (granularity) { |
| 353 case CharacterGranularity: | 353 case CharacterGranularity: |
| 354 // Don't do any expansion. | 354 // Don't do any expansion. |
| 355 break; | 355 break; |
| 356 case WordGranularity: { | 356 case WordGranularity: { |
| 357 // General case: Select the word the caret is positioned inside of. | 357 // General case: Select the word the caret is positioned inside of. |
| 358 // If the caret is on the word boundary, select the word according to |w
ordSide|. | 358 // If the caret is on the word boundary, select the word according to |w
ordSide|. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 397 } |
| 398 | 398 |
| 399 // Make sure we do not have a Null position. | 399 // Make sure we do not have a Null position. |
| 400 if (m_start.isNull()) | 400 if (m_start.isNull()) |
| 401 m_start = m_baseIsFirst ? m_base : m_extent; | 401 m_start = m_baseIsFirst ? m_base : m_extent; |
| 402 } | 402 } |
| 403 | 403 |
| 404 template <typename Strategy> | 404 template <typename Strategy> |
| 405 void VisibleSelectionTemplate<Strategy>::setEndRespectingGranularity(TextGranula
rity granularity, EWordSide wordSide) | 405 void VisibleSelectionTemplate<Strategy>::setEndRespectingGranularity(TextGranula
rity granularity, EWordSide wordSide) |
| 406 { | 406 { |
| 407 ASSERT(m_base.isNotNull()); | 407 DCHECK(m_base.isNotNull()); |
| 408 ASSERT(m_extent.isNotNull()); | 408 DCHECK(m_extent.isNotNull()); |
| 409 | 409 |
| 410 m_end = m_baseIsFirst ? m_extent : m_base; | 410 m_end = m_baseIsFirst ? m_extent : m_base; |
| 411 | 411 |
| 412 switch (granularity) { | 412 switch (granularity) { |
| 413 case CharacterGranularity: | 413 case CharacterGranularity: |
| 414 // Don't do any expansion. | 414 // Don't do any expansion. |
| 415 break; | 415 break; |
| 416 case WordGranularity: { | 416 case WordGranularity: { |
| 417 // General case: Select the word the caret is positioned inside of. | 417 // General case: Select the word the caret is positioned inside of. |
| 418 // If the caret is on the word boundary, select the word according to | 418 // If the caret is on the word boundary, select the word according to |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 setBaseAndExtentToDeepEquivalents(); | 533 setBaseAndExtentToDeepEquivalents(); |
| 534 if (m_base.isNull() || m_extent.isNull()) { | 534 if (m_base.isNull() || m_extent.isNull()) { |
| 535 m_base = m_extent = m_start = m_end = PositionTemplate<Strategy>(); | 535 m_base = m_extent = m_start = m_end = PositionTemplate<Strategy>(); |
| 536 updateSelectionType(); | 536 updateSelectionType(); |
| 537 return; | 537 return; |
| 538 } | 538 } |
| 539 | 539 |
| 540 m_start = m_baseIsFirst ? m_base : m_extent; | 540 m_start = m_baseIsFirst ? m_base : m_extent; |
| 541 m_end = m_baseIsFirst ? m_extent : m_base; | 541 m_end = m_baseIsFirst ? m_extent : m_base; |
| 542 setStartRespectingGranularity(granularity); | 542 setStartRespectingGranularity(granularity); |
| 543 ASSERT(m_start.isNotNull()); | 543 DCHECK(m_start.isNotNull()); |
| 544 setEndRespectingGranularity(granularity); | 544 setEndRespectingGranularity(granularity); |
| 545 ASSERT(m_end.isNotNull()); | 545 DCHECK(m_end.isNotNull()); |
| 546 adjustSelectionToAvoidCrossingShadowBoundaries(); | 546 adjustSelectionToAvoidCrossingShadowBoundaries(); |
| 547 adjustSelectionToAvoidCrossingEditingBoundaries(); | 547 adjustSelectionToAvoidCrossingEditingBoundaries(); |
| 548 updateSelectionType(); | 548 updateSelectionType(); |
| 549 | 549 |
| 550 if (getSelectionType() == RangeSelection) { | 550 if (getSelectionType() == RangeSelection) { |
| 551 // "Constrain" the selection to be the smallest equivalent range of | 551 // "Constrain" the selection to be the smallest equivalent range of |
| 552 // nodes. This is a somewhat arbitrary choice, but experience shows that | 552 // nodes. This is a somewhat arbitrary choice, but experience shows that |
| 553 // it is useful to make to make the selection "canonical" (if only for | 553 // it is useful to make to make the selection "canonical" (if only for |
| 554 // purposes of comparing selections). This is an ideal point of the code | 554 // purposes of comparing selections). This is an ideal point of the code |
| 555 // to do this operation, since all selection changes that result in a | 555 // to do this operation, since all selection changes that result in a |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 { | 799 { |
| 800 } | 800 } |
| 801 | 801 |
| 802 VisibleSelectionChangeObserver::~VisibleSelectionChangeObserver() | 802 VisibleSelectionChangeObserver::~VisibleSelectionChangeObserver() |
| 803 { | 803 { |
| 804 } | 804 } |
| 805 | 805 |
| 806 template <typename Strategy> | 806 template <typename Strategy> |
| 807 void VisibleSelectionTemplate<Strategy>::setChangeObserver(VisibleSelectionChang
eObserver& observer) | 807 void VisibleSelectionTemplate<Strategy>::setChangeObserver(VisibleSelectionChang
eObserver& observer) |
| 808 { | 808 { |
| 809 ASSERT(!m_changeObserver); | 809 DCHECK(!m_changeObserver); |
| 810 m_changeObserver = &observer; | 810 m_changeObserver = &observer; |
| 811 } | 811 } |
| 812 | 812 |
| 813 template <typename Strategy> | 813 template <typename Strategy> |
| 814 void VisibleSelectionTemplate<Strategy>::clearChangeObserver() | 814 void VisibleSelectionTemplate<Strategy>::clearChangeObserver() |
| 815 { | 815 { |
| 816 ASSERT(m_changeObserver); | 816 DCHECK(m_changeObserver); |
| 817 m_changeObserver = nullptr; | 817 m_changeObserver = nullptr; |
| 818 } | 818 } |
| 819 | 819 |
| 820 template <typename Strategy> | 820 template <typename Strategy> |
| 821 void VisibleSelectionTemplate<Strategy>::didChange() | 821 void VisibleSelectionTemplate<Strategy>::didChange() |
| 822 { | 822 { |
| 823 if (m_changeObserver) | 823 if (m_changeObserver) |
| 824 m_changeObserver->didChangeVisibleSelection(); | 824 m_changeObserver->didChangeVisibleSelection(); |
| 825 } | 825 } |
| 826 | 826 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 { | 975 { |
| 976 sel.showTreeForThis(); | 976 sel.showTreeForThis(); |
| 977 } | 977 } |
| 978 | 978 |
| 979 void showTree(const blink::VisibleSelectionInFlatTree* sel) | 979 void showTree(const blink::VisibleSelectionInFlatTree* sel) |
| 980 { | 980 { |
| 981 if (sel) | 981 if (sel) |
| 982 sel->showTreeForThis(); | 982 sel->showTreeForThis(); |
| 983 } | 983 } |
| 984 #endif | 984 #endif |
| OLD | NEW |