Bug 1746104 - part 6-2: Make constructors of `ContentCache::Selection` take `IMENotification::SelectionChangeData` or `WidgetQueryContentEvent` r=m_kato

Differential Revision: https://phabricator.services.mozilla.com/D137428
This commit is contained in:
Masayuki Nakano 2022-02-07 22:33:40 +00:00
Родитель e3a9c1271d
Коммит 47397b7081
6 изменённых файлов: 65 добавлений и 34 удалений

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

@ -137,15 +137,7 @@ bool ContentCacheInChild::CacheSelection(nsIWidget* aWidget,
return false;
}
MOZ_ASSERT(querySelectedTextEvent.mReply->mOffsetAndData.isSome());
if (querySelectedTextEvent.mReply->mReversed) {
mSelection.emplace(querySelectedTextEvent.mReply->EndOffset(),
querySelectedTextEvent.mReply->StartOffset(),
querySelectedTextEvent.mReply->WritingModeRef());
} else {
mSelection.emplace(querySelectedTextEvent.mReply->StartOffset(),
querySelectedTextEvent.mReply->EndOffset(),
querySelectedTextEvent.mReply->WritingModeRef());
}
mSelection.emplace(querySelectedTextEvent);
return CacheCaret(aWidget, aNotification) &&
CacheTextRects(aWidget, aNotification);
@ -474,21 +466,16 @@ bool ContentCacheInChild::CacheTextRects(nsIWidget* aWidget,
return true;
}
void ContentCacheInChild::SetSelection(nsIWidget* aWidget,
uint32_t aStartOffset, uint32_t aLength,
bool aReversed,
const WritingMode& aWritingMode) {
void ContentCacheInChild::SetSelection(
nsIWidget* aWidget,
const IMENotification::SelectionChangeDataBase& aSelectionChangeData) {
MOZ_LOG(
sContentCacheLog, LogLevel::Info,
("0x%p SetSelection(aStartOffset=%u, "
"aLength=%u, aReversed=%s, aWritingMode=%s), mText=%s",
this, aStartOffset, aLength, GetBoolName(aReversed),
ToString(aWritingMode).c_str(),
("0x%p SetSelection(aSelectionChangeData=%s), mText=%s", this,
ToString(aSelectionChangeData).c_str(),
PrintStringDetail(mText, PrintStringDetail::kMaxLengthForEditor).get()));
mSelection = Some(Selection(
!aReversed ? aStartOffset : aStartOffset + aLength,
!aReversed ? aStartOffset + aLength : aStartOffset, aWritingMode));
mSelection = Some(Selection(aSelectionChangeData));
if (mLastCommit.isSome()) {
// Forget last commit string range if selection is not collapsed
@ -1658,6 +1645,24 @@ void ContentCacheInParent::AppendEventMessageLog(nsACString& aLog) const {
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
/*****************************************************************************
* mozilla::ContentCache::Selection
*****************************************************************************/
ContentCache::Selection::Selection(
const WidgetQueryContentEvent& aQuerySelectedTextEvent)
: mAnchor(UINT32_MAX),
mFocus(UINT32_MAX),
mWritingMode(aQuerySelectedTextEvent.mReply->WritingModeRef()),
mHasRange(aQuerySelectedTextEvent.mReply->mOffsetAndData.isSome()) {
MOZ_ASSERT(aQuerySelectedTextEvent.mMessage == eQuerySelectedText);
MOZ_ASSERT(aQuerySelectedTextEvent.Succeeded());
if (mHasRange) {
mAnchor = aQuerySelectedTextEvent.mReply->AnchorOffset();
mFocus = aQuerySelectedTextEvent.mReply->FocusOffset();
}
}
/*****************************************************************************
* mozilla::ContentCache::TextRectArray
*****************************************************************************/

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

@ -60,6 +60,8 @@ class ContentCache {
WritingMode mWritingMode;
bool mHasRange;
// Character rects at previous and next character of mAnchor and mFocus.
// The reason why ContentCache needs to store each previous character of
// them is IME may query character rect of the last character of a line
@ -71,11 +73,19 @@ class ContentCache {
// Whole rect of selected text. This is empty if the selection is collapsed.
LayoutDeviceIntRect mRect;
explicit Selection(uint32_t aAnchorOffset, uint32_t aFocusOffset,
const WritingMode& aWritingMode)
: mAnchor(aAnchorOffset),
mFocus(aFocusOffset),
mWritingMode(aWritingMode) {}
explicit Selection(
const IMENotification::SelectionChangeDataBase& aSelectionChangeData)
: mAnchor(UINT32_MAX),
mFocus(UINT32_MAX),
mWritingMode(aSelectionChangeData.GetWritingMode()),
mHasRange(aSelectionChangeData.HasRange()) {
if (mHasRange) {
mAnchor = aSelectionChangeData.AnchorOffset();
mFocus = aSelectionChangeData.FocusOffset();
}
}
explicit Selection(const WidgetQueryContentEvent& aQuerySelectedTextEvent);
void ClearRects() {
for (auto& rect : mAnchorCharRects) {
@ -118,7 +128,12 @@ class ContentCache {
friend std::ostream& operator<<(std::ostream& aStream,
const Selection& aSelection) {
aStream << "{ mAnchor=" << aSelection.mAnchor
aStream << "{ ";
if (!aSelection.mHasRange) {
aStream << "HasRange()=false }";
return aStream;
}
aStream << "mAnchor=" << aSelection.mAnchor
<< ", mFocus=" << aSelection.mFocus
<< ", mWritingMode=" << ToString(aSelection.mWritingMode).c_str();
if (aSelection.HasRects()) {
@ -153,7 +168,8 @@ class ContentCache {
Maybe<Selection> mSelection;
bool IsSelectionValid() const {
return mSelection.isSome() && mSelection->EndOffset() <= mText.Length();
return mSelection.isSome() && mSelection->mHasRange &&
mSelection->EndOffset() <= mText.Length();
}
// Stores first char rect because Yosemite's Japanese IME sometimes tries
@ -308,8 +324,9 @@ class ContentCacheInChild final : public ContentCache {
* SetSelection() modifies selection with specified raw data. And also this
* tries to retrieve text rects too.
*/
void SetSelection(nsIWidget* aWidget, uint32_t aStartOffset, uint32_t aLength,
bool aReversed, const WritingMode& aWritingMode);
void SetSelection(
nsIWidget* aWidget,
const IMENotification::SelectionChangeDataBase& aSelectionChangeData);
private:
bool QueryCharRect(nsIWidget* aWidget, uint32_t aOffset,

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

@ -767,6 +767,14 @@ struct IMENotification final {
void SetWritingMode(const WritingMode& aWritingMode);
WritingMode GetWritingMode() const;
uint32_t StartOffset() const {
MOZ_ASSERT(mHasRange);
return mOffset;
}
uint32_t EndOffset() const {
MOZ_ASSERT(mHasRange);
return mOffset + Length();
}
uint32_t AnchorOffset() const {
MOZ_ASSERT(mHasRange);
return mOffset + (mReversed ? Length() : 0);

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

@ -835,11 +835,7 @@ nsresult PuppetWidget::NotifyIMEOfSelectionChange(
// Note that selection change must be notified after text change if it occurs.
// Therefore, we don't need to query text content again here.
mContentCache.SetSelection(
this, aIMENotification.mSelectionChangeData.mOffset,
aIMENotification.mSelectionChangeData.Length(),
aIMENotification.mSelectionChangeData.mReversed,
aIMENotification.mSelectionChangeData.GetWritingMode());
mContentCache.SetSelection(this, aIMENotification.mSelectionChangeData);
mBrowserChild->SendNotifyIMESelection(mContentCache, aIMENotification);

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

@ -25,6 +25,9 @@ with Files("reftests/*fallback*"):
with Files("*CompositorWidget*"):
BUG_COMPONENT = ("Core", "Graphics")
with Files("*ContentCache*"):
BUG_COMPONENT = ("Core", "DOM: UI Events & Focus Handling")
with Files("*ContentData*"):
BUG_COMPONENT = ("Core", "DOM: UI Events & Focus Handling")

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

@ -939,6 +939,7 @@ struct ParamTraits<mozilla::ContentCache::Selection> {
WriteParam(aMsg, aParam.mAnchor);
WriteParam(aMsg, aParam.mFocus);
WriteParam(aMsg, aParam.mWritingMode);
WriteParam(aMsg, aParam.mHasRange);
WriteParam(aMsg, aParam.mAnchorCharRects[0]);
WriteParam(aMsg, aParam.mAnchorCharRects[1]);
WriteParam(aMsg, aParam.mFocusCharRects[0]);
@ -951,6 +952,7 @@ struct ParamTraits<mozilla::ContentCache::Selection> {
return ReadParam(aMsg, aIter, &aResult->mAnchor) &&
ReadParam(aMsg, aIter, &aResult->mFocus) &&
ReadParam(aMsg, aIter, &aResult->mWritingMode) &&
ReadParam(aMsg, aIter, &aResult->mHasRange) &&
ReadParam(aMsg, aIter, &aResult->mAnchorCharRects[0]) &&
ReadParam(aMsg, aIter, &aResult->mAnchorCharRects[1]) &&
ReadParam(aMsg, aIter, &aResult->mFocusCharRects[0]) &&