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

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

Issue 1839753005: Move state machines to state_machines subdir (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix style errr 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 23 matching lines...) Expand all
34 #include "core/dom/shadow/ShadowRoot.h" 34 #include "core/dom/shadow/ShadowRoot.h"
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/frame/LocalFrame.h" 45 #include "core/frame/LocalFrame.h"
45 #include "core/frame/UseCounter.h" 46 #include "core/frame/UseCounter.h"
46 #include "core/html/HTMLBRElement.h" 47 #include "core/html/HTMLBRElement.h"
47 #include "core/html/HTMLDivElement.h" 48 #include "core/html/HTMLDivElement.h"
48 #include "core/html/HTMLLIElement.h" 49 #include "core/html/HTMLLIElement.h"
49 #include "core/html/HTMLParagraphElement.h" 50 #include "core/html/HTMLParagraphElement.h"
50 #include "core/html/HTMLSpanElement.h" 51 #include "core/html/HTMLSpanElement.h"
51 #include "core/html/HTMLTableCellElement.h" 52 #include "core/html/HTMLTableCellElement.h"
52 #include "core/html/HTMLUListElement.h" 53 #include "core/html/HTMLUListElement.h"
53 #include "core/layout/LayoutObject.h" 54 #include "core/layout/LayoutObject.h"
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 Position lastEditablePositionBeforePositionInRoot(const Position& position, Node & highestRoot) 537 Position lastEditablePositionBeforePositionInRoot(const Position& position, Node & highestRoot)
537 { 538 {
538 return lastEditablePositionBeforePositionInRootAlgorithm<EditingStrategy>(po sition, highestRoot); 539 return lastEditablePositionBeforePositionInRootAlgorithm<EditingStrategy>(po sition, highestRoot);
539 } 540 }
540 541
541 PositionInFlatTree lastEditablePositionBeforePositionInRoot(const PositionInFlat Tree& position, Node& highestRoot) 542 PositionInFlatTree lastEditablePositionBeforePositionInRoot(const PositionInFlat Tree& position, Node& highestRoot)
542 { 543 {
543 return lastEditablePositionBeforePositionInRootAlgorithm<EditingInFlatTreeSt rategy>(position, highestRoot); 544 return lastEditablePositionBeforePositionInRootAlgorithm<EditingInFlatTreeSt rategy>(position, highestRoot);
544 } 545 }
545 546
547 template<typename StateMachine>
548 int findNextBoundaryOffset(const String& str, int current)
549 {
550 StateMachine machine;
551 TextSegmentationMachineState state = TextSegmentationMachineState::Invalid;
552
553 for (int i = current - 1; i >= 0; --i) {
554 state = machine.feedPrecedingCodeUnit(str[i]);
555 if (state != TextSegmentationMachineState::NeedMoreCodeUnit)
556 break;
557 }
558 if (state == TextSegmentationMachineState::NeedMoreCodeUnit)
559 state = machine.tellEndOfPrecedingText();
560 if (state == TextSegmentationMachineState::Finished)
561 return current + machine.finalizeAndGetBoundaryOffset();
562 const int length = str.length();
563 DCHECK_EQ(TextSegmentationMachineState::NeedFollowingCodeUnit, state);
564 for (int i = current; i < length; ++i) {
565 state = machine.feedFollowingCodeUnit(str[i]);
566 if (state != TextSegmentationMachineState::NeedMoreCodeUnit)
567 break;
568 }
569 return current + machine.finalizeAndGetBoundaryOffset();
570 }
571
546 int uncheckedPreviousOffset(const Node* node, int current) 572 int uncheckedPreviousOffset(const Node* node, int current)
547 { 573 {
548 if (!node->isTextNode()) 574 if (!node->isTextNode())
549 return current - 1; 575 return current - 1;
550 const String& text = toText(node)->data(); 576 const String& text = toText(node)->data();
551 if (text.is8Bit()) 577 if (text.is8Bit())
552 return current - 1; // TODO(nona): Good to support CR x LF. 578 return current - 1; // TODO(nona): Good to support CR x LF.
553 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length()); 579 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length());
554 if (!iterator) 580 if (!iterator)
555 return current - 1; 581 return current - 1;
556 const int result = iterator->preceding(current); 582 const int result = iterator->preceding(current);
557 return result == TextBreakDone ? current - 1 : result; 583 return result == TextBreakDone ? current - 1 : result;
558 } 584 }
559 585
560 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int curr ent) 586 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int curr ent)
561 { 587 {
562 DCHECK_GE(current, 0); 588 DCHECK_GE(current, 0);
563 if (current <= 1) 589 if (current <= 1)
564 return 0; 590 return 0;
565 if (!node->isTextNode()) 591 if (!node->isTextNode())
566 return current - 1; 592 return current - 1;
567 593
568 const String& text = toText(node)->data(); 594 const String& text = toText(node)->data();
569 DCHECK(static_cast<unsigned>(current - 1) < text.length()); 595 DCHECK_LT(static_cast<unsigned>(current - 1), text.length());
570 if (U16_IS_TRAIL(text[--current])) 596 return findNextBoundaryOffset<BackspaceStateMachine>(text, current);
571 --current;
572 if (current < 0)
573 current = 0;
574 return current;
575 } 597 }
576 598
577 int uncheckedNextOffset(const Node* node, int current) 599 int uncheckedNextOffset(const Node* node, int current)
578 { 600 {
579 if (!node->isTextNode()) 601 if (!node->isTextNode())
580 return current + 1; 602 return current + 1;
581 const String& text = toText(node)->data(); 603 const String& text = toText(node)->data();
582 if (text.is8Bit()) 604 if (text.is8Bit())
583 return current + 1; // TODO(nona): Good to support CR x LF. 605 return current + 1; // TODO(nona): Good to support CR x LF.
584 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length()); 606 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length());
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 // instead of possibly at the end of the last node before the selection 1699 // instead of possibly at the end of the last node before the selection
1678 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); 1700 return mostForwardCaretPosition(visiblePosition.deepEquivalent());
1679 } 1701 }
1680 1702
1681 bool isTextSecurityNode(const Node* node) 1703 bool isTextSecurityNode(const Node* node)
1682 { 1704 {
1683 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE; 1705 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE;
1684 } 1706 }
1685 1707
1686 } // namespace blink 1708 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698