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/. */
|
2006-03-30 12:03:04 +04:00
|
|
|
|
|
|
|
/*
|
2018-03-19 22:15:39 +03:00
|
|
|
* Base class for DOM Core's Comment, DocumentType, Text,
|
2018-03-19 22:15:40 +03:00
|
|
|
* CDATASection and ProcessingInstruction nodes.
|
2006-03-30 12:03:04 +04:00
|
|
|
*/
|
|
|
|
|
2018-03-19 22:18:07 +03:00
|
|
|
#include "mozilla/dom/CharacterData.h"
|
|
|
|
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2014-03-17 10:56:54 +04:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
#include "mozilla/dom/BindContext.h"
|
2012-11-15 02:10:08 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2017-10-19 09:31:36 +03:00
|
|
|
#include "mozilla/dom/HTMLSlotElement.h"
|
2019-11-06 12:08:06 +03:00
|
|
|
#include "mozilla/dom/MutationObservers.h"
|
2013-12-02 14:26:11 +04:00
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2000-08-23 21:27:06 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2014-02-27 14:51:15 +04:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
1999-01-22 00:45:17 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2004-04-01 23:44:17 +04:00
|
|
|
#include "nsDOMString.h"
|
2005-11-02 03:41:51 +03:00
|
|
|
#include "nsChangeHint.h"
|
2006-03-22 21:36:36 +03:00
|
|
|
#include "nsCOMArray.h"
|
2012-11-21 14:13:57 +04:00
|
|
|
#include "mozilla/dom/DirectionalityUtils.h"
|
2008-03-28 17:09:00 +03:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2016-04-25 10:15:55 +03:00
|
|
|
#include "nsTextNode.h"
|
2017-08-31 14:54:46 +03:00
|
|
|
#include "nsBidiUtils.h"
|
2015-09-16 06:49:53 +03:00
|
|
|
#include "PLDHashTable.h"
|
2016-08-15 09:43:21 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2018-03-28 02:44:49 +03:00
|
|
|
#include "nsWindowSizes.h"
|
2011-05-26 23:58:35 +04:00
|
|
|
#include "nsWrapperCacheInlines.h"
|
2001-12-16 09:59:31 +03:00
|
|
|
|
2019-08-03 01:13:28 +03:00
|
|
|
#if defined(ACCESSIBILITY) && defined(DEBUG)
|
|
|
|
# include "nsAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-03-11 05:48:57 +03:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::CharacterData(already_AddRefed<dom::NodeInfo>&& aNodeInfo)
|
2018-09-21 23:45:49 +03:00
|
|
|
: nsIContent(std::move(aNodeInfo)) {
|
2018-01-30 07:10:53 +03:00
|
|
|
MOZ_ASSERT(mNodeInfo->NodeType() == TEXT_NODE ||
|
|
|
|
mNodeInfo->NodeType() == CDATA_SECTION_NODE ||
|
|
|
|
mNodeInfo->NodeType() == COMMENT_NODE ||
|
|
|
|
mNodeInfo->NodeType() == PROCESSING_INSTRUCTION_NODE ||
|
|
|
|
mNodeInfo->NodeType() == DOCUMENT_TYPE_NODE,
|
2015-02-10 01:34:50 +03:00
|
|
|
"Bad NodeType in aNodeInfo");
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
CharacterData::~CharacterData() {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(!IsInUncomposedDoc(),
|
|
|
|
"Please remove this from the document properly");
|
2011-07-26 15:11:14 +04:00
|
|
|
if (GetParent()) {
|
|
|
|
NS_RELEASE(mParent);
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(CharacterData)
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(CharacterData)
|
2009-05-13 00:20:42 +04:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(CharacterData)
|
2012-11-15 02:10:08 +04:00
|
|
|
return Element::CanSkip(tmp, aRemovingAllowed);
|
2012-01-31 00:08:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(CharacterData)
|
2012-11-15 02:10:08 +04:00
|
|
|
return Element::CanSkipInCC(tmp);
|
2012-01-31 00:08:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(CharacterData)
|
2012-11-15 02:10:08 +04:00
|
|
|
return Element::CanSkipThis(tmp);
|
2012-01-31 00:08:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
|
2018-03-29 01:07:40 +03:00
|
|
|
// We purposefully don't TRAVERSE_BEGIN_INHERITED here. All the bits
|
|
|
|
// we should traverse should be added here or in nsINode::Traverse.
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(CharacterData)
|
2014-07-18 21:41:34 +04:00
|
|
|
if (MOZ_UNLIKELY(cb.WantDebugInfo())) {
|
|
|
|
char name[40];
|
2018-03-19 22:18:06 +03:00
|
|
|
SprintfLiteral(name, "CharacterData (len=%d)", tmp->mText.GetLength());
|
2014-07-18 21:41:34 +04:00
|
|
|
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name);
|
|
|
|
} else {
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(CharacterData, tmp->mRefCnt.get())
|
2014-07-18 21:41:34 +04:00
|
|
|
}
|
|
|
|
|
2017-12-23 11:23:42 +03:00
|
|
|
if (!nsIContent::Traverse(tmp, cb)) {
|
2009-03-03 15:14:13 +03:00
|
|
|
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
|
2008-03-28 17:09:00 +03:00
|
|
|
}
|
2007-01-05 01:31:26 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2018-03-29 01:07:40 +03:00
|
|
|
// We purposefully don't UNLINK_BEGIN_INHERITED here.
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CharacterData)
|
2017-12-23 11:23:42 +03:00
|
|
|
nsIContent::Unlink(tmp);
|
2013-07-17 20:05:06 +04:00
|
|
|
|
2019-05-27 15:08:14 +03:00
|
|
|
if (nsContentSlots* slots = tmp->GetExistingContentSlots()) {
|
2013-07-17 20:05:06 +04:00
|
|
|
slots->Unlink();
|
|
|
|
}
|
2007-01-05 01:31:26 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2001-12-16 09:59:31 +03:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN(CharacterData)
|
|
|
|
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(CharacterData)
|
2018-03-29 01:07:40 +03:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsIContent)
|
2001-12-16 09:59:31 +03:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
void CharacterData::GetNodeValueInternal(nsAString& aNodeValue) {
|
2018-03-19 22:18:07 +03:00
|
|
|
GetData(aNodeValue);
|
2000-04-01 17:31:23 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
void CharacterData::SetNodeValueInternal(const nsAString& aNodeValue,
|
2012-10-09 16:31:24 +04:00
|
|
|
ErrorResult& aError) {
|
|
|
|
aError = SetTextInternal(0, mText.GetLength(), aNodeValue.BeginReading(),
|
|
|
|
aNodeValue.Length(), true);
|
2000-04-01 17:31:23 +04:00
|
|
|
}
|
|
|
|
|
1998-09-06 04:16:36 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2018-03-19 22:47:42 +03:00
|
|
|
// Implementation of CharacterData
|
1998-09-06 04:16:36 +04:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
void CharacterData::GetData(nsAString& aData) const {
|
1998-10-20 04:20:04 +04:00
|
|
|
if (mText.Is2b()) {
|
2017-08-31 14:48:07 +03:00
|
|
|
aData.Truncate();
|
|
|
|
mText.AppendTo(aData);
|
2001-12-16 09:59:31 +03:00
|
|
|
} else {
|
|
|
|
// Must use Substring() since nsDependentCString() requires null
|
|
|
|
// terminated strings.
|
|
|
|
|
|
|
|
const char* data = mText.Get1b();
|
2002-05-10 22:21:50 +04:00
|
|
|
|
|
|
|
if (data) {
|
2006-02-03 17:18:39 +03:00
|
|
|
CopyASCIItoUTF16(Substring(data, data + mText.GetLength()), aData);
|
2002-05-10 22:21:50 +04:00
|
|
|
} else {
|
|
|
|
aData.Truncate();
|
|
|
|
}
|
1998-10-20 04:20:04 +04:00
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:07 +03:00
|
|
|
void CharacterData::SetData(const nsAString& aData, ErrorResult& aRv) {
|
|
|
|
nsresult rv = SetTextInternal(0, mText.GetLength(), aData.BeginReading(),
|
|
|
|
aData.Length(), true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
void CharacterData::SubstringData(uint32_t aStart, uint32_t aCount,
|
|
|
|
nsAString& aReturn, ErrorResult& rv) {
|
1998-09-06 04:16:36 +04:00
|
|
|
aReturn.Truncate();
|
1998-10-20 04:20:04 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t textLength = mText.GetLength();
|
1999-10-16 02:18:23 +04:00
|
|
|
if (aStart > textLength) {
|
2013-01-04 21:02:14 +04:00
|
|
|
rv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
1998-10-20 04:20:04 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t amount = aCount;
|
2001-11-16 06:01:29 +03:00
|
|
|
if (amount > textLength - aStart) {
|
1998-10-20 04:20:04 +04:00
|
|
|
amount = textLength - aStart;
|
|
|
|
}
|
2001-11-16 06:01:29 +03:00
|
|
|
|
1998-10-20 04:20:04 +04:00
|
|
|
if (mText.Is2b()) {
|
2000-03-12 12:14:14 +03:00
|
|
|
aReturn.Assign(mText.Get2b() + aStart, amount);
|
2001-12-16 09:59:31 +03:00
|
|
|
} else {
|
|
|
|
// Must use Substring() since nsDependentCString() requires null
|
|
|
|
// terminated strings.
|
|
|
|
|
|
|
|
const char* data = mText.Get1b() + aStart;
|
2006-02-03 17:18:39 +03:00
|
|
|
CopyASCIItoUTF16(Substring(data, data + amount), aReturn);
|
1998-10-20 04:20:04 +04:00
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
1999-10-22 00:40:51 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2018-03-19 22:33:25 +03:00
|
|
|
void CharacterData::AppendData(const nsAString& aData, ErrorResult& aRv) {
|
2018-03-19 23:10:06 +03:00
|
|
|
InsertData(mText.GetLength(), aData, aRv);
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
void CharacterData::InsertData(uint32_t aOffset, const nsAString& aData,
|
2018-03-19 22:38:04 +03:00
|
|
|
ErrorResult& aRv) {
|
|
|
|
nsresult rv =
|
|
|
|
SetTextInternal(aOffset, 0, aData.BeginReading(), aData.Length(), true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:45:31 +03:00
|
|
|
void CharacterData::DeleteData(uint32_t aOffset, uint32_t aCount,
|
|
|
|
ErrorResult& aRv) {
|
|
|
|
nsresult rv = SetTextInternal(aOffset, aCount, nullptr, 0, true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
void CharacterData::ReplaceData(uint32_t aOffset, uint32_t aCount,
|
2018-03-19 22:45:34 +03:00
|
|
|
const nsAString& aData, ErrorResult& aRv) {
|
|
|
|
nsresult rv = SetTextInternal(aOffset, aCount, aData.BeginReading(),
|
|
|
|
aData.Length(), true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
2018-09-07 17:47:51 +03:00
|
|
|
}
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
nsresult CharacterData::SetTextInternal(
|
|
|
|
uint32_t aOffset, uint32_t aCount, const char16_t* aBuffer,
|
|
|
|
uint32_t aLength, bool aNotify,
|
|
|
|
CharacterDataChangeInfo::Details* aDetails) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(aBuffer || !aLength, "Null buffer passed to SetTextInternal!");
|
2006-10-28 05:22:53 +04:00
|
|
|
|
1998-09-06 04:16:36 +04:00
|
|
|
// sanitize arguments
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t textLength = mText.GetLength();
|
2001-03-27 19:40:15 +04:00
|
|
|
if (aOffset > textLength) {
|
1999-11-11 04:48:25 +03:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2010-04-10 02:55:11 +04:00
|
|
|
if (aCount > textLength - aOffset) {
|
|
|
|
aCount = textLength - aOffset;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t endOffset = aOffset + aCount;
|
2010-04-10 02:55:11 +04:00
|
|
|
|
|
|
|
// Make sure the text fragment can hold the new data.
|
|
|
|
if (aLength > aCount && !mText.CanGrowBy(aLength - aCount)) {
|
2012-04-12 01:55:21 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2010-04-10 02:55:11 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* document = GetComposedDoc();
|
2018-05-15 16:56:38 +03:00
|
|
|
mozAutoDocUpdate updateBatch(document, aNotify);
|
2005-07-20 00:52:12 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveMutationListeners =
|
2006-10-28 05:22:53 +04:00
|
|
|
aNotify && nsContentUtils::HasMutationListeners(
|
2007-07-05 00:39:10 +04:00
|
|
|
this, NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED, this);
|
2006-10-28 05:22:53 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> oldValue;
|
2006-10-28 05:22:53 +04:00
|
|
|
if (haveMutationListeners) {
|
|
|
|
oldValue = GetCurrentValueAtom();
|
|
|
|
}
|
2016-07-08 10:07:06 +03:00
|
|
|
|
2007-09-05 12:22:17 +04:00
|
|
|
if (aNotify) {
|
|
|
|
CharacterDataChangeInfo info = {aOffset == textLength, aOffset, endOffset,
|
2011-08-16 04:55:20 +04:00
|
|
|
aLength, aDetails};
|
2019-11-06 00:32:53 +03:00
|
|
|
MutationObservers::NotifyCharacterDataWillChange(this, info);
|
2007-09-05 12:22:17 +04:00
|
|
|
}
|
|
|
|
|
2014-08-06 13:02:59 +04:00
|
|
|
Directionality oldDir = eDir_NotSet;
|
2018-01-30 07:10:53 +03:00
|
|
|
bool dirAffectsAncestor =
|
|
|
|
(NodeType() == TEXT_NODE &&
|
2019-05-22 08:18:48 +03:00
|
|
|
TextNodeWillChangeDirection(static_cast<nsTextNode*>(this), &oldDir,
|
|
|
|
aOffset));
|
2012-11-21 14:13:57 +04:00
|
|
|
|
2006-10-28 05:22:53 +04:00
|
|
|
if (aOffset == 0 && endOffset == textLength) {
|
2011-09-09 20:27:00 +04:00
|
|
|
// Replacing whole text or old text was empty. Don't bother to check for
|
|
|
|
// bidi in this string if the document already has bidi enabled.
|
2017-08-18 10:05:16 +03:00
|
|
|
// If this is marked as "maybe modified frequently", the text should be
|
|
|
|
// stored as char16_t since converting char* to char16_t* is expensive.
|
|
|
|
bool ok =
|
|
|
|
mText.SetTo(aBuffer, aLength, !document || !document->GetBidiEnabled(),
|
|
|
|
HasFlag(NS_MAYBE_MODIFIED_FREQUENTLY));
|
2013-12-19 18:09:00 +04:00
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
2006-10-28 05:22:53 +04:00
|
|
|
} else if (aOffset == textLength) {
|
|
|
|
// Appending to existing
|
2017-08-18 10:05:16 +03:00
|
|
|
bool ok =
|
|
|
|
mText.Append(aBuffer, aLength, !document || !document->GetBidiEnabled(),
|
|
|
|
HasFlag(NS_MAYBE_MODIFIED_FREQUENTLY));
|
2013-12-19 18:09:00 +04:00
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
2006-10-28 05:22:53 +04:00
|
|
|
} else {
|
|
|
|
// Merging old and new
|
|
|
|
|
2017-08-31 14:54:46 +03:00
|
|
|
bool bidi = mText.IsBidi();
|
|
|
|
|
2006-10-28 05:22:53 +04:00
|
|
|
// Allocate new buffer
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newLength = textLength - aCount + aLength;
|
2017-08-31 14:54:46 +03:00
|
|
|
// Use nsString and not nsAutoString so that we get a nsStringBuffer which
|
|
|
|
// can be just AddRefed in nsTextFragment.
|
|
|
|
nsString to;
|
|
|
|
to.SetCapacity(newLength);
|
2006-10-28 05:22:53 +04:00
|
|
|
|
|
|
|
// Copy over appropriate data
|
2010-04-10 02:55:11 +04:00
|
|
|
if (aOffset) {
|
2017-08-31 14:54:46 +03:00
|
|
|
mText.AppendTo(to, 0, aOffset);
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
2010-04-10 02:55:11 +04:00
|
|
|
if (aLength) {
|
2017-08-31 14:54:46 +03:00
|
|
|
to.Append(aBuffer, aLength);
|
|
|
|
if (!bidi && (!document || !document->GetBidiEnabled())) {
|
2018-01-18 15:28:15 +03:00
|
|
|
bidi = HasRTLChars(MakeSpan(aBuffer, aLength));
|
2017-08-31 14:54:46 +03:00
|
|
|
}
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
|
|
|
if (endOffset != textLength) {
|
2017-08-31 14:54:46 +03:00
|
|
|
mText.AppendTo(to, endOffset, textLength - endOffset);
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
|
|
|
|
2017-08-18 10:05:16 +03:00
|
|
|
// If this is marked as "maybe modified frequently", the text should be
|
|
|
|
// stored as char16_t since converting char* to char16_t* is expensive.
|
2017-08-31 14:54:46 +03:00
|
|
|
// Use char16_t also when we have bidi characters.
|
|
|
|
bool use2b = HasFlag(NS_MAYBE_MODIFIED_FREQUENTLY) || bidi;
|
|
|
|
bool ok = mText.SetTo(to, false, use2b);
|
|
|
|
mText.SetBidi(bidi);
|
2013-12-19 18:09:00 +04:00
|
|
|
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
UnsetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE);
|
|
|
|
|
2011-09-09 20:27:00 +04:00
|
|
|
if (document && mText.IsBidi()) {
|
|
|
|
// If we found bidi characters in mText.SetTo() above, indicate that the
|
|
|
|
// document contains bidi characters.
|
|
|
|
document->SetBidiEnabled();
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
|
2014-08-06 13:02:59 +04:00
|
|
|
if (dirAffectsAncestor) {
|
2016-03-19 00:21:50 +03:00
|
|
|
// dirAffectsAncestor being true implies that we have a text node, see
|
|
|
|
// above.
|
2018-01-30 07:10:53 +03:00
|
|
|
MOZ_ASSERT(NodeType() == TEXT_NODE);
|
2016-03-19 00:21:50 +03:00
|
|
|
TextNodeChangedDirection(static_cast<nsTextNode*>(this), oldDir, aNotify);
|
2014-08-06 13:02:59 +04:00
|
|
|
}
|
|
|
|
|
2006-10-28 05:22:53 +04:00
|
|
|
// Notify observers
|
|
|
|
if (aNotify) {
|
2007-09-11 03:46:22 +04:00
|
|
|
CharacterDataChangeInfo info = {aOffset == textLength, aOffset, endOffset,
|
2011-08-16 04:55:20 +04:00
|
|
|
aLength, aDetails};
|
2019-11-06 00:32:53 +03:00
|
|
|
MutationObservers::NotifyCharacterDataChanged(this, info);
|
2007-09-11 03:46:22 +04:00
|
|
|
|
2006-10-28 05:22:53 +04:00
|
|
|
if (haveMutationListeners) {
|
2015-09-07 17:55:50 +03:00
|
|
|
InternalMutationEvent mutation(true, eLegacyCharacterDataModified);
|
2008-04-18 21:20:11 +04:00
|
|
|
|
|
|
|
mutation.mPrevAttrValue = oldValue;
|
|
|
|
if (aLength > 0) {
|
|
|
|
nsAutoString val;
|
|
|
|
mText.AppendTo(val);
|
2016-03-29 02:09:43 +03:00
|
|
|
mutation.mNewAttrValue = NS_Atomize(val);
|
2008-04-15 03:59:21 +04:00
|
|
|
}
|
2008-04-18 21:20:11 +04:00
|
|
|
|
2011-10-18 14:53:36 +04:00
|
|
|
mozAutoSubtreeModified subtree(OwnerDoc(), this);
|
2014-03-17 10:56:54 +04:00
|
|
|
(new AsyncEventDispatcher(this, mutation))->RunDOMEventWhenSafe();
|
2006-10-28 05:22:53 +04:00
|
|
|
}
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
|
2004-05-08 00:55:17 +04:00
|
|
|
return NS_OK;
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Implementation of nsIContent
|
|
|
|
|
2001-12-16 09:59:31 +03:00
|
|
|
#ifdef DEBUG
|
2018-03-19 22:18:06 +03:00
|
|
|
void CharacterData::ToCString(nsAString& aBuf, int32_t aOffset,
|
|
|
|
int32_t aLen) const {
|
1998-10-20 04:20:04 +04:00
|
|
|
if (mText.Is2b()) {
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* cp = mText.Get2b() + aOffset;
|
|
|
|
const char16_t* end = cp + aLen;
|
2001-12-16 09:59:31 +03:00
|
|
|
|
1998-10-20 04:20:04 +04:00
|
|
|
while (cp < end) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = *cp++;
|
2006-05-07 16:15:36 +04:00
|
|
|
if (ch == '&') {
|
2006-05-07 05:39:21 +04:00
|
|
|
aBuf.AppendLiteral("&");
|
|
|
|
} else if (ch == '<') {
|
|
|
|
aBuf.AppendLiteral("<");
|
|
|
|
} else if (ch == '>') {
|
|
|
|
aBuf.AppendLiteral(">");
|
1998-10-20 04:20:04 +04:00
|
|
|
} else if ((ch < ' ') || (ch >= 127)) {
|
2018-03-24 22:00:38 +03:00
|
|
|
aBuf.AppendPrintf("\\u%04x", ch);
|
1998-10-20 04:20:04 +04:00
|
|
|
} else {
|
|
|
|
aBuf.Append(ch);
|
|
|
|
}
|
|
|
|
}
|
2001-12-16 09:59:31 +03:00
|
|
|
} else {
|
1998-10-20 04:20:04 +04:00
|
|
|
unsigned char* cp = (unsigned char*)mText.Get1b() + aOffset;
|
|
|
|
const unsigned char* end = cp + aLen;
|
2001-12-16 09:59:31 +03:00
|
|
|
|
1998-10-20 04:20:04 +04:00
|
|
|
while (cp < end) {
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t ch = *cp++;
|
2006-05-07 16:15:36 +04:00
|
|
|
if (ch == '&') {
|
2006-05-07 05:39:21 +04:00
|
|
|
aBuf.AppendLiteral("&");
|
|
|
|
} else if (ch == '<') {
|
|
|
|
aBuf.AppendLiteral("<");
|
|
|
|
} else if (ch == '>') {
|
|
|
|
aBuf.AppendLiteral(">");
|
1998-10-20 04:20:04 +04:00
|
|
|
} else if ((ch < ' ') || (ch >= 127)) {
|
2018-03-24 22:00:38 +03:00
|
|
|
aBuf.AppendPrintf("\\u%04x", ch);
|
1998-10-20 04:20:04 +04:00
|
|
|
} else {
|
|
|
|
aBuf.Append(ch);
|
|
|
|
}
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-12-16 09:59:31 +03:00
|
|
|
#endif
|
1998-09-06 04:16:36 +04:00
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
nsresult CharacterData::BindToTree(BindContext& aContext, nsINode& aParent) {
|
|
|
|
MOZ_ASSERT(aParent.IsContent() || aParent.IsDocument(),
|
|
|
|
"Must have content or document parent!");
|
|
|
|
MOZ_ASSERT(aParent.OwnerDoc() == OwnerDoc(),
|
2018-04-28 22:50:58 +03:00
|
|
|
"Must have the same owner document");
|
2019-05-31 17:33:33 +03:00
|
|
|
MOZ_ASSERT(OwnerDoc() == &aContext.OwnerDoc(), "These should match too");
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
MOZ_ASSERT(!IsInUncomposedDoc(), "Already have a document. Unbind first!");
|
2018-08-20 14:56:27 +03:00
|
|
|
MOZ_ASSERT(!IsInComposedDoc(), "Already have a document. Unbind first!");
|
2005-04-06 03:54:35 +04:00
|
|
|
// Note that as we recurse into the kids, they'll have a non-null parent. So
|
|
|
|
// only assert if our parent is _changing_ while we have a parent.
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
MOZ_ASSERT(!GetParentNode() || &aParent == GetParentNode(),
|
2018-04-28 22:50:58 +03:00
|
|
|
"Already have a parent. Unbind first!");
|
2005-09-24 22:43:15 +04:00
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
const bool hadParent = !!GetParentNode();
|
2015-09-24 18:23:32 +03:00
|
|
|
|
2019-05-29 07:27:32 +03:00
|
|
|
if (aParent.IsInNativeAnonymousSubtree()) {
|
|
|
|
SetFlags(NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE);
|
|
|
|
}
|
|
|
|
if (aParent.HasFlag(NODE_HAS_BEEN_IN_UA_WIDGET)) {
|
|
|
|
SetFlags(NODE_HAS_BEEN_IN_UA_WIDGET);
|
|
|
|
}
|
2019-11-18 11:49:27 +03:00
|
|
|
if (IsRootOfNativeAnonymousSubtree()) {
|
2019-05-29 07:27:32 +03:00
|
|
|
aParent.SetMayHaveAnonymousChildren();
|
|
|
|
}
|
|
|
|
|
2005-04-06 03:54:35 +04:00
|
|
|
// Set parent
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
mParent = &aParent;
|
|
|
|
if (!hadParent && aParent.IsContent()) {
|
|
|
|
SetParentIsContent(true);
|
|
|
|
NS_ADDREF(mParent);
|
2006-04-15 09:09:16 +04:00
|
|
|
}
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
MOZ_ASSERT(!!GetParent() == aParent.IsContent());
|
2005-04-06 03:54:35 +04:00
|
|
|
|
2019-05-29 07:27:32 +03:00
|
|
|
if (aParent.IsInUncomposedDoc() || aParent.IsInShadowTree()) {
|
2012-03-15 00:14:02 +04:00
|
|
|
// We no longer need to track the subtree pointer (and in fact we'll assert
|
|
|
|
// if we do this any later).
|
|
|
|
ClearSubtreeRootPointer();
|
2019-05-29 07:27:32 +03:00
|
|
|
SetIsConnected(aParent.IsInComposedDoc());
|
2012-03-15 00:14:02 +04:00
|
|
|
|
2019-05-29 07:27:32 +03:00
|
|
|
if (aParent.IsInUncomposedDoc()) {
|
|
|
|
SetIsInDocument();
|
|
|
|
} else {
|
|
|
|
SetFlags(NODE_IS_IN_SHADOW_TREE);
|
|
|
|
MOZ_ASSERT(aParent.IsContent() &&
|
|
|
|
aParent.AsContent()->GetContainingShadow());
|
|
|
|
ExtendedContentSlots()->mContainingShadow =
|
|
|
|
aParent.AsContent()->GetContainingShadow();
|
2005-09-24 22:43:15 +04:00
|
|
|
}
|
2019-06-05 15:03:29 +03:00
|
|
|
|
2019-06-11 13:00:46 +03:00
|
|
|
if (IsInComposedDoc()) {
|
|
|
|
if (mText.IsBidi()) {
|
|
|
|
aContext.OwnerDoc().SetBidiEnabled();
|
|
|
|
}
|
|
|
|
if (aContext.CollectingDisplayedNodeDataDuringLoad()) {
|
|
|
|
aContext.OwnerDoc().AddToVisibleContentHeuristic(mText.GetLength());
|
|
|
|
}
|
2019-06-05 15:03:29 +03:00
|
|
|
}
|
|
|
|
|
2010-01-18 12:26:40 +03:00
|
|
|
// Clear the lazy frame construction bits.
|
|
|
|
UnsetFlags(NODE_NEEDS_FRAME | NODE_DESCENDANTS_NEED_FRAMES);
|
2019-05-29 07:27:32 +03:00
|
|
|
} else {
|
2014-06-07 12:42:53 +04:00
|
|
|
// If we're not in the doc and not in a shadow tree,
|
|
|
|
// update our subtree pointer.
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
SetSubtreeRootPointer(aParent.SubtreeRoot());
|
2006-06-02 17:28:14 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 00:32:53 +03:00
|
|
|
MutationObservers::NotifyParentChainChanged(this);
|
2015-09-24 18:23:32 +03:00
|
|
|
if (!hadParent && IsRootOfNativeAnonymousSubtree()) {
|
2019-11-06 00:32:53 +03:00
|
|
|
MutationObservers::NotifyNativeAnonymousChildListChange(this, false);
|
2015-09-24 18:23:32 +03:00
|
|
|
}
|
2007-03-10 16:49:43 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
UpdateEditableState(false);
|
2007-06-28 06:48:16 +04:00
|
|
|
|
2019-08-28 01:10:46 +03:00
|
|
|
// Ensure we only do these once, in the case we move the shadow host around.
|
|
|
|
if (aContext.SubtreeRootChanges()) {
|
|
|
|
HandleShadowDOMRelatedInsertionSteps(hadParent);
|
|
|
|
}
|
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
MOZ_ASSERT(OwnerDoc() == aParent.OwnerDoc(), "Bound to wrong document");
|
2019-06-01 17:40:33 +03:00
|
|
|
MOZ_ASSERT(IsInComposedDoc() == aContext.InComposedDoc());
|
|
|
|
MOZ_ASSERT(IsInUncomposedDoc() == aContext.InUncomposedDoc());
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
MOZ_ASSERT(&aParent == GetParentNode(), "Bound to wrong parent node");
|
|
|
|
MOZ_ASSERT(aParent.IsInUncomposedDoc() == IsInUncomposedDoc());
|
|
|
|
MOZ_ASSERT(aParent.IsInComposedDoc() == IsInComposedDoc());
|
|
|
|
MOZ_ASSERT(aParent.IsInShadowTree() == IsInShadowTree());
|
|
|
|
MOZ_ASSERT(aParent.SubtreeRoot() == SubtreeRoot());
|
2005-04-06 03:54:35 +04:00
|
|
|
return NS_OK;
|
1998-09-06 04:16:36 +04:00
|
|
|
}
|
|
|
|
|
2019-05-29 01:47:08 +03:00
|
|
|
void CharacterData::UnbindFromTree(bool aNullParent) {
|
2009-06-29 02:48:24 +04:00
|
|
|
// Unset frame flags; if we need them again later, they'll get set again.
|
2018-08-20 14:56:27 +03:00
|
|
|
UnsetFlags(NS_CREATE_FRAME_IF_NON_WHITESPACE | NS_REFRAME_IF_WHITESPACE);
|
2014-10-02 22:45:44 +04:00
|
|
|
|
2019-08-28 01:10:46 +03:00
|
|
|
HandleShadowDOMRelatedRemovalSteps(aNullParent);
|
|
|
|
|
2011-04-08 06:29:49 +04:00
|
|
|
if (aNullParent) {
|
2019-05-29 22:20:37 +03:00
|
|
|
if (IsRootOfNativeAnonymousSubtree()) {
|
2019-11-06 00:32:53 +03:00
|
|
|
MutationObservers::NotifyNativeAnonymousChildListChange(this, true);
|
2015-09-24 18:23:32 +03:00
|
|
|
}
|
2011-07-26 15:11:14 +04:00
|
|
|
if (GetParent()) {
|
|
|
|
NS_RELEASE(mParent);
|
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
mParent = nullptr;
|
2011-07-26 15:11:14 +04:00
|
|
|
}
|
2011-04-08 06:29:49 +04:00
|
|
|
SetParentIsContent(false);
|
|
|
|
}
|
|
|
|
ClearInDocument();
|
2018-08-20 14:56:27 +03:00
|
|
|
SetIsConnected(false);
|
2006-05-17 20:14:33 +04:00
|
|
|
|
2014-09-27 02:07:40 +04:00
|
|
|
if (aNullParent || !mParent->IsInShadowTree()) {
|
|
|
|
UnsetFlags(NODE_IS_IN_SHADOW_TREE);
|
|
|
|
|
|
|
|
// Begin keeping track of our subtree root.
|
|
|
|
SetSubtreeRootPointer(aNullParent ? this : mParent->SubtreeRoot());
|
|
|
|
}
|
2012-03-15 00:14:02 +04:00
|
|
|
|
2019-11-15 21:19:37 +03:00
|
|
|
if (nsExtendedContentSlots* slots = GetExistingExtendedContentSlots()) {
|
2014-09-27 02:07:40 +04:00
|
|
|
if (aNullParent || !mParent->IsInShadowTree()) {
|
|
|
|
slots->mContainingShadow = nullptr;
|
|
|
|
}
|
2006-05-17 20:14:33 +04:00
|
|
|
}
|
2007-03-10 16:49:43 +03:00
|
|
|
|
2019-11-06 00:32:53 +03:00
|
|
|
MutationObservers::NotifyParentChainChanged(this);
|
2019-08-03 01:13:28 +03:00
|
|
|
|
|
|
|
#if defined(ACCESSIBILITY) && defined(DEBUG)
|
|
|
|
MOZ_ASSERT(!GetAccService() || !GetAccService()->HasAccessible(this),
|
|
|
|
"An accessible for this element still exists!");
|
|
|
|
#endif
|
2001-12-16 09:59:31 +03:00
|
|
|
}
|
|
|
|
|
1999-04-01 00:49:25 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2006-07-19 08:36:36 +04:00
|
|
|
// Implementation of the nsIContent interface text functions
|
1999-04-01 00:49:25 +04:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
nsresult CharacterData::SetText(const char16_t* aBuffer, uint32_t aLength,
|
|
|
|
bool aNotify) {
|
2006-10-28 05:22:53 +04:00
|
|
|
return SetTextInternal(0, mText.GetLength(), aBuffer, aLength, aNotify);
|
|
|
|
}
|
2006-07-19 08:36:36 +04:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
nsresult CharacterData::AppendText(const char16_t* aBuffer, uint32_t aLength,
|
|
|
|
bool aNotify) {
|
2006-10-28 05:22:53 +04:00
|
|
|
return SetTextInternal(mText.GetLength(), 0, aBuffer, aLength, aNotify);
|
1999-04-01 00:49:25 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
bool CharacterData::TextIsOnlyWhitespace() {
|
2017-03-17 00:10:22 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (!ThreadSafeTextIsOnlyWhitespace()) {
|
|
|
|
UnsetFlags(NS_TEXT_IS_ONLY_WHITESPACE);
|
|
|
|
SetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE | NS_TEXT_IS_ONLY_WHITESPACE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
bool CharacterData::ThreadSafeTextIsOnlyWhitespace() const {
|
2012-11-30 20:04:11 +04:00
|
|
|
// FIXME: should this method take content language into account?
|
2006-03-24 06:29:52 +03:00
|
|
|
if (mText.Is2b()) {
|
|
|
|
// The fragment contains non-8bit characters and such characters
|
|
|
|
// are never considered whitespace.
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
//
|
|
|
|
// FIXME(emilio): This is not quite true in presence of the
|
|
|
|
// NS_MAYBE_MODIFIED_FREQUENTLY flag... But looks like we only set that on
|
|
|
|
// anonymous nodes, so should be fine...
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-03-24 06:29:52 +03:00
|
|
|
}
|
2001-12-16 09:59:31 +03:00
|
|
|
|
2013-07-18 07:23:52 +04:00
|
|
|
if (HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)) {
|
|
|
|
return HasFlag(NS_TEXT_IS_ONLY_WHITESPACE);
|
|
|
|
}
|
|
|
|
|
2006-03-24 06:29:52 +03:00
|
|
|
const char* cp = mText.Get1b();
|
|
|
|
const char* end = cp + mText.GetLength();
|
2001-12-16 09:59:31 +03:00
|
|
|
|
2006-03-24 06:29:52 +03:00
|
|
|
while (cp < end) {
|
|
|
|
char ch = *cp;
|
2001-12-16 09:59:31 +03:00
|
|
|
|
Bug 1427625: Optimize appends to avoid restyling unnecessarily. r=xidorn
This unfortunately doesn't fix my test-case (because we're replacing the text
content all the time and all that), but it's still worth it, since it fixes the
case we care about (the parser appending).
We could also optimize pure insertions (since in that case we can still figure
out what the old text was), but it's probably annoying and not worth the churn.
In any case, we cannot optimize anything that resembles any kind of removal,
because from there we don't know the old text in any way (and the text nodes
like to reuse string buffers and such).
We could do two other optimizations to replace / extend this one, in that order:
* Pass the buffer and length to CharacterDataWillChange, and use that to get
the exact old text and the new one in RestyleManager. That would make the
optimization exact.
* Pass some sort of Maybe<bool> mWasWhitespace down the CharacterDataChangeInfo
which is computed like:
HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)
? Some(NS_TEXT_IS_ONLY_WHITESPACE)
: Nothing()
It's not clear to me it's going to be completely worth the churn, so I haven't
done those yet, if we see code in the wild which resembles my testcase, we can
think of doing it.
MozReview-Commit-ID: 2rTWaZti8rv
--HG--
extra : rebase_source : 7390b8740801eb7b91700bb2533c43c173ac5db9
2018-02-27 19:02:52 +03:00
|
|
|
// NOTE(emilio): If you ever change the definition of "whitespace" here, you
|
|
|
|
// need to change it too in RestyleManager::CharacterDataChanged.
|
2012-11-30 20:04:11 +04:00
|
|
|
if (!dom::IsSpaceCharacter(ch)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
1999-04-01 00:49:25 +04:00
|
|
|
}
|
2006-03-24 06:29:52 +03:00
|
|
|
|
|
|
|
++cp;
|
1999-04-01 00:49:25 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2001-12-16 09:59:31 +03:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
already_AddRefed<nsAtom> CharacterData::GetCurrentValueAtom() {
|
2004-02-25 02:10:38 +03:00
|
|
|
nsAutoString val;
|
|
|
|
GetData(val);
|
2016-03-29 02:09:43 +03:00
|
|
|
return NS_Atomize(val);
|
2004-02-25 02:10:38 +03:00
|
|
|
}
|
2005-11-02 03:41:51 +03:00
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
void CharacterData::AddSizeOfExcludingThis(nsWindowSizes& aSizes,
|
|
|
|
size_t* aNodeSize) const {
|
2017-08-25 07:47:54 +03:00
|
|
|
nsIContent::AddSizeOfExcludingThis(aSizes, aNodeSize);
|
|
|
|
*aNodeSize += mText.SizeOfExcludingThis(aSizes.mState.mMallocSizeOf);
|
2011-07-19 21:04:09 +04:00
|
|
|
}
|
|
|
|
|
2018-03-19 22:18:06 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|