Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: third_party/WebKit/Source/core/editing/SelectionModifier.cpp

Issue 2555923002: Changed TextDirection to an enum class and renamed its members (Closed)
Patch Set: Rebase after reopen Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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() == LTR) 103 if (directionOfSelection() == TextDirection::Ltr)
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() == LTR) 112 if (directionOfSelection() == TextDirection::Ltr)
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
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() == LTR) 205 if (directionOfEnclosingBlock() == TextDirection::Ltr)
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() == LTR) 211 if (directionOfEnclosingBlock() == TextDirection::Ltr)
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() == LTR) 217 if (directionOfEnclosingBlock() == TextDirection::Ltr)
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(pos, directionOfEnclosingBlock() == LTR); 232 adjustPositionForUserSelectAll(
233 pos, directionOfEnclosingBlock() == TextDirection::Ltr);
233 return pos; 234 return pos;
234 } 235 }
235 236
236 VisiblePosition SelectionModifier::modifyExtendingForward( 237 VisiblePosition SelectionModifier::modifyExtendingForward(
237 TextGranularity granularity) { 238 TextGranularity granularity) {
238 VisiblePosition pos = 239 VisiblePosition pos =
239 createVisiblePosition(m_selection.extent(), m_selection.affinity()); 240 createVisiblePosition(m_selection.extent(), m_selection.affinity());
240 switch (granularity) { 241 switch (granularity) {
241 case CharacterGranularity: 242 case CharacterGranularity:
242 pos = nextPositionOf(pos, CanSkipOverEditingBoundary); 243 pos = nextPositionOf(pos, CanSkipOverEditingBoundary);
(...skipping 22 matching lines...) Expand all
265 pos = endOfParagraph(endForPlatform()); 266 pos = endOfParagraph(endForPlatform());
266 break; 267 break;
267 case DocumentBoundary: 268 case DocumentBoundary:
268 pos = endForPlatform(); 269 pos = endForPlatform();
269 if (isEditablePosition(pos.deepEquivalent())) 270 if (isEditablePosition(pos.deepEquivalent()))
270 pos = endOfEditableContent(pos); 271 pos = endOfEditableContent(pos);
271 else 272 else
272 pos = endOfDocument(pos); 273 pos = endOfDocument(pos);
273 break; 274 break;
274 } 275 }
275 adjustPositionForUserSelectAll(pos, directionOfEnclosingBlock() == LTR); 276 adjustPositionForUserSelectAll(
277 pos, directionOfEnclosingBlock() == TextDirection::Ltr);
276 return pos; 278 return pos;
277 } 279 }
278 280
279 VisiblePosition SelectionModifier::modifyMovingRight( 281 VisiblePosition SelectionModifier::modifyMovingRight(
280 TextGranularity granularity) { 282 TextGranularity granularity) {
281 VisiblePosition pos; 283 VisiblePosition pos;
282 switch (granularity) { 284 switch (granularity) {
283 case CharacterGranularity: 285 case CharacterGranularity:
284 if (m_selection.isRange()) { 286 if (m_selection.isRange()) {
285 if (directionOfSelection() == LTR) 287 if (directionOfSelection() == TextDirection::Ltr)
286 pos = 288 pos =
287 createVisiblePosition(m_selection.end(), m_selection.affinity()); 289 createVisiblePosition(m_selection.end(), m_selection.affinity());
288 else 290 else
289 pos = createVisiblePosition(m_selection.start(), 291 pos = createVisiblePosition(m_selection.start(),
290 m_selection.affinity()); 292 m_selection.affinity());
291 } else { 293 } else {
292 pos = rightPositionOf(createVisiblePosition(m_selection.extent(), 294 pos = rightPositionOf(createVisiblePosition(m_selection.extent(),
293 m_selection.affinity())); 295 m_selection.affinity()));
294 } 296 }
295 break; 297 break;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 createVisiblePosition(m_selection.extent(), m_selection.affinity()); 383 createVisiblePosition(m_selection.extent(), m_selection.affinity());
382 384
383 // The difference between modifyExtendingLeft and modifyExtendingBackward is: 385 // The difference between modifyExtendingLeft and modifyExtendingBackward is:
384 // modifyExtendingBackward always extends backward logically. 386 // modifyExtendingBackward always extends backward logically.
385 // modifyExtendingLeft behaves the same as modifyExtendingBackward except for 387 // modifyExtendingLeft behaves the same as modifyExtendingBackward except for
386 // extending character or word, it extends backward logically if the enclosing 388 // extending character or word, it extends backward logically if the enclosing
387 // 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
388 // block is RTL direction. 390 // block is RTL direction.
389 switch (granularity) { 391 switch (granularity) {
390 case CharacterGranularity: 392 case CharacterGranularity:
391 if (directionOfEnclosingBlock() == LTR) 393 if (directionOfEnclosingBlock() == TextDirection::Ltr)
392 pos = previousPositionOf(pos, CanSkipOverEditingBoundary); 394 pos = previousPositionOf(pos, CanSkipOverEditingBoundary);
393 else 395 else
394 pos = nextPositionOf(pos, CanSkipOverEditingBoundary); 396 pos = nextPositionOf(pos, CanSkipOverEditingBoundary);
395 break; 397 break;
396 case WordGranularity: 398 case WordGranularity:
397 if (directionOfEnclosingBlock() == LTR) 399 if (directionOfEnclosingBlock() == TextDirection::Ltr)
398 pos = previousWordPosition(pos); 400 pos = previousWordPosition(pos);
399 else 401 else
400 pos = nextWordPositionForPlatform(pos); 402 pos = nextWordPositionForPlatform(pos);
401 break; 403 break;
402 case LineBoundary: 404 case LineBoundary:
403 if (directionOfEnclosingBlock() == LTR) 405 if (directionOfEnclosingBlock() == TextDirection::Ltr)
404 pos = modifyExtendingBackward(granularity); 406 pos = modifyExtendingBackward(granularity);
405 else 407 else
406 pos = modifyExtendingForward(granularity); 408 pos = modifyExtendingForward(granularity);
407 break; 409 break;
408 case SentenceGranularity: 410 case SentenceGranularity:
409 case LineGranularity: 411 case LineGranularity:
410 case ParagraphGranularity: 412 case ParagraphGranularity:
411 case SentenceBoundary: 413 case SentenceBoundary:
412 case ParagraphBoundary: 414 case ParagraphBoundary:
413 case DocumentBoundary: 415 case DocumentBoundary:
414 pos = modifyExtendingBackward(granularity); 416 pos = modifyExtendingBackward(granularity);
415 break; 417 break;
416 } 418 }
417 adjustPositionForUserSelectAll(pos, !(directionOfEnclosingBlock() == LTR)); 419 adjustPositionForUserSelectAll(
420 pos, !(directionOfEnclosingBlock() == TextDirection::Ltr));
418 return pos; 421 return pos;
419 } 422 }
420 423
421 VisiblePosition SelectionModifier::modifyExtendingBackward( 424 VisiblePosition SelectionModifier::modifyExtendingBackward(
422 TextGranularity granularity) { 425 TextGranularity granularity) {
423 VisiblePosition pos = 426 VisiblePosition pos =
424 createVisiblePosition(m_selection.extent(), m_selection.affinity()); 427 createVisiblePosition(m_selection.extent(), m_selection.affinity());
425 428
426 // 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
427 // 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 27 matching lines...) Expand all
455 pos = startOfParagraph(startForPlatform()); 458 pos = startOfParagraph(startForPlatform());
456 break; 459 break;
457 case DocumentBoundary: 460 case DocumentBoundary:
458 pos = startForPlatform(); 461 pos = startForPlatform();
459 if (isEditablePosition(pos.deepEquivalent())) 462 if (isEditablePosition(pos.deepEquivalent()))
460 pos = startOfEditableContent(pos); 463 pos = startOfEditableContent(pos);
461 else 464 else
462 pos = startOfDocument(pos); 465 pos = startOfDocument(pos);
463 break; 466 break;
464 } 467 }
465 adjustPositionForUserSelectAll(pos, !(directionOfEnclosingBlock() == LTR)); 468 adjustPositionForUserSelectAll(
469 pos, !(directionOfEnclosingBlock() == TextDirection::Ltr));
466 return pos; 470 return pos;
467 } 471 }
468 472
469 VisiblePosition SelectionModifier::modifyMovingLeft( 473 VisiblePosition SelectionModifier::modifyMovingLeft(
470 TextGranularity granularity) { 474 TextGranularity granularity) {
471 VisiblePosition pos; 475 VisiblePosition pos;
472 switch (granularity) { 476 switch (granularity) {
473 case CharacterGranularity: 477 case CharacterGranularity:
474 if (m_selection.isRange()) { 478 if (m_selection.isRange()) {
475 if (directionOfSelection() == LTR) 479 if (directionOfSelection() == TextDirection::Ltr)
476 pos = createVisiblePosition(m_selection.start(), 480 pos = createVisiblePosition(m_selection.start(),
477 m_selection.affinity()); 481 m_selection.affinity());
478 else 482 else
479 pos = 483 pos =
480 createVisiblePosition(m_selection.end(), m_selection.affinity()); 484 createVisiblePosition(m_selection.end(), m_selection.affinity());
481 } else { 485 } else {
482 pos = leftPositionOf(createVisiblePosition(m_selection.extent(), 486 pos = leftPositionOf(createVisiblePosition(m_selection.extent(),
483 m_selection.affinity())); 487 m_selection.affinity()));
484 } 488 }
485 break; 489 break;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 if (!frame() || 678 if (!frame() ||
675 !frame() 679 !frame()
676 ->editor() 680 ->editor()
677 .behavior() 681 .behavior()
678 .shouldAlwaysGrowSelectionWhenExtendingToBoundary() || 682 .shouldAlwaysGrowSelectionWhenExtendingToBoundary() ||
679 m_selection.isCaret() || !isBoundary(granularity)) { 683 m_selection.isCaret() || !isBoundary(granularity)) {
680 m_selection.setExtent(position); 684 m_selection.setExtent(position);
681 } else { 685 } else {
682 TextDirection textDirection = directionOfEnclosingBlock(); 686 TextDirection textDirection = directionOfEnclosingBlock();
683 if (direction == DirectionForward || 687 if (direction == DirectionForward ||
684 (textDirection == LTR && direction == DirectionRight) || 688 (textDirection == TextDirection::Ltr &&
685 (textDirection == RTL && direction == DirectionLeft)) 689 direction == DirectionRight) ||
690 (textDirection == TextDirection::Rtl && direction == DirectionLeft))
686 setSelectionEnd(&m_selection, position); 691 setSelectionEnd(&m_selection, position);
687 else 692 else
688 setSelectionStart(&m_selection, position); 693 setSelectionStart(&m_selection, position);
689 } 694 }
690 break; 695 break;
691 } 696 }
692 697
693 if (granularity == LineGranularity || granularity == ParagraphGranularity) 698 if (granularity == LineGranularity || granularity == ParagraphGranularity)
694 m_xPosForVerticalArrowNavigation = x; 699 m_xPosForVerticalArrowNavigation = x;
695 700
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 867
863 return x; 868 return x;
864 } 869 }
865 870
866 DEFINE_TRACE(SelectionModifier) { 871 DEFINE_TRACE(SelectionModifier) {
867 visitor->trace(m_frame); 872 visitor->trace(m_frame);
868 visitor->trace(m_selection); 873 visitor->trace(m_selection);
869 } 874 }
870 875
871 } // namespace blink 876 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698