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"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.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"
|
2012-01-10 18:19:54 +04:00
|
|
|
#include "nsRange.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 "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"
|
2018-03-19 22:15:39 +03:00
|
|
|
#include "mozilla/dom/Comment.h"
|
2018-03-13 23:24:01 +03:00
|
|
|
#include "mozilla/dom/DocumentType.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2018-03-19 22:15:39 +03:00
|
|
|
#include "mozilla/dom/ProcessingInstruction.h"
|
2013-12-02 14:26:11 +04:00
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2018-03-19 22:18:07 +03:00
|
|
|
#include "mozilla/dom/Text.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;
|
|
|
|
|
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, 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, 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, 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-05-16 20:39:54 +04:00
|
|
|
virtual int32_t 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) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aNode, "null node");
|
2010-05-25 03:24:15 +04:00
|
|
|
|
|
|
|
if (mFlags & SkipInvisibleContent) {
|
2013-12-02 14:26:11 +04:00
|
|
|
// Treat the visibility of the ShadowRoot as if it were
|
|
|
|
// the host content.
|
2018-04-26 03:14:08 +03:00
|
|
|
//
|
|
|
|
// FIXME(emilio): I suspect instead of this a bunch of the GetParent()
|
|
|
|
// calls here should be doing GetFlattenedTreeParent, then this condition
|
|
|
|
// should be unreachable...
|
|
|
|
if (ShadowRoot* shadowRoot = ShadowRoot::FromNode(aNode)) {
|
|
|
|
aNode = shadowRoot->GetHost();
|
2013-12-02 14:26:11 +04:00
|
|
|
}
|
|
|
|
|
2018-04-26 03:14:08 +03:00
|
|
|
if (aNode->IsContent()) {
|
|
|
|
nsIFrame* frame = aNode->AsContent()->GetPrimaryFrame();
|
2010-05-25 03:24:15 +04:00
|
|
|
if (!frame) {
|
2018-04-26 03:14:08 +03:00
|
|
|
if (aNode->IsElement() && aNode->AsElement()->IsDisplayContents()) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-13 01:41:00 +03:00
|
|
|
if (aNode->IsText()) {
|
2010-05-25 03:24:15 +04:00
|
|
|
// We have already checked that our parent is visible.
|
2018-04-26 03:14:08 +03:00
|
|
|
//
|
|
|
|
// FIXME(emilio): Text not assigned to a <slot> in Shadow DOM should
|
|
|
|
// probably return false...
|
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();
|
2018-04-13 01:41:00 +03:00
|
|
|
if (!isVisible && aNode->IsText()) 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;
|
|
|
|
};
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsCOMPtr<Document> mDocument;
|
2018-03-27 07:35:20 +03:00
|
|
|
RefPtr<Selection> 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)
|
2018-12-13 16:07:19 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(nsDocumentEncoder, Clear())
|
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, mDocument, mSelection, mRange,
|
2017-04-24 13:17:17 +03:00
|
|
|
mNode, mSerializer, mCommonParent)
|
2010-06-27 00:39:56 +04:00
|
|
|
|
2017-04-27 13:27:03 +03:00
|
|
|
nsDocumentEncoder::nsDocumentEncoder()
|
|
|
|
: mEncoding(nullptr), mIsCopying(false), mCachedBuffer(nullptr) {
|
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) {
|
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() {
|
2010-06-27 00:39:56 +04:00
|
|
|
if (mCachedBuffer) {
|
|
|
|
mCachedBuffer->Release();
|
|
|
|
}
|
1999-06-10 04:35:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-01-02 16:05:23 +03:00
|
|
|
nsDocumentEncoder::Init(Document* aDocument, const nsAString& aMimeType,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags) {
|
2018-05-11 20:46:15 +03:00
|
|
|
return NativeInit(aDocument, aMimeType, aFlags);
|
2010-06-27 00:39:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-01-02 16:05:23 +03:00
|
|
|
nsDocumentEncoder::NativeInit(Document* aDocument, const nsAString& aMimeType,
|
|
|
|
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) {
|
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
|
2018-05-08 20:52:36 +03:00
|
|
|
nsDocumentEncoder::SetSelection(Selection* aSelection) {
|
|
|
|
mSelection = aSelection;
|
1999-06-30 23:26:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-10 04:35:02 +04:00
|
|
|
NS_IMETHODIMP
|
2018-05-17 19:01:37 +03:00
|
|
|
nsDocumentEncoder::SetRange(nsRange* aRange) {
|
|
|
|
mRange = 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
|
2018-05-30 05:58:49 +03:00
|
|
|
nsDocumentEncoder::SetNode(nsINode* aNode) {
|
2011-11-10 16:02:22 +04:00
|
|
|
mNodeIsContainer = false;
|
|
|
|
mNode = aNode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-06 00:32:48 +04:00
|
|
|
NS_IMETHODIMP
|
2018-05-30 05:58:49 +03:00
|
|
|
nsDocumentEncoder::SetContainerNode(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) {
|
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;
|
|
|
|
}
|
|
|
|
|
2010-04-30 15:15:09 +04:00
|
|
|
bool nsDocumentEncoder::IncludeInContext(nsINode* aNode) { return false; }
|
2001-02-15 16:22:26 +03:00
|
|
|
|
2010-04-30 15:15:09 +04:00
|
|
|
nsresult 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) {
|
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;
|
2018-05-30 05:58:49 +03:00
|
|
|
mNodeFixup->FixupNode(aNode, &dummy,
|
|
|
|
getter_AddRefs(fixedNodeKungfuDeathGrip));
|
2010-04-30 15:15:09 +04:00
|
|
|
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
|
|
|
|
if (!node) 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;
|
|
|
|
}
|
2018-05-30 17:56:24 +03:00
|
|
|
Element* originalElement = Element::FromNodeOrNull(aOriginalNode);
|
|
|
|
mSerializer->AppendElementStart(node->AsElement(), originalElement, aStr);
|
2010-10-15 21:59:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-11-30 04:08:22 +03:00
|
|
|
|
2011-06-14 11:56:48 +04:00
|
|
|
switch (node->NodeType()) {
|
2018-01-30 07:10:53 +03:00
|
|
|
case nsINode::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;
|
|
|
|
}
|
2018-01-30 07:10:53 +03:00
|
|
|
case nsINode::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;
|
|
|
|
}
|
2018-01-30 07:10:53 +03:00
|
|
|
case nsINode::PROCESSING_INSTRUCTION_NODE: {
|
2018-03-19 22:15:39 +03:00
|
|
|
mSerializer->AppendProcessingInstruction(
|
|
|
|
static_cast<ProcessingInstruction*>(node), aStartOffset, aEndOffset,
|
2010-05-04 17:19:54 +04:00
|
|
|
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;
|
|
|
|
}
|
2018-01-30 07:10:53 +03:00
|
|
|
case nsINode::COMMENT_NODE: {
|
2018-03-19 22:15:39 +03:00
|
|
|
mSerializer->AppendComment(static_cast<Comment*>(node), aStartOffset,
|
2010-05-04 17:19:54 +04:00
|
|
|
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;
|
|
|
|
}
|
2018-01-30 07:10:53 +03:00
|
|
|
case nsINode::DOCUMENT_TYPE_NODE: {
|
2018-03-13 23:24:01 +03:00
|
|
|
mSerializer->AppendDoctype(static_cast<DocumentType*>(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;
|
|
|
|
}
|
|
|
|
|
2010-04-30 15:15:09 +04:00
|
|
|
nsresult nsDocumentEncoder::SerializeNodeEnd(nsINode* aNode, nsAString& aStr) {
|
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;
|
|
|
|
}
|
|
|
|
|
2010-04-30 15:15:09 +04:00
|
|
|
nsresult 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) {
|
|
|
|
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) {
|
2018-05-30 05:58:49 +03:00
|
|
|
mNodeFixup->FixupNode(aNode, &serializeClonedChildren,
|
|
|
|
getter_AddRefs(fixedNodeKungfuDeathGrip));
|
2010-04-30 15:15:09 +04:00
|
|
|
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) {
|
2018-02-28 14:53:29 +03:00
|
|
|
rv = SerializeNodeEnd(maybeFixedNode, 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.
|
2018-04-15 13:14:22 +03:00
|
|
|
if (current && current != aNode && current->IsDocumentFragment()) {
|
|
|
|
nsIContent* host = current->AsDocumentFragment()->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;
|
|
|
|
}
|
|
|
|
|
2002-03-24 02:54:46 +03:00
|
|
|
static nsresult 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, Encoder* aEncoder,
|
2017-04-27 13:27:03 +03:00
|
|
|
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
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult 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) { return aNode && aNode->IsText(); }
|
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-01-10 18:19:54 +04:00
|
|
|
nsresult nsDocumentEncoder::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) {
|
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) {
|
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
|
2000-10-12 02:50:14 +04:00
|
|
|
// end of 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)) {
|
|
|
|
if (startNode == content) {
|
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);
|
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 {
|
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()) {
|
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) {
|
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;
|
|
|
|
}
|
|
|
|
|
2010-04-30 15:15:09 +04:00
|
|
|
nsresult nsDocumentEncoder::SerializeRangeContextStart(
|
|
|
|
const nsTArray<nsINode*>& aAncestorArray, nsAString& aString) {
|
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;
|
|
|
|
}
|
|
|
|
|
2017-12-01 18:45:25 +03:00
|
|
|
nsresult nsDocumentEncoder::SerializeRangeContextEnd(nsAString& aString) {
|
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)) break;
|
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
|
|
|
}
|
|
|
|
|
2018-03-13 16:51:33 +03:00
|
|
|
mRangeContexts.RemoveLastElement();
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-10 18:19:54 +04:00
|
|
|
nsresult nsDocumentEncoder::SerializeRangeToString(nsRange* aRange,
|
2002-03-24 02:54:46 +03:00
|
|
|
nsAString& aOutputString) {
|
2010-04-30 15:15:09 +04:00
|
|
|
if (!aRange || aRange->Collapsed()) 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
|
|
|
|
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) 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);
|
2018-05-30 05:58:49 +03:00
|
|
|
nsContentUtils::GetAncestorsAndOffsets(startContainer, startOffset,
|
2002-06-26 00:03:06 +04:00
|
|
|
&mStartNodes, &mStartOffsets);
|
2018-05-30 05:58:49 +03:00
|
|
|
nsContentUtils::GetAncestorsAndOffsets(endContainer, endOffset, &mEndNodes,
|
2002-06-26 00:03:06 +04:00
|
|
|
&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) {
|
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(),
|
2019-01-02 16:05:23 +03:00
|
|
|
"nsIDocumentEncoder 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) {
|
2018-03-27 07:35:20 +03:00
|
|
|
uint32_t count = mSelection->RangeCount();
|
1999-08-26 01:42:20 +04:00
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
nsCOMPtr<nsINode> node, prevNode;
|
2015-02-03 01:34:17 +03:00
|
|
|
uint32_t firstRangeStartDepth = 0;
|
2018-03-27 07:35:20 +03:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
RefPtr<nsRange> range = mSelection->GetRangeAt(i);
|
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
|
2012-05-16 20:39:54 +04:00
|
|
|
// needed 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.
|
2018-03-27 07:35:21 +03:00
|
|
|
node = range->GetStartContainer();
|
2007-03-27 19:10:23 +04:00
|
|
|
NS_ENSURE_TRUE(node, NS_ERROR_FAILURE);
|
2007-05-26 00:47:30 +04:00
|
|
|
if (node != prevNode) {
|
|
|
|
if (prevNode) {
|
2018-03-27 07:35:21 +03:00
|
|
|
rv = SerializeNodeEnd(prevNode, 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
|
|
|
if (!prevNode) {
|
|
|
|
// Went from a non-<tr> to a <tr>
|
|
|
|
mCommonAncestors.Clear();
|
2018-03-27 07:35:21 +03:00
|
|
|
nsContentUtils::GetAncestors(node->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
|
|
|
}
|
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
rv = SerializeNodeStart(node, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
rv = SerializeRangeToString(range, 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) {
|
2018-03-27 07:35:21 +03:00
|
|
|
rv = SerializeNodeEnd(prevNode, 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;
|
|
|
|
}
|
|
|
|
|
2018-11-05 03:41:05 +03:00
|
|
|
bool do_getDocumentTypeSupportedForEncoding(const char* aContentType) {
|
|
|
|
if (!nsCRT::strcmp(aContentType, "text/xml") ||
|
|
|
|
!nsCRT::strcmp(aContentType, "application/xml") ||
|
|
|
|
!nsCRT::strcmp(aContentType, "application/xhtml+xml") ||
|
|
|
|
!nsCRT::strcmp(aContentType, "image/svg+xml") ||
|
|
|
|
!nsCRT::strcmp(aContentType, "text/html") ||
|
|
|
|
!nsCRT::strcmp(aContentType, "text/plain")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2000-11-30 04:08:22 +03:00
|
|
|
|
2018-11-05 03:41:05 +03:00
|
|
|
already_AddRefed<nsIDocumentEncoder> do_createDocumentEncoder(
|
|
|
|
const char* aContentType) {
|
|
|
|
if (do_getDocumentTypeSupportedForEncoding(aContentType)) {
|
|
|
|
return do_AddRef(new nsDocumentEncoder);
|
|
|
|
}
|
|
|
|
return nullptr;
|
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
|
|
|
class nsHTMLCopyEncoder : public nsDocumentEncoder {
|
|
|
|
public:
|
|
|
|
nsHTMLCopyEncoder();
|
|
|
|
virtual ~nsHTMLCopyEncoder();
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
NS_IMETHOD Init(Document* aDocument, const nsAString& aMimeType,
|
2018-05-11 20:46:15 +03:00
|
|
|
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
|
2018-09-01 00:19:44 +03:00
|
|
|
MOZ_CAN_RUN_SCRIPT_BOUNDARY
|
2018-05-08 20:52:36 +03:00
|
|
|
NS_IMETHOD SetSelection(Selection* 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:
|
|
|
|
enum Endpoint { kStart, kEnd };
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2018-03-27 07:35:20 +03:00
|
|
|
nsresult PromoteRange(nsRange* inRange);
|
2018-03-27 07:35:21 +03:00
|
|
|
nsresult PromoteAncestorChain(nsCOMPtr<nsINode>* ioNode,
|
|
|
|
int32_t* ioStartOffset, int32_t* ioEndOffset);
|
|
|
|
nsresult GetPromotedPoint(Endpoint aWhere, nsINode* aNode, int32_t aOffset,
|
|
|
|
nsCOMPtr<nsINode>* outNode, int32_t* outOffset,
|
|
|
|
nsINode* aCommon);
|
|
|
|
nsCOMPtr<nsINode> GetChildAt(nsINode* aParent, int32_t aOffset);
|
2018-01-30 07:10:51 +03:00
|
|
|
bool IsMozBR(Element* aNode);
|
2018-03-27 07:35:21 +03:00
|
|
|
nsresult GetNodeLocation(nsINode* inChild, nsCOMPtr<nsINode>* outParent,
|
|
|
|
int32_t* outOffset);
|
|
|
|
bool IsRoot(nsINode* aNode);
|
|
|
|
bool IsFirstNode(nsINode* aNode);
|
|
|
|
bool IsLastNode(nsINode* aNode);
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual bool IncludeInContext(nsINode* aNode) override;
|
|
|
|
virtual int32_t 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() { 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
|
2019-01-02 16:05:23 +03:00
|
|
|
nsHTMLCopyEncoder::Init(Document* aDocument, 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;
|
2018-05-11 20:46:15 +03:00
|
|
|
mDocument = aDocument;
|
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()) mFlags |= OutputNoScriptContent;
|
2001-10-02 14:02:07 +04:00
|
|
|
|
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
|
2018-05-08 20:52:36 +03:00
|
|
|
nsHTMLCopyEncoder::SetSelection(Selection* 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
|
|
|
|
2001-02-15 16:22:26 +03:00
|
|
|
if (!aSelection) return NS_ERROR_NULL_POINTER;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2018-05-08 20:52:36 +03:00
|
|
|
uint32_t rangeCount = aSelection->RangeCount();
|
2001-02-15 16:22:26 +03:00
|
|
|
|
|
|
|
// if selection is uninitialized return
|
2018-03-27 07:35:20 +03:00
|
|
|
if (!rangeCount) {
|
2001-02-15 16:22:26 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2018-03-27 07:35:20 +03:00
|
|
|
}
|
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.
|
2018-04-26 03:14:08 +03:00
|
|
|
//
|
|
|
|
// FIXME(emilio, bug 1455894): This assumption is already wrong, and will
|
|
|
|
// probably be more wrong in a Shadow DOM world...
|
|
|
|
//
|
|
|
|
// We should be able to write this as "Find the common ancestor of the
|
|
|
|
// selection, then go through the flattened tree and serialize the selected
|
|
|
|
// nodes", effectively serializing the composed tree.
|
2018-05-08 20:52:36 +03:00
|
|
|
RefPtr<nsRange> range = aSelection->GetRangeAt(0);
|
2018-03-27 07:35:21 +03:00
|
|
|
nsINode* commonParent = range->GetCommonAncestor();
|
2001-02-15 16:22:26 +03:00
|
|
|
|
2003-07-29 01:09:56 +04:00
|
|
|
for (nsCOMPtr<nsIContent> selContent(do_QueryInterface(commonParent));
|
|
|
|
selContent; selContent = selContent->GetParent()) {
|
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)) {
|
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) {
|
2018-05-08 20:52:36 +03: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;
|
2018-05-08 20:52:36 +03:00
|
|
|
mSelection = aSelection;
|
2013-04-03 22:39:06 +04:00
|
|
|
// 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);
|
2018-03-27 07:35:20 +03:00
|
|
|
mSelection = new Selection();
|
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) {
|
2018-05-08 20:52:36 +03:00
|
|
|
range = aSelection->GetRangeAt(rangeIdx);
|
2000-10-12 02:50:14 +04:00
|
|
|
NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);
|
2018-03-27 07:35:20 +03:00
|
|
|
RefPtr<nsRange> myRange = range->CloneRange();
|
|
|
|
MOZ_ASSERT(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
|
|
|
|
|
|
|
// adjust range to include any ancestors who's children are entirely
|
|
|
|
// selected
|
2018-03-27 07:35:20 +03:00
|
|
|
nsresult 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;
|
2018-03-27 07:35:20 +03:00
|
|
|
mSelection->AddRangeInternal(*myRange, mDocument, result);
|
2017-02-25 13:33:34 +03:00
|
|
|
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) {
|
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
|
2016-08-24 21:09:12 +03:00
|
|
|
// multirange selections. encoding ancestors every range in a multirange
|
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
|
|
|
// selection in a way that could be 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;
|
2009-03-20 11:15:35 +03:00
|
|
|
if (count > 0) 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) {
|
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) {
|
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
|
2002-03-22 02:31:26 +03:00
|
|
|
// depth is distance down in the parent hierarchy. Later we will need to add
|
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
|
|
|
// leading/trailing 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
|
|
|
}
|
|
|
|
|
2010-04-30 15:15:09 +04:00
|
|
|
bool 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));
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
if (!content) 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
|
|
|
}
|
|
|
|
|
2018-03-27 07:35:20 +03:00
|
|
|
nsresult nsHTMLCopyEncoder::PromoteRange(nsRange* inRange) {
|
2018-03-27 07:35:21 +03:00
|
|
|
if (!inRange->IsPositioned()) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsINode> startNode = inRange->GetStartContainer();
|
|
|
|
uint32_t startOffset = inRange->StartOffset();
|
|
|
|
nsCOMPtr<nsINode> endNode = inRange->GetEndContainer();
|
|
|
|
uint32_t endOffset = inRange->EndOffset();
|
|
|
|
nsCOMPtr<nsINode> common = inRange->GetCommonAncestor();
|
2016-08-24 21:09:12 +03:00
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
nsCOMPtr<nsINode> opStartNode;
|
|
|
|
nsCOMPtr<nsINode> opEndNode;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t opStartOffset, opEndOffset;
|
2016-08-24 21:09:12 +03:00
|
|
|
|
|
|
|
// examine range endpoints.
|
2018-03-27 07:35:21 +03:00
|
|
|
nsresult rv =
|
2018-03-27 07:35:21 +03:00
|
|
|
GetPromotedPoint(kStart, startNode, static_cast<int32_t>(startOffset),
|
2018-03-27 07:35:21 +03:00
|
|
|
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);
|
2018-03-27 07:35:21 +03:00
|
|
|
rv = GetPromotedPoint(kEnd, endNode, static_cast<int32_t>(endOffset),
|
2018-03-27 07:35:21 +03:00
|
|
|
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
|
2018-03-27 07:35:21 +03:00
|
|
|
if (opStartNode == common && opEndNode == common) {
|
2002-09-04 01:55:03 +04:00
|
|
|
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
|
2018-03-27 07:35:21 +03:00
|
|
|
ErrorResult err;
|
|
|
|
inRange->SetStart(*opStartNode, static_cast<uint32_t>(opStartOffset), err);
|
|
|
|
if (NS_WARN_IF(err.Failed())) {
|
|
|
|
return err.StealNSResult();
|
|
|
|
}
|
|
|
|
inRange->SetEnd(*opEndNode, static_cast<uint32_t>(opEndOffset), err);
|
|
|
|
if (NS_WARN_IF(err.Failed())) {
|
|
|
|
return err.StealNSResult();
|
|
|
|
}
|
|
|
|
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
|
|
|
|
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.
|
2018-03-27 07:35:21 +03:00
|
|
|
nsresult nsHTMLCopyEncoder::PromoteAncestorChain(nsCOMPtr<nsINode>* 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
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
nsCOMPtr<nsINode> 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
|
2018-03-27 07:35:21 +03:00
|
|
|
nsCOMPtr<nsINode> node = *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) {
|
2018-03-27 07:35:21 +03:00
|
|
|
node = *ioNode;
|
|
|
|
parent = node->GetParentNode();
|
2018-01-30 07:10:52 +03:00
|
|
|
if (!parent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
done = true;
|
2018-01-30 07:10:52 +03:00
|
|
|
} else {
|
2002-09-04 01:55:03 +04:00
|
|
|
// passing parent as last param to GetPromotedPoint() allows it to promote
|
2007-11-10 03:02:23 +03:00
|
|
|
// only one level 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
|
|
|
|
2016-08-24 21:09:12 +03:00
|
|
|
// if both endpoints were promoted one level and isEditable is the same as
|
2009-11-02 02:43:18 +03:00
|
|
|
// the original node, keep looping - otherwise we are done.
|
2018-03-27 07:35:21 +03:00
|
|
|
if ((frontNode != parent) || (endNode != parent) ||
|
|
|
|
(frontNode->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;
|
|
|
|
}
|
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
nsresult nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsINode* aNode,
|
|
|
|
int32_t aOffset,
|
|
|
|
nsCOMPtr<nsINode>* outNode,
|
|
|
|
int32_t* outOffset,
|
|
|
|
nsINode* 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
|
|
|
nsresult rv = NS_OK;
|
2018-03-27 07:35:21 +03:00
|
|
|
nsCOMPtr<nsINode> node = aNode;
|
|
|
|
nsCOMPtr<nsINode> 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) 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
|
|
|
if (aWhere == kStart) {
|
|
|
|
// some special casing for text nodes
|
2018-08-13 12:05:19 +03:00
|
|
|
if (auto nodeAsText = aNode->GetAsText()) {
|
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.
|
|
|
|
nsAutoString text;
|
2018-03-19 22:18:07 +03:00
|
|
|
nodeAsText->SubstringData(0, offset, text, IgnoreErrors());
|
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
|
|
|
text.CompressWhitespace();
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!text.IsEmpty()) 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
|
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
|
|
|
// we are the 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)) {
|
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()) {
|
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
|
2018-08-13 12:05:19 +03:00
|
|
|
if (auto nodeAsText = aNode->GetAsText()) {
|
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
|
2018-08-13 12:05:19 +03:00
|
|
|
uint32_t len = aNode->Length();
|
2012-08-22 19:56:38 +04:00
|
|
|
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
|
|
|
nsAutoString text;
|
2018-03-19 22:18:07 +03:00
|
|
|
nodeAsText->SubstringData(offset, len - offset, text, IgnoreErrors());
|
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
|
|
|
text.CompressWhitespace();
|
2002-01-24 05:03:19 +03:00
|
|
|
if (!text.IsEmpty()) 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
|
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
|
|
|
// are the 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)) {
|
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()) {
|
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
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
nsCOMPtr<nsINode> nsHTMLCopyEncoder::GetChildAt(nsINode* aParent,
|
|
|
|
int32_t aOffset) {
|
|
|
|
nsCOMPtr<nsINode> 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
|
|
|
if (!aParent) 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);
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(content, "null content in nsHTMLCopyEncoder::GetChildAt");
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
resultNode = 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
|
|
|
|
2018-01-30 07:10:51 +03:00
|
|
|
bool nsHTMLCopyEncoder::IsMozBR(Element* aElement) {
|
|
|
|
return aElement->IsHTMLElement(nsGkAtoms::br) &&
|
|
|
|
aElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
NS_LITERAL_STRING("_moz"), eIgnoreCase);
|
1999-06-04 05:04:08 +04:00
|
|
|
}
|
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
nsresult nsHTMLCopyEncoder::GetNodeLocation(nsINode* inChild,
|
|
|
|
nsCOMPtr<nsINode>* 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");
|
|
|
|
if (inChild && outParent && outOffset) {
|
2018-01-30 07:10:52 +03:00
|
|
|
nsCOMPtr<nsIContent> child = do_QueryInterface(inChild);
|
|
|
|
if (!child) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2003-09-27 08:18:26 +04:00
|
|
|
|
2018-01-30 07:10:52 +03:00
|
|
|
nsIContent* parent = child->GetParent();
|
|
|
|
if (!parent) {
|
|
|
|
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
|
|
|
}
|
2018-01-30 07:10:52 +03:00
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
*outParent = parent;
|
2018-01-30 07:10:52 +03:00
|
|
|
*outOffset = parent->ComputeIndexOf(child);
|
|
|
|
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
|
|
|
}
|
2018-01-30 07:10:52 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
bool nsHTMLCopyEncoder::IsRoot(nsINode* 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
|
|
|
}
|
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
bool nsHTMLCopyEncoder::IsFirstNode(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
|
|
|
// 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.
|
2018-03-27 07:35:21 +03:00
|
|
|
for (nsIContent* sibling = aNode->GetPreviousSibling(); sibling;
|
2018-01-30 07:10:51 +03:00
|
|
|
sibling = sibling->GetPreviousSibling()) {
|
|
|
|
if (!sibling->TextIsOnlyWhitespace()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2018-01-30 07:10:51 +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
|
|
|
}
|
2018-01-30 07:10:51 +03: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
|
|
|
}
|
|
|
|
|
2018-03-27 07:35:21 +03:00
|
|
|
bool nsHTMLCopyEncoder::IsLastNode(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
|
|
|
// 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.
|
2018-03-27 07:35:21 +03:00
|
|
|
for (nsIContent* sibling = aNode->GetNextSibling(); sibling;
|
2018-01-30 07:10:51 +03:00
|
|
|
sibling = sibling->GetNextSibling()) {
|
|
|
|
if (sibling->IsElement() && IsMozBR(sibling->AsElement())) {
|
|
|
|
// 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;
|
2018-01-30 07:10:51 +03:00
|
|
|
}
|
|
|
|
if (!sibling->TextIsOnlyWhitespace()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2018-01-30 07:10:51 +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
|
|
|
}
|
2018-01-30 07:10:51 +03: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
|
|
|
}
|
|
|
|
|
2018-11-05 00:44:47 +03:00
|
|
|
already_AddRefed<nsIDocumentEncoder> do_createHTMLCopyEncoder() {
|
|
|
|
return do_AddRef(new nsHTMLCopyEncoder);
|
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
|
|
|
|
|
|
|
int32_t 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;
|
|
|
|
}
|