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

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

Issue 1299873002: ALL-IN-ONE Introduce enum class TextAffinity (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-19T18:08:52 Created 5 years, 4 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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // If there is a single child and it could be a placeholder, leave i t alone. 395 // If there is a single child and it could be a placeholder, leave i t alone.
396 if (root->layoutObject() && root->layoutObject()->isLayoutBlockFlow( )) 396 if (root->layoutObject() && root->layoutObject()->isLayoutBlockFlow( ))
397 return false; 397 return false;
398 } 398 }
399 } 399 }
400 400
401 while (Node* child = root->firstChild()) 401 while (Node* child = root->firstChild())
402 removeNode(child); 402 removeNode(child);
403 403
404 addBlockPlaceholderIfNeeded(root); 404 addBlockPlaceholderIfNeeded(root);
405 setEndingSelection(VisibleSelection(firstPositionInNode(root), DOWNSTREAM, e ndingSelection().isDirectional())); 405 setEndingSelection(VisibleSelection(firstPositionInNode(root), TextAffinity: :Downstream, endingSelection().isDirectional()));
406 406
407 return true; 407 return true;
408 } 408 }
409 409
410 void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool killRing) 410 void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool killRing)
411 { 411 {
412 LocalFrame* frame = document().frame(); 412 LocalFrame* frame = document().frame();
413 if (!frame) 413 if (!frame)
414 return; 414 return;
415 415
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(visibl eStart.previous(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(), 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;
471 } 471 }
472 472
473 selectionToDelete = selection->selection(); 473 selectionToDelete = selection->selection();
474 474
475 if (granularity == CharacterGranularity && selectionToDelete.end().compu teContainerNode() == selectionToDelete.start().computeContainerNode() 475 if (granularity == CharacterGranularity && selectionToDelete.end().compu teContainerNode() == selectionToDelete.start().computeContainerNode()
476 && selectionToDelete.end().computeOffsetInContainerNode() - selectio nToDelete.start().computeOffsetInContainerNode() > 1) { 476 && selectionToDelete.end().computeOffsetInContainerNode() - selectio nToDelete.start().computeOffsetInContainerNode() > 1) {
477 // If there are multiple Unicode code points to be deleted, adjust t he range to match platform conventions. 477 // If there are multiple Unicode code points to be deleted, adjust t he range to match platform conventions.
478 selectionToDelete.setWithoutValidation(selectionToDelete.end(), sele ctionToDelete.end().previous(BackwardDeletion)); 478 selectionToDelete.setWithoutValidation(selectionToDelete.end(), sele ctionToDelete.end().previous(BackwardDeletion));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 542
543 Position downstreamEnd = endingSelection().end().downstream(); 543 Position downstreamEnd = endingSelection().end().downstream();
544 VisiblePosition visibleEnd = endingSelection().visibleEnd(); 544 VisiblePosition visibleEnd = endingSelection().visibleEnd();
545 Node* enclosingTableCell = enclosingNodeOfType(visibleEnd.deepEquivalent (), &isTableCell); 545 Node* enclosingTableCell = enclosingNodeOfType(visibleEnd.deepEquivalent (), &isTableCell);
546 if (enclosingTableCell && visibleEnd.deepEquivalent() == VisiblePosition (lastPositionInNode(enclosingTableCell)).deepEquivalent()) 546 if (enclosingTableCell && visibleEnd.deepEquivalent() == VisiblePosition (lastPositionInNode(enclosingTableCell)).deepEquivalent())
547 return; 547 return;
548 if (visibleEnd.deepEquivalent() == endOfParagraph(visibleEnd).deepEquiva lent()) 548 if (visibleEnd.deepEquivalent() == endOfParagraph(visibleEnd).deepEquiva lent())
549 downstreamEnd = visibleEnd.next(CannotCrossEditingBoundary).deepEqui valent().downstream(); 549 downstreamEnd = visibleEnd.next(CannotCrossEditingBoundary).deepEqui valent().downstream();
550 // When deleting tables: Select the table first, then perform the deleti on 550 // When deleting tables: Select the table first, then perform the deleti on
551 if (isRenderedTableElement(downstreamEnd.computeContainerNode()) && down streamEnd.computeOffsetInContainerNode() <= caretMinOffset(downstreamEnd.compute ContainerNode())) { 551 if (isRenderedTableElement(downstreamEnd.computeContainerNode()) && down streamEnd.computeOffsetInContainerNode() <= caretMinOffset(downstreamEnd.compute ContainerNode())) {
552 setEndingSelection(VisibleSelection(endingSelection().end(), positio nAfterNode(downstreamEnd.computeContainerNode()), DOWNSTREAM, endingSelection(). isDirectional())); 552 setEndingSelection(VisibleSelection(endingSelection().end(), positio nAfterNode(downstreamEnd.computeContainerNode()), TextAffinity::Downstream, endi ngSelection().isDirectional()));
553 typingAddedToOpenCommand(ForwardDeleteKey); 553 typingAddedToOpenCommand(ForwardDeleteKey);
554 return; 554 return;
555 } 555 }
556 556
557 // deleting to end of paragraph when at end of paragraph needs to merge the next paragraph (if any) 557 // deleting to end of paragraph when at end of paragraph needs to merge the next paragraph (if any)
558 if (granularity == ParagraphBoundary && selection->selection().isCaret() && isEndOfParagraph(selection->selection().visibleEnd())) 558 if (granularity == ParagraphBoundary && selection->selection().isCaret() && isEndOfParagraph(selection->selection().visibleEnd()))
559 selection->modify(FrameSelection::AlterationExtend, DirectionForward , CharacterGranularity); 559 selection->modify(FrameSelection::AlterationExtend, DirectionForward , CharacterGranularity);
560 560
561 selectionToDelete = selection->selection(); 561 selectionToDelete = selection->selection();
562 if (!startingSelection().isRange() || selectionToDelete.base() != starti ngSelection().start()) { 562 if (!startingSelection().isRange() || selectionToDelete.base() != starti ngSelection().start()) {
(...skipping 63 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/InsertParagraphSeparatorCommand.cpp ('k') | Source/core/editing/spellcheck/SpellChecker.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698