| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 base_is_first_ = true; | 210 base_is_first_ = true; |
| 211 } else if (extent_.IsNull()) { | 211 } else if (extent_.IsNull()) { |
| 212 extent_ = base_; | 212 extent_ = base_; |
| 213 base_is_first_ = true; | 213 base_is_first_ = true; |
| 214 } else { | 214 } else { |
| 215 base_is_first_ = base_.CompareTo(extent_) <= 0; | 215 base_is_first_ = base_.CompareTo(extent_) <= 0; |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 template <typename Strategy> | 219 template <typename Strategy> |
| 220 static PositionTemplate<Strategy> ComputeStartRespectingGranularity( | 220 static PositionTemplate<Strategy> ComputeStartRespectingGranularityAlgorithm( |
| 221 const PositionWithAffinityTemplate<Strategy>& passed_start, | 221 const PositionWithAffinityTemplate<Strategy>& passed_start, |
| 222 TextGranularity granularity) { | 222 TextGranularity granularity) { |
| 223 DCHECK(passed_start.IsNotNull()); | 223 DCHECK(passed_start.IsNotNull()); |
| 224 | 224 |
| 225 switch (granularity) { | 225 switch (granularity) { |
| 226 case kCharacterGranularity: | 226 case kCharacterGranularity: |
| 227 // Don't do any expansion. | 227 // Don't do any expansion. |
| 228 return passed_start.GetPosition(); | 228 return passed_start.GetPosition(); |
| 229 case kWordGranularity: { | 229 case kWordGranularity: { |
| 230 // General case: Select the word the caret is positioned inside of. | 230 // General case: Select the word the caret is positioned inside of. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 .DeepEquivalent(); | 269 .DeepEquivalent(); |
| 270 case kSentenceBoundary: | 270 case kSentenceBoundary: |
| 271 return StartOfSentence(CreateVisiblePosition(passed_start)) | 271 return StartOfSentence(CreateVisiblePosition(passed_start)) |
| 272 .DeepEquivalent(); | 272 .DeepEquivalent(); |
| 273 } | 273 } |
| 274 | 274 |
| 275 NOTREACHED(); | 275 NOTREACHED(); |
| 276 return passed_start.GetPosition(); | 276 return passed_start.GetPosition(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 static Position ComputeStartRespectingGranularity( |
| 280 const PositionWithAffinity& start, |
| 281 TextGranularity granularity) { |
| 282 return ComputeStartRespectingGranularityAlgorithm(start, granularity); |
| 283 } |
| 284 |
| 285 PositionInFlatTree ComputeStartRespectingGranularity( |
| 286 const PositionInFlatTreeWithAffinity& start, |
| 287 TextGranularity granularity) { |
| 288 return ComputeStartRespectingGranularityAlgorithm(start, granularity); |
| 289 } |
| 290 |
| 279 template <typename Strategy> | 291 template <typename Strategy> |
| 280 static PositionTemplate<Strategy> ComputeEndRespectingGranularity( | 292 static PositionTemplate<Strategy> ComputeEndRespectingGranularityAlgorithm( |
| 281 const PositionTemplate<Strategy>& start, | 293 const PositionTemplate<Strategy>& start, |
| 282 const PositionWithAffinityTemplate<Strategy>& passed_end, | 294 const PositionWithAffinityTemplate<Strategy>& passed_end, |
| 283 TextGranularity granularity) { | 295 TextGranularity granularity) { |
| 284 DCHECK(passed_end.IsNotNull()); | 296 DCHECK(passed_end.IsNotNull()); |
| 285 | 297 |
| 286 switch (granularity) { | 298 switch (granularity) { |
| 287 case kCharacterGranularity: | 299 case kCharacterGranularity: |
| 288 // Don't do any expansion. | 300 // Don't do any expansion. |
| 289 return passed_end.GetPosition(); | 301 return passed_end.GetPosition(); |
| 290 case kWordGranularity: { | 302 case kWordGranularity: { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 return EndOfDocument(CreateVisiblePosition(passed_end)).DeepEquivalent(); | 397 return EndOfDocument(CreateVisiblePosition(passed_end)).DeepEquivalent(); |
| 386 case kParagraphBoundary: | 398 case kParagraphBoundary: |
| 387 return EndOfParagraph(CreateVisiblePosition(passed_end)).DeepEquivalent(); | 399 return EndOfParagraph(CreateVisiblePosition(passed_end)).DeepEquivalent(); |
| 388 case kSentenceBoundary: | 400 case kSentenceBoundary: |
| 389 return EndOfSentence(CreateVisiblePosition(passed_end)).DeepEquivalent(); | 401 return EndOfSentence(CreateVisiblePosition(passed_end)).DeepEquivalent(); |
| 390 } | 402 } |
| 391 NOTREACHED(); | 403 NOTREACHED(); |
| 392 return passed_end.GetPosition(); | 404 return passed_end.GetPosition(); |
| 393 } | 405 } |
| 394 | 406 |
| 407 static Position ComputeEndRespectingGranularity(const Position& start, |
| 408 const PositionWithAffinity& end, |
| 409 TextGranularity granularity) { |
| 410 return ComputeEndRespectingGranularityAlgorithm(start, end, granularity); |
| 411 } |
| 412 |
| 413 PositionInFlatTree ComputeEndRespectingGranularity( |
| 414 const PositionInFlatTree& start, |
| 415 const PositionInFlatTreeWithAffinity& end, |
| 416 TextGranularity granularity) { |
| 417 return ComputeEndRespectingGranularityAlgorithm(start, end, granularity); |
| 418 } |
| 419 |
| 395 template <typename Strategy> | 420 template <typename Strategy> |
| 396 void VisibleSelectionTemplate<Strategy>::UpdateSelectionType() { | 421 void VisibleSelectionTemplate<Strategy>::UpdateSelectionType() { |
| 397 selection_type_ = ComputeSelectionType(start_, end_); | 422 selection_type_ = ComputeSelectionType(start_, end_); |
| 398 | 423 |
| 399 // Affinity only makes sense for a caret | 424 // Affinity only makes sense for a caret |
| 400 if (selection_type_ != kCaretSelection) | 425 if (selection_type_ != kCaretSelection) |
| 401 affinity_ = TextAffinity::kDownstream; | 426 affinity_ = TextAffinity::kDownstream; |
| 402 } | 427 } |
| 403 | 428 |
| 404 template <typename Strategy> | 429 template <typename Strategy> |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 | 792 |
| 768 void showTree(const blink::VisibleSelectionInFlatTree& sel) { | 793 void showTree(const blink::VisibleSelectionInFlatTree& sel) { |
| 769 sel.ShowTreeForThis(); | 794 sel.ShowTreeForThis(); |
| 770 } | 795 } |
| 771 | 796 |
| 772 void showTree(const blink::VisibleSelectionInFlatTree* sel) { | 797 void showTree(const blink::VisibleSelectionInFlatTree* sel) { |
| 773 if (sel) | 798 if (sel) |
| 774 sel->ShowTreeForThis(); | 799 sel->ShowTreeForThis(); |
| 775 } | 800 } |
| 776 #endif | 801 #endif |
| OLD | NEW |