mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1053048 Implement nsIEditor.isInEditAction readonly attribute r=ehsan, sr=smaug
This commit is contained in:
parent
de1f9dee1c
commit
877aa4d8fb
@ -664,8 +664,6 @@ public:
|
||||
void SettingValue(bool aValue) { mSettingValue = aValue; }
|
||||
void SetValueChanged(bool aSetValueChanged) { mSetValueChanged = aSetValueChanged; }
|
||||
|
||||
bool IsInEditAction() const { return mInEditAction; }
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSISELECTIONLISTENER
|
||||
@ -710,10 +708,6 @@ protected:
|
||||
* |SetValueChanged| to be called.
|
||||
*/
|
||||
bool mSetValueChanged;
|
||||
/**
|
||||
* mInEditAction is true while editor handling an edit action.
|
||||
*/
|
||||
bool mInEditAction;
|
||||
};
|
||||
|
||||
|
||||
@ -729,7 +723,6 @@ nsTextInputListener::nsTextInputListener(nsITextControlElement* aTxtCtrlElement)
|
||||
, mHadRedoItems(false)
|
||||
, mSettingValue(false)
|
||||
, mSetValueChanged(true)
|
||||
, mInEditAction(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -896,8 +889,6 @@ nsTextInputListener::HandleEvent(nsIDOMEvent* aEvent)
|
||||
NS_IMETHODIMP
|
||||
nsTextInputListener::EditAction()
|
||||
{
|
||||
mInEditAction = false;
|
||||
|
||||
nsWeakFrame weakFrame = mFrame;
|
||||
|
||||
nsITextControlFrame* frameBase = do_QueryFrame(mFrame);
|
||||
@ -943,14 +934,12 @@ nsTextInputListener::EditAction()
|
||||
NS_IMETHODIMP
|
||||
nsTextInputListener::BeforeEditAction()
|
||||
{
|
||||
mInEditAction = true;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextInputListener::CancelEditAction()
|
||||
{
|
||||
mInEditAction = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -1529,10 +1518,11 @@ nsTextEditorState::UnbindFromFrame(nsTextControlFrame* aFrame)
|
||||
NS_ASSERTION(!aFrame || aFrame == mBoundFrame, "Unbinding from the wrong frame");
|
||||
NS_ENSURE_TRUE_VOID(!aFrame || aFrame == mBoundFrame);
|
||||
|
||||
// If the editor is modified, we need to notify it here because editor may be
|
||||
// destroyed before EditAction() is called if selection listener causes
|
||||
// flushing layout.
|
||||
if (mTextListener && mTextListener->IsInEditAction()) {
|
||||
// If the editor is modified but nsIEditorObserver::EditAction() hasn't been
|
||||
// called yet, we need to notify it here because editor may be destroyed
|
||||
// before EditAction() is called if selection listener causes flushing layout.
|
||||
if (mTextListener && mEditor && mEditorInitialized &&
|
||||
mEditor->GetIsInEditAction()) {
|
||||
mTextListener->EditAction();
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,6 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(IMEContentObserver)
|
||||
IMEContentObserver::IMEContentObserver()
|
||||
: mESM(nullptr)
|
||||
, mPreCharacterDataChangeLength(-1)
|
||||
, mIsEditorInTransaction(false)
|
||||
, mIsSelectionChangeEventPending(false)
|
||||
, mSelectionChangeCausedOnlyByComposition(false)
|
||||
, mIsPositionChangeEventPending(false)
|
||||
@ -911,7 +910,6 @@ IMEContentObserver::AttributeChanged(nsIDocument* aDocument,
|
||||
NS_IMETHODIMP
|
||||
IMEContentObserver::EditAction()
|
||||
{
|
||||
mIsEditorInTransaction = false;
|
||||
mEndOfAddedTextCache.Clear();
|
||||
mStartOfRemovingTextRangeCache.Clear();
|
||||
FlushMergeableNotifications();
|
||||
@ -921,7 +919,6 @@ IMEContentObserver::EditAction()
|
||||
NS_IMETHODIMP
|
||||
IMEContentObserver::BeforeEditAction()
|
||||
{
|
||||
mIsEditorInTransaction = true;
|
||||
mEndOfAddedTextCache.Clear();
|
||||
mStartOfRemovingTextRangeCache.Clear();
|
||||
return NS_OK;
|
||||
@ -930,7 +927,6 @@ IMEContentObserver::BeforeEditAction()
|
||||
NS_IMETHODIMP
|
||||
IMEContentObserver::CancelEditAction()
|
||||
{
|
||||
mIsEditorInTransaction = false;
|
||||
mEndOfAddedTextCache.Clear();
|
||||
mStartOfRemovingTextRangeCache.Clear();
|
||||
FlushMergeableNotifications();
|
||||
@ -988,10 +984,14 @@ private:
|
||||
void
|
||||
IMEContentObserver::FlushMergeableNotifications()
|
||||
{
|
||||
// If we're in handling an edit action, this method will be called later.
|
||||
// If this is already detached from the widget, this doesn't need to notify
|
||||
// anything.
|
||||
if (mIsEditorInTransaction || !mWidget) {
|
||||
if (!mWidget) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we're in handling an edit action, this method will be called later.
|
||||
if (mEditor && mEditor->GetIsInEditAction()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -217,7 +217,6 @@ private:
|
||||
uint32_t mPreAttrChangeLength;
|
||||
int64_t mPreCharacterDataChangeLength;
|
||||
|
||||
bool mIsEditorInTransaction;
|
||||
bool mIsSelectionChangeEventPending;
|
||||
bool mSelectionChangeCausedOnlyByComposition;
|
||||
bool mIsPositionChangeEventPending;
|
||||
|
@ -147,6 +147,7 @@ nsEditor::nsEditor()
|
||||
, mDidPreDestroy(false)
|
||||
, mDidPostCreate(false)
|
||||
, mDispatchInputEvent(true)
|
||||
, mIsInEditAction(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1832,6 +1833,7 @@ nsEditor::NotifyEditorObservers(NotificationForEditorObservers aNotification)
|
||||
{
|
||||
switch (aNotification) {
|
||||
case eNotifyEditorObserversOfEnd:
|
||||
mIsInEditAction = false;
|
||||
for (int32_t i = 0; i < mEditorObservers.Count(); i++) {
|
||||
mEditorObservers[i]->EditAction();
|
||||
}
|
||||
@ -1843,11 +1845,13 @@ nsEditor::NotifyEditorObservers(NotificationForEditorObservers aNotification)
|
||||
FireInputEvent();
|
||||
break;
|
||||
case eNotifyEditorObserversOfBefore:
|
||||
mIsInEditAction = true;
|
||||
for (int32_t i = 0; i < mEditorObservers.Count(); i++) {
|
||||
mEditorObservers[i]->BeforeEditAction();
|
||||
}
|
||||
break;
|
||||
case eNotifyEditorObserversOfCancel:
|
||||
mIsInEditAction = false;
|
||||
for (int32_t i = 0; i < mEditorObservers.Count(); i++) {
|
||||
mEditorObservers[i]->CancelEditAction();
|
||||
}
|
||||
@ -5273,3 +5277,11 @@ nsEditor::SetSuppressDispatchingInputEvent(bool aSuppress)
|
||||
mDispatchInputEvent = !aSuppress;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditor::GetIsInEditAction(bool* aIsInEditAction)
|
||||
{
|
||||
MOZ_ASSERT(aIsInEditAction, "aIsInEditAction must not be null");
|
||||
*aIsInEditAction = mIsInEditAction;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -895,6 +895,7 @@ protected:
|
||||
bool mDidPreDestroy; // whether PreDestroy has been called
|
||||
bool mDidPostCreate; // whether PostCreate has been called
|
||||
bool mDispatchInputEvent;
|
||||
bool mIsInEditAction; // true while the instance is handling an edit action
|
||||
|
||||
friend bool NSCanUnload(nsISupports* serviceMgr);
|
||||
friend class nsAutoTxnsConserveSelection;
|
||||
|
@ -21,7 +21,7 @@ interface nsIEditActionListener;
|
||||
interface nsIInlineSpellChecker;
|
||||
interface nsITransferable;
|
||||
|
||||
[scriptable, uuid(65523eab-db1f-44aa-893e-dfe57ad306f0)]
|
||||
[builtinclass, scriptable, uuid(c3b61bc9-ccdd-4bcd-acd8-1b8dcbe6a247)]
|
||||
|
||||
interface nsIEditor : nsISupports
|
||||
{
|
||||
@ -549,4 +549,11 @@ interface nsIEditor : nsISupports
|
||||
|
||||
/* Set true if you want to suppress dispatching input event. */
|
||||
attribute boolean suppressDispatchingInputEvent;
|
||||
|
||||
/**
|
||||
* True if an edit action is being handled (in other words, between calls of
|
||||
* nsIEditorObserver::BeforeEditAction() and nsIEditorObserver::EditAction()
|
||||
* or nsIEditorObserver::CancelEditAction(). Otherwise, false.
|
||||
*/
|
||||
[infallible, noscript] readonly attribute boolean isInEditAction;
|
||||
};
|
||||
|
@ -22,7 +22,7 @@ class Element;
|
||||
|
||||
[ptr] native Element (mozilla::dom::Element);
|
||||
|
||||
[scriptable, uuid(833f30de-94c7-4630-a852-2300ef329d7b)]
|
||||
[builtinclass, scriptable, uuid(9470bee7-cad3-4382-8fb4-6bdda9f0273a)]
|
||||
|
||||
interface nsIHTMLEditor : nsISupports
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(07b6d070-ccea-4a00-84b4-f4b94dd9eb52)]
|
||||
[builtinclass, scriptable, uuid(da8f244b-6ffc-4be1-8b1a-667abfe1d304)]
|
||||
interface nsIPlaintextEditor : nsISupports
|
||||
{
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user