2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-03-08 05:20:07 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
#include "mozilla/Logging.h"
|
|
|
|
|
2014-03-11 09:08:02 +04:00
|
|
|
#include "ContentEventHandler.h"
|
2014-03-08 05:20:07 +04:00
|
|
|
#include "IMEContentObserver.h"
|
2014-03-17 10:56:54 +04:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2014-08-13 15:25:14 +04:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2014-04-24 04:36:15 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-03-08 05:20:07 +04:00
|
|
|
#include "mozilla/IMEStateManager.h"
|
2014-08-29 14:08:43 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2014-04-03 08:18:37 +04:00
|
|
|
#include "mozilla/TextComposition.h"
|
2014-08-29 14:08:43 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2014-03-08 05:20:07 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMRange.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsISelectionController.h"
|
|
|
|
#include "nsISelectionPrivate.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsWeakReference.h"
|
2015-05-15 04:18:08 +03:00
|
|
|
#include "WritingModes.h"
|
2014-03-08 05:20:07 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace widget;
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
PRLogModuleInfo* sIMECOLog = nullptr;
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
ToChar(bool aBool)
|
|
|
|
{
|
|
|
|
return aBool ? "true" : "false";
|
|
|
|
}
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
static const char*
|
|
|
|
ToChar(EventMessage aEventMessage)
|
|
|
|
{
|
|
|
|
switch (aEventMessage) {
|
2015-09-10 04:40:05 +03:00
|
|
|
case eQuerySelectedText:
|
|
|
|
return "eQuerySelectedText";
|
2015-09-10 04:40:05 +03:00
|
|
|
case eQueryTextContent:
|
|
|
|
return "eQueryTextContent";
|
2015-09-10 04:40:06 +03:00
|
|
|
case eQueryCaretRect:
|
|
|
|
return "eQueryCaretRect";
|
2015-09-11 15:21:26 +03:00
|
|
|
case eQueryTextRect:
|
|
|
|
return "eQueryTextRect";
|
2015-09-10 04:40:06 +03:00
|
|
|
case eQueryEditorRect:
|
|
|
|
return "eQueryEditorRect";
|
2015-09-10 04:40:06 +03:00
|
|
|
case eQueryContentState:
|
|
|
|
return "eQueryContentState";
|
2015-09-10 04:40:05 +03:00
|
|
|
case eQuerySelectionAsTransferable:
|
|
|
|
return "eQuerySelectionAsTransferable";
|
2015-09-10 04:40:06 +03:00
|
|
|
case eQueryCharacterAtPoint:
|
|
|
|
return "eQueryCharacterAtPoint";
|
2015-09-10 04:40:06 +03:00
|
|
|
case eQueryDOMWidgetHittest:
|
|
|
|
return "eQueryDOMWidgetHittest";
|
2015-09-08 06:54:14 +03:00
|
|
|
default:
|
2015-09-10 04:40:06 +03:00
|
|
|
return "Unsupported message";
|
2015-09-08 06:54:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
static const char*
|
|
|
|
ToChar(IMEMessage aIMEMessage)
|
|
|
|
{
|
|
|
|
switch (aIMEMessage) {
|
|
|
|
case NOTIFY_IME_OF_NOTHING:
|
|
|
|
return "NOTIFY_IME_OF_NOTHING";
|
|
|
|
case NOTIFY_IME_OF_FOCUS:
|
|
|
|
return "NOTIFY_IME_OF_FOCUS";
|
|
|
|
case NOTIFY_IME_OF_BLUR:
|
|
|
|
return "NOTIFY_IME_OF_BLUR";
|
|
|
|
case NOTIFY_IME_OF_SELECTION_CHANGE:
|
|
|
|
return "NOTIFY_IME_OF_SELECTION_CHANGE";
|
|
|
|
case NOTIFY_IME_OF_TEXT_CHANGE:
|
|
|
|
return "NOTIFY_IME_OF_TEXT_CHANGE";
|
|
|
|
case NOTIFY_IME_OF_COMPOSITION_UPDATE:
|
|
|
|
return "NOTIFY_IME_OF_COMPOSITION_UPDATE";
|
|
|
|
case NOTIFY_IME_OF_POSITION_CHANGE:
|
|
|
|
return "NOTIFY_IME_OF_POSITION_CHANGE";
|
|
|
|
case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT:
|
|
|
|
return "NOTIFY_IME_OF_MOUSE_BUTTON_EVENT";
|
|
|
|
case REQUEST_TO_COMMIT_COMPOSITION:
|
|
|
|
return "REQUEST_TO_COMMIT_COMPOSITION";
|
|
|
|
case REQUEST_TO_CANCEL_COMPOSITION:
|
|
|
|
return "REQUEST_TO_CANCEL_COMPOSITION";
|
|
|
|
default:
|
|
|
|
return "Unexpected value";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
class WritingModeToString final : public nsAutoCString
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit WritingModeToString(const WritingMode& aWritingMode)
|
|
|
|
{
|
|
|
|
if (!aWritingMode.IsVertical()) {
|
|
|
|
AssignLiteral("Horizontal");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aWritingMode.IsVerticalLR()) {
|
|
|
|
AssignLiteral("Vertical (LR)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AssignLiteral("Vertical (RL)");
|
|
|
|
}
|
|
|
|
virtual ~WritingModeToString() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class SelectionChangeDataToString final : public nsAutoCString
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit SelectionChangeDataToString(
|
|
|
|
const IMENotification::SelectionChangeDataBase& aData)
|
|
|
|
{
|
|
|
|
if (!aData.IsValid()) {
|
|
|
|
AppendLiteral("{ IsValid()=false }");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AppendPrintf("{ mOffset=%u, ", aData.mOffset);
|
|
|
|
if (aData.mString->Length() > 20) {
|
|
|
|
AppendPrintf("mString.Length()=%u, ", aData.mString->Length());
|
|
|
|
} else {
|
|
|
|
AppendPrintf("mString=\"%s\" (Length()=%u), ",
|
|
|
|
NS_ConvertUTF16toUTF8(*aData.mString).get(),
|
|
|
|
aData.mString->Length());
|
|
|
|
}
|
|
|
|
AppendPrintf("GetWritingMode()=%s, mReversed=%s, mCausedByComposition=%s, "
|
|
|
|
"mCausedBySelectionEvent=%s }",
|
|
|
|
WritingModeToString(aData.GetWritingMode()).get(),
|
|
|
|
ToChar(aData.mReversed),
|
|
|
|
ToChar(aData.mCausedByComposition),
|
|
|
|
ToChar(aData.mCausedBySelectionEvent));
|
|
|
|
}
|
|
|
|
virtual ~SelectionChangeDataToString() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class TextChangeDataToString final : public nsAutoCString
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit TextChangeDataToString(
|
|
|
|
const IMENotification::TextChangeDataBase& aData)
|
|
|
|
{
|
|
|
|
if (!aData.IsValid()) {
|
|
|
|
AppendLiteral("{ IsValid()=false }");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AppendPrintf("{ mStartOffset=%u, mRemovedEndOffset=%u, mAddedEndOffset=%u, "
|
|
|
|
"mCausedByComposition=%s }", aData.mStartOffset,
|
|
|
|
aData.mRemovedEndOffset, aData.mAddedEndOffset,
|
|
|
|
ToChar(aData.mCausedByComposition));
|
|
|
|
}
|
|
|
|
virtual ~TextChangeDataToString() {}
|
|
|
|
};
|
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::IMEContentObserver
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-07-31 08:37:59 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IMEContentObserver)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IMEContentObserver)
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
|
2015-05-26 10:45:26 +03:00
|
|
|
tmp->NotifyIMEOfBlur();
|
2015-05-26 10:45:26 +03:00
|
|
|
tmp->UnregisterObservers();
|
2014-07-31 08:37:59 +04:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSelection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRootContent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEditableNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocShell)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEditor)
|
2014-07-31 08:38:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mEndOfAddedTextCache.mContainerNode)
|
2014-07-31 08:38:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mStartOfRemovingTextRangeCache.mContainerNode)
|
2014-07-31 08:37:59 +04:00
|
|
|
|
|
|
|
tmp->mUpdatePreference.mWantUpdates = nsIMEUpdatePreference::NOTIFY_NOTHING;
|
|
|
|
tmp->mESM = nullptr;
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(IMEContentObserver)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWidget)
|
2015-09-08 06:54:14 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFocusedWidget)
|
2014-07-31 08:37:59 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSelection)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRootContent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEditableNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocShell)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEditor)
|
2014-07-31 08:38:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEndOfAddedTextCache.mContainerNode)
|
2014-07-31 08:38:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(
|
|
|
|
mStartOfRemovingTextRangeCache.mContainerNode)
|
2014-07-31 08:37:59 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2014-04-24 04:36:14 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IMEContentObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISelectionListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIReflowObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScrollObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2014-07-31 08:37:59 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIEditorObserver)
|
2014-04-24 04:36:14 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISelectionListener)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(IMEContentObserver)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(IMEContentObserver)
|
2014-03-08 05:20:07 +04:00
|
|
|
|
|
|
|
IMEContentObserver::IMEContentObserver()
|
2014-04-24 04:36:15 +04:00
|
|
|
: mESM(nullptr)
|
2015-06-04 20:06:10 +03:00
|
|
|
, mSuppressNotifications(0)
|
2014-07-31 08:38:01 +04:00
|
|
|
, mPreCharacterDataChangeLength(-1)
|
2015-09-16 11:48:24 +03:00
|
|
|
, mSendingNotification(NOTIFY_IME_OF_NOTHING)
|
2015-05-26 10:45:26 +03:00
|
|
|
, mIsObserving(false)
|
2015-06-17 04:03:57 +03:00
|
|
|
, mIMEHasFocus(false)
|
|
|
|
, mIsFocusEventPending(false)
|
2015-09-16 11:48:23 +03:00
|
|
|
, mIsTextChangeEventPending(false)
|
2014-07-31 08:38:00 +04:00
|
|
|
, mIsSelectionChangeEventPending(false)
|
|
|
|
, mIsPositionChangeEventPending(false)
|
2014-08-13 15:25:14 +04:00
|
|
|
, mIsFlushingPendingNotifications(false)
|
2014-03-08 05:20:07 +04:00
|
|
|
{
|
2014-07-31 08:37:59 +04:00
|
|
|
#ifdef DEBUG
|
2015-07-11 04:53:56 +03:00
|
|
|
mTextChangeData.Test();
|
2014-07-31 08:37:59 +04:00
|
|
|
#endif
|
2015-09-08 06:54:14 +03:00
|
|
|
if (!sIMECOLog) {
|
|
|
|
sIMECOLog = PR_NewLogModule("IMEContentObserver");
|
|
|
|
}
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::Init(nsIWidget* aWidget,
|
|
|
|
nsPresContext* aPresContext,
|
2014-11-05 16:12:44 +03:00
|
|
|
nsIContent* aContent,
|
|
|
|
nsIEditor* aEditor)
|
2014-03-08 05:20:07 +04:00
|
|
|
{
|
2014-11-05 16:12:44 +03:00
|
|
|
MOZ_ASSERT(aEditor, "aEditor must not be null");
|
|
|
|
|
2015-05-26 10:45:26 +03:00
|
|
|
State state = GetState();
|
|
|
|
if (NS_WARN_IF(state == eState_Observing)) {
|
|
|
|
return; // Nothing to do.
|
|
|
|
}
|
|
|
|
|
|
|
|
bool firstInitialization = state != eState_StoppedObserving;
|
2015-05-26 10:45:26 +03:00
|
|
|
if (!firstInitialization) {
|
|
|
|
// If this is now trying to initialize with new contents, all observers
|
|
|
|
// should be registered again for simpler implementation.
|
|
|
|
UnregisterObservers();
|
|
|
|
// Clear members which may not be initialized again.
|
|
|
|
mRootContent = nullptr;
|
|
|
|
mEditor = nullptr;
|
|
|
|
mSelection = nullptr;
|
|
|
|
mDocShell = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-04-24 04:36:15 +04:00
|
|
|
mESM = aPresContext->EventStateManager();
|
|
|
|
mESM->OnStartToObserveContent(this);
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
mWidget = aWidget;
|
2015-05-26 10:45:26 +03:00
|
|
|
|
|
|
|
mEditableNode =
|
|
|
|
IMEStateManager::GetRootEditableNode(aPresContext, aContent);
|
2014-03-08 05:20:07 +04:00
|
|
|
if (!mEditableNode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-05 16:12:44 +03:00
|
|
|
mEditor = aEditor;
|
2014-07-31 08:37:59 +04:00
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
nsIPresShell* presShell = aPresContext->PresShell();
|
|
|
|
|
|
|
|
// get selection and root content
|
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
|
|
|
if (mEditableNode->IsNodeOfType(nsINode::eCONTENT)) {
|
|
|
|
nsIFrame* frame =
|
|
|
|
static_cast<nsIContent*>(mEditableNode.get())->GetPrimaryFrame();
|
|
|
|
NS_ENSURE_TRUE_VOID(frame);
|
|
|
|
|
|
|
|
frame->GetSelectionController(aPresContext,
|
|
|
|
getter_AddRefs(selCon));
|
|
|
|
} else {
|
|
|
|
// mEditableNode is a document
|
|
|
|
selCon = do_QueryInterface(presShell);
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE_VOID(selCon);
|
|
|
|
|
|
|
|
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
|
2014-03-08 05:20:07 +04:00
|
|
|
getter_AddRefs(mSelection));
|
|
|
|
NS_ENSURE_TRUE_VOID(mSelection);
|
2014-03-08 05:20:07 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMRange> selDomRange;
|
2014-03-08 05:20:07 +04:00
|
|
|
if (NS_SUCCEEDED(mSelection->GetRangeAt(0, getter_AddRefs(selDomRange)))) {
|
2014-03-08 05:20:07 +04:00
|
|
|
nsRange* selRange = static_cast<nsRange*>(selDomRange.get());
|
|
|
|
NS_ENSURE_TRUE_VOID(selRange && selRange->GetStartParent());
|
|
|
|
|
|
|
|
mRootContent = selRange->GetStartParent()->
|
|
|
|
GetSelectionRootContent(presShell);
|
|
|
|
} else {
|
|
|
|
mRootContent = mEditableNode->GetSelectionRootContent(presShell);
|
|
|
|
}
|
|
|
|
if (!mRootContent && mEditableNode->IsNodeOfType(nsINode::eDOCUMENT)) {
|
|
|
|
// The document node is editable, but there are no contents, this document
|
|
|
|
// is not editable.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE_VOID(mRootContent);
|
|
|
|
|
2015-05-26 10:45:26 +03:00
|
|
|
if (firstInitialization) {
|
2015-06-17 04:03:57 +03:00
|
|
|
MaybeNotifyIMEOfFocusSet();
|
2015-05-24 07:40:21 +03:00
|
|
|
|
2015-05-26 10:45:26 +03:00
|
|
|
// While Init() notifies IME of focus, pending layout may be flushed
|
|
|
|
// because the notification may cause querying content. Then, recursive
|
|
|
|
// call of Init() with the latest content may be occur. In such case, we
|
|
|
|
// shouldn't keep first initialization.
|
|
|
|
if (GetState() != eState_Initializing) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-26 10:45:26 +03:00
|
|
|
// NOTIFY_IME_OF_FOCUS might cause recreating IMEContentObserver
|
|
|
|
// instance via IMEStateManager::UpdateIMEState(). So, this
|
|
|
|
// instance might already have been destroyed, check it.
|
|
|
|
if (!mRootContent) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mDocShell = aPresContext->GetDocShell();
|
|
|
|
|
|
|
|
ObserveEditableNode();
|
2015-06-17 04:03:57 +03:00
|
|
|
|
|
|
|
// Some change events may wait to notify IME because this was being
|
|
|
|
// initialized. It is the time to flush them.
|
|
|
|
FlushMergeableNotifications();
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::ObserveEditableNode()
|
|
|
|
{
|
2015-05-26 10:45:26 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mEditor);
|
|
|
|
MOZ_RELEASE_ASSERT(mSelection);
|
|
|
|
MOZ_RELEASE_ASSERT(mRootContent);
|
|
|
|
MOZ_RELEASE_ASSERT(GetState() != eState_Observing);
|
|
|
|
|
|
|
|
mIsObserving = true;
|
|
|
|
mEditor->AddEditorObserver(this);
|
2014-03-08 05:20:07 +04:00
|
|
|
|
|
|
|
mUpdatePreference = mWidget->GetIMEUpdatePreference();
|
|
|
|
if (mUpdatePreference.WantSelectionChange()) {
|
|
|
|
// add selection change listener
|
2014-03-08 05:20:07 +04:00
|
|
|
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(mSelection));
|
2014-03-08 05:20:07 +04:00
|
|
|
NS_ENSURE_TRUE_VOID(selPrivate);
|
|
|
|
nsresult rv = selPrivate->AddSelectionListener(this);
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mUpdatePreference.WantTextChange()) {
|
|
|
|
// add text change observer
|
|
|
|
mRootContent->AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mUpdatePreference.WantPositionChanged() && mDocShell) {
|
|
|
|
// Add scroll position listener and reflow observer to detect position and
|
|
|
|
// size changes
|
|
|
|
mDocShell->AddWeakScrollObserver(this);
|
|
|
|
mDocShell->AddWeakReflowObserver(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-05-26 10:45:26 +03:00
|
|
|
IMEContentObserver::NotifyIMEOfBlur()
|
2015-05-24 04:11:37 +03:00
|
|
|
{
|
2015-06-17 04:03:57 +03:00
|
|
|
// Prevent any notifications to be sent IME.
|
|
|
|
nsCOMPtr<nsIWidget> widget;
|
|
|
|
mWidget.swap(widget);
|
|
|
|
|
|
|
|
// If we hasn't been set focus, we shouldn't send blur notification to IME.
|
|
|
|
if (!mIMEHasFocus) {
|
2015-05-26 10:45:26 +03:00
|
|
|
return;
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
2014-07-31 08:37:59 +04:00
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
// mWidget must have been non-nullptr if IME has focus.
|
|
|
|
MOZ_RELEASE_ASSERT(widget);
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
nsRefPtr<IMEContentObserver> kungFuDeathGrip(this);
|
|
|
|
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Info,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::NotifyIMEOfBlur(), "
|
|
|
|
"sending NOTIFY_IME_OF_BLUR", this));
|
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
// For now, we need to send blur notification in any condition because
|
|
|
|
// we don't have any simple ways to send blur notification asynchronously.
|
|
|
|
// After this call, Destroy() or Unlink() will stop observing the content
|
|
|
|
// and forget everything. Therefore, if it's not safe to send notification
|
|
|
|
// when script blocker is unlocked, we cannot send blur notification after
|
|
|
|
// that and before next focus notification.
|
|
|
|
// Anyway, as far as we know, IME doesn't try to query content when it loses
|
|
|
|
// focus. So, this may not cause any problem.
|
|
|
|
mIMEHasFocus = false;
|
2015-06-27 03:23:31 +03:00
|
|
|
IMEStateManager::NotifyIME(IMENotification(NOTIFY_IME_OF_BLUR), widget);
|
2015-09-08 06:54:14 +03:00
|
|
|
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::NotifyIMEOfBlur(), "
|
|
|
|
"sent NOTIFY_IME_OF_BLUR", this));
|
2015-05-26 10:45:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::UnregisterObservers()
|
|
|
|
{
|
2015-05-26 10:45:26 +03:00
|
|
|
if (!mIsObserving) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mIsObserving = false;
|
|
|
|
|
2015-05-26 10:45:26 +03:00
|
|
|
if (mEditor) {
|
|
|
|
mEditor->RemoveEditorObserver(this);
|
2015-05-24 07:40:21 +03:00
|
|
|
}
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
if (mUpdatePreference.WantSelectionChange() && mSelection) {
|
|
|
|
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(mSelection));
|
|
|
|
if (selPrivate) {
|
2014-03-08 05:20:07 +04:00
|
|
|
selPrivate->RemoveSelectionListener(this);
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
2015-09-08 06:54:14 +03:00
|
|
|
mSelectionData.Clear();
|
|
|
|
mFocusedWidget = nullptr;
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
2014-07-31 08:37:59 +04:00
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
if (mUpdatePreference.WantTextChange() && mRootContent) {
|
|
|
|
mRootContent->RemoveMutationObserver(this);
|
|
|
|
}
|
2014-07-31 08:37:59 +04:00
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
if (mUpdatePreference.WantPositionChanged() && mDocShell) {
|
|
|
|
mDocShell->RemoveWeakScrollObserver(this);
|
|
|
|
mDocShell->RemoveWeakReflowObserver(this);
|
|
|
|
}
|
2014-07-31 08:37:59 +04:00
|
|
|
}
|
|
|
|
|
2015-05-15 04:18:08 +03:00
|
|
|
nsPresContext*
|
|
|
|
IMEContentObserver::GetPresContext() const
|
|
|
|
{
|
|
|
|
return mESM ? mESM->GetPresContext() : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-07-31 08:37:59 +04:00
|
|
|
void
|
|
|
|
IMEContentObserver::Destroy()
|
|
|
|
{
|
|
|
|
// WARNING: When you change this method, you have to check Unlink() too.
|
|
|
|
|
2015-05-26 10:45:26 +03:00
|
|
|
NotifyIMEOfBlur();
|
2015-05-26 10:45:26 +03:00
|
|
|
UnregisterObservers();
|
2014-07-31 08:37:59 +04:00
|
|
|
|
|
|
|
mEditor = nullptr;
|
|
|
|
mWidget = nullptr;
|
|
|
|
mSelection = nullptr;
|
2014-03-08 05:20:07 +04:00
|
|
|
mRootContent = nullptr;
|
|
|
|
mEditableNode = nullptr;
|
|
|
|
mDocShell = nullptr;
|
|
|
|
mUpdatePreference.mWantUpdates = nsIMEUpdatePreference::NOTIFY_NOTHING;
|
2014-04-24 04:36:15 +04:00
|
|
|
|
|
|
|
if (mESM) {
|
|
|
|
mESM->OnStopObservingContent(this);
|
|
|
|
mESM = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::DisconnectFromEventStateManager()
|
|
|
|
{
|
|
|
|
mESM = nullptr;
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
|
|
|
|
2015-05-26 10:45:26 +03:00
|
|
|
bool
|
|
|
|
IMEContentObserver::MaybeReinitialize(nsIWidget* aWidget,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIEditor* aEditor)
|
|
|
|
{
|
|
|
|
if (!IsObservingContent(aPresContext, aContent)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetState() == eState_StoppedObserving) {
|
|
|
|
Init(aWidget, aPresContext, aContent, aEditor);
|
|
|
|
}
|
|
|
|
return IsManaging(aPresContext, aContent);
|
|
|
|
}
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
bool
|
|
|
|
IMEContentObserver::IsManaging(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent)
|
2015-05-26 10:45:26 +03:00
|
|
|
{
|
|
|
|
return GetState() == eState_Observing &&
|
|
|
|
IsObservingContent(aPresContext, aContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
IMEContentObserver::State
|
|
|
|
IMEContentObserver::GetState() const
|
2014-03-08 05:20:07 +04:00
|
|
|
{
|
2014-03-08 05:20:07 +04:00
|
|
|
if (!mSelection || !mRootContent || !mEditableNode) {
|
2015-05-26 10:45:26 +03:00
|
|
|
return eState_NotObserving; // failed to initialize or finalized.
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
2014-08-06 03:23:02 +04:00
|
|
|
if (!mRootContent->IsInComposedDoc()) {
|
2015-05-26 10:45:26 +03:00
|
|
|
// the focused editor has already been reframed.
|
|
|
|
return eState_StoppedObserving;
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
2015-05-26 10:45:26 +03:00
|
|
|
return mIsObserving ? eState_Observing : eState_Initializing;
|
2015-05-26 10:45:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IMEContentObserver::IsObservingContent(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent) const
|
|
|
|
{
|
2014-03-08 05:20:07 +04:00
|
|
|
return mEditableNode == IMEStateManager::GetRootEditableNode(aPresContext,
|
|
|
|
aContent);
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IMEContentObserver::IsEditorHandlingEventForComposition() const
|
|
|
|
{
|
|
|
|
if (!mWidget) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsRefPtr<TextComposition> composition =
|
2014-03-08 05:20:07 +04:00
|
|
|
IMEStateManager::GetTextCompositionFor(mWidget);
|
2014-03-08 05:20:07 +04:00
|
|
|
if (!composition) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return composition->IsEditorHandlingEvent();
|
|
|
|
}
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
nsresult
|
|
|
|
IMEContentObserver::GetSelectionAndRoot(nsISelection** aSelection,
|
|
|
|
nsIContent** aRootContent) const
|
|
|
|
{
|
|
|
|
if (!mEditableNode || !mSelection) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mSelection && mRootContent, "uninitialized content observer");
|
|
|
|
NS_ADDREF(*aSelection = mSelection);
|
|
|
|
NS_ADDREF(*aRootContent = mRootContent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
nsresult
|
2014-03-08 05:20:07 +04:00
|
|
|
IMEContentObserver::NotifySelectionChanged(nsIDOMDocument* aDOMDocument,
|
|
|
|
nsISelection* aSelection,
|
2014-03-08 05:20:07 +04:00
|
|
|
int16_t aReason)
|
|
|
|
{
|
|
|
|
int32_t count = 0;
|
2014-03-08 05:20:07 +04:00
|
|
|
nsresult rv = aSelection->GetRangeCount(&count);
|
2014-03-08 05:20:07 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (count > 0 && mWidget) {
|
2015-08-21 19:43:42 +03:00
|
|
|
bool causedByComposition = IsEditorHandlingEventForComposition();
|
2015-07-17 05:25:00 +03:00
|
|
|
bool causedBySelectionEvent = TextComposition::IsHandlingSelectionEvent();
|
|
|
|
MaybeNotifyIMEOfSelectionChange(causedByComposition,
|
|
|
|
causedBySelectionEvent);
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::ScrollPositionChanged()
|
|
|
|
{
|
2014-07-31 08:38:00 +04:00
|
|
|
MaybeNotifyIMEOfPositionChange();
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IMEContentObserver::Reflow(DOMHighResTimeStamp aStart,
|
|
|
|
DOMHighResTimeStamp aEnd)
|
|
|
|
{
|
2014-07-31 08:38:00 +04:00
|
|
|
MaybeNotifyIMEOfPositionChange();
|
2014-03-08 05:20:07 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IMEContentObserver::ReflowInterruptible(DOMHighResTimeStamp aStart,
|
|
|
|
DOMHighResTimeStamp aEnd)
|
|
|
|
{
|
2014-07-31 08:38:00 +04:00
|
|
|
MaybeNotifyIMEOfPositionChange();
|
2014-03-08 05:20:07 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
nsresult
|
|
|
|
IMEContentObserver::HandleQueryContentEvent(WidgetQueryContentEvent* aEvent)
|
|
|
|
{
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::HandleQueryContentEvent(aEvent={ "
|
|
|
|
"mMessage=%s })", this, ToChar(aEvent->mMessage)));
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
// If the instance has cache, it should use the cached selection which was
|
|
|
|
// sent to the widget.
|
2015-09-10 04:40:05 +03:00
|
|
|
if (aEvent->mMessage == eQuerySelectedText && aEvent->mUseNativeLineBreak &&
|
2015-09-08 06:54:14 +03:00
|
|
|
mSelectionData.IsValid()) {
|
|
|
|
aEvent->mReply.mContentsRoot = mRootContent;
|
|
|
|
aEvent->mReply.mHasSelection = !mSelectionData.IsCollapsed();
|
|
|
|
aEvent->mReply.mOffset = mSelectionData.mOffset;
|
|
|
|
aEvent->mReply.mString = mSelectionData.String();
|
|
|
|
aEvent->mReply.mWritingMode = mSelectionData.GetWritingMode();
|
|
|
|
aEvent->mReply.mReversed = mSelectionData.mReversed;
|
|
|
|
aEvent->mSucceeded = true;
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::HandleQueryContentEvent(aEvent={ "
|
|
|
|
"mMessage=%s })", this, ToChar(aEvent->mMessage)));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
ContentEventHandler handler(GetPresContext());
|
2015-09-08 06:54:14 +03:00
|
|
|
nsresult rv = handler.HandleQueryContentEvent(aEvent);
|
|
|
|
if (aEvent->mSucceeded) {
|
|
|
|
// We need to guarantee that mRootContent should be always same value for
|
|
|
|
// the observing editor.
|
|
|
|
aEvent->mReply.mContentsRoot = mRootContent;
|
|
|
|
}
|
|
|
|
return rv;
|
2015-09-08 06:54:14 +03:00
|
|
|
}
|
|
|
|
|
2014-08-29 14:08:43 +04:00
|
|
|
bool
|
|
|
|
IMEContentObserver::OnMouseButtonEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetMouseEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
if (!mUpdatePreference.WantMouseButtonEventOnChar()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!aMouseEvent->mFlags.mIsTrusted ||
|
|
|
|
aMouseEvent->mFlags.mDefaultPrevented ||
|
|
|
|
!aMouseEvent->widget) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Now, we need to notify only mouse down and mouse up event.
|
2015-08-22 04:34:51 +03:00
|
|
|
switch (aMouseEvent->mMessage) {
|
2015-08-29 02:58:30 +03:00
|
|
|
case eMouseUp:
|
2015-08-29 02:58:30 +03:00
|
|
|
case eMouseDown:
|
2014-08-29 14:08:43 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-17 16:20:08 +03:00
|
|
|
if (NS_WARN_IF(!mWidget) || NS_WARN_IF(mWidget->Destroyed())) {
|
2014-08-29 14:08:43 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-17 16:20:08 +03:00
|
|
|
nsRefPtr<IMEContentObserver> kungFuDeathGrip(this);
|
|
|
|
|
2015-09-10 04:40:06 +03:00
|
|
|
WidgetQueryContentEvent charAtPt(true, eQueryCharacterAtPoint,
|
2014-08-29 14:08:43 +04:00
|
|
|
aMouseEvent->widget);
|
|
|
|
charAtPt.refPoint = aMouseEvent->refPoint;
|
|
|
|
ContentEventHandler handler(aPresContext);
|
|
|
|
handler.OnQueryCharacterAtPoint(&charAtPt);
|
|
|
|
if (NS_WARN_IF(!charAtPt.mSucceeded) ||
|
|
|
|
charAtPt.mReply.mOffset == WidgetQueryContentEvent::NOT_FOUND) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-17 16:20:08 +03:00
|
|
|
// The widget might be destroyed during querying the content since it
|
|
|
|
// causes flushing layout.
|
|
|
|
if (!mWidget || NS_WARN_IF(mWidget->Destroyed())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-29 14:08:43 +04:00
|
|
|
// The result character rect is relative to the top level widget.
|
|
|
|
// We should notify it with offset in the widget.
|
|
|
|
nsIWidget* topLevelWidget = mWidget->GetTopLevelWidget();
|
|
|
|
if (topLevelWidget && topLevelWidget != mWidget) {
|
|
|
|
charAtPt.mReply.mRect.MoveBy(
|
2015-02-04 23:21:03 +03:00
|
|
|
topLevelWidget->WidgetToScreenOffset() -
|
|
|
|
mWidget->WidgetToScreenOffset());
|
2014-08-29 14:08:43 +04:00
|
|
|
}
|
|
|
|
// The refPt is relative to its widget.
|
|
|
|
// We should notify it with offset in the widget.
|
|
|
|
if (aMouseEvent->widget != mWidget) {
|
2015-02-04 23:21:03 +03:00
|
|
|
charAtPt.refPoint += aMouseEvent->widget->WidgetToScreenOffset() -
|
|
|
|
mWidget->WidgetToScreenOffset();
|
2014-08-29 14:08:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
IMENotification notification(NOTIFY_IME_OF_MOUSE_BUTTON_EVENT);
|
2015-08-22 04:34:51 +03:00
|
|
|
notification.mMouseButtonEventData.mEventMessage = aMouseEvent->mMessage;
|
2014-08-29 14:08:43 +04:00
|
|
|
notification.mMouseButtonEventData.mOffset = charAtPt.mReply.mOffset;
|
|
|
|
notification.mMouseButtonEventData.mCursorPos.Set(
|
|
|
|
LayoutDeviceIntPoint::ToUntyped(charAtPt.refPoint));
|
2015-02-04 23:21:03 +03:00
|
|
|
notification.mMouseButtonEventData.mCharRect.Set(
|
|
|
|
LayoutDevicePixel::ToUntyped(charAtPt.mReply.mRect));
|
2014-08-29 14:08:43 +04:00
|
|
|
notification.mMouseButtonEventData.mButton = aMouseEvent->button;
|
|
|
|
notification.mMouseButtonEventData.mButtons = aMouseEvent->buttons;
|
|
|
|
notification.mMouseButtonEventData.mModifiers = aMouseEvent->modifiers;
|
|
|
|
|
2015-06-27 03:23:31 +03:00
|
|
|
nsresult rv = IMEStateManager::NotifyIME(notification, mWidget);
|
2014-08-29 14:08:43 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool consumed = (rv == NS_SUCCESS_EVENT_CONSUMED);
|
|
|
|
aMouseEvent->mFlags.mDefaultPrevented = consumed;
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2014-07-31 08:38:01 +04:00
|
|
|
void
|
|
|
|
IMEContentObserver::CharacterDataWillChange(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
|
|
|
|
"character data changed for non-text node");
|
|
|
|
MOZ_ASSERT(mPreCharacterDataChangeLength < 0,
|
|
|
|
"CharacterDataChanged() should've reset "
|
|
|
|
"mPreCharacterDataChangeLength");
|
|
|
|
|
|
|
|
mEndOfAddedTextCache.Clear();
|
|
|
|
mStartOfRemovingTextRangeCache.Clear();
|
|
|
|
|
|
|
|
bool causedByComposition = IsEditorHandlingEventForComposition();
|
2015-07-11 04:53:56 +03:00
|
|
|
if (!mTextChangeData.IsValid() && causedByComposition &&
|
2014-07-31 08:38:01 +04:00
|
|
|
!mUpdatePreference.WantChangesCausedByComposition()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPreCharacterDataChangeLength =
|
|
|
|
ContentEventHandler::GetNativeTextLength(aContent, aInfo->mChangeStart,
|
|
|
|
aInfo->mChangeEnd);
|
|
|
|
MOZ_ASSERT(mPreCharacterDataChangeLength >=
|
|
|
|
aInfo->mChangeEnd - aInfo->mChangeStart,
|
|
|
|
"The computed length must be same as or larger than XP length");
|
|
|
|
}
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
void
|
|
|
|
IMEContentObserver::CharacterDataChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
CharacterDataChangeInfo* aInfo)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent->IsNodeOfType(nsINode::eTEXT),
|
|
|
|
"character data changed for non-text node");
|
|
|
|
|
2014-07-31 08:38:00 +04:00
|
|
|
mEndOfAddedTextCache.Clear();
|
2014-07-31 08:38:00 +04:00
|
|
|
mStartOfRemovingTextRangeCache.Clear();
|
2014-07-31 08:38:00 +04:00
|
|
|
|
2014-07-31 08:38:01 +04:00
|
|
|
int64_t removedLength = mPreCharacterDataChangeLength;
|
|
|
|
mPreCharacterDataChangeLength = -1;
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
bool causedByComposition = IsEditorHandlingEventForComposition();
|
2015-07-11 04:53:56 +03:00
|
|
|
if (!mTextChangeData.IsValid() && causedByComposition &&
|
2014-03-08 05:20:07 +04:00
|
|
|
!mUpdatePreference.WantChangesCausedByComposition()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-31 08:38:01 +04:00
|
|
|
MOZ_ASSERT(removedLength >= 0,
|
|
|
|
"mPreCharacterDataChangeLength should've been set by "
|
|
|
|
"CharacterDataWillChange()");
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
uint32_t offset = 0;
|
|
|
|
// get offsets of change and fire notification
|
2014-03-08 05:20:07 +04:00
|
|
|
nsresult rv =
|
2014-03-11 09:08:02 +04:00
|
|
|
ContentEventHandler::GetFlatTextOffsetOfRange(mRootContent, aContent,
|
|
|
|
aInfo->mChangeStart,
|
2014-04-26 03:52:12 +04:00
|
|
|
&offset,
|
|
|
|
LINE_BREAK_TYPE_NATIVE);
|
2014-03-08 05:20:07 +04:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2014-03-08 05:20:07 +04:00
|
|
|
|
2014-07-31 08:38:01 +04:00
|
|
|
uint32_t newLength =
|
|
|
|
ContentEventHandler::GetNativeTextLength(aContent, aInfo->mChangeStart,
|
|
|
|
aInfo->mChangeStart +
|
|
|
|
aInfo->mReplaceLength);
|
|
|
|
|
|
|
|
uint32_t oldEnd = offset + static_cast<uint32_t>(removedLength);
|
|
|
|
uint32_t newEnd = offset + newLength;
|
2014-03-08 05:20:07 +04:00
|
|
|
|
2014-07-31 08:37:59 +04:00
|
|
|
TextChangeData data(offset, oldEnd, newEnd, causedByComposition);
|
2014-07-31 08:38:00 +04:00
|
|
|
MaybeNotifyIMEOfTextChange(data);
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::NotifyContentAdded(nsINode* aContainer,
|
|
|
|
int32_t aStartIndex,
|
|
|
|
int32_t aEndIndex)
|
|
|
|
{
|
2014-07-31 08:38:00 +04:00
|
|
|
mStartOfRemovingTextRangeCache.Clear();
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
bool causedByComposition = IsEditorHandlingEventForComposition();
|
2015-07-11 04:53:56 +03:00
|
|
|
if (!mTextChangeData.IsValid() && causedByComposition &&
|
2014-03-08 05:20:07 +04:00
|
|
|
!mUpdatePreference.WantChangesCausedByComposition()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
uint32_t offset = 0;
|
2014-07-31 08:38:00 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (!mEndOfAddedTextCache.Match(aContainer, aStartIndex)) {
|
|
|
|
mEndOfAddedTextCache.Clear();
|
|
|
|
rv = ContentEventHandler::GetFlatTextOffsetOfRange(mRootContent, aContainer,
|
|
|
|
aStartIndex, &offset,
|
|
|
|
LINE_BREAK_TYPE_NATIVE);
|
|
|
|
if (NS_WARN_IF(NS_FAILED((rv)))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
offset = mEndOfAddedTextCache.mFlatTextLength;
|
|
|
|
}
|
2014-03-08 05:20:07 +04:00
|
|
|
|
|
|
|
// get offset at the end of the last added node
|
2014-03-08 05:20:07 +04:00
|
|
|
nsIContent* childAtStart = aContainer->GetChildAt(aStartIndex);
|
|
|
|
uint32_t addingLength = 0;
|
2014-03-11 09:08:02 +04:00
|
|
|
rv = ContentEventHandler::GetFlatTextOffsetOfRange(childAtStart, aContainer,
|
2014-04-26 03:52:12 +04:00
|
|
|
aEndIndex, &addingLength,
|
|
|
|
LINE_BREAK_TYPE_NATIVE);
|
2014-07-31 08:38:00 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED((rv)))) {
|
|
|
|
mEndOfAddedTextCache.Clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If multiple lines are being inserted in an HTML editor, next call of
|
|
|
|
// NotifyContentAdded() is for adding next node. Therefore, caching the text
|
|
|
|
// length can skip to compute the text length before the adding node and
|
|
|
|
// before of it.
|
|
|
|
mEndOfAddedTextCache.Cache(aContainer, aEndIndex, offset + addingLength);
|
2014-03-08 05:20:07 +04:00
|
|
|
|
|
|
|
if (!addingLength) {
|
2014-03-08 05:20:07 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-03-08 05:20:07 +04:00
|
|
|
|
2014-07-31 08:37:59 +04:00
|
|
|
TextChangeData data(offset, offset, offset + addingLength,
|
|
|
|
causedByComposition);
|
2014-07-31 08:38:00 +04:00
|
|
|
MaybeNotifyIMEOfTextChange(data);
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aFirstNewContent,
|
|
|
|
int32_t aNewIndexInContainer)
|
|
|
|
{
|
|
|
|
NotifyContentAdded(aContainer, aNewIndexInContainer,
|
|
|
|
aContainer->GetChildCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer)
|
|
|
|
{
|
|
|
|
NotifyContentAdded(NODE_FROM(aContainer, aDocument),
|
|
|
|
aIndexInContainer, aIndexInContainer + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer,
|
|
|
|
nsIContent* aPreviousSibling)
|
|
|
|
{
|
2014-07-31 08:38:00 +04:00
|
|
|
mEndOfAddedTextCache.Clear();
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
bool causedByComposition = IsEditorHandlingEventForComposition();
|
2015-07-11 04:53:56 +03:00
|
|
|
if (!mTextChangeData.IsValid() && causedByComposition &&
|
2014-03-08 05:20:07 +04:00
|
|
|
!mUpdatePreference.WantChangesCausedByComposition()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-31 08:38:00 +04:00
|
|
|
nsINode* containerNode = NODE_FROM(aContainer, aDocument);
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
uint32_t offset = 0;
|
2014-07-31 08:38:00 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (!mStartOfRemovingTextRangeCache.Match(containerNode, aIndexInContainer)) {
|
|
|
|
rv =
|
|
|
|
ContentEventHandler::GetFlatTextOffsetOfRange(mRootContent, containerNode,
|
|
|
|
aIndexInContainer, &offset,
|
|
|
|
LINE_BREAK_TYPE_NATIVE);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
mStartOfRemovingTextRangeCache.Clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mStartOfRemovingTextRangeCache.Cache(containerNode, aIndexInContainer,
|
|
|
|
offset);
|
|
|
|
} else {
|
|
|
|
offset = mStartOfRemovingTextRangeCache.mFlatTextLength;
|
|
|
|
}
|
2014-03-08 05:20:07 +04:00
|
|
|
|
|
|
|
// get offset at the end of the deleted node
|
2014-03-08 05:20:07 +04:00
|
|
|
int32_t nodeLength =
|
|
|
|
aChild->IsNodeOfType(nsINode::eTEXT) ?
|
|
|
|
static_cast<int32_t>(aChild->TextLength()) :
|
|
|
|
std::max(static_cast<int32_t>(aChild->GetChildCount()), 1);
|
|
|
|
MOZ_ASSERT(nodeLength >= 0, "The node length is out of range");
|
|
|
|
uint32_t textLength = 0;
|
2014-03-11 09:08:02 +04:00
|
|
|
rv = ContentEventHandler::GetFlatTextOffsetOfRange(aChild, aChild,
|
2014-04-26 03:52:12 +04:00
|
|
|
nodeLength, &textLength,
|
|
|
|
LINE_BREAK_TYPE_NATIVE);
|
2014-07-31 08:38:00 +04:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
mStartOfRemovingTextRangeCache.Clear();
|
|
|
|
return;
|
|
|
|
}
|
2014-03-08 05:20:07 +04:00
|
|
|
|
|
|
|
if (!textLength) {
|
2014-03-08 05:20:07 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-03-08 05:20:07 +04:00
|
|
|
|
2014-07-31 08:37:59 +04:00
|
|
|
TextChangeData data(offset, offset + textLength, offset, causedByComposition);
|
2014-07-31 08:38:00 +04:00
|
|
|
MaybeNotifyIMEOfTextChange(data);
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsIContent*
|
|
|
|
GetContentBR(dom::Element* aElement)
|
|
|
|
{
|
|
|
|
if (!aElement->IsNodeOfType(nsINode::eCONTENT)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-03-08 05:20:07 +04:00
|
|
|
nsIContent* content = static_cast<nsIContent*>(aElement);
|
2015-03-03 14:08:59 +03:00
|
|
|
return content->IsHTMLElement(nsGkAtoms::br) ? content : nullptr;
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::AttributeWillChange(nsIDocument* aDocument,
|
|
|
|
dom::Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
2015-07-25 09:05:19 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aNewValue)
|
2014-03-08 05:20:07 +04:00
|
|
|
{
|
|
|
|
nsIContent *content = GetContentBR(aElement);
|
|
|
|
mPreAttrChangeLength = content ?
|
2014-03-11 09:08:02 +04:00
|
|
|
ContentEventHandler::GetNativeTextLength(content) : 0;
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
dom::Element* aElement,
|
|
|
|
int32_t aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
2015-07-25 09:01:19 +03:00
|
|
|
int32_t aModType,
|
|
|
|
const nsAttrValue* aOldValue)
|
2014-03-08 05:20:07 +04:00
|
|
|
{
|
2014-07-31 08:38:00 +04:00
|
|
|
mEndOfAddedTextCache.Clear();
|
2014-07-31 08:38:00 +04:00
|
|
|
mStartOfRemovingTextRangeCache.Clear();
|
2014-07-31 08:38:00 +04:00
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
bool causedByComposition = IsEditorHandlingEventForComposition();
|
2015-07-11 04:53:56 +03:00
|
|
|
if (!mTextChangeData.IsValid() && causedByComposition &&
|
2014-03-08 05:20:07 +04:00
|
|
|
!mUpdatePreference.WantChangesCausedByComposition()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent *content = GetContentBR(aElement);
|
|
|
|
if (!content) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-08 05:20:07 +04:00
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
uint32_t postAttrChangeLength =
|
2014-03-11 09:08:02 +04:00
|
|
|
ContentEventHandler::GetNativeTextLength(content);
|
2014-03-08 05:20:07 +04:00
|
|
|
if (postAttrChangeLength == mPreAttrChangeLength) {
|
|
|
|
return;
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
2014-03-08 05:20:07 +04:00
|
|
|
uint32_t start;
|
|
|
|
nsresult rv =
|
2014-03-11 09:08:02 +04:00
|
|
|
ContentEventHandler::GetFlatTextOffsetOfRange(mRootContent, content,
|
2014-04-26 03:52:12 +04:00
|
|
|
0, &start,
|
|
|
|
LINE_BREAK_TYPE_NATIVE);
|
2014-03-08 05:20:07 +04:00
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
|
|
|
|
2014-07-31 08:37:59 +04:00
|
|
|
TextChangeData data(start, start + mPreAttrChangeLength,
|
|
|
|
start + postAttrChangeLength, causedByComposition);
|
2014-07-31 08:38:00 +04:00
|
|
|
MaybeNotifyIMEOfTextChange(data);
|
2014-07-31 08:37:59 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
void
|
|
|
|
IMEContentObserver::SuppressNotifyingIME()
|
|
|
|
{
|
|
|
|
mSuppressNotifications++;
|
|
|
|
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::SuppressNotifyingIME(), "
|
|
|
|
"mSuppressNotifications=%u", this, mSuppressNotifications));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::UnsuppressNotifyingIME()
|
|
|
|
{
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::UnsuppressNotifyingIME(), "
|
|
|
|
"mSuppressNotifications=%u", this, mSuppressNotifications));
|
|
|
|
|
|
|
|
if (!mSuppressNotifications || --mSuppressNotifications) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FlushMergeableNotifications();
|
|
|
|
}
|
|
|
|
|
2014-07-31 08:37:59 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IMEContentObserver::EditAction()
|
|
|
|
{
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::EditAction()", this));
|
|
|
|
|
2014-07-31 08:38:00 +04:00
|
|
|
mEndOfAddedTextCache.Clear();
|
2014-07-31 08:38:00 +04:00
|
|
|
mStartOfRemovingTextRangeCache.Clear();
|
2014-07-31 08:37:59 +04:00
|
|
|
FlushMergeableNotifications();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IMEContentObserver::BeforeEditAction()
|
|
|
|
{
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::BeforeEditAction()", this));
|
|
|
|
|
2014-07-31 08:38:00 +04:00
|
|
|
mEndOfAddedTextCache.Clear();
|
2014-07-31 08:38:00 +04:00
|
|
|
mStartOfRemovingTextRangeCache.Clear();
|
2014-07-31 08:37:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IMEContentObserver::CancelEditAction()
|
|
|
|
{
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::CancelEditAction()", this));
|
|
|
|
|
2014-07-31 08:38:00 +04:00
|
|
|
mEndOfAddedTextCache.Clear();
|
2014-07-31 08:38:00 +04:00
|
|
|
mStartOfRemovingTextRangeCache.Clear();
|
2014-07-31 08:37:59 +04:00
|
|
|
FlushMergeableNotifications();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
void
|
2015-06-17 04:03:57 +03:00
|
|
|
IMEContentObserver::PostFocusSetNotification()
|
2015-06-17 04:03:57 +03:00
|
|
|
{
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::PostFocusSetNotification()", this));
|
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
mIsFocusEventPending = true;
|
|
|
|
}
|
|
|
|
|
2014-07-31 08:38:00 +04:00
|
|
|
void
|
2015-09-16 11:48:23 +03:00
|
|
|
IMEContentObserver::PostTextChangeNotification()
|
2014-07-31 08:38:00 +04:00
|
|
|
{
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::PostTextChangeNotification("
|
2015-09-16 11:48:23 +03:00
|
|
|
"mTextChangeData=%s)",
|
|
|
|
this, TextChangeDataToString(mTextChangeData).get()));
|
2015-09-08 06:54:14 +03:00
|
|
|
|
2015-07-11 04:53:56 +03:00
|
|
|
MOZ_ASSERT(mTextChangeData.IsValid(),
|
2014-07-31 08:38:00 +04:00
|
|
|
"mTextChangeData must have text change data");
|
2015-09-16 11:48:23 +03:00
|
|
|
mIsTextChangeEventPending = true;
|
2014-07-31 08:38:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-09-14 17:28:43 +03:00
|
|
|
IMEContentObserver::PostSelectionChangeNotification()
|
2014-07-31 08:38:00 +04:00
|
|
|
{
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-14 17:28:43 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::PostSelectionChangeNotification(), "
|
|
|
|
"mSelectionData={ mCausedByComposition=%s, mCausedBySelectionEvent=%s }",
|
|
|
|
this, ToChar(mSelectionData.mCausedByComposition),
|
|
|
|
ToChar(mSelectionData.mCausedBySelectionEvent)));
|
2015-09-08 06:54:14 +03:00
|
|
|
|
2014-07-31 08:38:00 +04:00
|
|
|
mIsSelectionChangeEventPending = true;
|
|
|
|
}
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
void
|
|
|
|
IMEContentObserver::MaybeNotifyIMEOfFocusSet()
|
|
|
|
{
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::MaybeNotifyIMEOfFocusSet()", this));
|
|
|
|
|
|
|
|
PostFocusSetNotification();
|
|
|
|
FlushMergeableNotifications();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::MaybeNotifyIMEOfTextChange(
|
|
|
|
const TextChangeDataBase& aTextChangeData)
|
|
|
|
{
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::MaybeNotifyIMEOfTextChange("
|
|
|
|
"aTextChangeData=%s)",
|
|
|
|
this, TextChangeDataToString(aTextChangeData).get()));
|
|
|
|
|
2015-09-16 11:48:23 +03:00
|
|
|
mTextChangeData += aTextChangeData;
|
|
|
|
PostTextChangeNotification();
|
2015-09-08 06:54:14 +03:00
|
|
|
FlushMergeableNotifications();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::MaybeNotifyIMEOfSelectionChange(
|
|
|
|
bool aCausedByComposition,
|
|
|
|
bool aCausedBySelectionEvent)
|
|
|
|
{
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::MaybeNotifyIMEOfSelectionChange("
|
|
|
|
"aCausedByComposition=%s, aCausedBySelectionEvent=%s)",
|
|
|
|
this, ToChar(aCausedByComposition), ToChar(aCausedBySelectionEvent)));
|
|
|
|
|
2015-09-14 17:28:43 +03:00
|
|
|
mSelectionData.AssignReason(aCausedByComposition,
|
|
|
|
aCausedBySelectionEvent);
|
|
|
|
PostSelectionChangeNotification();
|
2015-09-08 06:54:14 +03:00
|
|
|
FlushMergeableNotifications();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::MaybeNotifyIMEOfPositionChange()
|
|
|
|
{
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::MaybeNotifyIMEOfPositionChange()", this));
|
|
|
|
PostPositionChangeNotification();
|
|
|
|
FlushMergeableNotifications();
|
|
|
|
}
|
|
|
|
|
2015-08-21 19:43:41 +03:00
|
|
|
bool
|
|
|
|
IMEContentObserver::UpdateSelectionCache()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsSafeToNotifyIME());
|
|
|
|
|
|
|
|
if (!mUpdatePreference.WantSelectionChange()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-14 17:28:43 +03:00
|
|
|
mSelectionData.ClearSelectionData();
|
2015-08-21 19:43:41 +03:00
|
|
|
|
|
|
|
// XXX Cannot we cache some information for reducing the cost to compute
|
|
|
|
// selection offset and writing mode?
|
2015-09-10 04:40:05 +03:00
|
|
|
WidgetQueryContentEvent selection(true, eQuerySelectedText, mWidget);
|
2015-08-21 19:43:41 +03:00
|
|
|
ContentEventHandler handler(GetPresContext());
|
|
|
|
handler.OnQuerySelectedText(&selection);
|
|
|
|
if (NS_WARN_IF(!selection.mSucceeded)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
mFocusedWidget = selection.mReply.mFocusedWidget;
|
2015-08-21 19:43:41 +03:00
|
|
|
mSelectionData.mOffset = selection.mReply.mOffset;
|
|
|
|
*mSelectionData.mString = selection.mReply.mString;
|
|
|
|
mSelectionData.SetWritingMode(selection.GetWritingMode());
|
|
|
|
mSelectionData.mReversed = selection.mReply.mReversed;
|
2015-09-14 17:28:43 +03:00
|
|
|
|
|
|
|
// WARNING: Don't modify the reason of selection change here.
|
2015-09-08 06:54:14 +03:00
|
|
|
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::UpdateSelectionCache(), "
|
|
|
|
"mSelectionData=%s",
|
|
|
|
this, SelectionChangeDataToString(mSelectionData).get()));
|
|
|
|
|
2015-08-21 19:43:41 +03:00
|
|
|
return mSelectionData.IsValid();
|
|
|
|
}
|
|
|
|
|
2014-07-31 08:38:00 +04:00
|
|
|
void
|
2015-06-17 04:03:57 +03:00
|
|
|
IMEContentObserver::PostPositionChangeNotification()
|
2014-07-31 08:38:00 +04:00
|
|
|
{
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::PostPositionChangeNotification()", this));
|
|
|
|
|
2014-07-31 08:38:00 +04:00
|
|
|
mIsPositionChangeEventPending = true;
|
|
|
|
}
|
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
bool
|
|
|
|
IMEContentObserver::IsReflowLocked() const
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = GetPresContext();
|
|
|
|
if (NS_WARN_IF(!presContext)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsIPresShell* presShell = presContext->GetPresShell();
|
|
|
|
if (NS_WARN_IF(!presShell)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// During reflow, we shouldn't notify IME because IME may query content
|
|
|
|
// synchronously. Then, it causes ContentEventHandler will try to flush
|
|
|
|
// pending notifications during reflow.
|
|
|
|
return presShell->IsReflowLocked();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IMEContentObserver::IsSafeToNotifyIME() const
|
2014-07-31 08:37:59 +04:00
|
|
|
{
|
2014-08-13 15:25:14 +04:00
|
|
|
// If this is already detached from the widget, this doesn't need to notify
|
|
|
|
// anything.
|
2014-08-19 15:54:08 +04:00
|
|
|
if (!mWidget) {
|
2015-06-17 04:03:57 +03:00
|
|
|
return false;
|
2014-08-19 15:54:08 +04:00
|
|
|
}
|
|
|
|
|
2015-06-04 20:06:10 +03:00
|
|
|
// Don't notify IME of anything if it's not good time to do it.
|
|
|
|
if (mSuppressNotifications) {
|
2015-06-17 04:03:57 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mESM || NS_WARN_IF(!GetPresContext())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it's in reflow, we should wait to finish the reflow.
|
|
|
|
// FYI: This should be called again from Reflow() or ReflowInterruptible().
|
|
|
|
if (IsReflowLocked()) {
|
|
|
|
return false;
|
2015-06-04 20:06:10 +03:00
|
|
|
}
|
|
|
|
|
2014-08-19 15:54:08 +04:00
|
|
|
// If we're in handling an edit action, this method will be called later.
|
2014-08-28 18:33:35 +04:00
|
|
|
bool isInEditAction = false;
|
|
|
|
if (mEditor && NS_SUCCEEDED(mEditor->GetIsInEditAction(&isInEditAction)) &&
|
|
|
|
isInEditAction) {
|
2015-06-17 04:03:57 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::FlushMergeableNotifications()
|
|
|
|
{
|
|
|
|
if (!IsSafeToNotifyIME()) {
|
|
|
|
// So, if this is already called, this should do nothing.
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::FlushMergeableNotifications(), "
|
|
|
|
"FAILED, due to unsafe to notify IME", this));
|
2014-07-31 08:37:59 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-13 15:25:14 +04:00
|
|
|
// Notifying something may cause nested call of this method. For example,
|
|
|
|
// when somebody notified one of the notifications may dispatch query content
|
|
|
|
// event. Then, it causes flushing layout which may cause another layout
|
|
|
|
// change notification.
|
|
|
|
|
|
|
|
if (mIsFlushingPendingNotifications) {
|
|
|
|
// So, if this is already called, this should do nothing.
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::FlushMergeableNotifications(), "
|
|
|
|
"FAILED, due to already flushing pending notifications", this));
|
2014-08-13 15:25:14 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
if (!NeedsToNotifyIMEOfSomething()) {
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::FlushMergeableNotifications(), "
|
|
|
|
"FAILED, due to no pending notifications", this));
|
2015-06-17 04:03:57 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
// NOTE: Reset each pending flag because sending notification may cause
|
|
|
|
// another change.
|
2014-07-31 08:38:00 +04:00
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::FlushMergeableNotifications(), "
|
|
|
|
"creating IMENotificationSender...", this));
|
2014-08-13 15:25:14 +04:00
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
mIsFlushingPendingNotifications = true;
|
2015-09-16 11:48:24 +03:00
|
|
|
nsContentUtils::AddScriptRunner(new IMENotificationSender(this));
|
2015-09-08 06:54:14 +03:00
|
|
|
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::FlushMergeableNotifications(), "
|
|
|
|
"finished", this));
|
2014-07-31 08:37:59 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::IMEContentObserver::AChangeEvent
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
bool
|
2015-09-16 11:48:24 +03:00
|
|
|
IMEContentObserver::AChangeEvent::CanNotifyIME(
|
|
|
|
ChangeEventType aChangeEventType) const
|
2015-06-17 04:03:57 +03:00
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!mIMEContentObserver)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
State state = mIMEContentObserver->GetState();
|
|
|
|
// If it's not initialized, we should do nothing.
|
|
|
|
if (state == eState_NotObserving) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// If setting focus, just check the state.
|
2015-09-16 11:48:24 +03:00
|
|
|
if (aChangeEventType == eChangeEventType_Focus) {
|
2015-06-17 04:03:57 +03:00
|
|
|
return !NS_WARN_IF(mIMEContentObserver->mIMEHasFocus);
|
|
|
|
}
|
|
|
|
// If we've not notified IME of focus yet, we shouldn't notify anything.
|
|
|
|
if (!mIMEContentObserver->mIMEHasFocus) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If IME has focus, IMEContentObserver must hold the widget.
|
|
|
|
MOZ_ASSERT(mIMEContentObserver->mWidget);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
bool
|
2015-09-16 11:48:24 +03:00
|
|
|
IMEContentObserver::AChangeEvent::IsSafeToNotifyIME(
|
|
|
|
ChangeEventType aChangeEventType) const
|
2015-06-17 04:03:57 +03:00
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!nsContentUtils::IsSafeToRunScript())) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-16 11:48:24 +03:00
|
|
|
// While we're sending a notification, we shouldn't send another notification
|
|
|
|
// recursively.
|
|
|
|
if (mIMEContentObserver->mSendingNotification != NOTIFY_IME_OF_NOTHING) {
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::AChangeEvent::IsSafeToNotifyIME(), "
|
|
|
|
"putting off sending notification due to detecting recursive call, "
|
|
|
|
"mIMEContentObserver={ mSendingNotification=%s }",
|
|
|
|
this, ToChar(mIMEContentObserver->mSendingNotification)));
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-17 04:03:57 +03:00
|
|
|
State state = mIMEContentObserver->GetState();
|
2015-09-16 11:48:24 +03:00
|
|
|
if (aChangeEventType == eChangeEventType_Focus) {
|
2015-06-17 04:03:57 +03:00
|
|
|
if (NS_WARN_IF(state != eState_Initializing && state != eState_Observing)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (state != eState_Observing) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return mIMEContentObserver->IsSafeToNotifyIME();
|
|
|
|
}
|
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
/******************************************************************************
|
2015-09-16 11:48:24 +03:00
|
|
|
* mozilla::IMEContentObserver::IMENotificationSender
|
2015-06-17 04:03:57 +03:00
|
|
|
******************************************************************************/
|
2015-09-16 11:48:24 +03:00
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
NS_IMETHODIMP
|
2015-09-16 11:48:24 +03:00
|
|
|
IMEContentObserver::IMENotificationSender::Run()
|
2015-06-17 04:03:57 +03:00
|
|
|
{
|
2015-09-16 11:48:24 +03:00
|
|
|
MOZ_ASSERT(mIMEContentObserver->mIsFlushingPendingNotifications);
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
// NOTE: Reset each pending flag because sending notification may cause
|
|
|
|
// another change.
|
|
|
|
|
|
|
|
if (mIMEContentObserver->mIsFocusEventPending) {
|
|
|
|
mIMEContentObserver->mIsFocusEventPending = false;
|
|
|
|
SendFocusSet();
|
|
|
|
// This is the first notification to IME. So, we don't need to notify
|
|
|
|
// anymore since IME starts to query content after it gets focus.
|
|
|
|
mIMEContentObserver->ClearPendingNotifications();
|
2015-09-16 11:48:24 +03:00
|
|
|
mIMEContentObserver->mIsFlushingPendingNotifications = false;
|
2015-09-16 11:48:24 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIMEContentObserver->mIsTextChangeEventPending) {
|
|
|
|
mIMEContentObserver->mIsTextChangeEventPending = false;
|
|
|
|
SendTextChange();
|
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
// If a text change notification causes another text change again, we should
|
|
|
|
// notify IME of that before sending a selection change notification.
|
|
|
|
if (!mIMEContentObserver->mIsTextChangeEventPending) {
|
|
|
|
// Be aware, PuppetWidget depends on the order of this. A selection change
|
|
|
|
// notification should not be sent before a text change notification because
|
|
|
|
// PuppetWidget shouldn't query new text content every selection change.
|
|
|
|
if (mIMEContentObserver->mIsSelectionChangeEventPending) {
|
|
|
|
mIMEContentObserver->mIsSelectionChangeEventPending = false;
|
|
|
|
SendSelectionChange();
|
|
|
|
}
|
2015-09-16 11:48:24 +03:00
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
// If a text change notification causes another text change again or a
|
|
|
|
// selection change notification causes either a text change or another
|
|
|
|
// selection change, we should notify IME of those before sending a position
|
|
|
|
// change notification.
|
|
|
|
if (!mIMEContentObserver->mIsTextChangeEventPending &&
|
|
|
|
!mIMEContentObserver->mIsSelectionChangeEventPending) {
|
|
|
|
if (mIMEContentObserver->mIsPositionChangeEventPending) {
|
|
|
|
mIMEContentObserver->mIsPositionChangeEventPending = false;
|
|
|
|
SendPositionChange();
|
|
|
|
}
|
2015-09-16 11:48:24 +03:00
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
// If notifications caused some new change, we should notify them now.
|
|
|
|
mIMEContentObserver->mIsFlushingPendingNotifications =
|
|
|
|
mIMEContentObserver->NeedsToNotifyIMEOfSomething();
|
|
|
|
if (mIMEContentObserver->mIsFlushingPendingNotifications) {
|
2015-09-16 11:48:24 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::Run(), "
|
|
|
|
"posting AsyncMergeableNotificationsFlusher to current thread", this));
|
|
|
|
nsRefPtr<AsyncMergeableNotificationsFlusher> asyncFlusher =
|
|
|
|
new AsyncMergeableNotificationsFlusher(mIMEContentObserver);
|
|
|
|
NS_DispatchToCurrentThread(asyncFlusher);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IMEContentObserver::IMENotificationSender::SendFocusSet()
|
|
|
|
{
|
|
|
|
if (!CanNotifyIME(eChangeEventType_Focus)) {
|
2015-06-17 04:03:57 +03:00
|
|
|
// If IMEContentObserver has already gone, we don't need to notify IME of
|
|
|
|
// focus.
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendFocusSet(), FAILED, due to impossible to notify IME of focus",
|
|
|
|
this));
|
2015-06-17 04:03:57 +03:00
|
|
|
mIMEContentObserver->ClearPendingNotifications();
|
2015-09-16 11:48:24 +03:00
|
|
|
return;
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
if (!IsSafeToNotifyIME(eChangeEventType_Focus)) {
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendFocusSet(), retrying to send NOTIFY_IME_OF_FOCUS...", this));
|
2015-06-17 04:03:57 +03:00
|
|
|
mIMEContentObserver->PostFocusSetNotification();
|
2015-09-16 11:48:24 +03:00
|
|
|
return;
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
mIMEContentObserver->mIMEHasFocus = true;
|
2015-08-21 19:43:42 +03:00
|
|
|
// Initialize selection cache with the first selection data.
|
|
|
|
mIMEContentObserver->UpdateSelectionCache();
|
2015-09-08 06:54:14 +03:00
|
|
|
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Info,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendFocusSet(), sending NOTIFY_IME_OF_FOCUS...", this));
|
2015-09-08 06:54:14 +03:00
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mIMEContentObserver->mSendingNotification ==
|
|
|
|
NOTIFY_IME_OF_NOTHING);
|
|
|
|
mIMEContentObserver->mSendingNotification = NOTIFY_IME_OF_FOCUS;
|
2015-06-27 03:23:31 +03:00
|
|
|
IMEStateManager::NotifyIME(IMENotification(NOTIFY_IME_OF_FOCUS),
|
|
|
|
mIMEContentObserver->mWidget);
|
2015-09-16 11:48:24 +03:00
|
|
|
mIMEContentObserver->mSendingNotification = NOTIFY_IME_OF_NOTHING;
|
2015-09-08 06:54:14 +03:00
|
|
|
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendFocusSet(), sent NOTIFY_IME_OF_FOCUS", this));
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
void
|
|
|
|
IMEContentObserver::IMENotificationSender::SendSelectionChange()
|
2015-06-17 04:03:57 +03:00
|
|
|
{
|
2015-09-16 11:48:24 +03:00
|
|
|
if (!CanNotifyIME(eChangeEventType_Selection)) {
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendSelectionChange(), FAILED, due to impossible to notify IME of "
|
|
|
|
"selection change", this));
|
|
|
|
return;
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
if (!IsSafeToNotifyIME(eChangeEventType_Selection)) {
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendSelectionChange(), retrying to send "
|
|
|
|
"NOTIFY_IME_OF_SELECTION_CHANGE...", this));
|
2015-09-14 17:28:43 +03:00
|
|
|
mIMEContentObserver->PostSelectionChangeNotification();
|
2015-09-16 11:48:24 +03:00
|
|
|
return;
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-08-21 19:43:42 +03:00
|
|
|
SelectionChangeData lastSelChangeData = mIMEContentObserver->mSelectionData;
|
2015-08-21 19:43:41 +03:00
|
|
|
if (NS_WARN_IF(!mIMEContentObserver->UpdateSelectionCache())) {
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Error,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendSelectionChange(), FAILED, due to UpdateSelectionCache() failure",
|
|
|
|
this));
|
|
|
|
return;
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-08-21 19:43:42 +03:00
|
|
|
// If the IME doesn't want selection change notifications caused by
|
|
|
|
// composition, we should do nothing anymore.
|
2015-09-14 17:28:43 +03:00
|
|
|
SelectionChangeData& newSelChangeData = mIMEContentObserver->mSelectionData;
|
|
|
|
if (newSelChangeData.mCausedByComposition &&
|
2015-08-21 19:43:42 +03:00
|
|
|
!mIMEContentObserver->
|
|
|
|
mUpdatePreference.WantChangesCausedByComposition()) {
|
2015-09-16 11:48:24 +03:00
|
|
|
return;
|
2015-08-21 19:43:42 +03:00
|
|
|
}
|
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
// The state may be changed since querying content causes flushing layout.
|
2015-09-16 11:48:24 +03:00
|
|
|
if (!CanNotifyIME(eChangeEventType_Selection)) {
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendSelectionChange(), FAILED, due to flushing layout having changed "
|
|
|
|
"something", this));
|
|
|
|
return;
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-08-21 19:43:42 +03:00
|
|
|
// If the selection isn't changed actually, we shouldn't notify IME of
|
|
|
|
// selection change.
|
|
|
|
if (lastSelChangeData.IsValid() &&
|
|
|
|
lastSelChangeData.mOffset == newSelChangeData.mOffset &&
|
|
|
|
lastSelChangeData.String() == newSelChangeData.String() &&
|
|
|
|
lastSelChangeData.GetWritingMode() == newSelChangeData.GetWritingMode() &&
|
|
|
|
lastSelChangeData.mReversed == newSelChangeData.mReversed) {
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendSelectionChange(), not notifying IME of "
|
|
|
|
"NOTIFY_IME_OF_SELECTION_CHANGE due to not changed actually", this));
|
|
|
|
return;
|
2015-08-21 19:43:42 +03:00
|
|
|
}
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Info,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendSelectionChange(), sending NOTIFY_IME_OF_SELECTION_CHANGE... "
|
|
|
|
"newSelChangeData=%s",
|
2015-09-08 06:54:14 +03:00
|
|
|
this, SelectionChangeDataToString(newSelChangeData).get()));
|
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
IMENotification notification(NOTIFY_IME_OF_SELECTION_CHANGE);
|
2015-09-14 17:28:43 +03:00
|
|
|
notification.SetData(mIMEContentObserver->mSelectionData);
|
2015-09-16 11:48:24 +03:00
|
|
|
|
|
|
|
MOZ_RELEASE_ASSERT(mIMEContentObserver->mSendingNotification ==
|
|
|
|
NOTIFY_IME_OF_NOTHING);
|
|
|
|
mIMEContentObserver->mSendingNotification = NOTIFY_IME_OF_SELECTION_CHANGE;
|
2015-06-27 03:23:31 +03:00
|
|
|
IMEStateManager::NotifyIME(notification, mIMEContentObserver->mWidget);
|
2015-09-16 11:48:24 +03:00
|
|
|
mIMEContentObserver->mSendingNotification = NOTIFY_IME_OF_NOTHING;
|
2015-09-08 06:54:14 +03:00
|
|
|
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendSelectionChange(), sent NOTIFY_IME_OF_SELECTION_CHANGE", this));
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
void
|
|
|
|
IMEContentObserver::IMENotificationSender::SendTextChange()
|
2015-06-17 04:03:57 +03:00
|
|
|
{
|
2015-09-16 11:48:24 +03:00
|
|
|
if (!CanNotifyIME(eChangeEventType_Text)) {
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendTextChange(), FAILED, due to impossible to notify IME of text "
|
|
|
|
"change", this));
|
|
|
|
return;
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
if (!IsSafeToNotifyIME(eChangeEventType_Text)) {
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendTextChange(), retrying to send NOTIFY_IME_OF_TEXT_CHANGE...",
|
|
|
|
this));
|
2015-09-16 11:48:23 +03:00
|
|
|
mIMEContentObserver->PostTextChangeNotification();
|
2015-09-16 11:48:24 +03:00
|
|
|
return;
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Info,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendTextChange(), sending NOTIFY_IME_OF_TEXT_CHANGE... "
|
|
|
|
"mIMEContentObserver={ mTextChangeData=%s }",
|
2015-09-16 11:48:23 +03:00
|
|
|
this, TextChangeDataToString(mIMEContentObserver->mTextChangeData).get()));
|
2015-09-08 06:54:14 +03:00
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
IMENotification notification(NOTIFY_IME_OF_TEXT_CHANGE);
|
2015-09-16 11:48:23 +03:00
|
|
|
notification.SetData(mIMEContentObserver->mTextChangeData);
|
|
|
|
mIMEContentObserver->mTextChangeData.Clear();
|
2015-09-16 11:48:24 +03:00
|
|
|
|
|
|
|
MOZ_RELEASE_ASSERT(mIMEContentObserver->mSendingNotification ==
|
|
|
|
NOTIFY_IME_OF_NOTHING);
|
|
|
|
mIMEContentObserver->mSendingNotification = NOTIFY_IME_OF_TEXT_CHANGE;
|
2015-06-27 03:23:31 +03:00
|
|
|
IMEStateManager::NotifyIME(notification, mIMEContentObserver->mWidget);
|
2015-09-16 11:48:24 +03:00
|
|
|
mIMEContentObserver->mSendingNotification = NOTIFY_IME_OF_NOTHING;
|
2015-09-08 06:54:14 +03:00
|
|
|
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendTextChange(), sent NOTIFY_IME_OF_TEXT_CHANGE", this));
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
void
|
|
|
|
IMEContentObserver::IMENotificationSender::SendPositionChange()
|
2015-06-17 04:03:57 +03:00
|
|
|
{
|
2015-09-16 11:48:24 +03:00
|
|
|
if (!CanNotifyIME(eChangeEventType_Position)) {
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendPositionChange(), FAILED, due to impossible to notify IME of "
|
|
|
|
"position change", this));
|
|
|
|
return;
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
if (!IsSafeToNotifyIME(eChangeEventType_Position)) {
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendPositionChange(), retrying to send "
|
|
|
|
"NOTIFY_IME_OF_POSITION_CHANGE...", this));
|
2015-06-17 04:03:57 +03:00
|
|
|
mIMEContentObserver->PostPositionChangeNotification();
|
2015-09-16 11:48:24 +03:00
|
|
|
return;
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Info,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendPositionChange(), sending NOTIFY_IME_OF_POSITION_CHANGE...", this));
|
2015-09-08 06:54:14 +03:00
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mIMEContentObserver->mSendingNotification ==
|
|
|
|
NOTIFY_IME_OF_NOTHING);
|
|
|
|
mIMEContentObserver->mSendingNotification = NOTIFY_IME_OF_POSITION_CHANGE;
|
2015-06-27 03:23:31 +03:00
|
|
|
IMEStateManager::NotifyIME(IMENotification(NOTIFY_IME_OF_POSITION_CHANGE),
|
|
|
|
mIMEContentObserver->mWidget);
|
2015-09-16 11:48:24 +03:00
|
|
|
mIMEContentObserver->mSendingNotification = NOTIFY_IME_OF_NOTHING;
|
2015-09-08 06:54:14 +03:00
|
|
|
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
2015-09-16 11:48:24 +03:00
|
|
|
("IMECO: 0x%p IMEContentObserver::IMENotificationSender::"
|
|
|
|
"SendPositionChange(), sent NOTIFY_IME_OF_POSITION_CHANGE", this));
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* mozilla::IMEContentObserver::AsyncMergeableNotificationsFlusher
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IMEContentObserver::AsyncMergeableNotificationsFlusher::Run()
|
|
|
|
{
|
2015-09-16 11:48:24 +03:00
|
|
|
if (!CanNotifyIME(eChangeEventType_FlushPendingEvents)) {
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::AsyncMergeableNotificationsFlusher::"
|
|
|
|
"Run(), FAILED, due to impossible to flush pending notifications",
|
|
|
|
this));
|
2015-06-17 04:03:57 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Info,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::AsyncMergeableNotificationsFlusher::"
|
|
|
|
"Run(), calling FlushMergeableNotifications()...", this));
|
|
|
|
|
2015-06-17 04:03:57 +03:00
|
|
|
mIMEContentObserver->FlushMergeableNotifications();
|
2015-09-08 06:54:14 +03:00
|
|
|
|
|
|
|
MOZ_LOG(sIMECOLog, LogLevel::Debug,
|
|
|
|
("IMECO: 0x%p IMEContentObserver::AsyncMergeableNotificationsFlusher::"
|
|
|
|
"Run(), called FlushMergeableNotifications()", this));
|
2015-06-17 04:03:57 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
} // namespace mozilla
|