2015-06-05 12:28:18 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=8 et :
|
|
|
|
*/
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/ContentCache.h"
|
2017-07-05 18:47:40 +03:00
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
#include "mozilla/IMEStateManager.h"
|
2017-07-05 18:47:40 +03:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
2015-06-05 12:28:20 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2017-07-05 18:47:40 +03:00
|
|
|
#include "mozilla/Move.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2015-06-05 12:28:20 +03:00
|
|
|
#include "mozilla/TextComposition.h"
|
2015-06-05 12:28:19 +03:00
|
|
|
#include "mozilla/TextEvents.h"
|
2019-04-10 00:38:15 +03:00
|
|
|
#include "mozilla/dom/BrowserParent.h"
|
2017-10-12 20:50:47 +03:00
|
|
|
#include "nsExceptionHandler.h"
|
2015-06-05 12:28:19 +03:00
|
|
|
#include "nsIWidget.h"
|
2015-06-05 12:28:18 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2017-07-05 18:47:40 +03:00
|
|
|
using namespace dom;
|
2015-06-05 12:28:19 +03:00
|
|
|
using namespace widget;
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
static const char* GetBoolName(bool aBool) { return aBool ? "true" : "false"; }
|
|
|
|
|
|
|
|
static const char* GetNotificationName(const IMENotification* aNotification) {
|
|
|
|
if (!aNotification) {
|
|
|
|
return "Not notification";
|
|
|
|
}
|
2016-05-31 05:39:15 +03:00
|
|
|
return ToChar(aNotification->mMessage);
|
2015-06-05 12:28:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class GetRectText : public nsAutoCString {
|
|
|
|
public:
|
|
|
|
explicit GetRectText(const LayoutDeviceIntRect& aRect) {
|
2017-09-04 08:12:56 +03:00
|
|
|
AssignLiteral("{ x=");
|
2018-01-10 19:14:16 +03:00
|
|
|
AppendInt(aRect.X());
|
2017-09-04 08:14:11 +03:00
|
|
|
AppendLiteral(", y=");
|
2018-01-10 19:14:16 +03:00
|
|
|
AppendInt(aRect.Y());
|
2017-09-04 08:14:11 +03:00
|
|
|
AppendLiteral(", width=");
|
2018-01-10 19:14:16 +03:00
|
|
|
AppendInt(aRect.Width());
|
2017-09-04 08:14:11 +03:00
|
|
|
AppendLiteral(", height=");
|
2018-01-10 19:14:16 +03:00
|
|
|
AppendInt(aRect.Height());
|
2017-09-04 08:14:11 +03:00
|
|
|
AppendLiteral(" }");
|
2015-06-05 12:28:20 +03:00
|
|
|
}
|
|
|
|
virtual ~GetRectText() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GetWritingModeName : public nsAutoCString {
|
|
|
|
public:
|
|
|
|
explicit GetWritingModeName(const WritingMode& aWritingMode) {
|
|
|
|
if (!aWritingMode.IsVertical()) {
|
2017-09-04 08:12:56 +03:00
|
|
|
AssignLiteral("Horizontal");
|
2015-06-05 12:28:20 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aWritingMode.IsVerticalLR()) {
|
2017-09-04 08:12:56 +03:00
|
|
|
AssignLiteral("Vertical (LTR)");
|
2015-06-05 12:28:20 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-09-04 08:12:56 +03:00
|
|
|
AssignLiteral("Vertical (RTL)");
|
2015-06-05 12:28:20 +03:00
|
|
|
}
|
|
|
|
virtual ~GetWritingModeName() {}
|
|
|
|
};
|
|
|
|
|
2016-07-13 12:16:04 +03:00
|
|
|
class GetEscapedUTF8String final : public NS_ConvertUTF16toUTF8 {
|
|
|
|
public:
|
|
|
|
explicit GetEscapedUTF8String(const nsAString& aString)
|
|
|
|
: NS_ConvertUTF16toUTF8(aString) {
|
|
|
|
Escape();
|
|
|
|
}
|
|
|
|
explicit GetEscapedUTF8String(const char16ptr_t aString)
|
|
|
|
: NS_ConvertUTF16toUTF8(aString) {
|
|
|
|
Escape();
|
|
|
|
}
|
|
|
|
GetEscapedUTF8String(const char16ptr_t aString, uint32_t aLength)
|
|
|
|
: NS_ConvertUTF16toUTF8(aString, aLength) {
|
|
|
|
Escape();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Escape() {
|
|
|
|
ReplaceSubstring("\r", "\\r");
|
|
|
|
ReplaceSubstring("\n", "\\n");
|
|
|
|
ReplaceSubstring("\t", "\\t");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-05 12:28:19 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::ContentCache
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-06-13 12:17:58 +03:00
|
|
|
LazyLogModule sContentCacheLog("ContentCacheWidgets");
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2016-06-13 12:17:58 +03:00
|
|
|
ContentCache::ContentCache() : mCompositionStart(UINT32_MAX) {}
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::ContentCacheInChild
|
|
|
|
*****************************************************************************/
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
ContentCacheInChild::ContentCacheInChild() : ContentCache() {}
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
void ContentCacheInChild::Clear() {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info, ("0x%p Clear()", this));
|
2015-06-05 12:28:21 +03:00
|
|
|
|
2016-06-13 12:17:58 +03:00
|
|
|
mCompositionStart = UINT32_MAX;
|
2015-06-05 12:28:18 +03:00
|
|
|
mText.Truncate();
|
2015-06-05 12:28:20 +03:00
|
|
|
mSelection.Clear();
|
2015-06-17 04:03:58 +03:00
|
|
|
mFirstCharRect.SetEmpty();
|
2015-06-05 12:28:20 +03:00
|
|
|
mCaret.Clear();
|
|
|
|
mTextRectArray.Clear();
|
|
|
|
mEditorRect.SetEmpty();
|
2015-06-05 12:28:18 +03:00
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
bool ContentCacheInChild::CacheAll(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheAll(aWidget=0x%p, aNotification=%s)", this, aWidget,
|
2015-06-26 02:21:13 +03:00
|
|
|
GetNotificationName(aNotification)));
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
if (NS_WARN_IF(!CacheText(aWidget, aNotification)) ||
|
|
|
|
NS_WARN_IF(!CacheEditorRect(aWidget, aNotification))) {
|
2015-06-05 12:28:20 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
bool ContentCacheInChild::CacheSelection(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheSelection(aWidget=0x%p, aNotification=%s)", this, aWidget,
|
2015-06-26 02:21:13 +03:00
|
|
|
GetNotificationName(aNotification)));
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
mCaret.Clear();
|
|
|
|
mSelection.Clear();
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-09-10 04:40:05 +03:00
|
|
|
WidgetQueryContentEvent selection(true, eQuerySelectedText, aWidget);
|
2015-06-05 12:28:20 +03:00
|
|
|
aWidget->DispatchEvent(&selection, status);
|
|
|
|
if (NS_WARN_IF(!selection.mSucceeded)) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheSelection(), FAILED, "
|
2015-06-26 02:21:13 +03:00
|
|
|
"couldn't retrieve the selected text",
|
|
|
|
this));
|
2015-06-05 12:28:20 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (selection.mReply.mReversed) {
|
|
|
|
mSelection.mAnchor =
|
|
|
|
selection.mReply.mOffset + selection.mReply.mString.Length();
|
|
|
|
mSelection.mFocus = selection.mReply.mOffset;
|
|
|
|
} else {
|
|
|
|
mSelection.mAnchor = selection.mReply.mOffset;
|
|
|
|
mSelection.mFocus =
|
|
|
|
selection.mReply.mOffset + selection.mReply.mString.Length();
|
|
|
|
}
|
|
|
|
mSelection.mWritingMode = selection.GetWritingMode();
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
return CacheCaret(aWidget, aNotification) &&
|
|
|
|
CacheTextRects(aWidget, aNotification);
|
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
bool ContentCacheInChild::CacheCaret(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheCaret(aWidget=0x%p, aNotification=%s)", this, aWidget,
|
2015-06-26 02:21:13 +03:00
|
|
|
GetNotificationName(aNotification)));
|
2015-06-05 12:28:20 +03:00
|
|
|
|
|
|
|
mCaret.Clear();
|
|
|
|
|
2015-06-05 12:28:21 +03:00
|
|
|
if (NS_WARN_IF(!mSelection.IsValid())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
// XXX Should be mSelection.mFocus?
|
2015-06-05 12:28:20 +03:00
|
|
|
mCaret.mOffset = mSelection.StartOffset();
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-09-10 04:40:06 +03:00
|
|
|
WidgetQueryContentEvent caretRect(true, eQueryCaretRect, aWidget);
|
2015-06-05 12:28:20 +03:00
|
|
|
caretRect.InitForQueryCaretRect(mCaret.mOffset);
|
|
|
|
aWidget->DispatchEvent(&caretRect, status);
|
|
|
|
if (NS_WARN_IF(!caretRect.mSucceeded)) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheCaret(), FAILED, "
|
2015-06-05 12:28:20 +03:00
|
|
|
"couldn't retrieve the caret rect at offset=%u",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, mCaret.mOffset));
|
2015-06-05 12:28:20 +03:00
|
|
|
mCaret.Clear();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mCaret.mRect = caretRect.mReply.mRect;
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheCaret(), Succeeded, "
|
2015-06-05 12:28:20 +03:00
|
|
|
"mSelection={ mAnchor=%u, mFocus=%u, mWritingMode=%s }, "
|
|
|
|
"mCaret={ mOffset=%u, mRect=%s }",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, mSelection.mAnchor, mSelection.mFocus,
|
2015-06-05 12:28:20 +03:00
|
|
|
GetWritingModeName(mSelection.mWritingMode).get(), mCaret.mOffset,
|
|
|
|
GetRectText(mCaret.mRect).get()));
|
2015-06-05 12:28:20 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
bool ContentCacheInChild::CacheEditorRect(
|
|
|
|
nsIWidget* aWidget, const IMENotification* aNotification) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheEditorRect(aWidget=0x%p, aNotification=%s)", this,
|
2015-06-26 02:21:13 +03:00
|
|
|
aWidget, GetNotificationName(aNotification)));
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-09-10 04:40:06 +03:00
|
|
|
WidgetQueryContentEvent editorRectEvent(true, eQueryEditorRect, aWidget);
|
2015-06-05 12:28:20 +03:00
|
|
|
aWidget->DispatchEvent(&editorRectEvent, status);
|
|
|
|
if (NS_WARN_IF(!editorRectEvent.mSucceeded)) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheEditorRect(), FAILED, "
|
2015-06-26 02:21:13 +03:00
|
|
|
"couldn't retrieve the editor rect",
|
|
|
|
this));
|
2015-06-05 12:28:20 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mEditorRect = editorRectEvent.mReply.mRect;
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheEditorRect(), Succeeded, "
|
2015-06-26 02:21:13 +03:00
|
|
|
"mEditorRect=%s",
|
|
|
|
this, GetRectText(mEditorRect).get()));
|
2015-06-05 12:28:20 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
bool ContentCacheInChild::CacheText(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheText(aWidget=0x%p, aNotification=%s)", this, aWidget,
|
2015-06-26 02:21:13 +03:00
|
|
|
GetNotificationName(aNotification)));
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-09-10 04:40:05 +03:00
|
|
|
WidgetQueryContentEvent queryText(true, eQueryTextContent, aWidget);
|
2015-06-05 12:28:20 +03:00
|
|
|
queryText.InitForQueryTextContent(0, UINT32_MAX);
|
|
|
|
aWidget->DispatchEvent(&queryText, status);
|
|
|
|
if (NS_WARN_IF(!queryText.mSucceeded)) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheText(), FAILED, couldn't retrieve whole text", this));
|
2015-06-05 12:28:20 +03:00
|
|
|
mText.Truncate();
|
2015-06-05 12:28:20 +03:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
mText = queryText.mReply.mString;
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheText(), Succeeded, mText.Length()=%u", this, mText.Length()));
|
2015-06-05 12:28:20 +03:00
|
|
|
|
|
|
|
return CacheSelection(aWidget, aNotification);
|
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
bool ContentCacheInChild::QueryCharRect(nsIWidget* aWidget, uint32_t aOffset,
|
|
|
|
LayoutDeviceIntRect& aCharRect) const {
|
2015-06-05 12:28:20 +03:00
|
|
|
aCharRect.SetEmpty();
|
|
|
|
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-09-11 15:21:26 +03:00
|
|
|
WidgetQueryContentEvent textRect(true, eQueryTextRect, aWidget);
|
2015-06-05 12:28:20 +03:00
|
|
|
textRect.InitForQueryTextRect(aOffset, 1);
|
|
|
|
aWidget->DispatchEvent(&textRect, status);
|
|
|
|
if (NS_WARN_IF(!textRect.mSucceeded)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aCharRect = textRect.mReply.mRect;
|
|
|
|
|
|
|
|
// Guarantee the rect is not empty.
|
2018-01-10 19:14:16 +03:00
|
|
|
if (NS_WARN_IF(!aCharRect.Height())) {
|
|
|
|
aCharRect.SetHeight(1);
|
2015-06-05 12:28:20 +03:00
|
|
|
}
|
2018-01-10 19:14:16 +03:00
|
|
|
if (NS_WARN_IF(!aCharRect.Width())) {
|
|
|
|
aCharRect.SetWidth(1);
|
2015-06-05 12:28:20 +03:00
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-22 14:47:51 +03:00
|
|
|
bool ContentCacheInChild::QueryCharRectArray(nsIWidget* aWidget,
|
|
|
|
uint32_t aOffset, uint32_t aLength,
|
|
|
|
RectArray& aCharRectArray) const {
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
WidgetQueryContentEvent textRects(true, eQueryTextRectArray, aWidget);
|
|
|
|
textRects.InitForQueryTextRectArray(aOffset, aLength);
|
|
|
|
aWidget->DispatchEvent(&textRects, status);
|
|
|
|
if (NS_WARN_IF(!textRects.mSucceeded)) {
|
|
|
|
aCharRectArray.Clear();
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-30 22:15:35 +03:00
|
|
|
aCharRectArray = std::move(textRects.mReply.mRectArray);
|
2016-07-22 14:47:51 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
bool ContentCacheInChild::CacheTextRects(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheTextRects(aWidget=0x%p, aNotification=%s), "
|
|
|
|
"mCaret={ mOffset=%u, IsValid()=%s }",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, aWidget, GetNotificationName(aNotification), mCaret.mOffset,
|
2015-06-05 12:28:20 +03:00
|
|
|
GetBoolName(mCaret.IsValid())));
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2016-06-13 12:17:58 +03:00
|
|
|
mCompositionStart = UINT32_MAX;
|
2015-06-05 12:28:20 +03:00
|
|
|
mTextRectArray.Clear();
|
2016-07-22 14:47:51 +03:00
|
|
|
mSelection.ClearAnchorCharRects();
|
|
|
|
mSelection.ClearFocusCharRects();
|
2015-06-08 05:46:17 +03:00
|
|
|
mSelection.mRect.SetEmpty();
|
2015-06-17 04:03:58 +03:00
|
|
|
mFirstCharRect.SetEmpty();
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-05 12:28:21 +03:00
|
|
|
if (NS_WARN_IF(!mSelection.IsValid())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
// Retrieve text rects in composition string if there is.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextComposition> textComposition =
|
2015-06-05 12:28:20 +03:00
|
|
|
IMEStateManager::GetTextCompositionFor(aWidget);
|
2015-06-05 12:28:20 +03:00
|
|
|
if (textComposition) {
|
2016-06-13 12:17:58 +03:00
|
|
|
// mCompositionStart may be updated by some composition event handlers.
|
|
|
|
// So, let's update it with the latest information.
|
|
|
|
mCompositionStart = textComposition->NativeOffsetOfStartComposition();
|
2015-06-05 12:28:20 +03:00
|
|
|
// Note that TextComposition::String() may not be modified here because
|
|
|
|
// it's modified after all edit action listeners are performed but this
|
|
|
|
// is called while some of them are performed.
|
2017-06-29 12:31:09 +03:00
|
|
|
// FYI: For supporting IME which commits composition and restart new
|
|
|
|
// composition immediately, we should cache next character of current
|
|
|
|
// composition too.
|
|
|
|
uint32_t length = textComposition->LastData().Length() + 1;
|
2016-06-13 12:17:58 +03:00
|
|
|
mTextRectArray.mStart = mCompositionStart;
|
2016-07-22 14:47:51 +03:00
|
|
|
if (NS_WARN_IF(!QueryCharRectArray(aWidget, mTextRectArray.mStart, length,
|
|
|
|
mTextRectArray.mRects))) {
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
|
|
|
("0x%p CacheTextRects(), FAILED, "
|
|
|
|
"couldn't retrieve text rect array of the composition string",
|
|
|
|
this));
|
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
}
|
|
|
|
|
2016-07-22 14:47:51 +03:00
|
|
|
if (mTextRectArray.InRange(mSelection.mAnchor) &&
|
|
|
|
(!mSelection.mAnchor || mTextRectArray.InRange(mSelection.mAnchor - 1))) {
|
|
|
|
mSelection.mAnchorCharRects[eNextCharRect] =
|
|
|
|
mTextRectArray.GetRect(mSelection.mAnchor);
|
|
|
|
if (mSelection.mAnchor) {
|
|
|
|
mSelection.mAnchorCharRects[ePrevCharRect] =
|
|
|
|
mTextRectArray.GetRect(mSelection.mAnchor - 1);
|
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
} else {
|
2016-07-22 14:47:51 +03:00
|
|
|
RectArray rects;
|
|
|
|
uint32_t startOffset = mSelection.mAnchor ? mSelection.mAnchor - 1 : 0;
|
|
|
|
uint32_t length = mSelection.mAnchor ? 2 : 1;
|
|
|
|
if (NS_WARN_IF(!QueryCharRectArray(aWidget, startOffset, length, rects))) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheTextRects(), FAILED, "
|
2016-07-22 14:47:51 +03:00
|
|
|
"couldn't retrieve text rect array around the selection anchor (%u)",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, mSelection.mAnchor));
|
2016-07-22 14:47:51 +03:00
|
|
|
MOZ_ASSERT(mSelection.mAnchorCharRects[ePrevCharRect].IsEmpty());
|
|
|
|
MOZ_ASSERT(mSelection.mAnchorCharRects[eNextCharRect].IsEmpty());
|
|
|
|
} else {
|
|
|
|
if (rects.Length() > 1) {
|
|
|
|
mSelection.mAnchorCharRects[ePrevCharRect] = rects[0];
|
|
|
|
mSelection.mAnchorCharRects[eNextCharRect] = rects[1];
|
|
|
|
} else if (rects.Length()) {
|
|
|
|
mSelection.mAnchorCharRects[eNextCharRect] = rects[0];
|
|
|
|
MOZ_ASSERT(mSelection.mAnchorCharRects[ePrevCharRect].IsEmpty());
|
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
}
|
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
|
|
|
|
if (mSelection.Collapsed()) {
|
2016-07-22 14:47:51 +03:00
|
|
|
mSelection.mFocusCharRects[0] = mSelection.mAnchorCharRects[0];
|
|
|
|
mSelection.mFocusCharRects[1] = mSelection.mAnchorCharRects[1];
|
|
|
|
} else if (mTextRectArray.InRange(mSelection.mFocus) &&
|
|
|
|
(!mSelection.mFocus ||
|
|
|
|
mTextRectArray.InRange(mSelection.mFocus - 1))) {
|
|
|
|
mSelection.mFocusCharRects[eNextCharRect] =
|
|
|
|
mTextRectArray.GetRect(mSelection.mFocus);
|
|
|
|
if (mSelection.mFocus) {
|
|
|
|
mSelection.mFocusCharRects[ePrevCharRect] =
|
|
|
|
mTextRectArray.GetRect(mSelection.mFocus - 1);
|
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
} else {
|
2016-07-22 14:47:51 +03:00
|
|
|
RectArray rects;
|
|
|
|
uint32_t startOffset = mSelection.mFocus ? mSelection.mFocus - 1 : 0;
|
|
|
|
uint32_t length = mSelection.mFocus ? 2 : 1;
|
|
|
|
if (NS_WARN_IF(!QueryCharRectArray(aWidget, startOffset, length, rects))) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheTextRects(), FAILED, "
|
2016-07-22 14:47:51 +03:00
|
|
|
"couldn't retrieve text rect array around the selection focus (%u)",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, mSelection.mFocus));
|
2016-07-22 14:47:51 +03:00
|
|
|
MOZ_ASSERT(mSelection.mFocusCharRects[ePrevCharRect].IsEmpty());
|
|
|
|
MOZ_ASSERT(mSelection.mFocusCharRects[eNextCharRect].IsEmpty());
|
|
|
|
} else {
|
|
|
|
if (rects.Length() > 1) {
|
|
|
|
mSelection.mFocusCharRects[ePrevCharRect] = rects[0];
|
|
|
|
mSelection.mFocusCharRects[eNextCharRect] = rects[1];
|
|
|
|
} else if (rects.Length()) {
|
|
|
|
mSelection.mFocusCharRects[eNextCharRect] = rects[0];
|
|
|
|
MOZ_ASSERT(mSelection.mFocusCharRects[ePrevCharRect].IsEmpty());
|
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-08 05:46:17 +03:00
|
|
|
if (!mSelection.Collapsed()) {
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2015-09-11 15:21:26 +03:00
|
|
|
WidgetQueryContentEvent textRect(true, eQueryTextRect, aWidget);
|
2015-06-08 05:46:17 +03:00
|
|
|
textRect.InitForQueryTextRect(mSelection.StartOffset(),
|
|
|
|
mSelection.Length());
|
|
|
|
aWidget->DispatchEvent(&textRect, status);
|
|
|
|
if (NS_WARN_IF(!textRect.mSucceeded)) {
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheTextRects(), FAILED, "
|
2015-06-26 02:21:13 +03:00
|
|
|
"couldn't retrieve text rect of whole selected text",
|
|
|
|
this));
|
2015-06-08 05:46:17 +03:00
|
|
|
} else {
|
|
|
|
mSelection.mRect = textRect.mReply.mRect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 04:03:58 +03:00
|
|
|
if (!mSelection.mFocus) {
|
2016-07-22 14:47:51 +03:00
|
|
|
mFirstCharRect = mSelection.mFocusCharRects[eNextCharRect];
|
|
|
|
} else if (mSelection.mFocus == 1) {
|
|
|
|
mFirstCharRect = mSelection.mFocusCharRects[ePrevCharRect];
|
2015-06-17 04:03:58 +03:00
|
|
|
} else if (!mSelection.mAnchor) {
|
2016-07-22 14:47:51 +03:00
|
|
|
mFirstCharRect = mSelection.mAnchorCharRects[eNextCharRect];
|
|
|
|
} else if (mSelection.mAnchor == 1) {
|
|
|
|
mFirstCharRect = mSelection.mFocusCharRects[ePrevCharRect];
|
2015-06-17 04:03:58 +03:00
|
|
|
} else if (mTextRectArray.InRange(0)) {
|
|
|
|
mFirstCharRect = mTextRectArray.GetRect(0);
|
|
|
|
} else {
|
|
|
|
LayoutDeviceIntRect charRect;
|
|
|
|
if (NS_WARN_IF(!QueryCharRect(aWidget, 0, charRect))) {
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheTextRects(), FAILED, "
|
2015-06-26 02:21:13 +03:00
|
|
|
"couldn't retrieve first char rect",
|
|
|
|
this));
|
2015-06-17 04:03:58 +03:00
|
|
|
} else {
|
|
|
|
mFirstCharRect = charRect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p CacheTextRects(), Succeeded, "
|
2017-07-26 23:03:57 +03:00
|
|
|
"mText.Length()=%x, mTextRectArray={ mStart=%u, mRects.Length()=%zu"
|
|
|
|
" }, mSelection={ mAnchor=%u, mAnchorCharRects[eNextCharRect]=%s, "
|
2016-07-22 14:47:51 +03:00
|
|
|
"mAnchorCharRects[ePrevCharRect]=%s, mFocus=%u, "
|
|
|
|
"mFocusCharRects[eNextCharRect]=%s, mFocusCharRects[ePrevCharRect]=%s, "
|
|
|
|
"mRect=%s }, mFirstCharRect=%s",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, mText.Length(), mTextRectArray.mStart,
|
2015-06-05 12:28:20 +03:00
|
|
|
mTextRectArray.mRects.Length(), mSelection.mAnchor,
|
2016-07-22 14:47:51 +03:00
|
|
|
GetRectText(mSelection.mAnchorCharRects[eNextCharRect]).get(),
|
|
|
|
GetRectText(mSelection.mAnchorCharRects[ePrevCharRect]).get(),
|
|
|
|
mSelection.mFocus,
|
|
|
|
GetRectText(mSelection.mFocusCharRects[eNextCharRect]).get(),
|
|
|
|
GetRectText(mSelection.mFocusCharRects[ePrevCharRect]).get(),
|
2015-06-17 04:03:58 +03:00
|
|
|
GetRectText(mSelection.mRect).get(), GetRectText(mFirstCharRect).get()));
|
2015-06-05 12:28:20 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
void ContentCacheInChild::SetSelection(nsIWidget* aWidget,
|
|
|
|
uint32_t aStartOffset, uint32_t aLength,
|
|
|
|
bool aReversed,
|
|
|
|
const WritingMode& aWritingMode) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p SetSelection(aStartOffset=%u, "
|
2015-06-05 12:28:20 +03:00
|
|
|
"aLength=%u, aReversed=%s, aWritingMode=%s), mText.Length()=%u",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, aStartOffset, aLength, GetBoolName(aReversed),
|
|
|
|
GetWritingModeName(aWritingMode).get(), mText.Length()));
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
if (!aReversed) {
|
|
|
|
mSelection.mAnchor = aStartOffset;
|
|
|
|
mSelection.mFocus = aStartOffset + aLength;
|
|
|
|
} else {
|
|
|
|
mSelection.mAnchor = aStartOffset + aLength;
|
|
|
|
mSelection.mFocus = aStartOffset;
|
|
|
|
}
|
|
|
|
mSelection.mWritingMode = aWritingMode;
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
if (NS_WARN_IF(!CacheCaret(aWidget))) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(!CacheTextRects(aWidget));
|
2015-06-05 12:28:19 +03:00
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::ContentCacheInParent
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2019-04-10 00:38:15 +03:00
|
|
|
ContentCacheInParent::ContentCacheInParent(BrowserParent& aBrowserParent)
|
2015-06-26 02:21:13 +03:00
|
|
|
: ContentCache(),
|
2019-04-10 00:38:15 +03:00
|
|
|
mBrowserParent(aBrowserParent),
|
2015-12-11 09:15:58 +03:00
|
|
|
mCommitStringByRequest(nullptr),
|
2015-07-11 04:53:55 +03:00
|
|
|
mPendingEventsNeedingAck(0),
|
2016-10-12 15:52:01 +03:00
|
|
|
mCompositionStartInChild(UINT32_MAX),
|
2017-11-27 12:51:01 +03:00
|
|
|
mPendingCommitLength(0),
|
2016-10-12 11:09:02 +03:00
|
|
|
mPendingCompositionCount(0),
|
2017-12-06 09:07:41 +03:00
|
|
|
mPendingCommitCount(0),
|
2016-10-12 10:42:28 +03:00
|
|
|
mWidgetHasComposition(false),
|
2017-12-06 09:07:41 +03:00
|
|
|
mIsChildIgnoringCompositionEvents(false) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
void ContentCacheInParent::AssignContent(const ContentCache& aOther,
|
2016-06-14 15:06:34 +03:00
|
|
|
nsIWidget* aWidget,
|
2015-06-26 02:21:13 +03:00
|
|
|
const IMENotification* aNotification) {
|
|
|
|
mText = aOther.mText;
|
|
|
|
mSelection = aOther.mSelection;
|
|
|
|
mFirstCharRect = aOther.mFirstCharRect;
|
|
|
|
mCaret = aOther.mCaret;
|
|
|
|
mTextRectArray = aOther.mTextRectArray;
|
|
|
|
mEditorRect = aOther.mEditorRect;
|
|
|
|
|
2016-10-12 16:03:16 +03:00
|
|
|
// Only when there is one composition, the TextComposition instance in this
|
|
|
|
// process is managing the composition in the remote process. Therefore,
|
|
|
|
// we shouldn't update composition start offset of TextComposition with
|
|
|
|
// old composition which is still being handled by the child process.
|
|
|
|
if (mWidgetHasComposition && mPendingCompositionCount == 1) {
|
2016-06-14 15:06:34 +03:00
|
|
|
IMEStateManager::MaybeStartOffsetUpdatedInChild(aWidget, mCompositionStart);
|
|
|
|
}
|
|
|
|
|
2018-01-12 09:05:24 +03:00
|
|
|
// When this instance allows to query content relative to composition string,
|
|
|
|
// we should modify mCompositionStart with the latest information in the
|
|
|
|
// remote process because now we have the information around the composition
|
|
|
|
// string.
|
2016-10-12 15:52:01 +03:00
|
|
|
mCompositionStartInChild = aOther.mCompositionStart;
|
2018-01-12 09:05:24 +03:00
|
|
|
if (mWidgetHasComposition || mPendingCommitCount) {
|
Bug 1304620 part.4 ContentCacheInParent::mCompositionStart should be set to better value for mWidgetHasComposition state r=m_kato
ContentCacheInParent::mCompositionStart was set to ContentCacheInChild::mCompositionStart without any check. However, that's clearly wrong approach. For example, when the remote process handles some composition events after eCompositionCommit(AsIs) in the parent process, mCompositionStart is valid offset even after mWidgetHasComposition is set to false. Similarly, even after parent process sends eCompositionStart, the remote process may send invalid offset for mCompositionStart due to no composition in it.
For solving this issue, ContentCacheInParent should check mWidgetHasComposition.
If it's true and coming offset is valid, let's use it (even if mPendingCompositionCount is 2 or bigger since widget shouldn't use WidgetQueryContentEvent when there are some pending events).
If the coming offset is invalid but mWidgetHasComposition is false, let's use selection start instead because HandleQueryContentEvent() can work around selection start offset only.
Otherwise, i.e., mWidgetHasComposition is false, we should always set mCompositionStart to invalid offset.
MozReview-Commit-ID: IONU0Cbhpil
--HG--
extra : rebase_source : 05ae9eb0e7a0bb63b65be7a54103eb798274c8ff
2016-10-12 16:05:09 +03:00
|
|
|
if (aOther.mCompositionStart != UINT32_MAX) {
|
2017-06-29 12:31:09 +03:00
|
|
|
if (mCompositionStart != aOther.mCompositionStart) {
|
|
|
|
mCompositionStart = aOther.mCompositionStart;
|
|
|
|
mPendingCommitLength = 0;
|
|
|
|
}
|
|
|
|
} else if (mCompositionStart != mSelection.StartOffset()) {
|
Bug 1304620 part.4 ContentCacheInParent::mCompositionStart should be set to better value for mWidgetHasComposition state r=m_kato
ContentCacheInParent::mCompositionStart was set to ContentCacheInChild::mCompositionStart without any check. However, that's clearly wrong approach. For example, when the remote process handles some composition events after eCompositionCommit(AsIs) in the parent process, mCompositionStart is valid offset even after mWidgetHasComposition is set to false. Similarly, even after parent process sends eCompositionStart, the remote process may send invalid offset for mCompositionStart due to no composition in it.
For solving this issue, ContentCacheInParent should check mWidgetHasComposition.
If it's true and coming offset is valid, let's use it (even if mPendingCompositionCount is 2 or bigger since widget shouldn't use WidgetQueryContentEvent when there are some pending events).
If the coming offset is invalid but mWidgetHasComposition is false, let's use selection start instead because HandleQueryContentEvent() can work around selection start offset only.
Otherwise, i.e., mWidgetHasComposition is false, we should always set mCompositionStart to invalid offset.
MozReview-Commit-ID: IONU0Cbhpil
--HG--
extra : rebase_source : 05ae9eb0e7a0bb63b65be7a54103eb798274c8ff
2016-10-12 16:05:09 +03:00
|
|
|
mCompositionStart = mSelection.StartOffset();
|
2017-06-29 12:31:09 +03:00
|
|
|
mPendingCommitLength = 0;
|
Bug 1304620 part.4 ContentCacheInParent::mCompositionStart should be set to better value for mWidgetHasComposition state r=m_kato
ContentCacheInParent::mCompositionStart was set to ContentCacheInChild::mCompositionStart without any check. However, that's clearly wrong approach. For example, when the remote process handles some composition events after eCompositionCommit(AsIs) in the parent process, mCompositionStart is valid offset even after mWidgetHasComposition is set to false. Similarly, even after parent process sends eCompositionStart, the remote process may send invalid offset for mCompositionStart due to no composition in it.
For solving this issue, ContentCacheInParent should check mWidgetHasComposition.
If it's true and coming offset is valid, let's use it (even if mPendingCompositionCount is 2 or bigger since widget shouldn't use WidgetQueryContentEvent when there are some pending events).
If the coming offset is invalid but mWidgetHasComposition is false, let's use selection start instead because HandleQueryContentEvent() can work around selection start offset only.
Otherwise, i.e., mWidgetHasComposition is false, we should always set mCompositionStart to invalid offset.
MozReview-Commit-ID: IONU0Cbhpil
--HG--
extra : rebase_source : 05ae9eb0e7a0bb63b65be7a54103eb798274c8ff
2016-10-12 16:05:09 +03:00
|
|
|
NS_WARNING_ASSERTION(mCompositionStart != UINT32_MAX,
|
|
|
|
"mCompositionStart shouldn't be invalid offset when "
|
|
|
|
"the widget has composition");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p AssignContent(aNotification=%s), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"Succeeded, mText.Length()=%u, mSelection={ mAnchor=%u, mFocus=%u, "
|
2016-07-22 14:47:51 +03:00
|
|
|
"mWritingMode=%s, mAnchorCharRects[eNextCharRect]=%s, "
|
|
|
|
"mAnchorCharRects[ePrevCharRect]=%s, mFocusCharRects[eNextCharRect]=%s, "
|
|
|
|
"mFocusCharRects[ePrevCharRect]=%s, mRect=%s }, "
|
2015-06-26 02:21:13 +03:00
|
|
|
"mFirstCharRect=%s, mCaret={ mOffset=%u, mRect=%s }, mTextRectArray={ "
|
2017-07-26 23:03:57 +03:00
|
|
|
"mStart=%u, mRects.Length()=%zu }, mWidgetHasComposition=%s, "
|
2017-06-29 12:31:09 +03:00
|
|
|
"mPendingCompositionCount=%u, mCompositionStart=%u, "
|
|
|
|
"mPendingCommitLength=%u, mEditorRect=%s",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, GetNotificationName(aNotification), mText.Length(),
|
|
|
|
mSelection.mAnchor, mSelection.mFocus,
|
|
|
|
GetWritingModeName(mSelection.mWritingMode).get(),
|
2016-07-22 14:47:51 +03:00
|
|
|
GetRectText(mSelection.mAnchorCharRects[eNextCharRect]).get(),
|
|
|
|
GetRectText(mSelection.mAnchorCharRects[ePrevCharRect]).get(),
|
|
|
|
GetRectText(mSelection.mFocusCharRects[eNextCharRect]).get(),
|
|
|
|
GetRectText(mSelection.mFocusCharRects[ePrevCharRect]).get(),
|
2015-06-26 02:21:13 +03:00
|
|
|
GetRectText(mSelection.mRect).get(), GetRectText(mFirstCharRect).get(),
|
|
|
|
mCaret.mOffset, GetRectText(mCaret.mRect).get(), mTextRectArray.mStart,
|
2016-10-12 10:42:28 +03:00
|
|
|
mTextRectArray.mRects.Length(), GetBoolName(mWidgetHasComposition),
|
2017-06-29 12:31:09 +03:00
|
|
|
mPendingCompositionCount, mCompositionStart, mPendingCommitLength,
|
2016-10-12 16:03:16 +03:00
|
|
|
GetRectText(mEditorRect).get()));
|
2015-06-26 02:21:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ContentCacheInParent::HandleQueryContentEvent(
|
|
|
|
WidgetQueryContentEvent& aEvent, nsIWidget* aWidget) const {
|
|
|
|
MOZ_ASSERT(aWidget);
|
|
|
|
|
|
|
|
aEvent.mSucceeded = false;
|
|
|
|
aEvent.mReply.mFocusedWidget = aWidget;
|
|
|
|
|
2016-06-14 14:54:54 +03:00
|
|
|
// ContentCache doesn't store offset of its start with XP linebreaks.
|
|
|
|
// So, we don't support to query contents relative to composition start
|
|
|
|
// offset with XP linebreaks.
|
|
|
|
if (NS_WARN_IF(!aEvent.mUseNativeLineBreak)) {
|
2016-07-12 11:44:44 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
|
|
|
("0x%p HandleQueryContentEvent(), FAILED due to query with XP "
|
|
|
|
"linebreaks",
|
|
|
|
this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!aEvent.mInput.IsValidOffset())) {
|
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Error,
|
|
|
|
("0x%p HandleQueryContentEvent(), FAILED due to invalid offset", this));
|
2016-06-14 14:54:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-12 11:44:44 +03:00
|
|
|
if (NS_WARN_IF(!aEvent.mInput.IsValidEventMessage(aEvent.mMessage))) {
|
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Error,
|
|
|
|
("0x%p HandleQueryContentEvent(), FAILED due to invalid event message",
|
|
|
|
this));
|
2016-06-14 14:54:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-06-22 08:16:59 +03:00
|
|
|
bool isRelativeToInsertionPoint = aEvent.mInput.mRelativeToInsertionPoint;
|
|
|
|
if (isRelativeToInsertionPoint) {
|
2016-06-14 14:54:54 +03:00
|
|
|
if (aWidget->PluginHasFocus()) {
|
|
|
|
if (NS_WARN_IF(!aEvent.mInput.MakeOffsetAbsolute(0))) {
|
2016-07-12 11:44:44 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
|
|
|
("0x%p HandleQueryContentEvent(), FAILED due to "
|
|
|
|
"aEvent.mInput.MakeOffsetAbsolute(0) failure, aEvent={ "
|
|
|
|
"mMessage=%s, "
|
2016-12-16 06:16:31 +03:00
|
|
|
"mInput={ mOffset=%" PRId64 ", mLength=%" PRIu32 " } }",
|
2016-07-12 11:44:44 +03:00
|
|
|
this, ToChar(aEvent.mMessage), aEvent.mInput.mOffset,
|
|
|
|
aEvent.mInput.mLength));
|
2016-06-14 14:54:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
2018-01-12 09:05:24 +03:00
|
|
|
} else if (mWidgetHasComposition || mPendingCommitCount) {
|
2017-06-29 12:31:09 +03:00
|
|
|
if (NS_WARN_IF(!aEvent.mInput.MakeOffsetAbsolute(mCompositionStart +
|
|
|
|
mPendingCommitLength))) {
|
2016-07-12 11:44:44 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Error,
|
|
|
|
("0x%p HandleQueryContentEvent(), FAILED due to "
|
2017-06-29 12:31:09 +03:00
|
|
|
"aEvent.mInput.MakeOffsetAbsolute(mCompositionStart + "
|
|
|
|
"mPendingCommitLength) failure, "
|
|
|
|
"mCompositionStart=%" PRIu32 ", mPendingCommitLength=%" PRIu32 ", "
|
|
|
|
"aEvent={ mMessage=%s, mInput={ mOffset=%" PRId64
|
|
|
|
", mLength=%" PRIu32 " } }",
|
|
|
|
this, mCompositionStart, mPendingCommitLength,
|
|
|
|
ToChar(aEvent.mMessage), aEvent.mInput.mOffset,
|
|
|
|
aEvent.mInput.mLength));
|
2016-06-14 14:54:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-12 11:44:44 +03:00
|
|
|
} else if (NS_WARN_IF(!mSelection.IsValid())) {
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
|
|
|
("0x%p HandleQueryContentEvent(), FAILED due to mSelection is "
|
|
|
|
"invalid",
|
|
|
|
this));
|
|
|
|
return false;
|
|
|
|
} else if (NS_WARN_IF(!aEvent.mInput.MakeOffsetAbsolute(
|
2017-06-29 12:31:09 +03:00
|
|
|
mSelection.StartOffset() + mPendingCommitLength))) {
|
2016-07-12 11:44:44 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
|
|
|
("0x%p HandleQueryContentEvent(), FAILED due to "
|
2017-06-29 12:31:09 +03:00
|
|
|
"aEvent.mInput.MakeOffsetAbsolute(mSelection.StartOffset() + "
|
|
|
|
"mPendingCommitLength) failure, "
|
|
|
|
"mSelection={ StartOffset()=%d, Length()=%d }, "
|
|
|
|
"mPendingCommitLength=%" PRIu32 ", aEvent={ mMessage=%s, "
|
|
|
|
"mInput={ mOffset=%" PRId64 ", mLength=%" PRIu32 " } }",
|
2016-07-12 11:44:44 +03:00
|
|
|
this, mSelection.StartOffset(), mSelection.Length(),
|
2017-06-29 12:31:09 +03:00
|
|
|
mPendingCommitLength, ToChar(aEvent.mMessage),
|
|
|
|
aEvent.mInput.mOffset, aEvent.mInput.mLength));
|
2016-06-14 14:54:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-22 04:34:51 +03:00
|
|
|
switch (aEvent.mMessage) {
|
2015-09-10 04:40:05 +03:00
|
|
|
case eQuerySelectedText:
|
2015-06-26 02:21:13 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent("
|
2015-09-10 04:40:05 +03:00
|
|
|
"aEvent={ mMessage=eQuerySelectedText }, aWidget=0x%p)",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, aWidget));
|
2015-12-29 16:57:38 +03:00
|
|
|
if (aWidget->PluginHasFocus()) {
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-12-29 16:57:38 +03:00
|
|
|
"return emtpy selection becasue plugin has focus",
|
|
|
|
this));
|
|
|
|
aEvent.mSucceeded = true;
|
|
|
|
aEvent.mReply.mOffset = 0;
|
|
|
|
aEvent.mReply.mReversed = false;
|
|
|
|
aEvent.mReply.mHasSelection = false;
|
|
|
|
return true;
|
|
|
|
}
|
2015-06-26 02:21:13 +03:00
|
|
|
if (NS_WARN_IF(!IsSelectionValid())) {
|
|
|
|
// If content cache hasn't been initialized properly, make the query
|
|
|
|
// failed.
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"FAILED because mSelection is not valid",
|
|
|
|
this));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
aEvent.mReply.mOffset = mSelection.StartOffset();
|
|
|
|
if (mSelection.Collapsed()) {
|
|
|
|
aEvent.mReply.mString.Truncate(0);
|
|
|
|
} else {
|
|
|
|
if (NS_WARN_IF(mSelection.EndOffset() > mText.Length())) {
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"FAILED because mSelection.EndOffset()=%u is larger than "
|
|
|
|
"mText.Length()=%u",
|
|
|
|
this, mSelection.EndOffset(), mText.Length()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aEvent.mReply.mString =
|
|
|
|
Substring(mText, aEvent.mReply.mOffset, mSelection.Length());
|
|
|
|
}
|
|
|
|
aEvent.mReply.mReversed = mSelection.Reversed();
|
|
|
|
aEvent.mReply.mHasSelection = true;
|
|
|
|
aEvent.mReply.mWritingMode = mSelection.mWritingMode;
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"Succeeded, aEvent={ mReply={ mOffset=%u, mString=\"%s\", "
|
|
|
|
"mReversed=%s, mHasSelection=%s, mWritingMode=%s } }",
|
|
|
|
this, aEvent.mReply.mOffset,
|
2016-07-13 12:16:04 +03:00
|
|
|
GetEscapedUTF8String(aEvent.mReply.mString).get(),
|
2015-06-26 02:21:13 +03:00
|
|
|
GetBoolName(aEvent.mReply.mReversed),
|
|
|
|
GetBoolName(aEvent.mReply.mHasSelection),
|
|
|
|
GetWritingModeName(aEvent.mReply.mWritingMode).get()));
|
|
|
|
break;
|
2015-09-10 04:40:05 +03:00
|
|
|
case eQueryTextContent: {
|
2015-06-26 02:21:13 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent("
|
2016-12-16 06:16:31 +03:00
|
|
|
"aEvent={ mMessage=eQueryTextContent, mInput={ mOffset=%" PRId64
|
|
|
|
", mLength=%u } }, aWidget=0x%p), mText.Length()=%u",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, aEvent.mInput.mOffset, aEvent.mInput.mLength, aWidget,
|
|
|
|
mText.Length()));
|
|
|
|
uint32_t inputOffset = aEvent.mInput.mOffset;
|
|
|
|
uint32_t inputEndOffset =
|
|
|
|
std::min(aEvent.mInput.EndOffset(), mText.Length());
|
|
|
|
if (NS_WARN_IF(inputEndOffset < inputOffset)) {
|
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"FAILED because inputOffset=%u is larger than inputEndOffset=%u",
|
|
|
|
this, inputOffset, inputEndOffset));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aEvent.mReply.mOffset = inputOffset;
|
|
|
|
aEvent.mReply.mString =
|
|
|
|
Substring(mText, inputOffset, inputEndOffset - inputOffset);
|
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"Succeeded, aEvent={ mReply={ mOffset=%u, mString.Length()=%u } }",
|
|
|
|
this, aEvent.mReply.mOffset, aEvent.mReply.mString.Length()));
|
|
|
|
break;
|
|
|
|
}
|
2015-09-11 15:21:26 +03:00
|
|
|
case eQueryTextRect:
|
2015-06-26 02:21:13 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent("
|
2016-12-16 06:16:31 +03:00
|
|
|
"aEvent={ mMessage=eQueryTextRect, mInput={ mOffset=%" PRId64
|
|
|
|
", mLength=%u } }, aWidget=0x%p), mText.Length()=%u",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, aEvent.mInput.mOffset, aEvent.mInput.mLength, aWidget,
|
|
|
|
mText.Length()));
|
|
|
|
if (NS_WARN_IF(!IsSelectionValid())) {
|
|
|
|
// If content cache hasn't been initialized properly, make the query
|
|
|
|
// failed.
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"FAILED because mSelection is not valid",
|
|
|
|
this));
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-22 08:16:59 +03:00
|
|
|
// Note that if the query is relative to insertion point, the query was
|
|
|
|
// probably requested by native IME. In such case, we should return
|
|
|
|
// non-empty rect since returning failure causes IME showing its window
|
|
|
|
// at odd position.
|
2015-06-26 02:21:13 +03:00
|
|
|
if (aEvent.mInput.mLength) {
|
|
|
|
if (NS_WARN_IF(!GetUnionTextRects(
|
|
|
|
aEvent.mInput.mOffset, aEvent.mInput.mLength,
|
2016-06-22 08:16:59 +03:00
|
|
|
isRelativeToInsertionPoint, aEvent.mReply.mRect))) {
|
2015-06-26 02:21:13 +03:00
|
|
|
// XXX We don't have cache for this request.
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"FAILED to get union rect",
|
|
|
|
this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If the length is 0, we should return caret rect instead.
|
|
|
|
if (NS_WARN_IF(!GetCaretRect(aEvent.mInput.mOffset,
|
2016-06-22 08:16:59 +03:00
|
|
|
isRelativeToInsertionPoint,
|
2015-06-26 02:21:13 +03:00
|
|
|
aEvent.mReply.mRect))) {
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"FAILED to get caret rect",
|
|
|
|
this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aEvent.mInput.mOffset < mText.Length()) {
|
|
|
|
aEvent.mReply.mString = Substring(
|
|
|
|
mText, aEvent.mInput.mOffset,
|
|
|
|
mText.Length() >= aEvent.mInput.EndOffset() ? aEvent.mInput.mLength
|
|
|
|
: UINT32_MAX);
|
|
|
|
} else {
|
|
|
|
aEvent.mReply.mString.Truncate(0);
|
|
|
|
}
|
|
|
|
aEvent.mReply.mOffset = aEvent.mInput.mOffset;
|
|
|
|
// XXX This may be wrong if storing range isn't in the selection range.
|
|
|
|
aEvent.mReply.mWritingMode = mSelection.mWritingMode;
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"Succeeded, aEvent={ mReply={ mOffset=%u, mString=\"%s\", "
|
|
|
|
"mWritingMode=%s, mRect=%s } }",
|
|
|
|
this, aEvent.mReply.mOffset,
|
2016-07-13 12:16:04 +03:00
|
|
|
GetEscapedUTF8String(aEvent.mReply.mString).get(),
|
2015-06-26 02:21:13 +03:00
|
|
|
GetWritingModeName(aEvent.mReply.mWritingMode).get(),
|
|
|
|
GetRectText(aEvent.mReply.mRect).get()));
|
|
|
|
break;
|
2015-09-10 04:40:06 +03:00
|
|
|
case eQueryCaretRect:
|
2015-06-26 02:21:13 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent("
|
2016-12-16 06:16:31 +03:00
|
|
|
"aEvent={ mMessage=eQueryCaretRect, mInput={ mOffset=%" PRId64
|
|
|
|
" } }, "
|
2015-06-26 02:21:13 +03:00
|
|
|
"aWidget=0x%p), mText.Length()=%u",
|
|
|
|
this, aEvent.mInput.mOffset, aWidget, mText.Length()));
|
|
|
|
if (NS_WARN_IF(!IsSelectionValid())) {
|
|
|
|
// If content cache hasn't been initialized properly, make the query
|
|
|
|
// failed.
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"FAILED because mSelection is not valid",
|
|
|
|
this));
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-22 08:16:59 +03:00
|
|
|
// Note that if the query is relative to insertion point, the query was
|
|
|
|
// probably requested by native IME. In such case, we should return
|
|
|
|
// non-empty rect since returning failure causes IME showing its window
|
|
|
|
// at odd position.
|
2015-06-26 02:21:13 +03:00
|
|
|
if (NS_WARN_IF(!GetCaretRect(aEvent.mInput.mOffset,
|
2016-06-22 08:16:59 +03:00
|
|
|
isRelativeToInsertionPoint,
|
2015-06-26 02:21:13 +03:00
|
|
|
aEvent.mReply.mRect))) {
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Error,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"FAILED to get caret rect",
|
|
|
|
this));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aEvent.mReply.mOffset = aEvent.mInput.mOffset;
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"Succeeded, aEvent={ mReply={ mOffset=%u, mRect=%s } }",
|
|
|
|
this, aEvent.mReply.mOffset,
|
|
|
|
GetRectText(aEvent.mReply.mRect).get()));
|
|
|
|
break;
|
2015-09-10 04:40:06 +03:00
|
|
|
case eQueryEditorRect:
|
2015-06-26 02:21:13 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent("
|
2015-09-10 04:40:06 +03:00
|
|
|
"aEvent={ mMessage=eQueryEditorRect }, aWidget=0x%p)",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, aWidget));
|
|
|
|
aEvent.mReply.mRect = mEditorRect;
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p HandleQueryContentEvent(), "
|
2015-06-26 02:21:13 +03:00
|
|
|
"Succeeded, aEvent={ mReply={ mRect=%s } }",
|
|
|
|
this, GetRectText(aEvent.mReply.mRect).get()));
|
|
|
|
break;
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
2015-06-26 02:21:13 +03:00
|
|
|
}
|
|
|
|
aEvent.mSucceeded = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ContentCacheInParent::GetTextRect(uint32_t aOffset,
|
2016-06-22 08:16:59 +03:00
|
|
|
bool aRoundToExistingOffset,
|
2015-06-26 02:21:13 +03:00
|
|
|
LayoutDeviceIntRect& aTextRect) const {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p GetTextRect(aOffset=%u, "
|
2016-06-22 08:16:59 +03:00
|
|
|
"aRoundToExistingOffset=%s), "
|
2017-07-26 23:03:57 +03:00
|
|
|
"mTextRectArray={ mStart=%u, mRects.Length()=%zu }, "
|
2015-06-05 12:28:20 +03:00
|
|
|
"mSelection={ mAnchor=%u, mFocus=%u }",
|
2016-06-22 08:16:59 +03:00
|
|
|
this, aOffset, GetBoolName(aRoundToExistingOffset),
|
|
|
|
mTextRectArray.mStart, mTextRectArray.mRects.Length(),
|
2015-06-26 02:21:13 +03:00
|
|
|
mSelection.mAnchor, mSelection.mFocus));
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-17 04:03:58 +03:00
|
|
|
if (!aOffset) {
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(!mFirstCharRect.IsEmpty(), "empty rect");
|
2015-06-17 04:03:58 +03:00
|
|
|
aTextRect = mFirstCharRect;
|
|
|
|
return !aTextRect.IsEmpty();
|
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
if (aOffset == mSelection.mAnchor) {
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(!mSelection.mAnchorCharRects[eNextCharRect].IsEmpty(),
|
|
|
|
"empty rect");
|
2016-07-22 14:47:51 +03:00
|
|
|
aTextRect = mSelection.mAnchorCharRects[eNextCharRect];
|
|
|
|
return !aTextRect.IsEmpty();
|
|
|
|
}
|
|
|
|
if (mSelection.mAnchor && aOffset == mSelection.mAnchor - 1) {
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(!mSelection.mAnchorCharRects[ePrevCharRect].IsEmpty(),
|
|
|
|
"empty rect");
|
2016-07-22 14:47:51 +03:00
|
|
|
aTextRect = mSelection.mAnchorCharRects[ePrevCharRect];
|
2015-06-05 12:28:20 +03:00
|
|
|
return !aTextRect.IsEmpty();
|
|
|
|
}
|
|
|
|
if (aOffset == mSelection.mFocus) {
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(!mSelection.mFocusCharRects[eNextCharRect].IsEmpty(),
|
|
|
|
"empty rect");
|
2016-07-22 14:47:51 +03:00
|
|
|
aTextRect = mSelection.mFocusCharRects[eNextCharRect];
|
|
|
|
return !aTextRect.IsEmpty();
|
|
|
|
}
|
|
|
|
if (mSelection.mFocus && aOffset == mSelection.mFocus - 1) {
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(!mSelection.mFocusCharRects[ePrevCharRect].IsEmpty(),
|
|
|
|
"empty rect");
|
2016-07-22 14:47:51 +03:00
|
|
|
aTextRect = mSelection.mFocusCharRects[ePrevCharRect];
|
2015-06-05 12:28:20 +03:00
|
|
|
return !aTextRect.IsEmpty();
|
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2016-06-22 08:16:59 +03:00
|
|
|
uint32_t offset = aOffset;
|
2015-06-05 12:28:21 +03:00
|
|
|
if (!mTextRectArray.InRange(aOffset)) {
|
2016-06-22 08:16:59 +03:00
|
|
|
if (!aRoundToExistingOffset) {
|
|
|
|
aTextRect.SetEmpty();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!mTextRectArray.IsValid()) {
|
|
|
|
// If there are no rects in mTextRectArray, we should refer the start of
|
|
|
|
// the selection because IME must query a char rect around it if there is
|
|
|
|
// no composition.
|
|
|
|
aTextRect = mSelection.StartCharRect();
|
|
|
|
return !aTextRect.IsEmpty();
|
|
|
|
}
|
|
|
|
if (offset < mTextRectArray.StartOffset()) {
|
|
|
|
offset = mTextRectArray.StartOffset();
|
|
|
|
} else {
|
|
|
|
offset = mTextRectArray.EndOffset() - 1;
|
|
|
|
}
|
2015-06-05 12:28:19 +03:00
|
|
|
}
|
2016-06-22 08:16:59 +03:00
|
|
|
aTextRect = mTextRectArray.GetRect(offset);
|
|
|
|
return !aTextRect.IsEmpty();
|
2015-06-05 12:28:19 +03:00
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
bool ContentCacheInParent::GetUnionTextRects(
|
2016-06-22 08:16:59 +03:00
|
|
|
uint32_t aOffset, uint32_t aLength, bool aRoundToExistingOffset,
|
2015-06-26 02:21:13 +03:00
|
|
|
LayoutDeviceIntRect& aUnionTextRect) const {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p GetUnionTextRects(aOffset=%u, "
|
2016-06-22 08:16:59 +03:00
|
|
|
"aLength=%u, aRoundToExistingOffset=%s), mTextRectArray={ "
|
2017-07-26 23:03:57 +03:00
|
|
|
"mStart=%u, mRects.Length()=%zu }, "
|
2015-06-05 12:28:20 +03:00
|
|
|
"mSelection={ mAnchor=%u, mFocus=%u }",
|
2016-06-22 08:16:59 +03:00
|
|
|
this, aOffset, aLength, GetBoolName(aRoundToExistingOffset),
|
|
|
|
mTextRectArray.mStart, mTextRectArray.mRects.Length(),
|
|
|
|
mSelection.mAnchor, mSelection.mFocus));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-06-17 04:03:58 +03:00
|
|
|
CheckedInt<uint32_t> endOffset = CheckedInt<uint32_t>(aOffset) + aLength;
|
|
|
|
if (!endOffset.isValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-08 05:46:17 +03:00
|
|
|
if (!mSelection.Collapsed() && aOffset == mSelection.StartOffset() &&
|
|
|
|
aLength == mSelection.Length()) {
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(!mSelection.mRect.IsEmpty(), "empty rect");
|
2015-06-08 05:46:17 +03:00
|
|
|
aUnionTextRect = mSelection.mRect;
|
|
|
|
return !aUnionTextRect.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
if (aLength == 1) {
|
2015-06-17 04:03:58 +03:00
|
|
|
if (!aOffset) {
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(!mFirstCharRect.IsEmpty(), "empty rect");
|
2015-06-17 04:03:58 +03:00
|
|
|
aUnionTextRect = mFirstCharRect;
|
|
|
|
return !aUnionTextRect.IsEmpty();
|
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
if (aOffset == mSelection.mAnchor) {
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
!mSelection.mAnchorCharRects[eNextCharRect].IsEmpty(), "empty rect");
|
2016-07-22 14:47:51 +03:00
|
|
|
aUnionTextRect = mSelection.mAnchorCharRects[eNextCharRect];
|
|
|
|
return !aUnionTextRect.IsEmpty();
|
|
|
|
}
|
|
|
|
if (mSelection.mAnchor && aOffset == mSelection.mAnchor - 1) {
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(
|
|
|
|
!mSelection.mAnchorCharRects[ePrevCharRect].IsEmpty(), "empty rect");
|
2016-07-22 14:47:51 +03:00
|
|
|
aUnionTextRect = mSelection.mAnchorCharRects[ePrevCharRect];
|
2015-06-05 12:28:20 +03:00
|
|
|
return !aUnionTextRect.IsEmpty();
|
|
|
|
}
|
|
|
|
if (aOffset == mSelection.mFocus) {
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(!mSelection.mFocusCharRects[eNextCharRect].IsEmpty(),
|
|
|
|
"empty rect");
|
2016-07-22 14:47:51 +03:00
|
|
|
aUnionTextRect = mSelection.mFocusCharRects[eNextCharRect];
|
|
|
|
return !aUnionTextRect.IsEmpty();
|
|
|
|
}
|
|
|
|
if (mSelection.mFocus && aOffset == mSelection.mFocus - 1) {
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(!mSelection.mFocusCharRects[ePrevCharRect].IsEmpty(),
|
|
|
|
"empty rect");
|
2016-07-22 14:47:51 +03:00
|
|
|
aUnionTextRect = mSelection.mFocusCharRects[ePrevCharRect];
|
2015-06-05 12:28:20 +03:00
|
|
|
return !aUnionTextRect.IsEmpty();
|
|
|
|
}
|
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-17 04:03:58 +03:00
|
|
|
// Even if some text rects are not cached of the queried range,
|
|
|
|
// we should return union rect when the first character's rect is cached
|
|
|
|
// since the first character rect is important and the others are not so
|
|
|
|
// in most cases.
|
|
|
|
|
|
|
|
if (!aOffset && aOffset != mSelection.mAnchor &&
|
|
|
|
aOffset != mSelection.mFocus && !mTextRectArray.InRange(aOffset)) {
|
|
|
|
// The first character rect isn't cached.
|
2015-06-05 12:28:19 +03:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-17 04:03:58 +03:00
|
|
|
|
2016-08-02 06:02:14 +03:00
|
|
|
if ((aRoundToExistingOffset && mTextRectArray.HasRects()) ||
|
2016-06-22 08:16:59 +03:00
|
|
|
mTextRectArray.IsOverlappingWith(aOffset, aLength)) {
|
|
|
|
aUnionTextRect = mTextRectArray.GetUnionRectAsFarAsPossible(
|
|
|
|
aOffset, aLength, aRoundToExistingOffset);
|
2015-06-17 04:03:58 +03:00
|
|
|
} else {
|
|
|
|
aUnionTextRect.SetEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aOffset) {
|
|
|
|
aUnionTextRect = aUnionTextRect.Union(mFirstCharRect);
|
|
|
|
}
|
|
|
|
if (aOffset <= mSelection.mAnchor && mSelection.mAnchor < endOffset.value()) {
|
2016-07-22 14:47:51 +03:00
|
|
|
aUnionTextRect =
|
|
|
|
aUnionTextRect.Union(mSelection.mAnchorCharRects[eNextCharRect]);
|
|
|
|
}
|
|
|
|
if (mSelection.mAnchor && aOffset <= mSelection.mAnchor - 1 &&
|
|
|
|
mSelection.mAnchor - 1 < endOffset.value()) {
|
|
|
|
aUnionTextRect =
|
|
|
|
aUnionTextRect.Union(mSelection.mAnchorCharRects[ePrevCharRect]);
|
2015-06-17 04:03:58 +03:00
|
|
|
}
|
|
|
|
if (aOffset <= mSelection.mFocus && mSelection.mFocus < endOffset.value()) {
|
2016-07-22 14:47:51 +03:00
|
|
|
aUnionTextRect =
|
|
|
|
aUnionTextRect.Union(mSelection.mFocusCharRects[eNextCharRect]);
|
|
|
|
}
|
|
|
|
if (mSelection.mFocus && aOffset <= mSelection.mFocus - 1 &&
|
|
|
|
mSelection.mFocus - 1 < endOffset.value()) {
|
|
|
|
aUnionTextRect =
|
|
|
|
aUnionTextRect.Union(mSelection.mFocusCharRects[ePrevCharRect]);
|
2015-06-17 04:03:58 +03:00
|
|
|
}
|
2016-07-22 14:47:51 +03:00
|
|
|
|
2015-06-17 04:03:58 +03:00
|
|
|
return !aUnionTextRect.IsEmpty();
|
2015-06-05 12:28:19 +03:00
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
bool ContentCacheInParent::GetCaretRect(uint32_t aOffset,
|
2016-06-22 08:16:59 +03:00
|
|
|
bool aRoundToExistingOffset,
|
2015-06-26 02:21:13 +03:00
|
|
|
LayoutDeviceIntRect& aCaretRect) const {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p GetCaretRect(aOffset=%u, "
|
2016-06-22 08:16:59 +03:00
|
|
|
"aRoundToExistingOffset=%s), "
|
2015-06-05 12:28:20 +03:00
|
|
|
"mCaret={ mOffset=%u, mRect=%s, IsValid()=%s }, mTextRectArray={ "
|
2017-07-26 23:03:57 +03:00
|
|
|
"mStart=%u, mRects.Length()=%zu }, mSelection={ mAnchor=%u, mFocus=%u, "
|
2016-07-22 14:47:51 +03:00
|
|
|
"mWritingMode=%s, mAnchorCharRects[eNextCharRect]=%s, "
|
|
|
|
"mAnchorCharRects[ePrevCharRect]=%s, mFocusCharRects[eNextCharRect]=%s, "
|
|
|
|
"mFocusCharRects[ePrevCharRect]=%s }, mFirstCharRect=%s",
|
2016-06-22 08:16:59 +03:00
|
|
|
this, aOffset, GetBoolName(aRoundToExistingOffset), mCaret.mOffset,
|
|
|
|
GetRectText(mCaret.mRect).get(), GetBoolName(mCaret.IsValid()),
|
2015-06-26 02:21:13 +03:00
|
|
|
mTextRectArray.mStart, mTextRectArray.mRects.Length(),
|
|
|
|
mSelection.mAnchor, mSelection.mFocus,
|
2015-06-05 12:28:20 +03:00
|
|
|
GetWritingModeName(mSelection.mWritingMode).get(),
|
2016-07-22 14:47:51 +03:00
|
|
|
GetRectText(mSelection.mAnchorCharRects[eNextCharRect]).get(),
|
|
|
|
GetRectText(mSelection.mAnchorCharRects[ePrevCharRect]).get(),
|
|
|
|
GetRectText(mSelection.mFocusCharRects[eNextCharRect]).get(),
|
|
|
|
GetRectText(mSelection.mFocusCharRects[ePrevCharRect]).get(),
|
2015-06-17 04:03:58 +03:00
|
|
|
GetRectText(mFirstCharRect).get()));
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
if (mCaret.IsValid() && mCaret.mOffset == aOffset) {
|
|
|
|
aCaretRect = mCaret.mRect;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Guess caret rect from the text rect if it's stored.
|
2016-06-22 08:16:59 +03:00
|
|
|
if (!GetTextRect(aOffset, aRoundToExistingOffset, aCaretRect)) {
|
2015-06-05 12:28:21 +03:00
|
|
|
// There might be previous character rect in the cache. If so, we can
|
|
|
|
// guess the caret rect with it.
|
2016-06-22 08:16:59 +03:00
|
|
|
if (!aOffset ||
|
|
|
|
!GetTextRect(aOffset - 1, aRoundToExistingOffset, aCaretRect)) {
|
2015-06-05 12:28:21 +03:00
|
|
|
aCaretRect.SetEmpty();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSelection.mWritingMode.IsVertical()) {
|
2018-01-10 19:14:16 +03:00
|
|
|
aCaretRect.MoveToY(aCaretRect.YMost());
|
2015-06-05 12:28:21 +03:00
|
|
|
} else {
|
|
|
|
// XXX bidi-unaware.
|
2018-01-10 19:14:16 +03:00
|
|
|
aCaretRect.MoveToX(aCaretRect.XMost());
|
2015-06-05 12:28:21 +03:00
|
|
|
}
|
2015-06-05 12:28:19 +03:00
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
|
|
|
|
// XXX This is not bidi aware because we don't cache each character's
|
|
|
|
// direction. However, this is usually used by IME, so, assuming the
|
|
|
|
// character is in LRT context must not cause any problem.
|
|
|
|
if (mSelection.mWritingMode.IsVertical()) {
|
2018-01-10 19:14:16 +03:00
|
|
|
aCaretRect.SetHeight(mCaret.IsValid() ? mCaret.mRect.Height() : 1);
|
2015-06-05 12:28:20 +03:00
|
|
|
} else {
|
2018-01-10 19:14:16 +03:00
|
|
|
aCaretRect.SetWidth(mCaret.IsValid() ? mCaret.mRect.Width() : 1);
|
2015-06-05 12:28:20 +03:00
|
|
|
}
|
2015-06-05 12:28:19 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
bool ContentCacheInParent::OnCompositionEvent(
|
|
|
|
const WidgetCompositionEvent& aEvent) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p OnCompositionEvent(aEvent={ "
|
2017-07-26 23:03:57 +03:00
|
|
|
"mMessage=%s, mData=\"%s\" (Length()=%u), mRanges->Length()=%zu }), "
|
2016-10-12 10:42:28 +03:00
|
|
|
"mPendingEventsNeedingAck=%u, mWidgetHasComposition=%s, "
|
2017-12-06 09:07:41 +03:00
|
|
|
"mPendingCompositionCount=%" PRIu8 ", mPendingCommitCount=%" PRIu8 ", "
|
|
|
|
"mIsChildIgnoringCompositionEvents=%s, mCommitStringByRequest=0x%p",
|
2016-07-13 12:16:04 +03:00
|
|
|
this, ToChar(aEvent.mMessage), GetEscapedUTF8String(aEvent.mData).get(),
|
2015-07-11 04:53:55 +03:00
|
|
|
aEvent.mData.Length(), aEvent.mRanges ? aEvent.mRanges->Length() : 0,
|
2016-10-12 11:09:02 +03:00
|
|
|
mPendingEventsNeedingAck, GetBoolName(mWidgetHasComposition),
|
|
|
|
mPendingCompositionCount, mPendingCommitCount,
|
2017-12-06 09:07:41 +03:00
|
|
|
GetBoolName(mIsChildIgnoringCompositionEvents), mCommitStringByRequest));
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
mDispatchedEventMessages.AppendElement(aEvent.mMessage);
|
2017-11-20 17:30:18 +03:00
|
|
|
#endif // #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
|
2015-12-11 09:15:58 +03:00
|
|
|
// We must be able to simulate the selection because
|
|
|
|
// we might not receive selection updates in time
|
2016-10-12 10:42:28 +03:00
|
|
|
if (!mWidgetHasComposition) {
|
2016-04-14 11:03:14 +03:00
|
|
|
if (aEvent.mWidget && aEvent.mWidget->PluginHasFocus()) {
|
2015-12-29 16:57:38 +03:00
|
|
|
// If focus is on plugin, we cannot get selection range
|
|
|
|
mCompositionStart = 0;
|
2016-10-12 15:52:01 +03:00
|
|
|
} else if (mCompositionStartInChild != UINT32_MAX) {
|
|
|
|
// If there is pending composition in the remote process, let's use
|
|
|
|
// its start offset temporarily because this stores a lot of information
|
|
|
|
// around it and the user must look around there, so, showing some UI
|
|
|
|
// around it must make sense.
|
|
|
|
mCompositionStart = mCompositionStartInChild;
|
2015-12-29 16:57:38 +03:00
|
|
|
} else {
|
|
|
|
mCompositionStart = mSelection.StartOffset();
|
|
|
|
}
|
2016-10-12 11:09:02 +03:00
|
|
|
MOZ_ASSERT(aEvent.mMessage == eCompositionStart);
|
|
|
|
MOZ_RELEASE_ASSERT(mPendingCompositionCount < UINT8_MAX);
|
|
|
|
mPendingCompositionCount++;
|
2015-06-05 12:28:19 +03:00
|
|
|
}
|
|
|
|
|
2016-10-12 10:42:28 +03:00
|
|
|
mWidgetHasComposition = !aEvent.CausesDOMCompositionEndEvent();
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2016-10-12 10:42:28 +03:00
|
|
|
if (!mWidgetHasComposition) {
|
2018-01-12 09:05:24 +03:00
|
|
|
// mCompositionStart will be reset when commit event is completely handled
|
|
|
|
// in the remote process.
|
2017-06-29 12:31:09 +03:00
|
|
|
if (mPendingCompositionCount == 1) {
|
|
|
|
mPendingCommitLength = aEvent.mData.Length();
|
|
|
|
}
|
2017-12-06 09:07:41 +03:00
|
|
|
mPendingCommitCount++;
|
2017-07-05 13:55:18 +03:00
|
|
|
} else if (aEvent.mMessage != eCompositionStart) {
|
|
|
|
mCompositionString = aEvent.mData;
|
2016-06-13 12:17:58 +03:00
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:19 +03:00
|
|
|
// During REQUEST_TO_COMMIT_COMPOSITION or REQUEST_TO_CANCEL_COMPOSITION,
|
2015-12-11 09:15:58 +03:00
|
|
|
// widget usually sends a eCompositionChange and/or eCompositionCommit event
|
|
|
|
// to finalize or clear the composition, respectively. In this time,
|
|
|
|
// we need to intercept all composition events here and pass the commit
|
|
|
|
// string for returning to the remote process as a result of
|
|
|
|
// RequestIMEToCommitComposition(). Then, eCommitComposition event will
|
|
|
|
// be dispatched with the committed string in the remote process internally.
|
|
|
|
if (mCommitStringByRequest) {
|
2019-12-02 18:27:29 +03:00
|
|
|
if (aEvent.mMessage == eCompositionCommitAsIs) {
|
|
|
|
*mCommitStringByRequest = mCompositionString;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(aEvent.mMessage == eCompositionChange ||
|
|
|
|
aEvent.mMessage == eCompositionCommit);
|
|
|
|
*mCommitStringByRequest = aEvent.mData;
|
|
|
|
}
|
2017-06-27 17:41:12 +03:00
|
|
|
// We need to wait eCompositionCommitRequestHandled from the remote process
|
|
|
|
// in this case. Therefore, mPendingEventsNeedingAck needs to be
|
2017-12-06 09:07:41 +03:00
|
|
|
// incremented here. Additionally, we stop sending eCompositionCommit(AsIs)
|
|
|
|
// event. Therefore, we need to decrement mPendingCommitCount which has
|
|
|
|
// been incremented above.
|
2017-06-27 17:41:12 +03:00
|
|
|
if (!mWidgetHasComposition) {
|
|
|
|
mPendingEventsNeedingAck++;
|
2017-12-06 09:07:41 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mPendingCommitCount);
|
|
|
|
if (mPendingCommitCount) {
|
|
|
|
mPendingCommitCount--;
|
|
|
|
}
|
2017-06-27 17:41:12 +03:00
|
|
|
}
|
2015-06-05 12:28:19 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-11 04:53:55 +03:00
|
|
|
mPendingEventsNeedingAck++;
|
2015-06-05 12:28:19 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-11 04:53:55 +03:00
|
|
|
void ContentCacheInParent::OnSelectionEvent(
|
|
|
|
const WidgetSelectionEvent& aSelectionEvent) {
|
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p OnSelectionEvent(aEvent={ "
|
2015-08-22 04:34:51 +03:00
|
|
|
"mMessage=%s, mOffset=%u, mLength=%u, mReversed=%s, "
|
2015-07-11 04:53:55 +03:00
|
|
|
"mExpandToClusterBoundary=%s, mUseNativeLineBreak=%s }), "
|
2016-10-12 11:09:02 +03:00
|
|
|
"mPendingEventsNeedingAck=%u, mWidgetHasComposition=%s, "
|
2017-12-06 09:07:41 +03:00
|
|
|
"mPendingCompositionCount=%" PRIu8 ", mPendingCommitCount=%" PRIu8 ", "
|
|
|
|
"mIsChildIgnoringCompositionEvents=%s",
|
2015-09-17 06:05:44 +03:00
|
|
|
this, ToChar(aSelectionEvent.mMessage), aSelectionEvent.mOffset,
|
2015-07-11 04:53:55 +03:00
|
|
|
aSelectionEvent.mLength, GetBoolName(aSelectionEvent.mReversed),
|
|
|
|
GetBoolName(aSelectionEvent.mExpandToClusterBoundary),
|
|
|
|
GetBoolName(aSelectionEvent.mUseNativeLineBreak),
|
2017-12-06 09:07:41 +03:00
|
|
|
mPendingEventsNeedingAck, GetBoolName(mWidgetHasComposition),
|
|
|
|
mPendingCompositionCount, mPendingCommitCount,
|
|
|
|
GetBoolName(mIsChildIgnoringCompositionEvents)));
|
2015-07-11 04:53:55 +03:00
|
|
|
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
mDispatchedEventMessages.AppendElement(aSelectionEvent.mMessage);
|
2017-11-23 12:59:04 +03:00
|
|
|
#endif // MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
|
2015-07-11 04:53:55 +03:00
|
|
|
mPendingEventsNeedingAck++;
|
|
|
|
}
|
|
|
|
|
2015-07-22 08:51:36 +03:00
|
|
|
void ContentCacheInParent::OnEventNeedingAckHandled(nsIWidget* aWidget,
|
2015-08-26 15:56:59 +03:00
|
|
|
EventMessage aMessage) {
|
2015-07-11 04:53:55 +03:00
|
|
|
// This is called when the child process receives WidgetCompositionEvent or
|
|
|
|
// WidgetSelectionEvent.
|
|
|
|
|
2015-07-11 04:53:55 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p OnEventNeedingAckHandled(aWidget=0x%p, "
|
2017-12-06 09:07:41 +03:00
|
|
|
"aMessage=%s), mPendingEventsNeedingAck=%u, "
|
2018-01-12 09:05:24 +03:00
|
|
|
"mWidgetHasComposition=%s, mPendingCompositionCount=%" PRIu8 ", "
|
|
|
|
"mPendingCommitCount=%" PRIu8 ", mIsChildIgnoringCompositionEvents=%s",
|
2017-12-06 09:07:41 +03:00
|
|
|
this, aWidget, ToChar(aMessage), mPendingEventsNeedingAck,
|
2018-01-12 09:05:24 +03:00
|
|
|
GetBoolName(mWidgetHasComposition), mPendingCompositionCount,
|
|
|
|
mPendingCommitCount, GetBoolName(mIsChildIgnoringCompositionEvents)));
|
2017-06-27 16:02:07 +03:00
|
|
|
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
mReceivedEventMessages.AppendElement(aMessage);
|
2017-12-06 09:07:41 +03:00
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
|
2017-12-06 09:07:41 +03:00
|
|
|
bool isCommittedInChild =
|
|
|
|
// Commit requester in the remote process has committed the composition.
|
|
|
|
aMessage == eCompositionCommitRequestHandled ||
|
|
|
|
// The commit event has been handled normally in the remote process.
|
|
|
|
(!mIsChildIgnoringCompositionEvents &&
|
|
|
|
WidgetCompositionEvent::IsFollowedByCompositionEnd(aMessage));
|
2017-10-12 20:50:47 +03:00
|
|
|
|
2017-12-06 09:07:41 +03:00
|
|
|
if (isCommittedInChild) {
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
if (mPendingCompositionCount == 1) {
|
|
|
|
RemoveUnnecessaryEventMessageLog();
|
|
|
|
}
|
2017-11-23 12:59:04 +03:00
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
|
|
|
|
if (NS_WARN_IF(!mPendingCompositionCount)) {
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-18 18:13:42 +03:00
|
|
|
nsPrintfCString info(
|
|
|
|
"\nThere is no pending composition but received %s "
|
2017-10-12 20:50:47 +03:00
|
|
|
"message from the remote child\n\n",
|
|
|
|
ToChar(aMessage));
|
|
|
|
AppendEventMessageLog(info);
|
|
|
|
CrashReporter::AppendAppNotesToCrashReport(info);
|
2017-11-20 17:30:18 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
false, "No pending composition but received unexpected commit event");
|
2017-12-06 09:07:41 +03:00
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
|
|
|
|
|
|
|
// Prevent odd behavior in release channel.
|
2017-11-20 17:30:18 +03:00
|
|
|
mPendingCompositionCount = 1;
|
2017-10-12 20:50:47 +03:00
|
|
|
}
|
|
|
|
|
2017-06-27 16:02:07 +03:00
|
|
|
mPendingCompositionCount--;
|
2017-12-06 09:07:41 +03:00
|
|
|
|
2017-07-05 13:55:18 +03:00
|
|
|
// Forget composition string only when the latest composition string is
|
|
|
|
// handled in the remote process because if there is 2 or more pending
|
|
|
|
// composition, this value shouldn't be referred.
|
|
|
|
if (!mPendingCompositionCount) {
|
|
|
|
mCompositionString.Truncate();
|
|
|
|
}
|
2017-12-06 09:07:41 +03:00
|
|
|
|
2017-06-29 12:31:09 +03:00
|
|
|
// Forget pending commit string length if it's handled in the remote
|
|
|
|
// process. Note that this doesn't care too old composition's commit
|
|
|
|
// string because in such case, we cannot return proper information
|
|
|
|
// to IME synchornously.
|
|
|
|
mPendingCommitLength = 0;
|
2017-06-27 16:02:07 +03:00
|
|
|
}
|
2016-10-12 11:09:02 +03:00
|
|
|
|
2017-12-06 09:07:41 +03:00
|
|
|
if (WidgetCompositionEvent::IsFollowedByCompositionEnd(aMessage)) {
|
|
|
|
// After the remote process receives eCompositionCommit(AsIs) event,
|
|
|
|
// it'll restart to handle composition events.
|
|
|
|
mIsChildIgnoringCompositionEvents = false;
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!mPendingCommitCount)) {
|
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
|
|
|
nsPrintfCString info(
|
|
|
|
"\nThere is no pending comment events but received "
|
|
|
|
"%s message from the remote child\n\n",
|
|
|
|
ToChar(aMessage));
|
|
|
|
AppendEventMessageLog(info);
|
|
|
|
CrashReporter::AppendAppNotesToCrashReport(info);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
false,
|
|
|
|
"No pending commit events but received unexpected commit event");
|
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
|
|
|
|
|
|
|
// Prevent odd behavior in release channel.
|
|
|
|
mPendingCommitCount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPendingCommitCount--;
|
|
|
|
} else if (aMessage == eCompositionCommitRequestHandled &&
|
|
|
|
mPendingCommitCount) {
|
|
|
|
// If the remote process commits composition synchronously after
|
|
|
|
// requesting commit composition and we've already sent commit composition,
|
|
|
|
// it starts to ignore following composition events until receiving
|
|
|
|
// eCompositionStart event.
|
|
|
|
mIsChildIgnoringCompositionEvents = true;
|
|
|
|
}
|
|
|
|
|
2018-01-12 09:05:24 +03:00
|
|
|
// If neither widget (i.e., IME) nor the remote process has composition,
|
|
|
|
// now, we can forget composition string informations.
|
|
|
|
if (!mWidgetHasComposition && !mPendingCompositionCount &&
|
|
|
|
!mPendingCommitCount) {
|
|
|
|
mCompositionStart = UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
2017-10-12 20:50:47 +03:00
|
|
|
if (NS_WARN_IF(!mPendingEventsNeedingAck)) {
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-18 18:13:42 +03:00
|
|
|
nsPrintfCString info(
|
|
|
|
"\nThere is no pending events but received %s "
|
2017-10-12 20:50:47 +03:00
|
|
|
"message from the remote child\n\n",
|
|
|
|
ToChar(aMessage));
|
|
|
|
AppendEventMessageLog(info);
|
|
|
|
CrashReporter::AppendAppNotesToCrashReport(info);
|
2017-11-23 12:59:04 +03:00
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-11-20 17:30:18 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
false, "No pending event message but received unexpected event");
|
|
|
|
mPendingEventsNeedingAck = 1;
|
2017-10-12 20:50:47 +03:00
|
|
|
}
|
2015-07-11 04:53:55 +03:00
|
|
|
if (--mPendingEventsNeedingAck) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
FlushPendingNotifications(aWidget);
|
2015-07-11 04:53:55 +03:00
|
|
|
}
|
|
|
|
|
2015-12-11 09:15:58 +03:00
|
|
|
bool ContentCacheInParent::RequestIMEToCommitComposition(
|
|
|
|
nsIWidget* aWidget, bool aCancel, nsAString& aCommittedString) {
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("0x%p RequestToCommitComposition(aWidget=%p, "
|
2017-12-06 09:07:41 +03:00
|
|
|
"aCancel=%s), mPendingCompositionCount=%" PRIu8 ", "
|
|
|
|
"mPendingCommitCount=%" PRIu8 ", mIsChildIgnoringCompositionEvents=%s, "
|
2019-04-10 00:38:15 +03:00
|
|
|
"IMEStateManager::DoesBrowserParentHaveIMEFocus(&mBrowserParent)=%s, "
|
2017-07-05 13:55:18 +03:00
|
|
|
"mWidgetHasComposition=%s, mCommitStringByRequest=%p",
|
|
|
|
this, aWidget, GetBoolName(aCancel), mPendingCompositionCount,
|
2017-12-06 09:07:41 +03:00
|
|
|
mPendingCommitCount, GetBoolName(mIsChildIgnoringCompositionEvents),
|
2019-04-10 00:38:15 +03:00
|
|
|
GetBoolName(
|
|
|
|
IMEStateManager::DoesBrowserParentHaveIMEFocus(&mBrowserParent)),
|
2017-07-05 13:55:18 +03:00
|
|
|
GetBoolName(mWidgetHasComposition), mCommitStringByRequest));
|
2015-12-11 09:15:58 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(!mCommitStringByRequest);
|
|
|
|
|
2017-07-05 13:55:18 +03:00
|
|
|
// If there are 2 or more pending compositions, we already sent
|
|
|
|
// eCompositionCommit(AsIs) to the remote process. So, this request is
|
|
|
|
// too late for IME. The remote process should wait following
|
|
|
|
// composition events for cleaning up TextComposition and handle the
|
|
|
|
// request as it's handled asynchronously.
|
|
|
|
if (mPendingCompositionCount > 1) {
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-18 18:13:42 +03:00
|
|
|
mRequestIMEToCommitCompositionResults.AppendElement(
|
|
|
|
RequestIMEToCommitCompositionResult::eToOldCompositionReceived);
|
2017-11-23 12:59:04 +03:00
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-07-05 13:55:18 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-21 15:22:23 +03:00
|
|
|
// If there is no pending composition, we may have already sent
|
|
|
|
// eCompositionCommit(AsIs) event for the active composition. If so, the
|
|
|
|
// remote process will receive composition events which causes cleaning up
|
|
|
|
// TextComposition. So, this shouldn't do nothing and TextComposition
|
|
|
|
// should handle the request as it's handled asynchronously.
|
2017-12-06 09:07:41 +03:00
|
|
|
// XXX Perhaps, this is wrong because TextComposition in child process
|
|
|
|
// may commit the composition with current composition string in the
|
|
|
|
// remote process. I.e., it may be different from actual commit string
|
|
|
|
// which user typed. So, perhaps, we should return true and the commit
|
|
|
|
// string.
|
|
|
|
if (mPendingCommitCount) {
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-18 18:13:42 +03:00
|
|
|
mRequestIMEToCommitCompositionResults.AppendElement(
|
|
|
|
RequestIMEToCommitCompositionResult::eToCommittedCompositionReceived);
|
2017-11-23 12:59:04 +03:00
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-07-21 15:22:23 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-04-10 00:38:15 +03:00
|
|
|
// If BrowserParent which has IME focus was already changed to different one,
|
|
|
|
// the request shouldn't be sent to IME because it's too late.
|
|
|
|
if (!IMEStateManager::DoesBrowserParentHaveIMEFocus(&mBrowserParent)) {
|
2017-07-05 13:55:18 +03:00
|
|
|
// Use the latest composition string which may not be handled in the
|
|
|
|
// remote process for avoiding data loss.
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-18 18:13:42 +03:00
|
|
|
mRequestIMEToCommitCompositionResults.AppendElement(
|
2019-04-10 00:38:15 +03:00
|
|
|
RequestIMEToCommitCompositionResult::eReceivedAfterBrowserParentBlur);
|
2017-11-23 12:59:04 +03:00
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-07-05 13:55:18 +03:00
|
|
|
aCommittedString = mCompositionString;
|
2017-11-20 16:20:02 +03:00
|
|
|
// After we return true from here, i.e., without actually requesting IME
|
|
|
|
// to commit composition, we will receive eCompositionCommitRequestHandled
|
|
|
|
// pseudo event message from the remote process. So, we need to increment
|
|
|
|
// mPendingEventsNeedingAck here.
|
|
|
|
mPendingEventsNeedingAck++;
|
2017-07-05 13:55:18 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-11 09:15:58 +03:00
|
|
|
RefPtr<TextComposition> composition =
|
|
|
|
IMEStateManager::GetTextCompositionFor(aWidget);
|
|
|
|
if (NS_WARN_IF(!composition)) {
|
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Warning,
|
2016-07-05 12:56:18 +03:00
|
|
|
(" 0x%p RequestToCommitComposition(), "
|
2015-12-11 09:15:58 +03:00
|
|
|
"does nothing due to no composition",
|
|
|
|
this));
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-18 18:13:42 +03:00
|
|
|
mRequestIMEToCommitCompositionResults.AppendElement(
|
|
|
|
RequestIMEToCommitCompositionResult::eReceivedButNoTextComposition);
|
2017-11-23 12:59:04 +03:00
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2015-12-11 09:15:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-12-11 09:15:58 +03:00
|
|
|
mCommitStringByRequest = &aCommittedString;
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2017-11-20 17:08:37 +03:00
|
|
|
// Request commit or cancel composition with TextComposition because we may
|
|
|
|
// have already requested to commit or cancel the composition or we may
|
|
|
|
// have already received eCompositionCommit(AsIs) event. Those status are
|
|
|
|
// managed by composition. So, if we don't request commit composition,
|
|
|
|
// we should do nothing with native IME here.
|
|
|
|
composition->RequestToCommit(aWidget, aCancel);
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2015-12-11 09:15:58 +03:00
|
|
|
mCommitStringByRequest = nullptr;
|
|
|
|
|
|
|
|
MOZ_LOG(
|
|
|
|
sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
(" 0x%p RequestToCommitComposition(), "
|
2016-10-12 10:42:28 +03:00
|
|
|
"mWidgetHasComposition=%s, the composition %s committed synchronously",
|
|
|
|
this, GetBoolName(mWidgetHasComposition),
|
2015-12-11 09:15:58 +03:00
|
|
|
composition->Destroyed() ? "WAS" : "has NOT been"));
|
|
|
|
|
|
|
|
if (!composition->Destroyed()) {
|
|
|
|
// When the composition isn't committed synchronously, the remote process's
|
|
|
|
// TextComposition instance will synthesize commit events and wait to
|
|
|
|
// receive delayed composition events. When TextComposition instances both
|
|
|
|
// in this process and the remote process will be destroyed when delayed
|
|
|
|
// composition events received. TextComposition instance in the parent
|
|
|
|
// process will dispatch following composition events and be destroyed
|
|
|
|
// normally. On the other hand, TextComposition instance in the remote
|
|
|
|
// process won't dispatch following composition events and will be
|
|
|
|
// destroyed by IMEStateManager::DispatchCompositionEvent().
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-18 18:13:42 +03:00
|
|
|
mRequestIMEToCommitCompositionResults.AppendElement(
|
|
|
|
RequestIMEToCommitCompositionResult::eHandledAsynchronously);
|
2017-11-23 12:59:04 +03:00
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2015-12-11 09:15:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the composition is committed synchronously, the commit string will be
|
2017-11-27 14:34:01 +03:00
|
|
|
// returned to the remote process. Then, PuppetWidget will dispatch
|
2015-12-11 09:15:58 +03:00
|
|
|
// eCompositionCommit event with the returned commit string (i.e., the value
|
2017-11-27 14:34:01 +03:00
|
|
|
// is aCommittedString of this method) and that causes destroying
|
|
|
|
// TextComposition instance in the remote process (Note that TextComposition
|
|
|
|
// instance in this process was already destroyed).
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-18 18:13:42 +03:00
|
|
|
mRequestIMEToCommitCompositionResults.AppendElement(
|
|
|
|
RequestIMEToCommitCompositionResult::eHandledSynchronously);
|
2017-11-23 12:59:04 +03:00
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2015-12-11 09:15:58 +03:00
|
|
|
return true;
|
2015-06-05 12:28:19 +03:00
|
|
|
}
|
|
|
|
|
2015-07-11 04:53:55 +03:00
|
|
|
void ContentCacheInParent::MaybeNotifyIME(
|
2015-07-17 07:30:01 +03:00
|
|
|
nsIWidget* aWidget, const IMENotification& aNotification) {
|
2015-07-11 04:53:55 +03:00
|
|
|
if (!mPendingEventsNeedingAck) {
|
2019-04-10 00:38:15 +03:00
|
|
|
IMEStateManager::NotifyIME(aNotification, aWidget, &mBrowserParent);
|
2015-06-05 12:28:20 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-07-11 04:53:55 +03:00
|
|
|
|
|
|
|
switch (aNotification.mMessage) {
|
|
|
|
case NOTIFY_IME_OF_SELECTION_CHANGE:
|
|
|
|
mPendingSelectionChange.MergeWith(aNotification);
|
|
|
|
break;
|
|
|
|
case NOTIFY_IME_OF_TEXT_CHANGE:
|
|
|
|
mPendingTextChange.MergeWith(aNotification);
|
|
|
|
break;
|
2015-07-22 08:15:06 +03:00
|
|
|
case NOTIFY_IME_OF_POSITION_CHANGE:
|
|
|
|
mPendingLayoutChange.MergeWith(aNotification);
|
|
|
|
break;
|
2016-05-31 05:39:15 +03:00
|
|
|
case NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED:
|
2015-07-11 04:53:55 +03:00
|
|
|
mPendingCompositionUpdate.MergeWith(aNotification);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unsupported notification");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentCacheInParent::FlushPendingNotifications(nsIWidget* aWidget) {
|
|
|
|
MOZ_ASSERT(!mPendingEventsNeedingAck);
|
|
|
|
|
2019-04-10 00:38:15 +03:00
|
|
|
// If the BrowserParent's widget has already gone, this can do nothing since
|
2017-07-10 11:33:26 +03:00
|
|
|
// widget is necessary to notify IME of something.
|
|
|
|
if (!aWidget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-11 04:53:55 +03:00
|
|
|
// New notifications which are notified during flushing pending notifications
|
|
|
|
// should be merged again.
|
|
|
|
mPendingEventsNeedingAck++;
|
|
|
|
|
2017-07-10 11:33:26 +03:00
|
|
|
nsCOMPtr<nsIWidget> widget = aWidget;
|
2015-07-11 04:53:55 +03:00
|
|
|
|
|
|
|
// First, text change notification should be sent because selection change
|
|
|
|
// notification notifies IME of current selection range in the latest content.
|
|
|
|
// So, IME may need the latest content before that.
|
|
|
|
if (mPendingTextChange.HasNotification()) {
|
|
|
|
IMENotification notification(mPendingTextChange);
|
2017-07-10 11:33:26 +03:00
|
|
|
if (!widget->Destroyed()) {
|
2015-07-11 04:53:55 +03:00
|
|
|
mPendingTextChange.Clear();
|
2019-04-10 00:38:15 +03:00
|
|
|
IMEStateManager::NotifyIME(notification, widget, &mBrowserParent);
|
2015-07-11 04:53:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPendingSelectionChange.HasNotification()) {
|
|
|
|
IMENotification notification(mPendingSelectionChange);
|
2017-07-10 11:33:26 +03:00
|
|
|
if (!widget->Destroyed()) {
|
2015-07-11 04:53:55 +03:00
|
|
|
mPendingSelectionChange.Clear();
|
2019-04-10 00:38:15 +03:00
|
|
|
IMEStateManager::NotifyIME(notification, widget, &mBrowserParent);
|
2015-07-11 04:53:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 08:15:06 +03:00
|
|
|
// Layout change notification should be notified after selection change
|
|
|
|
// notification because IME may want to query position of new caret position.
|
|
|
|
if (mPendingLayoutChange.HasNotification()) {
|
|
|
|
IMENotification notification(mPendingLayoutChange);
|
2017-07-10 11:33:26 +03:00
|
|
|
if (!widget->Destroyed()) {
|
2015-07-22 08:15:06 +03:00
|
|
|
mPendingLayoutChange.Clear();
|
2019-04-10 00:38:15 +03:00
|
|
|
IMEStateManager::NotifyIME(notification, widget, &mBrowserParent);
|
2015-07-22 08:15:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-11 04:53:55 +03:00
|
|
|
// Finally, send composition update notification because it notifies IME of
|
|
|
|
// finishing handling whole sending events.
|
|
|
|
if (mPendingCompositionUpdate.HasNotification()) {
|
|
|
|
IMENotification notification(mPendingCompositionUpdate);
|
2017-07-10 11:33:26 +03:00
|
|
|
if (!widget->Destroyed()) {
|
2015-07-11 04:53:55 +03:00
|
|
|
mPendingCompositionUpdate.Clear();
|
2019-04-10 00:38:15 +03:00
|
|
|
IMEStateManager::NotifyIME(notification, widget, &mBrowserParent);
|
2015-07-11 04:53:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-10 11:33:26 +03:00
|
|
|
if (!--mPendingEventsNeedingAck && !widget->Destroyed() &&
|
2015-07-11 04:53:55 +03:00
|
|
|
(mPendingTextChange.HasNotification() ||
|
|
|
|
mPendingSelectionChange.HasNotification() ||
|
2015-07-22 08:15:06 +03:00
|
|
|
mPendingLayoutChange.HasNotification() ||
|
2015-07-11 04:53:55 +03:00
|
|
|
mPendingCompositionUpdate.HasNotification())) {
|
2017-07-10 11:33:26 +03:00
|
|
|
FlushPendingNotifications(widget);
|
2015-07-11 04:53:55 +03:00
|
|
|
}
|
2015-06-05 12:28:20 +03:00
|
|
|
}
|
|
|
|
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
|
|
|
|
void ContentCacheInParent::RemoveUnnecessaryEventMessageLog() {
|
|
|
|
bool foundLastCompositionStart = false;
|
|
|
|
for (size_t i = mDispatchedEventMessages.Length(); i > 1; i--) {
|
|
|
|
if (mDispatchedEventMessages[i - 1] != eCompositionStart) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!foundLastCompositionStart) {
|
|
|
|
// Find previous eCompositionStart of the latest eCompositionStart.
|
|
|
|
foundLastCompositionStart = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Remove the messages before the last 2 sets of composition events.
|
|
|
|
mDispatchedEventMessages.RemoveElementsAt(0, i - 1);
|
|
|
|
break;
|
|
|
|
}
|
2017-10-18 18:13:42 +03:00
|
|
|
uint32_t numberOfCompositionCommitRequestHandled = 0;
|
2017-10-12 20:50:47 +03:00
|
|
|
foundLastCompositionStart = false;
|
|
|
|
for (size_t i = mReceivedEventMessages.Length(); i > 1; i--) {
|
2017-10-18 18:13:42 +03:00
|
|
|
if (mReceivedEventMessages[i - 1] == eCompositionCommitRequestHandled) {
|
|
|
|
numberOfCompositionCommitRequestHandled++;
|
|
|
|
}
|
2017-10-12 20:50:47 +03:00
|
|
|
if (mReceivedEventMessages[i - 1] != eCompositionStart) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!foundLastCompositionStart) {
|
|
|
|
// Find previous eCompositionStart of the latest eCompositionStart.
|
|
|
|
foundLastCompositionStart = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Remove the messages before the last 2 sets of composition events.
|
|
|
|
mReceivedEventMessages.RemoveElementsAt(0, i - 1);
|
|
|
|
break;
|
|
|
|
}
|
2017-10-18 18:13:42 +03:00
|
|
|
|
|
|
|
if (!numberOfCompositionCommitRequestHandled) {
|
|
|
|
// If there is no eCompositionCommitRequestHandled in
|
|
|
|
// mReceivedEventMessages, we don't need to store log of
|
|
|
|
// RequestIMEToCommmitComposition().
|
|
|
|
mRequestIMEToCommitCompositionResults.Clear();
|
|
|
|
} else {
|
|
|
|
// We need to keep all reason of eCompositionCommitRequestHandled, which
|
|
|
|
// is sent when mRequestIMEToCommitComposition() returns true.
|
|
|
|
// So, we can discard older log than the first
|
|
|
|
// eCompositionCommitRequestHandled in mReceivedEventMessages.
|
|
|
|
for (size_t i = mRequestIMEToCommitCompositionResults.Length(); i > 1;
|
|
|
|
i--) {
|
|
|
|
if (mRequestIMEToCommitCompositionResults[i - 1] ==
|
|
|
|
RequestIMEToCommitCompositionResult::
|
2019-04-10 00:38:15 +03:00
|
|
|
eReceivedAfterBrowserParentBlur ||
|
2017-10-18 18:13:42 +03:00
|
|
|
mRequestIMEToCommitCompositionResults[i - 1] ==
|
|
|
|
RequestIMEToCommitCompositionResult::eHandledSynchronously) {
|
|
|
|
--numberOfCompositionCommitRequestHandled;
|
|
|
|
if (!numberOfCompositionCommitRequestHandled) {
|
|
|
|
mRequestIMEToCommitCompositionResults.RemoveElementsAt(0, i - 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-12 20:50:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContentCacheInParent::AppendEventMessageLog(nsACString& aLog) const {
|
|
|
|
aLog.AppendLiteral("Dispatched Event Message Log:\n");
|
|
|
|
for (EventMessage message : mDispatchedEventMessages) {
|
|
|
|
aLog.AppendLiteral(" ");
|
|
|
|
aLog.Append(ToChar(message));
|
|
|
|
aLog.AppendLiteral("\n");
|
|
|
|
}
|
|
|
|
aLog.AppendLiteral("\nReceived Event Message Log:\n");
|
|
|
|
for (EventMessage message : mReceivedEventMessages) {
|
|
|
|
aLog.AppendLiteral(" ");
|
|
|
|
aLog.Append(ToChar(message));
|
|
|
|
aLog.AppendLiteral("\n");
|
|
|
|
}
|
2017-10-18 18:13:42 +03:00
|
|
|
aLog.AppendLiteral("\nResult of RequestIMEToCommitComposition():\n");
|
|
|
|
for (RequestIMEToCommitCompositionResult result :
|
|
|
|
mRequestIMEToCommitCompositionResults) {
|
|
|
|
aLog.AppendLiteral(" ");
|
|
|
|
aLog.Append(ToReadableText(result));
|
|
|
|
aLog.AppendLiteral("\n");
|
|
|
|
}
|
2017-10-12 20:50:47 +03:00
|
|
|
aLog.AppendLiteral("\n");
|
|
|
|
}
|
|
|
|
|
2017-11-23 12:59:04 +03:00
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
|
2015-06-05 12:28:19 +03:00
|
|
|
/*****************************************************************************
|
|
|
|
* mozilla::ContentCache::TextRectArray
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
LayoutDeviceIntRect ContentCache::TextRectArray::GetRect(
|
|
|
|
uint32_t aOffset) const {
|
|
|
|
LayoutDeviceIntRect rect;
|
|
|
|
if (InRange(aOffset)) {
|
|
|
|
rect = mRects[aOffset - mStart];
|
|
|
|
}
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
LayoutDeviceIntRect ContentCache::TextRectArray::GetUnionRect(
|
|
|
|
uint32_t aOffset, uint32_t aLength) const {
|
|
|
|
LayoutDeviceIntRect rect;
|
|
|
|
if (!InRange(aOffset, aLength)) {
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
for (uint32_t i = 0; i < aLength; i++) {
|
|
|
|
rect = rect.Union(mRects[aOffset - mStart + i]);
|
|
|
|
}
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2015-06-17 04:03:58 +03:00
|
|
|
LayoutDeviceIntRect ContentCache::TextRectArray::GetUnionRectAsFarAsPossible(
|
2016-06-22 08:16:59 +03:00
|
|
|
uint32_t aOffset, uint32_t aLength, bool aRoundToExistingOffset) const {
|
2015-06-17 04:03:58 +03:00
|
|
|
LayoutDeviceIntRect rect;
|
2016-08-16 18:15:44 +03:00
|
|
|
if (!HasRects() ||
|
|
|
|
(!aRoundToExistingOffset && !IsOverlappingWith(aOffset, aLength))) {
|
2015-06-17 04:03:58 +03:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
uint32_t startOffset = std::max(aOffset, mStart);
|
2016-06-22 08:16:59 +03:00
|
|
|
if (aRoundToExistingOffset && startOffset >= EndOffset()) {
|
|
|
|
startOffset = EndOffset() - 1;
|
|
|
|
}
|
2015-06-17 04:03:58 +03:00
|
|
|
uint32_t endOffset = std::min(aOffset + aLength, EndOffset());
|
2016-06-22 08:16:59 +03:00
|
|
|
if (aRoundToExistingOffset && endOffset < mStart + 1) {
|
|
|
|
endOffset = mStart + 1;
|
|
|
|
}
|
2016-08-16 18:15:44 +03:00
|
|
|
if (NS_WARN_IF(endOffset < startOffset)) {
|
|
|
|
return rect;
|
|
|
|
}
|
2015-06-17 04:03:58 +03:00
|
|
|
for (uint32_t i = 0; i < endOffset - startOffset; i++) {
|
|
|
|
rect = rect.Union(mRects[startOffset - mStart + i]);
|
|
|
|
}
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:18 +03:00
|
|
|
} // namespace mozilla
|