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

Side by Side Diff: Source/core/editing/commands/TypingCommand.cpp

Issue 1310043003: Introduce previousPositionOf() for VisiblePosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-28T16:28:03 Created 5 years, 3 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) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 if (!frame->spellChecker().isContinuousSpellCheckingEnabled()) 296 if (!frame->spellChecker().isContinuousSpellCheckingEnabled())
297 return; 297 return;
298 298
299 frame->spellChecker().cancelCheck(); 299 frame->spellChecker().cancelCheck();
300 300
301 // Take a look at the selection that results after typing and determine whet her we need to spellcheck. 301 // Take a look at the selection that results after typing and determine whet her we need to spellcheck.
302 // Since the word containing the current selection is never marked, this doe s a check to 302 // Since the word containing the current selection is never marked, this doe s a check to
303 // see if typing made a new word that is not in the current selection. Basic ally, you 303 // see if typing made a new word that is not in the current selection. Basic ally, you
304 // get this by being at the end of a word and typing a space. 304 // get this by being at the end of a word and typing a space.
305 VisiblePosition start(endingSelection().start(), endingSelection().affinity( )); 305 VisiblePosition start(endingSelection().start(), endingSelection().affinity( ));
306 VisiblePosition previous = start.previous(); 306 VisiblePosition previous = previousPositionOf(start);
307 307
308 VisiblePosition p1 = startOfWord(previous, LeftWordIfOnBoundary); 308 VisiblePosition p1 = startOfWord(previous, LeftWordIfOnBoundary);
309 309
310 if (commandType == InsertParagraphSeparator) { 310 if (commandType == InsertParagraphSeparator) {
311 VisiblePosition p2 = nextWordPosition(start); 311 VisiblePosition p2 = nextWordPosition(start);
312 VisibleSelection words(p1, endOfWord(p2)); 312 VisibleSelection words(p1, endOfWord(p2));
313 frame->spellChecker().markMisspellingsAfterLineBreak(words); 313 frame->spellChecker().markMisspellingsAfterLineBreak(words);
314 } else if (previous.isNotNull()) { 314 } else if (previous.isNotNull()) {
315 VisiblePosition p2 = startOfWord(start, LeftWordIfOnBoundary); 315 VisiblePosition p2 = startOfWord(start, LeftWordIfOnBoundary);
316 if (p1.deepEquivalent() != p2.deepEquivalent()) 316 if (p1.deepEquivalent() != p2.deepEquivalent())
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 431
432 m_smartDelete = false; 432 m_smartDelete = false;
433 433
434 OwnPtrWillBeRawPtr<FrameSelection> selection = FrameSelection::create(); 434 OwnPtrWillBeRawPtr<FrameSelection> selection = FrameSelection::create();
435 selection->setSelection(endingSelection()); 435 selection->setSelection(endingSelection());
436 selection->modify(FrameSelection::AlterationExtend, DirectionBackward, g ranularity); 436 selection->modify(FrameSelection::AlterationExtend, DirectionBackward, g ranularity);
437 if (killRing && selection->isCaret() && granularity != CharacterGranular ity) 437 if (killRing && selection->isCaret() && granularity != CharacterGranular ity)
438 selection->modify(FrameSelection::AlterationExtend, DirectionBackwar d, CharacterGranularity); 438 selection->modify(FrameSelection::AlterationExtend, DirectionBackwar d, CharacterGranularity);
439 439
440 VisiblePosition visibleStart(endingSelection().visibleStart()); 440 VisiblePosition visibleStart(endingSelection().visibleStart());
441 if (visibleStart.previous(CannotCrossEditingBoundary).isNull()) { 441 if (previousPositionOf(visibleStart, CannotCrossEditingBoundary).isNull( )) {
442 // When the caret is at the start of the editable area in an empty l ist item, break out of the list item. 442 // When the caret is at the start of the editable area in an empty l ist item, break out of the list item.
443 if (breakOutOfEmptyListItem()) { 443 if (breakOutOfEmptyListItem()) {
444 typingAddedToOpenCommand(DeleteKey); 444 typingAddedToOpenCommand(DeleteKey);
445 return; 445 return;
446 } 446 }
447 // When there are no visible positions in the editing root, delete i ts entire contents. 447 // When there are no visible positions in the editing root, delete i ts entire contents.
448 if (visibleStart.next(CannotCrossEditingBoundary).isNull() && makeEd itableRootEmpty()) { 448 if (visibleStart.next(CannotCrossEditingBoundary).isNull() && makeEd itableRootEmpty()) {
449 typingAddedToOpenCommand(DeleteKey); 449 typingAddedToOpenCommand(DeleteKey);
450 return; 450 return;
451 } 451 }
452 } 452 }
453 453
454 // If we have a caret selection at the beginning of a cell, we have noth ing to do. 454 // If we have a caret selection at the beginning of a cell, we have noth ing to do.
455 Node* enclosingTableCell = enclosingNodeOfType(visibleStart.deepEquivale nt(), &isTableCell); 455 Node* enclosingTableCell = enclosingNodeOfType(visibleStart.deepEquivale nt(), &isTableCell);
456 if (enclosingTableCell && visibleStart.deepEquivalent() == VisiblePositi on(firstPositionInNode(enclosingTableCell)).deepEquivalent()) 456 if (enclosingTableCell && visibleStart.deepEquivalent() == VisiblePositi on(firstPositionInNode(enclosingTableCell)).deepEquivalent())
457 return; 457 return;
458 458
459 // If the caret is at the start of a paragraph after a table, move conte nt into the last table cell. 459 // If the caret is at the start of a paragraph after a table, move conte nt into the last table cell.
460 if (isStartOfParagraph(visibleStart) && isFirstPositionAfterTable(visibl eStart.previous(CannotCrossEditingBoundary))) { 460 if (isStartOfParagraph(visibleStart) && isFirstPositionAfterTable(previo usPositionOf(visibleStart, CannotCrossEditingBoundary))) {
461 // Unless the caret is just before a table. We don't want to move a table into the last table cell. 461 // Unless the caret is just before a table. We don't want to move a table into the last table cell.
462 if (isLastPositionBeforeTable(visibleStart)) 462 if (isLastPositionBeforeTable(visibleStart))
463 return; 463 return;
464 // Extend the selection backward into the last cell, then deletion w ill handle the move. 464 // Extend the selection backward into the last cell, then deletion w ill handle the move.
465 selection->modify(FrameSelection::AlterationExtend, DirectionBackwar d, granularity); 465 selection->modify(FrameSelection::AlterationExtend, DirectionBackwar d, granularity);
466 // If the caret is just after a table, select the table and don't delete anything. 466 // If the caret is just after a table, select the table and don't delete anything.
467 } else if (Element* table = isFirstPositionAfterTable(visibleStart)) { 467 } else if (Element* table = isFirstPositionAfterTable(visibleStart)) {
468 setEndingSelection(VisibleSelection(positionBeforeNode(table), endin gSelection().start(), TextAffinity::Downstream, endingSelection().isDirectional( ))); 468 setEndingSelection(VisibleSelection(positionBeforeNode(table), endin gSelection().start(), TextAffinity::Downstream, endingSelection().isDirectional( )));
469 typingAddedToOpenCommand(DeleteKey); 469 typingAddedToOpenCommand(DeleteKey);
470 return; 470 return;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 ASSERT_NOT_REACHED(); 626 ASSERT_NOT_REACHED();
627 m_preservesTypingStyle = false; 627 m_preservesTypingStyle = false;
628 } 628 }
629 629
630 bool TypingCommand::isTypingCommand() const 630 bool TypingCommand::isTypingCommand() const
631 { 631 {
632 return true; 632 return true;
633 } 633 }
634 634
635 } // namespace blink 635 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/commands/ReplaceSelectionCommand.cpp ('k') | Source/core/editing/serializers/StyledMarkupSerializer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698