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-05-21 15:12:37 +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/. */
|
1999-06-04 05:04:08 +04:00
|
|
|
|
2006-03-30 12:03:04 +04:00
|
|
|
/*
|
|
|
|
* Object that can be used to serialize selections, ranges, or nodes
|
|
|
|
* to strings in a gazillion different ways.
|
|
|
|
*/
|
2016-08-24 21:09:12 +03:00
|
|
|
|
1999-06-08 04:01:55 +04:00
|
|
|
#include "nsIDocumentEncoder.h"
|
|
|
|
|
1999-06-04 05:04:08 +04:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsIFactory.h"
|
|
|
|
#include "nsISupports.h"
|
1999-06-08 04:01:55 +04:00
|
|
|
#include "nsIDocument.h"
|
2000-10-12 02:50:14 +04:00
|
|
|
#include "nsIHTMLDocument.h"
|
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 14:57:30 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIContentSerializer.h"
|
2017-04-27 13:27:03 +03:00
|
|
|
#include "mozilla/Encoding.h"
|
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 14:57:30 +04:00
|
|
|
#include "nsIOutputStream.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMText.h"
|
|
|
|
#include "nsIDOMComment.h"
|
|
|
|
#include "nsIDOMProcessingInstruction.h"
|
|
|
|
#include "nsIDOMDocumentType.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
2012-01-10 18:19:54 +04:00
|
|
|
#include "nsRange.h"
|
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 14:57:30 +04:00
|
|
|
#include "nsIDOMRange.h"
|
2002-08-13 22:41:16 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2006-07-19 08:36:36 +04:00
|
|
|
#include "nsIContent.h"
|
2001-10-02 14:02:07 +04:00
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
2014-04-10 20:09:40 +04:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2010-05-25 03:24:15 +04:00
|
|
|
#include "nsISelectionPrivate.h"
|
|
|
|
#include "nsITransferable.h" // for kUnicodeMime
|
2002-06-26 00:03:06 +04:00
|
|
|
#include "nsContentUtils.h"
|
2017-09-05 13:19:06 +03:00
|
|
|
#include "nsElementTable.h"
|
2013-03-26 11:15:23 +04:00
|
|
|
#include "nsNodeUtils.h"
|
2001-12-17 10:14:49 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
2003-06-11 22:16:03 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2009-03-20 11:15:35 +03:00
|
|
|
#include "nsTArray.h"
|
2010-04-11 00:05:58 +04:00
|
|
|
#include "nsIFrame.h"
|
2010-06-27 00:39:56 +04:00
|
|
|
#include "nsStringBuffer.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-12-02 14:26:11 +04:00
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2016-10-14 21:21:00 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2017-12-01 18:45:25 +03:00
|
|
|
#include "mozilla/ScopeExit.h"
|
1999-06-04 05:04:08 +04:00
|
|
|
|
2012-02-10 14:04:45 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2000-10-12 02:50:14 +04:00
|
|
|
nsresult NS_NewDomSelection(nsISelection **aDomSelection);
|
1999-06-04 05:04:08 +04:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
enum nsRangeIterationDirection {
|
|
|
|
kDirectionOut = -1,
|
|
|
|
kDirectionIn = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsDocumentEncoder : public nsIDocumentEncoder
|
1999-06-10 04:35:02 +04:00
|
|
|
{
|
|
|
|
public:
|
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 14:57:30 +04:00
|
|
|
nsDocumentEncoder();
|
1999-06-10 04:35:02 +04:00
|
|
|
|
2010-06-27 00:39:56 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(nsDocumentEncoder)
|
2006-06-06 00:32:48 +04:00
|
|
|
NS_DECL_NSIDOCUMENTENCODER
|
|
|
|
|
1999-08-24 22:30:19 +04:00
|
|
|
protected:
|
2014-06-25 06:09:15 +04:00
|
|
|
virtual ~nsDocumentEncoder();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void Initialize(bool aClearCachedSerializer = true);
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult SerializeNodeStart(nsINode* aNode, int32_t aStartOffset,
|
|
|
|
int32_t aEndOffset, nsAString& aStr,
|
2012-07-30 18:20:58 +04:00
|
|
|
nsINode* aOriginalNode = nullptr);
|
2010-04-30 15:15:09 +04:00
|
|
|
nsresult SerializeToStringRecursive(nsINode* aNode,
|
2006-06-06 00:32:48 +04:00
|
|
|
nsAString& aStr,
|
2014-04-17 02:01:55 +04:00
|
|
|
bool aDontSerializeRoot,
|
|
|
|
uint32_t aMaxLength = 0);
|
2010-04-30 15:15:09 +04:00
|
|
|
nsresult SerializeNodeEnd(nsINode* aNode, nsAString& aStr);
|
2010-10-15 21:59:00 +04:00
|
|
|
// This serializes the content of aNode.
|
|
|
|
nsresult SerializeToStringIterative(nsINode* aNode,
|
|
|
|
nsAString& aStr);
|
2012-01-10 18:19:54 +04:00
|
|
|
nsresult SerializeRangeToString(nsRange *aRange,
|
2002-03-24 02:54:46 +03:00
|
|
|
nsAString& aOutputString);
|
2016-08-24 21:09:12 +03:00
|
|
|
nsresult SerializeRangeNodes(nsRange* aRange,
|
|
|
|
nsINode* aNode,
|
2002-03-24 02:54:46 +03:00
|
|
|
nsAString& aString,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aDepth);
|
2010-04-30 15:15:09 +04:00
|
|
|
nsresult SerializeRangeContextStart(const nsTArray<nsINode*>& aAncestorArray,
|
2002-03-24 02:54:46 +03:00
|
|
|
nsAString& aString);
|
2017-12-01 18:45:25 +03:00
|
|
|
nsresult SerializeRangeContextEnd(nsAString& aString);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual int32_t
|
2012-05-16 20:39:54 +04:00
|
|
|
GetImmediateContextCount(const nsTArray<nsINode*>& aAncestorArray)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult FlushText(nsAString& aString, bool aForce);
|
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 14:57:30 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsVisibleNode(nsINode* aNode)
|
2010-05-25 03:24:15 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNode, "");
|
|
|
|
|
|
|
|
if (mFlags & SkipInvisibleContent) {
|
2013-12-02 14:26:11 +04:00
|
|
|
// Treat the visibility of the ShadowRoot as if it were
|
|
|
|
// the host content.
|
2017-12-31 22:57:32 +03:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
|
|
|
if (ShadowRoot* shadowRoot = ShadowRoot::FromNodeOrNull(content)) {
|
2013-12-02 14:26:11 +04:00
|
|
|
content = shadowRoot->GetHost();
|
|
|
|
}
|
|
|
|
|
2010-05-25 03:24:15 +04:00
|
|
|
if (content) {
|
|
|
|
nsIFrame* frame = content->GetPrimaryFrame();
|
|
|
|
if (!frame) {
|
|
|
|
if (aNode->IsNodeOfType(nsINode::eTEXT)) {
|
|
|
|
// We have already checked that our parent is visible.
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-05-25 03:24:15 +04:00
|
|
|
}
|
2015-03-10 09:11:55 +03:00
|
|
|
if (aNode->IsHTMLElement(nsGkAtoms::rp)) {
|
|
|
|
// Ruby parentheses are part of ruby structure, hence
|
|
|
|
// shouldn't be stripped out even if it is not displayed.
|
|
|
|
return true;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-05-25 03:24:15 +04:00
|
|
|
}
|
2013-02-17 01:51:02 +04:00
|
|
|
bool isVisible = frame->StyleVisibility()->IsVisible();
|
2010-05-25 03:24:15 +04:00
|
|
|
if (!isVisible && aNode->IsNodeOfType(nsINode::eTEXT))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-05-25 03:24:15 +04:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-05-25 03:24:15 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool IncludeInContext(nsINode *aNode);
|
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 14:57:30 +04:00
|
|
|
|
2017-04-24 12:14:53 +03:00
|
|
|
void Clear();
|
|
|
|
|
2017-04-17 13:49:52 +03:00
|
|
|
class MOZ_STACK_CLASS AutoReleaseDocumentIfNeeded final
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AutoReleaseDocumentIfNeeded(nsDocumentEncoder* aEncoder)
|
|
|
|
: mEncoder(aEncoder)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoReleaseDocumentIfNeeded()
|
|
|
|
{
|
|
|
|
if (mEncoder->mFlags & RequiresReinitAfterOutput) {
|
2017-04-24 12:14:53 +03:00
|
|
|
mEncoder->Clear();
|
2017-04-17 13:49:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsDocumentEncoder* mEncoder;
|
|
|
|
};
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
|
|
|
nsCOMPtr<nsISelection> mSelection;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsRange> mRange;
|
2010-04-30 15:15:09 +04:00
|
|
|
nsCOMPtr<nsINode> mNode;
|
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 14:57:30 +04:00
|
|
|
nsCOMPtr<nsIOutputStream> mStream;
|
|
|
|
nsCOMPtr<nsIContentSerializer> mSerializer;
|
2017-04-27 13:27:03 +03:00
|
|
|
UniquePtr<Encoder> mUnicodeEncoder;
|
2010-04-30 15:15:09 +04:00
|
|
|
nsCOMPtr<nsINode> mCommonParent;
|
2000-11-30 04:08:22 +03:00
|
|
|
nsCOMPtr<nsIDocumentEncoderNodeFixup> mNodeFixup;
|
1999-06-10 04:35:02 +04:00
|
|
|
|
|
|
|
nsString mMimeType;
|
2017-04-27 13:27:03 +03:00
|
|
|
const Encoding* mEncoding;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mFlags;
|
|
|
|
uint32_t mWrapColumn;
|
|
|
|
uint32_t mStartDepth;
|
|
|
|
uint32_t mEndDepth;
|
|
|
|
int32_t mStartRootIndex;
|
|
|
|
int32_t mEndRootIndex;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<nsINode*, 8> mCommonAncestors;
|
|
|
|
AutoTArray<nsIContent*, 8> mStartNodes;
|
|
|
|
AutoTArray<int32_t, 8> mStartOffsets;
|
|
|
|
AutoTArray<nsIContent*, 8> mEndNodes;
|
|
|
|
AutoTArray<int32_t, 8> mEndOffsets;
|
2017-12-01 18:45:25 +03:00
|
|
|
AutoTArray<AutoTArray<nsINode*, 8>, 8> mRangeContexts;
|
2017-06-12 22:20:44 +03:00
|
|
|
// Whether the serializer cares about being notified to scan elements to
|
|
|
|
// keep track of whether they are preformatted. This stores the out
|
|
|
|
// argument of nsIContentSerializer::Init().
|
|
|
|
bool mNeedsPreformatScanning;
|
2016-08-24 21:09:12 +03:00
|
|
|
bool mHaltRangeHint;
|
2012-05-16 20:39:54 +04:00
|
|
|
// Used when context has already been serialized for
|
2012-05-16 20:39:54 +04:00
|
|
|
// table cell selections (where parent is <tr>)
|
2012-05-16 20:39:54 +04:00
|
|
|
bool mDisableContextSerialize;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsCopying; // Set to true only while copying
|
|
|
|
bool mNodeIsContainer;
|
2017-04-27 13:27:03 +03:00
|
|
|
bool mIsPlainText;
|
2010-06-27 00:39:56 +04:00
|
|
|
nsStringBuffer* mCachedBuffer;
|
1999-06-10 04:35:02 +04:00
|
|
|
};
|
|
|
|
|
2010-06-27 00:39:56 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDocumentEncoder)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDocumentEncoder)
|
1999-06-10 04:35:02 +04:00
|
|
|
|
2010-06-27 00:39:56 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDocumentEncoder)
|
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 14:57:30 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDocumentEncoder)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
1999-06-10 04:35:02 +04:00
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION(nsDocumentEncoder,
|
2017-04-24 13:17:17 +03:00
|
|
|
mDocument, mSelection, mRange, mNode, mSerializer,
|
|
|
|
mCommonParent)
|
2010-06-27 00:39:56 +04:00
|
|
|
|
2017-04-27 13:27:03 +03:00
|
|
|
nsDocumentEncoder::nsDocumentEncoder()
|
|
|
|
: mEncoding(nullptr)
|
|
|
|
, mCachedBuffer(nullptr)
|
1999-06-10 04:35:02 +04:00
|
|
|
{
|
2005-01-21 02:20:59 +03:00
|
|
|
Initialize();
|
2004-06-17 04:13:25 +04:00
|
|
|
mMimeType.AssignLiteral("text/plain");
|
2005-01-21 02:20:59 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void nsDocumentEncoder::Initialize(bool aClearCachedSerializer)
|
2005-01-21 02:20:59 +03:00
|
|
|
{
|
1999-09-10 23:12:46 +04:00
|
|
|
mFlags = 0;
|
1999-09-15 01:32:06 +04:00
|
|
|
mWrapColumn = 72;
|
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 14:57:30 +04:00
|
|
|
mStartDepth = 0;
|
|
|
|
mEndDepth = 0;
|
2005-01-21 02:20:59 +03:00
|
|
|
mStartRootIndex = 0;
|
|
|
|
mEndRootIndex = 0;
|
2017-06-12 22:20:44 +03:00
|
|
|
mNeedsPreformatScanning = false;
|
2011-10-17 18:59:28 +04:00
|
|
|
mHaltRangeHint = false;
|
2012-05-16 20:39:54 +04:00
|
|
|
mDisableContextSerialize = false;
|
2011-10-17 18:59:28 +04:00
|
|
|
mNodeIsContainer = false;
|
2017-04-27 13:27:03 +03:00
|
|
|
mIsPlainText = false;
|
2010-06-27 01:59:32 +04:00
|
|
|
if (aClearCachedSerializer) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mSerializer = nullptr;
|
2010-06-27 01:59:32 +04:00
|
|
|
}
|
1999-06-10 04:35:02 +04:00
|
|
|
}
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsDocumentEncoder::~nsDocumentEncoder()
|
1999-06-10 04:35:02 +04:00
|
|
|
{
|
2010-06-27 00:39:56 +04:00
|
|
|
if (mCachedBuffer) {
|
|
|
|
mCachedBuffer->Release();
|
|
|
|
}
|
1999-06-10 04:35:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-05-01 09:25:52 +04:00
|
|
|
nsDocumentEncoder::Init(nsIDOMDocument* aDocument,
|
2002-03-24 02:54:46 +03:00
|
|
|
const nsAString& aMimeType,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags)
|
1999-06-10 04:35:02 +04:00
|
|
|
{
|
|
|
|
if (!aDocument)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2010-06-27 00:39:56 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDocument);
|
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return NativeInit(doc, aMimeType, aFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocumentEncoder::NativeInit(nsIDocument* aDocument,
|
|
|
|
const nsAString& aMimeType,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags)
|
2010-06-27 00:39:56 +04:00
|
|
|
{
|
|
|
|
if (!aDocument)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2010-06-27 01:59:32 +04:00
|
|
|
Initialize(!mMimeType.Equals(aMimeType));
|
2005-01-21 02:20:59 +03:00
|
|
|
|
2010-06-27 00:39:56 +04:00
|
|
|
mDocument = aDocument;
|
1999-08-26 01:42:20 +04:00
|
|
|
|
1999-06-10 04:35:02 +04:00
|
|
|
mMimeType = aMimeType;
|
1999-08-24 22:30:19 +04:00
|
|
|
|
|
|
|
mFlags = aFlags;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsCopying = false;
|
1999-08-24 22:30:19 +04:00
|
|
|
|
1999-06-04 05:04:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsDocumentEncoder::SetWrapColumn(uint32_t aWC)
|
1999-06-10 04:35:02 +04:00
|
|
|
{
|
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 14:57:30 +04:00
|
|
|
mWrapColumn = aWC;
|
|
|
|
return NS_OK;
|
1999-06-10 04:35:02 +04:00
|
|
|
}
|
|
|
|
|
1999-06-30 23:26:08 +04:00
|
|
|
NS_IMETHODIMP
|
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 14:57:30 +04:00
|
|
|
nsDocumentEncoder::SetSelection(nsISelection* aSelection)
|
1999-06-30 23:26:08 +04:00
|
|
|
{
|
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 14:57:30 +04:00
|
|
|
mSelection = aSelection;
|
1999-06-30 23:26:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-10 04:35:02 +04:00
|
|
|
NS_IMETHODIMP
|
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 14:57:30 +04:00
|
|
|
nsDocumentEncoder::SetRange(nsIDOMRange* aRange)
|
1999-06-10 04:35:02 +04:00
|
|
|
{
|
2012-01-10 18:19:54 +04:00
|
|
|
mRange = static_cast<nsRange*>(aRange);
|
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 14:57:30 +04:00
|
|
|
return NS_OK;
|
1999-06-10 04:35:02 +04:00
|
|
|
}
|
|
|
|
|
2003-04-15 22:13:13 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocumentEncoder::SetNode(nsIDOMNode* aNode)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mNodeIsContainer = false;
|
2010-04-30 15:15:09 +04:00
|
|
|
mNode = do_QueryInterface(aNode);
|
2003-04-15 22:13:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-10 16:02:22 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocumentEncoder::SetNativeNode(nsINode* aNode)
|
|
|
|
{
|
|
|
|
mNodeIsContainer = false;
|
|
|
|
mNode = aNode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-06 00:32:48 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocumentEncoder::SetContainerNode(nsIDOMNode *aContainer)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mNodeIsContainer = true;
|
2010-04-30 15:15:09 +04:00
|
|
|
mNode = do_QueryInterface(aContainer);
|
2006-06-06 00:32:48 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-27 00:39:56 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocumentEncoder::SetNativeContainerNode(nsINode* aContainer)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mNodeIsContainer = true;
|
2010-06-27 00:39:56 +04:00
|
|
|
mNode = aContainer;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-10 04:35:02 +04:00
|
|
|
NS_IMETHODIMP
|
2003-06-17 20:40:34 +04:00
|
|
|
nsDocumentEncoder::SetCharset(const nsACString& aCharset)
|
1999-06-10 04:35:02 +04:00
|
|
|
{
|
2017-04-27 13:27:03 +03:00
|
|
|
const Encoding* encoding = Encoding::ForLabel(aCharset);
|
|
|
|
if (!encoding) {
|
|
|
|
return NS_ERROR_UCONV_NOCONV;
|
|
|
|
}
|
|
|
|
mEncoding = encoding->OutputEncoding();
|
1999-06-10 04:35:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-15 16:22:26 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 02:54:46 +03:00
|
|
|
nsDocumentEncoder::GetMimeType(nsAString& aMimeType)
|
2001-02-15 16:22:26 +03:00
|
|
|
{
|
|
|
|
aMimeType = mMimeType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-04-30 15:15:09 +04:00
|
|
|
nsDocumentEncoder::IncludeInContext(nsINode *aNode)
|
1999-06-10 04:35:02 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
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 14:57:30 +04:00
|
|
|
}
|
1999-06-10 04:35:02 +04:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsresult
|
2010-04-30 15:15:09 +04:00
|
|
|
nsDocumentEncoder::SerializeNodeStart(nsINode* aNode,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aStartOffset,
|
|
|
|
int32_t aEndOffset,
|
2008-07-29 09:59:25 +04:00
|
|
|
nsAString& aStr,
|
2010-04-30 15:15:09 +04:00
|
|
|
nsINode* aOriginalNode)
|
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 14:57:30 +04:00
|
|
|
{
|
2017-06-12 22:20:44 +03:00
|
|
|
if (mNeedsPreformatScanning && aNode->IsElement()) {
|
|
|
|
mSerializer->ScanElementForPreformat(aNode->AsElement());
|
|
|
|
}
|
|
|
|
|
2010-05-25 03:24:15 +04:00
|
|
|
if (!IsVisibleNode(aNode))
|
|
|
|
return NS_OK;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsINode* node = nullptr;
|
2010-04-30 15:15:09 +04:00
|
|
|
nsCOMPtr<nsINode> fixedNodeKungfuDeathGrip;
|
2008-07-29 09:59:25 +04:00
|
|
|
|
|
|
|
// Caller didn't do fixup, so we'll do it ourselves
|
2008-07-31 00:20:25 +04:00
|
|
|
if (!aOriginalNode) {
|
2008-07-29 09:59:25 +04:00
|
|
|
aOriginalNode = aNode;
|
2016-08-24 21:09:12 +03:00
|
|
|
if (mNodeFixup) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dummy;
|
2010-04-30 15:15:09 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> domNodeIn = do_QueryInterface(aNode);
|
|
|
|
nsCOMPtr<nsIDOMNode> domNodeOut;
|
|
|
|
mNodeFixup->FixupNode(domNodeIn, &dummy, getter_AddRefs(domNodeOut));
|
|
|
|
fixedNodeKungfuDeathGrip = do_QueryInterface(domNodeOut);
|
|
|
|
node = fixedNodeKungfuDeathGrip;
|
2008-07-31 00:20:25 +04:00
|
|
|
}
|
2000-11-30 04:08:22 +03:00
|
|
|
}
|
2008-07-29 09:59:25 +04:00
|
|
|
|
|
|
|
// Either there was no fixed-up node,
|
|
|
|
// or the caller did fixup themselves and aNode is already fixed
|
2000-11-30 04:08:22 +03:00
|
|
|
if (!node)
|
2008-07-29 09:59:25 +04:00
|
|
|
node = aNode;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2010-10-15 21:59:00 +04:00
|
|
|
if (node->IsElement()) {
|
2012-03-31 18:10:34 +04:00
|
|
|
if ((mFlags & (nsIDocumentEncoder::OutputPreformatted |
|
|
|
|
nsIDocumentEncoder::OutputDropInvisibleBreak)) &&
|
2016-10-14 21:21:00 +03:00
|
|
|
nsLayoutUtils::IsInvisibleBreak(node)) {
|
2012-03-31 18:10:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-02-10 14:04:45 +04:00
|
|
|
Element* originalElement =
|
2010-10-15 21:59:00 +04:00
|
|
|
aOriginalNode && aOriginalNode->IsElement() ?
|
2012-07-30 18:20:58 +04:00
|
|
|
aOriginalNode->AsElement() : nullptr;
|
2010-10-15 21:59:00 +04:00
|
|
|
mSerializer->AppendElementStart(node->AsElement(),
|
|
|
|
originalElement, aStr);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-11-30 04:08:22 +03:00
|
|
|
|
2011-06-14 11:56:48 +04:00
|
|
|
switch (node->NodeType()) {
|
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 14:57:30 +04:00
|
|
|
case nsIDOMNode::TEXT_NODE:
|
|
|
|
{
|
2010-05-04 17:19:54 +04:00
|
|
|
mSerializer->AppendText(static_cast<nsIContent*>(node),
|
|
|
|
aStartOffset, aEndOffset, aStr);
|
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 14:57:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIDOMNode::CDATA_SECTION_NODE:
|
|
|
|
{
|
2010-05-04 17:19:54 +04:00
|
|
|
mSerializer->AppendCDATASection(static_cast<nsIContent*>(node),
|
|
|
|
aStartOffset, aEndOffset, aStr);
|
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 14:57:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIDOMNode::PROCESSING_INSTRUCTION_NODE:
|
|
|
|
{
|
2010-05-04 17:19:54 +04:00
|
|
|
mSerializer->AppendProcessingInstruction(static_cast<nsIContent*>(node),
|
|
|
|
aStartOffset, aEndOffset, aStr);
|
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 14:57:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIDOMNode::COMMENT_NODE:
|
|
|
|
{
|
2010-05-04 17:19:54 +04:00
|
|
|
mSerializer->AppendComment(static_cast<nsIContent*>(node),
|
|
|
|
aStartOffset, aEndOffset, aStr);
|
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 14:57:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case nsIDOMNode::DOCUMENT_TYPE_NODE:
|
|
|
|
{
|
2010-05-04 17:19:54 +04:00
|
|
|
mSerializer->AppendDoctype(static_cast<nsIContent*>(node), aStr);
|
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 14:57:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-04-30 15:15:09 +04:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-04-30 15:15:09 +04:00
|
|
|
nsDocumentEncoder::SerializeNodeEnd(nsINode* aNode,
|
2002-03-24 02:54:46 +03:00
|
|
|
nsAString& aStr)
|
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 14:57:30 +04:00
|
|
|
{
|
2017-06-12 22:20:44 +03:00
|
|
|
if (mNeedsPreformatScanning && aNode->IsElement()) {
|
|
|
|
mSerializer->ForgetElementForPreformat(aNode->AsElement());
|
|
|
|
}
|
|
|
|
|
2010-05-25 03:24:15 +04:00
|
|
|
if (!IsVisibleNode(aNode))
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-04-30 17:12:05 +04:00
|
|
|
if (aNode->IsElement()) {
|
2010-10-23 01:25:22 +04:00
|
|
|
mSerializer->AppendElementEnd(aNode->AsElement(), aStr);
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-04-30 15:15:09 +04:00
|
|
|
nsDocumentEncoder::SerializeToStringRecursive(nsINode* aNode,
|
2006-06-06 00:32:48 +04:00
|
|
|
nsAString& aStr,
|
2014-04-17 02:01:55 +04:00
|
|
|
bool aDontSerializeRoot,
|
|
|
|
uint32_t aMaxLength)
|
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 14:57:30 +04:00
|
|
|
{
|
2014-04-17 02:01:55 +04:00
|
|
|
if (aMaxLength > 0 && aStr.Length() >= aMaxLength) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-25 03:24:15 +04:00
|
|
|
if (!IsVisibleNode(aNode))
|
|
|
|
return NS_OK;
|
|
|
|
|
2006-06-06 00:32:48 +04:00
|
|
|
nsresult rv = NS_OK;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool serializeClonedChildren = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsINode* maybeFixedNode = nullptr;
|
2010-04-30 15:15:09 +04:00
|
|
|
|
|
|
|
// Keep the node from FixupNode alive.
|
|
|
|
nsCOMPtr<nsINode> fixedNodeKungfuDeathGrip;
|
|
|
|
if (mNodeFixup) {
|
|
|
|
nsCOMPtr<nsIDOMNode> domNodeIn = do_QueryInterface(aNode);
|
|
|
|
nsCOMPtr<nsIDOMNode> domNodeOut;
|
|
|
|
mNodeFixup->FixupNode(domNodeIn, &serializeClonedChildren, getter_AddRefs(domNodeOut));
|
|
|
|
fixedNodeKungfuDeathGrip = do_QueryInterface(domNodeOut);
|
|
|
|
maybeFixedNode = fixedNodeKungfuDeathGrip;
|
|
|
|
}
|
2008-07-29 09:59:25 +04:00
|
|
|
|
|
|
|
if (!maybeFixedNode)
|
|
|
|
maybeFixedNode = aNode;
|
|
|
|
|
2013-08-06 18:40:38 +04:00
|
|
|
if ((mFlags & SkipInvisibleContent) &&
|
|
|
|
!(mFlags & OutputNonTextContentAsPlaceholder)) {
|
2017-10-25 18:19:11 +03:00
|
|
|
if (aNode->IsContent()) {
|
|
|
|
if (nsIFrame* frame = aNode->AsContent()->GetPrimaryFrame()) {
|
2016-11-29 02:31:29 +03:00
|
|
|
if (!frame->IsSelectable(nullptr)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aDontSerializeRoot = true;
|
2010-04-14 18:55:16 +04:00
|
|
|
}
|
2010-04-11 00:05:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-06 00:32:48 +04:00
|
|
|
if (!aDontSerializeRoot) {
|
2014-04-17 02:01:55 +04:00
|
|
|
int32_t endOffset = -1;
|
|
|
|
if (aMaxLength > 0) {
|
|
|
|
MOZ_ASSERT(aMaxLength >= aStr.Length());
|
|
|
|
endOffset = aMaxLength - aStr.Length();
|
|
|
|
}
|
|
|
|
rv = SerializeNodeStart(maybeFixedNode, 0, endOffset, aStr, aNode);
|
2006-06-06 00:32:48 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
|
2010-04-30 15:15:09 +04:00
|
|
|
nsINode* node = serializeClonedChildren ? maybeFixedNode : aNode;
|
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 14:57:30 +04:00
|
|
|
|
2013-03-26 11:15:23 +04:00
|
|
|
for (nsINode* child = nsNodeUtils::GetFirstChildOfTemplateOrNode(node);
|
|
|
|
child;
|
2010-07-19 14:35:02 +04:00
|
|
|
child = child->GetNextSibling()) {
|
2014-04-17 02:01:55 +04:00
|
|
|
rv = SerializeToStringRecursive(child, aStr, false, aMaxLength);
|
2010-04-30 15:15:09 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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 14:57:30 +04:00
|
|
|
}
|
1999-07-14 22:54:29 +04:00
|
|
|
|
2006-06-06 00:32:48 +04:00
|
|
|
if (!aDontSerializeRoot) {
|
2008-07-29 09:59:25 +04:00
|
|
|
rv = SerializeNodeEnd(node, aStr);
|
2006-06-06 00:32:48 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
1999-07-14 22:54:29 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return FlushText(aStr, false);
|
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 14:57:30 +04:00
|
|
|
}
|
1999-06-10 04:35:02 +04:00
|
|
|
|
2010-10-15 21:59:00 +04:00
|
|
|
nsresult
|
|
|
|
nsDocumentEncoder::SerializeToStringIterative(nsINode* aNode,
|
|
|
|
nsAString& aStr)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2014-06-05 02:21:23 +04:00
|
|
|
nsINode* node = nsNodeUtils::GetFirstChildOfTemplateOrNode(aNode);
|
2010-10-15 21:59:00 +04:00
|
|
|
while (node) {
|
|
|
|
nsINode* current = node;
|
|
|
|
rv = SerializeNodeStart(current, 0, -1, aStr, current);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-06-05 02:21:23 +04:00
|
|
|
node = nsNodeUtils::GetFirstChildOfTemplateOrNode(current);
|
2010-10-15 21:59:00 +04:00
|
|
|
while (!node && current && current != aNode) {
|
|
|
|
rv = SerializeNodeEnd(current, aStr);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Check if we have siblings.
|
|
|
|
node = current->GetNextSibling();
|
|
|
|
if (!node) {
|
|
|
|
// Perhaps parent node has siblings.
|
2012-10-09 16:31:24 +04:00
|
|
|
current = current->GetParentNode();
|
2014-06-05 02:21:23 +04:00
|
|
|
|
|
|
|
// Handle template element. If the parent is a template's content,
|
|
|
|
// then adjust the parent to be the template element.
|
|
|
|
if (current && current != aNode &&
|
|
|
|
current->NodeType() == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) {
|
|
|
|
DocumentFragment* frag = static_cast<DocumentFragment*>(current);
|
|
|
|
nsIContent* host = frag->GetHost();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (host && host->IsHTMLElement(nsGkAtoms::_template)) {
|
2014-06-05 02:21:23 +04:00
|
|
|
current = host;
|
|
|
|
}
|
|
|
|
}
|
2010-10-15 21:59:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
static nsresult
|
2002-03-24 02:54:46 +03:00
|
|
|
ConvertAndWrite(const nsAString& aString,
|
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 14:57:30 +04:00
|
|
|
nsIOutputStream* aStream,
|
2017-04-27 13:27:03 +03:00
|
|
|
Encoder* aEncoder,
|
|
|
|
bool aIsPlainText)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aStream);
|
|
|
|
NS_ENSURE_ARG_POINTER(aEncoder);
|
2000-10-13 15:06:05 +04:00
|
|
|
|
2017-04-27 13:27:03 +03:00
|
|
|
if (!aString.Length()) {
|
2014-02-18 18:57:44 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-04-27 13:27:03 +03:00
|
|
|
uint8_t buffer[4096];
|
|
|
|
auto src = MakeSpan(aString);
|
|
|
|
auto bufferSpan = MakeSpan(buffer);
|
|
|
|
// Reserve space for terminator
|
|
|
|
auto dst = bufferSpan.To(bufferSpan.Length() - 1);
|
|
|
|
for (;;) {
|
|
|
|
uint32_t result;
|
|
|
|
size_t read;
|
|
|
|
size_t written;
|
|
|
|
bool hadErrors;
|
|
|
|
if (aIsPlainText) {
|
|
|
|
Tie(result, read, written) =
|
|
|
|
aEncoder->EncodeFromUTF16WithoutReplacement(src, dst, false);
|
|
|
|
if (result != kInputEmpty && result != kOutputFull) {
|
|
|
|
// There's always room for one byte in the case of
|
|
|
|
// an unmappable character, because otherwise
|
|
|
|
// we'd have gotten `kOutputFull`.
|
|
|
|
dst[written++] = '?';
|
2002-08-27 00:23:14 +04:00
|
|
|
}
|
2017-04-27 13:27:03 +03:00
|
|
|
} else {
|
|
|
|
Tie(result, read, written, hadErrors) =
|
|
|
|
aEncoder->EncodeFromUTF16(src, dst, false);
|
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 14:57:30 +04:00
|
|
|
}
|
2017-04-27 13:27:03 +03:00
|
|
|
Unused << hadErrors;
|
|
|
|
src = src.From(read);
|
|
|
|
// Sadly, we still have test cases that implement nsIOutputStream in JS, so
|
|
|
|
// the buffer needs to be zero-terminated for XPConnect to do its thing.
|
|
|
|
// See bug 170416.
|
|
|
|
bufferSpan[written] = 0;
|
|
|
|
uint32_t streamWritten;
|
|
|
|
nsresult rv = aStream->Write(
|
|
|
|
reinterpret_cast<char*>(dst.Elements()), written, &streamWritten);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (result == kInputEmpty) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
}
|
1999-06-10 04:35:02 +04:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
nsDocumentEncoder::FlushText(nsAString& aString, bool aForce)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
if (!mStream)
|
|
|
|
return NS_OK;
|
1999-07-14 22:54:29 +04:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (aString.Length() > 1024 || aForce) {
|
2017-04-27 13:27:03 +03:00
|
|
|
rv = ConvertAndWrite(aString, mStream, mUnicodeEncoder.get(), mIsPlainText);
|
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 14:57:30 +04:00
|
|
|
|
|
|
|
aString.Truncate();
|
|
|
|
}
|
1999-07-14 22:54:29 +04:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsTextNode(nsINode *aNode)
|
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 14:57:30 +04:00
|
|
|
{
|
2010-04-30 15:15:09 +04:00
|
|
|
return aNode && aNode->IsNodeOfType(nsINode::eTEXT);
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-01-10 18:19:54 +04:00
|
|
|
nsDocumentEncoder::SerializeRangeNodes(nsRange* aRange,
|
2010-04-30 15:15:09 +04:00
|
|
|
nsINode* aNode,
|
2002-03-24 02:54:46 +03:00
|
|
|
nsAString& aString,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aDepth)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
|
|
|
NS_ENSURE_TRUE(content, NS_ERROR_FAILURE);
|
2000-10-12 02:50:14 +04:00
|
|
|
|
2010-05-25 03:24:15 +04:00
|
|
|
if (!IsVisibleNode(aNode))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2000-10-12 02:50:14 +04:00
|
|
|
// get start and end nodes for this recursion level
|
|
|
|
nsCOMPtr<nsIContent> startNode, endNode;
|
2010-05-25 03:24:15 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t start = mStartRootIndex - aDepth;
|
|
|
|
if (start >= 0 && (uint32_t)start <= mStartNodes.Length())
|
2010-05-25 03:24:15 +04:00
|
|
|
startNode = mStartNodes[start];
|
2001-12-21 04:10:07 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t end = mEndRootIndex - aDepth;
|
|
|
|
if (end >= 0 && (uint32_t)end <= mEndNodes.Length())
|
2010-05-25 03:24:15 +04:00
|
|
|
endNode = mEndNodes[end];
|
|
|
|
}
|
2001-12-21 04:10:07 +03:00
|
|
|
|
2010-05-25 03:24:15 +04:00
|
|
|
if (startNode != content && endNode != content)
|
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 14:57:30 +04:00
|
|
|
{
|
2000-10-12 02:50:14 +04:00
|
|
|
// node is completely contained in range. Serialize the whole subtree
|
|
|
|
// rooted by this node.
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = SerializeToStringRecursive(aNode, aString, false);
|
2000-10-12 02:50:14 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-24 21:09:12 +03:00
|
|
|
// due to implementation it is impossible for text node to be both start and end of
|
2000-10-12 02:50:14 +04:00
|
|
|
// range. We would have handled that case without getting here.
|
2010-04-30 15:15:09 +04:00
|
|
|
//XXXsmaug What does this all mean?
|
2000-10-12 02:50:14 +04:00
|
|
|
if (IsTextNode(aNode))
|
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 14:57:30 +04:00
|
|
|
{
|
2000-10-12 02:50:14 +04:00
|
|
|
if (startNode == content)
|
1999-08-26 01:42:20 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startOffset = aRange->StartOffset();
|
2000-10-12 02:50:14 +04:00
|
|
|
rv = SerializeNodeStart(aNode, startOffset, -1, aString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-06-10 04:35:02 +04:00
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
else
|
2000-10-12 02:50:14 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t endOffset = aRange->EndOffset();
|
2000-10-12 02:50:14 +04:00
|
|
|
rv = SerializeNodeStart(aNode, 0, endOffset, aString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-11-19 04:20:56 +03:00
|
|
|
if (aNode != mCommonParent)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
if (IncludeInContext(aNode))
|
|
|
|
{
|
|
|
|
// halt the incrementing of mStartDepth/mEndDepth. This is
|
|
|
|
// so paste client will include this node in paste.
|
2011-10-17 18:59:28 +04:00
|
|
|
mHaltRangeHint = 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 14:57:30 +04:00
|
|
|
}
|
2000-10-12 02:50:14 +04:00
|
|
|
if ((startNode == content) && !mHaltRangeHint) mStartDepth++;
|
|
|
|
if ((endNode == content) && !mHaltRangeHint) mEndDepth++;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2000-10-12 02:50:14 +04:00
|
|
|
// serialize the start of this node
|
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 14:57:30 +04:00
|
|
|
rv = SerializeNodeStart(aNode, 0, -1, aString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-10-12 02:50:14 +04:00
|
|
|
}
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
// do some calculations that will tell us which children of this
|
|
|
|
// node are in the range.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startOffset = 0, endOffset = -1;
|
2001-12-21 04:10:07 +03:00
|
|
|
if (startNode == content && mStartRootIndex >= aDepth)
|
2009-03-20 11:15:35 +03:00
|
|
|
startOffset = mStartOffsets[mStartRootIndex - aDepth];
|
2001-12-21 04:10:07 +03:00
|
|
|
if (endNode == content && mEndRootIndex >= aDepth)
|
2009-03-20 11:15:35 +03:00
|
|
|
endOffset = mEndOffsets[mEndRootIndex - aDepth];
|
2016-08-24 21:09:12 +03:00
|
|
|
// generated content will cause offset values of -1 to be returned.
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount = content->GetChildCount();
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2000-10-12 02:50:14 +04:00
|
|
|
if (startOffset == -1) startOffset = 0;
|
|
|
|
if (endOffset == -1) endOffset = childCount;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if we are at the "tip" of the selection, endOffset is fine.
|
|
|
|
// otherwise, we need to add one. This is because of the semantics
|
|
|
|
// of the offset list created by GetAncestorsAndOffsets(). The
|
2016-08-24 21:09:12 +03:00
|
|
|
// intermediate points on the list use the endOffset of the
|
2000-10-12 02:50:14 +04:00
|
|
|
// location of the ancestor, rather than just past it. So we need
|
|
|
|
// to add one here in order to include it in the children we serialize.
|
2017-07-11 15:11:37 +03:00
|
|
|
if (aNode != aRange->GetEndContainer())
|
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 14:57:30 +04:00
|
|
|
{
|
2000-10-12 02:50:14 +04:00
|
|
|
endOffset++;
|
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 14:57:30 +04:00
|
|
|
}
|
2000-10-12 02:50:14 +04:00
|
|
|
}
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2018-01-15 19:18:03 +03:00
|
|
|
if (endOffset) {
|
|
|
|
// serialize the children of this node that are in the range
|
|
|
|
nsIContent* childAsNode = content->GetFirstChild();
|
|
|
|
int32_t j = 0;
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2018-01-15 19:18:03 +03:00
|
|
|
for (; j < startOffset && childAsNode; ++j) {
|
|
|
|
childAsNode = childAsNode->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(!!childAsNode, NS_ERROR_FAILURE);
|
|
|
|
MOZ_ASSERT(j == startOffset);
|
|
|
|
|
|
|
|
for (; childAsNode && j < endOffset; ++j)
|
|
|
|
{
|
|
|
|
if ((j==startOffset) || (j==endOffset-1)) {
|
|
|
|
rv = SerializeRangeNodes(aRange, childAsNode, aString, aDepth+1);
|
|
|
|
} else {
|
|
|
|
rv = SerializeToStringRecursive(childAsNode, aString, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
childAsNode = childAsNode->GetNextSibling();
|
|
|
|
}
|
2000-10-12 02:50:14 +04:00
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
|
2000-10-12 02:50:14 +04:00
|
|
|
// serialize the end of this node
|
2003-11-19 04:20:56 +03:00
|
|
|
if (aNode != mCommonParent)
|
2000-10-12 02:50:14 +04:00
|
|
|
{
|
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 14:57:30 +04:00
|
|
|
rv = SerializeNodeEnd(aNode, aString);
|
2016-08-24 21:09:12 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-10-12 02:50:14 +04:00
|
|
|
}
|
1999-08-26 01:42:20 +04:00
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-04-30 15:15:09 +04:00
|
|
|
nsDocumentEncoder::SerializeRangeContextStart(const nsTArray<nsINode*>& aAncestorArray,
|
2002-03-24 02:54:46 +03:00
|
|
|
nsAString& aString)
|
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 14:57:30 +04:00
|
|
|
{
|
2012-05-16 20:39:54 +04:00
|
|
|
if (mDisableContextSerialize) {
|
2012-05-16 20:39:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-12-01 18:45:25 +03:00
|
|
|
|
|
|
|
AutoTArray<nsINode*, 8>* serializedContext = mRangeContexts.AppendElement();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i = aAncestorArray.Length(), j;
|
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 14:57:30 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2012-05-16 20:39:54 +04:00
|
|
|
// currently only for table-related elements; see Bug 137450
|
|
|
|
j = GetImmediateContextCount(aAncestorArray);
|
|
|
|
|
2001-12-21 04:10:07 +03:00
|
|
|
while (i > 0) {
|
2010-04-30 15:15:09 +04:00
|
|
|
nsINode *node = aAncestorArray.ElementAt(--i);
|
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 14:57:30 +04:00
|
|
|
|
|
|
|
if (!node)
|
|
|
|
break;
|
|
|
|
|
2012-05-16 20:39:54 +04:00
|
|
|
// Either a general inclusion or as immediate context
|
|
|
|
if (IncludeInContext(node) || i < j) {
|
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 14:57:30 +04:00
|
|
|
rv = SerializeNodeStart(node, 0, -1, aString);
|
2017-12-01 18:45:25 +03:00
|
|
|
serializedContext->AppendElement(node);
|
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 14:57:30 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-10 04:35:02 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsresult
|
2017-12-01 18:45:25 +03:00
|
|
|
nsDocumentEncoder::SerializeRangeContextEnd(nsAString& aString)
|
1999-06-10 04:35:02 +04:00
|
|
|
{
|
2012-05-16 20:39:54 +04:00
|
|
|
if (mDisableContextSerialize) {
|
2012-05-16 20:39:54 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
|
2017-12-01 18:45:25 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mRangeContexts.IsEmpty(), "Tried to end context without starting one.");
|
|
|
|
AutoTArray<nsINode*, 8>& serializedContext = mRangeContexts.LastElement();
|
2012-05-16 20:39:54 +04:00
|
|
|
|
2017-12-01 18:45:25 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
for (nsINode* node : Reversed(serializedContext)) {
|
|
|
|
rv = SerializeNodeEnd(node, aString);
|
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 14:57:30 +04:00
|
|
|
|
2017-12-01 18:45:25 +03:00
|
|
|
if (NS_FAILED(rv))
|
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 14:57:30 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-12-01 18:45:25 +03:00
|
|
|
mRangeContexts.RemoveElementAt(mRangeContexts.Length() - 1);
|
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 14:57:30 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-01-10 18:19:54 +04:00
|
|
|
nsDocumentEncoder::SerializeRangeToString(nsRange *aRange,
|
2002-03-24 02:54:46 +03:00
|
|
|
nsAString& aOutputString)
|
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 14:57:30 +04:00
|
|
|
{
|
2010-04-30 15:15:09 +04:00
|
|
|
if (!aRange || aRange->Collapsed())
|
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 14:57:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-04-30 15:15:09 +04:00
|
|
|
mCommonParent = aRange->GetCommonAncestor();
|
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 14:57:30 +04:00
|
|
|
|
2000-10-12 02:50:14 +04:00
|
|
|
if (!mCommonParent)
|
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 14:57:30 +04:00
|
|
|
return NS_OK;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2017-07-11 18:02:14 +03:00
|
|
|
nsINode* startContainer = aRange->GetStartContainer();
|
|
|
|
NS_ENSURE_TRUE(startContainer, NS_ERROR_FAILURE);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t startOffset = aRange->StartOffset();
|
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 14:57:30 +04:00
|
|
|
|
2017-07-11 18:08:37 +03:00
|
|
|
nsINode* endContainer = aRange->GetEndContainer();
|
|
|
|
NS_ENSURE_TRUE(endContainer, NS_ERROR_FAILURE);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t endOffset = aRange->EndOffset();
|
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 14:57:30 +04:00
|
|
|
|
2015-02-03 01:34:17 +03:00
|
|
|
mStartDepth = mEndDepth = 0;
|
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 14:57:30 +04:00
|
|
|
mCommonAncestors.Clear();
|
2000-10-12 02:50:14 +04:00
|
|
|
mStartNodes.Clear();
|
|
|
|
mStartOffsets.Clear();
|
|
|
|
mEndNodes.Clear();
|
|
|
|
mEndOffsets.Clear();
|
|
|
|
|
2010-04-30 15:15:09 +04:00
|
|
|
nsContentUtils::GetAncestors(mCommonParent, mCommonAncestors);
|
2017-07-11 18:02:14 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> sp = do_QueryInterface(startContainer);
|
2010-04-30 15:15:09 +04:00
|
|
|
nsContentUtils::GetAncestorsAndOffsets(sp, startOffset,
|
2002-06-26 00:03:06 +04:00
|
|
|
&mStartNodes, &mStartOffsets);
|
2017-07-11 18:08:37 +03:00
|
|
|
nsCOMPtr<nsIDOMNode> ep = do_QueryInterface(endContainer);
|
2010-04-30 15:15:09 +04:00
|
|
|
nsContentUtils::GetAncestorsAndOffsets(ep, endOffset,
|
2002-06-26 00:03:06 +04:00
|
|
|
&mEndNodes, &mEndOffsets);
|
|
|
|
|
2000-10-12 02:50:14 +04:00
|
|
|
nsCOMPtr<nsIContent> commonContent = do_QueryInterface(mCommonParent);
|
|
|
|
mStartRootIndex = mStartNodes.IndexOf(commonContent);
|
|
|
|
mEndRootIndex = mEndNodes.IndexOf(commonContent);
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
rv = SerializeRangeContextStart(mCommonAncestors, aOutputString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-07-11 18:08:37 +03:00
|
|
|
if (startContainer == endContainer && IsTextNode(startContainer)) {
|
2010-05-25 03:24:15 +04:00
|
|
|
if (mFlags & SkipInvisibleContent) {
|
|
|
|
// Check that the parent is visible if we don't a frame.
|
|
|
|
// IsVisibleNode() will do it when there's a frame.
|
2017-07-11 18:02:14 +03:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(startContainer);
|
2010-05-25 03:24:15 +04:00
|
|
|
if (content && !content->GetPrimaryFrame()) {
|
|
|
|
nsIContent* parent = content->GetParent();
|
|
|
|
if (!parent || !IsVisibleNode(parent))
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2017-07-11 18:02:14 +03:00
|
|
|
rv = SerializeNodeStart(startContainer, startOffset, endOffset,
|
|
|
|
aOutputString);
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-07-11 18:02:14 +03:00
|
|
|
} else {
|
2000-10-12 02:50:14 +04:00
|
|
|
rv = SerializeRangeNodes(aRange, mCommonParent, aOutputString, 0);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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 14:57:30 +04:00
|
|
|
}
|
2017-12-01 18:45:25 +03:00
|
|
|
rv = SerializeRangeContextEnd(aOutputString);
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-04-24 12:14:53 +03:00
|
|
|
void
|
|
|
|
nsDocumentEncoder::Clear()
|
|
|
|
{
|
|
|
|
mDocument = nullptr;
|
|
|
|
mSelection = nullptr;
|
|
|
|
mRange = nullptr;
|
|
|
|
mNode = nullptr;
|
|
|
|
mCommonParent = nullptr;
|
|
|
|
mNodeFixup = nullptr;
|
|
|
|
|
|
|
|
Initialize(false);
|
|
|
|
}
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 02:54:46 +03:00
|
|
|
nsDocumentEncoder::EncodeToString(nsAString& aOutputString)
|
2014-04-17 02:01:55 +04:00
|
|
|
{
|
|
|
|
return EncodeToStringWithMaxLength(0, aOutputString);
|
|
|
|
}
|
|
|
|
|
2017-08-14 14:24:51 +03:00
|
|
|
static bool ParentIsTR(nsIContent* aContent) {
|
|
|
|
mozilla::dom::Element* parent = aContent->GetParentElement();
|
|
|
|
if (!parent) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return parent->IsHTMLElement(nsGkAtoms::tr);
|
|
|
|
}
|
|
|
|
|
2014-04-17 02:01:55 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocumentEncoder::EncodeToStringWithMaxLength(uint32_t aMaxLength,
|
|
|
|
nsAString& aOutputString)
|
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 14:57:30 +04:00
|
|
|
{
|
2017-12-01 18:45:25 +03:00
|
|
|
MOZ_ASSERT(mRangeContexts.IsEmpty(), "Re-entrant call to nsDocumentEncoder.");
|
|
|
|
auto rangeContextGuard = MakeScopeExit([&] {
|
|
|
|
mRangeContexts.Clear();
|
|
|
|
});
|
|
|
|
|
1999-06-10 04:35:02 +04:00
|
|
|
if (!mDocument)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2017-04-17 13:49:52 +03:00
|
|
|
AutoReleaseDocumentIfNeeded autoReleaseDocument(this);
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
aOutputString.Truncate();
|
|
|
|
|
2010-06-27 00:39:56 +04:00
|
|
|
nsString output;
|
|
|
|
static const size_t bufferSize = 2048;
|
|
|
|
if (!mCachedBuffer) {
|
2014-03-15 23:00:15 +04:00
|
|
|
mCachedBuffer = nsStringBuffer::Alloc(bufferSize).take();
|
2016-01-20 02:01:40 +03:00
|
|
|
if (NS_WARN_IF(!mCachedBuffer)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2010-06-27 00:39:56 +04:00
|
|
|
}
|
|
|
|
NS_ASSERTION(!mCachedBuffer->IsReadonly(),
|
|
|
|
"DocumentEncoder shouldn't keep reference to non-readonly buffer!");
|
2014-01-04 19:02:17 +04:00
|
|
|
static_cast<char16_t*>(mCachedBuffer->Data())[0] = char16_t(0);
|
2011-10-17 18:59:28 +04:00
|
|
|
mCachedBuffer->ToString(0, output, true);
|
2010-06-27 00:39:56 +04:00
|
|
|
// output owns the buffer now!
|
2012-07-30 18:20:58 +04:00
|
|
|
mCachedBuffer = nullptr;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2010-06-27 00:39:56 +04:00
|
|
|
|
|
|
|
if (!mSerializer) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString progId(NS_CONTENTSERIALIZER_CONTRACTID_PREFIX);
|
2010-06-27 00:39:56 +04:00
|
|
|
AppendUTF16toUTF8(mMimeType, progId);
|
1999-06-10 04:35:02 +04:00
|
|
|
|
2010-06-27 00:39:56 +04:00
|
|
|
mSerializer = do_CreateInstance(progId.get());
|
|
|
|
NS_ENSURE_TRUE(mSerializer, NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
}
|
1999-06-10 04:35:02 +04:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsresult rv = NS_OK;
|
1999-06-10 04:35:02 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool rewriteEncodingDeclaration = !(mSelection || mRange || mNode) && !(mFlags & OutputDontRewriteEncodingDeclaration);
|
2017-04-27 13:27:03 +03:00
|
|
|
mSerializer->Init(
|
|
|
|
mFlags, mWrapColumn, mEncoding, mIsCopying, rewriteEncodingDeclaration, &mNeedsPreformatScanning);
|
2001-02-13 04:00:14 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
if (mSelection) {
|
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i, count = 0;
|
1999-07-14 22:54:29 +04:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
rv = mSelection->GetRangeCount(&count);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-08-26 01:42:20 +04:00
|
|
|
|
2007-03-27 19:10:23 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> node, prevNode;
|
2015-02-03 01:34:17 +03:00
|
|
|
uint32_t firstRangeStartDepth = 0;
|
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 14:57:30 +04:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
mSelection->GetRangeAt(i, getter_AddRefs(range));
|
1999-09-07 23:13:04 +04:00
|
|
|
|
2007-03-27 19:10:23 +04:00
|
|
|
// Bug 236546: newlines not added when copying table cells into clipboard
|
|
|
|
// Each selected cell shows up as a range containing a row with a single cell
|
|
|
|
// get the row, compare it to previous row and emit </tr><tr> as needed
|
2012-05-16 20:39:54 +04:00
|
|
|
// Bug 137450: Problem copying/pasting a table from a web page to Excel.
|
|
|
|
// Each separate block of <tr></tr> produced above will be wrapped by the
|
|
|
|
// immediate context. This assumes that you can't select cells that are
|
|
|
|
// multiple selections from two tables simultaneously.
|
2007-03-27 19:10:23 +04:00
|
|
|
range->GetStartContainer(getter_AddRefs(node));
|
|
|
|
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
|
2007-05-26 00:47:30 +04:00
|
|
|
if (node != prevNode) {
|
2012-05-16 20:39:54 +04:00
|
|
|
nsCOMPtr<nsINode> p;
|
2007-05-26 00:47:30 +04:00
|
|
|
if (prevNode) {
|
2012-05-16 20:39:54 +04:00
|
|
|
p = do_QueryInterface(prevNode);
|
2010-06-27 00:39:56 +04:00
|
|
|
rv = SerializeNodeEnd(p, output);
|
2007-05-26 00:47:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(node);
|
2017-08-14 14:24:51 +03:00
|
|
|
if (content && content->IsHTMLElement(nsGkAtoms::tr) && !ParentIsTR(content)) {
|
2012-05-16 20:39:54 +04:00
|
|
|
nsINode* n = content;
|
|
|
|
if (!prevNode) {
|
|
|
|
// Went from a non-<tr> to a <tr>
|
|
|
|
mCommonAncestors.Clear();
|
2012-10-09 16:31:24 +04:00
|
|
|
nsContentUtils::GetAncestors(n->GetParentNode(), mCommonAncestors);
|
2012-05-16 20:39:54 +04:00
|
|
|
rv = SerializeRangeContextStart(mCommonAncestors, output);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Don't let SerializeRangeToString serialize the context again
|
2012-05-16 20:39:54 +04:00
|
|
|
mDisableContextSerialize = true;
|
2012-05-16 20:39:54 +04:00
|
|
|
}
|
|
|
|
|
2010-06-27 00:39:56 +04:00
|
|
|
rv = SerializeNodeStart(n, 0, -1, output);
|
2007-05-26 00:47:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
prevNode = node;
|
2012-05-16 20:39:54 +04:00
|
|
|
} else if (prevNode) {
|
|
|
|
// Went from a <tr> to a non-<tr>
|
2012-05-16 20:39:54 +04:00
|
|
|
mDisableContextSerialize = false;
|
2017-12-01 18:45:25 +03:00
|
|
|
rv = SerializeRangeContextEnd(output);
|
2012-05-16 20:39:54 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-07-30 18:20:58 +04:00
|
|
|
prevNode = nullptr;
|
2007-03-27 19:10:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 18:19:54 +04:00
|
|
|
nsRange* r = static_cast<nsRange*>(range.get());
|
2010-06-27 00:39:56 +04:00
|
|
|
rv = SerializeRangeToString(r, output);
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-02-03 01:34:17 +03:00
|
|
|
if (i == 0) {
|
|
|
|
firstRangeStartDepth = mStartDepth;
|
|
|
|
}
|
1999-08-26 01:42:20 +04:00
|
|
|
}
|
2015-02-03 01:34:17 +03:00
|
|
|
mStartDepth = firstRangeStartDepth;
|
2012-05-16 20:39:54 +04:00
|
|
|
|
2007-05-26 00:47:30 +04:00
|
|
|
if (prevNode) {
|
2010-04-30 15:15:09 +04:00
|
|
|
nsCOMPtr<nsINode> p = do_QueryInterface(prevNode);
|
2010-06-27 00:39:56 +04:00
|
|
|
rv = SerializeNodeEnd(p, output);
|
2007-05-26 00:47:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2016-08-24 21:09:12 +03:00
|
|
|
mDisableContextSerialize = false;
|
2017-12-01 18:45:25 +03:00
|
|
|
rv = SerializeRangeContextEnd(output);
|
2012-05-16 20:39:54 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-27 19:10:23 +04:00
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
|
2012-05-16 20:39:54 +04:00
|
|
|
// Just to be safe
|
2016-08-24 21:09:12 +03:00
|
|
|
mDisableContextSerialize = false;
|
2012-05-16 20:39:54 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mSelection = nullptr;
|
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 14:57:30 +04:00
|
|
|
} else if (mRange) {
|
2010-06-27 00:39:56 +04:00
|
|
|
rv = SerializeRangeToString(mRange, output);
|
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 14:57:30 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mRange = nullptr;
|
2003-04-15 22:13:13 +04:00
|
|
|
} else if (mNode) {
|
2010-10-15 21:59:00 +04:00
|
|
|
if (!mNodeFixup && !(mFlags & SkipInvisibleContent) && !mStream &&
|
|
|
|
mNodeIsContainer) {
|
|
|
|
rv = SerializeToStringIterative(mNode, output);
|
|
|
|
} else {
|
|
|
|
rv = SerializeToStringRecursive(mNode, output, mNodeIsContainer);
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mNode = nullptr;
|
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 14:57:30 +04:00
|
|
|
} else {
|
2010-06-27 00:39:56 +04:00
|
|
|
rv = mSerializer->AppendDocumentStart(mDocument, output);
|
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 14:57:30 +04:00
|
|
|
|
2002-08-13 22:41:16 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2014-04-17 02:01:55 +04:00
|
|
|
rv = SerializeToStringRecursive(mDocument, output, false, aMaxLength);
|
2002-08-13 22:41:16 +04:00
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-06-27 00:39:56 +04:00
|
|
|
rv = mSerializer->Flush(output);
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2010-06-27 00:39:56 +04:00
|
|
|
mCachedBuffer = nsStringBuffer::FromString(output);
|
2010-10-07 05:01:24 +04:00
|
|
|
// We have to be careful how we set aOutputString, because we don't
|
|
|
|
// want it to end up sharing mCachedBuffer if we plan to reuse it.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool setOutput = false;
|
2010-06-27 00:39:56 +04:00
|
|
|
// Try to cache the buffer.
|
2010-10-07 05:01:24 +04:00
|
|
|
if (mCachedBuffer) {
|
|
|
|
if (mCachedBuffer->StorageSize() == bufferSize &&
|
|
|
|
!mCachedBuffer->IsReadonly()) {
|
|
|
|
mCachedBuffer->AddRef();
|
|
|
|
} else {
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mCachedBuffer->ToString(output.Length(), aOutputString);
|
2011-10-17 18:59:28 +04:00
|
|
|
setOutput = true;
|
2010-10-07 05:01:24 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mCachedBuffer = nullptr;
|
2010-10-07 05:01:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!setOutput && NS_SUCCEEDED(rv)) {
|
|
|
|
aOutputString.Append(output.get(), output.Length());
|
2010-06-27 00:39:56 +04:00
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
|
1999-06-10 04:35:02 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocumentEncoder::EncodeToStream(nsIOutputStream* aStream)
|
|
|
|
{
|
2017-12-01 18:45:25 +03:00
|
|
|
MOZ_ASSERT(mRangeContexts.IsEmpty(), "Re-entrant call to nsDocumentEncoder.");
|
|
|
|
auto rangeContextGuard = MakeScopeExit([&] {
|
|
|
|
mRangeContexts.Clear();
|
|
|
|
});
|
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 14:57:30 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!mDocument)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2017-04-27 13:27:03 +03:00
|
|
|
if (!mEncoding) {
|
2014-05-08 13:32:00 +04:00
|
|
|
return NS_ERROR_UCONV_NOCONV;
|
2001-02-13 04:00:14 +03:00
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
|
2017-04-27 13:27:03 +03:00
|
|
|
mUnicodeEncoder = mEncoding->NewEncoder();
|
|
|
|
|
|
|
|
mIsPlainText = (mMimeType.LowerCaseEqualsLiteral("text/plain"));
|
2001-03-24 02:39:04 +03:00
|
|
|
|
2013-05-17 00:11:55 +04:00
|
|
|
mStream = aStream;
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsAutoString buf;
|
|
|
|
|
|
|
|
rv = EncodeToString(buf);
|
|
|
|
|
|
|
|
// Force a flush of the last chunk of data.
|
2011-10-17 18:59:28 +04:00
|
|
|
FlushText(buf, 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 14:57:30 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mStream = nullptr;
|
|
|
|
mUnicodeEncoder = nullptr;
|
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 14:57:30 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-03-14 20:12:41 +03:00
|
|
|
nsDocumentEncoder::EncodeToStringWithContext(nsAString& aContextString,
|
|
|
|
nsAString& aInfoString,
|
|
|
|
nsAString& aEncodedString)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2000-11-30 04:08:22 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDocumentEncoder::SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup)
|
|
|
|
{
|
|
|
|
mNodeFixup = aFixup;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsresult NS_NewTextEncoder(nsIDocumentEncoder** aResult); // make mac compiler happy
|
|
|
|
|
1999-06-10 04:35:02 +04:00
|
|
|
nsresult
|
|
|
|
NS_NewTextEncoder(nsIDocumentEncoder** aResult)
|
|
|
|
{
|
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 14:57:30 +04:00
|
|
|
*aResult = new nsDocumentEncoder;
|
1999-06-10 04:35:02 +04:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
class nsHTMLCopyEncoder : public nsDocumentEncoder
|
1999-06-04 05:04:08 +04:00
|
|
|
{
|
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 14:57:30 +04:00
|
|
|
public:
|
1999-06-04 05:04:08 +04:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsHTMLCopyEncoder();
|
|
|
|
virtual ~nsHTMLCopyEncoder();
|
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
NS_IMETHOD Init(nsIDOMDocument* aDocument, const nsAString& aMimeType, uint32_t aFlags) override;
|
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 14:57:30 +04:00
|
|
|
|
|
|
|
// overridden methods from nsDocumentEncoder
|
2017-11-06 06:37:28 +03:00
|
|
|
NS_IMETHOD SetSelection(nsISelection* aSelection) override;
|
2006-03-14 20:12:41 +03:00
|
|
|
NS_IMETHOD EncodeToStringWithContext(nsAString& aContextString,
|
|
|
|
nsAString& aInfoString,
|
2017-11-06 06:37:28 +03:00
|
|
|
nsAString& aEncodedString) override;
|
|
|
|
NS_IMETHOD EncodeToString(nsAString& aOutputString) override;
|
1999-06-04 05:04:08 +04:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
protected:
|
1999-06-04 05:04:08 +04:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
enum Endpoint
|
|
|
|
{
|
|
|
|
kStart,
|
|
|
|
kEnd
|
|
|
|
};
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsresult PromoteRange(nsIDOMRange *inRange);
|
2016-08-24 21:09:12 +03:00
|
|
|
nsresult PromoteAncestorChain(nsCOMPtr<nsIDOMNode> *ioNode,
|
|
|
|
int32_t *ioStartOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t *ioEndOffset);
|
2016-08-24 21:09:12 +03:00
|
|
|
nsresult GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t aOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> *outNode, int32_t *outOffset, nsIDOMNode *aCommon);
|
|
|
|
nsCOMPtr<nsIDOMNode> GetChildAt(nsIDOMNode *aParent, int32_t aOffset);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsMozBR(nsIDOMNode* aNode);
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult GetNodeLocation(nsIDOMNode *inChild, nsCOMPtr<nsIDOMNode> *outParent, int32_t *outOffset);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsRoot(nsIDOMNode* aNode);
|
|
|
|
bool IsFirstNode(nsIDOMNode *aNode);
|
|
|
|
bool IsLastNode(nsIDOMNode *aNode);
|
|
|
|
bool IsEmptyTextContent(nsIDOMNode* aNode);
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual bool IncludeInContext(nsINode *aNode) override;
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual int32_t
|
2017-11-06 06:37:28 +03:00
|
|
|
GetImmediateContextCount(const nsTArray<nsINode*>& aAncestorArray) override;
|
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 14:57:30 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsTextWidget;
|
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 14:57:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
nsHTMLCopyEncoder::nsHTMLCopyEncoder()
|
1999-06-04 05:04:08 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsTextWidget = false;
|
1999-06-04 05:04:08 +04:00
|
|
|
}
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsHTMLCopyEncoder::~nsHTMLCopyEncoder()
|
1999-06-04 05:04:08 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
NS_IMETHODIMP
|
2006-05-01 09:25:52 +04:00
|
|
|
nsHTMLCopyEncoder::Init(nsIDOMDocument* aDocument,
|
2010-05-25 03:24:15 +04:00
|
|
|
const nsAString& aMimeType,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
if (!aDocument)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsTextWidget = false;
|
2005-01-21 02:20:59 +03:00
|
|
|
Initialize();
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsCopying = true;
|
2006-05-01 09:25:52 +04:00
|
|
|
mDocument = do_QueryInterface(aDocument);
|
|
|
|
NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
|
2005-01-21 02:20:59 +03:00
|
|
|
|
2012-03-31 18:10:34 +04:00
|
|
|
// Hack, hack! Traditionally, the caller passes text/unicode, which is
|
|
|
|
// treated as "guess text/html or text/plain" in this context. (It has a
|
|
|
|
// different meaning in other contexts. Sigh.) From now on, "text/plain"
|
|
|
|
// means forcing text/plain instead of guessing.
|
|
|
|
if (aMimeType.EqualsLiteral("text/plain")) {
|
|
|
|
mMimeType.AssignLiteral("text/plain");
|
|
|
|
} else {
|
|
|
|
mMimeType.AssignLiteral("text/html");
|
|
|
|
}
|
2010-05-25 03:24:15 +04:00
|
|
|
|
2001-01-24 17:59:57 +03:00
|
|
|
// Make all links absolute when copying
|
|
|
|
// (see related bugs #57296, #41924, #58646, #32768)
|
|
|
|
mFlags = aFlags | OutputAbsoluteLinks;
|
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 14:57:30 +04:00
|
|
|
|
2003-06-26 10:10:03 +04:00
|
|
|
if (!mDocument->IsScriptEnabled())
|
2001-10-02 14:02:07 +04:00
|
|
|
mFlags |= OutputNoScriptContent;
|
|
|
|
|
2002-11-22 15:20:05 +03:00
|
|
|
return NS_OK;
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLCopyEncoder::SetSelection(nsISelection* aSelection)
|
|
|
|
{
|
2000-10-12 02:50:14 +04:00
|
|
|
// check for text widgets: we need to recognize these so that
|
|
|
|
// we don't tweak the selection to be outside of the magic
|
|
|
|
// div that ender-lite text widgets are embedded in.
|
2016-08-24 21:09:12 +03:00
|
|
|
|
|
|
|
if (!aSelection)
|
2001-02-15 16:22:26 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2001-02-15 16:22:26 +03:00
|
|
|
nsCOMPtr<nsIDOMRange> range;
|
|
|
|
nsCOMPtr<nsIDOMNode> commonParent;
|
2016-06-17 16:32:49 +03:00
|
|
|
Selection* selection = aSelection->AsSelection();
|
2015-02-25 19:08:00 +03:00
|
|
|
uint32_t rangeCount = selection->RangeCount();
|
2001-02-15 16:22:26 +03:00
|
|
|
|
|
|
|
// if selection is uninitialized return
|
2013-02-07 18:17:47 +04:00
|
|
|
if (!rangeCount)
|
2001-02-15 16:22:26 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2001-02-15 16:22:26 +03:00
|
|
|
// we'll just use the common parent of the first range. Implicit assumption
|
|
|
|
// here that multi-range selections are table cell selections, in which case
|
|
|
|
// the common parent is somewhere in the table and we don't really care where.
|
2013-02-07 18:17:47 +04:00
|
|
|
nsresult rv = aSelection->GetRangeAt(0, getter_AddRefs(range));
|
2001-02-15 16:22:26 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!range)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
range->GetCommonAncestorContainer(getter_AddRefs(commonParent));
|
|
|
|
|
2003-07-29 01:09:56 +04:00
|
|
|
for (nsCOMPtr<nsIContent> selContent(do_QueryInterface(commonParent));
|
|
|
|
selContent;
|
|
|
|
selContent = selContent->GetParent())
|
2000-10-12 02:50:14 +04:00
|
|
|
{
|
2001-02-15 16:22:26 +03:00
|
|
|
// checking for selection inside a plaintext form widget
|
2015-03-03 14:09:00 +03:00
|
|
|
if (selContent->IsAnyOfHTMLElements(nsGkAtoms::input, nsGkAtoms::textarea))
|
2000-10-12 02:50:14 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsTextWidget = true;
|
2000-10-12 02:50:14 +04:00
|
|
|
break;
|
|
|
|
}
|
2016-02-09 08:47:00 +03:00
|
|
|
#if defined(MOZ_THUNDERBIRD) || defined(MOZ_SUITE)
|
2015-11-26 11:21:00 +03:00
|
|
|
else if (selContent->IsHTMLElement(nsGkAtoms::body)) {
|
|
|
|
// Currently, setting mIsTextWidget to 'true' will result in the selection
|
|
|
|
// being encoded/copied as pre-formatted plain text.
|
|
|
|
// This is fine for copying pre-formatted plain text with Firefox, it is
|
|
|
|
// already not correct for copying pre-formatted "rich" text (bold, colour)
|
|
|
|
// with Firefox. As long as the serialisers aren't fixed, copying
|
|
|
|
// pre-formatted text in Firefox is broken. If we set mIsTextWidget,
|
|
|
|
// pre-formatted plain text is copied, but pre-formatted "rich" text loses
|
|
|
|
// the "rich" formatting. If we don't set mIsTextWidget, "rich" text
|
|
|
|
// attributes aren't lost, but white-space is lost.
|
|
|
|
// So far the story for Firefox.
|
|
|
|
//
|
|
|
|
// Thunderbird has two *conflicting* requirements.
|
|
|
|
// Case 1:
|
|
|
|
// When selecting and copying text, even pre-formatted text, as a quote
|
|
|
|
// to be placed into a reply, we *always* expect HTML to be copied.
|
|
|
|
// Case 2:
|
|
|
|
// When copying text in a so-called "plain text" message, that is
|
|
|
|
// one where the body carries style "white-space:pre-wrap", the text should
|
|
|
|
// be copied as pre-formatted plain text.
|
|
|
|
//
|
|
|
|
// Therefore the following code checks for "pre-wrap" on the body.
|
|
|
|
// This is a terrible hack.
|
|
|
|
//
|
|
|
|
// The proper fix would be this:
|
|
|
|
// For case 1:
|
|
|
|
// Communicate the fact that HTML is required to EncodeToString(),
|
|
|
|
// bug 1141786.
|
|
|
|
// For case 2:
|
|
|
|
// Wait for Firefox to get fixed to detect pre-formatting correctly,
|
|
|
|
// bug 1174452.
|
|
|
|
nsAutoString styleVal;
|
2017-12-26 03:58:00 +03:00
|
|
|
if (selContent->IsElement() &&
|
|
|
|
selContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::style, styleVal) &&
|
2015-11-26 11:21:00 +03:00
|
|
|
styleVal.Find(NS_LITERAL_STRING("pre-wrap")) != kNotFound) {
|
|
|
|
mIsTextWidget = true;
|
|
|
|
break;
|
2015-11-06 22:42:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2000-10-12 02:50:14 +04:00
|
|
|
}
|
2015-02-26 22:34:09 +03:00
|
|
|
|
2000-10-12 02:50:14 +04:00
|
|
|
// normalize selection if we are not in a widget
|
2016-08-24 21:09:12 +03:00
|
|
|
if (mIsTextWidget)
|
2000-10-12 02:50:14 +04:00
|
|
|
{
|
|
|
|
mSelection = aSelection;
|
2004-06-17 04:13:25 +04:00
|
|
|
mMimeType.AssignLiteral("text/plain");
|
2000-10-12 02:50:14 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-04-03 22:39:06 +04:00
|
|
|
|
2017-02-25 13:33:34 +03:00
|
|
|
// XXX We should try to get rid of the Selection object here.
|
|
|
|
// XXX bug 1245883
|
|
|
|
|
2013-04-03 22:39:06 +04:00
|
|
|
// also consider ourselves in a text widget if we can't find an html document
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!(htmlDoc && mDocument->IsHTMLDocument())) {
|
2013-04-03 22:39:06 +04:00
|
|
|
mIsTextWidget = true;
|
|
|
|
mSelection = aSelection;
|
|
|
|
// mMimeType is set to text/plain when encoding starts.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
// there's no Clone() for selection! fix...
|
|
|
|
//nsresult rv = aSelection->Clone(getter_AddRefs(mSelection);
|
|
|
|
//NS_ENSURE_SUCCESS(rv, rv);
|
2000-10-12 02:50:14 +04:00
|
|
|
NS_NewDomSelection(getter_AddRefs(mSelection));
|
|
|
|
NS_ENSURE_TRUE(mSelection, NS_ERROR_FAILURE);
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
// loop thru the ranges in the selection
|
2013-02-07 18:17:47 +04:00
|
|
|
for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
|
|
|
|
range = selection->GetRangeAt(rangeIdx);
|
2000-10-12 02:50:14 +04:00
|
|
|
NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIDOMRange> myRange;
|
|
|
|
range->CloneRange(getter_AddRefs(myRange));
|
|
|
|
NS_ENSURE_TRUE(myRange, NS_ERROR_FAILURE);
|
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 14:57:30 +04:00
|
|
|
|
|
|
|
// adjust range to include any ancestors who's children are entirely selected
|
2000-10-12 02:50:14 +04:00
|
|
|
rv = PromoteRange(myRange);
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2017-02-25 13:33:34 +03:00
|
|
|
ErrorResult result;
|
|
|
|
nsRange* r = static_cast<nsRange*>(myRange.get());
|
|
|
|
mSelection->AsSelection()->AddRangeInternal(*r, mDocument, result);
|
|
|
|
rv = result.StealNSResult();
|
2000-10-12 02:50:14 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-04 05:04:08 +04:00
|
|
|
|
2013-04-03 22:39:06 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLCopyEncoder::EncodeToString(nsAString& aOutputString)
|
|
|
|
{
|
|
|
|
if (mIsTextWidget) {
|
|
|
|
mMimeType.AssignLiteral("text/plain");
|
|
|
|
}
|
|
|
|
return nsDocumentEncoder::EncodeToString(aOutputString);
|
|
|
|
}
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
NS_IMETHODIMP
|
2006-03-14 20:12:41 +03:00
|
|
|
nsHTMLCopyEncoder::EncodeToStringWithContext(nsAString& aContextString,
|
|
|
|
nsAString& aInfoString,
|
|
|
|
nsAString& aEncodedString)
|
1999-06-04 05:04:08 +04:00
|
|
|
{
|
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 14:57:30 +04:00
|
|
|
nsresult rv = EncodeToString(aEncodedString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-10-12 02:50:14 +04:00
|
|
|
|
|
|
|
// do not encode any context info or range hints if we are in a text widget.
|
|
|
|
if (mIsTextWidget) return NS_OK;
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
// now encode common ancestors into aContextString. Note that the common ancestors
|
|
|
|
// will be for the last range in the selection in the case of multirange selections.
|
2016-08-24 21:09:12 +03:00
|
|
|
// encoding ancestors every range in a multirange selection in a way that could be
|
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 14:57:30 +04:00
|
|
|
// understood by the paste code would be a lot more work to do. As a practical matter,
|
|
|
|
// selections are single range, and the ones that aren't are table cell selections
|
|
|
|
// where all the cells are in the same table.
|
|
|
|
|
|
|
|
// leaf of ancestors might be text node. If so discard it.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = mCommonAncestors.Length();
|
|
|
|
int32_t i;
|
2010-04-30 15:15:09 +04:00
|
|
|
nsCOMPtr<nsINode> node;
|
2001-12-21 04:10:07 +03:00
|
|
|
if (count > 0)
|
2009-03-20 11:15:35 +03:00
|
|
|
node = mCommonAncestors.ElementAt(0);
|
2001-12-21 04:10:07 +03:00
|
|
|
|
2016-08-24 21:09:12 +03:00
|
|
|
if (node && IsTextNode(node))
|
2001-03-09 04:36:38 +03:00
|
|
|
{
|
|
|
|
mCommonAncestors.RemoveElementAt(0);
|
|
|
|
// don't forget to adjust range depth info
|
|
|
|
if (mStartDepth) mStartDepth--;
|
|
|
|
if (mEndDepth) mEndDepth--;
|
2001-12-21 04:10:07 +03:00
|
|
|
// and the count
|
|
|
|
count--;
|
2001-03-09 04:36:38 +03:00
|
|
|
}
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2001-12-21 04:10:07 +03:00
|
|
|
i = count;
|
|
|
|
while (i > 0)
|
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 14:57:30 +04:00
|
|
|
{
|
2009-03-20 11:15:35 +03:00
|
|
|
node = mCommonAncestors.ElementAt(--i);
|
2001-12-21 04:10:07 +03:00
|
|
|
SerializeNodeStart(node, 0, -1, aContextString);
|
1999-06-04 05:04:08 +04:00
|
|
|
}
|
2001-12-21 04:10:07 +03:00
|
|
|
//i = 0; guaranteed by above
|
|
|
|
while (i < count)
|
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 14:57:30 +04:00
|
|
|
{
|
2009-03-20 11:15:35 +03:00
|
|
|
node = mCommonAncestors.ElementAt(i++);
|
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 14:57:30 +04:00
|
|
|
SerializeNodeEnd(node, aContextString);
|
|
|
|
}
|
1999-06-04 05:04:08 +04:00
|
|
|
|
2016-08-24 21:09:12 +03:00
|
|
|
// encode range info : the start and end depth of the selection, where the depth is
|
2002-03-22 02:31:26 +03:00
|
|
|
// distance down in the parent hierarchy. Later we will need to add leading/trailing
|
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 14:57:30 +04:00
|
|
|
// whitespace info to this.
|
|
|
|
nsAutoString infoString;
|
|
|
|
infoString.AppendInt(mStartDepth);
|
2014-01-04 19:02:17 +04:00
|
|
|
infoString.Append(char16_t(','));
|
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 14:57:30 +04:00
|
|
|
infoString.AppendInt(mEndDepth);
|
|
|
|
aInfoString = infoString;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
return NS_OK;
|
1999-06-04 05:04:08 +04:00
|
|
|
}
|
|
|
|
|
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 14:57:30 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-04-30 15:15:09 +04:00
|
|
|
nsHTMLCopyEncoder::IncludeInContext(nsINode *aNode)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
|
|
|
|
|
|
|
|
if (!content)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
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 14:57:30 +04:00
|
|
|
|
2015-03-03 14:09:00 +03:00
|
|
|
return content->IsAnyOfHTMLElements(nsGkAtoms::b,
|
|
|
|
nsGkAtoms::i,
|
|
|
|
nsGkAtoms::u,
|
|
|
|
nsGkAtoms::a,
|
|
|
|
nsGkAtoms::tt,
|
|
|
|
nsGkAtoms::s,
|
|
|
|
nsGkAtoms::big,
|
|
|
|
nsGkAtoms::small,
|
|
|
|
nsGkAtoms::strike,
|
|
|
|
nsGkAtoms::em,
|
|
|
|
nsGkAtoms::strong,
|
|
|
|
nsGkAtoms::dfn,
|
|
|
|
nsGkAtoms::code,
|
|
|
|
nsGkAtoms::cite,
|
|
|
|
nsGkAtoms::var,
|
|
|
|
nsGkAtoms::abbr,
|
|
|
|
nsGkAtoms::font,
|
|
|
|
nsGkAtoms::script,
|
|
|
|
nsGkAtoms::span,
|
|
|
|
nsGkAtoms::pre,
|
|
|
|
nsGkAtoms::h1,
|
|
|
|
nsGkAtoms::h2,
|
|
|
|
nsGkAtoms::h3,
|
|
|
|
nsGkAtoms::h4,
|
|
|
|
nsGkAtoms::h5,
|
|
|
|
nsGkAtoms::h6);
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-24 21:09:12 +03:00
|
|
|
nsresult
|
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 14:57:30 +04:00
|
|
|
nsHTMLCopyEncoder::PromoteRange(nsIDOMRange *inRange)
|
|
|
|
{
|
2017-07-19 16:49:52 +03:00
|
|
|
RefPtr<nsRange> range = static_cast<nsRange*>(inRange);
|
|
|
|
if (!range) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
nsresult rv;
|
2002-09-04 01:55:03 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> startNode, endNode, common;
|
2017-07-19 16:49:52 +03:00
|
|
|
uint32_t startOffset, endOffset;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2002-09-04 01:55:03 +04:00
|
|
|
rv = inRange->GetCommonAncestorContainer(getter_AddRefs(common));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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 14:57:30 +04:00
|
|
|
rv = inRange->GetStartContainer(getter_AddRefs(startNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = inRange->GetStartOffset(&startOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = inRange->GetEndContainer(getter_AddRefs(endNode));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = inRange->GetEndOffset(&endOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> opStartNode;
|
|
|
|
nsCOMPtr<nsIDOMNode> opEndNode;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t opStartOffset, opEndOffset;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
|
|
|
// examine range endpoints.
|
2017-07-19 16:49:52 +03:00
|
|
|
rv = GetPromotedPoint(kStart, startNode, static_cast<int32_t>(startOffset),
|
|
|
|
address_of(opStartNode), &opStartOffset, common);
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-07-19 16:49:52 +03:00
|
|
|
rv = GetPromotedPoint(kEnd, endNode, static_cast<int32_t>(endOffset),
|
|
|
|
address_of(opEndNode), &opEndOffset, common);
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2002-09-04 01:55:03 +04:00
|
|
|
// if both range endpoints are at the common ancestor, check for possible inclusion of ancestors
|
|
|
|
if ( (opStartNode == common) && (opEndNode == common) )
|
|
|
|
{
|
|
|
|
rv = PromoteAncestorChain(address_of(opStartNode), &opStartOffset, &opEndOffset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-09-20 06:27:19 +04:00
|
|
|
opEndNode = opStartNode;
|
2002-09-04 01:55:03 +04:00
|
|
|
}
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2002-09-04 01:55:03 +04:00
|
|
|
// set the range to the new values
|
2017-07-19 16:49:52 +03:00
|
|
|
rv = inRange->SetStart(opStartNode, static_cast<uint32_t>(opStartOffset));
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-07-19 16:49:52 +03:00
|
|
|
rv = inRange->SetEnd(opEndNode, static_cast<uint32_t>(opEndOffset));
|
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 14:57:30 +04:00
|
|
|
return rv;
|
2016-08-24 21:09:12 +03:00
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
|
2002-09-04 01:55:03 +04:00
|
|
|
|
|
|
|
// PromoteAncestorChain will promote a range represented by [{*ioNode,*ioStartOffset} , {*ioNode,*ioEndOffset}]
|
|
|
|
// The promotion is different from that found in getPromotedPoint: it will only promote one endpoint if it can
|
|
|
|
// promote the other. Thus, instead of having a startnode/endNode, there is just the one ioNode.
|
|
|
|
nsresult
|
2016-08-24 21:09:12 +03:00
|
|
|
nsHTMLCopyEncoder::PromoteAncestorChain(nsCOMPtr<nsIDOMNode> *ioNode,
|
|
|
|
int32_t *ioStartOffset,
|
|
|
|
int32_t *ioEndOffset)
|
2002-09-04 01:55:03 +04:00
|
|
|
{
|
|
|
|
if (!ioNode || !ioStartOffset || !ioEndOffset) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool done = false;
|
2002-09-04 01:55:03 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> frontNode, endNode, parent;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t frontOffset, endOffset;
|
2009-11-02 02:43:18 +03:00
|
|
|
|
|
|
|
//save the editable state of the ioNode, so we don't promote an ancestor if it has different editable state
|
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(*ioNode);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEditable = node->IsEditable();
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2002-09-04 01:55:03 +04:00
|
|
|
// loop for as long as we can promote both endpoints
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
rv = (*ioNode)->GetParentNode(getter_AddRefs(parent));
|
|
|
|
if ((NS_FAILED(rv)) || !parent)
|
2011-10-17 18:59:28 +04:00
|
|
|
done = true;
|
2002-09-04 01:55:03 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// passing parent as last param to GetPromotedPoint() allows it to promote only one level
|
2007-11-10 03:02:23 +03:00
|
|
|
// up the hierarchy.
|
2002-09-04 01:55:03 +04:00
|
|
|
rv = GetPromotedPoint( kStart, *ioNode, *ioStartOffset, address_of(frontNode), &frontOffset, parent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// then we make the same attempt with the endpoint
|
|
|
|
rv = GetPromotedPoint( kEnd, *ioNode, *ioEndOffset, address_of(endNode), &endOffset, parent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-11-02 02:43:18 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsINode> frontINode = do_QueryInterface(frontNode);
|
2016-08-24 21:09:12 +03:00
|
|
|
// if both endpoints were promoted one level and isEditable is the same as the original node,
|
2009-11-02 02:43:18 +03:00
|
|
|
// keep looping - otherwise we are done.
|
|
|
|
if ( (frontNode != parent) || (endNode != parent) || (frontINode->IsEditable() != isEditable) )
|
2011-10-17 18:59:28 +04:00
|
|
|
done = true;
|
2002-09-04 01:55:03 +04:00
|
|
|
else
|
|
|
|
{
|
2016-08-24 21:09:12 +03:00
|
|
|
*ioNode = frontNode;
|
2002-09-04 01:55:03 +04:00
|
|
|
*ioStartOffset = frontOffset;
|
|
|
|
*ioEndOffset = endOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-06-04 05:04:08 +04:00
|
|
|
nsresult
|
2016-08-24 21:09:12 +03:00
|
|
|
nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, int32_t aOffset,
|
2012-08-22 19:56:38 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> *outNode, int32_t *outOffset, nsIDOMNode *common)
|
1999-06-04 05:04:08 +04:00
|
|
|
{
|
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 14:57:30 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIDOMNode> node = aNode;
|
|
|
|
nsCOMPtr<nsIDOMNode> parent = aNode;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t offset = aOffset;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool bResetPromotion = false;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2002-09-04 01:55:03 +04:00
|
|
|
// default values
|
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 14:57:30 +04:00
|
|
|
*outNode = node;
|
|
|
|
*outOffset = offset;
|
1999-06-04 05:04:08 +04:00
|
|
|
|
2016-08-24 21:09:12 +03:00
|
|
|
if (common == node)
|
2002-09-04 01:55:03 +04:00
|
|
|
return NS_OK;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
if (aWhere == kStart)
|
|
|
|
{
|
|
|
|
// some special casing for text nodes
|
2010-04-30 15:15:09 +04:00
|
|
|
nsCOMPtr<nsINode> t = do_QueryInterface(aNode);
|
|
|
|
if (IsTextNode(t))
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
// if not at beginning of text node, we are done
|
2016-08-24 21:09:12 +03:00
|
|
|
if (offset > 0)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
// unless everything before us in just whitespace. NOTE: we need a more
|
|
|
|
// general solution that truly detects all cases of non-significant
|
|
|
|
// whitesace with no false alarms.
|
|
|
|
nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(aNode);
|
|
|
|
nsAutoString text;
|
|
|
|
nodeAsText->SubstringData(0, offset, text);
|
|
|
|
text.CompressWhitespace();
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!text.IsEmpty())
|
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 14:57:30 +04:00
|
|
|
return NS_OK;
|
2011-10-17 18:59:28 +04:00
|
|
|
bResetPromotion = 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 14:57:30 +04:00
|
|
|
}
|
|
|
|
// else
|
2000-12-09 07:46:08 +03:00
|
|
|
rv = GetNodeLocation(aNode, address_of(parent), &offset);
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
node = GetChildAt(parent,offset);
|
|
|
|
}
|
|
|
|
if (!node) node = parent;
|
1999-06-04 05:04:08 +04:00
|
|
|
|
2016-08-24 21:09:12 +03:00
|
|
|
// finding the real start for this point. look up the tree for as long as we are the
|
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 14:57:30 +04:00
|
|
|
// first node in the container, and as long as we haven't hit the body node.
|
2002-09-04 01:55:03 +04:00
|
|
|
if (!IsRoot(node) && (parent != common))
|
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 14:57:30 +04:00
|
|
|
{
|
2000-12-09 07:46:08 +03:00
|
|
|
rv = GetNodeLocation(node, address_of(parent), &offset);
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (offset == -1) return NS_OK; // we hit generated content; STOP
|
2002-09-04 01:55:03 +04:00
|
|
|
while ((IsFirstNode(node)) && (!IsRoot(parent)) && (parent != common))
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
if (bResetPromotion)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(parent);
|
2015-03-03 14:09:00 +03:00
|
|
|
if (content && content->IsHTMLElement())
|
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 14:57:30 +04:00
|
|
|
{
|
2017-09-05 13:19:06 +03:00
|
|
|
if (nsHTMLElement::IsBlock(nsHTMLTags::AtomTagToId(
|
|
|
|
content->NodeInfo()->NameAtom()))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
bResetPromotion = false;
|
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 14:57:30 +04:00
|
|
|
}
|
2016-08-24 21:09:12 +03:00
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
}
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
node = parent;
|
2000-12-09 07:46:08 +03:00
|
|
|
rv = GetNodeLocation(node, address_of(parent), &offset);
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (offset == -1) // we hit generated content; STOP
|
|
|
|
{
|
|
|
|
// back up a bit
|
|
|
|
parent = node;
|
|
|
|
offset = 0;
|
|
|
|
break;
|
|
|
|
}
|
2016-08-24 21:09:12 +03:00
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
if (bResetPromotion)
|
|
|
|
{
|
|
|
|
*outNode = aNode;
|
|
|
|
*outOffset = aOffset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*outNode = parent;
|
|
|
|
*outOffset = offset;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
if (aWhere == kEnd)
|
|
|
|
{
|
|
|
|
// some special casing for text nodes
|
2010-04-30 15:15:09 +04:00
|
|
|
nsCOMPtr<nsINode> n = do_QueryInterface(aNode);
|
|
|
|
if (IsTextNode(n))
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
// if not at end of text node, we are done
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = n->Length();
|
|
|
|
if (offset < (int32_t)len)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
// unless everything after us in just whitespace. NOTE: we need a more
|
|
|
|
// general solution that truly detects all cases of non-significant
|
2012-03-30 01:09:04 +04:00
|
|
|
// whitespace with no false alarms.
|
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 14:57:30 +04:00
|
|
|
nsCOMPtr<nsIDOMCharacterData> nodeAsText = do_QueryInterface(aNode);
|
|
|
|
nsAutoString text;
|
|
|
|
nodeAsText->SubstringData(offset, len-offset, text);
|
|
|
|
text.CompressWhitespace();
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!text.IsEmpty())
|
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 14:57:30 +04:00
|
|
|
return NS_OK;
|
2011-10-17 18:59:28 +04:00
|
|
|
bResetPromotion = 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 14:57:30 +04:00
|
|
|
}
|
2000-12-09 07:46:08 +03:00
|
|
|
rv = GetNodeLocation(aNode, address_of(parent), &offset);
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (offset) offset--; // we want node _before_ offset
|
|
|
|
node = GetChildAt(parent,offset);
|
|
|
|
}
|
|
|
|
if (!node) node = parent;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
|
|
|
// finding the real end for this point. look up the tree for as long as we are the
|
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 14:57:30 +04:00
|
|
|
// last node in the container, and as long as we haven't hit the body node.
|
2002-09-04 01:55:03 +04:00
|
|
|
if (!IsRoot(node) && (parent != common))
|
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 14:57:30 +04:00
|
|
|
{
|
2000-12-09 07:46:08 +03:00
|
|
|
rv = GetNodeLocation(node, address_of(parent), &offset);
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (offset == -1) return NS_OK; // we hit generated content; STOP
|
2002-09-04 01:55:03 +04:00
|
|
|
while ((IsLastNode(node)) && (!IsRoot(parent)) && (parent != common))
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
if (bResetPromotion)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(parent);
|
2015-03-03 14:09:00 +03:00
|
|
|
if (content && content->IsHTMLElement())
|
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 14:57:30 +04:00
|
|
|
{
|
2017-09-05 13:19:06 +03:00
|
|
|
if (nsHTMLElement::IsBlock(nsHTMLTags::AtomTagToId(
|
|
|
|
content->NodeInfo()->NameAtom()))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
bResetPromotion = false;
|
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 14:57:30 +04:00
|
|
|
}
|
2016-08-24 21:09:12 +03:00
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
}
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
node = parent;
|
2000-12-09 07:46:08 +03:00
|
|
|
rv = GetNodeLocation(node, address_of(parent), &offset);
|
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 14:57:30 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (offset == -1) // we hit generated content; STOP
|
|
|
|
{
|
|
|
|
// back up a bit
|
|
|
|
parent = node;
|
|
|
|
offset = 0;
|
|
|
|
break;
|
|
|
|
}
|
2016-08-24 21:09:12 +03:00
|
|
|
}
|
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 14:57:30 +04:00
|
|
|
if (bResetPromotion)
|
|
|
|
{
|
|
|
|
*outNode = aNode;
|
|
|
|
*outOffset = aOffset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*outNode = parent;
|
|
|
|
offset++; // add one since this in an endpoint - want to be AFTER node.
|
|
|
|
*outOffset = offset;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
return rv;
|
|
|
|
}
|
1999-06-04 05:04:08 +04:00
|
|
|
|
2016-08-24 21:09:12 +03:00
|
|
|
nsCOMPtr<nsIDOMNode>
|
2012-08-22 19:56:38 +04:00
|
|
|
nsHTMLCopyEncoder::GetChildAt(nsIDOMNode *aParent, int32_t aOffset)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> resultNode;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
|
|
|
if (!aParent)
|
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 14:57:30 +04:00
|
|
|
return resultNode;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aParent);
|
|
|
|
NS_PRECONDITION(content, "null content in nsHTMLCopyEncoder::GetChildAt");
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2018-01-03 15:59:54 +03:00
|
|
|
resultNode = do_QueryInterface(content->GetChildAt_Deprecated(aOffset));
|
2003-09-27 08:18:26 +04:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
return resultNode;
|
|
|
|
}
|
1999-06-04 05:04:08 +04:00
|
|
|
|
2016-08-24 21:09:12 +03:00
|
|
|
bool
|
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 14:57:30 +04:00
|
|
|
nsHTMLCopyEncoder::IsMozBR(nsIDOMNode* aNode)
|
|
|
|
{
|
2012-02-10 14:04:45 +04:00
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
nsCOMPtr<Element> element = do_QueryInterface(aNode);
|
|
|
|
return element &&
|
2015-03-03 14:08:59 +03:00
|
|
|
element->IsHTMLElement(nsGkAtoms::br) &&
|
2012-02-10 14:04:45 +04:00
|
|
|
element->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
NS_LITERAL_STRING("_moz"), eIgnoreCase);
|
1999-06-04 05:04:08 +04:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:09:12 +03:00
|
|
|
nsresult
|
2003-09-27 08:18:26 +04:00
|
|
|
nsHTMLCopyEncoder::GetNodeLocation(nsIDOMNode *inChild,
|
|
|
|
nsCOMPtr<nsIDOMNode> *outParent,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t *outOffset)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION((inChild && outParent && outOffset), "bad args");
|
|
|
|
nsresult result = NS_ERROR_NULL_POINTER;
|
|
|
|
if (inChild && outParent && outOffset)
|
|
|
|
{
|
|
|
|
result = inChild->GetParentNode(getter_AddRefs(*outParent));
|
|
|
|
if ((NS_SUCCEEDED(result)) && (*outParent))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(*outParent);
|
|
|
|
nsCOMPtr<nsIContent> cChild = do_QueryInterface(inChild);
|
2003-09-27 08:18:26 +04:00
|
|
|
if (!cChild || !content)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2018-01-23 16:30:18 +03:00
|
|
|
*outOffset = content->ComputeIndexOf(cChild);
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2000-10-12 02:50:14 +04:00
|
|
|
nsHTMLCopyEncoder::IsRoot(nsIDOMNode* aNode)
|
|
|
|
{
|
2010-04-30 15:15:09 +04:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
2015-03-03 14:09:00 +03:00
|
|
|
if (!content) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-04-30 15:15:09 +04:00
|
|
|
|
2015-03-03 14:09:00 +03:00
|
|
|
if (mIsTextWidget) {
|
|
|
|
return content->IsHTMLElement(nsGkAtoms::div);
|
2000-10-12 02:50:14 +04:00
|
|
|
}
|
2015-03-03 14:09:00 +03:00
|
|
|
|
|
|
|
return content->IsAnyOfHTMLElements(nsGkAtoms::body,
|
|
|
|
nsGkAtoms::td,
|
|
|
|
nsGkAtoms::th);
|
2000-10-12 02:50:14 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
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 14:57:30 +04:00
|
|
|
nsHTMLCopyEncoder::IsFirstNode(nsIDOMNode *aNode)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t offset, j=0;
|
2000-12-09 07:46:08 +03:00
|
|
|
nsresult rv = GetNodeLocation(aNode, address_of(parent), &offset);
|
2016-08-24 21:09:12 +03:00
|
|
|
if (NS_FAILED(rv))
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("failure in IsFirstNode");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
if (offset == 0) // easy case, we are first dom child
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2016-08-24 21:09:12 +03:00
|
|
|
if (!parent)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
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 14:57:30 +04:00
|
|
|
// need to check if any nodes before us are really visible.
|
|
|
|
// Mike wrote something for me along these lines in nsSelectionController,
|
|
|
|
// but I don't think it's ready for use yet - revisit.
|
2016-08-24 21:09:12 +03:00
|
|
|
// HACK: for now, simply consider all whitespace text nodes to be
|
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 14:57:30 +04:00
|
|
|
// invisible formatting nodes.
|
|
|
|
nsCOMPtr<nsIDOMNodeList> childList;
|
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
|
|
|
|
|
|
|
rv = parent->GetChildNodes(getter_AddRefs(childList));
|
2016-08-24 21:09:12 +03:00
|
|
|
if (NS_FAILED(rv) || !childList)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("failure in IsFirstNode");
|
2011-10-17 18:59:28 +04:00
|
|
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
while (j < offset)
|
|
|
|
{
|
|
|
|
childList->Item(j, getter_AddRefs(child));
|
2016-08-24 21:09:12 +03:00
|
|
|
if (!IsEmptyTextContent(child))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
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 14:57:30 +04:00
|
|
|
j++;
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
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 14:57:30 +04:00
|
|
|
nsHTMLCopyEncoder::IsLastNode(nsIDOMNode *aNode)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t offset,j;
|
2000-12-09 07:46:08 +03:00
|
|
|
nsresult rv = GetNodeLocation(aNode, address_of(parent), &offset);
|
2016-08-24 21:09:12 +03:00
|
|
|
if (NS_FAILED(rv))
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("failure in IsLastNode");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
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 14:57:30 +04:00
|
|
|
}
|
2012-03-30 01:09:04 +04:00
|
|
|
nsCOMPtr<nsINode> parentNode = do_QueryInterface(parent);
|
|
|
|
if (!parentNode) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2012-03-30 01:09:04 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t numChildren = parentNode->Length();
|
|
|
|
if (offset+1 == (int32_t)numChildren) // easy case, we are last dom child
|
2011-10-17 18:59:28 +04:00
|
|
|
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 14:57:30 +04:00
|
|
|
// need to check if any nodes after us are really visible.
|
|
|
|
// Mike wrote something for me along these lines in nsSelectionController,
|
|
|
|
// but I don't think it's ready for use yet - revisit.
|
2016-08-24 21:09:12 +03:00
|
|
|
// HACK: for now, simply consider all whitespace text nodes to be
|
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 14:57:30 +04:00
|
|
|
// invisible formatting nodes.
|
2012-08-22 19:56:38 +04:00
|
|
|
j = (int32_t)numChildren-1;
|
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 14:57:30 +04:00
|
|
|
nsCOMPtr<nsIDOMNodeList>childList;
|
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
|
|
|
rv = parent->GetChildNodes(getter_AddRefs(childList));
|
2016-08-24 21:09:12 +03:00
|
|
|
if (NS_FAILED(rv) || !childList)
|
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 14:57:30 +04:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("failure in IsLastNode");
|
2011-10-17 18:59:28 +04:00
|
|
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
while (j > offset)
|
|
|
|
{
|
|
|
|
childList->Item(j, getter_AddRefs(child));
|
|
|
|
j--;
|
2016-08-24 21:09:12 +03:00
|
|
|
if (IsMozBR(child)) // we ignore trailing moz BRs.
|
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 14:57:30 +04:00
|
|
|
continue;
|
2016-08-24 21:09:12 +03:00
|
|
|
if (!IsEmptyTextContent(child))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
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 14:57:30 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
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 14:57:30 +04:00
|
|
|
nsHTMLCopyEncoder::IsEmptyTextContent(nsIDOMNode* aNode)
|
|
|
|
{
|
2006-07-19 08:36:36 +04:00
|
|
|
nsCOMPtr<nsIContent> cont = do_QueryInterface(aNode);
|
|
|
|
return cont && cont->TextIsOnlyWhitespace();
|
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 14:57:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NS_NewHTMLCopyTextEncoder(nsIDocumentEncoder** aResult); // make mac compiler happy
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewHTMLCopyTextEncoder(nsIDocumentEncoder** aResult)
|
|
|
|
{
|
|
|
|
*aResult = new nsHTMLCopyEncoder;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-05-16 20:39:54 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2012-05-16 20:39:54 +04:00
|
|
|
nsHTMLCopyEncoder::GetImmediateContextCount(const nsTArray<nsINode*>& aAncestorArray)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i = aAncestorArray.Length(), j = 0;
|
2012-05-16 20:39:54 +04:00
|
|
|
while (j < i) {
|
|
|
|
nsINode *node = aAncestorArray.ElementAt(j);
|
|
|
|
if (!node) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(node));
|
2015-03-03 14:09:00 +03:00
|
|
|
if (!content ||
|
|
|
|
!content->IsAnyOfHTMLElements(nsGkAtoms::tr,
|
|
|
|
nsGkAtoms::thead,
|
|
|
|
nsGkAtoms::tbody,
|
|
|
|
nsGkAtoms::tfoot,
|
|
|
|
nsGkAtoms::table)) {
|
2012-05-16 20:39:54 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
return j;
|
|
|
|
}
|