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

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: 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* n, int current)
yosin_UTC9 2016/03/25 04:13:30 Could you avoid to use one letter variable name?
Seigo Nonaka 2016/03/25 05:11:22 Done.
546 { 546 {
547 return n->layoutObject() ? n->layoutObject()->previousOffset(current) : curr ent - 1; 547 if (!n->isTextNode())
tkent 2016/03/25 04:34:08 Is it ok to remove n->layoutObject() check in the
yosin_UTC9 2016/03/25 04:57:53 Yes. Using |LayoutObject::previousOffset()| is wro
tkent 2016/03/25 05:05:25 I asked about a case of no LayoutObject. Anyway, w
Seigo Nonaka 2016/03/25 05:11:21 Sure, I'm happy to add these test case but let me
Seigo Nonaka 2016/03/25 05:11:22 Thank you for your follow-up comment. Let me add o
yosin_UTC9 2016/03/25 05:50:04 Oh, sorry for confusion. |return n->layoutObject(
Seigo Nonaka 2016/03/25 08:02:41 Added test cases for first-letter and text-transfo
yosin_UTC9 2016/03/25 08:18:55 You need to call |updateLayoutAndStyleForPainting(
548 return current - 1;
549 const String& text = toText(n)->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 long result = iterator->preceding(current);
yosin_UTC9 2016/03/25 04:13:30 |int| is better since |TextBreakIterator::precedin
Seigo Nonaka 2016/03/25 05:11:22 Done.
556 if (result == TextBreakDone)
yosin_UTC9 2016/03/25 04:13:30 Use ternary or early return: return reuslt == Tex
Seigo Nonaka 2016/03/25 05:11:21 Done.
557 result = current - 1;
558 return result;
548 } 559 }
549 560
550 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current ) 561 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current )
551 { 562 {
552 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet ion(current) : current - 1; 563 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet ion(current) : current - 1;
553 } 564 }
554 565
555 int uncheckedNextOffset(const Node* n, int current) 566 int uncheckedNextOffset(const Node* n, int current)
556 { 567 {
557 return n->layoutObject() ? n->layoutObject()->nextOffset(current) : current + 1; 568 if (!n->isTextNode())
569 return current + 1;
570 const String& text = toText(n)->data();
571 if (text.is8Bit())
572 return current + 1; // TODO(nona): Good to support CR x LF.
573 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length());
574 if (!iterator)
575 return current + 1;
576 long result = iterator->following(current);
yosin_UTC9 2016/03/25 04:13:30 |int| is better since |TextBreakIterator::followin
Seigo Nonaka 2016/03/25 05:11:21 Done.
577 if (result == TextBreakDone)
yosin_UTC9 2016/03/25 04:13:30 Use ternary or early return: return reuslt == Tex
Seigo Nonaka 2016/03/25 05:11:22 Done.
578 result = current + 1;
579 return result;
558 } 580 }
559 581
560 template <typename Strategy> 582 template <typename Strategy>
561 PositionTemplate<Strategy> previousPositionOfAlgorithm(const PositionTemplate<St rategy>& position, PositionMoveType moveType) 583 PositionTemplate<Strategy> previousPositionOfAlgorithm(const PositionTemplate<St rategy>& position, PositionMoveType moveType)
562 { 584 {
563 Node* const node = position.anchorNode(); 585 Node* const node = position.anchorNode();
564 if (!node) 586 if (!node)
565 return position; 587 return position;
566 588
567 const int offset = position.computeEditingOffset(); 589 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 1668 // instead of possibly at the end of the last node before the selection
1647 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); 1669 return mostForwardCaretPosition(visiblePosition.deepEquivalent());
1648 } 1670 }
1649 1671
1650 bool isTextSecurityNode(const Node* node) 1672 bool isTextSecurityNode(const Node* node)
1651 { 1673 {
1652 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE; 1674 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE;
1653 } 1675 }
1654 1676
1655 } // namespace blink 1677 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698