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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_ContentCache_h
|
|
|
|
#define mozilla_ContentCache_h
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2020-11-23 19:12:02 +03:00
|
|
|
#include "mozilla/widget/IMEData.h"
|
2015-06-05 12:28:19 +03:00
|
|
|
#include "mozilla/Assertions.h"
|
2015-06-05 12:28:21 +03:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2015-06-05 12:28:19 +03:00
|
|
|
#include "mozilla/EventForwards.h"
|
2020-11-23 12:29:34 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2020-11-27 17:47:37 +03:00
|
|
|
#include "mozilla/ToString.h"
|
2015-06-05 12:28:19 +03:00
|
|
|
#include "mozilla/WritingModes.h"
|
2015-06-05 12:28:18 +03:00
|
|
|
#include "nsString.h"
|
2015-06-05 12:28:19 +03:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "Units.h"
|
2015-06-05 12:28:18 +03:00
|
|
|
|
2020-11-23 19:12:02 +03:00
|
|
|
class nsIWidget;
|
|
|
|
|
2015-06-05 12:28:18 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
class ContentCacheInParent;
|
|
|
|
|
2017-07-05 18:47:40 +03:00
|
|
|
namespace dom {
|
2019-04-10 00:38:15 +03:00
|
|
|
class BrowserParent;
|
2017-07-05 18:47:40 +03:00
|
|
|
} // namespace dom
|
|
|
|
|
2015-06-05 12:28:18 +03:00
|
|
|
/**
|
2015-06-26 02:21:13 +03:00
|
|
|
* ContentCache stores various information of the child content.
|
|
|
|
* This class has members which are necessary both in parent process and
|
|
|
|
* content process.
|
2015-06-05 12:28:18 +03:00
|
|
|
*/
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
class ContentCache {
|
2015-06-05 12:28:18 +03:00
|
|
|
public:
|
2020-04-30 12:38:38 +03:00
|
|
|
typedef CopyableTArray<LayoutDeviceIntRect> RectArray;
|
2015-06-05 12:28:20 +03:00
|
|
|
typedef widget::IMENotification IMENotification;
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2020-11-23 12:29:34 +03:00
|
|
|
ContentCache() = default;
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
protected:
|
2015-06-05 12:28:18 +03:00
|
|
|
// Whole text in the target
|
|
|
|
nsString mText;
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2016-06-13 12:17:58 +03:00
|
|
|
// Start offset of the composition string.
|
2020-11-23 12:29:34 +03:00
|
|
|
Maybe<uint32_t> mCompositionStart;
|
2016-06-13 12:17:58 +03:00
|
|
|
|
2016-07-22 14:47:51 +03:00
|
|
|
enum { ePrevCharRect = 1, eNextCharRect = 0 };
|
|
|
|
|
2015-06-05 12:28:19 +03:00
|
|
|
struct Selection final {
|
|
|
|
// Following values are offset in "flat text".
|
|
|
|
uint32_t mAnchor;
|
|
|
|
uint32_t mFocus;
|
|
|
|
|
2015-06-05 12:28:19 +03:00
|
|
|
WritingMode mWritingMode;
|
|
|
|
|
2016-07-22 14:47:51 +03:00
|
|
|
// Character rects at previous and next character of mAnchor and mFocus.
|
|
|
|
// The reason why ContentCache needs to store each previous character of
|
|
|
|
// them is IME may query character rect of the last character of a line
|
|
|
|
// when caret is at the end of the line.
|
|
|
|
// Note that use ePrevCharRect and eNextCharRect for accessing each item.
|
|
|
|
LayoutDeviceIntRect mAnchorCharRects[2];
|
|
|
|
LayoutDeviceIntRect mFocusCharRects[2];
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2015-06-08 05:46:17 +03:00
|
|
|
// Whole rect of selected text. This is empty if the selection is collapsed.
|
|
|
|
LayoutDeviceIntRect mRect;
|
|
|
|
|
2020-11-27 17:47:37 +03:00
|
|
|
explicit Selection(uint32_t aAnchorOffset, uint32_t aFocusOffset,
|
|
|
|
const WritingMode& aWritingMode)
|
|
|
|
: mAnchor(aAnchorOffset),
|
|
|
|
mFocus(aFocusOffset),
|
|
|
|
mWritingMode(aWritingMode) {}
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2020-11-27 17:47:37 +03:00
|
|
|
void ClearRects() {
|
|
|
|
for (auto& rect : mAnchorCharRects) {
|
|
|
|
rect.SetEmpty();
|
|
|
|
}
|
|
|
|
for (auto& rect : mFocusCharRects) {
|
|
|
|
rect.SetEmpty();
|
|
|
|
}
|
2015-06-08 05:46:17 +03:00
|
|
|
mRect.SetEmpty();
|
2015-06-05 12:28:20 +03:00
|
|
|
}
|
2020-11-27 17:47:37 +03:00
|
|
|
bool HasRects() const {
|
|
|
|
for (auto& rect : mAnchorCharRects) {
|
|
|
|
if (!rect.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-07-22 14:47:51 +03:00
|
|
|
}
|
2020-11-27 17:47:37 +03:00
|
|
|
for (auto& rect : mFocusCharRects) {
|
|
|
|
if (!rect.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-07-22 14:47:51 +03:00
|
|
|
}
|
2020-11-27 17:47:37 +03:00
|
|
|
return !mRect.IsEmpty();
|
2016-07-22 14:47:51 +03:00
|
|
|
}
|
|
|
|
|
2020-11-27 17:47:37 +03:00
|
|
|
bool Collapsed() const { return mFocus == mAnchor; }
|
|
|
|
bool Reversed() const { return mFocus < mAnchor; }
|
|
|
|
uint32_t StartOffset() const { return Reversed() ? mFocus : mAnchor; }
|
|
|
|
uint32_t EndOffset() const { return Reversed() ? mAnchor : mFocus; }
|
2015-06-05 12:28:19 +03:00
|
|
|
uint32_t Length() const {
|
|
|
|
return Reversed() ? mAnchor - mFocus : mFocus - mAnchor;
|
|
|
|
}
|
2016-06-22 08:16:59 +03:00
|
|
|
LayoutDeviceIntRect StartCharRect() const {
|
2016-07-22 14:47:51 +03:00
|
|
|
return Reversed() ? mFocusCharRects[eNextCharRect]
|
|
|
|
: mAnchorCharRects[eNextCharRect];
|
2016-06-22 08:16:59 +03:00
|
|
|
}
|
|
|
|
LayoutDeviceIntRect EndCharRect() const {
|
2016-07-22 14:47:51 +03:00
|
|
|
return Reversed() ? mAnchorCharRects[eNextCharRect]
|
|
|
|
: mFocusCharRects[eNextCharRect];
|
2016-06-22 08:16:59 +03:00
|
|
|
}
|
2020-11-27 17:47:37 +03:00
|
|
|
|
|
|
|
friend std::ostream& operator<<(std::ostream& aStream,
|
|
|
|
const Selection& aSelection) {
|
|
|
|
aStream << "{ mAnchor=" << aSelection.mAnchor
|
|
|
|
<< ", mFocus=" << aSelection.mFocus
|
|
|
|
<< ", mWritingMode=" << ToString(aSelection.mWritingMode).c_str();
|
|
|
|
if (aSelection.HasRects()) {
|
|
|
|
if (aSelection.mAnchor > 0) {
|
|
|
|
aStream << ", mAnchorCharRects[ePrevCharRect]="
|
|
|
|
<< aSelection.mAnchorCharRects[ContentCache::ePrevCharRect];
|
|
|
|
}
|
|
|
|
aStream << ", mAnchorCharRects[eNextCharRect]="
|
|
|
|
<< aSelection.mAnchorCharRects[ContentCache::eNextCharRect];
|
|
|
|
if (aSelection.mFocus > 0) {
|
|
|
|
aStream << ", mFocusCharRects[ePrevCharRect]="
|
|
|
|
<< aSelection.mFocusCharRects[ContentCache::ePrevCharRect];
|
|
|
|
}
|
|
|
|
aStream << ", mFocusCharRects[eNextCharRect]="
|
|
|
|
<< aSelection.mFocusCharRects[ContentCache::eNextCharRect]
|
|
|
|
<< ", mRect=" << aSelection.mRect;
|
|
|
|
}
|
|
|
|
aStream << ", Reversed()=" << (aSelection.Reversed() ? "true" : "false")
|
|
|
|
<< ", StartOffset()=" << aSelection.StartOffset()
|
|
|
|
<< ", EndOffset()=" << aSelection.EndOffset()
|
|
|
|
<< ", Collapsed()=" << (aSelection.Collapsed() ? "true" : "false")
|
|
|
|
<< ", Length()=" << aSelection.Length() << " }";
|
|
|
|
return aStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Selection() = default;
|
|
|
|
|
|
|
|
friend struct IPC::ParamTraits<ContentCache::Selection>;
|
|
|
|
friend struct IPC::ParamTraits<Maybe<ContentCache::Selection>>;
|
|
|
|
};
|
|
|
|
Maybe<Selection> mSelection;
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2015-06-05 12:28:21 +03:00
|
|
|
bool IsSelectionValid() const {
|
2020-11-27 17:47:37 +03:00
|
|
|
return mSelection.isSome() && mSelection->EndOffset() <= mText.Length();
|
2015-06-05 12:28:21 +03:00
|
|
|
}
|
|
|
|
|
2015-06-17 04:03:58 +03:00
|
|
|
// Stores first char rect because Yosemite's Japanese IME sometimes tries
|
|
|
|
// to query it. If there is no text, this is caret rect.
|
|
|
|
LayoutDeviceIntRect mFirstCharRect;
|
|
|
|
|
2015-06-05 12:28:19 +03:00
|
|
|
struct Caret final {
|
|
|
|
uint32_t mOffset;
|
|
|
|
LayoutDeviceIntRect mRect;
|
|
|
|
|
2020-11-27 17:47:50 +03:00
|
|
|
explicit Caret(uint32_t aOffset, LayoutDeviceIntRect aCaretRect)
|
|
|
|
: mOffset(aOffset), mRect(aCaretRect) {}
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2020-11-27 17:47:50 +03:00
|
|
|
uint32_t Offset() const { return mOffset; }
|
|
|
|
bool HasRect() const { return !mRect.IsEmpty(); }
|
|
|
|
|
|
|
|
friend std::ostream& operator<<(std::ostream& aStream,
|
|
|
|
const Caret& aCaret) {
|
|
|
|
aStream << "{ mOffset=" << aCaret.mOffset;
|
|
|
|
if (aCaret.HasRect()) {
|
|
|
|
aStream << ", mRect=" << aCaret.mRect;
|
|
|
|
}
|
|
|
|
return aStream << " }";
|
2015-06-05 12:28:20 +03:00
|
|
|
}
|
|
|
|
|
2020-11-27 17:47:50 +03:00
|
|
|
private:
|
|
|
|
Caret() = default;
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2020-11-27 17:47:50 +03:00
|
|
|
friend struct IPC::ParamTraits<ContentCache::Caret>;
|
|
|
|
friend struct IPC::ParamTraits<Maybe<ContentCache::Caret>>;
|
|
|
|
};
|
|
|
|
Maybe<Caret> mCaret;
|
2015-06-05 12:28:19 +03:00
|
|
|
|
|
|
|
struct TextRectArray final {
|
|
|
|
uint32_t mStart;
|
|
|
|
RectArray mRects;
|
|
|
|
|
2020-11-27 17:48:03 +03:00
|
|
|
explicit TextRectArray(uint32_t aStartOffset) : mStart(aStartOffset) {}
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2020-11-27 17:48:03 +03:00
|
|
|
bool HasRects() const { return Length() > 0; }
|
|
|
|
uint32_t StartOffset() const { return mStart; }
|
|
|
|
uint32_t EndOffset() const {
|
2015-06-05 12:28:21 +03:00
|
|
|
CheckedInt<uint32_t> endOffset =
|
|
|
|
CheckedInt<uint32_t>(mStart) + mRects.Length();
|
2020-11-27 17:48:03 +03:00
|
|
|
return endOffset.isValid() ? endOffset.value() : UINT32_MAX;
|
2015-06-05 12:28:19 +03:00
|
|
|
}
|
2020-11-27 17:48:03 +03:00
|
|
|
uint32_t Length() const { return EndOffset() - mStart; }
|
|
|
|
bool IsOffsetInRange(uint32_t aOffset) const {
|
|
|
|
return StartOffset() <= aOffset && aOffset < EndOffset();
|
2015-06-05 12:28:19 +03:00
|
|
|
}
|
2020-11-27 17:48:03 +03:00
|
|
|
bool IsRangeCompletelyInRange(uint32_t aOffset, uint32_t aLength) const {
|
2015-06-05 12:28:21 +03:00
|
|
|
CheckedInt<uint32_t> endOffset = CheckedInt<uint32_t>(aOffset) + aLength;
|
|
|
|
if (NS_WARN_IF(!endOffset.isValid())) {
|
2015-06-05 12:28:19 +03:00
|
|
|
return false;
|
|
|
|
}
|
2020-11-27 17:48:03 +03:00
|
|
|
return IsOffsetInRange(aOffset) && aOffset + aLength <= EndOffset();
|
2015-06-05 12:28:19 +03:00
|
|
|
}
|
2015-06-17 04:03:58 +03:00
|
|
|
bool IsOverlappingWith(uint32_t aOffset, uint32_t aLength) const {
|
2016-08-16 10:07:54 +03:00
|
|
|
if (!HasRects() || aOffset == UINT32_MAX || !aLength) {
|
2015-06-17 04:03:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
CheckedInt<uint32_t> endOffset = CheckedInt<uint32_t>(aOffset) + aLength;
|
|
|
|
if (NS_WARN_IF(!endOffset.isValid())) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-16 10:07:54 +03:00
|
|
|
return aOffset < EndOffset() && endOffset.value() > mStart;
|
2015-06-17 04:03:58 +03:00
|
|
|
}
|
2015-06-05 12:28:19 +03:00
|
|
|
LayoutDeviceIntRect GetRect(uint32_t aOffset) const;
|
|
|
|
LayoutDeviceIntRect GetUnionRect(uint32_t aOffset, uint32_t aLength) const;
|
2016-06-22 08:16:59 +03:00
|
|
|
LayoutDeviceIntRect GetUnionRectAsFarAsPossible(
|
|
|
|
uint32_t aOffset, uint32_t aLength, bool aRoundToExistingOffset) const;
|
2020-11-27 17:48:03 +03:00
|
|
|
|
|
|
|
friend std::ostream& operator<<(std::ostream& aStream,
|
|
|
|
const TextRectArray& aTextRectArray) {
|
|
|
|
aStream << "{ mStart=" << aTextRectArray.mStart
|
|
|
|
<< ", mRects={ Length()=" << aTextRectArray.Length();
|
|
|
|
if (aTextRectArray.HasRects()) {
|
|
|
|
aStream << ", Elements()=[ ";
|
|
|
|
static constexpr uint32_t kMaxPrintRects = 4;
|
|
|
|
const uint32_t kFirstHalf = aTextRectArray.Length() <= kMaxPrintRects
|
|
|
|
? UINT32_MAX
|
|
|
|
: (kMaxPrintRects + 1) / 2;
|
|
|
|
const uint32_t kSecondHalf =
|
|
|
|
aTextRectArray.Length() <= kMaxPrintRects ? 0 : kMaxPrintRects / 2;
|
|
|
|
for (uint32_t i = 0; i < aTextRectArray.Length(); i++) {
|
|
|
|
if (i > 0) {
|
|
|
|
aStream << ", ";
|
|
|
|
}
|
|
|
|
aStream << ToString(aTextRectArray.mRects[i]).c_str();
|
|
|
|
if (i + 1 == kFirstHalf) {
|
|
|
|
aStream << " ...";
|
|
|
|
i = aTextRectArray.Length() - kSecondHalf - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aStream << " ] } }";
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
TextRectArray() = default;
|
|
|
|
|
|
|
|
friend struct IPC::ParamTraits<ContentCache::TextRectArray>;
|
|
|
|
friend struct IPC::ParamTraits<Maybe<ContentCache::TextRectArray>>;
|
2020-11-24 04:31:46 +03:00
|
|
|
};
|
2020-11-27 17:48:03 +03:00
|
|
|
Maybe<TextRectArray> mTextRectArray;
|
|
|
|
Maybe<TextRectArray> mLastCommitStringTextRectArray;
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2015-06-05 12:28:19 +03:00
|
|
|
LayoutDeviceIntRect mEditorRect;
|
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
friend class ContentCacheInParent;
|
|
|
|
friend struct IPC::ParamTraits<ContentCache>;
|
2020-11-27 17:47:37 +03:00
|
|
|
friend struct IPC::ParamTraits<ContentCache::Selection>;
|
2020-11-27 17:47:50 +03:00
|
|
|
friend struct IPC::ParamTraits<ContentCache::Caret>;
|
2020-11-27 17:48:03 +03:00
|
|
|
friend struct IPC::ParamTraits<ContentCache::TextRectArray>;
|
2020-11-27 17:47:37 +03:00
|
|
|
friend std::ostream& operator<<(
|
|
|
|
std::ostream& aStream,
|
|
|
|
const Selection& aSelection); // For e(Prev|Next)CharRect
|
2015-06-26 02:21:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class ContentCacheInChild final : public ContentCache {
|
|
|
|
public:
|
2020-11-24 04:31:46 +03:00
|
|
|
ContentCacheInChild() = default;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when composition event will be dispatched in this process from
|
|
|
|
* PuppetWidget.
|
|
|
|
*/
|
|
|
|
void OnCompositionEvent(const WidgetCompositionEvent& aCompositionEvent);
|
2015-06-05 12:28:19 +03:00
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
/**
|
|
|
|
* When IME loses focus, this should be called and making this forget the
|
|
|
|
* content for reducing footprint.
|
|
|
|
*/
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache*() retrieves the latest content information and store them.
|
|
|
|
* Be aware, CacheSelection() calls CacheTextRects(), and also CacheText()
|
|
|
|
* calls CacheSelection(). So, related data is also retrieved automatically.
|
|
|
|
*/
|
|
|
|
bool CacheEditorRect(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification = nullptr);
|
|
|
|
bool CacheSelection(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification = nullptr);
|
|
|
|
bool CacheText(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification = nullptr);
|
|
|
|
|
|
|
|
bool CacheAll(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification = nullptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SetSelection() modifies selection with specified raw data. And also this
|
|
|
|
* tries to retrieve text rects too.
|
|
|
|
*/
|
|
|
|
void SetSelection(nsIWidget* aWidget, uint32_t aStartOffset, uint32_t aLength,
|
|
|
|
bool aReversed, const WritingMode& aWritingMode);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
private:
|
2015-06-05 12:28:20 +03:00
|
|
|
bool QueryCharRect(nsIWidget* aWidget, uint32_t aOffset,
|
|
|
|
LayoutDeviceIntRect& aCharRect) const;
|
2016-07-22 14:47:51 +03:00
|
|
|
bool QueryCharRectArray(nsIWidget* aWidget, uint32_t aOffset,
|
|
|
|
uint32_t aLength, RectArray& aCharRectArray) const;
|
2015-06-05 12:28:20 +03:00
|
|
|
bool CacheCaret(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification = nullptr);
|
|
|
|
bool CacheTextRects(nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification = nullptr);
|
2020-11-24 04:31:46 +03:00
|
|
|
|
|
|
|
// Once composition is committed, all of the commit string may be composed
|
|
|
|
// again by Kakutei-Undo of Japanese IME. Therefore, we need to keep
|
|
|
|
// storing the last composition start to cache all character rects of the
|
|
|
|
// last commit string.
|
2020-11-27 17:47:30 +03:00
|
|
|
Maybe<OffsetAndData<uint32_t>> mLastCommit;
|
2015-06-26 02:21:13 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class ContentCacheInParent final : public ContentCache {
|
|
|
|
public:
|
2019-04-10 00:38:15 +03:00
|
|
|
explicit ContentCacheInParent(dom::BrowserParent& aBrowserParent);
|
2015-06-26 02:21:13 +03:00
|
|
|
|
|
|
|
/**
|
2019-04-10 00:38:15 +03:00
|
|
|
* AssignContent() is called when BrowserParent receives ContentCache from
|
2015-06-26 02:21:13 +03:00
|
|
|
* the content process. This doesn't copy composition information because
|
2019-04-10 00:38:15 +03:00
|
|
|
* it's managed by BrowserParent itself.
|
2015-06-26 02:21:13 +03:00
|
|
|
*/
|
|
|
|
void AssignContent(const ContentCache& aOther, nsIWidget* aWidget,
|
|
|
|
const IMENotification* aNotification = nullptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HandleQueryContentEvent() sets content data to aEvent.mReply.
|
|
|
|
*
|
2015-09-10 04:40:05 +03:00
|
|
|
* For eQuerySelectedText, fail if the cache doesn't contain the whole
|
2015-06-26 02:21:13 +03:00
|
|
|
* selected range. (This shouldn't happen because PuppetWidget should have
|
|
|
|
* already sent the whole selection.)
|
|
|
|
*
|
2015-09-10 04:40:05 +03:00
|
|
|
* For eQueryTextContent, fail only if the cache doesn't overlap with
|
2015-06-26 02:21:13 +03:00
|
|
|
* the queried range. Note the difference from above. We use
|
2015-09-10 04:40:05 +03:00
|
|
|
* this behavior because a normal eQueryTextContent event is allowed to
|
2015-06-26 02:21:13 +03:00
|
|
|
* have out-of-bounds offsets, so that widget can request content without
|
|
|
|
* knowing the exact length of text. It's up to widget to handle cases when
|
|
|
|
* the returned offset/length are different from the queried offset/length.
|
|
|
|
*
|
2015-09-11 15:21:26 +03:00
|
|
|
* For eQueryTextRect, fail if cached offset/length aren't equals to input.
|
2015-06-26 02:21:13 +03:00
|
|
|
* Cocoa widget always queries selected offset, so it works on it.
|
|
|
|
*
|
2015-09-10 04:40:06 +03:00
|
|
|
* For eQueryCaretRect, fail if cached offset isn't equals to input
|
2015-06-26 02:21:13 +03:00
|
|
|
*
|
2015-09-10 04:40:06 +03:00
|
|
|
* For eQueryEditorRect, always success
|
2015-06-26 02:21:13 +03:00
|
|
|
*/
|
|
|
|
bool HandleQueryContentEvent(WidgetQueryContentEvent& aEvent,
|
|
|
|
nsIWidget* aWidget) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OnCompositionEvent() should be called before sending composition string.
|
|
|
|
* This returns true if the event should be sent. Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool OnCompositionEvent(const WidgetCompositionEvent& aCompositionEvent);
|
|
|
|
|
2015-07-11 04:53:55 +03:00
|
|
|
/**
|
|
|
|
* OnSelectionEvent() should be called before sending selection event.
|
|
|
|
*/
|
|
|
|
void OnSelectionEvent(const WidgetSelectionEvent& aSelectionEvent);
|
|
|
|
|
|
|
|
/**
|
2015-07-22 08:51:36 +03:00
|
|
|
* OnEventNeedingAckHandled() should be called after the child process
|
|
|
|
* handles a sent event which needs acknowledging.
|
2015-07-11 04:53:55 +03:00
|
|
|
*
|
|
|
|
* WARNING: This may send notifications to IME. That might cause destroying
|
2019-04-10 00:38:15 +03:00
|
|
|
* BrowserParent or aWidget. Therefore, the caller must not destroy
|
2015-07-11 04:53:55 +03:00
|
|
|
* this instance during a call of this method.
|
2015-07-11 04:53:55 +03:00
|
|
|
*/
|
2015-08-26 15:56:59 +03:00
|
|
|
void OnEventNeedingAckHandled(nsIWidget* aWidget, EventMessage aMessage);
|
2015-07-11 04:53:55 +03:00
|
|
|
|
2015-06-26 02:21:13 +03:00
|
|
|
/**
|
2015-12-11 09:15:58 +03:00
|
|
|
* RequestIMEToCommitComposition() requests aWidget to commit or cancel
|
|
|
|
* composition. If it's handled synchronously, this returns true.
|
2015-06-26 02:21:13 +03:00
|
|
|
*
|
|
|
|
* @param aWidget The widget to be requested to commit or cancel
|
|
|
|
* the composition.
|
|
|
|
* @param aCancel When the caller tries to cancel the composition, true.
|
|
|
|
* Otherwise, i.e., tries to commit the composition, false.
|
2015-12-11 09:15:58 +03:00
|
|
|
* @param aCommittedString The committed string (i.e., the last data of
|
|
|
|
* dispatched composition events during requesting
|
|
|
|
* IME to commit composition.
|
|
|
|
* @return Whether the composition is actually committed
|
|
|
|
* synchronously.
|
2015-06-26 02:21:13 +03:00
|
|
|
*/
|
2015-12-11 09:15:58 +03:00
|
|
|
bool RequestIMEToCommitComposition(nsIWidget* aWidget, bool aCancel,
|
|
|
|
nsAString& aCommittedString);
|
2015-06-26 02:21:13 +03:00
|
|
|
|
|
|
|
/**
|
2015-07-11 04:53:55 +03:00
|
|
|
* MaybeNotifyIME() may notify IME of the notification. If child process
|
|
|
|
* hasn't been handled all sending events yet, this stores the notification
|
|
|
|
* and flush it later.
|
2015-06-26 02:21:13 +03:00
|
|
|
*/
|
2015-07-11 04:53:55 +03:00
|
|
|
void MaybeNotifyIME(nsIWidget* aWidget, const IMENotification& aNotification);
|
2015-06-26 02:21:13 +03:00
|
|
|
|
|
|
|
private:
|
2015-07-11 04:53:55 +03:00
|
|
|
IMENotification mPendingSelectionChange;
|
|
|
|
IMENotification mPendingTextChange;
|
2015-07-22 08:15:06 +03:00
|
|
|
IMENotification mPendingLayoutChange;
|
2015-07-11 04:53:55 +03:00
|
|
|
IMENotification mPendingCompositionUpdate;
|
|
|
|
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
// Log of event messages to be output to crash report.
|
|
|
|
nsTArray<EventMessage> mDispatchedEventMessages;
|
|
|
|
nsTArray<EventMessage> mReceivedEventMessages;
|
2017-10-18 18:13:42 +03:00
|
|
|
// Log of RequestIMEToCommitComposition() in the last 2 compositions.
|
|
|
|
enum class RequestIMEToCommitCompositionResult : uint8_t {
|
|
|
|
eToOldCompositionReceived,
|
|
|
|
eToCommittedCompositionReceived,
|
2019-04-10 00:38:15 +03:00
|
|
|
eReceivedAfterBrowserParentBlur,
|
2017-10-18 18:13:42 +03:00
|
|
|
eReceivedButNoTextComposition,
|
|
|
|
eHandledAsynchronously,
|
|
|
|
eHandledSynchronously,
|
|
|
|
};
|
|
|
|
const char* ToReadableText(
|
|
|
|
RequestIMEToCommitCompositionResult aResult) const {
|
|
|
|
switch (aResult) {
|
|
|
|
case RequestIMEToCommitCompositionResult::eToOldCompositionReceived:
|
|
|
|
return "Commit request is not handled because it's for "
|
|
|
|
"older composition";
|
|
|
|
case RequestIMEToCommitCompositionResult::eToCommittedCompositionReceived:
|
2019-04-10 00:38:15 +03:00
|
|
|
return "Commit request is not handled because BrowserParent has "
|
|
|
|
"already "
|
2017-10-18 18:13:42 +03:00
|
|
|
"sent commit event for the composition";
|
2019-04-10 00:38:15 +03:00
|
|
|
case RequestIMEToCommitCompositionResult::eReceivedAfterBrowserParentBlur:
|
2017-10-18 18:13:42 +03:00
|
|
|
return "Commit request is handled with stored composition string "
|
2019-04-10 00:38:15 +03:00
|
|
|
"because BrowserParent has already lost focus";
|
2017-10-18 18:13:42 +03:00
|
|
|
case RequestIMEToCommitCompositionResult::eReceivedButNoTextComposition:
|
|
|
|
return "Commit request is not handled because there is no "
|
|
|
|
"TextCompsition instance";
|
|
|
|
case RequestIMEToCommitCompositionResult::eHandledAsynchronously:
|
|
|
|
return "Commit request is handled but IME doesn't commit current "
|
|
|
|
"composition synchronously";
|
|
|
|
case RequestIMEToCommitCompositionResult::eHandledSynchronously:
|
|
|
|
return "Commit reqeust is handled synchronously";
|
|
|
|
default:
|
|
|
|
return "Unknown reason";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsTArray<RequestIMEToCommitCompositionResult>
|
|
|
|
mRequestIMEToCommitCompositionResults;
|
2017-11-23 12:59:04 +03:00
|
|
|
#endif // MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
|
2019-04-10 00:38:15 +03:00
|
|
|
// mBrowserParent is owner of the instance.
|
|
|
|
dom::BrowserParent& MOZ_NON_OWNING_REF mBrowserParent;
|
2017-07-05 13:55:18 +03:00
|
|
|
// mCompositionString is composition string which were sent to the remote
|
|
|
|
// process but not yet committed in the remote process.
|
|
|
|
nsString mCompositionString;
|
2015-12-11 09:15:58 +03:00
|
|
|
// This is not nullptr only while the instance is requesting IME to
|
|
|
|
// composition. Then, data value of dispatched composition events should
|
|
|
|
// be stored into the instance.
|
|
|
|
nsAString* mCommitStringByRequest;
|
2015-07-11 04:53:55 +03:00
|
|
|
// mPendingEventsNeedingAck is increased before sending a composition event or
|
|
|
|
// a selection event and decreased after they are received in the child
|
|
|
|
// process.
|
|
|
|
uint32_t mPendingEventsNeedingAck;
|
2016-10-12 15:52:01 +03:00
|
|
|
// mCompositionStartInChild stores current composition start offset in the
|
|
|
|
// remote process.
|
2020-11-23 12:29:34 +03:00
|
|
|
Maybe<uint32_t> mCompositionStartInChild;
|
2017-06-29 12:31:09 +03:00
|
|
|
// mPendingCommitLength is commit string length of the first pending
|
|
|
|
// composition. This is used by relative offset query events when querying
|
|
|
|
// new composition start offset.
|
|
|
|
// Note that when mPendingCompositionCount is not 0, i.e., there are 2 or
|
|
|
|
// more pending compositions, this cache won't be used because in such case,
|
|
|
|
// anyway ContentCacheInParent cannot return proper character rect.
|
|
|
|
uint32_t mPendingCommitLength;
|
2016-10-12 11:09:02 +03:00
|
|
|
// mPendingCompositionCount is number of compositions which started in widget
|
|
|
|
// but not yet handled in the child process.
|
|
|
|
uint8_t mPendingCompositionCount;
|
2017-12-06 09:07:41 +03:00
|
|
|
// mPendingCommitCount is number of eCompositionCommit(AsIs) events which
|
|
|
|
// were sent to the child process but not yet handled in it.
|
|
|
|
uint8_t mPendingCommitCount;
|
2016-10-12 10:42:28 +03:00
|
|
|
// mWidgetHasComposition is true when the widget in this process thinks that
|
|
|
|
// IME has composition. So, this is set to true when eCompositionStart is
|
|
|
|
// dispatched and set to false when eCompositionCommit(AsIs) is dispatched.
|
|
|
|
bool mWidgetHasComposition;
|
2017-12-06 09:07:41 +03:00
|
|
|
// mIsChildIgnoringCompositionEvents is set to true if the child process
|
|
|
|
// requests commit composition whose commit has already been sent to it.
|
|
|
|
// Then, set to false when the child process ignores the commit event.
|
|
|
|
bool mIsChildIgnoringCompositionEvents;
|
2015-06-05 12:28:20 +03:00
|
|
|
|
2017-07-05 18:47:40 +03:00
|
|
|
ContentCacheInParent() = delete;
|
|
|
|
|
2016-06-22 08:16:59 +03:00
|
|
|
/**
|
|
|
|
* When following methods' aRoundToExistingOffset is true, even if specified
|
|
|
|
* offset or range is out of bounds, the result is computed with the existing
|
|
|
|
* cache forcibly.
|
|
|
|
*/
|
|
|
|
bool GetCaretRect(uint32_t aOffset, bool aRoundToExistingOffset,
|
|
|
|
LayoutDeviceIntRect& aCaretRect) const;
|
2015-06-05 12:28:20 +03:00
|
|
|
bool GetTextRect(uint32_t aOffset, bool aRoundToExistingOffset,
|
|
|
|
LayoutDeviceIntRect& aTextRect) const;
|
|
|
|
bool GetUnionTextRects(uint32_t aOffset, uint32_t aLength,
|
2016-06-22 08:16:59 +03:00
|
|
|
bool aRoundToExistingOffset,
|
2015-06-05 12:28:20 +03:00
|
|
|
LayoutDeviceIntRect& aUnionTextRect) const;
|
|
|
|
|
2015-07-11 04:53:55 +03:00
|
|
|
void FlushPendingNotifications(nsIWidget* aWidget);
|
2017-10-12 20:50:47 +03:00
|
|
|
|
2017-11-23 12:59:04 +03:00
|
|
|
#if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2017-10-12 20:50:47 +03:00
|
|
|
/**
|
|
|
|
* Remove unnecessary messages from mDispatchedEventMessages and
|
|
|
|
* mReceivedEventMessages.
|
|
|
|
*/
|
|
|
|
void RemoveUnnecessaryEventMessageLog();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append event message log to aLog.
|
|
|
|
*/
|
|
|
|
void AppendEventMessageLog(nsACString& aLog) const;
|
2017-11-23 12:59:04 +03:00
|
|
|
#endif // #if MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
2015-06-05 12:28:18 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_ContentCache_h
|