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

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

Issue 1824143003: [All-In-One] Introduce BackspaceStateMachine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased to HEAD 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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 const String& text = toText(node)->data(); 550 const String& text = toText(node)->data();
550 if (text.is8Bit()) 551 if (text.is8Bit())
551 return current - 1; // TODO(nona): Good to support CR x LF. 552 return current - 1; // TODO(nona): Good to support CR x LF.
552 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length()); 553 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length());
553 if (!iterator) 554 if (!iterator)
554 return current - 1; 555 return current - 1;
555 const int result = iterator->preceding(current); 556 const int result = iterator->preceding(current);
556 return result == TextBreakDone ? current - 1 : result; 557 return result == TextBreakDone ? current - 1 : result;
557 } 558 }
558 559
559 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current ) 560 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* node, int curr ent)
560 { 561 {
yosin_UTC9 2016/03/28 05:05:47 Could you add DCHECK_GE(current, 0)?
Seigo Nonaka 2016/03/28 07:28:12 Done.
561 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet ion(current) : current - 1; 562 if (current <= 1)
563 return 0;
564 if (!node->isTextNode())
565 return current - 1;
566
567 const String& text = toText(node)->data();
568 CHECK(static_cast<unsigned>(current - 1) < text.length());
569 BackspaceStateMachine machine;
570 for (int i = current - 1; i >= 0; --i) {
571 if (machine.updateState(text[i]))
572 break;
573 }
574 return current - machine.finalizeAndGetCodeUnitCountToBeDeleted();
yosin_UTC9 2016/03/28 05:05:47 Could you check |current| >= 0? e.g. int amount =
Seigo Nonaka 2016/03/28 07:28:11 Done.
562 } 575 }
563 576
564 int uncheckedNextOffset(const Node* node, int current) 577 int uncheckedNextOffset(const Node* node, int current)
565 { 578 {
566 if (!node->isTextNode()) 579 if (!node->isTextNode())
567 return current + 1; 580 return current + 1;
568 const String& text = toText(node)->data(); 581 const String& text = toText(node)->data();
569 if (text.is8Bit()) 582 if (text.is8Bit())
570 return current + 1; // TODO(nona): Good to support CR x LF. 583 return current + 1; // TODO(nona): Good to support CR x LF.
571 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length()); 584 TextBreakIterator* iterator = cursorMovementIterator(text.characters16(), te xt.length());
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 // instead of possibly at the end of the last node before the selection 1677 // instead of possibly at the end of the last node before the selection
1665 return mostForwardCaretPosition(visiblePosition.deepEquivalent()); 1678 return mostForwardCaretPosition(visiblePosition.deepEquivalent());
1666 } 1679 }
1667 1680
1668 bool isTextSecurityNode(const Node* node) 1681 bool isTextSecurityNode(const Node* node)
1669 { 1682 {
1670 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE; 1683 return node && node->layoutObject() && node->layoutObject()->style()->textSe curity() != TSNONE;
1671 } 1684 }
1672 1685
1673 } // namespace blink 1686 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698