зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1700051: part 31.5) Move `mSoftTextDOMMapping` to `SoftText`. r=smaug
Depends on D112544 Differential Revision: https://phabricator.services.mozilla.com/D112545
This commit is contained in:
Родитель
12f19abd5f
Коммит
c7077c610e
|
@ -832,7 +832,7 @@ void mozInlineSpellWordUtil::AdjustSoftBeginAndBuildSoftText() {
|
|||
// the soft end and *then* see a DOM word separator, a non-inline-element
|
||||
// boundary, or the hard end node.
|
||||
mSoftText.mValue.Truncate();
|
||||
mSoftTextDOMMapping.Clear();
|
||||
mSoftText.mDOMMapping.Clear();
|
||||
bool seenSoftEnd = false;
|
||||
// Leave this outside the loop so large heap string allocations can be reused
|
||||
// across iterations
|
||||
|
@ -865,15 +865,15 @@ void mozInlineSpellWordUtil::AdjustSoftBeginAndBuildSoftText() {
|
|||
|
||||
if (firstOffsetInNode < lastOffsetInNode) {
|
||||
int32_t len = lastOffsetInNode - firstOffsetInNode;
|
||||
mSoftTextDOMMapping.AppendElement(
|
||||
mSoftText.mDOMMapping.AppendElement(
|
||||
DOMTextMapping(NodeOffset(node, firstOffsetInNode),
|
||||
mSoftText.mValue.Length(), len));
|
||||
|
||||
bool ok = textFragment->AppendTo(mSoftText.mValue, firstOffsetInNode,
|
||||
len, mozilla::fallible);
|
||||
if (!ok) {
|
||||
// probably out of memory, remove from mSoftTextDOMMapping
|
||||
mSoftTextDOMMapping.RemoveLastElement();
|
||||
// probably out of memory, remove from mSoftText.mDOMMapping
|
||||
mSoftText.mDOMMapping.RemoveLastElement();
|
||||
exit = true;
|
||||
}
|
||||
}
|
||||
|
@ -942,8 +942,8 @@ int32_t mozInlineSpellWordUtil::MapDOMPositionToSoftTextOffset(
|
|||
return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < int32_t(mSoftTextDOMMapping.Length()); ++i) {
|
||||
const DOMTextMapping& map = mSoftTextDOMMapping[i];
|
||||
for (int32_t i = 0; i < int32_t(mSoftText.mDOMMapping.Length()); ++i) {
|
||||
const DOMTextMapping& map = mSoftText.mDOMMapping[i];
|
||||
if (map.mNodeOffset.mNode == aNodeOffset.mNode) {
|
||||
// Allow offsets at either end of the string, in particular, allow the
|
||||
// offset that's at the end of the contributed string
|
||||
|
@ -1005,7 +1005,7 @@ NodeOffset mozInlineSpellWordUtil::MapSoftTextOffsetToDOMPosition(
|
|||
// Find the last mapping, if any, such that mSoftTextOffset <= aSoftTextOffset
|
||||
size_t index;
|
||||
bool found =
|
||||
FindLastNongreaterOffset(mSoftTextDOMMapping, aSoftTextOffset, &index);
|
||||
FindLastNongreaterOffset(mSoftText.mDOMMapping, aSoftTextOffset, &index);
|
||||
if (!found) {
|
||||
return NodeOffset(nullptr, -1);
|
||||
}
|
||||
|
@ -1015,7 +1015,7 @@ NodeOffset mozInlineSpellWordUtil::MapSoftTextOffsetToDOMPosition(
|
|||
// If we're doing HINT_END, then we may want to return the end of the
|
||||
// the previous mapping instead of the start of this mapping
|
||||
if (aHint == HINT_END && index > 0) {
|
||||
const DOMTextMapping& map = mSoftTextDOMMapping[index - 1];
|
||||
const DOMTextMapping& map = mSoftText.mDOMMapping[index - 1];
|
||||
if (map.mSoftTextOffset + map.mLength == aSoftTextOffset)
|
||||
return NodeOffset(map.mNodeOffset.mNode,
|
||||
map.mNodeOffset.mOffset + map.mLength);
|
||||
|
@ -1024,7 +1024,7 @@ NodeOffset mozInlineSpellWordUtil::MapSoftTextOffsetToDOMPosition(
|
|||
// We allow ourselves to return the end of this mapping even if we're
|
||||
// doing HINT_START. This will only happen if there is no mapping which this
|
||||
// point is the start of. I'm not 100% sure this is OK...
|
||||
const DOMTextMapping& map = mSoftTextDOMMapping[index];
|
||||
const DOMTextMapping& map = mSoftText.mDOMMapping[index];
|
||||
int32_t offset = aSoftTextOffset - map.mSoftTextOffset;
|
||||
if (offset >= 0 && offset <= map.mLength)
|
||||
return NodeOffset(map.mNodeOffset.mNode, map.mNodeOffset.mOffset + offset);
|
||||
|
|
|
@ -120,6 +120,20 @@ class MOZ_STACK_CLASS mozInlineSpellWordUtil {
|
|||
const nsINode* GetRootNode() const { return mRootNode; }
|
||||
|
||||
private:
|
||||
// A list of where we extracted text from, ordered by mSoftTextOffset. A given
|
||||
// DOM node appears at most once in this list.
|
||||
struct DOMTextMapping {
|
||||
NodeOffset mNodeOffset;
|
||||
int32_t mSoftTextOffset;
|
||||
int32_t mLength;
|
||||
|
||||
DOMTextMapping(NodeOffset aNodeOffset, int32_t aSoftTextOffset,
|
||||
int32_t aLength)
|
||||
: mNodeOffset(aNodeOffset),
|
||||
mSoftTextOffset(aSoftTextOffset),
|
||||
mLength(aLength) {}
|
||||
};
|
||||
|
||||
struct SoftText {
|
||||
// DOM text covering the soft range, with newlines added at block boundaries
|
||||
nsString mValue;
|
||||
|
@ -128,6 +142,8 @@ class MOZ_STACK_CLASS mozInlineSpellWordUtil {
|
|||
NodeOffset mEnd = NodeOffset(nullptr, 0);
|
||||
|
||||
bool mIsValid = false;
|
||||
|
||||
nsTArray<DOMTextMapping> mDOMMapping;
|
||||
};
|
||||
|
||||
SoftText mSoftText;
|
||||
|
@ -148,21 +164,6 @@ class MOZ_STACK_CLASS mozInlineSpellWordUtil {
|
|||
// range to check, see SetPosition and SetEnd
|
||||
const nsINode* mRootNode;
|
||||
|
||||
// A list of where we extracted text from, ordered by mSoftTextOffset. A given
|
||||
// DOM node appears at most once in this list.
|
||||
struct DOMTextMapping {
|
||||
NodeOffset mNodeOffset;
|
||||
int32_t mSoftTextOffset;
|
||||
int32_t mLength;
|
||||
|
||||
DOMTextMapping(NodeOffset aNodeOffset, int32_t aSoftTextOffset,
|
||||
int32_t aLength)
|
||||
: mNodeOffset(aNodeOffset),
|
||||
mSoftTextOffset(aSoftTextOffset),
|
||||
mLength(aLength) {}
|
||||
};
|
||||
nsTArray<DOMTextMapping> mSoftTextDOMMapping;
|
||||
|
||||
// A list of the "real words" in mSoftText.mValue, ordered by mSoftTextOffset
|
||||
struct RealWord {
|
||||
int32_t mSoftTextOffset;
|
||||
|
@ -211,7 +212,8 @@ class MOZ_STACK_CLASS mozInlineSpellWordUtil {
|
|||
int32_t FindRealWordContaining(int32_t aSoftTextOffset, DOMMapHint aHint,
|
||||
bool aSearchForward) const;
|
||||
|
||||
// build mSoftText.mValue and mSoftTextDOMMapping and adjust mSoftText.mBegin.
|
||||
// build mSoftText.mValue and mSoftText.mDOMMapping and adjust
|
||||
// mSoftText.mBegin.
|
||||
void AdjustSoftBeginAndBuildSoftText();
|
||||
|
||||
mozilla::Result<RealWords, nsresult> BuildRealWords() const;
|
||||
|
|
Загрузка…
Ссылка в новой задаче