mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1277756 part.1 Make anonymous enum for NS_TEXTRANGE_* to an enum class named "TextRangeType" r=smaug
For making our code clearer by the stronger type check, we should change the anonymous enum for NS_TEXTRANGE_* to enum class whose name is "TextRangeType" and whose type is "RawTextRangeType" which is an alias of uint8_t. Additionally, this also adds some utility methods for them. Note that some lines which are changed by this patch become over 80 characters but it will be fixed by the following patches. MozReview-Commit-ID: 76izA1WqTkp --HG-- extra : rebase_source : 27cd8cc8f7f8e82055dbfe82aba94c02beda5fa4
This commit is contained in:
parent
6cb8ad8742
commit
4fc95828b6
@ -422,11 +422,13 @@ TextInputProcessor::AppendClauseToPendingComposition(uint32_t aLength,
|
||||
{
|
||||
MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome());
|
||||
RefPtr<TextEventDispatcher> kungfuDeathGrip(mDispatcher);
|
||||
TextRangeType textRangeType;
|
||||
switch (aAttribute) {
|
||||
case ATTR_RAW_CLAUSE:
|
||||
case ATTR_SELECTED_RAW_CLAUSE:
|
||||
case ATTR_CONVERTED_CLAUSE:
|
||||
case ATTR_SELECTED_CLAUSE:
|
||||
textRangeType = ToTextRangeType(aAttribute);
|
||||
break;
|
||||
default:
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
@ -435,7 +437,7 @@ TextInputProcessor::AppendClauseToPendingComposition(uint32_t aLength,
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
return mDispatcher->AppendClauseToPendingComposition(aLength, aAttribute);
|
||||
return mDispatcher->AppendClauseToPendingComposition(aLength, textRangeType);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -886,16 +886,16 @@ nsPluginInstanceOwner::GetCompositionString(uint32_t aType,
|
||||
for (TextRange& range : *ranges) {
|
||||
uint8_t type = ATTR_INPUT;
|
||||
switch(range.mRangeType) {
|
||||
case NS_TEXTRANGE_RAWINPUT:
|
||||
case TextRangeType::NS_TEXTRANGE_RAWINPUT:
|
||||
type = ATTR_INPUT;
|
||||
break;
|
||||
case NS_TEXTRANGE_SELECTEDRAWTEXT:
|
||||
case TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT:
|
||||
type = ATTR_TARGET_NOTCONVERTED;
|
||||
break;
|
||||
case NS_TEXTRANGE_CONVERTEDTEXT:
|
||||
case TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT:
|
||||
type = ATTR_CONVERTED;
|
||||
break;
|
||||
case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
|
||||
case TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
|
||||
type = ATTR_TARGET_CONVERTED;
|
||||
break;
|
||||
default:
|
||||
|
@ -135,16 +135,16 @@ IMETextTxn::GetTxnDescription(nsAString& aString)
|
||||
|
||||
/* ============ private methods ================== */
|
||||
static SelectionType
|
||||
ToSelectionType(uint32_t aTextRangeType)
|
||||
ToSelectionType(TextRangeType aTextRangeType)
|
||||
{
|
||||
switch(aTextRangeType) {
|
||||
case NS_TEXTRANGE_RAWINPUT:
|
||||
switch (aTextRangeType) {
|
||||
case TextRangeType::NS_TEXTRANGE_RAWINPUT:
|
||||
return nsISelectionController::SELECTION_IME_RAWINPUT;
|
||||
case NS_TEXTRANGE_SELECTEDRAWTEXT:
|
||||
case TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT:
|
||||
return nsISelectionController::SELECTION_IME_SELECTEDRAWTEXT;
|
||||
case NS_TEXTRANGE_CONVERTEDTEXT:
|
||||
case TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT:
|
||||
return nsISelectionController::SELECTION_IME_CONVERTEDTEXT;
|
||||
case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
|
||||
case TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
|
||||
return nsISelectionController::SELECTION_IME_SELECTEDCONVERTEDTEXT;
|
||||
default:
|
||||
MOZ_CRASH("Selection type is invalid");
|
||||
@ -213,7 +213,7 @@ IMETextTxn::SetIMESelection(nsEditor& aEditor,
|
||||
|
||||
// Caret needs special handling since its length may be 0 and if it's not
|
||||
// specified explicitly, we need to handle it ourselves later.
|
||||
if (textRange.mRangeType == NS_TEXTRANGE_CARETPOSITION) {
|
||||
if (textRange.mRangeType == TextRangeType::NS_TEXTRANGE_CARETPOSITION) {
|
||||
NS_ASSERTION(!setCaret, "The ranges already has caret position");
|
||||
NS_ASSERTION(!textRange.Length(), "nsEditor doesn't support wide caret");
|
||||
int32_t caretOffset = static_cast<int32_t>(
|
||||
|
@ -2422,7 +2422,7 @@ nsEditor::InsertTextIntoTextNodeImpl(const nsAString& aStringToInsert,
|
||||
for (uint32_t i = 0; i < (ranges ? ranges->Length() : 0); ++i) {
|
||||
const TextRange& textRange = ranges->ElementAt(i);
|
||||
if (!textRange.Length() ||
|
||||
textRange.mRangeType != NS_TEXTRANGE_RAWINPUT) {
|
||||
textRange.mRangeType != TextRangeType::NS_TEXTRANGE_RAWINPUT) {
|
||||
continue;
|
||||
}
|
||||
if (!mPhonetic) {
|
||||
|
@ -151,6 +151,9 @@ typedef nsTArray<ShortcutKeyCandidate> ShortcutKeyCandidateArray;
|
||||
typedef AutoTArray<ShortcutKeyCandidate, 10> AutoShortcutKeyCandidateArray;
|
||||
|
||||
// TextRange.h
|
||||
typedef uint8_t RawTextRangeType;
|
||||
enum class TextRangeType : RawTextRangeType;
|
||||
|
||||
struct TextRangeStyle;
|
||||
struct TextRange;
|
||||
|
||||
|
@ -595,7 +595,7 @@ TextEventDispatcher::PendingComposition::Clear()
|
||||
{
|
||||
mString.Truncate();
|
||||
mClauses = nullptr;
|
||||
mCaret.mRangeType = 0;
|
||||
mCaret.mRangeType = TextRangeType::NS_TEXTRANGE_UNDEFINED;
|
||||
}
|
||||
|
||||
void
|
||||
@ -615,24 +615,25 @@ TextEventDispatcher::PendingComposition::SetString(const nsAString& aString)
|
||||
}
|
||||
|
||||
nsresult
|
||||
TextEventDispatcher::PendingComposition::AppendClause(uint32_t aLength,
|
||||
uint32_t aAttribute)
|
||||
TextEventDispatcher::PendingComposition::AppendClause(
|
||||
uint32_t aLength,
|
||||
TextRangeType aTextRangeType)
|
||||
{
|
||||
if (NS_WARN_IF(!aLength)) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
switch (aAttribute) {
|
||||
case NS_TEXTRANGE_RAWINPUT:
|
||||
case NS_TEXTRANGE_SELECTEDRAWTEXT:
|
||||
case NS_TEXTRANGE_CONVERTEDTEXT:
|
||||
case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT: {
|
||||
switch (aTextRangeType) {
|
||||
case TextRangeType::NS_TEXTRANGE_RAWINPUT:
|
||||
case TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT:
|
||||
case TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT:
|
||||
case TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT: {
|
||||
EnsureClauseArray();
|
||||
TextRange textRange;
|
||||
textRange.mStartOffset =
|
||||
mClauses->IsEmpty() ? 0 : mClauses->LastElement().mEndOffset;
|
||||
textRange.mEndOffset = textRange.mStartOffset + aLength;
|
||||
textRange.mRangeType = aAttribute;
|
||||
textRange.mRangeType = aTextRangeType;
|
||||
mClauses->AppendElement(textRange);
|
||||
return NS_OK;
|
||||
}
|
||||
@ -647,7 +648,7 @@ TextEventDispatcher::PendingComposition::SetCaret(uint32_t aOffset,
|
||||
{
|
||||
mCaret.mStartOffset = aOffset;
|
||||
mCaret.mEndOffset = mCaret.mStartOffset + aLength;
|
||||
mCaret.mRangeType = NS_TEXTRANGE_CARETPOSITION;
|
||||
mCaret.mRangeType = TextRangeType::NS_TEXTRANGE_CARETPOSITION;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -668,7 +669,7 @@ TextEventDispatcher::PendingComposition::Set(const nsAString& aString,
|
||||
if (!aRanges || aRanges->IsEmpty()) {
|
||||
// Create dummy range if aString isn't empty.
|
||||
if (!aString.IsEmpty()) {
|
||||
rv = AppendClause(str.Length(), NS_TEXTRANGE_RAWINPUT);
|
||||
rv = AppendClause(str.Length(), TextRangeType::NS_TEXTRANGE_RAWINPUT);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
@ -698,7 +699,7 @@ TextEventDispatcher::PendingComposition::Set(const nsAString& aString,
|
||||
NS_LITERAL_STRING("\n"));
|
||||
range.mEndOffset = range.mStartOffset + clause.Length();
|
||||
}
|
||||
if (range.mRangeType == NS_TEXTRANGE_CARETPOSITION) {
|
||||
if (range.mRangeType == TextRangeType::NS_TEXTRANGE_CARETPOSITION) {
|
||||
mCaret = range;
|
||||
} else {
|
||||
EnsureClauseArray();
|
||||
@ -728,7 +729,7 @@ TextEventDispatcher::PendingComposition::Flush(
|
||||
Clear();
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
if (mCaret.mRangeType == NS_TEXTRANGE_CARETPOSITION) {
|
||||
if (mCaret.mRangeType == TextRangeType::NS_TEXTRANGE_CARETPOSITION) {
|
||||
if (mCaret.mEndOffset > mString.Length()) {
|
||||
NS_WARNING("Caret position is out of the composition string");
|
||||
Clear();
|
||||
|
@ -152,15 +152,15 @@ public:
|
||||
* the pending composition string.
|
||||
*
|
||||
* @param aLength Length of the clause.
|
||||
* @param aAttribute One of NS_TEXTRANGE_RAWINPUT,
|
||||
* @param aTextRangeType One of NS_TEXTRANGE_RAWINPUT,
|
||||
* NS_TEXTRANGE_SELECTEDRAWTEXT,
|
||||
* NS_TEXTRANGE_CONVERTEDTEXT or
|
||||
* NS_TEXTRANGE_SELECTEDCONVERTEDTEXT.
|
||||
*/
|
||||
nsresult AppendClauseToPendingComposition(uint32_t aLength,
|
||||
uint32_t aAttribute)
|
||||
TextRangeType aTextRangeType)
|
||||
{
|
||||
return mPendingComposition.AppendClause(aLength, aAttribute);
|
||||
return mPendingComposition.AppendClause(aLength, aTextRangeType);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -304,7 +304,7 @@ private:
|
||||
public:
|
||||
PendingComposition();
|
||||
nsresult SetString(const nsAString& aString);
|
||||
nsresult AppendClause(uint32_t aLength, uint32_t aAttribute);
|
||||
nsresult AppendClause(uint32_t aLength, TextRangeType aTextRangeType);
|
||||
nsresult SetCaret(uint32_t aOffset, uint32_t aLength);
|
||||
nsresult Set(const nsAString& aString, const TextRangeArray* aRanges);
|
||||
nsresult Flush(TextEventDispatcher* aDispatcher,
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "mozilla/EventForwards.h"
|
||||
|
||||
#include "nsColor.h"
|
||||
#include "nsITextInputProcessor.h"
|
||||
#include "nsStyleConsts.h"
|
||||
@ -126,8 +128,7 @@ struct TextRangeStyle
|
||||
* mozilla::TextRange
|
||||
******************************************************************************/
|
||||
|
||||
// XXX NS_TEXTRANGE_* should be moved into TextRange as an typed enum.
|
||||
enum
|
||||
enum class TextRangeType : RawTextRangeType
|
||||
{
|
||||
NS_TEXTRANGE_UNDEFINED = 0x00,
|
||||
NS_TEXTRANGE_CARETPOSITION = 0x01,
|
||||
@ -141,10 +142,17 @@ enum
|
||||
nsITextInputProcessor::ATTR_SELECTED_CLAUSE
|
||||
};
|
||||
|
||||
bool IsValidRawTextRangeValue(RawTextRangeType aRawTextRangeValue);
|
||||
RawTextRangeType ToRawTextRangeType(TextRangeType aTextRangeType);
|
||||
TextRangeType ToTextRangeType(RawTextRangeType aRawTextRangeType);
|
||||
const char* ToChar(TextRangeType aTextRangeType);
|
||||
|
||||
struct TextRange
|
||||
{
|
||||
TextRange() :
|
||||
mStartOffset(0), mEndOffset(0), mRangeType(NS_TEXTRANGE_UNDEFINED)
|
||||
TextRange()
|
||||
: mStartOffset(0)
|
||||
, mEndOffset(0)
|
||||
, mRangeType(TextRangeType::NS_TEXTRANGE_UNDEFINED)
|
||||
{
|
||||
}
|
||||
|
||||
@ -152,18 +160,16 @@ struct TextRange
|
||||
// XXX Storing end offset makes the initializing code very complicated.
|
||||
// We should replace it with mLength.
|
||||
uint32_t mEndOffset;
|
||||
uint32_t mRangeType;
|
||||
|
||||
TextRangeStyle mRangeStyle;
|
||||
|
||||
TextRangeType mRangeType;
|
||||
|
||||
uint32_t Length() const { return mEndOffset - mStartOffset; }
|
||||
|
||||
bool IsClause() const
|
||||
{
|
||||
MOZ_ASSERT(mRangeType >= NS_TEXTRANGE_CARETPOSITION &&
|
||||
mRangeType <= NS_TEXTRANGE_SELECTEDCONVERTEDTEXT,
|
||||
"Invalid range type");
|
||||
return mRangeType != NS_TEXTRANGE_CARETPOSITION;
|
||||
return mRangeType != TextRangeType::NS_TEXTRANGE_CARETPOSITION;
|
||||
}
|
||||
|
||||
bool Equals(const TextRange& aOther) const
|
||||
@ -200,8 +206,8 @@ class TextRangeArray final : public AutoTArray<TextRange, 10>
|
||||
{
|
||||
for (uint32_t i = 0; i < Length(); ++i) {
|
||||
const TextRange& range = ElementAt(i);
|
||||
if (range.mRangeType == NS_TEXTRANGE_SELECTEDRAWTEXT ||
|
||||
range.mRangeType == NS_TEXTRANGE_SELECTEDCONVERTEDTEXT) {
|
||||
if (range.mRangeType == TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT ||
|
||||
range.mRangeType == TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT) {
|
||||
return ⦥
|
||||
}
|
||||
}
|
||||
@ -259,7 +265,7 @@ public:
|
||||
bool HasCaret() const
|
||||
{
|
||||
for (const TextRange& range : *this) {
|
||||
if (range.mRangeType == NS_TEXTRANGE_CARETPOSITION) {
|
||||
if (range.mRangeType == TextRangeType::NS_TEXTRANGE_CARETPOSITION) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -269,7 +275,7 @@ public:
|
||||
uint32_t GetCaretPosition() const
|
||||
{
|
||||
for (const TextRange& range : *this) {
|
||||
if (range.mRangeType == NS_TEXTRANGE_CARETPOSITION) {
|
||||
if (range.mRangeType == TextRangeType::NS_TEXTRANGE_CARETPOSITION) {
|
||||
return range.mStartOffset;
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,56 @@ ToChar(EventClassID aEventClassID)
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
IsValidRawTextRangeValue(RawTextRangeType aRawTextRangeType)
|
||||
{
|
||||
switch (static_cast<TextRangeType>(aRawTextRangeType)) {
|
||||
case TextRangeType::NS_TEXTRANGE_UNDEFINED:
|
||||
case TextRangeType::NS_TEXTRANGE_CARETPOSITION:
|
||||
case TextRangeType::NS_TEXTRANGE_RAWINPUT:
|
||||
case TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT:
|
||||
case TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT:
|
||||
case TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
RawTextRangeType
|
||||
ToRawTextRangeType(TextRangeType aTextRangeType)
|
||||
{
|
||||
return static_cast<RawTextRangeType>(aTextRangeType);
|
||||
}
|
||||
|
||||
TextRangeType
|
||||
ToTextRangeType(RawTextRangeType aRawTextRangeType)
|
||||
{
|
||||
MOZ_ASSERT(IsValidRawTextRangeValue(aRawTextRangeType));
|
||||
return static_cast<TextRangeType>(aRawTextRangeType);
|
||||
}
|
||||
|
||||
const char*
|
||||
ToChar(TextRangeType aTextRangeType)
|
||||
{
|
||||
switch (aTextRangeType) {
|
||||
case TextRangeType::NS_TEXTRANGE_UNDEFINED:
|
||||
return "NS_TEXTRANGE_UNDEFINED";
|
||||
case TextRangeType::NS_TEXTRANGE_CARETPOSITION:
|
||||
return "NS_TEXTRANGE_CARETPOSITION";
|
||||
case TextRangeType::NS_TEXTRANGE_RAWINPUT:
|
||||
return "NS_TEXTRANGE_RAWINPUT";
|
||||
case TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT:
|
||||
return "NS_TEXTRANGE_SELECTEDRAWTEXT";
|
||||
case TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT:
|
||||
return "NS_TEXTRANGE_CONVERTEDTEXT";
|
||||
case TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
|
||||
return "NS_TEXTRANGE_SELECTEDCONVERTEDTEXT";
|
||||
default:
|
||||
return "Invalid TextRangeType";
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* As*Event() implementation
|
||||
******************************************************************************/
|
||||
|
@ -3147,7 +3147,7 @@ nsWindow::GeckoViewSupport::OnImeReplaceText(int32_t aStart, int32_t aEnd,
|
||||
TextRange range;
|
||||
range.mStartOffset = 0;
|
||||
range.mEndOffset = event.mData.Length();
|
||||
range.mRangeType = NS_TEXTRANGE_RAWINPUT;
|
||||
range.mRangeType = TextRangeType::NS_TEXTRANGE_RAWINPUT;
|
||||
event.mRanges = new TextRangeArray();
|
||||
event.mRanges->AppendElement(range);
|
||||
}
|
||||
@ -3183,7 +3183,7 @@ nsWindow::GeckoViewSupport::OnImeAddCompositionRange(
|
||||
TextRange range;
|
||||
range.mStartOffset = aStart;
|
||||
range.mEndOffset = aEnd;
|
||||
range.mRangeType = aRangeType;
|
||||
range.mRangeType = ToTextRangeType(aRangeType);
|
||||
range.mRangeStyle.mDefinedStyles = aRangeStyle;
|
||||
range.mRangeStyle.mLineStyle = aRangeLineStyle;
|
||||
range.mRangeStyle.mIsBoldLine = aRangeBoldLine;
|
||||
|
@ -966,8 +966,8 @@ private:
|
||||
* @param aSelectedRange Current selected range (or caret position).
|
||||
* @return NS_TEXTRANGE_*.
|
||||
*/
|
||||
uint32_t ConvertToTextRangeType(uint32_t aUnderlineStyle,
|
||||
NSRange& aSelectedRange);
|
||||
TextRangeType ConvertToTextRangeType(uint32_t aUnderlineStyle,
|
||||
NSRange& aSelectedRange);
|
||||
|
||||
/**
|
||||
* GetRangeCount() computes the range count of aAttrString.
|
||||
|
@ -232,25 +232,6 @@ GetGeckoKeyEventType(const WidgetEvent& aEvent)
|
||||
}
|
||||
}
|
||||
|
||||
static const char*
|
||||
GetRangeTypeName(uint32_t aRangeType)
|
||||
{
|
||||
switch (aRangeType) {
|
||||
case NS_TEXTRANGE_RAWINPUT:
|
||||
return "NS_TEXTRANGE_RAWINPUT";
|
||||
case NS_TEXTRANGE_CONVERTEDTEXT:
|
||||
return "NS_TEXTRANGE_CONVERTEDTEXT";
|
||||
case NS_TEXTRANGE_SELECTEDRAWTEXT:
|
||||
return "NS_TEXTRANGE_SELECTEDRAWTEXT";
|
||||
case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
|
||||
return "NS_TEXTRANGE_SELECTEDCONVERTEDTEXT";
|
||||
case NS_TEXTRANGE_CARETPOSITION:
|
||||
return "NS_TEXTRANGE_CARETPOSITION";
|
||||
default:
|
||||
return "invalid range type";
|
||||
}
|
||||
}
|
||||
|
||||
static const char*
|
||||
GetWindowLevelName(NSInteger aWindowLevel)
|
||||
{
|
||||
@ -2743,7 +2724,7 @@ IMEInputHandler::ExecutePendingMethods()
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
uint32_t
|
||||
TextRangeType
|
||||
IMEInputHandler::ConvertToTextRangeType(uint32_t aUnderlineStyle,
|
||||
NSRange& aSelectedRange)
|
||||
{
|
||||
@ -2759,23 +2740,23 @@ IMEInputHandler::ConvertToTextRangeType(uint32_t aUnderlineStyle,
|
||||
if (aSelectedRange.length == 0) {
|
||||
switch (aUnderlineStyle) {
|
||||
case NSUnderlineStyleSingle:
|
||||
return NS_TEXTRANGE_RAWINPUT;
|
||||
return TextRangeType::NS_TEXTRANGE_RAWINPUT;
|
||||
case NSUnderlineStyleThick:
|
||||
return NS_TEXTRANGE_SELECTEDRAWTEXT;
|
||||
return TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT;
|
||||
default:
|
||||
NS_WARNING("Unexpected line style");
|
||||
return NS_TEXTRANGE_SELECTEDRAWTEXT;
|
||||
return TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT;
|
||||
}
|
||||
}
|
||||
|
||||
switch (aUnderlineStyle) {
|
||||
case NSUnderlineStyleSingle:
|
||||
return NS_TEXTRANGE_CONVERTEDTEXT;
|
||||
return TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT;
|
||||
case NSUnderlineStyleThick:
|
||||
return NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
|
||||
return TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
|
||||
default:
|
||||
NS_WARNING("Unexpected line style");
|
||||
return NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
|
||||
return TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2841,7 +2822,7 @@ IMEInputHandler::CreateTextRangeArray(NSAttributedString *aAttrString,
|
||||
("%p IMEInputHandler::CreateTextRangeArray, "
|
||||
"range={ mStartOffset=%llu, mEndOffset=%llu, mRangeType=%s }",
|
||||
this, range.mStartOffset, range.mEndOffset,
|
||||
GetRangeTypeName(range.mRangeType)));
|
||||
ToChar(range.mRangeType)));
|
||||
|
||||
limitRange =
|
||||
NSMakeRange(NSMaxRange(effectiveRange),
|
||||
@ -2852,14 +2833,14 @@ IMEInputHandler::CreateTextRangeArray(NSAttributedString *aAttrString,
|
||||
TextRange range;
|
||||
range.mStartOffset = aSelectedRange.location + aSelectedRange.length;
|
||||
range.mEndOffset = range.mStartOffset;
|
||||
range.mRangeType = NS_TEXTRANGE_CARETPOSITION;
|
||||
range.mRangeType = TextRangeType::NS_TEXTRANGE_CARETPOSITION;
|
||||
textRangeArray->AppendElement(range);
|
||||
|
||||
MOZ_LOG(gLog, LogLevel::Info,
|
||||
("%p IMEInputHandler::CreateTextRangeArray, "
|
||||
"range={ mStartOffset=%llu, mEndOffset=%llu, mRangeType=%s }",
|
||||
this, range.mStartOffset, range.mEndOffset,
|
||||
GetRangeTypeName(range.mRangeType)));
|
||||
ToChar(range.mRangeType)));
|
||||
|
||||
return textRangeArray.forget();
|
||||
|
||||
|
@ -29,25 +29,6 @@ ToChar(bool aBool)
|
||||
return aBool ? "true" : "false";
|
||||
}
|
||||
|
||||
static const char*
|
||||
GetRangeTypeName(uint32_t aRangeType)
|
||||
{
|
||||
switch (aRangeType) {
|
||||
case NS_TEXTRANGE_RAWINPUT:
|
||||
return "NS_TEXTRANGE_RAWINPUT";
|
||||
case NS_TEXTRANGE_CONVERTEDTEXT:
|
||||
return "NS_TEXTRANGE_CONVERTEDTEXT";
|
||||
case NS_TEXTRANGE_SELECTEDRAWTEXT:
|
||||
return "NS_TEXTRANGE_SELECTEDRAWTEXT";
|
||||
case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
|
||||
return "NS_TEXTRANGE_SELECTEDCONVERTEDTEXT";
|
||||
case NS_TEXTRANGE_CARETPOSITION:
|
||||
return "NS_TEXTRANGE_CARETPOSITION";
|
||||
default:
|
||||
return "UNKNOWN SELECTION TYPE!!";
|
||||
}
|
||||
}
|
||||
|
||||
static const char*
|
||||
GetEnabledStateName(uint32_t aState)
|
||||
{
|
||||
@ -1691,13 +1672,13 @@ IMContextWrapper::CreateTextRangeArray(GtkIMContext* aContext,
|
||||
|
||||
TextRange range;
|
||||
range.mStartOffset = range.mEndOffset = caretOffsetInUTF16;
|
||||
range.mRangeType = NS_TEXTRANGE_CARETPOSITION;
|
||||
range.mRangeType = TextRangeType::NS_TEXTRANGE_CARETPOSITION;
|
||||
textRangeArray->AppendElement(range);
|
||||
MOZ_LOG(gGtkIMLog, LogLevel::Debug,
|
||||
("GTKIM: %p CreateTextRangeArray(), mStartOffset=%u, "
|
||||
"mEndOffset=%u, mRangeType=%s",
|
||||
this, range.mStartOffset, range.mEndOffset,
|
||||
GetRangeTypeName(range.mRangeType)));
|
||||
ToChar(range.mRangeType)));
|
||||
|
||||
pango_attr_iterator_destroy(iter);
|
||||
pango_attr_list_unref(feedback_list);
|
||||
@ -1871,26 +1852,26 @@ IMContextWrapper::SetTextRange(PangoAttrIterator* aPangoAttrIter,
|
||||
if (!utf8ClauseStart &&
|
||||
utf8ClauseEnd == static_cast<gint>(strlen(aUTF8CompositionString)) &&
|
||||
aTextRange.mEndOffset == aUTF16CaretOffset) {
|
||||
aTextRange.mRangeType = NS_TEXTRANGE_RAWINPUT;
|
||||
aTextRange.mRangeType = TextRangeType::NS_TEXTRANGE_RAWINPUT;
|
||||
}
|
||||
// Typically, the caret is set at the start of the selected clause.
|
||||
// So, if the caret is in the clause, we can assume that the clause is
|
||||
// selected.
|
||||
else if (aTextRange.mStartOffset <= aUTF16CaretOffset &&
|
||||
aTextRange.mEndOffset > aUTF16CaretOffset) {
|
||||
aTextRange.mRangeType = NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
|
||||
aTextRange.mRangeType = TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
|
||||
}
|
||||
// Otherwise, we should assume that the clause is converted but not
|
||||
// selected.
|
||||
else {
|
||||
aTextRange.mRangeType = NS_TEXTRANGE_CONVERTEDTEXT;
|
||||
aTextRange.mRangeType = TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT;
|
||||
}
|
||||
|
||||
MOZ_LOG(gGtkIMLog, LogLevel::Debug,
|
||||
("GTKIM: %p SetTextRange(), succeeded, aTextRange= { "
|
||||
"mStartOffset=%u, mEndOffset=%u, mRangeType=%s, mRangeStyle=%s }",
|
||||
this, aTextRange.mStartOffset, aTextRange.mEndOffset,
|
||||
GetRangeTypeName(aTextRange.mRangeType),
|
||||
ToChar(aTextRange.mRangeType),
|
||||
GetTextRangeStyleText(aTextRange.mRangeStyle).get()));
|
||||
|
||||
return true;
|
||||
|
@ -526,16 +526,21 @@ struct ParamTraits<mozilla::TextRange>
|
||||
{
|
||||
WriteParam(aMsg, aParam.mStartOffset);
|
||||
WriteParam(aMsg, aParam.mEndOffset);
|
||||
WriteParam(aMsg, aParam.mRangeType);
|
||||
WriteParam(aMsg, mozilla::ToRawTextRangeType(aParam.mRangeType));
|
||||
WriteParam(aMsg, aParam.mRangeStyle);
|
||||
}
|
||||
|
||||
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
||||
{
|
||||
return ReadParam(aMsg, aIter, &aResult->mStartOffset) &&
|
||||
ReadParam(aMsg, aIter, &aResult->mEndOffset) &&
|
||||
ReadParam(aMsg, aIter, &aResult->mRangeType) &&
|
||||
ReadParam(aMsg, aIter, &aResult->mRangeStyle);
|
||||
mozilla::RawTextRangeType rawTextRangeType;
|
||||
if (ReadParam(aMsg, aIter, &aResult->mStartOffset) &&
|
||||
ReadParam(aMsg, aIter, &aResult->mEndOffset) &&
|
||||
ReadParam(aMsg, aIter, &rawTextRangeType) &&
|
||||
ReadParam(aMsg, aIter, &aResult->mRangeStyle)) {
|
||||
aResult->mRangeType = mozilla::ToTextRangeType(rawTextRangeType);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1888,7 +1888,7 @@ IMMHandler::CommitCompositionOnPreviousWindow(nsWindow* aWindow)
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
static TextRangeType
|
||||
PlatformToNSAttr(uint8_t aAttr)
|
||||
{
|
||||
switch (aAttr)
|
||||
@ -1896,35 +1896,16 @@ PlatformToNSAttr(uint8_t aAttr)
|
||||
case ATTR_INPUT_ERROR:
|
||||
// case ATTR_FIXEDCONVERTED:
|
||||
case ATTR_INPUT:
|
||||
return NS_TEXTRANGE_RAWINPUT;
|
||||
return TextRangeType::NS_TEXTRANGE_RAWINPUT;
|
||||
case ATTR_CONVERTED:
|
||||
return NS_TEXTRANGE_CONVERTEDTEXT;
|
||||
return TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT;
|
||||
case ATTR_TARGET_NOTCONVERTED:
|
||||
return NS_TEXTRANGE_SELECTEDRAWTEXT;
|
||||
return TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT;
|
||||
case ATTR_TARGET_CONVERTED:
|
||||
return NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
|
||||
return TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
|
||||
default:
|
||||
NS_ASSERTION(false, "unknown attribute");
|
||||
return NS_TEXTRANGE_CARETPOSITION;
|
||||
}
|
||||
}
|
||||
|
||||
static const char*
|
||||
GetRangeTypeName(uint32_t aRangeType)
|
||||
{
|
||||
switch (aRangeType) {
|
||||
case NS_TEXTRANGE_RAWINPUT:
|
||||
return "NS_TEXTRANGE_RAWINPUT";
|
||||
case NS_TEXTRANGE_CONVERTEDTEXT:
|
||||
return "NS_TEXTRANGE_CONVERTEDTEXT";
|
||||
case NS_TEXTRANGE_SELECTEDRAWTEXT:
|
||||
return "NS_TEXTRANGE_SELECTEDRAWTEXT";
|
||||
case NS_TEXTRANGE_SELECTEDCONVERTEDTEXT:
|
||||
return "NS_TEXTRANGE_SELECTEDCONVERTEDTEXT";
|
||||
case NS_TEXTRANGE_CARETPOSITION:
|
||||
return "NS_TEXTRANGE_CARETPOSITION";
|
||||
default:
|
||||
return "UNKNOWN SELECTION TYPE!!";
|
||||
return TextRangeType::NS_TEXTRANGE_CARETPOSITION;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2014,8 +1995,9 @@ IMMHandler::DispatchCompositionChangeEvent(nsWindow* aWindow,
|
||||
}
|
||||
|
||||
uint32_t length = current - lastOffset;
|
||||
uint32_t attr = PlatformToNSAttr(mAttributeArray[lastOffset]);
|
||||
rv = dispatcher->AppendClauseToPendingComposition(length, attr);
|
||||
TextRangeType textRangeType =
|
||||
PlatformToNSAttr(mAttributeArray[lastOffset]);
|
||||
rv = dispatcher->AppendClauseToPendingComposition(length, textRangeType);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
MOZ_LOG(gIMMLog, LogLevel::Error,
|
||||
("IMM: DispatchCompositionChangeEvent, FAILED due to"
|
||||
@ -2028,7 +2010,7 @@ IMMHandler::DispatchCompositionChangeEvent(nsWindow* aWindow,
|
||||
MOZ_LOG(gIMMLog, LogLevel::Info,
|
||||
("IMM: DispatchCompositionChangeEvent, index=%ld, rangeType=%s, "
|
||||
"range length=%lu",
|
||||
i, GetRangeTypeName(attr), length));
|
||||
i, ToChar(textRangeType), length));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2045,25 +2045,19 @@ GetRangeExtent(ITfRange* aRange, LONG* aStart, LONG* aLength)
|
||||
return rangeACP->GetExtent(aStart, aLength);
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
static TextRangeType
|
||||
GetGeckoSelectionValue(TF_DISPLAYATTRIBUTE& aDisplayAttr)
|
||||
{
|
||||
uint32_t result;
|
||||
switch (aDisplayAttr.bAttr) {
|
||||
case TF_ATTR_TARGET_CONVERTED:
|
||||
result = NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
|
||||
break;
|
||||
return TextRangeType::NS_TEXTRANGE_SELECTEDCONVERTEDTEXT;
|
||||
case TF_ATTR_CONVERTED:
|
||||
result = NS_TEXTRANGE_CONVERTEDTEXT;
|
||||
break;
|
||||
return TextRangeType::NS_TEXTRANGE_CONVERTEDTEXT;
|
||||
case TF_ATTR_TARGET_NOTCONVERTED:
|
||||
result = NS_TEXTRANGE_SELECTEDRAWTEXT;
|
||||
break;
|
||||
return TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT;
|
||||
default:
|
||||
result = NS_TEXTRANGE_RAWINPUT;
|
||||
break;
|
||||
return TextRangeType::NS_TEXTRANGE_RAWINPUT;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
HRESULT
|
||||
@ -2285,7 +2279,7 @@ TSFTextStore::RestartComposition(ITfCompositionView* aCompositionView,
|
||||
TextRange caretRange;
|
||||
caretRange.mStartOffset = caretRange.mEndOffset =
|
||||
uint32_t(oldComposition.mStart + commitString.Length());
|
||||
caretRange.mRangeType = NS_TEXTRANGE_CARETPOSITION;
|
||||
caretRange.mRangeType = TextRangeType::NS_TEXTRANGE_CARETPOSITION;
|
||||
action->mRanges->AppendElement(caretRange);
|
||||
action->mIncomplete = false;
|
||||
|
||||
@ -2434,7 +2428,7 @@ TSFTextStore::RecordCompositionUpdateAction()
|
||||
// we always pass in at least one range to eCompositionChange
|
||||
newRange.mStartOffset = 0;
|
||||
newRange.mEndOffset = action->mData.Length();
|
||||
newRange.mRangeType = NS_TEXTRANGE_RAWINPUT;
|
||||
newRange.mRangeType = TextRangeType::NS_TEXTRANGE_RAWINPUT;
|
||||
action->mRanges->AppendElement(newRange);
|
||||
|
||||
RefPtr<ITfRange> range;
|
||||
@ -2479,7 +2473,7 @@ TSFTextStore::RecordCompositionUpdateAction()
|
||||
TF_DISPLAYATTRIBUTE attr;
|
||||
hr = GetDisplayAttribute(attrPropetry, range, &attr);
|
||||
if (FAILED(hr)) {
|
||||
newRange.mRangeType = NS_TEXTRANGE_RAWINPUT;
|
||||
newRange.mRangeType = TextRangeType::NS_TEXTRANGE_RAWINPUT;
|
||||
} else {
|
||||
newRange.mRangeType = GetGeckoSelectionValue(attr);
|
||||
if (GetColor(attr.crText, newRange.mRangeStyle.mForegroundColor)) {
|
||||
@ -2529,7 +2523,7 @@ TSFTextStore::RecordCompositionUpdateAction()
|
||||
range.mRangeStyle.IsNoChangeStyle()) {
|
||||
range.mRangeStyle.Clear();
|
||||
// The looks of selected type is better than others.
|
||||
range.mRangeType = NS_TEXTRANGE_SELECTEDRAWTEXT;
|
||||
range.mRangeType = TextRangeType::NS_TEXTRANGE_SELECTEDRAWTEXT;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2547,7 +2541,7 @@ TSFTextStore::RecordCompositionUpdateAction()
|
||||
caretPosition > targetClause->mEndOffset) {
|
||||
TextRange caretRange;
|
||||
caretRange.mStartOffset = caretRange.mEndOffset = caretPosition;
|
||||
caretRange.mRangeType = NS_TEXTRANGE_CARETPOSITION;
|
||||
caretRange.mRangeType = TextRangeType::NS_TEXTRANGE_CARETPOSITION;
|
||||
action->mRanges->AppendElement(caretRange);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user