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

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

Issue 1657203003: Detemplatize SimplifiedBackwardsTextIterator::copyTextTo with BackwardsTextBuffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@apply_forward_buffer
Patch Set: Replace ref parameters by ptr ones Created 4 years, 10 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, 2008, 2009 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
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 21 matching lines...) Expand all
32 #include "core/dom/NodeTraversal.h" 32 #include "core/dom/NodeTraversal.h"
33 #include "core/dom/Text.h" 33 #include "core/dom/Text.h"
34 #include "core/editing/EditingUtilities.h" 34 #include "core/editing/EditingUtilities.h"
35 #include "core/editing/FrameSelection.h" 35 #include "core/editing/FrameSelection.h"
36 #include "core/editing/Position.h" 36 #include "core/editing/Position.h"
37 #include "core/editing/PositionIterator.h" 37 #include "core/editing/PositionIterator.h"
38 #include "core/editing/RenderedPosition.h" 38 #include "core/editing/RenderedPosition.h"
39 #include "core/editing/TextAffinity.h" 39 #include "core/editing/TextAffinity.h"
40 #include "core/editing/VisiblePosition.h" 40 #include "core/editing/VisiblePosition.h"
41 #include "core/editing/iterators/BackwardsCharacterIterator.h" 41 #include "core/editing/iterators/BackwardsCharacterIterator.h"
42 #include "core/editing/iterators/BackwardsTextBuffer.h"
42 #include "core/editing/iterators/CharacterIterator.h" 43 #include "core/editing/iterators/CharacterIterator.h"
43 #include "core/editing/iterators/ForwardsTextBuffer.h" 44 #include "core/editing/iterators/ForwardsTextBuffer.h"
44 #include "core/editing/iterators/SimplifiedBackwardsTextIterator.h" 45 #include "core/editing/iterators/SimplifiedBackwardsTextIterator.h"
45 #include "core/editing/iterators/TextIterator.h" 46 #include "core/editing/iterators/TextIterator.h"
46 #include "core/frame/LocalFrame.h" 47 #include "core/frame/LocalFrame.h"
47 #include "core/frame/Settings.h" 48 #include "core/frame/Settings.h"
48 #include "core/html/HTMLBRElement.h" 49 #include "core/html/HTMLBRElement.h"
49 #include "core/html/HTMLTextFormControlElement.h" 50 #include "core/html/HTMLTextFormControlElement.h"
50 #include "core/layout/HitTestRequest.h" 51 #include "core/layout/HitTestRequest.h"
51 #include "core/layout/HitTestResult.h" 52 #include "core/layout/HitTestResult.h"
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 forwardsIterator.copyTextTo(&characters); 679 forwardsIterator.copyTextTo(&characters);
679 int i = endOfFirstWordBoundaryContext(characters.data(), characters. size()); 680 int i = endOfFirstWordBoundaryContext(characters.data(), characters. size());
680 suffixString.pushRange(characters.data(), i); 681 suffixString.pushRange(characters.data(), i);
681 suffixLength += i; 682 suffixLength += i;
682 if (static_cast<unsigned>(i) < characters.size()) 683 if (static_cast<unsigned>(i) < characters.size())
683 break; 684 break;
684 forwardsIterator.advance(); 685 forwardsIterator.advance();
685 } 686 }
686 } 687 }
687 688
688 Vector<UChar, 1024> string; 689 BackwardsTextBuffer string;
689 string.append(suffixString.data(), suffixString.size()); 690 string.pushRange(suffixString.data(), suffixString.size());
690 691
691 SimplifiedBackwardsTextIteratorAlgorithm<Strategy> it(start, end); 692 SimplifiedBackwardsTextIteratorAlgorithm<Strategy> it(start, end);
692 unsigned next = 0; 693 unsigned next = 0;
693 bool needMoreContext = false; 694 bool needMoreContext = false;
694 while (!it.atEnd()) { 695 while (!it.atEnd()) {
695 bool inTextSecurityMode = it.isInTextSecurityMode(); 696 bool inTextSecurityMode = it.isInTextSecurityMode();
696 // iterate to get chunks until the searchFunction returns a non-zero 697 // iterate to get chunks until the searchFunction returns a non-zero
697 // value. 698 // value.
698 // TODO(xiaochengh): Iterative prepending has quadratic running time
699 // in the worst case. Should improve it to linear.
700 if (!inTextSecurityMode) { 699 if (!inTextSecurityMode) {
701 it.copyTextTo(string); 700 it.copyTextTo(&string);
702 } else { 701 } else {
703 // Treat bullets used in the text security mode as regular 702 // Treat bullets used in the text security mode as regular
704 // characters when looking for boundaries 703 // characters when looking for boundaries
705 Vector<UChar, 1024> iteratorString; 704 string.pushCharacters('x', it.length());
706 iteratorString.fill('x', it.length());
707 string.prepend(iteratorString.data(), iteratorString.size());
708 } 705 }
709 // TODO(xiaochengh): The following line takes O(string.size()) time, 706 // TODO(xiaochengh): The following line takes O(string.size()) time,
710 // which makes the while loop take quadratic time in the worst case. 707 // which makes the while loop take quadratic time in the worst case.
711 // Should improve it in some way. 708 // Should improve it in some way.
712 next = searchFunction(string.data(), string.size(), string.size() - suff ixLength, MayHaveMoreContext, needMoreContext); 709 next = searchFunction(string.data(), string.size(), string.size() - suff ixLength, MayHaveMoreContext, needMoreContext);
713 if (next) 710 if (next)
714 break; 711 break;
715 it.advance(); 712 it.advance();
716 } 713 }
717 if (needMoreContext) { 714 if (needMoreContext) {
(...skipping 26 matching lines...) Expand all
744 static VisiblePositionTemplate<Strategy> nextBoundary(const VisiblePositionTempl ate<Strategy>& c, BoundarySearchFunction searchFunction) 741 static VisiblePositionTemplate<Strategy> nextBoundary(const VisiblePositionTempl ate<Strategy>& c, BoundarySearchFunction searchFunction)
745 { 742 {
746 PositionTemplate<Strategy> pos = c.deepEquivalent(); 743 PositionTemplate<Strategy> pos = c.deepEquivalent();
747 Node* boundary = parentEditingBoundary(pos); 744 Node* boundary = parentEditingBoundary(pos);
748 if (!boundary) 745 if (!boundary)
749 return VisiblePositionTemplate<Strategy>(); 746 return VisiblePositionTemplate<Strategy>();
750 747
751 Document& d = boundary->document(); 748 Document& d = boundary->document();
752 const PositionTemplate<Strategy> start(pos.parentAnchoredEquivalent()); 749 const PositionTemplate<Strategy> start(pos.parentAnchoredEquivalent());
753 750
754 Vector<UChar, 1024> prefixString; 751 BackwardsTextBuffer prefixString;
755 unsigned prefixLength = 0; 752 unsigned prefixLength = 0;
756 753
757 if (requiresContextForWordBoundary(characterAfter(c))) { 754 if (requiresContextForWordBoundary(characterAfter(c))) {
758 SimplifiedBackwardsTextIteratorAlgorithm<Strategy> backwardsIterator(Pos itionTemplate<Strategy>::firstPositionInNode(&d), start); 755 SimplifiedBackwardsTextIteratorAlgorithm<Strategy> backwardsIterator(Pos itionTemplate<Strategy>::firstPositionInNode(&d), start);
759 while (!backwardsIterator.atEnd()) { 756 while (!backwardsIterator.atEnd()) {
760 // TODO(xiaochengh): Eliminate this intermediate buffer. 757 // TODO(xiaochengh): Eliminate this intermediate buffer.
761 Vector<UChar, 1024> characters; 758 BackwardsTextBuffer characters;
762 backwardsIterator.copyTextTo(characters); 759 backwardsIterator.copyTextTo(&characters);
763 int length = characters.size(); 760 int length = characters.size();
764 int i = startOfLastWordBoundaryContext(characters.data(), length); 761 int i = startOfLastWordBoundaryContext(characters.data(), length);
765 // TODO(xiaochengh): Iterative prepending has quadratic running 762 prefixString.pushRange(characters.data() + i, length - i);
766 // time in the worst case. Should improve it to linear.
767 prefixString.prepend(characters.data() + i, length - i);
768 prefixLength += length - i; 763 prefixLength += length - i;
769 if (i > 0) 764 if (i > 0)
770 break; 765 break;
771 backwardsIterator.advance(); 766 backwardsIterator.advance();
772 } 767 }
773 } 768 }
774 769
775 ForwardsTextBuffer string; 770 ForwardsTextBuffer string;
776 string.pushRange(prefixString.data(), prefixString.size()); 771 string.pushRange(prefixString.data(), prefixString.size());
777 772
(...skipping 2579 matching lines...) Expand 10 before | Expand all | Expand 10 after
3357 { 3352 {
3358 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); 3353 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule);
3359 } 3354 }
3360 3355
3361 VisiblePositionInComposedTree previousPositionOf(const VisiblePositionInComposed Tree& visiblePosition, EditingBoundaryCrossingRule rule) 3356 VisiblePositionInComposedTree previousPositionOf(const VisiblePositionInComposed Tree& visiblePosition, EditingBoundaryCrossingRule rule)
3362 { 3357 {
3363 return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePos ition, rule); 3358 return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePos ition, rule);
3364 } 3359 }
3365 3360
3366 } // namespace blink 3361 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698