| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // beginning of the next text node, each of which has a different style. | 173 // beginning of the next text node, each of which has a different style. |
| 174 // | 174 // |
| 175 // On a treasure map, <b>X</b> marks the spot. | 175 // On a treasure map, <b>X</b> marks the spot. |
| 176 // ^ selected | 176 // ^ selected |
| 177 // | 177 // |
| 178 DCHECK(IsRange()); | 178 DCHECK(IsRange()); |
| 179 return NormalizeRange(EphemeralRangeTemplate<Strategy>(start_, end_)); | 179 return NormalizeRange(EphemeralRangeTemplate<Strategy>(start_, end_)); |
| 180 } | 180 } |
| 181 | 181 |
| 182 template <typename Strategy> | 182 template <typename Strategy> |
| 183 void VisibleSelectionTemplate<Strategy>::AppendTrailingWhitespace() { | 183 VisibleSelectionTemplate<Strategy> |
| 184 VisibleSelectionTemplate<Strategy>::AppendTrailingWhitespace() const { |
| 184 if (IsNone()) | 185 if (IsNone()) |
| 185 return; | 186 return *this; |
| 186 DCHECK_EQ(granularity_, kWordGranularity); | 187 DCHECK_EQ(granularity_, kWordGranularity); |
| 187 if (!IsRange()) | 188 if (!IsRange()) |
| 188 return; | 189 return *this; |
| 189 const PositionTemplate<Strategy>& new_end = SkipWhitespace(end_); | 190 const PositionTemplate<Strategy>& new_end = SkipWhitespace(end_); |
| 190 if (end_ == new_end) | 191 if (end_ == new_end) |
| 191 return; | 192 return *this; |
| 192 has_trailing_whitespace_ = true; | 193 VisibleSelectionTemplate<Strategy> result = *this; |
| 193 end_ = new_end; | 194 result.has_trailing_whitespace_ = true; |
| 195 result.end_ = new_end; |
| 196 return result; |
| 194 } | 197 } |
| 195 | 198 |
| 196 template <typename Strategy> | 199 template <typename Strategy> |
| 197 void VisibleSelectionTemplate<Strategy>::SetBaseAndExtentToDeepEquivalents() { | 200 void VisibleSelectionTemplate<Strategy>::SetBaseAndExtentToDeepEquivalents() { |
| 198 // Move the selection to rendered positions, if possible. | 201 // Move the selection to rendered positions, if possible. |
| 199 bool base_and_extent_equal = base_ == extent_; | 202 bool base_and_extent_equal = base_ == extent_; |
| 200 if (base_.IsNotNull()) { | 203 if (base_.IsNotNull()) { |
| 201 base_ = CreateVisiblePosition(base_, affinity_).DeepEquivalent(); | 204 base_ = CreateVisiblePosition(base_, affinity_).DeepEquivalent(); |
| 202 if (base_and_extent_equal) | 205 if (base_and_extent_equal) |
| 203 extent_ = base_; | 206 extent_ = base_; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 // to do this operation, since all selection changes that result in a | 448 // to do this operation, since all selection changes that result in a |
| 446 // RANGE come through here before anyone uses it. | 449 // RANGE come through here before anyone uses it. |
| 447 // TODO(yosin) Canonicalizing is good, but haven't we already done it | 450 // TODO(yosin) Canonicalizing is good, but haven't we already done it |
| 448 // (when we set these two positions to |VisiblePosition| | 451 // (when we set these two positions to |VisiblePosition| |
| 449 // |deepEquivalent()|s above)? | 452 // |deepEquivalent()|s above)? |
| 450 start_ = MostForwardCaretPosition(start_); | 453 start_ = MostForwardCaretPosition(start_); |
| 451 end_ = MostBackwardCaretPosition(end_); | 454 end_ = MostBackwardCaretPosition(end_); |
| 452 } | 455 } |
| 453 if (!has_trailing_whitespace_) | 456 if (!has_trailing_whitespace_) |
| 454 return; | 457 return; |
| 455 AppendTrailingWhitespace(); | 458 *this = AppendTrailingWhitespace(); |
| 456 } | 459 } |
| 457 | 460 |
| 458 template <typename Strategy> | 461 template <typename Strategy> |
| 459 bool VisibleSelectionTemplate<Strategy>::IsValidFor( | 462 bool VisibleSelectionTemplate<Strategy>::IsValidFor( |
| 460 const Document& document) const { | 463 const Document& document) const { |
| 461 if (IsNone()) | 464 if (IsNone()) |
| 462 return true; | 465 return true; |
| 463 | 466 |
| 464 return base_.GetDocument() == &document && !base_.IsOrphan() && | 467 return base_.GetDocument() == &document && !base_.IsOrphan() && |
| 465 !extent_.IsOrphan() && !start_.IsOrphan() && !end_.IsOrphan(); | 468 !extent_.IsOrphan() && !start_.IsOrphan() && !end_.IsOrphan(); |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 | 779 |
| 777 void showTree(const blink::VisibleSelectionInFlatTree& sel) { | 780 void showTree(const blink::VisibleSelectionInFlatTree& sel) { |
| 778 sel.ShowTreeForThis(); | 781 sel.ShowTreeForThis(); |
| 779 } | 782 } |
| 780 | 783 |
| 781 void showTree(const blink::VisibleSelectionInFlatTree* sel) { | 784 void showTree(const blink::VisibleSelectionInFlatTree* sel) { |
| 782 if (sel) | 785 if (sel) |
| 783 sel->ShowTreeForThis(); | 786 sel->ShowTreeForThis(); |
| 784 } | 787 } |
| 785 #endif | 788 #endif |
| OLD | NEW |