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: */
|
2012-09-26 09:47:45 +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_TextComposition_h
|
|
|
|
#define mozilla_TextComposition_h
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsINode.h"
|
2014-02-12 17:02:56 +04:00
|
|
|
#include "nsIWeakReference.h"
|
2013-09-14 06:39:41 +04:00
|
|
|
#include "nsIWidget.h"
|
2012-09-26 09:47:45 +04:00
|
|
|
#include "nsTArray.h"
|
2012-09-26 09:47:51 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2013-11-07 04:11:11 +04:00
|
|
|
#include "nsPresContext.h"
|
2012-09-26 09:47:45 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-24 14:04:14 +04:00
|
|
|
#include "mozilla/EventForwards.h"
|
2014-03-04 17:48:26 +04:00
|
|
|
#include "mozilla/TextRange.h"
|
2015-07-03 05:49:36 +03:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2012-09-26 09:47:45 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2017-06-20 13:23:44 +03:00
|
|
|
class EditorBase;
|
2014-03-18 08:48:20 +04:00
|
|
|
class EventDispatchingCallback;
|
2014-03-08 05:20:07 +04:00
|
|
|
class IMEStateManager;
|
|
|
|
|
2012-09-26 09:47:45 +04:00
|
|
|
/**
|
|
|
|
* TextComposition represents a text composition. This class stores the
|
|
|
|
* composition event target and its presContext. At dispatching the event via
|
|
|
|
* this class, the instances use the stored event target.
|
|
|
|
*/
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class TextComposition final
|
2012-09-26 09:47:45 +04:00
|
|
|
{
|
2014-03-08 05:20:07 +04:00
|
|
|
friend class IMEStateManager;
|
2014-01-28 12:19:29 +04:00
|
|
|
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(TextComposition)
|
|
|
|
|
2012-09-26 09:47:45 +04:00
|
|
|
public:
|
2015-07-03 05:49:36 +03:00
|
|
|
typedef dom::TabParent TabParent;
|
|
|
|
|
2015-07-17 05:25:00 +03:00
|
|
|
static bool IsHandlingSelectionEvent() { return sHandlingSelectionEvent; }
|
|
|
|
|
2012-09-26 09:47:45 +04:00
|
|
|
TextComposition(nsPresContext* aPresContext,
|
|
|
|
nsINode* aNode,
|
2015-07-03 05:49:36 +03:00
|
|
|
TabParent* aTabParent,
|
2014-10-07 14:01:49 +04:00
|
|
|
WidgetCompositionEvent* aCompositionEvent);
|
2012-09-26 09:47:45 +04:00
|
|
|
|
2014-02-25 10:59:28 +04:00
|
|
|
bool Destroyed() const { return !mPresContext; }
|
2012-09-26 09:47:45 +04:00
|
|
|
nsPresContext* GetPresContext() const { return mPresContext; }
|
|
|
|
nsINode* GetEventTargetNode() const { return mNode; }
|
2012-09-26 09:47:51 +04:00
|
|
|
// The latest CompositionEvent.data value except compositionstart event.
|
2014-02-12 17:02:56 +04:00
|
|
|
// This value is modified at dispatching compositionupdate.
|
|
|
|
const nsString& LastData() const { return mLastData; }
|
|
|
|
// The composition string which is already handled by the focused editor.
|
|
|
|
// I.e., this value must be same as the composition string on the focused
|
2014-10-07 14:01:49 +04:00
|
|
|
// editor. This value is modified at a call of
|
|
|
|
// EditorDidHandleCompositionChangeEvent().
|
2014-02-12 17:02:56 +04:00
|
|
|
// Note that mString and mLastData are different between dispatcing
|
2014-10-07 14:01:47 +04:00
|
|
|
// compositionupdate and compositionchange event handled by focused editor.
|
2014-02-12 17:02:56 +04:00
|
|
|
const nsString& String() const { return mString; }
|
2015-12-29 16:57:38 +03:00
|
|
|
// The latest clauses range of the composition string.
|
|
|
|
// During compositionupdate event, GetRanges() returns old ranges.
|
|
|
|
// So if getting on compositionupdate, Use GetLastRange instead of GetRange().
|
|
|
|
TextRangeArray* GetLastRanges() const { return mLastRanges; }
|
2014-03-04 17:48:26 +04:00
|
|
|
// Returns the clauses and/or caret range of the composition string.
|
2014-10-07 14:01:49 +04:00
|
|
|
// This is modified at a call of EditorWillHandleCompositionChangeEvent().
|
2014-03-04 17:48:26 +04:00
|
|
|
// This may return null if there is no clauses and caret.
|
|
|
|
// XXX We should return |const TextRangeArray*| here, but it causes compile
|
|
|
|
// error due to inaccessible Release() method.
|
|
|
|
TextRangeArray* GetRanges() const { return mRanges; }
|
2014-09-26 04:05:11 +04:00
|
|
|
// Returns the widget which is proper to call NotifyIME().
|
|
|
|
nsIWidget* GetWidget() const
|
|
|
|
{
|
|
|
|
return mPresContext ? mPresContext->GetRootWidget() : nullptr;
|
|
|
|
}
|
2017-07-05 18:47:40 +03:00
|
|
|
// Returns the tab parent which has this composition in its remote process.
|
|
|
|
TabParent* GetTabParent() const
|
|
|
|
{
|
|
|
|
return mTabParent;
|
|
|
|
}
|
2012-09-26 09:47:51 +04:00
|
|
|
// Returns true if the composition is started with synthesized event which
|
|
|
|
// came from nsDOMWindowUtils.
|
|
|
|
bool IsSynthesizedForTests() const { return mIsSynthesizedForTests; }
|
2012-09-26 09:47:45 +04:00
|
|
|
|
2015-12-11 09:15:57 +03:00
|
|
|
const widget::NativeIMEContext& GetNativeIMEContext() const
|
|
|
|
{
|
|
|
|
return mNativeContext;
|
|
|
|
}
|
2012-09-26 09:47:45 +04:00
|
|
|
|
2014-02-25 10:59:28 +04:00
|
|
|
/**
|
2014-03-08 05:20:07 +04:00
|
|
|
* This is called when IMEStateManager stops managing the instance.
|
2014-02-25 10:59:28 +04:00
|
|
|
*/
|
|
|
|
void Destroy();
|
|
|
|
|
2012-09-26 09:47:51 +04:00
|
|
|
/**
|
2014-09-26 04:05:11 +04:00
|
|
|
* Request to commit (or cancel) the composition to IME. This method should
|
|
|
|
* be called only by IMEStateManager::NotifyIME().
|
2012-09-26 09:47:51 +04:00
|
|
|
*/
|
2014-09-26 04:05:11 +04:00
|
|
|
nsresult RequestToCommit(nsIWidget* aWidget, bool aDiscard);
|
2012-09-26 09:47:51 +04:00
|
|
|
|
2017-11-20 16:59:04 +03:00
|
|
|
/**
|
|
|
|
* IsRequestingCommitOrCancelComposition() returns true if the instance is
|
|
|
|
* requesting widget to commit or cancel composition.
|
|
|
|
*/
|
|
|
|
bool IsRequestingCommitOrCancelComposition() const
|
|
|
|
{
|
|
|
|
return mIsRequestingCancel || mIsRequestingCommit;
|
|
|
|
}
|
|
|
|
|
2012-09-26 09:47:51 +04:00
|
|
|
/**
|
|
|
|
* Send a notification to IME. It depends on the IME or platform spec what
|
|
|
|
* will occur (or not occur).
|
|
|
|
*/
|
2014-02-18 04:00:15 +04:00
|
|
|
nsresult NotifyIME(widget::IMEMessage aMessage);
|
2012-09-26 09:47:51 +04:00
|
|
|
|
2014-09-15 11:11:08 +04:00
|
|
|
/**
|
|
|
|
* the offset of first composition string
|
|
|
|
*/
|
|
|
|
uint32_t NativeOffsetOfStartComposition() const
|
|
|
|
{
|
|
|
|
return mCompositionStartOffset;
|
|
|
|
}
|
|
|
|
|
2013-11-07 04:11:11 +04:00
|
|
|
/**
|
2016-06-02 08:26:47 +03:00
|
|
|
* the offset of first selected clause or start of composition
|
2013-11-07 04:11:11 +04:00
|
|
|
*/
|
2016-06-02 08:26:47 +03:00
|
|
|
uint32_t NativeOffsetOfTargetClause() const
|
|
|
|
{
|
|
|
|
return mCompositionStartOffset + mTargetClauseOffsetInComposition;
|
|
|
|
}
|
2013-11-07 04:11:11 +04:00
|
|
|
|
2014-02-12 17:02:56 +04:00
|
|
|
/**
|
|
|
|
* Returns true if there is non-empty composition string and it's not fixed.
|
|
|
|
* Otherwise, false.
|
|
|
|
*/
|
|
|
|
bool IsComposing() const { return mIsComposing; }
|
|
|
|
|
2014-02-26 04:48:02 +04:00
|
|
|
/**
|
|
|
|
* Returns true while editor is handling an event which is modifying the
|
|
|
|
* composition string.
|
|
|
|
*/
|
|
|
|
bool IsEditorHandlingEvent() const
|
|
|
|
{
|
|
|
|
return mIsEditorHandlingEvent;
|
|
|
|
}
|
|
|
|
|
2014-02-12 17:02:56 +04:00
|
|
|
/**
|
|
|
|
* StartHandlingComposition() and EndHandlingComposition() are called by
|
|
|
|
* editor when it holds a TextComposition instance and release it.
|
|
|
|
*/
|
2017-06-20 13:23:44 +03:00
|
|
|
void StartHandlingComposition(EditorBase* aEditorBase);
|
|
|
|
void EndHandlingComposition(EditorBase* aEditorBase);
|
2014-02-12 17:02:56 +04:00
|
|
|
|
2015-06-04 20:06:09 +03:00
|
|
|
/**
|
|
|
|
* OnEditorDestroyed() is called when the editor is destroyed but there is
|
|
|
|
* active composition.
|
|
|
|
*/
|
|
|
|
void OnEditorDestroyed();
|
|
|
|
|
2014-02-12 17:02:57 +04:00
|
|
|
/**
|
2014-10-07 14:01:49 +04:00
|
|
|
* CompositionChangeEventHandlingMarker class should be created at starting
|
|
|
|
* to handle text event in focused editor. This calls
|
|
|
|
* EditorWillHandleCompositionChangeEvent() and
|
|
|
|
* EditorDidHandleCompositionChangeEvent() automatically.
|
2014-02-12 17:02:57 +04:00
|
|
|
*/
|
2014-10-07 14:01:49 +04:00
|
|
|
class MOZ_STACK_CLASS CompositionChangeEventHandlingMarker
|
2014-02-12 17:02:57 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-10-07 14:01:49 +04:00
|
|
|
CompositionChangeEventHandlingMarker(
|
2014-10-07 14:01:49 +04:00
|
|
|
TextComposition* aComposition,
|
|
|
|
const WidgetCompositionEvent* aCompositionChangeEvent)
|
2014-02-12 17:02:57 +04:00
|
|
|
: mComposition(aComposition)
|
|
|
|
{
|
2014-10-07 14:01:49 +04:00
|
|
|
mComposition->EditorWillHandleCompositionChangeEvent(
|
|
|
|
aCompositionChangeEvent);
|
2014-02-12 17:02:57 +04:00
|
|
|
}
|
|
|
|
|
2014-10-07 14:01:49 +04:00
|
|
|
~CompositionChangeEventHandlingMarker()
|
2014-02-12 17:02:57 +04:00
|
|
|
{
|
2014-10-07 14:01:49 +04:00
|
|
|
mComposition->EditorDidHandleCompositionChangeEvent();
|
2014-02-12 17:02:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextComposition> mComposition;
|
2014-10-07 14:01:49 +04:00
|
|
|
CompositionChangeEventHandlingMarker();
|
|
|
|
CompositionChangeEventHandlingMarker(
|
|
|
|
const CompositionChangeEventHandlingMarker& aOther);
|
2014-02-12 17:02:57 +04:00
|
|
|
};
|
|
|
|
|
2012-09-26 09:47:45 +04:00
|
|
|
private:
|
2014-04-02 20:21:03 +04:00
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
2017-06-27 16:02:07 +03:00
|
|
|
~TextComposition()
|
|
|
|
{
|
|
|
|
// WARNING: mPresContext may be destroying, so, be careful if you touch it.
|
|
|
|
}
|
2014-04-02 20:21:03 +04:00
|
|
|
|
2015-07-17 05:25:00 +03:00
|
|
|
// sHandlingSelectionEvent is true while TextComposition sends a selection
|
|
|
|
// event to ContentEventHandler.
|
|
|
|
static bool sHandlingSelectionEvent;
|
|
|
|
|
2012-09-26 09:47:45 +04:00
|
|
|
// This class holds nsPresContext weak. This instance shouldn't block
|
|
|
|
// destroying it. When the presContext is being destroyed, it's notified to
|
2014-03-08 05:20:07 +04:00
|
|
|
// IMEStateManager::OnDestroyPresContext(), and then, it destroy
|
2012-09-26 09:47:45 +04:00
|
|
|
// this instance.
|
|
|
|
nsPresContext* mPresContext;
|
|
|
|
nsCOMPtr<nsINode> mNode;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TabParent> mTabParent;
|
2012-09-26 09:47:45 +04:00
|
|
|
|
2014-03-04 17:48:26 +04:00
|
|
|
// This is the clause and caret range information which is managed by
|
|
|
|
// the focused editor. This may be null if there is no clauses or caret.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextRangeArray> mRanges;
|
2015-12-29 16:57:38 +03:00
|
|
|
// Same as mRange, but mRange will have old data during compositionupdate.
|
|
|
|
// So this will be valied during compositionupdate.
|
|
|
|
RefPtr<TextRangeArray> mLastRanges;
|
2014-03-04 17:48:26 +04:00
|
|
|
|
2012-09-26 09:47:45 +04:00
|
|
|
// mNativeContext stores a opaque pointer. This works as the "ID" for this
|
|
|
|
// composition. Don't access the instance, it may not be available.
|
2015-12-11 09:15:57 +03:00
|
|
|
widget::NativeIMEContext mNativeContext;
|
2012-09-26 09:47:45 +04:00
|
|
|
|
2017-06-20 13:23:44 +03:00
|
|
|
// mEditorBaseWeak is a weak reference to the focused editor handling
|
|
|
|
// composition.
|
|
|
|
nsWeakPtr mEditorBaseWeak;
|
2014-02-12 17:02:56 +04:00
|
|
|
|
2012-09-26 09:47:51 +04:00
|
|
|
// mLastData stores the data attribute of the latest composition event (except
|
|
|
|
// the compositionstart event).
|
|
|
|
nsString mLastData;
|
|
|
|
|
2014-02-12 17:02:56 +04:00
|
|
|
// mString stores the composition text which has been handled by the focused
|
|
|
|
// editor.
|
|
|
|
nsString mString;
|
|
|
|
|
2013-11-07 04:11:11 +04:00
|
|
|
// Offset of the composition string from start of the editor
|
|
|
|
uint32_t mCompositionStartOffset;
|
2016-06-02 08:26:47 +03:00
|
|
|
// Offset of the selected clause of the composition string from
|
|
|
|
// mCompositionStartOffset
|
|
|
|
uint32_t mTargetClauseOffsetInComposition;
|
2013-11-07 04:11:11 +04:00
|
|
|
|
2012-09-26 09:47:51 +04:00
|
|
|
// See the comment for IsSynthesizedForTests().
|
|
|
|
bool mIsSynthesizedForTests;
|
|
|
|
|
2014-02-12 17:02:56 +04:00
|
|
|
// See the comment for IsComposing().
|
|
|
|
bool mIsComposing;
|
|
|
|
|
2014-02-26 04:48:02 +04:00
|
|
|
// mIsEditorHandlingEvent is true while editor is modifying the composition
|
|
|
|
// string.
|
|
|
|
bool mIsEditorHandlingEvent;
|
|
|
|
|
2014-09-26 04:05:11 +04:00
|
|
|
// mIsRequestingCommit or mIsRequestingCancel is true *only* while we're
|
|
|
|
// requesting commit or canceling the composition. In other words, while
|
|
|
|
// one of these values is true, we're handling the request.
|
|
|
|
bool mIsRequestingCommit;
|
|
|
|
bool mIsRequestingCancel;
|
|
|
|
|
|
|
|
// mRequestedToCommitOrCancel is true *after* we requested IME to commit or
|
|
|
|
// cancel the composition. In other words, we already requested of IME that
|
|
|
|
// it commits or cancels current composition.
|
2017-11-20 16:59:04 +03:00
|
|
|
// NOTE: Before this is set to true, both mIsRequestingCommit and
|
|
|
|
// mIsRequestingCancel are set to false.
|
2014-09-26 04:05:11 +04:00
|
|
|
bool mRequestedToCommitOrCancel;
|
|
|
|
|
2017-11-20 16:59:04 +03:00
|
|
|
// Before this dispatches commit event into the tree, this is set to true.
|
|
|
|
// So, this means if native IME already commits the composition.
|
|
|
|
bool mHasReceivedCommitEvent;
|
|
|
|
|
2014-09-26 04:05:12 +04:00
|
|
|
// mWasNativeCompositionEndEventDiscarded is true if this composition was
|
|
|
|
// requested commit or cancel itself but native compositionend event is
|
|
|
|
// discarded by PresShell due to not safe to dispatch events.
|
|
|
|
bool mWasNativeCompositionEndEventDiscarded;
|
|
|
|
|
2015-05-01 07:49:29 +03:00
|
|
|
// Allow control characters appear in composition string.
|
|
|
|
// When this is false, control characters except
|
|
|
|
// CHARACTER TABULATION (horizontal tab) are removed from
|
|
|
|
// both composition string and data attribute of compositionupdate
|
|
|
|
// and compositionend events.
|
|
|
|
bool mAllowControlCharacters;
|
|
|
|
|
2016-06-10 13:32:49 +03:00
|
|
|
// mWasCompositionStringEmpty is true if the composition string was empty
|
|
|
|
// when DispatchCompositionEvent() is called.
|
|
|
|
bool mWasCompositionStringEmpty;
|
|
|
|
|
2014-01-28 12:19:29 +04:00
|
|
|
// Hide the default constructor and copy constructor.
|
2016-01-12 21:16:59 +03:00
|
|
|
TextComposition()
|
|
|
|
: mPresContext(nullptr)
|
|
|
|
, mNativeContext(nullptr)
|
|
|
|
, mCompositionStartOffset(0)
|
2016-06-02 08:26:47 +03:00
|
|
|
, mTargetClauseOffsetInComposition(0)
|
2016-01-12 21:16:59 +03:00
|
|
|
, mIsSynthesizedForTests(false)
|
|
|
|
, mIsComposing(false)
|
|
|
|
, mIsEditorHandlingEvent(false)
|
|
|
|
, mIsRequestingCommit(false)
|
|
|
|
, mIsRequestingCancel(false)
|
|
|
|
, mRequestedToCommitOrCancel(false)
|
2017-11-20 16:59:04 +03:00
|
|
|
, mHasReceivedCommitEvent(false)
|
2016-01-12 21:16:59 +03:00
|
|
|
, mWasNativeCompositionEndEventDiscarded(false)
|
|
|
|
, mAllowControlCharacters(false)
|
2016-06-10 13:32:49 +03:00
|
|
|
, mWasCompositionStringEmpty(true)
|
2016-01-12 21:16:59 +03:00
|
|
|
{}
|
2014-01-28 12:19:29 +04:00
|
|
|
TextComposition(const TextComposition& aOther);
|
|
|
|
|
2017-11-20 16:59:04 +03:00
|
|
|
/**
|
|
|
|
* If we're requesting IME to commit or cancel composition, or we've already
|
|
|
|
* requested it, or we've already known this composition has been ended in
|
|
|
|
* IME, we don't need to request commit nor cancel composition anymore and
|
|
|
|
* shouldn't do so if we're in content process for not committing/canceling
|
|
|
|
* "current" composition in native IME. So, when this returns true,
|
|
|
|
* RequestIMEToCommit() does nothing.
|
|
|
|
*/
|
|
|
|
bool CanRequsetIMEToCommitOrCancelComposition() const
|
|
|
|
{
|
|
|
|
return !mIsRequestingCommit && !mIsRequestingCancel &&
|
|
|
|
!mRequestedToCommitOrCancel && !mHasReceivedCommitEvent;
|
|
|
|
}
|
|
|
|
|
2014-02-12 17:02:56 +04:00
|
|
|
/**
|
2017-06-20 13:23:44 +03:00
|
|
|
* GetEditorBase() returns EditorBase pointer of mEditorBaseWeak.
|
2014-02-12 17:02:56 +04:00
|
|
|
*/
|
2017-06-20 13:23:44 +03:00
|
|
|
already_AddRefed<EditorBase> GetEditorBase() const;
|
2014-02-12 17:02:56 +04:00
|
|
|
|
|
|
|
/**
|
2017-06-20 13:23:44 +03:00
|
|
|
* HasEditor() returns true if mEditorBaseWeak holds EditorBase instance
|
|
|
|
* which is alive. Otherwise, false.
|
2014-02-12 17:02:56 +04:00
|
|
|
*/
|
|
|
|
bool HasEditor() const;
|
2012-09-26 09:47:45 +04:00
|
|
|
|
|
|
|
/**
|
2014-10-07 14:01:49 +04:00
|
|
|
* EditorWillHandleCompositionChangeEvent() must be called before the focused
|
|
|
|
* editor handles the compositionchange event.
|
2014-02-12 17:02:57 +04:00
|
|
|
*/
|
2014-10-07 14:01:49 +04:00
|
|
|
void EditorWillHandleCompositionChangeEvent(
|
2014-10-07 14:01:49 +04:00
|
|
|
const WidgetCompositionEvent* aCompositionChangeEvent);
|
2014-02-12 17:02:57 +04:00
|
|
|
|
|
|
|
/**
|
2014-10-07 14:01:49 +04:00
|
|
|
* EditorDidHandleCompositionChangeEvent() must be called after the focused
|
|
|
|
* editor handles a compositionchange event.
|
2014-02-12 17:02:57 +04:00
|
|
|
*/
|
2014-10-07 14:01:49 +04:00
|
|
|
void EditorDidHandleCompositionChangeEvent();
|
2014-02-12 17:02:57 +04:00
|
|
|
|
2014-11-25 08:02:29 +03:00
|
|
|
/**
|
|
|
|
* IsValidStateForComposition() returns true if it's safe to dispatch an event
|
|
|
|
* to the DOM tree. Otherwise, false.
|
|
|
|
* WARNING: This doesn't check script blocker state. It should be checked
|
|
|
|
* before dispatching the first event.
|
|
|
|
*/
|
|
|
|
bool IsValidStateForComposition(nsIWidget* aWidget) const;
|
|
|
|
|
2014-02-12 17:02:57 +04:00
|
|
|
/**
|
2014-10-07 14:01:49 +04:00
|
|
|
* DispatchCompositionEvent() dispatches the aCompositionEvent to the mContent
|
|
|
|
* synchronously. The caller must ensure that it's safe to dispatch the event.
|
2012-09-26 09:47:45 +04:00
|
|
|
*/
|
2014-10-07 14:01:49 +04:00
|
|
|
void DispatchCompositionEvent(WidgetCompositionEvent* aCompositionEvent,
|
|
|
|
nsEventStatus* aStatus,
|
|
|
|
EventDispatchingCallback* aCallBack,
|
|
|
|
bool aIsSynthesized);
|
2012-09-26 09:47:51 +04:00
|
|
|
|
2015-12-29 16:57:37 +03:00
|
|
|
/**
|
|
|
|
* Simply calling EventDispatcher::Dispatch() with plugin event.
|
|
|
|
* If dispatching event has no orginal clone, aOriginalEvent can be null.
|
|
|
|
*/
|
|
|
|
void DispatchEvent(WidgetCompositionEvent* aDispatchEvent,
|
|
|
|
nsEventStatus* aStatus,
|
|
|
|
EventDispatchingCallback* aCallback,
|
|
|
|
const WidgetCompositionEvent *aOriginalEvent = nullptr);
|
|
|
|
|
2015-07-17 05:25:00 +03:00
|
|
|
/**
|
|
|
|
* HandleSelectionEvent() sends the selection event to ContentEventHandler
|
|
|
|
* or dispatches it to the focused child process.
|
|
|
|
*/
|
|
|
|
void HandleSelectionEvent(WidgetSelectionEvent* aSelectionEvent)
|
|
|
|
{
|
|
|
|
HandleSelectionEvent(mPresContext, mTabParent, aSelectionEvent);
|
|
|
|
}
|
|
|
|
static void HandleSelectionEvent(nsPresContext* aPresContext,
|
|
|
|
TabParent* aTabParent,
|
|
|
|
WidgetSelectionEvent* aSelectionEvent);
|
|
|
|
|
2014-09-26 04:05:12 +04:00
|
|
|
/**
|
|
|
|
* MaybeDispatchCompositionUpdate() may dispatch a compositionupdate event
|
2014-10-07 14:01:49 +04:00
|
|
|
* if aCompositionEvent changes composition string.
|
2014-09-26 04:05:12 +04:00
|
|
|
* @return Returns false if dispatching the compositionupdate event caused
|
|
|
|
* destroying this composition.
|
|
|
|
*/
|
2014-10-07 14:01:49 +04:00
|
|
|
bool MaybeDispatchCompositionUpdate(
|
|
|
|
const WidgetCompositionEvent* aCompositionEvent);
|
2014-09-26 04:05:12 +04:00
|
|
|
|
2014-11-25 08:02:30 +03:00
|
|
|
/**
|
|
|
|
* CloneAndDispatchAs() dispatches a composition event which is
|
|
|
|
* duplicateed from aCompositionEvent and set the aMessage.
|
2014-11-25 08:02:31 +03:00
|
|
|
*
|
|
|
|
* @return Returns BaseEventFlags which is the result of dispatched event.
|
2014-11-25 08:02:30 +03:00
|
|
|
*/
|
2014-11-25 08:02:31 +03:00
|
|
|
BaseEventFlags CloneAndDispatchAs(
|
|
|
|
const WidgetCompositionEvent* aCompositionEvent,
|
2015-08-26 15:56:59 +03:00
|
|
|
EventMessage aMessage,
|
2014-11-25 08:02:31 +03:00
|
|
|
nsEventStatus* aStatus = nullptr,
|
|
|
|
EventDispatchingCallback* aCallBack = nullptr);
|
2014-11-25 08:02:30 +03:00
|
|
|
|
2014-09-26 04:05:12 +04:00
|
|
|
/**
|
|
|
|
* If IME has already dispatched compositionend event but it was discarded
|
|
|
|
* by PresShell due to not safe to dispatch, this returns true.
|
|
|
|
*/
|
|
|
|
bool WasNativeCompositionEndEventDiscarded() const
|
|
|
|
{
|
|
|
|
return mWasNativeCompositionEndEventDiscarded;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* OnCompositionEventDiscarded() is called when PresShell discards
|
2014-10-07 14:01:47 +04:00
|
|
|
* compositionupdate, compositionend or compositionchange event due to not
|
|
|
|
* safe to dispatch event.
|
2014-09-26 04:05:12 +04:00
|
|
|
*/
|
2015-07-03 05:49:36 +03:00
|
|
|
void OnCompositionEventDiscarded(WidgetCompositionEvent* aCompositionEvent);
|
2014-09-26 04:05:12 +04:00
|
|
|
|
2013-11-07 04:11:11 +04:00
|
|
|
/**
|
2016-06-10 13:32:49 +03:00
|
|
|
* OnCompositionEventDispatched() is called after a composition event is
|
|
|
|
* dispatched.
|
|
|
|
*/
|
|
|
|
void OnCompositionEventDispatched(
|
|
|
|
const WidgetCompositionEvent* aDispatchEvent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MaybeNotifyIMEOfCompositionEventHandled() notifies IME of composition
|
|
|
|
* event handled. This should be called after dispatching a composition
|
|
|
|
* event which came from widget.
|
2013-11-07 04:11:11 +04:00
|
|
|
*/
|
2016-06-10 13:32:49 +03:00
|
|
|
void MaybeNotifyIMEOfCompositionEventHandled(
|
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
|
|
|
const WidgetCompositionEvent* aCompositionEvent);
|
2013-11-07 04:11:11 +04:00
|
|
|
|
2016-06-10 13:45:21 +03:00
|
|
|
/**
|
|
|
|
* GetSelectionStartOffset() returns normal selection start offset in the
|
|
|
|
* editor which has this composition.
|
|
|
|
* If it failed or lost focus, this would return 0.
|
|
|
|
*/
|
|
|
|
uint32_t GetSelectionStartOffset();
|
|
|
|
|
2016-06-14 15:06:34 +03:00
|
|
|
/**
|
|
|
|
* OnStartOffsetUpdatedInChild() is called when composition start offset
|
|
|
|
* is updated in the child process. I.e., this is called and never called
|
|
|
|
* if the composition is in this process.
|
|
|
|
* @param aStartOffset New composition start offset with native
|
|
|
|
* linebreaks.
|
|
|
|
*/
|
|
|
|
void OnStartOffsetUpdatedInChild(uint32_t aStartOffset);
|
|
|
|
|
2012-09-26 09:47:51 +04:00
|
|
|
/**
|
|
|
|
* CompositionEventDispatcher dispatches the specified composition (or text)
|
|
|
|
* event.
|
|
|
|
*/
|
2016-04-26 03:23:21 +03:00
|
|
|
class CompositionEventDispatcher : public Runnable
|
2012-09-26 09:47:51 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-09-26 04:05:11 +04:00
|
|
|
CompositionEventDispatcher(TextComposition* aTextComposition,
|
2012-09-26 09:47:51 +04:00
|
|
|
nsINode* aEventTarget,
|
2015-08-26 15:56:59 +03:00
|
|
|
EventMessage aEventMessage,
|
2014-09-26 04:05:11 +04:00
|
|
|
const nsAString& aData,
|
|
|
|
bool aIsSynthesizedEvent = false);
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override;
|
2012-09-26 09:47:51 +04:00
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TextComposition> mTextComposition;
|
2012-09-26 09:47:51 +04:00
|
|
|
nsCOMPtr<nsINode> mEventTarget;
|
|
|
|
nsString mData;
|
2015-08-26 15:56:59 +03:00
|
|
|
EventMessage mEventMessage;
|
2014-09-26 04:05:11 +04:00
|
|
|
bool mIsSynthesizedEvent;
|
2012-09-26 09:47:51 +04:00
|
|
|
|
2017-06-12 22:34:10 +03:00
|
|
|
CompositionEventDispatcher()
|
|
|
|
: Runnable("TextComposition::CompositionEventDispatcher")
|
|
|
|
, mIsSynthesizedEvent(false){};
|
2012-09-26 09:47:51 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-10-07 14:01:47 +04:00
|
|
|
* DispatchCompositionEventRunnable() dispatches a composition event to the
|
|
|
|
* content. Be aware, if you use this method, nsPresShellEventCB isn't used.
|
|
|
|
* That means that nsIFrame::HandleEvent() is never called.
|
2014-03-08 05:20:07 +04:00
|
|
|
* WARNING: The instance which is managed by IMEStateManager may be
|
2012-09-26 09:47:51 +04:00
|
|
|
* destroyed by this method call.
|
|
|
|
*
|
2014-10-07 14:01:47 +04:00
|
|
|
* @param aEventMessage Must be one of composition events.
|
|
|
|
* @param aData Used for mData value.
|
2014-09-26 04:05:11 +04:00
|
|
|
* @param aIsSynthesizingCommit true if this is called for synthesizing
|
|
|
|
* commit or cancel composition. Otherwise,
|
|
|
|
* false.
|
2012-09-26 09:47:51 +04:00
|
|
|
*/
|
2015-08-26 15:56:59 +03:00
|
|
|
void DispatchCompositionEventRunnable(EventMessage aEventMessage,
|
2014-09-26 04:05:11 +04:00
|
|
|
const nsAString& aData,
|
|
|
|
bool aIsSynthesizingCommit = false);
|
2012-09-26 09:47:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TextCompositionArray manages the instances of TextComposition class.
|
|
|
|
* Managing with array is enough because only one composition is typically
|
|
|
|
* there. Even if user switches native IME context, it's very rare that
|
|
|
|
* second or more composition is started.
|
2014-03-08 05:20:07 +04:00
|
|
|
* It's assumed that this is used by IMEStateManager for storing all active
|
2012-09-26 09:47:45 +04:00
|
|
|
* compositions in the process. If the instance is it, each TextComposition
|
|
|
|
* in the array can be destroyed by calling some methods of itself.
|
|
|
|
*/
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class TextCompositionArray final :
|
2016-02-02 18:36:30 +03:00
|
|
|
public AutoTArray<RefPtr<TextComposition>, 2>
|
2012-09-26 09:47:45 +04:00
|
|
|
{
|
|
|
|
public:
|
2015-12-04 12:50:34 +03:00
|
|
|
// Looking for per native IME context.
|
2015-12-11 09:15:57 +03:00
|
|
|
index_type IndexOf(const widget::NativeIMEContext& aNativeIMEContext);
|
2012-09-26 09:47:45 +04:00
|
|
|
index_type IndexOf(nsIWidget* aWidget);
|
2015-12-04 12:50:34 +03:00
|
|
|
|
|
|
|
TextComposition* GetCompositionFor(nsIWidget* aWidget);
|
|
|
|
TextComposition* GetCompositionFor(
|
|
|
|
const WidgetCompositionEvent* aCompositionEvent);
|
|
|
|
|
|
|
|
// Looking for per nsPresContext
|
2012-09-26 09:47:45 +04:00
|
|
|
index_type IndexOf(nsPresContext* aPresContext);
|
|
|
|
index_type IndexOf(nsPresContext* aPresContext, nsINode* aNode);
|
|
|
|
|
2015-12-04 12:50:43 +03:00
|
|
|
TextComposition* GetCompositionFor(nsPresContext* aPresContext);
|
2012-09-26 09:47:45 +04:00
|
|
|
TextComposition* GetCompositionFor(nsPresContext* aPresContext,
|
|
|
|
nsINode* aNode);
|
|
|
|
TextComposition* GetCompositionInContent(nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // #ifndef mozilla_TextComposition_h
|