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

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

Issue 1833653002: Move LayoutObject::nextOffset/previousOffset() to editing utility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added test cases. 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 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 Position lastEditablePositionBeforePositionInRoot(const Position& position, Node & highestRoot) 535 Position lastEditablePositionBeforePositionInRoot(const Position& position, Node & highestRoot)
536 { 536 {
537 return lastEditablePositionBeforePositionInRootAlgorithm<EditingStrategy>(po sition, highestRoot); 537 return lastEditablePositionBeforePositionInRootAlgorithm<EditingStrategy>(po sition, highestRoot);
538 } 538 }
539 539
540 PositionInFlatTree lastEditablePositionBeforePositionInRoot(const PositionInFlat Tree& position, Node& highestRoot) 540 PositionInFlatTree lastEditablePositionBeforePositionInRoot(const PositionInFlat Tree& position, Node& highestRoot)
541 { 541 {
542 return lastEditablePositionBeforePositionInRootAlgorithm<EditingInFlatTreeSt rategy>(position, highestRoot); 542 return lastEditablePositionBeforePositionInRootAlgorithm<EditingInFlatTreeSt rategy>(position, highestRoot);
543 } 543 }
544 544
545 int uncheckedPreviousOffset(const Node* n, int current) 545 int uncheckedPreviousOffset(const Node* node, int current)
546 { 546 {
547 return n->layoutObject() ? n->layoutObject()->previousOffset(current) : curr ent - 1; 547 if (!node->isTextNode())
548 return current - 1;
549 const String& text = toText(node)->data();
550 if (text.is8Bit())
551 return current - 1; // TODO(nona): Good to support CR x LF.
552 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length());
553 if (!iterator)
554 return current - 1;
555 const int result = iterator->preceding(current);
556 return result == TextBreakDone ? current - 1 : result;
548 } 557 }
549 558
550 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current ) 559 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current )
551 { 560 {
552 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet ion(current) : current - 1; 561 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet ion(current) : current - 1;
553 } 562 }
554 563
555 int uncheckedNextOffset(const Node* n, int current) 564 int uncheckedNextOffset(const Node* node, int current)
556 { 565 {
557 return n->layoutObject() ? n->layoutObject()->nextOffset(current) : current + 1; 566 if (!node->isTextNode())
567 return current + 1;
568 const String& text = toText(node)->data();
569 if (text.is8Bit())
570 return current + 1; // TODO(nona): Good to support CR x LF.
571 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length());
572 if (!iterator)
573 return current + 1;
574 const int result = iterator->following(current);
575 return result == TextBreakDone ? current + 1 : result;
558 } 576 }
559 577
560 template <typename Strategy> 578 template <typename Strategy>
561 PositionTemplate<Strategy> previousPositionOfAlgorithm(const PositionTemplate<St rategy>& position, PositionMoveType moveType) 579 PositionTemplate<Strategy> previousPositionOfAlgorithm(const PositionTemplate<St rategy>& position, PositionMoveType moveType)
562 { 580 {
563 Node* const node = position.anchorNode(); 581 Node* const node = position.anchorNode();
564 if (!node) 582 if (!node)
565 return position; 583 return position;
566 584
567 const int offset = position.computeEditingOffset(); 585 const int offset = position.computeEditingOffset();
(...skipping 1078 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 // instead of possibly at the end of the last node before the selection 1664 // instead of possibly at the end of the last node before the selection
1647 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); 1665 return mostForwardCaretPosition(visiblePosition.deepEquivalent());
1648 } 1666 }
1649 1667
1650 bool isTextSecurityNode(const Node* node) 1668 bool isTextSecurityNode(const Node* node)
1651 { 1669 {
1652 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE; 1670 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE;
1653 } 1671 }
1654 1672
1655 } // namespace blink 1673 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698