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

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

Issue 1864963002: Rename unchecked functions to appropriate name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo /nextGraphmeBoundaryOf/nextGraphemeBoundaryOf/ Created 4 years, 8 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 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007 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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 const int length = str.length(); 562 const int length = str.length();
563 DCHECK_EQ(TextSegmentationMachineState::NeedFollowingCodeUnit, state); 563 DCHECK_EQ(TextSegmentationMachineState::NeedFollowingCodeUnit, state);
564 for (int i = current; i < length; ++i) { 564 for (int i = current; i < length; ++i) {
565 state = machine.feedFollowingCodeUnit(str[i]); 565 state = machine.feedFollowingCodeUnit(str[i]);
566 if (state != TextSegmentationMachineState::NeedMoreCodeUnit) 566 if (state != TextSegmentationMachineState::NeedMoreCodeUnit)
567 break; 567 break;
568 } 568 }
569 return current + machine.finalizeAndGetBoundaryOffset(); 569 return current + machine.finalizeAndGetBoundaryOffset();
570 } 570 }
571 571
572 int uncheckedPreviousOffset(const Node* node, int current) 572 int previousGraphemeBoundaryOf(const Node* node, int current)
573 { 573 {
574 if (!node->isTextNode()) 574 if (!node->isTextNode())
575 return current - 1; 575 return current - 1;
576 const String& text = toText(node)->data(); 576 const String& text = toText(node)->data();
577 if (text.is8Bit()) 577 if (text.is8Bit())
578 return current - 1; // TODO(nona): Good to support CR x LF. 578 return current - 1; // TODO(nona): Good to support CR x LF.
579 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length()); 579 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length());
580 if (!iterator) 580 if (!iterator)
581 return current - 1; 581 return current - 1;
582 const int result = iterator->preceding(current); 582 const int result = iterator->preceding(current);
583 return result == TextBreakDone ? current - 1 : result; 583 return result == TextBreakDone ? current - 1 : result;
584 } 584 }
585 585
586 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int curr ent) 586 static int previousBackwardDeletionOffsetOf(const Node* node, int current)
587 { 587 {
588 DCHECK_GE(current, 0); 588 DCHECK_GE(current, 0);
589 if (current <= 1) 589 if (current <= 1)
590 return 0; 590 return 0;
591 if (!node->isTextNode()) 591 if (!node->isTextNode())
592 return current - 1; 592 return current - 1;
593 593
594 const String& text = toText(node)->data(); 594 const String& text = toText(node)->data();
595 DCHECK_LT(static_cast<unsigned>(current - 1), text.length()); 595 DCHECK_LT(static_cast<unsigned>(current - 1), text.length());
596 return findNextBoundaryOffset<BackspaceStateMachine>(text, current); 596 return findNextBoundaryOffset<BackspaceStateMachine>(text, current);
597 } 597 }
598 598
599 int uncheckedNextOffset(const Node* node, int current) 599 int nextGraphemeBoundaryOf(const Node* node, int current)
600 { 600 {
601 if (!node->isTextNode()) 601 if (!node->isTextNode())
602 return current + 1; 602 return current + 1;
603 const String& text = toText(node)->data(); 603 const String& text = toText(node)->data();
604 if (text.is8Bit()) 604 if (text.is8Bit())
605 return current + 1; // TODO(nona): Good to support CR x LF. 605 return current + 1; // TODO(nona): Good to support CR x LF.
606 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length()); 606 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length());
607 if (!iterator) 607 if (!iterator)
608 return current + 1; 608 return current + 1;
609 const int result = iterator->following(current); 609 const int result = iterator->following(current);
(...skipping 18 matching lines...) Expand all
628 // There are two reasons child might be 0: 628 // There are two reasons child might be 0:
629 // 1) The node is node like a text node that is not an element, and 629 // 1) The node is node like a text node that is not an element, and
630 // therefore has no children. Going backward one character at a 630 // therefore has no children. Going backward one character at a
631 // time is correct. 631 // time is correct.
632 // 2) The old offset was a bogus offset like (<br>, 1), and there is 632 // 2) The old offset was a bogus offset like (<br>, 1), and there is
633 // no child. Going from 1 to 0 is correct. 633 // no child. Going from 1 to 0 is correct.
634 switch (moveType) { 634 switch (moveType) {
635 case PositionMoveType::CodeUnit: 635 case PositionMoveType::CodeUnit:
636 return PositionTemplate<Strategy>(node, offset - 1); 636 return PositionTemplate<Strategy>(node, offset - 1);
637 case PositionMoveType::CodePoint: 637 case PositionMoveType::CodePoint:
638 return PositionTemplate<Strategy>(node, uncheckedPreviousOffset(node , offset)); 638 // TODO(nona): Move to PositionMoveType::GraphemeBoundary case.
639 return PositionTemplate<Strategy>(node, previousGraphemeBoundaryOf(n ode, offset));
639 case PositionMoveType::BackwardDeletion: 640 case PositionMoveType::BackwardDeletion:
640 return PositionTemplate<Strategy>(node, uncheckedPreviousOffsetForBa ckwardDeletion(node, offset)); 641 return PositionTemplate<Strategy>(node, previousBackwardDeletionOffs etOf(node, offset));
641 } 642 }
642 } 643 }
643 644
644 if (ContainerNode* parent = Strategy::parent(*node)) { 645 if (ContainerNode* parent = Strategy::parent(*node)) {
645 if (editingIgnoresContent(parent)) 646 if (editingIgnoresContent(parent))
646 return PositionTemplate<Strategy>::beforeNode(parent); 647 return PositionTemplate<Strategy>::beforeNode(parent);
647 // TODO(yosin) We should use |Strategy::index(Node&)| instead of 648 // TODO(yosin) We should use |Strategy::index(Node&)| instead of
648 // |Node::nodeIndex()|. 649 // |Node::nodeIndex()|.
649 return PositionTemplate<Strategy>(parent, node->nodeIndex()); 650 return PositionTemplate<Strategy>(parent, node->nodeIndex());
650 } 651 }
(...skipping 26 matching lines...) Expand all
677 678
678 // TODO(yosin) We should use |Strategy::lastOffsetForEditing()| instead of 679 // TODO(yosin) We should use |Strategy::lastOffsetForEditing()| instead of
679 // DOM tree version. 680 // DOM tree version.
680 if (!Strategy::hasChildren(*node) && offset < EditingStrategy::lastOffsetFor Editing(node)) { 681 if (!Strategy::hasChildren(*node) && offset < EditingStrategy::lastOffsetFor Editing(node)) {
681 // There are two reasons child might be 0: 682 // There are two reasons child might be 0:
682 // 1) The node is node like a text node that is not an element, and 683 // 1) The node is node like a text node that is not an element, and
683 // therefore has no children. Going forward one character at a time 684 // therefore has no children. Going forward one character at a time
684 // is correct. 685 // is correct.
685 // 2) The new offset is a bogus offset like (<br>, 1), and there is no 686 // 2) The new offset is a bogus offset like (<br>, 1), and there is no
686 // child. Going from 0 to 1 is correct. 687 // child. Going from 0 to 1 is correct.
687 return PositionTemplate<Strategy>::editingPositionOf(node, (moveType == PositionMoveType::CodePoint) ? uncheckedNextOffset(node, offset) : offset + 1); 688 // TODO(nona): Call nextGraphemeBoundaryOf if
689 // moveType == PositionMoveType::GraphemeBoundary
690 return PositionTemplate<Strategy>::editingPositionOf(node, (moveType == PositionMoveType::CodePoint) ? nextGraphemeBoundaryOf(node, offset) : offset + 1 );
688 } 691 }
689 692
690 if (ContainerNode* parent = Strategy::parent(*node)) 693 if (ContainerNode* parent = Strategy::parent(*node))
691 return PositionTemplate<Strategy>::editingPositionOf(parent, Strategy::i ndex(*node) + 1); 694 return PositionTemplate<Strategy>::editingPositionOf(parent, Strategy::i ndex(*node) + 1);
692 return position; 695 return position;
693 } 696 }
694 697
695 Position nextPositionOf(const Position& position, PositionMoveType moveType) 698 Position nextPositionOf(const Position& position, PositionMoveType moveType)
696 { 699 {
697 return nextPositionOfAlgorithm<EditingStrategy>(position, moveType); 700 return nextPositionOfAlgorithm<EditingStrategy>(position, moveType);
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 // instead of possibly at the end of the last node before the selection 1703 // instead of possibly at the end of the last node before the selection
1701 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); 1704 return mostForwardCaretPosition(visiblePosition.deepEquivalent());
1702 } 1705 }
1703 1706
1704 bool isTextSecurityNode(const Node* node) 1707 bool isTextSecurityNode(const Node* node)
1705 { 1708 {
1706 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE; 1709 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE;
1707 } 1710 }
1708 1711
1709 } // namespace blink 1712 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698