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

Unified Diff: third_party/WebKit/Source/core/editing/state_machines/ForwardGraphemeBoundaryStateMachine.h

Issue 1833413002: [All-in-one patch] Implement own grapheme boundary breaker for editing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Upload All-in-one patch Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/state_machines/ForwardGraphemeBoundaryStateMachine.h
diff --git a/third_party/WebKit/Source/core/editing/state_machines/ForwardGraphemeBoundaryStateMachine.h b/third_party/WebKit/Source/core/editing/state_machines/ForwardGraphemeBoundaryStateMachine.h
new file mode 100644
index 0000000000000000000000000000000000000000..a0fd6a524ad9103b63447ea1fc8025f5804c2a23
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/state_machines/ForwardGraphemeBoundaryStateMachine.h
@@ -0,0 +1,80 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ForwardGraphemeBoundaryStateMachine_h
+#define ForwardGraphemeBoundaryStateMachine_h
+
+#include "core/CoreExport.h"
+#include "core/editing/state_machines/TextSegmentationMachineState.h"
+#include "wtf/Allocator.h"
+#include "wtf/Noncopyable.h"
+#include "wtf/text/Unicode.h"
+#include <iosfwd>
+
+namespace blink {
+
+class CORE_EXPORT ForwardGraphemeBoundaryStateMachine {
+ STACK_ALLOCATED();
+ WTF_MAKE_NONCOPYABLE(ForwardGraphemeBoundaryStateMachine);
+public:
+ ForwardGraphemeBoundaryStateMachine();
+
+ // Find boundary offset by feeding preceding text.
+ // This method must not be called after feedFollowingCodeUnit().
+ TextSegmentationMachineState feedPrecedingCodeUnit(UChar codeUnit);
+
+ // Tells the end of preceding text to the state machine.
+ TextSegmentationMachineState tellEndOfPrecedingText();
+
+ // This method must be called after feedPrecedingCodeUnit() returns
+ // NeedsFollowingCodeUnit.
+ TextSegmentationMachineState feedFollowingCodeUnit(UChar codeUnit);
+
+ // Returns the next boundary offset. This method finalizes the state machine
+ // if it is not finished.
+ int finalizeAndGetBoundaryOffset();
+
+ // Resets the internal state to the initial state.
+ void reset();
+
+private:
+ enum class InternalState;
+ friend std::ostream& operator<<(std::ostream&, InternalState);
+
+ // Changes internal state to start searching grapheme cluster boundary.
+ TextSegmentationMachineState startSearchingBoundary();
+
+ // Updates the internal state to InternalState::Finished then
+ // returnsTextSegmentationMachineState::Finished.
+ TextSegmentationMachineState finish();
+
+ // Handles broken surrogate pair. This method always finishes the state
+ // machine.
+ TextSegmentationMachineState finishWithBrokenSurrogatePair();
+
+ // Handles end of text. This method always finishes the state machine.
+ TextSegmentationMachineState finishWithEndOfText();
+
+ // Used for composing supplementary code point with surrogate pairs.
+ UChar m_pendingCodeUnit = 0;
+
+ // The code point at the m_BoundaryOffset.
+ UChar32 m_nextCodePoint = 0;
+
+ // The code point immediately before the m_BoundaryOffset.
+ UChar32 m_prevCodePoint = 0;
+
+ // The relative offset from the begging of this state machine.
+ int m_boundaryOffset = 0;
+
+ // The number of regional indicator symbols preceding to the begging offset.
+ int m_precedingRISCount = 0;
+
+ // The internal state.
+ InternalState m_internalState;
+};
+
+} // namespace blink
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698