mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 14:25:49 +00:00
Bug 1746104 - part 2-3: Clean up some code in IMEData.h r=m_kato
I'd like to use `OffsetAndData` in `IMMHandler` to store selection range. Before doing this, this patch adds some useful methods into it. Differential Revision: https://phabricator.services.mozilla.com/D137411
This commit is contained in:
parent
8365e27282
commit
9297e199b1
@ -339,5 +339,18 @@ std::ostream& operator<<(std::ostream& aStream,
|
||||
return aStream;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* IMENotification::SelectionChangeDataBase
|
||||
******************************************************************************/
|
||||
|
||||
void IMENotification::SelectionChangeDataBase::SetWritingMode(
|
||||
const WritingMode& aWritingMode) {
|
||||
mWritingModeBits = aWritingMode.GetBits();
|
||||
}
|
||||
|
||||
WritingMode IMENotification::SelectionChangeDataBase::GetWritingMode() const {
|
||||
return WritingMode(mWritingModeBits);
|
||||
}
|
||||
|
||||
} // namespace widget
|
||||
} // namespace mozilla
|
||||
|
@ -124,9 +124,15 @@ class OffsetAndData {
|
||||
OffsetAndDataFor aFor = OffsetAndDataFor::CompositionString)
|
||||
: mData(aData), mOffset(aStartOffset), mFor(aFor) {}
|
||||
|
||||
bool IsValid() const {
|
||||
CheckedInt<IntType> offset(mOffset);
|
||||
offset += mData.Length();
|
||||
return offset.isValid();
|
||||
}
|
||||
IntType StartOffset() const { return mOffset; }
|
||||
IntType Length() const {
|
||||
CheckedInt<IntType> endOffset(mOffset + mData.Length());
|
||||
CheckedInt<IntType> endOffset(CheckedInt<IntType>(mOffset) +
|
||||
mData.Length());
|
||||
return endOffset.isValid() ? mData.Length() : MaxOffset() - mOffset;
|
||||
}
|
||||
IntType EndOffset() const { return mOffset + Length(); }
|
||||
@ -742,13 +748,15 @@ struct IMENotification final {
|
||||
nsString* mString;
|
||||
|
||||
// Writing mode at the selection.
|
||||
uint8_t mWritingMode;
|
||||
uint8_t mWritingModeBits;
|
||||
|
||||
bool mReversed;
|
||||
bool mCausedByComposition;
|
||||
bool mCausedBySelectionEvent;
|
||||
bool mOccurredDuringComposition;
|
||||
|
||||
// FYI: Cannot we make these methods inline because of an include hell of
|
||||
// RawServoAnimationValueMap
|
||||
void SetWritingMode(const WritingMode& aWritingMode);
|
||||
WritingMode GetWritingMode() const;
|
||||
|
||||
@ -763,7 +771,7 @@ struct IMENotification final {
|
||||
void ClearSelectionData() {
|
||||
mOffset = UINT32_MAX;
|
||||
mString->Truncate();
|
||||
mWritingMode = 0;
|
||||
mWritingModeBits = 0;
|
||||
mReversed = false;
|
||||
}
|
||||
void Clear() {
|
||||
@ -776,7 +784,7 @@ struct IMENotification final {
|
||||
void Assign(const SelectionChangeDataBase& aOther) {
|
||||
mOffset = aOther.mOffset;
|
||||
*mString = aOther.String();
|
||||
mWritingMode = aOther.mWritingMode;
|
||||
mWritingModeBits = aOther.mWritingModeBits;
|
||||
mReversed = aOther.mReversed;
|
||||
AssignReason(aOther.mCausedByComposition, aOther.mCausedBySelectionEvent,
|
||||
aOther.mOccurredDuringComposition);
|
||||
@ -787,6 +795,11 @@ struct IMENotification final {
|
||||
mCausedBySelectionEvent = aCausedBySelectionEvent;
|
||||
mOccurredDuringComposition = aOccurredDuringComposition;
|
||||
}
|
||||
|
||||
OffsetAndData<uint32_t> ToUint32OffsetAndData() const {
|
||||
return OffsetAndData<uint32_t>(mOffset, *mString,
|
||||
OffsetAndDataFor::SelectedString);
|
||||
}
|
||||
};
|
||||
|
||||
// SelectionChangeDataBase cannot have constructors because it's used in
|
||||
|
@ -14,7 +14,6 @@
|
||||
#include "LiveResizeListener.h"
|
||||
#include "SwipeTracker.h"
|
||||
#include "TouchEvents.h"
|
||||
#include "WritingModes.h"
|
||||
#include "X11UndefineNone.h"
|
||||
#include "base/thread.h"
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
@ -124,19 +123,6 @@ uint64_t AutoObserverNotifier::sObserverId = 0;
|
||||
// milliseconds.
|
||||
const uint32_t kAsyncDragDropTimeout = 1000;
|
||||
|
||||
namespace mozilla::widget {
|
||||
|
||||
void IMENotification::SelectionChangeDataBase::SetWritingMode(
|
||||
const WritingMode& aWritingMode) {
|
||||
mWritingMode = aWritingMode.mWritingMode.bits;
|
||||
}
|
||||
|
||||
WritingMode IMENotification::SelectionChangeDataBase::GetWritingMode() const {
|
||||
return WritingMode(mWritingMode);
|
||||
}
|
||||
|
||||
} // namespace mozilla::widget
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsBaseWidget, nsIWidget, nsISupportsWeakReference)
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -702,7 +702,7 @@ struct ParamTraits<mozilla::widget::IMENotification::SelectionChangeDataBase> {
|
||||
MOZ_RELEASE_ASSERT(aParam.mString);
|
||||
WriteParam(aMsg, aParam.mOffset);
|
||||
WriteParam(aMsg, *aParam.mString);
|
||||
WriteParam(aMsg, aParam.mWritingMode);
|
||||
WriteParam(aMsg, aParam.mWritingModeBits);
|
||||
WriteParam(aMsg, aParam.mReversed);
|
||||
WriteParam(aMsg, aParam.mCausedByComposition);
|
||||
WriteParam(aMsg, aParam.mCausedBySelectionEvent);
|
||||
@ -714,7 +714,7 @@ struct ParamTraits<mozilla::widget::IMENotification::SelectionChangeDataBase> {
|
||||
aResult->mString = new nsString();
|
||||
return ReadParam(aMsg, aIter, &aResult->mOffset) &&
|
||||
ReadParam(aMsg, aIter, aResult->mString) &&
|
||||
ReadParam(aMsg, aIter, &aResult->mWritingMode) &&
|
||||
ReadParam(aMsg, aIter, &aResult->mWritingModeBits) &&
|
||||
ReadParam(aMsg, aIter, &aResult->mReversed) &&
|
||||
ReadParam(aMsg, aIter, &aResult->mCausedByComposition) &&
|
||||
ReadParam(aMsg, aIter, &aResult->mCausedBySelectionEvent) &&
|
||||
|
Loading…
x
Reference in New Issue
Block a user