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

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

Issue 1853033002: Use our own grapheme boundary handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/EditingUtilitiesTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 24 matching lines...) Expand all
35 #include "core/editing/EditingStrategy.h" 35 #include "core/editing/EditingStrategy.h"
36 #include "core/editing/Editor.h" 36 #include "core/editing/Editor.h"
37 #include "core/editing/PlainTextRange.h" 37 #include "core/editing/PlainTextRange.h"
38 #include "core/editing/PositionIterator.h" 38 #include "core/editing/PositionIterator.h"
39 #include "core/editing/VisiblePosition.h" 39 #include "core/editing/VisiblePosition.h"
40 #include "core/editing/VisibleSelection.h" 40 #include "core/editing/VisibleSelection.h"
41 #include "core/editing/VisibleUnits.h" 41 #include "core/editing/VisibleUnits.h"
42 #include "core/editing/iterators/TextIterator.h" 42 #include "core/editing/iterators/TextIterator.h"
43 #include "core/editing/serializers/HTMLInterchange.h" 43 #include "core/editing/serializers/HTMLInterchange.h"
44 #include "core/editing/state_machines/BackspaceStateMachine.h" 44 #include "core/editing/state_machines/BackspaceStateMachine.h"
45 #include "core/editing/state_machines/BackwardGraphemeBoundaryStateMachine.h"
46 #include "core/editing/state_machines/ForwardGraphemeBoundaryStateMachine.h"
45 #include "core/frame/LocalFrame.h" 47 #include "core/frame/LocalFrame.h"
46 #include "core/frame/UseCounter.h" 48 #include "core/frame/UseCounter.h"
47 #include "core/html/HTMLBRElement.h" 49 #include "core/html/HTMLBRElement.h"
48 #include "core/html/HTMLDivElement.h" 50 #include "core/html/HTMLDivElement.h"
49 #include "core/html/HTMLLIElement.h" 51 #include "core/html/HTMLLIElement.h"
50 #include "core/html/HTMLParagraphElement.h" 52 #include "core/html/HTMLParagraphElement.h"
51 #include "core/html/HTMLSpanElement.h" 53 #include "core/html/HTMLSpanElement.h"
52 #include "core/html/HTMLTableCellElement.h" 54 #include "core/html/HTMLTableCellElement.h"
53 #include "core/html/HTMLUListElement.h" 55 #include "core/html/HTMLUListElement.h"
54 #include "core/layout/LayoutObject.h" 56 #include "core/layout/LayoutObject.h"
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 int findNextBoundaryOffset(const String& str, int current) 550 int findNextBoundaryOffset(const String& str, int current)
549 { 551 {
550 StateMachine machine; 552 StateMachine machine;
551 TextSegmentationMachineState state = TextSegmentationMachineState::Invalid; 553 TextSegmentationMachineState state = TextSegmentationMachineState::Invalid;
552 554
553 for (int i = current - 1; i >= 0; --i) { 555 for (int i = current - 1; i >= 0; --i) {
554 state = machine.feedPrecedingCodeUnit(str[i]); 556 state = machine.feedPrecedingCodeUnit(str[i]);
555 if (state != TextSegmentationMachineState::NeedMoreCodeUnit) 557 if (state != TextSegmentationMachineState::NeedMoreCodeUnit)
556 break; 558 break;
557 } 559 }
558 if (state == TextSegmentationMachineState::NeedMoreCodeUnit) 560 if (current == 0 || state == TextSegmentationMachineState::NeedMoreCodeUnit)
559 state = machine.tellEndOfPrecedingText(); 561 state = machine.tellEndOfPrecedingText();
560 if (state == TextSegmentationMachineState::Finished) 562 if (state == TextSegmentationMachineState::Finished)
561 return current + machine.finalizeAndGetBoundaryOffset(); 563 return current + machine.finalizeAndGetBoundaryOffset();
562 const int length = str.length(); 564 const int length = str.length();
563 DCHECK_EQ(TextSegmentationMachineState::NeedFollowingCodeUnit, state); 565 DCHECK_EQ(TextSegmentationMachineState::NeedFollowingCodeUnit, state);
564 for (int i = current; i < length; ++i) { 566 for (int i = current; i < length; ++i) {
565 state = machine.feedFollowingCodeUnit(str[i]); 567 state = machine.feedFollowingCodeUnit(str[i]);
566 if (state != TextSegmentationMachineState::NeedMoreCodeUnit) 568 if (state != TextSegmentationMachineState::NeedMoreCodeUnit)
567 break; 569 break;
568 } 570 }
569 return current + machine.finalizeAndGetBoundaryOffset(); 571 return current + machine.finalizeAndGetBoundaryOffset();
570 } 572 }
571 573
572 int previousGraphemeBoundaryOf(const Node* node, int current) 574 int previousGraphemeBoundaryOf(const Node* node, int current)
yosin_UTC9 2016/04/07 01:06:53 Could you add TODO comment that we need to support
Seigo Nonaka 2016/04/07 03:44:59 Done.
573 { 575 {
574 if (!node->isTextNode()) 576 DCHECK_GE(current, 0);
577 if (current <= 1 || !node->isTextNode())
575 return current - 1; 578 return current - 1;
576 const String& text = toText(node)->data(); 579 const String& text = toText(node)->data();
577 if (text.is8Bit()) 580 return findNextBoundaryOffset<BackwardGraphemeBoundaryStateMachine>(
578 return current - 1; // TODO(nona): Good to support CR x LF. 581 text, current);
yosin_UTC9 2016/04/07 01:06:53 nit: Could you make this call in one line to follo
Seigo Nonaka 2016/04/07 03:44:59 Done.
579 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length());
580 if (!iterator)
581 return current - 1;
582 const int result = iterator->preceding(current);
583 return result == TextBreakDone ? current - 1 : result;
584 } 582 }
585 583
586 static int previousBackwardDeletionOffsetOf(const Node* node, int current) 584 static int previousBackwardDeletionOffsetOf(const Node* node, int current)
587 { 585 {
588 DCHECK_GE(current, 0); 586 DCHECK_GE(current, 0);
589 if (current <= 1) 587 if (current <= 1)
590 return 0; 588 return 0;
591 if (!node->isTextNode()) 589 if (!node->isTextNode())
592 return current - 1; 590 return current - 1;
593 591
594 const String& text = toText(node)->data(); 592 const String& text = toText(node)->data();
595 DCHECK_LT(static_cast<unsigned>(current - 1), text.length()); 593 DCHECK_LT(static_cast<unsigned>(current - 1), text.length());
596 return findNextBoundaryOffset<BackspaceStateMachine>(text, current); 594 return findNextBoundaryOffset<BackspaceStateMachine>(text, current);
597 } 595 }
598 596
599 int nextGraphemeBoundaryOf(const Node* node, int current) 597 int nextGraphemeBoundaryOf(const Node* node, int current)
600 { 598 {
601 if (!node->isTextNode()) 599 if (!node->isTextNode())
yosin_UTC9 2016/04/07 01:06:53 Could you add TODO comment that we need to support
Seigo Nonaka 2016/04/07 03:44:59 Done.
602 return current + 1; 600 return current + 1;
603 const String& text = toText(node)->data(); 601 const String& text = toText(node)->data();
604 if (text.is8Bit()) 602 const int length = text.length();
605 return current + 1; // TODO(nona): Good to support CR x LF. 603 DCHECK_LE(current, length);
606 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length()); 604 if (current >= (length - 1))
yosin_UTC9 2016/04/07 01:06:53 nit: We don't need to have parenthesis for |(lengt
Seigo Nonaka 2016/04/07 03:44:59 Done.
607 if (!iterator)
608 return current + 1; 605 return current + 1;
609 const int result = iterator->following(current); 606 return findNextBoundaryOffset<ForwardGraphemeBoundaryStateMachine>(
610 return result == TextBreakDone ? current + 1 : result; 607 text, current);
yosin_UTC9 2016/04/07 01:06:53 nit: Could you make this call in one line to follo
Seigo Nonaka 2016/04/07 03:44:59 Done.
611 } 608 }
612 609
613 template <typename Strategy> 610 template <typename Strategy>
614 PositionTemplate<Strategy> previousPositionOfAlgorithm(const PositionTemplate<St rategy>& position, PositionMoveType moveType) 611 PositionTemplate<Strategy> previousPositionOfAlgorithm(const PositionTemplate<St rategy>& position, PositionMoveType moveType)
615 { 612 {
616 Node* const node = position.anchorNode(); 613 Node* const node = position.anchorNode();
617 if (!node) 614 if (!node)
618 return position; 615 return position;
619 616
620 const int offset = position.computeEditingOffset(); 617 const int offset = position.computeEditingOffset();
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 // instead of possibly at the end of the last node before the selection 1700 // instead of possibly at the end of the last node before the selection
1704 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); 1701 return mostForwardCaretPosition(visiblePosition.deepEquivalent());
1705 } 1702 }
1706 1703
1707 bool isTextSecurityNode(const Node* node) 1704 bool isTextSecurityNode(const Node* node)
1708 { 1705 {
1709 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE; 1706 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE;
1710 } 1707 }
1711 1708
1712 } // namespace blink 1709 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/EditingUtilitiesTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698