Bug 1615532 - Make line style in TextRangeStyle an enum class and sync it with GeckoEditable.IME_RANGE_LINE_* r=m_kato

At bug 1614208, the line style value mapping was changed, but
`GeckoEditable.IME_RANGE_LINE_*` are not updated.

This patch makes the style in `TextRangeStyle` an enum class for making it
type safer, and updates `GeckoEditable.IME_RANGE_LINE_*`, and finally, adds
`FYI` comments in `TextRangeStyle` to make developers realize it requires
manual update.

Differential Revision: https://phabricator.services.mozilla.com/D62883

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2020-02-17 07:53:46 +00:00
Родитель 916ea683da
Коммит 351bd16f96
7 изменённых файлов: 82 добавлений и 59 удалений

Просмотреть файл

@ -5692,20 +5692,21 @@ void nsTextFrame::PaintDecorationLine(
static uint8_t ToStyleLineStyle(const TextRangeStyle& aStyle) {
switch (aStyle.mLineStyle) {
case TextRangeStyle::LINESTYLE_NONE:
case TextRangeStyle::LineStyle::None:
return NS_STYLE_TEXT_DECORATION_STYLE_NONE;
case TextRangeStyle::LINESTYLE_WAVY:
return NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
case TextRangeStyle::LINESTYLE_DASHED:
return NS_STYLE_TEXT_DECORATION_STYLE_DASHED;
case TextRangeStyle::LINESTYLE_DOTTED:
case TextRangeStyle::LineStyle::Solid:
return NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
case TextRangeStyle::LineStyle::Dotted:
return NS_STYLE_TEXT_DECORATION_STYLE_DOTTED;
case TextRangeStyle::LINESTYLE_DOUBLE:
case TextRangeStyle::LineStyle::Dashed:
return NS_STYLE_TEXT_DECORATION_STYLE_DASHED;
case TextRangeStyle::LineStyle::Double:
return NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE;
default:
MOZ_ASSERT_UNREACHABLE("Unknown line style?");
return NS_STYLE_TEXT_DECORATION_STYLE_NONE;
case TextRangeStyle::LineStyle::Wavy:
return NS_STYLE_TEXT_DECORATION_STYLE_WAVY;
}
MOZ_ASSERT_UNREACHABLE("Invalid line style");
return NS_STYLE_TEXT_DECORATION_STYLE_NONE;
}
/**
@ -5785,7 +5786,7 @@ void nsTextFrame::DrawSelectionDecorations(
if (isIMEType && aRangeStyle.IsDefined()) {
// If IME defines the style, that should override our definition.
if (aRangeStyle.IsLineStyleDefined()) {
if (aRangeStyle.mLineStyle == TextRangeStyle::LINESTYLE_NONE) {
if (aRangeStyle.mLineStyle == TextRangeStyle::LineStyle::None) {
return;
}
params.style = ToStyleLineStyle(aRangeStyle);
@ -7362,7 +7363,7 @@ bool nsTextFrame::CombineSelectionUnderlineRect(nsPresContext* aPresContext,
TextRangeStyle& rangeStyle = sd->mTextRangeStyle;
if (rangeStyle.IsDefined()) {
if (!rangeStyle.IsLineStyleDefined() ||
rangeStyle.mLineStyle == TextRangeStyle::LINESTYLE_NONE) {
rangeStyle.mLineStyle == TextRangeStyle::LineStyle::None) {
continue;
}
params.style = ToStyleLineStyle(rangeStyle);

Просмотреть файл

@ -123,9 +123,9 @@ import android.view.inputmethod.EditorInfo;
private static final int IME_RANGE_SELECTEDCONVERTEDTEXT = 5;
private static final int IME_RANGE_LINE_NONE = 0;
private static final int IME_RANGE_LINE_DOTTED = 1;
private static final int IME_RANGE_LINE_DASHED = 2;
private static final int IME_RANGE_LINE_SOLID = 3;
private static final int IME_RANGE_LINE_SOLID = 1;
private static final int IME_RANGE_LINE_DOTTED = 2;
private static final int IME_RANGE_LINE_DASHED = 3;
private static final int IME_RANGE_LINE_DOUBLE = 4;
private static final int IME_RANGE_LINE_WAVY = 5;

Просмотреть файл

@ -22,14 +22,29 @@ namespace mozilla {
******************************************************************************/
struct TextRangeStyle {
enum {
LINESTYLE_NONE,
LINESTYLE_SOLID,
LINESTYLE_DOTTED,
LINESTYLE_DASHED,
LINESTYLE_DOUBLE,
LINESTYLE_WAVY,
typedef uint8_t LineStyleType;
// FYI: Modify IME_RANGE_LINE_* too when you modify LineStyle.
enum class LineStyle : LineStyleType {
None,
Solid,
Dotted,
Dashed,
Double,
Wavy,
};
inline static LineStyle ToLineStyle(RawTextRangeType aRawLineStyle) {
switch (static_cast<LineStyle>(aRawLineStyle)) {
case LineStyle::None:
case LineStyle::Solid:
case LineStyle::Dotted:
case LineStyle::Dashed:
case LineStyle::Double:
case LineStyle::Wavy:
return static_cast<LineStyle>(aRawLineStyle);
}
MOZ_ASSERT_UNREACHABLE("aRawLineStyle value is invalid");
return LineStyle::None;
}
enum {
DEFINED_NONE = 0x00,
@ -48,7 +63,7 @@ struct TextRangeStyle {
void Clear() {
mDefinedStyles = DEFINED_NONE;
mLineStyle = LINESTYLE_NONE;
mLineStyle = LineStyle::None;
mIsBoldLine = false;
mForegroundColor = mBackgroundColor = mUnderlineColor = NS_RGBA(0, 0, 0, 0);
}
@ -73,7 +88,7 @@ struct TextRangeStyle {
bool IsNoChangeStyle() const {
return !IsForegroundColorDefined() && !IsBackgroundColorDefined() &&
IsLineStyleDefined() && mLineStyle == LINESTYLE_NONE;
IsLineStyleDefined() && mLineStyle == LineStyle::None;
}
bool Equals(const TextRangeStyle& aOther) const {
@ -100,7 +115,7 @@ struct TextRangeStyle {
bool operator==(const TextRangeStyle& aOther) const { return Equals(aOther); }
uint8_t mDefinedStyles;
uint8_t mLineStyle; // DEFINED_LINESTYLE
LineStyle mLineStyle; // DEFINED_LINESTYLE
bool mIsBoldLine; // DEFINED_LINESTYLE

Просмотреть файл

@ -1188,7 +1188,7 @@ void GeckoEditableSupport::OnImeAddCompositionRange(
range.mEndOffset = aEnd;
range.mRangeType = ToTextRangeType(aRangeType);
range.mRangeStyle.mDefinedStyles = aRangeStyle;
range.mRangeStyle.mLineStyle = aRangeLineStyle;
range.mRangeStyle.mLineStyle = TextRangeStyle::ToLineStyle(aRangeLineStyle);
range.mRangeStyle.mIsBoldLine = aRangeBoldLine;
range.mRangeStyle.mForegroundColor =
ConvertAndroidColor(uint32_t(aRangeForeColor));

Просмотреть файл

@ -171,28 +171,29 @@ class GetTextRangeStyleText final : public nsAutoCString {
AppendLiteral(" }");
}
void AppendLineStyle(uint8_t aLineStyle) {
void AppendLineStyle(TextRangeStyle::LineStyle aLineStyle) {
switch (aLineStyle) {
case TextRangeStyle::LINESTYLE_NONE:
AppendLiteral("LINESTYLE_NONE");
case TextRangeStyle::LineStyle::None:
AppendLiteral("LineStyle::None");
break;
case TextRangeStyle::LINESTYLE_SOLID:
AppendLiteral("LINESTYLE_SOLID");
case TextRangeStyle::LineStyle::Solid:
AppendLiteral("LineStyle::Solid");
break;
case TextRangeStyle::LINESTYLE_DOTTED:
AppendLiteral("LINESTYLE_DOTTED");
case TextRangeStyle::LineStyle::Dotted:
AppendLiteral("LineStyle::Dotted");
break;
case TextRangeStyle::LINESTYLE_DASHED:
AppendLiteral("LINESTYLE_DASHED");
case TextRangeStyle::LineStyle::Dashed:
AppendLiteral("LineStyle::Dashed");
break;
case TextRangeStyle::LINESTYLE_DOUBLE:
AppendLiteral("LINESTYLE_DOUBLE");
case TextRangeStyle::LineStyle::Double:
AppendLiteral("LineStyle::Double");
break;
case TextRangeStyle::LINESTYLE_WAVY:
AppendLiteral("LINESTYLE_WAVY");
case TextRangeStyle::LineStyle::Wavy:
AppendLiteral("LineStyle::Wavy");
break;
default:
AppendPrintf("Invalid(0x%02X)", aLineStyle);
AppendPrintf("Invalid(0x%02X)",
static_cast<TextRangeStyle::LineStyleType>(aLineStyle));
break;
}
}
@ -2622,24 +2623,24 @@ bool IMContextWrapper::SetTextRange(PangoAttrIterator* aPangoAttrIter,
if (attrUnderline) {
switch (attrUnderline->value) {
case PANGO_UNDERLINE_NONE:
style.mLineStyle = TextRangeStyle::LINESTYLE_NONE;
style.mLineStyle = TextRangeStyle::LineStyle::None;
break;
case PANGO_UNDERLINE_DOUBLE:
style.mLineStyle = TextRangeStyle::LINESTYLE_DOUBLE;
style.mLineStyle = TextRangeStyle::LineStyle::Double;
break;
case PANGO_UNDERLINE_ERROR:
style.mLineStyle = TextRangeStyle::LINESTYLE_WAVY;
style.mLineStyle = TextRangeStyle::LineStyle::Wavy;
break;
case PANGO_UNDERLINE_SINGLE:
case PANGO_UNDERLINE_LOW:
style.mLineStyle = TextRangeStyle::LINESTYLE_SOLID;
style.mLineStyle = TextRangeStyle::LineStyle::Solid;
break;
default:
MOZ_LOG(gGtkIMLog, LogLevel::Warning,
("0x%p SetTextRange(), retrieved unknown underline "
"style: %d",
this, attrUnderline->value));
style.mLineStyle = TextRangeStyle::LINESTYLE_SOLID;
style.mLineStyle = TextRangeStyle::LineStyle::Solid;
break;
}
style.mDefinedStyles |= TextRangeStyle::DEFINED_LINESTYLE;
@ -2652,7 +2653,7 @@ bool IMContextWrapper::SetTextRange(PangoAttrIterator* aPangoAttrIter,
style.mDefinedStyles |= TextRangeStyle::DEFINED_UNDERLINE_COLOR;
}
} else {
style.mLineStyle = TextRangeStyle::LINESTYLE_NONE;
style.mLineStyle = TextRangeStyle::LineStyle::None;
style.mDefinedStyles |= TextRangeStyle::DEFINED_LINESTYLE;
}

Просмотреть файл

@ -484,7 +484,8 @@ struct ParamTraits<mozilla::TextRangeStyle> {
static void Write(Message* aMsg, const paramType& aParam) {
WriteParam(aMsg, aParam.mDefinedStyles);
WriteParam(aMsg, aParam.mLineStyle);
WriteParam(aMsg, static_cast<mozilla::TextRangeStyle::LineStyleType>(
aParam.mLineStyle));
WriteParam(aMsg, aParam.mIsBoldLine);
WriteParam(aMsg, aParam.mForegroundColor);
WriteParam(aMsg, aParam.mBackgroundColor);
@ -493,12 +494,17 @@ struct ParamTraits<mozilla::TextRangeStyle> {
static bool Read(const Message* aMsg, PickleIterator* aIter,
paramType* aResult) {
return ReadParam(aMsg, aIter, &aResult->mDefinedStyles) &&
ReadParam(aMsg, aIter, &aResult->mLineStyle) &&
ReadParam(aMsg, aIter, &aResult->mIsBoldLine) &&
ReadParam(aMsg, aIter, &aResult->mForegroundColor) &&
ReadParam(aMsg, aIter, &aResult->mBackgroundColor) &&
ReadParam(aMsg, aIter, &aResult->mUnderlineColor);
mozilla::TextRangeStyle::LineStyleType lineStyle;
if (!ReadParam(aMsg, aIter, &aResult->mDefinedStyles) ||
!ReadParam(aMsg, aIter, &lineStyle) ||
!ReadParam(aMsg, aIter, &aResult->mIsBoldLine) ||
!ReadParam(aMsg, aIter, &aResult->mForegroundColor) ||
!ReadParam(aMsg, aIter, &aResult->mBackgroundColor) ||
!ReadParam(aMsg, aIter, &aResult->mUnderlineColor)) {
return false;
}
aResult->mLineStyle = mozilla::TextRangeStyle::ToLineStyle(lineStyle);
return true;
}
};

Просмотреть файл

@ -3301,22 +3301,22 @@ static bool GetColor(const TF_DA_COLOR& aTSFColor, nscolor& aResult) {
}
static bool GetLineStyle(TF_DA_LINESTYLE aTSFLineStyle,
uint8_t& aTextRangeLineStyle) {
TextRangeStyle::LineStyle& aTextRangeLineStyle) {
switch (aTSFLineStyle) {
case TF_LS_NONE:
aTextRangeLineStyle = TextRangeStyle::LINESTYLE_NONE;
aTextRangeLineStyle = TextRangeStyle::LineStyle::None;
return true;
case TF_LS_SOLID:
aTextRangeLineStyle = TextRangeStyle::LINESTYLE_SOLID;
aTextRangeLineStyle = TextRangeStyle::LineStyle::Solid;
return true;
case TF_LS_DOT:
aTextRangeLineStyle = TextRangeStyle::LINESTYLE_DOTTED;
aTextRangeLineStyle = TextRangeStyle::LineStyle::Dotted;
return true;
case TF_LS_DASH:
aTextRangeLineStyle = TextRangeStyle::LINESTYLE_DASHED;
aTextRangeLineStyle = TextRangeStyle::LineStyle::Dashed;
return true;
case TF_LS_SQUIGGLE:
aTextRangeLineStyle = TextRangeStyle::LINESTYLE_WAVY;
aTextRangeLineStyle = TextRangeStyle::LineStyle::Wavy;
return true;
default:
return false;