/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Initialize all members, because TextRange instances may be compared by // memcomp. // // FIXME(emilio): I don't think that'd be sound, as it has padding which the // compiler is not guaranteed to initialize.
TextRangeStyle() { Clear(); }
uint32_t mStartOffset; // XXX Storing end offset makes the initializing code very complicated. // We should replace it with mLength.
uint32_t mEndOffset;
constexpr bool IsValidRawTextRangeValue(RawTextRangeType aRawTextRangeType) { switch (static_cast<TextRangeType>(aRawTextRangeType)) { case TextRangeType::eUninitialized: case TextRangeType::eCaret: case TextRangeType::eRawClause: case TextRangeType::eSelectedRawClause: case TextRangeType::eConvertedClause: case TextRangeType::eSelectedClause: returntrue; default: returnfalse;
}
}
constexpr constchar* ToChar(TextRangeType aTextRangeType) { switch (aTextRangeType) { case TextRangeType::eUninitialized: return"TextRangeType::eUninitialized"; case TextRangeType::eCaret: return"TextRangeType::eCaret"; case TextRangeType::eRawClause: return"TextRangeType::eRawClause"; case TextRangeType::eSelectedRawClause: return"TextRangeType::eSelectedRawClause"; case TextRangeType::eConvertedClause: return"TextRangeType::eConvertedClause"; case TextRangeType::eSelectedClause: return"TextRangeType::eSelectedClause"; default: return"Invalid TextRangeType";
}
}
constexpr SelectionType ToSelectionType(TextRangeType aTextRangeType) { switch (aTextRangeType) { case TextRangeType::eRawClause: return SelectionType::eIMERawClause; case TextRangeType::eSelectedRawClause: return SelectionType::eIMESelectedRawClause; case TextRangeType::eConvertedClause: return SelectionType::eIMEConvertedClause; case TextRangeType::eSelectedClause: return SelectionType::eIMESelectedClause; default:
MOZ_CRASH("TextRangeType is invalid"); return SelectionType::eNormal;
}
}
/****************************************************************************** * mozilla::TextRangeArray
******************************************************************************/ class TextRangeArray final : public AutoTArray<TextRange, 10> { friendclass WidgetCompositionEvent;
~TextRangeArray() = default;
NS_INLINE_DECL_REFCOUNTING(TextRangeArray)
const TextRange* GetTargetClause() const { for (uint32_t i = 0; i < Length(); ++i) { const TextRange& range = ElementAt(i); if (range.mRangeType == TextRangeType::eSelectedRawClause ||
range.mRangeType == TextRangeType::eSelectedClause) { return ⦥
}
} return nullptr;
}
// Returns target clause offset. If there are selected clauses, this returns // the first selected clause offset. Otherwise, 0.
uint32_t TargetClauseOffset() const { const TextRange* range = GetTargetClause(); return range ? range->mStartOffset : 0;
}
// Returns target clause length. If there are selected clauses, this returns // the first selected clause length. Otherwise, UINT32_MAX.
uint32_t TargetClauseLength() const { const TextRange* range = GetTargetClause(); return range ? range->Length() : UINT32_MAX;
}
public: bool IsComposing() const { for (uint32_t i = 0; i < Length(); ++i) { if (ElementAt(i).IsClause()) { returntrue;
}
} returnfalse;
}
bool Equals(const TextRangeArray& aOther) const {
size_t len = Length(); if (len != aOther.Length()) { returnfalse;
} for (size_t i = 0; i < len; i++) { if (!ElementAt(i).Equals(aOther.ElementAt(i))) { returnfalse;
}
} returntrue;
}
void RemoveCharacter(uint32_t aOffset) { for (size_t i = 0, len = Length(); i < len; i++) {
ElementAt(i).RemoveCharacter(aOffset);
}
}
bool HasCaret() const { for (const TextRange& range : *this) { if (range.mRangeType == TextRangeType::eCaret) { returntrue;
}
} returnfalse;
}
bool HasClauses() const { for (const TextRange& range : *this) { if (range.IsClause()) { returntrue;
}
} returnfalse;
}
uint32_t GetCaretPosition() const { for (const TextRange& range : *this) { if (range.mRangeType == TextRangeType::eCaret) { return range.mStartOffset;
}
} return UINT32_MAX;
}
const TextRange* GetFirstClause() const { for (const TextRange& range : *this) { // Look for the range of a clause whose start offset is 0 because the // first clause's start offset is always 0. if (range.IsClause() && !range.mStartOffset) { return ⦥
}
}
MOZ_ASSERT(!HasClauses()); return nullptr;
}
};
} // namespace mozilla
#endif// mozilla_TextRage_h_
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.