зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1678553
- part 14: Make `nsQueryContentEventResult` store some results with `Maybe` r=m_kato
Depends on D98264 Differential Revision: https://phabricator.services.mozilla.com/D98265
This commit is contained in:
Родитель
350909e718
Коммит
fcb32b803d
|
@ -48,23 +48,14 @@ NS_INTERFACE_MAP_END
|
|||
NS_IMPL_ADDREF(nsQueryContentEventResult)
|
||||
NS_IMPL_RELEASE(nsQueryContentEventResult)
|
||||
|
||||
#define NOT_FOUND UINT32_MAX
|
||||
|
||||
nsQueryContentEventResult::nsQueryContentEventResult(
|
||||
mozilla::WidgetQueryContentEvent&& aEvent)
|
||||
: mEventMessage(aEvent.mMessage),
|
||||
mOffset(NOT_FOUND),
|
||||
mTentativeCaretOffset(NOT_FOUND),
|
||||
mSucceeded(aEvent.Succeeded()),
|
||||
mReversed(false) {
|
||||
if (mSucceeded) {
|
||||
if (aEvent.mReply->mOffsetAndData.isSome()) {
|
||||
mOffset = aEvent.mReply->StartOffset();
|
||||
mString = aEvent.mReply->DataRef();
|
||||
}
|
||||
if (aEvent.mReply->mTentativeCaretOffset.isSome()) {
|
||||
mTentativeCaretOffset = aEvent.mReply->mTentativeCaretOffset.value();
|
||||
}
|
||||
mOffsetAndData = std::move(aEvent.mReply->mOffsetAndData);
|
||||
mTentativeCaretOffset = std::move(aEvent.mReply->mTentativeCaretOffset);
|
||||
mRect = std::move(aEvent.mReply->mRect);
|
||||
mRectArray = std::move(aEvent.mReply->mRectArray);
|
||||
mReversed = aEvent.mReply->mReversed;
|
||||
|
@ -73,8 +64,6 @@ nsQueryContentEventResult::nsQueryContentEventResult(
|
|||
aEvent.mReply.reset();
|
||||
}
|
||||
|
||||
nsQueryContentEventResult::~nsQueryContentEventResult() = default;
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsQueryContentEventResult::GetOffset(uint32_t* aOffset) {
|
||||
if (NS_WARN_IF(!mSucceeded)) {
|
||||
|
@ -102,7 +91,7 @@ nsQueryContentEventResult::GetOffset(uint32_t* aOffset) {
|
|||
}
|
||||
}
|
||||
|
||||
*aOffset = mOffset;
|
||||
*aOffset = mOffsetAndData->StartOffset();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -116,7 +105,7 @@ nsQueryContentEventResult::GetTentativeCaretOffset(uint32_t* aOffset) {
|
|||
if (NS_WARN_IF(notFound)) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
*aOffset = mTentativeCaretOffset;
|
||||
*aOffset = mTentativeCaretOffset.value();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -171,7 +160,8 @@ nsQueryContentEventResult::GetText(nsAString& aText) {
|
|||
mEventMessage == eQueryTextContent ||
|
||||
mEventMessage == eQueryTextRect,
|
||||
NS_ERROR_NOT_AVAILABLE);
|
||||
aText = mString;
|
||||
NS_ENSURE_TRUE(mOffsetAndData.isSome(), NS_ERROR_NOT_AVAILABLE);
|
||||
aText = mOffsetAndData->DataRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -188,7 +178,7 @@ nsQueryContentEventResult::GetNotFound(bool* aNotFound) {
|
|||
NS_WARN_IF(!IsNotFoundPropertyAvailable(mEventMessage))) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
*aNotFound = mOffset == NOT_FOUND;
|
||||
*aNotFound = mOffsetAndData.isNothing();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -200,7 +190,7 @@ nsQueryContentEventResult::GetTentativeCaretOffsetNotFound(bool* aNotFound) {
|
|||
if (NS_WARN_IF(mEventMessage != eQueryCharacterAtPoint)) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
*aNotFound = mTentativeCaretOffset == NOT_FOUND;
|
||||
*aNotFound = mTentativeCaretOffset.isNothing();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -211,7 +201,7 @@ nsQueryContentEventResult::GetCharacterRect(int32_t aOffset, int32_t* aLeft,
|
|||
NS_ENSURE_TRUE(mSucceeded, NS_ERROR_NOT_AVAILABLE);
|
||||
NS_ENSURE_TRUE(mEventMessage == eQueryTextRectArray, NS_ERROR_NOT_AVAILABLE);
|
||||
|
||||
if (NS_WARN_IF(mRectArray.Length() <= static_cast<uint32_t>(aOffset))) {
|
||||
if (NS_WARN_IF(mRectArray.Length() <= static_cast<size_t>(aOffset))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -242,5 +232,3 @@ void nsQueryContentEventResult::SetEventResult(nsIWidget* aWidget) {
|
|||
mRectArray[i].MoveBy(-offset);
|
||||
}
|
||||
}
|
||||
|
||||
#undef NOT_FOUND
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include "Units.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/EventForwards.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/widget/IMEData.h"
|
||||
|
||||
class nsIWidget;
|
||||
|
||||
|
@ -26,13 +28,12 @@ class nsQueryContentEventResult final : public nsIQueryContentEventResult {
|
|||
void SetEventResult(nsIWidget* aWidget);
|
||||
|
||||
protected:
|
||||
~nsQueryContentEventResult();
|
||||
~nsQueryContentEventResult() = default;
|
||||
|
||||
mozilla::EventMessage mEventMessage;
|
||||
|
||||
uint32_t mOffset;
|
||||
uint32_t mTentativeCaretOffset;
|
||||
nsString mString;
|
||||
mozilla::Maybe<mozilla::OffsetAndData<uint32_t>> mOffsetAndData;
|
||||
mozilla::Maybe<uint32_t> mTentativeCaretOffset;
|
||||
mozilla::LayoutDeviceIntRect mRect;
|
||||
CopyableTArray<mozilla::LayoutDeviceIntRect> mRectArray;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче