OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights |
3 * reserved. | 3 * reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // selection. This only matters for cases where base and extend point to | 93 // selection. This only matters for cases where base and extend point to |
94 // different positions than start and end (e.g. after a double-click to | 94 // different positions than start and end (e.g. after a double-click to |
95 // select a word). | 95 // select a word). |
96 if (m_selection.isBaseFirst()) | 96 if (m_selection.isBaseFirst()) |
97 baseIsStart = true; | 97 baseIsStart = true; |
98 else | 98 else |
99 baseIsStart = false; | 99 baseIsStart = false; |
100 } else { | 100 } else { |
101 switch (direction) { | 101 switch (direction) { |
102 case DirectionRight: | 102 case DirectionRight: |
103 if (directionOfSelection() == TextDirection::Ltr) | 103 if (directionOfSelection() == TextDirection::kLtr) |
104 baseIsStart = true; | 104 baseIsStart = true; |
105 else | 105 else |
106 baseIsStart = false; | 106 baseIsStart = false; |
107 break; | 107 break; |
108 case DirectionForward: | 108 case DirectionForward: |
109 baseIsStart = true; | 109 baseIsStart = true; |
110 break; | 110 break; |
111 case DirectionLeft: | 111 case DirectionLeft: |
112 if (directionOfSelection() == TextDirection::Ltr) | 112 if (directionOfSelection() == TextDirection::kLtr) |
113 baseIsStart = false; | 113 baseIsStart = false; |
114 else | 114 else |
115 baseIsStart = true; | 115 baseIsStart = true; |
116 break; | 116 break; |
117 case DirectionBackward: | 117 case DirectionBackward: |
118 baseIsStart = false; | 118 baseIsStart = false; |
119 break; | 119 break; |
120 } | 120 } |
121 } | 121 } |
122 if (baseIsStart) { | 122 if (baseIsStart) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 createVisiblePosition(m_selection.extent(), m_selection.affinity()); | 195 createVisiblePosition(m_selection.extent(), m_selection.affinity()); |
196 | 196 |
197 // The difference between modifyExtendingRight and modifyExtendingForward is: | 197 // The difference between modifyExtendingRight and modifyExtendingForward is: |
198 // modifyExtendingForward always extends forward logically. | 198 // modifyExtendingForward always extends forward logically. |
199 // modifyExtendingRight behaves the same as modifyExtendingForward except for | 199 // modifyExtendingRight behaves the same as modifyExtendingForward except for |
200 // extending character or word, it extends forward logically if the enclosing | 200 // extending character or word, it extends forward logically if the enclosing |
201 // block is LTR direction, but it extends backward logically if the enclosing | 201 // block is LTR direction, but it extends backward logically if the enclosing |
202 // block is RTL direction. | 202 // block is RTL direction. |
203 switch (granularity) { | 203 switch (granularity) { |
204 case CharacterGranularity: | 204 case CharacterGranularity: |
205 if (directionOfEnclosingBlock() == TextDirection::Ltr) | 205 if (directionOfEnclosingBlock() == TextDirection::kLtr) |
206 pos = nextPositionOf(pos, CanSkipOverEditingBoundary); | 206 pos = nextPositionOf(pos, CanSkipOverEditingBoundary); |
207 else | 207 else |
208 pos = previousPositionOf(pos, CanSkipOverEditingBoundary); | 208 pos = previousPositionOf(pos, CanSkipOverEditingBoundary); |
209 break; | 209 break; |
210 case WordGranularity: | 210 case WordGranularity: |
211 if (directionOfEnclosingBlock() == TextDirection::Ltr) | 211 if (directionOfEnclosingBlock() == TextDirection::kLtr) |
212 pos = nextWordPositionForPlatform(pos); | 212 pos = nextWordPositionForPlatform(pos); |
213 else | 213 else |
214 pos = previousWordPosition(pos); | 214 pos = previousWordPosition(pos); |
215 break; | 215 break; |
216 case LineBoundary: | 216 case LineBoundary: |
217 if (directionOfEnclosingBlock() == TextDirection::Ltr) | 217 if (directionOfEnclosingBlock() == TextDirection::kLtr) |
218 pos = modifyExtendingForward(granularity); | 218 pos = modifyExtendingForward(granularity); |
219 else | 219 else |
220 pos = modifyExtendingBackward(granularity); | 220 pos = modifyExtendingBackward(granularity); |
221 break; | 221 break; |
222 case SentenceGranularity: | 222 case SentenceGranularity: |
223 case LineGranularity: | 223 case LineGranularity: |
224 case ParagraphGranularity: | 224 case ParagraphGranularity: |
225 case SentenceBoundary: | 225 case SentenceBoundary: |
226 case ParagraphBoundary: | 226 case ParagraphBoundary: |
227 case DocumentBoundary: | 227 case DocumentBoundary: |
228 // FIXME: implement all of the above? | 228 // FIXME: implement all of the above? |
229 pos = modifyExtendingForward(granularity); | 229 pos = modifyExtendingForward(granularity); |
230 break; | 230 break; |
231 } | 231 } |
232 adjustPositionForUserSelectAll( | 232 adjustPositionForUserSelectAll( |
233 pos, directionOfEnclosingBlock() == TextDirection::Ltr); | 233 pos, directionOfEnclosingBlock() == TextDirection::kLtr); |
234 return pos; | 234 return pos; |
235 } | 235 } |
236 | 236 |
237 VisiblePosition SelectionModifier::modifyExtendingForward( | 237 VisiblePosition SelectionModifier::modifyExtendingForward( |
238 TextGranularity granularity) { | 238 TextGranularity granularity) { |
239 VisiblePosition pos = | 239 VisiblePosition pos = |
240 createVisiblePosition(m_selection.extent(), m_selection.affinity()); | 240 createVisiblePosition(m_selection.extent(), m_selection.affinity()); |
241 switch (granularity) { | 241 switch (granularity) { |
242 case CharacterGranularity: | 242 case CharacterGranularity: |
243 pos = nextPositionOf(pos, CanSkipOverEditingBoundary); | 243 pos = nextPositionOf(pos, CanSkipOverEditingBoundary); |
(...skipping 23 matching lines...) Expand all Loading... |
267 break; | 267 break; |
268 case DocumentBoundary: | 268 case DocumentBoundary: |
269 pos = endForPlatform(); | 269 pos = endForPlatform(); |
270 if (isEditablePosition(pos.deepEquivalent())) | 270 if (isEditablePosition(pos.deepEquivalent())) |
271 pos = endOfEditableContent(pos); | 271 pos = endOfEditableContent(pos); |
272 else | 272 else |
273 pos = endOfDocument(pos); | 273 pos = endOfDocument(pos); |
274 break; | 274 break; |
275 } | 275 } |
276 adjustPositionForUserSelectAll( | 276 adjustPositionForUserSelectAll( |
277 pos, directionOfEnclosingBlock() == TextDirection::Ltr); | 277 pos, directionOfEnclosingBlock() == TextDirection::kLtr); |
278 return pos; | 278 return pos; |
279 } | 279 } |
280 | 280 |
281 VisiblePosition SelectionModifier::modifyMovingRight( | 281 VisiblePosition SelectionModifier::modifyMovingRight( |
282 TextGranularity granularity) { | 282 TextGranularity granularity) { |
283 VisiblePosition pos; | 283 VisiblePosition pos; |
284 switch (granularity) { | 284 switch (granularity) { |
285 case CharacterGranularity: | 285 case CharacterGranularity: |
286 if (m_selection.isRange()) { | 286 if (m_selection.isRange()) { |
287 if (directionOfSelection() == TextDirection::Ltr) | 287 if (directionOfSelection() == TextDirection::kLtr) |
288 pos = | 288 pos = |
289 createVisiblePosition(m_selection.end(), m_selection.affinity()); | 289 createVisiblePosition(m_selection.end(), m_selection.affinity()); |
290 else | 290 else |
291 pos = createVisiblePosition(m_selection.start(), | 291 pos = createVisiblePosition(m_selection.start(), |
292 m_selection.affinity()); | 292 m_selection.affinity()); |
293 } else { | 293 } else { |
294 pos = rightPositionOf(createVisiblePosition(m_selection.extent(), | 294 pos = rightPositionOf(createVisiblePosition(m_selection.extent(), |
295 m_selection.affinity())); | 295 m_selection.affinity())); |
296 } | 296 } |
297 break; | 297 break; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 createVisiblePosition(m_selection.extent(), m_selection.affinity()); | 383 createVisiblePosition(m_selection.extent(), m_selection.affinity()); |
384 | 384 |
385 // The difference between modifyExtendingLeft and modifyExtendingBackward is: | 385 // The difference between modifyExtendingLeft and modifyExtendingBackward is: |
386 // modifyExtendingBackward always extends backward logically. | 386 // modifyExtendingBackward always extends backward logically. |
387 // modifyExtendingLeft behaves the same as modifyExtendingBackward except for | 387 // modifyExtendingLeft behaves the same as modifyExtendingBackward except for |
388 // extending character or word, it extends backward logically if the enclosing | 388 // extending character or word, it extends backward logically if the enclosing |
389 // block is LTR direction, but it extends forward logically if the enclosing | 389 // block is LTR direction, but it extends forward logically if the enclosing |
390 // block is RTL direction. | 390 // block is RTL direction. |
391 switch (granularity) { | 391 switch (granularity) { |
392 case CharacterGranularity: | 392 case CharacterGranularity: |
393 if (directionOfEnclosingBlock() == TextDirection::Ltr) | 393 if (directionOfEnclosingBlock() == TextDirection::kLtr) |
394 pos = previousPositionOf(pos, CanSkipOverEditingBoundary); | 394 pos = previousPositionOf(pos, CanSkipOverEditingBoundary); |
395 else | 395 else |
396 pos = nextPositionOf(pos, CanSkipOverEditingBoundary); | 396 pos = nextPositionOf(pos, CanSkipOverEditingBoundary); |
397 break; | 397 break; |
398 case WordGranularity: | 398 case WordGranularity: |
399 if (directionOfEnclosingBlock() == TextDirection::Ltr) | 399 if (directionOfEnclosingBlock() == TextDirection::kLtr) |
400 pos = previousWordPosition(pos); | 400 pos = previousWordPosition(pos); |
401 else | 401 else |
402 pos = nextWordPositionForPlatform(pos); | 402 pos = nextWordPositionForPlatform(pos); |
403 break; | 403 break; |
404 case LineBoundary: | 404 case LineBoundary: |
405 if (directionOfEnclosingBlock() == TextDirection::Ltr) | 405 if (directionOfEnclosingBlock() == TextDirection::kLtr) |
406 pos = modifyExtendingBackward(granularity); | 406 pos = modifyExtendingBackward(granularity); |
407 else | 407 else |
408 pos = modifyExtendingForward(granularity); | 408 pos = modifyExtendingForward(granularity); |
409 break; | 409 break; |
410 case SentenceGranularity: | 410 case SentenceGranularity: |
411 case LineGranularity: | 411 case LineGranularity: |
412 case ParagraphGranularity: | 412 case ParagraphGranularity: |
413 case SentenceBoundary: | 413 case SentenceBoundary: |
414 case ParagraphBoundary: | 414 case ParagraphBoundary: |
415 case DocumentBoundary: | 415 case DocumentBoundary: |
416 pos = modifyExtendingBackward(granularity); | 416 pos = modifyExtendingBackward(granularity); |
417 break; | 417 break; |
418 } | 418 } |
419 adjustPositionForUserSelectAll( | 419 adjustPositionForUserSelectAll( |
420 pos, !(directionOfEnclosingBlock() == TextDirection::Ltr)); | 420 pos, !(directionOfEnclosingBlock() == TextDirection::kLtr)); |
421 return pos; | 421 return pos; |
422 } | 422 } |
423 | 423 |
424 VisiblePosition SelectionModifier::modifyExtendingBackward( | 424 VisiblePosition SelectionModifier::modifyExtendingBackward( |
425 TextGranularity granularity) { | 425 TextGranularity granularity) { |
426 VisiblePosition pos = | 426 VisiblePosition pos = |
427 createVisiblePosition(m_selection.extent(), m_selection.affinity()); | 427 createVisiblePosition(m_selection.extent(), m_selection.affinity()); |
428 | 428 |
429 // Extending a selection backward by word or character from just after a table | 429 // Extending a selection backward by word or character from just after a table |
430 // selects the table. This "makes sense" from the user perspective, esp. when | 430 // selects the table. This "makes sense" from the user perspective, esp. when |
(...skipping 28 matching lines...) Expand all Loading... |
459 break; | 459 break; |
460 case DocumentBoundary: | 460 case DocumentBoundary: |
461 pos = startForPlatform(); | 461 pos = startForPlatform(); |
462 if (isEditablePosition(pos.deepEquivalent())) | 462 if (isEditablePosition(pos.deepEquivalent())) |
463 pos = startOfEditableContent(pos); | 463 pos = startOfEditableContent(pos); |
464 else | 464 else |
465 pos = startOfDocument(pos); | 465 pos = startOfDocument(pos); |
466 break; | 466 break; |
467 } | 467 } |
468 adjustPositionForUserSelectAll( | 468 adjustPositionForUserSelectAll( |
469 pos, !(directionOfEnclosingBlock() == TextDirection::Ltr)); | 469 pos, !(directionOfEnclosingBlock() == TextDirection::kLtr)); |
470 return pos; | 470 return pos; |
471 } | 471 } |
472 | 472 |
473 VisiblePosition SelectionModifier::modifyMovingLeft( | 473 VisiblePosition SelectionModifier::modifyMovingLeft( |
474 TextGranularity granularity) { | 474 TextGranularity granularity) { |
475 VisiblePosition pos; | 475 VisiblePosition pos; |
476 switch (granularity) { | 476 switch (granularity) { |
477 case CharacterGranularity: | 477 case CharacterGranularity: |
478 if (m_selection.isRange()) { | 478 if (m_selection.isRange()) { |
479 if (directionOfSelection() == TextDirection::Ltr) | 479 if (directionOfSelection() == TextDirection::kLtr) |
480 pos = createVisiblePosition(m_selection.start(), | 480 pos = createVisiblePosition(m_selection.start(), |
481 m_selection.affinity()); | 481 m_selection.affinity()); |
482 else | 482 else |
483 pos = | 483 pos = |
484 createVisiblePosition(m_selection.end(), m_selection.affinity()); | 484 createVisiblePosition(m_selection.end(), m_selection.affinity()); |
485 } else { | 485 } else { |
486 pos = leftPositionOf(createVisiblePosition(m_selection.extent(), | 486 pos = leftPositionOf(createVisiblePosition(m_selection.extent(), |
487 m_selection.affinity())); | 487 m_selection.affinity())); |
488 } | 488 } |
489 break; | 489 break; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 if (!frame() || | 678 if (!frame() || |
679 !frame() | 679 !frame() |
680 ->editor() | 680 ->editor() |
681 .behavior() | 681 .behavior() |
682 .shouldAlwaysGrowSelectionWhenExtendingToBoundary() || | 682 .shouldAlwaysGrowSelectionWhenExtendingToBoundary() || |
683 m_selection.isCaret() || !isBoundary(granularity)) { | 683 m_selection.isCaret() || !isBoundary(granularity)) { |
684 m_selection.setExtent(position); | 684 m_selection.setExtent(position); |
685 } else { | 685 } else { |
686 TextDirection textDirection = directionOfEnclosingBlock(); | 686 TextDirection textDirection = directionOfEnclosingBlock(); |
687 if (direction == DirectionForward || | 687 if (direction == DirectionForward || |
688 (textDirection == TextDirection::Ltr && | 688 (textDirection == TextDirection::kLtr && |
689 direction == DirectionRight) || | 689 direction == DirectionRight) || |
690 (textDirection == TextDirection::Rtl && direction == DirectionLeft)) | 690 (textDirection == TextDirection::kRtl && |
| 691 direction == DirectionLeft)) |
691 setSelectionEnd(&m_selection, position); | 692 setSelectionEnd(&m_selection, position); |
692 else | 693 else |
693 setSelectionStart(&m_selection, position); | 694 setSelectionStart(&m_selection, position); |
694 } | 695 } |
695 break; | 696 break; |
696 } | 697 } |
697 | 698 |
698 if (granularity == LineGranularity || granularity == ParagraphGranularity) | 699 if (granularity == LineGranularity || granularity == ParagraphGranularity) |
699 m_xPosForVerticalArrowNavigation = x; | 700 m_xPosForVerticalArrowNavigation = x; |
700 | 701 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 | 868 |
868 return x; | 869 return x; |
869 } | 870 } |
870 | 871 |
871 DEFINE_TRACE(SelectionModifier) { | 872 DEFINE_TRACE(SelectionModifier) { |
872 visitor->trace(m_frame); | 873 visitor->trace(m_frame); |
873 visitor->trace(m_selection); | 874 visitor->trace(m_selection); |
874 } | 875 } |
875 | 876 |
876 } // namespace blink | 877 } // namespace blink |
OLD | NEW |