mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 1678553
- part 2: Make TSFTextStore::Content
store the last composition with Maybe<OffsetAndData>
r=m_kato
When there is no composition, `Nothing` is clearer to indicate it. Differential Revision: https://phabricator.services.mozilla.com/D97948
This commit is contained in:
parent
6e9461562e
commit
eb1c061636
@ -26,6 +26,7 @@ class WritingMode;
|
||||
class MOZ_STACK_CLASS PrintStringDetail : public nsAutoCString {
|
||||
public:
|
||||
static constexpr uint32_t kMaxLengthForCompositionString = 8;
|
||||
static constexpr uint32_t kMaxLengthForEditor = 20;
|
||||
|
||||
PrintStringDetail() = delete;
|
||||
explicit PrintStringDetail(const nsAString& aString,
|
||||
|
@ -2832,18 +2832,8 @@ TSFTextStore::Content& TSFTextStore::ContentForTSFRef() {
|
||||
}
|
||||
|
||||
MOZ_LOG(sTextStoreLog, LogLevel::Debug,
|
||||
("0x%p TSFTextStore::ContentForTSFRef(): "
|
||||
"mContentForTSF={ mText=\"%s\" (Length()=%u), "
|
||||
"mLastCompositionString=\"%s\" (Length()=%u), "
|
||||
"mMinTextModifiedOffset=%u }",
|
||||
this,
|
||||
mContentForTSF.Text().Length() <= 40
|
||||
? GetEscapedUTF8String(mContentForTSF.Text()).get()
|
||||
: "<omitted>",
|
||||
mContentForTSF.Text().Length(),
|
||||
GetEscapedUTF8String(mContentForTSF.LastCompositionString()).get(),
|
||||
mContentForTSF.LastCompositionString().Length(),
|
||||
mContentForTSF.MinTextModifiedOffset()));
|
||||
("0x%p TSFTextStore::ContentForTSFRef(): mContentForTSF=%s", this,
|
||||
mozilla::ToString(mContentForTSF).c_str()));
|
||||
|
||||
return mContentForTSF;
|
||||
}
|
||||
@ -4812,9 +4802,9 @@ bool TSFTextStore::MaybeHackNoErrorLayoutBugs(LONG& aACPStart, LONG& aACPEnd) {
|
||||
// first character of composition string is stored since it was
|
||||
// selection start or caret position.
|
||||
LONG maxCachedOffset = mContentForTSF.LatestCompositionEndOffset();
|
||||
if (mContentForTSF.WasLastComposition()) {
|
||||
if (mContentForTSF.LastComposition().isSome()) {
|
||||
maxCachedOffset = std::min(
|
||||
maxCachedOffset, mContentForTSF.LastCompositionStringEndOffset());
|
||||
maxCachedOffset, mContentForTSF.LastComposition()->EndOffset());
|
||||
}
|
||||
aACPStart = std::min(aACPStart, maxCachedOffset);
|
||||
}
|
||||
@ -7111,11 +7101,14 @@ void TSFTextStore::Content::ReplaceTextWith(LONG aStart, LONG aLength,
|
||||
static_cast<uint32_t>(aLength), aReplaceString);
|
||||
// TIP may set composition string twice or more times during a document
|
||||
// lock. Therefore, we should compute the first difference offset with
|
||||
// mLastCompositionString.
|
||||
if (mComposition.DataRef() != mLastCompositionString) {
|
||||
firstDifferentOffset = mComposition.StartOffset() +
|
||||
FirstDifferentCharOffset(mComposition.DataRef(),
|
||||
mLastCompositionString);
|
||||
// mLastComposition.
|
||||
if (mLastComposition.isNothing()) {
|
||||
firstDifferentOffset = mComposition.StartOffset();
|
||||
} else if (mComposition.DataRef() != mLastComposition->DataRef()) {
|
||||
firstDifferentOffset =
|
||||
mComposition.StartOffset() +
|
||||
FirstDifferentCharOffset(mComposition.DataRef(),
|
||||
mLastComposition->DataRef());
|
||||
// The previous change to the composition string is canceled.
|
||||
if (mMinTextModifiedOffset >=
|
||||
static_cast<uint32_t>(mComposition.StartOffset()) &&
|
||||
@ -7134,11 +7127,10 @@ void TSFTextStore::Content::ReplaceTextWith(LONG aStart, LONG aLength,
|
||||
sTextStoreLog, LogLevel::Debug,
|
||||
("0x%p TSFTextStore::Content::ReplaceTextWith(aStart=%d, "
|
||||
"aLength=%d, aReplaceString=\"%s\"), mComposition=%s, "
|
||||
"mLastCompositionString=\"%s\", mMinTextModifiedOffset=%u, "
|
||||
"mLastComposition=%s, mMinTextModifiedOffset=%u, "
|
||||
"firstDifferentOffset=%u",
|
||||
this, aStart, aLength, GetEscapedUTF8String(aReplaceString).get(),
|
||||
ToString(mComposition).c_str(),
|
||||
GetEscapedUTF8String(mLastCompositionString).get(),
|
||||
ToString(mComposition).c_str(), ToString(mLastComposition).c_str(),
|
||||
mMinTextModifiedOffset, firstDifferentOffset));
|
||||
} else {
|
||||
firstDifferentOffset =
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "WritingModes.h"
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "mozilla/TextEventDispatcher.h"
|
||||
@ -810,8 +811,7 @@ class TSFTextStore final : public ITextStoreACP,
|
||||
|
||||
void Clear() {
|
||||
mText.Truncate();
|
||||
mLastCompositionString.Truncate();
|
||||
mLastCompositionStart = -1;
|
||||
mLastComposition.reset();
|
||||
mInitialized = false;
|
||||
}
|
||||
|
||||
@ -820,11 +820,9 @@ class TSFTextStore final : public ITextStoreACP,
|
||||
void Init(const nsAString& aText) {
|
||||
mText = aText;
|
||||
if (mComposition.IsComposing()) {
|
||||
mLastCompositionString = mComposition.DataRef();
|
||||
mLastCompositionStart = mComposition.StartOffset();
|
||||
mLastComposition = Some(mComposition);
|
||||
} else {
|
||||
mLastCompositionString.Truncate();
|
||||
mLastCompositionStart = -1;
|
||||
mLastComposition.reset();
|
||||
}
|
||||
mMinTextModifiedOffset = NOT_MODIFIED;
|
||||
mLatestCompositionStartOffset = mLatestCompositionEndOffset = LONG_MAX;
|
||||
@ -841,11 +839,9 @@ class TSFTextStore final : public ITextStoreACP,
|
||||
return;
|
||||
}
|
||||
if (mComposition.IsComposing()) {
|
||||
mLastCompositionString = mComposition.DataRef();
|
||||
mLastCompositionStart = mComposition.StartOffset();
|
||||
mLastComposition = Some(mComposition);
|
||||
} else {
|
||||
mLastCompositionString.Truncate();
|
||||
mLastCompositionStart = -1;
|
||||
mLastComposition.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@ -879,18 +875,9 @@ class TSFTextStore final : public ITextStoreACP,
|
||||
MOZ_ASSERT(mInitialized);
|
||||
return mText;
|
||||
}
|
||||
const nsString& LastCompositionString() const {
|
||||
const Maybe<OffsetAndData<LONG>>& LastComposition() const {
|
||||
MOZ_ASSERT(mInitialized);
|
||||
return mLastCompositionString;
|
||||
}
|
||||
LONG LastCompositionStringEndOffset() const {
|
||||
MOZ_ASSERT(mInitialized);
|
||||
MOZ_ASSERT(WasLastComposition());
|
||||
return mLastCompositionStart + mLastCompositionString.Length();
|
||||
}
|
||||
bool WasLastComposition() const {
|
||||
MOZ_ASSERT(mInitialized);
|
||||
return mLastCompositionStart >= 0;
|
||||
return mLastComposition;
|
||||
}
|
||||
uint32_t MinTextModifiedOffset() const {
|
||||
MOZ_ASSERT(mInitialized);
|
||||
@ -930,18 +917,33 @@ class TSFTextStore final : public ITextStoreACP,
|
||||
TSFTextStore::Composition& Composition() { return mComposition; }
|
||||
TSFTextStore::Selection& Selection() { return mSelection; }
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& aStream,
|
||||
const Content& aContent) {
|
||||
aStream << "{ mText="
|
||||
<< PrintStringDetail(aContent.mText,
|
||||
PrintStringDetail::kMaxLengthForEditor)
|
||||
.get()
|
||||
<< ", mLastComposition=" << aContent.mLastComposition
|
||||
<< ", mLatestCompositionStartOffset="
|
||||
<< aContent.mLatestCompositionStartOffset
|
||||
<< ", mLatestCompositionEndOffset="
|
||||
<< aContent.mLatestCompositionEndOffset
|
||||
<< ", mMinTextModifiedOffset=" << aContent.mMinTextModifiedOffset
|
||||
<< ", mInitialized=" << aContent.mInitialized << " }";
|
||||
return aStream;
|
||||
}
|
||||
|
||||
private:
|
||||
nsString mText;
|
||||
// mLastCompositionString stores the composition string when the document
|
||||
// is locked. This is necessary to compute mMinTextModifiedOffset.
|
||||
nsString mLastCompositionString;
|
||||
|
||||
// mLastComposition may store the composition string and its start offset
|
||||
// when the document is locked. This is necessary to compute
|
||||
// mMinTextModifiedOffset.
|
||||
Maybe<OffsetAndData<LONG>> mLastComposition;
|
||||
|
||||
TSFTextStore::Composition& mComposition;
|
||||
TSFTextStore::Selection& mSelection;
|
||||
|
||||
// mLastCompositionStart stores the start offset of composition when
|
||||
// mLastCompositionString is set.
|
||||
LONG mLastCompositionStart;
|
||||
|
||||
// The latest composition's start and end offset. If composition hasn't
|
||||
// been started since this instance is initialized, they are LONG_MAX.
|
||||
LONG mLatestCompositionStartOffset;
|
||||
|
Loading…
Reference in New Issue
Block a user