2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
1999-08-09 01:34:04 +00:00
|
|
|
|
|
|
|
|
2016-07-08 05:03:31 +00:00
|
|
|
#ifndef mozilla_EditorUtils_h
|
|
|
|
#define mozilla_EditorUtils_h
|
1999-08-09 01:34:04 +00:00
|
|
|
|
2017-06-28 00:34:18 +00:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2016-07-08 04:10:13 +00:00
|
|
|
#include "mozilla/EditorBase.h"
|
|
|
|
#include "mozilla/GuardObjects.h"
|
1999-08-09 01:34:04 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nsDebug.h"
|
1999-08-09 01:34:04 +00:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIEditor.h"
|
2012-07-13 06:33:42 +00:00
|
|
|
#include "nscore.h"
|
1999-12-07 08:30:19 +00:00
|
|
|
|
2012-07-13 06:33:42 +00:00
|
|
|
class nsIAtom;
|
|
|
|
class nsIContentIterator;
|
|
|
|
class nsIDOMDocument;
|
2016-06-23 07:59:15 +00:00
|
|
|
class nsIDOMEvent;
|
|
|
|
class nsISimpleEnumerator;
|
|
|
|
class nsITransferable;
|
2014-11-02 12:04:13 +00:00
|
|
|
class nsRange;
|
2016-06-23 09:51:19 +00:00
|
|
|
|
2014-11-02 12:04:13 +00:00
|
|
|
namespace mozilla {
|
2015-04-24 11:27:35 +00:00
|
|
|
template <class T> class OwningNonNull;
|
2016-06-23 09:51:19 +00:00
|
|
|
|
2016-11-18 08:59:23 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* EditActionResult is useful to return multiple results of an editor
|
|
|
|
* action handler without out params.
|
|
|
|
* Note that when you return an anonymous instance from a method, you should
|
|
|
|
* use EditActionIgnored(), EditActionHandled() or EditActionCanceled() for
|
|
|
|
* easier to read. In other words, EditActionResult should be used when
|
|
|
|
* declaring return type of a method, being an argument or defined as a local
|
|
|
|
* variable.
|
|
|
|
*/
|
|
|
|
class MOZ_STACK_CLASS EditActionResult final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool Succeeded() const { return NS_SUCCEEDED(mRv); }
|
|
|
|
bool Failed() const { return NS_FAILED(mRv); }
|
|
|
|
nsresult Rv() const { return mRv; }
|
|
|
|
bool Canceled() const { return mCanceled; }
|
|
|
|
bool Handled() const { return mHandled; }
|
|
|
|
|
|
|
|
EditActionResult SetResult(nsresult aRv)
|
|
|
|
{
|
|
|
|
mRv = aRv;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
EditActionResult MarkAsCanceled()
|
|
|
|
{
|
|
|
|
mCanceled = true;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
EditActionResult MarkAsHandled()
|
|
|
|
{
|
|
|
|
mHandled = true;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit EditActionResult(nsresult aRv)
|
|
|
|
: mRv(aRv)
|
|
|
|
, mCanceled(false)
|
|
|
|
, mHandled(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EditActionResult& operator|=(const EditActionResult& aOther)
|
|
|
|
{
|
|
|
|
mCanceled |= aOther.mCanceled;
|
|
|
|
mHandled |= aOther.mHandled;
|
|
|
|
// When both result are same, keep the result.
|
|
|
|
if (mRv == aOther.mRv) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
// If one of the results is error, use NS_ERROR_FAILURE.
|
|
|
|
if (Failed() || aOther.Failed()) {
|
|
|
|
mRv = NS_ERROR_FAILURE;
|
|
|
|
} else {
|
|
|
|
// Otherwise, use generic success code, NS_OK.
|
|
|
|
mRv = NS_OK;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsresult mRv;
|
|
|
|
bool mCanceled;
|
|
|
|
bool mHandled;
|
|
|
|
|
|
|
|
EditActionResult(nsresult aRv, bool aCanceled, bool aHandled)
|
|
|
|
: mRv(aRv)
|
|
|
|
, mCanceled(aCanceled)
|
|
|
|
, mHandled(aHandled)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EditActionResult()
|
|
|
|
: mRv(NS_ERROR_NOT_INITIALIZED)
|
|
|
|
, mCanceled(false)
|
|
|
|
, mHandled(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
friend EditActionResult EditActionIgnored(nsresult aRv);
|
|
|
|
friend EditActionResult EditActionHandled(nsresult aRv);
|
|
|
|
friend EditActionResult EditActionCanceled(nsresult aRv);
|
|
|
|
};
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* When an edit action handler (or its helper) does nothing,
|
|
|
|
* EditActionIgnored should be returned.
|
|
|
|
*/
|
|
|
|
inline EditActionResult
|
|
|
|
EditActionIgnored(nsresult aRv = NS_OK)
|
|
|
|
{
|
|
|
|
return EditActionResult(aRv, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* When an edit action handler (or its helper) handled and not canceled,
|
|
|
|
* EditActionHandled should be returned.
|
|
|
|
*/
|
|
|
|
inline EditActionResult
|
|
|
|
EditActionHandled(nsresult aRv = NS_OK)
|
|
|
|
{
|
|
|
|
return EditActionResult(aRv, false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* When an edit action handler (or its helper) handled and canceled,
|
|
|
|
* EditActionHandled should be returned.
|
|
|
|
*/
|
|
|
|
inline EditActionResult
|
|
|
|
EditActionCanceled(nsresult aRv = NS_OK)
|
|
|
|
{
|
|
|
|
return EditActionResult(aRv, true, true);
|
|
|
|
}
|
|
|
|
|
2000-01-31 10:30:12 +00:00
|
|
|
/***************************************************************************
|
2017-06-22 06:02:59 +00:00
|
|
|
* stack based helper class for batching a collection of transactions inside a
|
|
|
|
* placeholder transaction.
|
2000-01-31 10:30:12 +00:00
|
|
|
*/
|
2017-08-14 05:56:39 +00:00
|
|
|
class MOZ_RAII AutoPlaceholderBatch final
|
1999-09-29 20:08:15 +00:00
|
|
|
{
|
2016-06-23 09:51:19 +00:00
|
|
|
private:
|
2017-08-14 05:56:39 +00:00
|
|
|
RefPtr<EditorBase> mEditorBase;
|
2016-06-23 09:51:19 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
|
|
|
|
public:
|
2017-08-14 05:56:39 +00:00
|
|
|
explicit AutoPlaceholderBatch(EditorBase* aEditorBase
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
|
|
|
: mEditorBase(aEditorBase)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
|
|
|
BeginPlaceholderTransaction(nullptr);
|
|
|
|
}
|
|
|
|
AutoPlaceholderBatch(EditorBase* aEditorBase,
|
|
|
|
nsIAtom* aTransactionName
|
2016-06-23 09:51:19 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2017-08-14 05:56:39 +00:00
|
|
|
: mEditorBase(aEditorBase)
|
2016-06-23 09:51:19 +00:00
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2017-08-14 05:56:39 +00:00
|
|
|
BeginPlaceholderTransaction(aTransactionName);
|
2016-06-23 09:51:19 +00:00
|
|
|
}
|
2017-08-14 05:56:39 +00:00
|
|
|
~AutoPlaceholderBatch()
|
2016-06-23 09:51:19 +00:00
|
|
|
{
|
2017-08-14 05:56:39 +00:00
|
|
|
if (mEditorBase) {
|
|
|
|
mEditorBase->EndPlaceholderTransaction();
|
2015-08-25 18:04:12 +00:00
|
|
|
}
|
2016-06-23 09:51:19 +00:00
|
|
|
}
|
1999-09-29 20:08:15 +00:00
|
|
|
|
2016-06-23 09:46:58 +00:00
|
|
|
private:
|
2017-08-14 05:56:39 +00:00
|
|
|
void BeginPlaceholderTransaction(nsIAtom* aTransactionName)
|
2016-06-23 09:46:58 +00:00
|
|
|
{
|
2017-08-14 05:56:39 +00:00
|
|
|
if (mEditorBase) {
|
|
|
|
mEditorBase->BeginPlaceholderTransaction(aTransactionName);
|
|
|
|
}
|
2016-06-23 09:46:58 +00:00
|
|
|
}
|
|
|
|
};
|
2016-07-07 04:27:31 +00:00
|
|
|
|
2000-01-31 10:30:12 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for saving/restoring selection. Note that this
|
|
|
|
* assumes that the nodes involved are still around afterwards!
|
|
|
|
*/
|
2016-07-07 04:27:31 +00:00
|
|
|
class MOZ_RAII AutoSelectionRestorer final
|
1999-08-09 01:34:04 +00:00
|
|
|
{
|
2016-07-07 04:27:31 +00:00
|
|
|
private:
|
|
|
|
// Ref-counted reference to the selection that we are supposed to restore.
|
|
|
|
RefPtr<dom::Selection> mSelection;
|
2016-07-08 04:10:13 +00:00
|
|
|
EditorBase* mEditorBase; // Non-owning ref to EditorBase.
|
2016-07-07 04:27:31 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
1999-08-09 01:34:04 +00:00
|
|
|
|
2016-07-07 04:27:31 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor responsible for remembering all state needed to restore
|
|
|
|
* aSelection.
|
|
|
|
*/
|
|
|
|
AutoSelectionRestorer(dom::Selection* aSelection,
|
2016-07-08 04:10:13 +00:00
|
|
|
EditorBase* aEditorBase
|
2016-07-07 04:27:31 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-07-07 04:27:31 +00:00
|
|
|
/**
|
|
|
|
* Destructor restores mSelection to its former state
|
|
|
|
*/
|
|
|
|
~AutoSelectionRestorer();
|
2000-08-26 04:03:50 +00:00
|
|
|
|
2016-07-07 04:27:31 +00:00
|
|
|
/**
|
|
|
|
* Abort() cancels to restore the selection.
|
|
|
|
*/
|
|
|
|
void Abort();
|
1999-08-09 01:34:04 +00:00
|
|
|
};
|
|
|
|
|
1999-12-07 08:30:19 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for StartOperation()/EndOperation() sandwich
|
|
|
|
*/
|
2016-06-23 09:15:42 +00:00
|
|
|
class MOZ_RAII AutoRules final
|
1999-12-07 08:30:19 +00:00
|
|
|
{
|
2016-06-23 09:15:42 +00:00
|
|
|
public:
|
2016-07-08 04:10:13 +00:00
|
|
|
AutoRules(EditorBase* aEditorBase, EditAction aAction,
|
2016-06-23 09:15:42 +00:00
|
|
|
nsIEditor::EDirection aDirection
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2016-07-08 04:10:13 +00:00
|
|
|
: mEditorBase(aEditorBase)
|
2016-06-23 09:15:42 +00:00
|
|
|
, mDoNothing(false)
|
2015-05-28 15:58:42 +00:00
|
|
|
{
|
2015-08-25 18:04:12 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2016-06-23 09:15:42 +00:00
|
|
|
// mAction will already be set if this is nested call
|
2016-07-08 04:10:13 +00:00
|
|
|
if (mEditorBase && !mEditorBase->mAction) {
|
|
|
|
mEditorBase->StartOperation(aAction, aDirection);
|
2016-06-23 09:15:42 +00:00
|
|
|
} else {
|
|
|
|
mDoNothing = true; // nested calls will end up here
|
2000-08-14 02:39:37 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-23 09:15:42 +00:00
|
|
|
|
|
|
|
~AutoRules()
|
2000-08-14 02:39:37 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
if (mEditorBase && !mDoNothing) {
|
|
|
|
mEditorBase->EndOperation();
|
2000-08-14 02:39:37 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-06-23 09:15:42 +00:00
|
|
|
protected:
|
2016-07-08 04:10:13 +00:00
|
|
|
EditorBase* mEditorBase;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mDoNothing;
|
2015-08-25 18:04:12 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
1999-12-07 08:30:19 +00:00
|
|
|
};
|
|
|
|
|
2000-01-04 03:09:41 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for turning off active selection adjustment
|
|
|
|
* by low level transactions
|
|
|
|
*/
|
2016-06-23 09:01:23 +00:00
|
|
|
class MOZ_RAII AutoTransactionsConserveSelection final
|
2000-01-04 03:09:41 +00:00
|
|
|
{
|
2016-06-23 09:01:23 +00:00
|
|
|
public:
|
2016-07-08 04:10:13 +00:00
|
|
|
explicit AutoTransactionsConserveSelection(EditorBase* aEditorBase
|
2016-06-23 09:01:23 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2016-07-08 04:10:13 +00:00
|
|
|
: mEditorBase(aEditorBase)
|
2016-06-23 09:01:23 +00:00
|
|
|
, mOldState(true)
|
2000-01-04 03:09:41 +00:00
|
|
|
{
|
2015-08-25 18:04:12 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2016-07-08 04:10:13 +00:00
|
|
|
if (mEditorBase) {
|
|
|
|
mOldState = mEditorBase->GetShouldTxnSetSelection();
|
|
|
|
mEditorBase->SetShouldTxnSetSelection(false);
|
2000-01-04 03:09:41 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-06-23 09:01:23 +00:00
|
|
|
~AutoTransactionsConserveSelection()
|
2000-01-04 03:09:41 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
if (mEditorBase) {
|
|
|
|
mEditorBase->SetShouldTxnSetSelection(mOldState);
|
2000-01-04 03:09:41 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-06-23 09:01:23 +00:00
|
|
|
protected:
|
2016-07-08 04:10:13 +00:00
|
|
|
EditorBase* mEditorBase;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mOldState;
|
2015-08-25 18:04:12 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2000-01-04 03:09:41 +00:00
|
|
|
};
|
|
|
|
|
2001-05-11 13:59:11 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* stack based helper class for batching reflow and paint requests.
|
|
|
|
*/
|
2016-07-07 04:09:51 +00:00
|
|
|
class MOZ_RAII AutoUpdateViewBatch final
|
2001-05-11 13:59:11 +00:00
|
|
|
{
|
2016-07-07 04:09:51 +00:00
|
|
|
public:
|
2016-07-08 04:10:13 +00:00
|
|
|
explicit AutoUpdateViewBatch(EditorBase* aEditorBase
|
2016-07-07 04:09:51 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2016-07-08 04:10:13 +00:00
|
|
|
: mEditorBase(aEditorBase)
|
2001-05-11 13:59:11 +00:00
|
|
|
{
|
2015-08-25 18:04:12 +00:00
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2016-07-08 04:10:13 +00:00
|
|
|
NS_ASSERTION(mEditorBase, "null mEditorBase pointer!");
|
2001-05-11 13:59:11 +00:00
|
|
|
|
2016-07-08 04:10:13 +00:00
|
|
|
if (mEditorBase) {
|
|
|
|
mEditorBase->BeginUpdateViewBatch();
|
2016-07-07 04:09:51 +00:00
|
|
|
}
|
2001-05-11 13:59:11 +00:00
|
|
|
}
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-07-07 04:09:51 +00:00
|
|
|
~AutoUpdateViewBatch()
|
2001-05-11 13:59:11 +00:00
|
|
|
{
|
2016-07-08 04:10:13 +00:00
|
|
|
if (mEditorBase) {
|
|
|
|
mEditorBase->EndUpdateViewBatch();
|
2016-07-07 04:09:51 +00:00
|
|
|
}
|
2001-05-11 13:59:11 +00:00
|
|
|
}
|
2015-05-28 15:58:42 +00:00
|
|
|
|
2016-07-07 04:09:51 +00:00
|
|
|
protected:
|
2016-07-08 04:10:13 +00:00
|
|
|
EditorBase* mEditorBase;
|
2015-08-25 18:04:12 +00:00
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
2001-05-11 13:59:11 +00:00
|
|
|
};
|
|
|
|
|
2017-06-28 00:34:18 +00:00
|
|
|
class MOZ_STACK_CLASS AutoRangeArray final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoRangeArray(dom::Selection* aSelection)
|
|
|
|
{
|
|
|
|
if (!aSelection) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint32_t rangeCount = aSelection->RangeCount();
|
|
|
|
for (uint32_t i = 0; i < rangeCount; i++) {
|
|
|
|
mRanges.AppendElement(*aSelection->GetRangeAt(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoTArray<mozilla::OwningNonNull<nsRange>, 8> mRanges;
|
|
|
|
};
|
|
|
|
|
2000-08-26 04:03:50 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* some helper classes for iterating the dom tree
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-06-23 08:39:47 +00:00
|
|
|
class BoolDomIterFunctor
|
2000-08-26 04:03:50 +00:00
|
|
|
{
|
2016-06-23 08:39:47 +00:00
|
|
|
public:
|
|
|
|
virtual bool operator()(nsINode* aNode) const = 0;
|
2000-08-26 04:03:50 +00:00
|
|
|
};
|
|
|
|
|
2016-06-23 08:30:39 +00:00
|
|
|
class MOZ_RAII DOMIterator
|
2000-08-26 04:03:50 +00:00
|
|
|
{
|
2016-06-23 08:30:39 +00:00
|
|
|
public:
|
|
|
|
explicit DOMIterator(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
|
2015-05-22 13:58:30 +00:00
|
|
|
|
2016-06-23 08:30:39 +00:00
|
|
|
explicit DOMIterator(nsINode& aNode MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
|
|
|
|
virtual ~DOMIterator();
|
2015-04-24 11:27:34 +00:00
|
|
|
|
2016-06-23 08:30:39 +00:00
|
|
|
nsresult Init(nsRange& aRange);
|
2015-05-22 13:58:30 +00:00
|
|
|
|
2016-06-23 08:30:39 +00:00
|
|
|
void AppendList(
|
2016-06-23 08:39:47 +00:00
|
|
|
const BoolDomIterFunctor& functor,
|
2016-06-23 08:30:39 +00:00
|
|
|
nsTArray<mozilla::OwningNonNull<nsINode>>& arrayOfNodes) const;
|
2000-08-26 04:03:50 +00:00
|
|
|
|
2016-06-23 08:30:39 +00:00
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIContentIterator> mIter;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
2016-06-23 08:25:03 +00:00
|
|
|
|
2016-06-23 08:30:39 +00:00
|
|
|
class MOZ_RAII DOMSubtreeIterator final : public DOMIterator
|
2000-08-26 04:03:50 +00:00
|
|
|
{
|
2016-06-23 08:25:03 +00:00
|
|
|
public:
|
|
|
|
explicit DOMSubtreeIterator(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM);
|
|
|
|
virtual ~DOMSubtreeIterator();
|
2015-05-22 13:58:30 +00:00
|
|
|
|
2016-06-23 08:25:03 +00:00
|
|
|
nsresult Init(nsRange& aRange);
|
2000-08-26 04:03:50 +00:00
|
|
|
};
|
2000-01-04 03:09:41 +00:00
|
|
|
|
2016-06-23 08:39:47 +00:00
|
|
|
class TrivialFunctor final : public BoolDomIterFunctor
|
Checking in for bug 50742, this change removes the use of XIF in mozilla and replaces the XIF converter with a HTML (and XML) serializer.
Contextual information added to HTML copy and intelligence added to HTML paste in the editor (fixes bugs 47014, 50568 and 46554, and partly (at least) fixes bug 53188).
Code written by vidur, jfrancis, jst, akkana. Tested by jfrancis, akkana, vidur, jst, kin. Reviwed (and super reviewed) by waterson, vidur, kin, jfrancis, jst
2000-10-07 10:57:30 +00:00
|
|
|
{
|
2016-06-23 08:19:35 +00:00
|
|
|
public:
|
|
|
|
// Used to build list of all nodes iterator covers
|
|
|
|
virtual bool operator()(nsINode* aNode) const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
Checking in for bug 50742, this change removes the use of XIF in mozilla and replaces the XIF converter with a HTML (and XML) serializer.
Contextual information added to HTML copy and intelligence added to HTML paste in the editor (fixes bugs 47014, 50568 and 46554, and partly (at least) fixes bug 53188).
Code written by vidur, jfrancis, jst, akkana. Tested by jfrancis, akkana, vidur, jst, kin. Reviwed (and super reviewed) by waterson, vidur, kin, jfrancis, jst
2000-10-07 10:57:30 +00:00
|
|
|
};
|
|
|
|
|
2002-08-29 07:49:31 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* general dom point utility struct
|
|
|
|
*****************************************************************************/
|
2016-06-23 08:13:03 +00:00
|
|
|
struct MOZ_STACK_CLASS EditorDOMPoint final
|
2002-08-29 07:49:31 +00:00
|
|
|
{
|
2014-04-28 15:34:05 +00:00
|
|
|
nsCOMPtr<nsINode> node;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t offset;
|
2014-11-02 12:04:13 +00:00
|
|
|
|
2016-06-23 08:13:03 +00:00
|
|
|
EditorDOMPoint()
|
|
|
|
: node(nullptr)
|
|
|
|
, offset(-1)
|
|
|
|
{}
|
|
|
|
EditorDOMPoint(nsINode* aNode, int32_t aOffset)
|
2014-04-28 15:34:05 +00:00
|
|
|
: node(aNode)
|
|
|
|
, offset(aOffset)
|
|
|
|
{}
|
2016-06-23 08:13:03 +00:00
|
|
|
EditorDOMPoint(nsIDOMNode* aNode, int32_t aOffset)
|
2014-04-28 15:34:05 +00:00
|
|
|
: node(do_QueryInterface(aNode))
|
|
|
|
, offset(aOffset)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void SetPoint(nsINode* aNode, int32_t aOffset)
|
2002-08-29 07:49:31 +00:00
|
|
|
{
|
2014-04-28 15:34:05 +00:00
|
|
|
node = aNode;
|
|
|
|
offset = aOffset;
|
2002-08-29 07:49:31 +00:00
|
|
|
}
|
2014-04-28 15:34:05 +00:00
|
|
|
void SetPoint(nsIDOMNode* aNode, int32_t aOffset)
|
2002-08-29 07:49:31 +00:00
|
|
|
{
|
2014-04-28 15:34:05 +00:00
|
|
|
node = do_QueryInterface(aNode);
|
|
|
|
offset = aOffset;
|
2002-08-29 07:49:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-07 02:49:42 +00:00
|
|
|
class EditorUtils final
|
2002-12-22 01:51:14 +00:00
|
|
|
{
|
2016-07-07 02:49:42 +00:00
|
|
|
public:
|
2017-08-24 22:38:33 +00:00
|
|
|
// Note that aChild isn't a normal XPCOM outparam and won't get AddRef'ed.
|
2016-07-07 02:49:42 +00:00
|
|
|
static bool IsDescendantOf(nsINode* aNode, nsINode* aParent,
|
2017-08-23 02:04:43 +00:00
|
|
|
nsIContent** aChild);
|
|
|
|
static bool IsDescendantOf(nsINode* aNode, nsINode* aParent,
|
|
|
|
int32_t* aOffset = nullptr);
|
2016-07-07 02:49:42 +00:00
|
|
|
static bool IsDescendantOf(nsIDOMNode* aNode, nsIDOMNode* aParent,
|
2017-08-23 02:04:43 +00:00
|
|
|
int32_t* aOffset = nullptr);
|
2016-07-07 02:49:42 +00:00
|
|
|
static bool IsLeafNode(nsIDOMNode* aNode);
|
2002-12-22 01:51:14 +00:00
|
|
|
};
|
|
|
|
|
2016-06-23 07:59:15 +00:00
|
|
|
class EditorHookUtils final
|
2003-04-25 21:05:32 +00:00
|
|
|
{
|
2016-06-23 07:59:15 +00:00
|
|
|
public:
|
|
|
|
static bool DoInsertionHook(nsIDOMDocument* aDoc, nsIDOMEvent* aEvent,
|
|
|
|
nsITransferable* aTrans);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static nsresult GetHookEnumeratorFromDocument(
|
|
|
|
nsIDOMDocument*aDoc,
|
|
|
|
nsISimpleEnumerator** aEnumerator);
|
2003-04-25 21:05:32 +00:00
|
|
|
};
|
|
|
|
|
2016-06-23 07:59:15 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2016-07-08 05:03:31 +00:00
|
|
|
#endif // #ifndef mozilla_EditorUtils_h
|