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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_IMEContentObserver_h_
|
|
|
|
#define mozilla_IMEContentObserver_h_
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2014-04-24 04:36:14 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2014-03-08 05:20:07 +04:00
|
|
|
#include "nsIDocShell.h" // XXX Why does only this need to be included here?
|
2014-07-31 08:37:59 +04:00
|
|
|
#include "nsIEditor.h"
|
|
|
|
#include "nsIEditorObserver.h"
|
2014-03-08 05:20:07 +04:00
|
|
|
#include "nsIReflowObserver.h"
|
|
|
|
#include "nsISelectionListener.h"
|
|
|
|
#include "nsIScrollObserver.h"
|
2017-04-11 15:24:55 +03:00
|
|
|
#include "nsIWidget.h"
|
2014-03-08 05:20:07 +04:00
|
|
|
#include "nsStubMutationObserver.h"
|
2015-06-17 04:03:57 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2014-03-08 05:20:07 +04:00
|
|
|
#include "nsWeakReference.h"
|
|
|
|
|
|
|
|
class nsIContent;
|
|
|
|
class nsINode;
|
|
|
|
class nsISelection;
|
|
|
|
class nsPresContext;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-04-24 04:36:15 +04:00
|
|
|
class EventStateManager;
|
Bug 1275906 part.2 TextComposition should use IMEContentObserver for sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED if the editor which has the composition is in the active IMEContentObserver r=smaug
For sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED after the other change notifications which was caused by the user input, we need to use IMEContentObserver::IMENotificationSender because it sends the notifications when it's safe to do it.
This patch makes TextComposition use IMEContentObserver to send the notification. However, if there is no active IMEContentObserver, e.g., composition events are fired on unfocused window, TextComposition sends it by itself (same as current implementation).
If IMEContentObserver stops observing when it has pending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED, it cannot send the notification (i.e., it is discarded completely in such case). However, in such case, IMEContentObserver sends NOTIFY_IME_OF_BLUR. So, anyway, native IME handler should treat the blur notification as it including NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED.
On the other hand, we're buggy if composition events are fired in non-active window. Even in such case, IMEContentObserver should be created for active editor in each document and it notifies IME of the changes. But this is out of the scope of this bug.
MozReview-Commit-ID: 7Q0ZsJTh4hX
--HG--
extra : rebase_source : 6417f991fa8c0fbe3f25b27bacf4257e5485aecc
2016-06-01 16:14:41 +03:00
|
|
|
class TextComposition;
|
2014-04-24 04:36:15 +04:00
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
// IMEContentObserver notifies widget of any text and selection changes
|
|
|
|
// in the currently focused editor
|
2015-03-21 19:28:04 +03:00
|
|
|
class IMEContentObserver final : public nsISelectionListener
|
2015-03-27 21:52:19 +03:00
|
|
|
, public nsStubMutationObserver
|
|
|
|
, public nsIReflowObserver
|
|
|
|
, public nsIScrollObserver
|
|
|
|
, public nsSupportsWeakReference
|
|
|
|
, public nsIEditorObserver
|
2014-03-08 05:20:07 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-12-02 07:20:00 +03:00
|
|
|
typedef ContentEventHandler::NodePosition NodePosition;
|
2015-12-02 07:20:00 +03:00
|
|
|
typedef ContentEventHandler::NodePositionBefore NodePositionBefore;
|
2015-08-21 19:43:41 +03:00
|
|
|
typedef widget::IMENotification::SelectionChangeData SelectionChangeData;
|
2015-07-11 04:53:56 +03:00
|
|
|
typedef widget::IMENotification::TextChangeData TextChangeData;
|
|
|
|
typedef widget::IMENotification::TextChangeDataBase TextChangeDataBase;
|
2017-04-11 15:24:55 +03:00
|
|
|
typedef widget::IMENotificationRequests IMENotificationRequests;
|
2015-09-16 11:48:24 +03:00
|
|
|
typedef widget::IMEMessage IMEMessage;
|
2015-07-11 04:53:56 +03:00
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
IMEContentObserver();
|
|
|
|
|
2014-04-24 04:36:14 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(IMEContentObserver,
|
|
|
|
nsISelectionListener)
|
2014-07-31 08:37:59 +04:00
|
|
|
NS_DECL_NSIEDITOROBSERVER
|
2014-03-08 05:20:07 +04:00
|
|
|
NS_DECL_NSISELECTIONLISTENER
|
2014-07-31 08:38:01 +04:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATAWILLCHANGE
|
2014-03-08 05:20:07 +04:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
|
|
|
NS_DECL_NSIREFLOWOBSERVER
|
|
|
|
|
|
|
|
// nsIScrollObserver
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ScrollPositionChanged() override;
|
2014-03-08 05:20:07 +04:00
|
|
|
|
2014-08-29 14:08:43 +04:00
|
|
|
bool OnMouseButtonEvent(nsPresContext* aPresContext,
|
|
|
|
WidgetMouseEvent* aMouseEvent);
|
|
|
|
|
2015-09-08 06:54:14 +03:00
|
|
|
nsresult HandleQueryContentEvent(WidgetQueryContentEvent* aEvent);
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
void 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
|
|
|
void Destroy();
|
2014-04-24 04:36:15 +04:00
|
|
|
/**
|
|
|
|
* IMEContentObserver is stored by EventStateManager during observing.
|
|
|
|
* DisconnectFromEventStateManager() is called when EventStateManager stops
|
|
|
|
* storing the instance.
|
|
|
|
*/
|
|
|
|
void DisconnectFromEventStateManager();
|
2015-05-26 10:45:26 +03:00
|
|
|
/**
|
|
|
|
* MaybeReinitialize() tries to restart to observe the editor's root node.
|
|
|
|
* This is useful when the editor is reframed and all children are replaced
|
|
|
|
* with new node instances.
|
|
|
|
* @return Returns true if the instance is managing the content.
|
|
|
|
* Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool MaybeReinitialize(nsIWidget* aWidget,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIEditor* aEditor);
|
Bug 1275906 part.2 TextComposition should use IMEContentObserver for sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED if the editor which has the composition is in the active IMEContentObserver r=smaug
For sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED after the other change notifications which was caused by the user input, we need to use IMEContentObserver::IMENotificationSender because it sends the notifications when it's safe to do it.
This patch makes TextComposition use IMEContentObserver to send the notification. However, if there is no active IMEContentObserver, e.g., composition events are fired on unfocused window, TextComposition sends it by itself (same as current implementation).
If IMEContentObserver stops observing when it has pending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED, it cannot send the notification (i.e., it is discarded completely in such case). However, in such case, IMEContentObserver sends NOTIFY_IME_OF_BLUR. So, anyway, native IME handler should treat the blur notification as it including NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED.
On the other hand, we're buggy if composition events are fired in non-active window. Even in such case, IMEContentObserver should be created for active editor in each document and it notifies IME of the changes. But this is out of the scope of this bug.
MozReview-Commit-ID: 7Q0ZsJTh4hX
--HG--
extra : rebase_source : 6417f991fa8c0fbe3f25b27bacf4257e5485aecc
2016-06-01 16:14:41 +03:00
|
|
|
bool IsManaging(nsPresContext* aPresContext, nsIContent* aContent) const;
|
|
|
|
bool IsManaging(const TextComposition* aTextComposition) const;
|
2016-06-28 09:23:12 +03:00
|
|
|
bool WasInitializedWithPlugin() const;
|
2014-03-08 05:20:07 +04:00
|
|
|
bool IsEditorHandlingEventForComposition() const;
|
|
|
|
bool KeepAliveDuringDeactive() const
|
2014-03-08 05:20:07 +04:00
|
|
|
{
|
2017-04-11 15:24:55 +03:00
|
|
|
return mIMENotificationRequests.WantDuringDeactive();
|
2014-03-08 05:20:07 +04:00
|
|
|
}
|
2014-03-08 05:20:07 +04:00
|
|
|
nsIWidget* GetWidget() const { return mWidget; }
|
2015-06-04 20:06:10 +03:00
|
|
|
nsIEditor* GetEditor() const { return mEditor; }
|
2015-09-08 06:54:14 +03:00
|
|
|
void SuppressNotifyingIME();
|
|
|
|
void UnsuppressNotifyingIME();
|
2015-05-15 04:18:08 +03:00
|
|
|
nsPresContext* GetPresContext() const;
|
2014-03-08 05:20:07 +04:00
|
|
|
nsresult GetSelectionAndRoot(nsISelection** aSelection,
|
|
|
|
nsIContent** aRoot) const;
|
2014-03-08 05:20:07 +04:00
|
|
|
|
2015-11-10 05:49:05 +03:00
|
|
|
/**
|
|
|
|
* TryToFlushPendingNotifications() should be called when pending events
|
|
|
|
* should be flushed. This tries to run the queued IMENotificationSender.
|
|
|
|
*/
|
|
|
|
void TryToFlushPendingNotifications();
|
|
|
|
|
Bug 1275906 part.2 TextComposition should use IMEContentObserver for sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED if the editor which has the composition is in the active IMEContentObserver r=smaug
For sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED after the other change notifications which was caused by the user input, we need to use IMEContentObserver::IMENotificationSender because it sends the notifications when it's safe to do it.
This patch makes TextComposition use IMEContentObserver to send the notification. However, if there is no active IMEContentObserver, e.g., composition events are fired on unfocused window, TextComposition sends it by itself (same as current implementation).
If IMEContentObserver stops observing when it has pending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED, it cannot send the notification (i.e., it is discarded completely in such case). However, in such case, IMEContentObserver sends NOTIFY_IME_OF_BLUR. So, anyway, native IME handler should treat the blur notification as it including NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED.
On the other hand, we're buggy if composition events are fired in non-active window. Even in such case, IMEContentObserver should be created for active editor in each document and it notifies IME of the changes. But this is out of the scope of this bug.
MozReview-Commit-ID: 7Q0ZsJTh4hX
--HG--
extra : rebase_source : 6417f991fa8c0fbe3f25b27bacf4257e5485aecc
2016-06-01 16:14:41 +03:00
|
|
|
/**
|
|
|
|
* MaybeNotifyCompositionEventHandled() posts composition event handled
|
|
|
|
* notification into the pseudo queue.
|
|
|
|
*/
|
|
|
|
void MaybeNotifyCompositionEventHandled();
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
private:
|
2014-06-23 23:56:07 +04:00
|
|
|
~IMEContentObserver() {}
|
|
|
|
|
2015-05-26 10:45:26 +03:00
|
|
|
enum State {
|
|
|
|
eState_NotObserving,
|
2015-05-26 10:45:26 +03:00
|
|
|
eState_Initializing,
|
2015-05-26 10:45:26 +03:00
|
|
|
eState_StoppedObserving,
|
|
|
|
eState_Observing
|
|
|
|
};
|
|
|
|
State GetState() const;
|
2015-10-10 04:21:01 +03:00
|
|
|
bool InitWithEditor(nsPresContext* aPresContext, nsIContent* aContent,
|
|
|
|
nsIEditor* aEditor);
|
|
|
|
bool InitWithPlugin(nsPresContext* aPresContext, nsIContent* aContent);
|
|
|
|
bool IsInitializedWithPlugin() const { return !mEditor; }
|
2015-11-10 05:49:04 +03:00
|
|
|
void OnIMEReceivedFocus();
|
2015-10-10 04:21:01 +03:00
|
|
|
void Clear();
|
2015-05-26 10:45:26 +03:00
|
|
|
bool IsObservingContent(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent) const;
|
2015-06-17 04:03:57 +03:00
|
|
|
bool IsReflowLocked() const;
|
|
|
|
bool IsSafeToNotifyIME() const;
|
2015-10-27 01:21:37 +03:00
|
|
|
bool IsEditorComposing() const;
|
2015-06-17 04:03:57 +03:00
|
|
|
|
|
|
|
void PostFocusSetNotification();
|
2015-09-08 06:54:14 +03:00
|
|
|
void MaybeNotifyIMEOfFocusSet();
|
2015-09-16 11:48:23 +03:00
|
|
|
void PostTextChangeNotification();
|
2015-09-08 06:54:14 +03:00
|
|
|
void MaybeNotifyIMEOfTextChange(const TextChangeDataBase& aTextChangeData);
|
2015-09-14 17:28:43 +03:00
|
|
|
void PostSelectionChangeNotification();
|
2015-07-17 05:25:00 +03:00
|
|
|
void MaybeNotifyIMEOfSelectionChange(bool aCausedByComposition,
|
2015-10-27 01:21:37 +03:00
|
|
|
bool aCausedBySelectionEvent,
|
|
|
|
bool aOccurredDuringComposition);
|
2015-06-17 04:03:57 +03:00
|
|
|
void PostPositionChangeNotification();
|
2015-09-08 06:54:14 +03:00
|
|
|
void MaybeNotifyIMEOfPositionChange();
|
Bug 1275906 part.2 TextComposition should use IMEContentObserver for sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED if the editor which has the composition is in the active IMEContentObserver r=smaug
For sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED after the other change notifications which was caused by the user input, we need to use IMEContentObserver::IMENotificationSender because it sends the notifications when it's safe to do it.
This patch makes TextComposition use IMEContentObserver to send the notification. However, if there is no active IMEContentObserver, e.g., composition events are fired on unfocused window, TextComposition sends it by itself (same as current implementation).
If IMEContentObserver stops observing when it has pending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED, it cannot send the notification (i.e., it is discarded completely in such case). However, in such case, IMEContentObserver sends NOTIFY_IME_OF_BLUR. So, anyway, native IME handler should treat the blur notification as it including NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED.
On the other hand, we're buggy if composition events are fired in non-active window. Even in such case, IMEContentObserver should be created for active editor in each document and it notifies IME of the changes. But this is out of the scope of this bug.
MozReview-Commit-ID: 7Q0ZsJTh4hX
--HG--
extra : rebase_source : 6417f991fa8c0fbe3f25b27bacf4257e5485aecc
2016-06-01 16:14:41 +03:00
|
|
|
void PostCompositionEventHandledNotification();
|
2014-07-31 08:38:00 +04:00
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
void NotifyContentAdded(nsINode* aContainer, int32_t aStart, int32_t aEnd);
|
|
|
|
void ObserveEditableNode();
|
2014-07-31 08:37:59 +04:00
|
|
|
/**
|
2015-05-26 10:45:26 +03:00
|
|
|
* NotifyIMEOfBlur() notifies IME of blur.
|
2015-05-24 04:11:37 +03:00
|
|
|
*/
|
2015-05-26 10:45:26 +03:00
|
|
|
void NotifyIMEOfBlur();
|
2015-05-26 10:45:26 +03:00
|
|
|
/**
|
|
|
|
* UnregisterObservers() unregisters all listeners and observers.
|
|
|
|
*/
|
|
|
|
void UnregisterObservers();
|
2014-07-31 08:37:59 +04:00
|
|
|
void FlushMergeableNotifications();
|
2015-06-17 04:03:57 +03:00
|
|
|
void ClearPendingNotifications()
|
|
|
|
{
|
2015-09-16 11:48:24 +03:00
|
|
|
mNeedsToNotifyIMEOfFocusSet = false;
|
|
|
|
mNeedsToNotifyIMEOfTextChange = false;
|
|
|
|
mNeedsToNotifyIMEOfSelectionChange = false;
|
|
|
|
mNeedsToNotifyIMEOfPositionChange = false;
|
Bug 1275906 part.2 TextComposition should use IMEContentObserver for sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED if the editor which has the composition is in the active IMEContentObserver r=smaug
For sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED after the other change notifications which was caused by the user input, we need to use IMEContentObserver::IMENotificationSender because it sends the notifications when it's safe to do it.
This patch makes TextComposition use IMEContentObserver to send the notification. However, if there is no active IMEContentObserver, e.g., composition events are fired on unfocused window, TextComposition sends it by itself (same as current implementation).
If IMEContentObserver stops observing when it has pending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED, it cannot send the notification (i.e., it is discarded completely in such case). However, in such case, IMEContentObserver sends NOTIFY_IME_OF_BLUR. So, anyway, native IME handler should treat the blur notification as it including NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED.
On the other hand, we're buggy if composition events are fired in non-active window. Even in such case, IMEContentObserver should be created for active editor in each document and it notifies IME of the changes. But this is out of the scope of this bug.
MozReview-Commit-ID: 7Q0ZsJTh4hX
--HG--
extra : rebase_source : 6417f991fa8c0fbe3f25b27bacf4257e5485aecc
2016-06-01 16:14:41 +03:00
|
|
|
mNeedsToNotifyIMEOfCompositionEventHandled = false;
|
2015-07-11 04:53:56 +03:00
|
|
|
mTextChangeData.Clear();
|
2015-06-17 04:03:57 +03:00
|
|
|
}
|
2015-09-16 11:48:24 +03:00
|
|
|
bool NeedsToNotifyIMEOfSomething() const
|
|
|
|
{
|
2015-09-16 11:48:24 +03:00
|
|
|
return mNeedsToNotifyIMEOfFocusSet ||
|
|
|
|
mNeedsToNotifyIMEOfTextChange ||
|
|
|
|
mNeedsToNotifyIMEOfSelectionChange ||
|
Bug 1275906 part.2 TextComposition should use IMEContentObserver for sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED if the editor which has the composition is in the active IMEContentObserver r=smaug
For sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED after the other change notifications which was caused by the user input, we need to use IMEContentObserver::IMENotificationSender because it sends the notifications when it's safe to do it.
This patch makes TextComposition use IMEContentObserver to send the notification. However, if there is no active IMEContentObserver, e.g., composition events are fired on unfocused window, TextComposition sends it by itself (same as current implementation).
If IMEContentObserver stops observing when it has pending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED, it cannot send the notification (i.e., it is discarded completely in such case). However, in such case, IMEContentObserver sends NOTIFY_IME_OF_BLUR. So, anyway, native IME handler should treat the blur notification as it including NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED.
On the other hand, we're buggy if composition events are fired in non-active window. Even in such case, IMEContentObserver should be created for active editor in each document and it notifies IME of the changes. But this is out of the scope of this bug.
MozReview-Commit-ID: 7Q0ZsJTh4hX
--HG--
extra : rebase_source : 6417f991fa8c0fbe3f25b27bacf4257e5485aecc
2016-06-01 16:14:41 +03:00
|
|
|
mNeedsToNotifyIMEOfPositionChange ||
|
|
|
|
mNeedsToNotifyIMEOfCompositionEventHandled;
|
2015-09-16 11:48:24 +03:00
|
|
|
}
|
2014-07-31 08:37:59 +04:00
|
|
|
|
2015-08-21 19:43:41 +03:00
|
|
|
/**
|
|
|
|
* UpdateSelectionCache() updates mSelectionData with the latest selection.
|
|
|
|
* This should be called only when IsSafeToNotifyIME() returns true.
|
|
|
|
*
|
2016-06-28 09:23:12 +03:00
|
|
|
* Note that this does nothing if WasInitializedWithPlugin() returns true.
|
2015-08-21 19:43:41 +03:00
|
|
|
*/
|
|
|
|
bool UpdateSelectionCache();
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
2015-09-08 06:54:14 +03:00
|
|
|
// mFocusedWidget has the editor observed by the instance. E.g., if the
|
|
|
|
// focused editor is in XUL panel, this should be the widget of the panel.
|
|
|
|
// On the other hand, mWidget is its parent which handles IME.
|
|
|
|
nsCOMPtr<nsIWidget> mFocusedWidget;
|
2014-03-08 05:20:07 +04:00
|
|
|
nsCOMPtr<nsISelection> mSelection;
|
|
|
|
nsCOMPtr<nsIContent> mRootContent;
|
|
|
|
nsCOMPtr<nsINode> mEditableNode;
|
|
|
|
nsCOMPtr<nsIDocShell> mDocShell;
|
2014-07-31 08:37:59 +04:00
|
|
|
nsCOMPtr<nsIEditor> mEditor;
|
2014-04-24 04:36:15 +04:00
|
|
|
|
2015-11-10 05:49:05 +03:00
|
|
|
/**
|
|
|
|
* Helper classes to notify IME.
|
|
|
|
*/
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class AChangeEvent: public Runnable
|
2015-11-10 05:49:05 +03:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
enum ChangeEventType
|
|
|
|
{
|
|
|
|
eChangeEventType_Focus,
|
|
|
|
eChangeEventType_Selection,
|
|
|
|
eChangeEventType_Text,
|
|
|
|
eChangeEventType_Position,
|
Bug 1275906 part.2 TextComposition should use IMEContentObserver for sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED if the editor which has the composition is in the active IMEContentObserver r=smaug
For sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED after the other change notifications which was caused by the user input, we need to use IMEContentObserver::IMENotificationSender because it sends the notifications when it's safe to do it.
This patch makes TextComposition use IMEContentObserver to send the notification. However, if there is no active IMEContentObserver, e.g., composition events are fired on unfocused window, TextComposition sends it by itself (same as current implementation).
If IMEContentObserver stops observing when it has pending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED, it cannot send the notification (i.e., it is discarded completely in such case). However, in such case, IMEContentObserver sends NOTIFY_IME_OF_BLUR. So, anyway, native IME handler should treat the blur notification as it including NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED.
On the other hand, we're buggy if composition events are fired in non-active window. Even in such case, IMEContentObserver should be created for active editor in each document and it notifies IME of the changes. But this is out of the scope of this bug.
MozReview-Commit-ID: 7Q0ZsJTh4hX
--HG--
extra : rebase_source : 6417f991fa8c0fbe3f25b27bacf4257e5485aecc
2016-06-01 16:14:41 +03:00
|
|
|
eChangeEventType_CompositionEventHandled
|
2015-11-10 05:49:05 +03:00
|
|
|
};
|
|
|
|
|
2017-02-11 09:11:48 +03:00
|
|
|
explicit AChangeEvent(const char* aName,
|
|
|
|
IMEContentObserver* aIMEContentObserver)
|
|
|
|
: Runnable(aName)
|
|
|
|
, mIMEContentObserver(aIMEContentObserver)
|
2015-11-10 05:49:05 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIMEContentObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IMEContentObserver> mIMEContentObserver;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CanNotifyIME() checks if mIMEContentObserver can and should notify IME.
|
|
|
|
*/
|
|
|
|
bool CanNotifyIME(ChangeEventType aChangeEventType) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IsSafeToNotifyIME() checks if it's safe to noitify IME.
|
|
|
|
*/
|
|
|
|
bool IsSafeToNotifyIME(ChangeEventType aChangeEventType) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class IMENotificationSender: public AChangeEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit IMENotificationSender(IMEContentObserver* aIMEContentObserver)
|
2017-02-11 09:11:48 +03:00
|
|
|
: AChangeEvent("IMENotificationSender", aIMEContentObserver)
|
2015-11-10 05:49:05 +03:00
|
|
|
, mIsRunning(false)
|
2015-11-10 05:49:05 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
NS_IMETHOD Run() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void SendFocusSet();
|
|
|
|
void SendSelectionChange();
|
|
|
|
void SendTextChange();
|
|
|
|
void SendPositionChange();
|
Bug 1275906 part.2 TextComposition should use IMEContentObserver for sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED if the editor which has the composition is in the active IMEContentObserver r=smaug
For sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED after the other change notifications which was caused by the user input, we need to use IMEContentObserver::IMENotificationSender because it sends the notifications when it's safe to do it.
This patch makes TextComposition use IMEContentObserver to send the notification. However, if there is no active IMEContentObserver, e.g., composition events are fired on unfocused window, TextComposition sends it by itself (same as current implementation).
If IMEContentObserver stops observing when it has pending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED, it cannot send the notification (i.e., it is discarded completely in such case). However, in such case, IMEContentObserver sends NOTIFY_IME_OF_BLUR. So, anyway, native IME handler should treat the blur notification as it including NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED.
On the other hand, we're buggy if composition events are fired in non-active window. Even in such case, IMEContentObserver should be created for active editor in each document and it notifies IME of the changes. But this is out of the scope of this bug.
MozReview-Commit-ID: 7Q0ZsJTh4hX
--HG--
extra : rebase_source : 6417f991fa8c0fbe3f25b27bacf4257e5485aecc
2016-06-01 16:14:41 +03:00
|
|
|
void SendCompositionEventHandled();
|
2015-11-10 05:49:05 +03:00
|
|
|
|
|
|
|
bool mIsRunning;
|
2015-11-10 05:49:05 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// mQueuedSender is, it was put into the event queue but not run yet.
|
|
|
|
RefPtr<IMENotificationSender> mQueuedSender;
|
|
|
|
|
2014-07-31 08:38:00 +04:00
|
|
|
/**
|
|
|
|
* FlatTextCache stores flat text length from start of the content to
|
|
|
|
* mNodeOffset of mContainerNode.
|
|
|
|
*/
|
|
|
|
struct FlatTextCache
|
|
|
|
{
|
|
|
|
// mContainerNode and mNodeOffset represent a point in DOM tree. E.g.,
|
|
|
|
// if mContainerNode is a div element, mNodeOffset is index of its child.
|
|
|
|
nsCOMPtr<nsINode> mContainerNode;
|
|
|
|
int32_t mNodeOffset;
|
|
|
|
// Length of flat text generated from contents between the start of content
|
|
|
|
// and a child node whose index is mNodeOffset of mContainerNode.
|
|
|
|
uint32_t mFlatTextLength;
|
|
|
|
|
|
|
|
FlatTextCache()
|
|
|
|
: mNodeOffset(0)
|
|
|
|
, mFlatTextLength(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mContainerNode = nullptr;
|
|
|
|
mNodeOffset = 0;
|
|
|
|
mFlatTextLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cache(nsINode* aContainer, int32_t aNodeOffset,
|
|
|
|
uint32_t aFlatTextLength)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aContainer, "aContainer must not be null");
|
|
|
|
MOZ_ASSERT(
|
|
|
|
aNodeOffset <= static_cast<int32_t>(aContainer->GetChildCount()),
|
|
|
|
"aNodeOffset must be same as or less than the count of children");
|
|
|
|
mContainerNode = aContainer;
|
|
|
|
mNodeOffset = aNodeOffset;
|
|
|
|
mFlatTextLength = aFlatTextLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Match(nsINode* aContainer, int32_t aNodeOffset) const
|
|
|
|
{
|
|
|
|
return aContainer == mContainerNode && aNodeOffset == mNodeOffset;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// mEndOfAddedTextCache caches text length from the start of content to
|
|
|
|
// the end of the last added content only while an edit action is being
|
|
|
|
// handled by the editor and no other mutation (e.g., removing node)
|
|
|
|
// occur.
|
|
|
|
FlatTextCache mEndOfAddedTextCache;
|
2014-07-31 08:38:00 +04:00
|
|
|
// mStartOfRemovingTextRangeCache caches text length from the start of content
|
|
|
|
// to the start of the last removed content only while an edit action is being
|
|
|
|
// handled by the editor and no other mutation (e.g., adding node) occur.
|
|
|
|
FlatTextCache mStartOfRemovingTextRangeCache;
|
2014-07-31 08:38:00 +04:00
|
|
|
|
2014-07-31 08:37:59 +04:00
|
|
|
TextChangeData mTextChangeData;
|
|
|
|
|
2015-09-14 17:28:43 +03:00
|
|
|
// mSelectionData is the last selection data which was notified. The
|
|
|
|
// selection information is modified by UpdateSelectionCache(). The reason
|
|
|
|
// of the selection change is modified by MaybeNotifyIMEOfSelectionChange().
|
2015-08-21 19:43:41 +03:00
|
|
|
SelectionChangeData mSelectionData;
|
|
|
|
|
2014-04-24 04:36:15 +04:00
|
|
|
EventStateManager* mESM;
|
|
|
|
|
2017-04-11 15:24:55 +03:00
|
|
|
IMENotificationRequests mIMENotificationRequests;
|
2014-03-08 05:20:07 +04:00
|
|
|
uint32_t mPreAttrChangeLength;
|
2015-06-04 20:06:10 +03:00
|
|
|
uint32_t mSuppressNotifications;
|
2014-07-31 08:38:01 +04:00
|
|
|
int64_t mPreCharacterDataChangeLength;
|
2014-07-31 08:37:59 +04:00
|
|
|
|
2015-09-16 11:48:24 +03:00
|
|
|
// mSendingNotification is a notification which is now sending from
|
|
|
|
// IMENotificationSender. When the value is NOTIFY_IME_OF_NOTHING, it's
|
|
|
|
// not sending any notification.
|
|
|
|
IMEMessage mSendingNotification;
|
|
|
|
|
2015-05-26 10:45:26 +03:00
|
|
|
bool mIsObserving;
|
2015-06-17 04:03:57 +03:00
|
|
|
bool mIMEHasFocus;
|
2015-09-16 11:48:24 +03:00
|
|
|
bool mNeedsToNotifyIMEOfFocusSet;
|
|
|
|
bool mNeedsToNotifyIMEOfTextChange;
|
|
|
|
bool mNeedsToNotifyIMEOfSelectionChange;
|
|
|
|
bool mNeedsToNotifyIMEOfPositionChange;
|
Bug 1275906 part.2 TextComposition should use IMEContentObserver for sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED if the editor which has the composition is in the active IMEContentObserver r=smaug
For sending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED after the other change notifications which was caused by the user input, we need to use IMEContentObserver::IMENotificationSender because it sends the notifications when it's safe to do it.
This patch makes TextComposition use IMEContentObserver to send the notification. However, if there is no active IMEContentObserver, e.g., composition events are fired on unfocused window, TextComposition sends it by itself (same as current implementation).
If IMEContentObserver stops observing when it has pending NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED, it cannot send the notification (i.e., it is discarded completely in such case). However, in such case, IMEContentObserver sends NOTIFY_IME_OF_BLUR. So, anyway, native IME handler should treat the blur notification as it including NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED.
On the other hand, we're buggy if composition events are fired in non-active window. Even in such case, IMEContentObserver should be created for active editor in each document and it notifies IME of the changes. But this is out of the scope of this bug.
MozReview-Commit-ID: 7Q0ZsJTh4hX
--HG--
extra : rebase_source : 6417f991fa8c0fbe3f25b27bacf4257e5485aecc
2016-06-01 16:14:41 +03:00
|
|
|
bool mNeedsToNotifyIMEOfCompositionEventHandled;
|
2015-09-16 11:48:24 +03:00
|
|
|
// mIsHandlingQueryContentEvent is true when IMEContentObserver is handling
|
|
|
|
// WidgetQueryContentEvent with ContentEventHandler.
|
|
|
|
bool mIsHandlingQueryContentEvent;
|
2014-03-08 05:20:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-03-08 05:20:07 +04:00
|
|
|
#endif // mozilla_IMEContentObserver_h_
|