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

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: Introduce notifyEndOfPrecedingText. 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 14 matching lines...) Expand all
25 25
26 #include "core/editing/EditingUtilities.h" 26 #include "core/editing/EditingUtilities.h"
27 27
28 #include "core/HTMLElementFactory.h" 28 #include "core/HTMLElementFactory.h"
29 #include "core/HTMLNames.h" 29 #include "core/HTMLNames.h"
30 #include "core/dom/Document.h" 30 #include "core/dom/Document.h"
31 #include "core/dom/ElementTraversal.h" 31 #include "core/dom/ElementTraversal.h"
32 #include "core/dom/Range.h" 32 #include "core/dom/Range.h"
33 #include "core/dom/Text.h" 33 #include "core/dom/Text.h"
34 #include "core/dom/shadow/ShadowRoot.h" 34 #include "core/dom/shadow/ShadowRoot.h"
35 #include "core/editing/BackspaceStateMachine.h"
35 #include "core/editing/EditingStrategy.h" 36 #include "core/editing/EditingStrategy.h"
36 #include "core/editing/Editor.h" 37 #include "core/editing/Editor.h"
37 #include "core/editing/PlainTextRange.h" 38 #include "core/editing/PlainTextRange.h"
38 #include "core/editing/PositionIterator.h" 39 #include "core/editing/PositionIterator.h"
39 #include "core/editing/VisiblePosition.h" 40 #include "core/editing/VisiblePosition.h"
40 #include "core/editing/VisibleSelection.h" 41 #include "core/editing/VisibleSelection.h"
41 #include "core/editing/VisibleUnits.h" 42 #include "core/editing/VisibleUnits.h"
42 #include "core/editing/iterators/TextIterator.h" 43 #include "core/editing/iterators/TextIterator.h"
43 #include "core/editing/serializers/HTMLInterchange.h" 44 #include "core/editing/serializers/HTMLInterchange.h"
44 #include "core/frame/LocalFrame.h" 45 #include "core/frame/LocalFrame.h"
(...skipping 491 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 constexpr typename StateMachine::State NeedMoreCodeUnit = StateMachine::Stat e::NeedMoreCodeUnit;
yosin_UTC9 2016/03/30 07:43:07 Sorry, |constexpr| is still banned feature. But, i
Seigo Nonaka 2016/03/30 08:13:09 Sure, to address DCHECK_EQ in following comments,
551 constexpr typename StateMachine::State Finished = StateMachine::State::Finis hed;
552 constexpr typename StateMachine::State Unknown = StateMachine::State::Unknow n;
553
554 StateMachine machine;
555 typename StateMachine::State state = Unknown;
556
557 for (int i = current - 1; i >= 0; --i) {
558 state = machine.feedPrecedingCodeUnit(str[i]);
559 if (state != NeedMoreCodeUnit)
560 break;
561 }
562 if (state == NeedMoreCodeUnit)
563 state = machine.notifyEndOfPrecedingText();
564 if (state == Finished)
565 return current + machine.finalizeAndGetBoundaryOffset();
566 const int length = str.length();
yosin_UTC9 2016/03/30 07:43:07 DCHECK_EQ(StateMachine::State::NeedFollowingCodeUn
Seigo Nonaka 2016/03/30 08:13:09 Done.
567 for (int i = current; i < length; ++i) {
568 state = machine.feedFollowingCodeUnit(str[i]);
569 if (state != NeedMoreCodeUnit)
570 break;
571 }
572 return current + machine.finalizeAndGetBoundaryOffset();
573 }
574
546 int uncheckedPreviousOffset(const Node* node, int current) 575 int uncheckedPreviousOffset(const Node* node, int current)
547 { 576 {
548 if (!node->isTextNode()) 577 if (!node->isTextNode())
549 return current - 1; 578 return current - 1;
550 const String& text = toText(node)->data(); 579 const String& text = toText(node)->data();
551 if (text.is8Bit()) 580 if (text.is8Bit())
552 return current - 1; // TODO(nona): Good to support CR x LF. 581 return current - 1; // TODO(nona): Good to support CR x LF.
553 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length()); 582 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length());
554 if (!iterator) 583 if (!iterator)
555 return current - 1; 584 return current - 1;
556 const int result = iterator->preceding(current); 585 const int result = iterator->preceding(current);
557 return result == TextBreakDone ? current - 1 : result; 586 return result == TextBreakDone ? current - 1 : result;
558 } 587 }
559 588
560 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int curr ent) 589 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int curr ent)
561 { 590 {
562 DCHECK_GE(current, 0); 591 DCHECK_GE(current, 0);
563 if (current <= 1) 592 if (current <= 1)
564 return 0; 593 return 0;
565 if (!node->isTextNode()) 594 if (!node->isTextNode())
566 return current - 1; 595 return current - 1;
567 596
568 const String& text = toText(node)->data(); 597 const String& text = toText(node)->data();
569 DCHECK(static_cast<unsigned>(current - 1) < text.length()); 598 DCHECK(static_cast<unsigned>(current - 1) < text.length());
yosin_UTC9 2016/03/30 07:43:07 Oops, DCHECK_LT(static_cast<unsigned>(current), te
Seigo Nonaka 2016/03/30 08:13:09 Done.
570 if (U16_IS_TRAIL(text[--current])) 599 return findNextBoundaryOffset<BackspaceStateMachine>(text, current);
571 --current;
572 if (current < 0)
573 current = 0;
574 return current;
575 } 600 }
576 601
577 int uncheckedNextOffset(const Node* node, int current) 602 int uncheckedNextOffset(const Node* node, int current)
578 { 603 {
579 if (!node->isTextNode()) 604 if (!node->isTextNode())
580 return current + 1; 605 return current + 1;
581 const String& text = toText(node)->data(); 606 const String& text = toText(node)->data();
582 if (text.is8Bit()) 607 if (text.is8Bit())
583 return current + 1; // TODO(nona): Good to support CR x LF. 608 return current + 1; // TODO(nona): Good to support CR x LF.
584 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length()); 609 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 1702 // instead of possibly at the end of the last node before the selection
1678 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); 1703 return mostForwardCaretPosition(visiblePosition.deepEquivalent());
1679 } 1704 }
1680 1705
1681 bool isTextSecurityNode(const Node* node) 1706 bool isTextSecurityNode(const Node* node)
1682 { 1707 {
1683 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE; 1708 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE;
1684 } 1709 }
1685 1710
1686 } // namespace blink 1711 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698