Bug 1166436 part.9 PuppetWidget should have mozilla::ContentCache and send it to TabParent r=m_kato

This commit is contained in:
Masayuki Nakano 2015-06-05 18:28:20 +09:00
parent 9ed6a67057
commit 6b1468139e
7 changed files with 246 additions and 200 deletions

View File

@ -41,6 +41,7 @@ using struct nsIMEUpdatePreference from "nsIWidget.h";
using mozilla::gfx::IntSize from "mozilla/gfx/Point.h";
using mozilla::gfx::IntPoint from "mozilla/gfx/Point.h";
using mozilla::gfx::IntRect from "mozilla/gfx/Rect.h";
using class mozilla::ContentCache from "ipc/nsGUIEventIPC.h";
using class mozilla::WidgetKeyboardEvent from "ipc/nsGUIEventIPC.h";
using class mozilla::WidgetMouseEvent from "ipc/nsGUIEventIPC.h";
using class mozilla::WidgetWheelEvent from "ipc/nsGUIEventIPC.h";
@ -171,9 +172,10 @@ parent:
*
* focus PR_TRUE if editable object is receiving focus
* PR_FALSE if losing focus
* contentCache Cache of content
* preference Native widget preference for IME updates
*/
prio(urgent) sync NotifyIMEFocus(bool focus)
prio(urgent) sync NotifyIMEFocus(bool focus, ContentCache contentCache)
returns (nsIMEUpdatePreference preference);
/**
@ -181,6 +183,7 @@ parent:
* One call can encompass both a delete and an insert operation
* Only called when NotifyIMEFocus returns PR_TRUE for mWantUpdates
*
* contentCache Cache of content
* offset Starting offset of the change
* end Ending offset of the range deleted
* newEnd New ending offset after insertion
@ -189,43 +192,34 @@ parent:
* for insertion, offset == end
* for deletion, offset == newEnd
*/
prio(urgent) async NotifyIMETextChange(uint32_t offset, uint32_t end,
prio(urgent) async NotifyIMETextChange(ContentCache contentCache,
uint32_t offset, uint32_t end,
uint32_t newEnd,
bool causedByComposition);
/**
* Notifies chrome that there is a IME compostion rect updated
*
* offset The starting offset of this rect
* rect The rect of first character of selected IME composition
* caretOffset The offset of caret position
* caretRect The rect of IME caret
* contentCache Cache of content
*/
prio(urgent) async NotifyIMESelectedCompositionRect(uint32_t offset,
LayoutDeviceIntRect[] rect,
uint32_t caretOffset,
LayoutDeviceIntRect caretRect);
prio(urgent) async NotifyIMESelectedCompositionRect(ContentCache contentCache);
/**
* Notifies chrome that there has been a change in selection
* Only called when NotifyIMEFocus returns PR_TRUE for mWantUpdates
*
* anchor Offset where the selection started
* focus Offset where the caret is
* writingMode CSS writing-mode in effect at the focus
* contentCache Cache of content
* causedByComposition true if the change is caused by composition
*/
prio(urgent) async NotifyIMESelection(uint32_t anchor,
uint32_t focus,
WritingMode writingMode,
prio(urgent) async NotifyIMESelection(ContentCache contentCache,
bool causedByComposition);
/**
* Notifies chrome to refresh its text cache
*
* text The entire content of the text field
* contentCache Cache of content
*/
prio(urgent) async NotifyIMETextHint(nsString text);
prio(urgent) async NotifyIMETextHint(ContentCache contentCache);
/**
* Notifies IME of mouse button event on a character in focused editor.
@ -238,19 +232,16 @@ parent:
/**
* Notifies chrome to currect editor rect
*
* rect Rect of current focused editor
* contentCache Cache of content
*/
prio(urgent) async NotifyIMEEditorRect(LayoutDeviceIntRect rect);
prio(urgent) async NotifyIMEEditorRect(ContentCache contentCache);
/**
* Notifies chrome to position change
*
* editorRect Rect of current focused editor
* compositionRects Rects of current composition string
* contentCache Cache of content
*/
prio(urgent) async NotifyIMEPositionChange(LayoutDeviceIntRect editorRect,
LayoutDeviceIntRect[] compositionRects,
LayoutDeviceIntRect caretRect);
prio(urgent) async NotifyIMEPositionChange(ContentCache contentCache);
/**
* Instructs chrome to end any pending composition

View File

@ -1881,6 +1881,7 @@ TabParent::RecvHideTooltip()
bool
TabParent::RecvNotifyIMEFocus(const bool& aFocus,
const ContentCache& aContentCache,
nsIMEUpdatePreference* aPreference)
{
nsCOMPtr<nsIWidget> widget = GetWidget();
@ -1890,20 +1891,19 @@ TabParent::RecvNotifyIMEFocus(const bool& aFocus,
}
mIMETabParent = aFocus ? this : nullptr;
mContentCache.SetSelection(0, mContentCache.SelectionWritingMode());
mContentCache.AssignContent(aContentCache);
widget->NotifyIME(IMENotification(aFocus ? NOTIFY_IME_OF_FOCUS :
NOTIFY_IME_OF_BLUR));
if (aFocus) {
*aPreference = widget->GetIMEUpdatePreference();
} else {
mContentCache.Clear();
}
return true;
}
bool
TabParent::RecvNotifyIMETextChange(const uint32_t& aStart,
TabParent::RecvNotifyIMETextChange(const ContentCache& aContentCache,
const uint32_t& aStart,
const uint32_t& aEnd,
const uint32_t& aNewEnd,
const bool& aCausedByComposition)
@ -1921,6 +1921,8 @@ TabParent::RecvNotifyIMETextChange(const uint32_t& aStart,
"The widget doesn't want text change notification caused by composition");
#endif
mContentCache.AssignContent(aContentCache);
IMENotification notification(NOTIFY_IME_OF_TEXT_CHANGE);
notification.mTextChangeData.mStartOffset = aStart;
notification.mTextChangeData.mOldEndOffset = aEnd;
@ -1932,37 +1934,29 @@ TabParent::RecvNotifyIMETextChange(const uint32_t& aStart,
bool
TabParent::RecvNotifyIMESelectedCompositionRect(
const uint32_t& aOffset,
InfallibleTArray<LayoutDeviceIntRect>&& aRects,
const uint32_t& aCaretOffset,
const LayoutDeviceIntRect& aCaretRect)
const ContentCache& aContentCache)
{
if (!mContentCache.InitTextRectArray(aOffset, aRects)) {
NS_WARNING("Failed to set text rect array");
}
if (!mContentCache.InitCaretRect(aCaretOffset, aCaretRect)) {
NS_WARNING("Failed to set caret rect");
}
nsCOMPtr<nsIWidget> widget = GetWidget();
if (!widget) {
return true;
}
mContentCache.AssignContent(aContentCache);
widget->NotifyIME(IMENotification(NOTIFY_IME_OF_COMPOSITION_UPDATE));
return true;
}
bool
TabParent::RecvNotifyIMESelection(const uint32_t& aAnchor,
const uint32_t& aFocus,
const mozilla::WritingMode& aWritingMode,
TabParent::RecvNotifyIMESelection(const ContentCache& aContentCache,
const bool& aCausedByComposition)
{
nsCOMPtr<nsIWidget> widget = GetWidget();
if (!widget)
return true;
mContentCache.SetSelection(aAnchor, aFocus, aWritingMode);
mContentCache.AssignContent(aContentCache);
const nsIMEUpdatePreference updatePreference =
widget->GetIMEUpdatePreference();
if (updatePreference.WantSelectionChange() &&
@ -1973,7 +1967,8 @@ TabParent::RecvNotifyIMESelection(const uint32_t& aAnchor,
notification.mSelectionChangeData.mLength = mContentCache.SelectionLength();
notification.mSelectionChangeData.mReversed =
mContentCache.SelectionReversed();
notification.mSelectionChangeData.SetWritingMode(aWritingMode);
notification.mSelectionChangeData.SetWritingMode(
mContentCache.SelectionWritingMode());
notification.mSelectionChangeData.mCausedByComposition =
aCausedByComposition;
widget->NotifyIME(notification);
@ -1982,9 +1977,9 @@ TabParent::RecvNotifyIMESelection(const uint32_t& aAnchor,
}
bool
TabParent::RecvNotifyIMETextHint(const nsString& aText)
TabParent::RecvNotifyIMETextHint(const ContentCache& aContentCache)
{
mContentCache.SetText(aText);
mContentCache.AssignContent(aContentCache);
return true;
}
@ -2005,27 +2000,22 @@ TabParent::RecvNotifyIMEMouseButtonEvent(
}
bool
TabParent::RecvNotifyIMEEditorRect(const LayoutDeviceIntRect& aRect)
TabParent::RecvNotifyIMEEditorRect(const ContentCache& aContentCache)
{
mContentCache.SetEditorRect(aRect);
mContentCache.AssignContent(aContentCache);
return true;
}
bool
TabParent::RecvNotifyIMEPositionChange(
const LayoutDeviceIntRect& aEditorRect,
InfallibleTArray<LayoutDeviceIntRect>&& aCompositionRects,
const LayoutDeviceIntRect& aCaretRect)
TabParent::RecvNotifyIMEPositionChange(const ContentCache& aContentCache)
{
mContentCache.SetEditorRect(aEditorRect);
mContentCache.UpdateTextRectArray(aCompositionRects);
mContentCache.UpdateCaretRect(aCaretRect);
nsCOMPtr<nsIWidget> widget = GetWidget();
if (!widget) {
return true;
}
mContentCache.AssignContent(aContentCache);
const nsIMEUpdatePreference updatePreference =
widget->GetIMEUpdatePreference();
if (updatePreference.WantPositionChanged()) {

View File

@ -161,29 +161,22 @@ public:
InfallibleTArray<CpowEntry>&& aCpows,
const IPC::Principal& aPrincipal) override;
virtual bool RecvNotifyIMEFocus(const bool& aFocus,
const ContentCache& aContentCache,
nsIMEUpdatePreference* aPreference)
override;
virtual bool RecvNotifyIMETextChange(const uint32_t& aStart,
virtual bool RecvNotifyIMETextChange(const ContentCache& aContentCache,
const uint32_t& aStart,
const uint32_t& aEnd,
const uint32_t& aNewEnd,
const bool& aCausedByComposition) override;
virtual bool RecvNotifyIMESelectedCompositionRect(
const uint32_t& aOffset,
InfallibleTArray<LayoutDeviceIntRect>&& aRects,
const uint32_t& aCaretOffset,
const LayoutDeviceIntRect& aCaretRect) override;
virtual bool RecvNotifyIMESelection(const uint32_t& aAnchor,
const uint32_t& aFocus,
const mozilla::WritingMode& aWritingMode,
virtual bool RecvNotifyIMESelectedCompositionRect(const ContentCache& aContentCache) override;
virtual bool RecvNotifyIMESelection(const ContentCache& aContentCache,
const bool& aCausedByComposition) override;
virtual bool RecvNotifyIMETextHint(const nsString& aText) override;
virtual bool RecvNotifyIMETextHint(const ContentCache& aContentCache) override;
virtual bool RecvNotifyIMEMouseButtonEvent(const widget::IMENotification& aEventMessage,
bool* aConsumedByIME) override;
virtual bool RecvNotifyIMEEditorRect(const LayoutDeviceIntRect& aRect) override;
virtual bool RecvNotifyIMEPositionChange(
const LayoutDeviceIntRect& aEditorRect,
InfallibleTArray<LayoutDeviceIntRect>&& aCompositionRects,
const LayoutDeviceIntRect& aCaretRect) override;
virtual bool RecvNotifyIMEEditorRect(const ContentCache& aContentCache) override;
virtual bool RecvNotifyIMEPositionChange(const ContentCache& aContentCache) override;
virtual bool RecvEndIMEComposition(const bool& aCancel,
bool* aNoCompositionEvent,
nsString* aComposition) override;

View File

@ -6,8 +6,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/ContentCache.h"
#include "mozilla/IMEStateManager.h"
#include "mozilla/TextComposition.h"
#include "mozilla/TextEvents.h"
#include "nsIWidget.h"
#include "nsRefPtr.h"
namespace mozilla {
@ -105,12 +108,140 @@ ContentCache::HandleQueryContentEvent(WidgetQueryContentEvent& aEvent,
return true;
}
bool
ContentCache::CacheAll(nsIWidget* aWidget)
{
if (NS_WARN_IF(!CacheText(aWidget)) ||
NS_WARN_IF(!CacheSelection(aWidget)) ||
NS_WARN_IF(!CacheTextRects(aWidget)) ||
NS_WARN_IF(!CacheEditorRect(aWidget))) {
return false;
}
return true;
}
bool
ContentCache::CacheSelection(nsIWidget* aWidget)
{
mCaret.Clear();
mSelection.Clear();
nsEventStatus status = nsEventStatus_eIgnore;
WidgetQueryContentEvent selection(true, NS_QUERY_SELECTED_TEXT, aWidget);
aWidget->DispatchEvent(&selection, status);
if (NS_WARN_IF(!selection.mSucceeded)) {
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();
nsRefPtr<TextComposition> textComposition =
IMEStateManager::GetTextCompositionFor(aWidget);
if (textComposition) {
mCaret.mOffset = textComposition->OffsetOfTargetClause();
} else {
mCaret.mOffset = selection.mReply.mOffset;
}
status = nsEventStatus_eIgnore;
WidgetQueryContentEvent caretRect(true, NS_QUERY_CARET_RECT, aWidget);
caretRect.InitForQueryCaretRect(mCaret.mOffset);
aWidget->DispatchEvent(&caretRect, status);
if (NS_WARN_IF(!caretRect.mSucceeded)) {
mCaret.Clear();
return false;
}
mCaret.mRect = caretRect.mReply.mRect;
return true;
}
bool
ContentCache::CacheEditorRect(nsIWidget* aWidget)
{
nsEventStatus status = nsEventStatus_eIgnore;
WidgetQueryContentEvent editorRectEvent(true, NS_QUERY_EDITOR_RECT, aWidget);
aWidget->DispatchEvent(&editorRectEvent, status);
if (NS_WARN_IF(!editorRectEvent.mSucceeded)) {
return false;
}
mEditorRect = editorRectEvent.mReply.mRect;
return true;
}
bool
ContentCache::CacheText(nsIWidget* aWidget)
{
nsEventStatus status = nsEventStatus_eIgnore;
WidgetQueryContentEvent queryText(true, NS_QUERY_TEXT_CONTENT, aWidget);
queryText.InitForQueryTextContent(0, UINT32_MAX);
aWidget->DispatchEvent(&queryText, status);
if (NS_WARN_IF(!queryText.mSucceeded)) {
SetText(EmptyString());
return false;
}
SetText(queryText.mReply.mString);
return true;
}
bool
ContentCache::CacheTextRects(nsIWidget* aWidget)
{
mTextRectArray.Clear();
nsRefPtr<TextComposition> textComposition =
IMEStateManager::GetTextCompositionFor(aWidget);
if (NS_WARN_IF(!textComposition)) {
return true;
}
nsEventStatus status = nsEventStatus_eIgnore;
mTextRectArray.mRects.SetCapacity(textComposition->String().Length());
mTextRectArray.mStart = textComposition->NativeOffsetOfStartComposition();
uint32_t endOffset =
mTextRectArray.mStart + textComposition->String().Length();
for (uint32_t i = mTextRectArray.mStart; i < endOffset; i++) {
WidgetQueryContentEvent textRect(true, NS_QUERY_TEXT_RECT, aWidget);
textRect.InitForQueryTextRect(i, 1);
aWidget->DispatchEvent(&textRect, status);
if (NS_WARN_IF(!textRect.mSucceeded)) {
mTextRectArray.Clear();
return false;
}
mTextRectArray.mRects.AppendElement(textRect.mReply.mRect);
}
return true;
}
void
ContentCache::SetText(const nsAString& aText)
{
mText = aText;
}
void
ContentCache::SetSelection(uint32_t aStartOffset,
uint32_t aLength,
bool aReversed,
const WritingMode& aWritingMode)
{
if (!aReversed) {
mSelection.mAnchor = aStartOffset;
mSelection.mFocus = aStartOffset + aLength;
} else {
mSelection.mAnchor = aStartOffset + aLength;
mSelection.mFocus = aStartOffset;
}
mSelection.mWritingMode = aWritingMode;
}
void
ContentCache::SetSelection(uint32_t aAnchorOffset,
uint32_t aFocusOffset,

View File

@ -74,6 +74,16 @@ public:
bool HandleQueryContentEvent(WidgetQueryContentEvent& aEvent,
nsIWidget* aWidget) const;
/**
* Cache*() retrieves the latest content information and store them.
*/
bool CacheEditorRect(nsIWidget* aWidget);
bool CacheSelection(nsIWidget* aWidget);
bool CacheText(nsIWidget* aWidget);
bool CacheTextRects(nsIWidget* aWidget);
bool CacheAll(nsIWidget* aWidget);
void SetText(const nsAString& aText);
const nsString& Text() const { return mText; }
uint32_t TextLength() const { return mText.Length(); }
@ -105,6 +115,10 @@ public:
{
SetSelection(aCaretOffset, aCaretOffset, aWritingMode);
}
void SetSelection(uint32_t aStartOffset,
uint32_t aLength,
bool aReversed,
const WritingMode& aWritingMode);
void SetSelection(uint32_t aAnchorOffset,
uint32_t aFocusOffset,
const WritingMode& aWritingMode);
@ -175,6 +189,12 @@ private:
{
}
void Clear()
{
mAnchor = mFocus = 0;
mWritingMode = WritingMode();
}
bool Collapsed() const { return mFocus == mAnchor; }
bool Reversed() const { return mFocus < mAnchor; }
uint32_t StartOffset() const { return Reversed() ? mFocus : mAnchor; }
@ -195,6 +215,12 @@ private:
{
}
void Clear()
{
mOffset = UINT32_MAX;
mRect.SetEmpty();
}
uint32_t Offset() const
{
NS_WARN_IF(mOffset == UINT32_MAX);
@ -212,6 +238,12 @@ private:
{
}
void Clear()
{
mStart = UINT32_MAX;
mRects.Clear();
}
uint32_t StartOffset() const
{
NS_WARN_IF(mStart == UINT32_MAX);

View File

@ -137,7 +137,9 @@ PuppetWidget::InitIMEState()
{
MOZ_ASSERT(mTabChild);
if (mNeedIMEStateInit) {
mTabChild->SendNotifyIMEFocus(false, &mIMEPreferenceOfParent);
mContentCache.Clear();
mTabChild->SendNotifyIMEFocus(false, mContentCache,
&mIMEPreferenceOfParent);
mNeedIMEStateInit = false;
}
}
@ -672,23 +674,21 @@ PuppetWidget::NotifyIMEOfFocusChange(bool aFocus)
return NS_ERROR_FAILURE;
if (aFocus) {
nsEventStatus status;
WidgetQueryContentEvent queryEvent(true, NS_QUERY_TEXT_CONTENT, this);
InitEvent(queryEvent, nullptr);
// Query entire content
queryEvent.InitForQueryTextContent(0, UINT32_MAX);
DispatchEvent(&queryEvent, status);
if (queryEvent.mSucceeded) {
mTabChild->SendNotifyIMETextHint(queryEvent.mReply.mString);
if (NS_WARN_IF(!mContentCache.CacheText(this))) {
return NS_ERROR_FAILURE;
}
mTabChild->SendNotifyIMETextHint(mContentCache);
} else {
mContentCache.Clear();
}
mIMEPreferenceOfParent = nsIMEUpdatePreference();
if (!mTabChild->SendNotifyIMEFocus(aFocus, &mIMEPreferenceOfParent)) {
if (!mTabChild->SendNotifyIMEFocus(aFocus, mContentCache,
&mIMEPreferenceOfParent)) {
return NS_ERROR_FAILURE;
}
// TODO: Optimize this later.
if (aFocus) {
IMENotification notification(NOTIFY_IME_OF_SELECTION_CHANGE);
notification.mSelectionChangeData.mCausedByComposition = false;
@ -707,77 +707,14 @@ PuppetWidget::NotifyIMEOfUpdateComposition()
NS_ENSURE_TRUE(mTabChild, NS_ERROR_FAILURE);
uint32_t startOffset;
uint32_t targetCauseOffset;
nsAutoTArray<LayoutDeviceIntRect, 16> textRectArray;
if (!GetCompositionRects(startOffset,
textRectArray,
targetCauseOffset)) {
if (NS_WARN_IF(!mContentCache.CacheTextRects(this)) ||
NS_WARN_IF(!mContentCache.CacheSelection(this))) {
return NS_ERROR_FAILURE;
}
LayoutDeviceIntRect caretRect;
GetCaretRect(caretRect, targetCauseOffset);
mTabChild->SendNotifyIMESelectedCompositionRect(startOffset,
textRectArray,
targetCauseOffset,
caretRect);
mTabChild->SendNotifyIMESelectedCompositionRect(mContentCache);
return NS_OK;
}
bool
PuppetWidget::GetCompositionRects(uint32_t& aStartOffset,
nsTArray<LayoutDeviceIntRect>& aTextRectArray,
uint32_t& aTargetCauseOffset)
{
nsRefPtr<TextComposition> textComposition =
IMEStateManager::GetTextCompositionFor(this);
NS_ENSURE_TRUE(textComposition, false);
nsEventStatus status;
aTextRectArray.SetCapacity(textComposition->String().Length());
aStartOffset = textComposition->NativeOffsetOfStartComposition();
aTargetCauseOffset = textComposition->OffsetOfTargetClause();
uint32_t endOffset = textComposition->String().Length() + aStartOffset;
for (uint32_t i = aStartOffset; i < endOffset; i++) {
WidgetQueryContentEvent textRect(true, NS_QUERY_TEXT_RECT, this);
InitEvent(textRect, nullptr);
textRect.InitForQueryTextRect(i, 1);
DispatchEvent(&textRect, status);
NS_ENSURE_TRUE(textRect.mSucceeded, false);
aTextRectArray.AppendElement(textRect.mReply.mRect);
}
return true;
}
uint32_t
PuppetWidget::GetCaretOffset()
{
nsEventStatus status;
WidgetQueryContentEvent selection(true, NS_QUERY_SELECTED_TEXT, this);
InitEvent(selection, nullptr);
DispatchEvent(&selection, status);
NS_ENSURE_TRUE(selection.mSucceeded, 0);
return selection.mReply.mOffset;
}
bool
PuppetWidget::GetCaretRect(LayoutDeviceIntRect& aCaretRect, uint32_t aCaretOffset)
{
nsEventStatus status;
WidgetQueryContentEvent caretRect(true, NS_QUERY_CARET_RECT, this);
InitEvent(caretRect, nullptr);
caretRect.InitForQueryCaretRect(aCaretOffset);
DispatchEvent(&caretRect, status);
NS_ENSURE_TRUE(caretRect.mSucceeded, false);
aCaretRect = caretRect.mReply.mRect;
return true;
}
nsresult
PuppetWidget::NotifyIMEOfEditorRect()
{
@ -788,29 +725,13 @@ PuppetWidget::NotifyIMEOfEditorRect()
return NS_ERROR_FAILURE;
}
LayoutDeviceIntRect rect;
if (!GetEditorRect(rect)) {
if (NS_WARN_IF(!mContentCache.CacheEditorRect(this))) {
return NS_ERROR_FAILURE;
}
mTabChild->SendNotifyIMEEditorRect(rect);
mTabChild->SendNotifyIMEEditorRect(mContentCache);
return NS_OK;
}
bool
PuppetWidget::GetEditorRect(LayoutDeviceIntRect& aRect)
{
nsEventStatus status;
WidgetQueryContentEvent editorRectEvent(true, NS_QUERY_EDITOR_RECT, this);
InitEvent(editorRectEvent);
DispatchEvent(&editorRectEvent, status);
if (NS_WARN_IF(!editorRectEvent.mSucceeded)) {
return false;
}
aRect = editorRectEvent.mReply.mRect;
return true;
}
nsIMEUpdatePreference
PuppetWidget::GetIMEUpdatePreference()
{
@ -839,15 +760,10 @@ PuppetWidget::NotifyIMEOfTextChange(const IMENotification& aIMENotification)
if (!mTabChild)
return NS_ERROR_FAILURE;
nsEventStatus status;
WidgetQueryContentEvent queryEvent(true, NS_QUERY_TEXT_CONTENT, this);
InitEvent(queryEvent, nullptr);
queryEvent.InitForQueryTextContent(0, UINT32_MAX);
DispatchEvent(&queryEvent, status);
if (queryEvent.mSucceeded) {
mTabChild->SendNotifyIMETextHint(queryEvent.mReply.mString);
if (NS_WARN_IF(!mContentCache.CacheText(this))) {
return NS_ERROR_FAILURE;
}
mTabChild->SendNotifyIMETextHint(mContentCache);
// TabParent doesn't this this to cache. we don't send the notification
// if parent process doesn't request NOTIFY_TEXT_CHANGE.
@ -855,6 +771,7 @@ PuppetWidget::NotifyIMEOfTextChange(const IMENotification& aIMENotification)
(mIMEPreferenceOfParent.WantChangesCausedByComposition() ||
!aIMENotification.mTextChangeData.mCausedByComposition)) {
mTabChild->SendNotifyIMETextChange(
mContentCache,
aIMENotification.mTextChangeData.mStartOffset,
aIMENotification.mTextChangeData.mOldEndOffset,
aIMENotification.mTextChangeData.mNewEndOffset,
@ -877,11 +794,14 @@ PuppetWidget::NotifyIMEOfSelectionChange(
if (!mTabChild)
return NS_ERROR_FAILURE;
mContentCache.SetSelection(
aIMENotification.mSelectionChangeData.mOffset,
aIMENotification.mSelectionChangeData.mLength,
aIMENotification.mSelectionChangeData.mReversed,
aIMENotification.mSelectionChangeData.GetWritingMode());
mTabChild->SendNotifyIMESelection(
aIMENotification.mSelectionChangeData.StartOffset(),
aIMENotification.mSelectionChangeData.EndOffset(),
aIMENotification.mSelectionChangeData.GetWritingMode(),
aIMENotification.mSelectionChangeData.mCausedByComposition);
mContentCache, aIMENotification.mSelectionChangeData.mCausedByComposition);
return NS_OK;
}
@ -912,25 +832,12 @@ PuppetWidget::NotifyIMEOfPositionChange()
return NS_ERROR_FAILURE;
}
LayoutDeviceIntRect editorRect;
if (!GetEditorRect(editorRect)) {
if (NS_WARN_IF(!mContentCache.CacheEditorRect(this)) ||
NS_WARN_IF(!mContentCache.CacheTextRects(this)) ||
NS_WARN_IF(!mContentCache.CacheSelection(this))) {
return NS_ERROR_FAILURE;
}
uint32_t startOffset;
uint32_t targetCauseOffset;
nsAutoTArray<LayoutDeviceIntRect, 16> textRectArray;
if (!GetCompositionRects(startOffset,
textRectArray,
targetCauseOffset)) {
// no composition string, get caret offset by NS_QUERY_SELECTED_TEXT
targetCauseOffset = GetCaretOffset();
}
LayoutDeviceIntRect caretRect;
GetCaretRect(caretRect, targetCauseOffset);
if (!mTabChild->SendNotifyIMEPositionChange(editorRect, textRectArray,
caretRect)) {
if (!mTabChild->SendNotifyIMEPositionChange(mContentCache)) {
return NS_ERROR_FAILURE;
}
return NS_OK;

View File

@ -22,6 +22,7 @@
#include "nsIScreenManager.h"
#include "nsThreadUtils.h"
#include "mozilla/Attributes.h"
#include "mozilla/ContentCache.h"
#include "mozilla/EventForwards.h"
namespace mozilla {
@ -264,10 +265,10 @@ private:
nsresult NotifyIMEOfEditorRect();
nsresult NotifyIMEOfPositionChange();
bool GetEditorRect(mozilla::LayoutDeviceIntRect& aEditorRect);
bool GetCompositionRects(uint32_t& aStartOffset,
nsTArray<mozilla::LayoutDeviceIntRect>& aRectArray,
uint32_t& aTargetCauseOffset);
bool CacheEditorRect();
bool CacheCompositionRects(uint32_t& aStartOffset,
nsTArray<mozilla::LayoutDeviceIntRect>& aRectArray,
uint32_t& aTargetCauseOffset);
bool GetCaretRect(mozilla::LayoutDeviceIntRect& aCaretRect, uint32_t aCaretOffset);
uint32_t GetCaretOffset();
@ -310,6 +311,7 @@ private:
mozilla::RefPtr<DrawTarget> mDrawTarget;
// IME
nsIMEUpdatePreference mIMEPreferenceOfParent;
ContentCache mContentCache;
bool mNeedIMEStateInit;
// The DPI of the screen corresponding to this widget