diff --git a/dom/base/Selection.h b/dom/base/Selection.h index bee0af78c760..9714b0d43579 100644 --- a/dom/base/Selection.h +++ b/dom/base/Selection.h @@ -1228,28 +1228,28 @@ class MOZ_RAII AutoHideSelectionChanges final { } // namespace dom -inline bool IsValidRawSelectionType(RawSelectionType aRawSelectionType) { +constexpr bool IsValidRawSelectionType(RawSelectionType aRawSelectionType) { return aRawSelectionType >= nsISelectionController::SELECTION_NONE && aRawSelectionType <= nsISelectionController::SELECTION_URLSTRIKEOUT; } -inline SelectionType ToSelectionType(RawSelectionType aRawSelectionType) { +constexpr SelectionType ToSelectionType(RawSelectionType aRawSelectionType) { if (!IsValidRawSelectionType(aRawSelectionType)) { return SelectionType::eInvalid; } return static_cast(aRawSelectionType); } -inline RawSelectionType ToRawSelectionType(SelectionType aSelectionType) { +constexpr RawSelectionType ToRawSelectionType(SelectionType aSelectionType) { MOZ_ASSERT(aSelectionType != SelectionType::eInvalid); return static_cast(aSelectionType); } -inline RawSelectionType ToRawSelectionType(TextRangeType aTextRangeType) { +constexpr RawSelectionType ToRawSelectionType(TextRangeType aTextRangeType) { return ToRawSelectionType(ToSelectionType(aTextRangeType)); } -inline SelectionTypeMask ToSelectionTypeMask(SelectionType aSelectionType) { +constexpr SelectionTypeMask ToSelectionTypeMask(SelectionType aSelectionType) { MOZ_ASSERT(aSelectionType != SelectionType::eInvalid); return aSelectionType == SelectionType::eNone ? 0 diff --git a/dom/base/nsISelectionController.idl b/dom/base/nsISelectionController.idl index eaaa2d02bca0..29d1875384ca 100644 --- a/dom/base/nsISelectionController.idl +++ b/dom/base/nsISelectionController.idl @@ -339,10 +339,10 @@ static const SelectionType kPresentSelectionTypes[] = { }; // Please include mozilla/dom/Selection.h for the following APIs. -inline bool IsValidRawSelectionType(RawSelectionType aRawSelectionType); -inline SelectionType ToSelectionType(RawSelectionType aRawSelectionType); -inline RawSelectionType ToRawSelectionType(SelectionType aSelectionType); -inline SelectionTypeMask ToSelectionTypeMask(SelectionType aSelectionType); +constexpr bool IsValidRawSelectionType(RawSelectionType aRawSelectionType); +constexpr SelectionType ToSelectionType(RawSelectionType aRawSelectionType); +constexpr RawSelectionType ToRawSelectionType(SelectionType aSelectionType); +constexpr SelectionTypeMask ToSelectionTypeMask(SelectionType aSelectionType); } // namespace mozilla %} diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index e65dc70f56aa..5412fe04648b 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -5472,7 +5472,7 @@ gfxFloat nsTextFrame::ComputeDescentLimitForSelectionUnderline( } // Make sure this stays in sync with DrawSelectionDecorations below -static const SelectionTypeMask kSelectionTypesWithDecorations = +static constexpr SelectionTypeMask kSelectionTypesWithDecorations = ToSelectionTypeMask(SelectionType::eSpellCheck) | ToSelectionTypeMask(SelectionType::eURLStrikeout) | ToSelectionTypeMask(SelectionType::eIMERawClause) | diff --git a/widget/TextRange.h b/widget/TextRange.h index 2ad41a6bc618..eed62b7c387a 100644 --- a/widget/TextRange.h +++ b/widget/TextRange.h @@ -137,12 +137,6 @@ enum class TextRangeType : RawTextRangeType { eSelectedClause = nsITextInputProcessor::ATTR_SELECTED_CLAUSE }; -bool IsValidRawTextRangeValue(RawTextRangeType aRawTextRangeValue); -RawTextRangeType ToRawTextRangeType(TextRangeType aTextRangeType); -TextRangeType ToTextRangeType(RawTextRangeType aRawTextRangeType); -const char* ToChar(TextRangeType aTextRangeType); -SelectionType ToSelectionType(TextRangeType aTextRangeType); - struct TextRange { TextRange() : mStartOffset(0), @@ -178,6 +172,64 @@ struct TextRange { } }; +constexpr bool IsValidRawTextRangeValue(RawTextRangeType aRawTextRangeType) { + switch (static_cast(aRawTextRangeType)) { + case TextRangeType::eUninitialized: + case TextRangeType::eCaret: + case TextRangeType::eRawClause: + case TextRangeType::eSelectedRawClause: + case TextRangeType::eConvertedClause: + case TextRangeType::eSelectedClause: + return true; + default: + return false; + } +} + +constexpr RawTextRangeType ToRawTextRangeType(TextRangeType aTextRangeType) { + return static_cast(aTextRangeType); +} + +constexpr TextRangeType ToTextRangeType(RawTextRangeType aRawTextRangeType) { + MOZ_ASSERT(IsValidRawTextRangeValue(aRawTextRangeType)); + return static_cast(aRawTextRangeType); +} + +constexpr const char* 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 ******************************************************************************/ diff --git a/widget/WidgetEventImpl.cpp b/widget/WidgetEventImpl.cpp index 0e761d371614..44b5a3d67297 100644 --- a/widget/WidgetEventImpl.cpp +++ b/widget/WidgetEventImpl.cpp @@ -256,64 +256,6 @@ const nsCString GetDOMKeyCodeName(uint32_t aKeyCode) { } } -bool IsValidRawTextRangeValue(RawTextRangeType aRawTextRangeType) { - switch (static_cast(aRawTextRangeType)) { - case TextRangeType::eUninitialized: - case TextRangeType::eCaret: - case TextRangeType::eRawClause: - case TextRangeType::eSelectedRawClause: - case TextRangeType::eConvertedClause: - case TextRangeType::eSelectedClause: - return true; - default: - return false; - } -} - -RawTextRangeType ToRawTextRangeType(TextRangeType aTextRangeType) { - return static_cast(aTextRangeType); -} - -TextRangeType ToTextRangeType(RawTextRangeType aRawTextRangeType) { - MOZ_ASSERT(IsValidRawTextRangeValue(aRawTextRangeType)); - return static_cast(aRawTextRangeType); -} - -const char* 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"; - } -} - -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; - } -} - /****************************************************************************** * non class method implementation ******************************************************************************/