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"
|
2017-07-05 18:47:40 +03:00
|
|
|
#include "mozilla/dom/TabParent.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)
|
|
|
|
{
|
|
|
|
Assign("{ x=");
|
|
|
|
AppendInt(aRect.x);
|
|
|
|
Append(", y=");
|
|
|
|
AppendInt(aRect.y);
|
|
|
|
Append(", width=");
|
|
|
|
AppendInt(aRect.width);
|
|
|
|
Append(", height=");
|
|
|
|
AppendInt(aRect.height);
|
|
|
|
Append(" }");
|
|
|
|
}
|
|
|
|
virtual ~GetRectText() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GetWritingModeName : public nsAutoCString
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit GetWritingModeName(const WritingMode& aWritingMode)
|
|
|
|
{
|
|
|
|
if (!aWritingMode.IsVertical()) {
|
|
|
|
Assign("Horizontal");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aWritingMode.IsVerticalLR()) {
|
|
|
|
Assign("Vertical (LTR)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Assign("Vertical (RTL)");
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2015-06-05 12:28:19 +03:00
|
|
|
ContentCache::ContentCache()
|
2016-06-13 12:17:58 +03:00
|
|
|
: mCompositionStart(UINT32_MAX)
|
2015-06-05 12:28:19 +03:00
|
|
|
{
|
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-05 12:28:18 +03:00
|
|
|
void
|
2015-06-26 02:21:13 +03:00
|
|
|
ContentCacheInChild::Clear()
|
2015-06-05 12:28:18 +03:00
|
|
|
{
|
2015-06-05 12:28:20 +03:00
|
|
|
MOZ_LOG(sContentCacheLog, LogLevel::Info,
|
2016-07-05 12:56:18 +03:00
|
|
|
("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-05 12:28:19 +03:00
|
|
|
bool
|
2015-06-26 02:21:13 +03:00
|
|
|
ContentCacheInChild::CacheAll(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification)
|
2015-06-05 12:28:20 +03:00
|
|
|
{
|
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)",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, aWidget, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-06-26 02:21:13 +03:00
|
|
|
ContentCacheInChild::CacheSelection(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification)
|
2015-06-05 12:28:20 +03:00
|
|
|
{
|
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)",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, aWidget, 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-06-26 02:21:13 +03:00
|
|
|
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)",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, aWidget, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-06-26 02:21:13 +03:00
|
|
|
ContentCacheInChild::CacheEditorRect(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification)
|
2015-06-05 12:28:20 +03:00
|
|
|
{
|
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)",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-06-26 02:21:13 +03:00
|
|
|
ContentCacheInChild::CacheText(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification)
|
2015-06-05 12:28:20 +03:00
|
|
|
{
|
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)",
|
2015-06-26 02:21:13 +03:00
|
|
|
this, 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: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-06-26 02:21:13 +03:00
|
|
|
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.
|
|
|
|
if (NS_WARN_IF(!aCharRect.height)) {
|
|
|
|
aCharRect.height = 1;
|
|
|
|
}
|
|
|
|
if (NS_WARN_IF(!aCharRect.width)) {
|
|
|
|
aCharRect.width = 1;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
aCharRectArray = Move(textRects.mReply.mRectArray);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
bool
|
2015-06-26 02:21:13 +03:00
|
|
|
ContentCacheInChild::CacheTextRects(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification)
|
2015-06-05 12:28:20 +03:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-06-26 02:21:13 +03:00
|
|
|
ContentCacheInChild::SetSelection(nsIWidget* aWidget,
|
|
|
|
uint32_t aStartOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
bool aReversed,
|
|
|
|
const WritingMode& aWritingMode)
|
2015-06-05 12:28:20 +03:00
|
|
|
{
|
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
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2017-07-05 18:47:40 +03:00
|
|
|
ContentCacheInParent::ContentCacheInParent(TabParent& aTabParent)
|
2015-06-26 02:21:13 +03:00
|
|
|
: ContentCache()
|
2017-07-05 18:47:40 +03:00
|
|
|
, mTabParent(aTabParent)
|
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)
|
2016-10-12 11:09:02 +03:00
|
|
|
, mPendingCompositionCount(0)
|
2016-10-12 10:42:28 +03:00
|
|
|
, mWidgetHasComposition(false)
|
2017-07-05 13:55:18 +03:00
|
|
|
, mIsPendingLastCommitEvent(false)
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// When the widget has composition, we should set mCompositionStart to
|
|
|
|
// *current* composition start offset. Note that, in strictly speaking,
|
|
|
|
// widget should not use WidgetQueryContentEvent if there are some pending
|
|
|
|
// compositions (i.e., when mPendingCompositionCount is 2 or more).
|
2016-10-12 15:52:01 +03:00
|
|
|
mCompositionStartInChild = aOther.mCompositionStart;
|
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 (mWidgetHasComposition) {
|
|
|
|
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");
|
|
|
|
}
|
2017-06-29 12:31:09 +03:00
|
|
|
} else if (mCompositionStart != UINT32_MAX) {
|
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 = UINT32_MAX;
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2016-10-12 10:42:28 +03:00
|
|
|
} else if (mWidgetHasComposition) {
|
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,
|
2015-06-26 02:21:13 +03:00
|
|
|
aEvent.mReply.mRect))) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:19 +03:00
|
|
|
bool
|
2015-06-26 02:21:13 +03:00
|
|
|
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:19 +03:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-06-26 02:21:13 +03:00
|
|
|
ContentCacheInParent::GetUnionTextRects(
|
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
2016-06-22 08:16:59 +03:00
|
|
|
bool aRoundToExistingOffset,
|
2015-06-26 02:21:13 +03:00
|
|
|
LayoutDeviceIntRect& aUnionTextRect) const
|
2015-06-05 12:28:19 +03:00
|
|
|
{
|
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));
|
2015-06-05 12:28:20 +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)) {
|
2015-06-17 04:03:58 +03:00
|
|
|
aUnionTextRect =
|
2016-06-22 08:16:59 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-06-26 02:21:13 +03:00
|
|
|
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:19 +03:00
|
|
|
{
|
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(),
|
2015-06-26 02:21:13 +03:00
|
|
|
GetBoolName(mCaret.IsValid()), 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()) {
|
|
|
|
aCaretRect.y = aCaretRect.YMost();
|
|
|
|
} else {
|
|
|
|
// XXX bidi-unaware.
|
|
|
|
aCaretRect.x = aCaretRect.XMost();
|
|
|
|
}
|
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()) {
|
|
|
|
aCaretRect.height = mCaret.IsValid() ? mCaret.mRect.height : 1;
|
|
|
|
} else {
|
|
|
|
aCaretRect.width = mCaret.IsValid() ? mCaret.mRect.width : 1;
|
|
|
|
}
|
2015-06-05 12:28:19 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:19 +03:00
|
|
|
bool
|
2015-06-26 02:21:13 +03:00
|
|
|
ContentCacheInParent::OnCompositionEvent(const WidgetCompositionEvent& aEvent)
|
2015-06-05 12:28:19 +03:00
|
|
|
{
|
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, "
|
2016-10-12 11:09:02 +03:00
|
|
|
"mPendingCompositionCount=%u, mCommitStringByRequest=0x%p",
|
2015-09-17 06:05:44 +03:00
|
|
|
this, ToChar(aEvent.mMessage),
|
2016-07-13 12:16:04 +03:00
|
|
|
GetEscapedUTF8String(aEvent.mData).get(), aEvent.mData.Length(),
|
2015-07-11 04:53:55 +03:00
|
|
|
aEvent.mRanges ? aEvent.mRanges->Length() : 0, mPendingEventsNeedingAck,
|
2016-10-12 11:09:02 +03:00
|
|
|
GetBoolName(mWidgetHasComposition), mPendingCompositionCount,
|
|
|
|
mCommitStringByRequest));
|
2015-06-05 12:28:20 +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) {
|
2016-06-13 12:17:58 +03:00
|
|
|
mCompositionStart = UINT32_MAX;
|
2017-06-29 12:31:09 +03:00
|
|
|
if (mPendingCompositionCount == 1) {
|
|
|
|
mPendingCommitLength = aEvent.mData.Length();
|
|
|
|
}
|
2017-07-05 13:55:18 +03:00
|
|
|
mIsPendingLastCommitEvent = true;
|
|
|
|
} 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) {
|
|
|
|
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
|
|
|
|
// incremented here.
|
|
|
|
if (!mWidgetHasComposition) {
|
|
|
|
mPendingEventsNeedingAck++;
|
|
|
|
}
|
2017-07-05 13:55:18 +03:00
|
|
|
// Cancel mIsPendingLastCommitEvent because we won't send the commit event
|
|
|
|
// to the remote process.
|
|
|
|
mIsPendingLastCommitEvent = false;
|
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, "
|
|
|
|
"mPendingCompositionCount=%u",
|
2015-09-17 06:05:44 +03:00
|
|
|
this, ToChar(aSelectionEvent.mMessage),
|
2015-07-11 04:53:55 +03:00
|
|
|
aSelectionEvent.mOffset, aSelectionEvent.mLength,
|
|
|
|
GetBoolName(aSelectionEvent.mReversed),
|
|
|
|
GetBoolName(aSelectionEvent.mExpandToClusterBoundary),
|
|
|
|
GetBoolName(aSelectionEvent.mUseNativeLineBreak), mPendingEventsNeedingAck,
|
2016-10-12 11:09:02 +03:00
|
|
|
GetBoolName(mWidgetHasComposition), mPendingCompositionCount));
|
2015-07-11 04:53:55 +03:00
|
|
|
|
|
|
|
mPendingEventsNeedingAck++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-07-22 08:51:36 +03:00
|
|
|
ContentCacheInParent::OnEventNeedingAckHandled(nsIWidget* aWidget,
|
2015-08-26 15:56:59 +03:00
|
|
|
EventMessage aMessage)
|
2015-07-11 04:53:55 +03:00
|
|
|
{
|
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-06-27 16:02:07 +03:00
|
|
|
"aMessage=%s), mPendingEventsNeedingAck=%u, mPendingCompositionCount=%" PRIu8,
|
|
|
|
this, aWidget, ToChar(aMessage), mPendingEventsNeedingAck, mPendingCompositionCount));
|
|
|
|
|
2017-06-27 17:41:12 +03:00
|
|
|
if (WidgetCompositionEvent::IsFollowedByCompositionEnd(aMessage) ||
|
|
|
|
aMessage == eCompositionCommitRequestHandled) {
|
2017-06-27 16:02:07 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mPendingCompositionCount > 0);
|
|
|
|
mPendingCompositionCount--;
|
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();
|
|
|
|
mIsPendingLastCommitEvent = false;
|
|
|
|
}
|
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
|
|
|
|
2015-07-11 04:53:55 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mPendingEventsNeedingAck > 0);
|
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:19 +03:00
|
|
|
{
|
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-07-05 13:55:18 +03:00
|
|
|
"aCancel=%s), mPendingCompositionCount=%u, "
|
|
|
|
"IMEStateManager::DoesTabParentHaveIMEFocus(&mTabParent)=%s, "
|
|
|
|
"mWidgetHasComposition=%s, mCommitStringByRequest=%p",
|
|
|
|
this, aWidget, GetBoolName(aCancel), mPendingCompositionCount,
|
|
|
|
GetBoolName(IMEStateManager::DoesTabParentHaveIMEFocus(&mTabParent)),
|
|
|
|
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) {
|
|
|
|
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.
|
|
|
|
if (mIsPendingLastCommitEvent) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-05 13:55:18 +03:00
|
|
|
// If TabParent 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::DoesTabParentHaveIMEFocus(&mTabParent)) {
|
|
|
|
// Use the latest composition string which may not be handled in the
|
|
|
|
// remote process for avoiding data loss.
|
|
|
|
aCommittedString = mCompositionString;
|
|
|
|
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));
|
|
|
|
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
|
|
|
|
|
|
|
aWidget->NotifyIME(IMENotification(aCancel ? REQUEST_TO_CANCEL_COMPOSITION :
|
|
|
|
REQUEST_TO_COMMIT_COMPOSITION));
|
|
|
|
|
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().
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the composition is committed synchronously, the commit string will be
|
|
|
|
// returned to the remote process. Then, PuppetWidget will dispatch
|
|
|
|
// eCompositionCommit event with the returned commit string (i.e., the value
|
|
|
|
// is aCommittedString of this method). Finally, TextComposition instance in
|
|
|
|
// the remote process will be destroyed by
|
|
|
|
// IMEStateManager::DispatchCompositionEvent() at receiving the
|
|
|
|
// eCompositionCommit event (Note that TextComposition instance in this
|
|
|
|
// process was already destroyed).
|
|
|
|
return true;
|
2015-06-05 12:28:19 +03:00
|
|
|
}
|
|
|
|
|
2015-06-05 12:28:20 +03:00
|
|
|
void
|
2015-07-11 04:53:55 +03:00
|
|
|
ContentCacheInParent::MaybeNotifyIME(nsIWidget* aWidget,
|
2015-07-17 07:30:01 +03:00
|
|
|
const IMENotification& aNotification)
|
2015-06-05 12:28:20 +03:00
|
|
|
{
|
2015-07-11 04:53:55 +03:00
|
|
|
if (!mPendingEventsNeedingAck) {
|
2017-07-05 18:47:40 +03:00
|
|
|
IMEStateManager::NotifyIME(aNotification, aWidget, &mTabParent);
|
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);
|
|
|
|
|
2017-07-10 11:33:26 +03:00
|
|
|
// If the TabParent's widget has already gone, this can do nothing since
|
|
|
|
// 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();
|
2017-07-10 11:33:26 +03:00
|
|
|
IMEStateManager::NotifyIME(notification, widget, &mTabParent);
|
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();
|
2017-07-10 11:33:26 +03:00
|
|
|
IMEStateManager::NotifyIME(notification, widget, &mTabParent);
|
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();
|
2017-07-10 11:33:26 +03:00
|
|
|
IMEStateManager::NotifyIME(notification, widget, &mTabParent);
|
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();
|
2017-07-10 11:33:26 +03:00
|
|
|
IMEStateManager::NotifyIME(notification, widget, &mTabParent);
|
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
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
uint32_t aOffset,
|
2016-06-22 08:16:59 +03:00
|
|
|
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
|