mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
14d496a73d
- Bug 1222098 - Devicemotion event timestamp should return values from Android sensor API and not Gecko. r:smaug (0fb05341d5)
- Bug 1266701 - some header missing in dom/events, r=jwatt (59a8a30af3)
- namespace (c5796648b6)
- Bug 1243555: Remove unnecessary nsDocShell static_cast in EventListenerManager::HandleEventInternal(). r=smaug (21c559122c)
- Bug 1254629 - Let query events fail when content root is wrong; r=masayuki (64454249aa)
- Bug 1224233 - fix crashy usage of IMENotificationSender::Run using on-screen keyboard on Windows, r=smaug (ddcdf13ad0)
- Bug 1252058 IMEContentObserver::IMENotificationSender shouldn't post notifications when IMEContentObserver which is the owner of it stopped observing contents r=smaug (9f4a14f13a)
- Bug 1259671 part.1 Rename InternalScrollPortEvent::orientType to InternalScrollPortEvent::OrientType r=smaug (eaefa4472f)
- Bug 1259671 part.2 Rename InternalScrollPortEvent::vertical to InternalScrollPortEvent::eVertical r=smaug (91bcdcd1df)
- Bug 1259671 part.3 Rename InternalScrollPortEvent::horizontal to InternalScrollPortEvent::eHorizontal r=smaug (f3c206dc4c)
- Bug 1259671 part.4 Rename InternalScrollPortEvent::both to InternalScrollPortEvent::eBoth r=smaug (ac34dc95c1)
- Bug 1259671 part.5 Rename InternalScrollPortEvent::orient to InternalScrollPortEvent::mOrient r=smaug (6736862c75)
- Bug 1257873 - Split Addons and Workers into separate Target classes in about:debugging. r=ochameau (e7e41532ae)
- Bug 1232931 - Skip browser_service_workers_timeout.js for frequent failures across all platforms. (b02b21518d)
- Bug 1258902 - part1:add service worker unregister link in about:debugging;r=janx (dfdd0935dc)
- Bug 1258902 - part2: create service-worker-target component;r=janx (e2af5c51a0)
- Bug 1258902 - Fix a typo that caused the newly-added test to be skipped (and re-enabled a frequently-failing one). (1c7d4c32e1)
- Bug 1257874 - Use getProperties instead of getFrames in animation-detail. r=pbro (04741384f1)
- Bug 1260680 - Filter out unwanted data in getProperties to reduce protocol traffic; r=miker (583bdcf768)
- Bug 1262324 (part 1) - Remove "locale.all" prefix from Unix charsets. r=emk. (b337137c3d)
- Bug 1255655 - Const-ify dom encodings and similar arrays. r=baku. (93d79e84a7)
- Bug 1262324 (part 2) - Introduce nsUConvProp. r=emk. (bad497dee6)
- Bug 1206420 - Display animated pseudo-elements in the animation-inspector; r=tromey (bbc2795e22)
- Bug 1257877 - Remove UTF-16 support from TextEncoder. r=hsivonen (ad647b12a3)
- Bug 1120813 - Add support for the MS932 label of Shift_JIS. r=emk, r=Ms2ger (8a35fd93cf)
- Bug 1250930 - Use correct global when creating a key in GenerateAsymmetricKeyTask r=bz (ba65e0ae34)
- Bug 842818 - Allow calling WebCryptoTask::DispatchWithPromise() from workers r=keeler (e99301ba3e)
- Bug 1251390. Make timer queries available at the appropriate time. r=jgilbert (f1a0dcf7d3)
- Bug 1259696 - Check read buffer mode when doing CopyTexImage. r=jgilbert (fe51211b56)
- Bug 1241042 - Get correct frag varying from angle validator. r=jmuizelaar (29a4298a7e)
- Bug 1244611 - "Using named uniform buffer objects in the fragment shader fails". r=jgilbert (2e05e31d09)
- Bug 1263018 - Only update active prog info if linking active prog. - r=jrmuizel (1603ebdd8c)
- Bug 1257593 - Handle webgl FramebufferTexture2D() with an unbound texture. r=jgilbert (4d75981cb7)
- Bug 1257593 followup, fix bustage from believing a reviewer and then sending a different patch to try (7766b0cdb4)
- Bug 1258061 - Clarify FramebufferTexture2D handling for tex2D and cubeMap; r=jgilbert (0635d9412a)
- Bug 1240762 - Fix ServiceWorker request coming from Cache/Fetch. r=vporof (0251ffbb9f)
- remove PM hack (c6a751ac41)
- Bug 1230544 - JSON Viewer: support for .json URL extensions; r=jryans (32930bc41a)
- Bug 1235118 - JSON Viewer: remove support for .json URL extensions; r=jryans (626b490083)
- Bug 1255799 - make devtools/client/webconsole eslint-clean; r=odvarko (f4f85bdc4c)
- Bug 1240896 - Reorder imports to match style. r=gl (8f69df841c)
- Bug 1240896 - Port browser_responsive_cmd.js, add GCLI resize support. r=gl (33ce902874)
- Bug 1237986 - Avoid timeouts when the inspector opens in devtools mochitests; r=miker (2dd794f43a)
- Bug 1244755 - 1 - Enable browser_layout.js with e10s by using the testActor; r=miker (94504c2c96)
- Bug 1244755 - 2 - Remove addTest logic from layout-view tests for better consistency; r=miker (d3058ca6d5)
- Bug 1244755 - 3 - Remove CPOW usages and eslint warnings from devtools/client/inspector/layout; r=miker (5b7274dbc5)
- Bug 1239438 - fix most eslint warnings in styles.js; r=pbro (b03014105e)
- Bug 1139187 - Allow moving and resizing elements in content; r=pbro (b95284a4c4)
- Bug 1252099 - Do not use CPOWs in browser_markup_copy_image_data.js; r=jdescottes (5becee8341)
- Bug 1259449 - Require GLFeature::sync for WebGL's disjoint_timer_query. - r=jrmuizel (b6017134a3)
- Bug 1247804 - Enable seamless cubemaps where available. - r=jrmuizel (e7fd3ec5ed)
- Bug 1247977: More information when we hit the OpenGL error in FakeBlackTexture. r=jgilbert (f6f2c82e33)
- Bug 1261179 - Don't fallback GLContextProviders in WebGL. - r=jrmuizel (296223131f)
- Bug 1255655 - Const-ify sExtensionNames. r=mattwoodrow. (c0c60b34c7)
- Bug 1262757 - Use StaticRefPtr for the global context in GLContextProviderWGL, r=jrmuizel (0cc29a3385)
- Bug 1259811 - Require FBO support for GLContexts. - r=jrmuizel (ec3c1a6045)
- Bug 1234441 - Allow malformed ESSL version string. - r=jrmuizel (8fda1569ab)
- Bug 1199923 - Work around Intel Linux driver lying about max texture size - r=jgilbert (546b7dfe6a)
- Bug 1262265 - Cleanup GLContext symbol init. - r=jrmuizel (8da8ce647a)
- Bug 1232334 - [1.2] Only set context on successful attach. r=snorp (ca29c322bf)
- Bug 1261320 - Check DataSurface is vaild before using, r=milan (be9aebba47)
- Bug 1245868 - repalce pass by value with pass by pointer in IsHeadRequest. r=jst (f9d7f6185f)
- fix tests (3ccf9d1715)
- Bug 1232941 - Register Observer and listen to NS_XPCOM_SHUTDOWN_OBSERVER_ID for GATT, r=shuang (aa367807fa)
- Bug 1239979: Init and uninit all Bluetooth profile managers, r=shuang (78c1ebbd13)
- Bug 1239979: Uninitialized Bluetooth profile managers explictly to release refs, r=shuang (83b5389539)
- Bug 1262630. Replace workers::GetGlobalObjectForGlobal with xpc::NativeGlobal. r=khuey (9f639580be)
- Bug 1255817 part 6. Fix up some comments in CallbackObject that refer to things that no longer exist. r=bholley (575bf90c98)
- Bug 1259545. Remove the JS_SaveFrameChain bits in CallbackObject error reporting, since they are no longer needed. r=bholley (16181ddb38)
- Bug 1260511 part 1. Fix WebContentConverter to behave consistently in both e10s and non-e10s mode in terms of the argument sanity checking registerContentHandler does. r=gijs (1b24614bab)
- Bug 1260511 part 2. Change XPConnect's handling of exceptions thrown from JS components so that if an nsresult integer is thrown we convert it into an actual exception object before handing it out to content instead of propagating out the numeric value. r=khuey (dc02854e3f)
- Bug 1260511 part 3. In dom::Throw, ignore the pending xpconnect exception if we were given a non-default message string (because we don't want to lose that string). Also, make sure to always clear the pending xpconnect exception there. r=khuey (978a1e9132)
- Bug 1193093 - Tighten up these checks a little. r=Gijs (0ba7ebd060)
- Bug 1260511 part 4. Fix some of the places where registerProtocolHandler should be throwing a SECURITY_ERR to actually do so. r=gijs (11e6c5bfee)
- Bug 1130449 - fix reuse of accesskey string for protocol handler notification "Add" button, r=gijs (8c0c45aee5)
- Bug 1263045 - Avoid JavaScript strict warning in WebContentConverter.js during startup. r=Gijs (0948bbae40)
- Bug 1249702 - Fix e10s feed handling with auto content handler prefs. r=Gijs (7f0d9085f3)
- Bug 1250106 - Correctly set charging status and remaining time when battery level is rounded to 1.0 r=bz (662e18648c)
- Bug 1253641 - DOMException's CC participant should traverse mData. r=khuey. (0a48e3f8e7)
- Bug 1261115 - when Console is running in the main thread the existence of mWindow should always be ensured, r=smaug (caa1efd087)
- Bug 1257208 - Use the nsTextNode concrete type in several places in DirectionalityUtils.cpp instead of nsINode and nsIContent; r=peterv (69529fd8d4)
- Bug 1260982 - BlobFileImpl::GetType() should work also in workers, r=smaug (4b01d269bc)
- Bug 1262104 - Remove a non-used CTOR for BlobImplFile, r=ehsan (37ee0ec6d4)
- Bug 1259477 - Port test_document_register.html to mochitest-plain so that it can be turned on in e10s mode; r=mrbkap (411c220cda)
- Bug 1222128 - Turn test_bug1011748.html into a browser mochitest to make it run properly in e10s mode r=bzbarsky (45403d3d15)
- Bug 1259588 - new File("") throws TypeError exception, r=baku (05f6e7292d)
- Bug 1264710 - Catch IDB exceptions in IndexedDBHelper. r=fabrice (0d3c860a89)
- Bug 1263553 - Move MultipartBlobImpl into mozilla::dom namespace, r=smaug (e286c6cfe1)
- Bug 1263551 - Remove unused method in MultipartBlobImpl, r=smaug (54c2da9a12)
- Bug 1252687 - get rid of static nsStrings in PerformanceObserver.cpp r=bz (319f2697d4)
- Bug 1148535 - Check if the density descriptor in srcset consists of a valid floating-point number. r=jdm (79ac8d8dea)
- Bug 1257742 - Part 1: Follow the update-source-set rule to append default source into source set; r=jdm (853c69cc8c)
- Bug 1257742 - Part 2: Allow both width and static density candidates showing in same selector; r=jdm (4f1e00225d)
- Bug 1257742 - Part 3: Support using floating point in sizes descriptor; r=jdm (c1a7e36bb3)
- Bug 1257742 - Part 4: Update web-platform test expectation; r=jdm (e41044b88e)
- Bug 1262942 - Remove unnecessary warning message in ResponsiveImageSelector; r=jdm (ffb757204d)
- Bug 1158412 - Remove assertion for document prescontex and add crash test; r=jdm (947ccdfbfc)
- Bug 1237633 - Part 1: Percentages are not allowed in a <source-size-value>. r=jdm (614b560097)
- Bug 1237633 - Part 2: Avoid fatal assertion when a responsive image's size specifier is invalid. r=johns, r=jdm (4e90829d97)
- Bug 495546 - Add crashtest. (c2765ecbf4)
- fix some tests (d9b393b168)
- Bug 1256419. Null-check our nsDOMWindowList before trying to get its length. r=smaug (6c14430e5d)
- Bug 1162775: Make contentAreaDropListener use dataTransfer.files to get the files dropped. r=smaug (d2850f2008)
- Bug 1220679 - replace AutoSafeJSContext with AutoJSAPI. r=bz. (64538bdd44)
- Bug 1239047 - Make comment nodes draggable in the markup-view; r=miker (d829b881c0)
- reinstantiate assert, present in up to esr68 (221cec538a)
- Bug 1209329 - Improve comments about about: URIs in nsContentUtils::InternalStorageAllowedForPrincipal, r=bholley (71152e5639)
- Bug 1246250 - Deal with failure to create a blob actor. r=khuey (102686ac28)
- Bug 1265902 - part 1 - be more efficient when using nsContentUtils::GetSurfaceData(); r=mccr8 (ba2a52abd3)
- Bug 1258857 - Add empty items to an IPC transferable object for every flavor of the source object that did not have any data associated to it r=enndeakin (0a02b61566)
- Bug 1265902 - part 2 - don't construct unnecessary string temporaries in TransferablesToIPCTransferables; r=mccr8 (aec10c8fc6)
- remove unknown blob handling, not found in Tycho-dev repo, nor esr60 or TFF (eb6a24720a)
- Bug 1155486 - Convert nsDOMAttributeMap::mLocalName to void* to ensure that we can never dereference it; r=baku (34e2864340)
- Bug 1250926 - Remove unused SCRIPTABLE_FLAGS defines from nsDOMClassInfo; r=peterv (76917fb76b)
- No bug. Helper tool to partially autogenerate portions of the release notes. (3818e5534b)
- Bug 1203423 - Move call to AddClone outside nsMutationReceiver constructor; r=smaug (35c94ad785)
- Bug 1254096 - Update CaretPositionFromPoint() for type=number, r=ehsan (df31edca8f)
- Bug 1265771 P1 Only store active documents in the global observer list. r=bz (01502e91e5)
- Bug 1265771 P2 Expand navigate-window.https.html wpt test to cover uncontrolled windows. r=bz (3333906720)
- Bug 1265771 P3 Expand browser_force_refresh.js to verify Clients.matchAll() behavior on refresh. r=bz (01394ec8f1)
- stop hiding things for _LIBCPP_VERSION (5de86e8bbf)
1126 lines
30 KiB
C++
1126 lines
30 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
/*
|
|
* Base class for DOM Core's nsIDOMComment, nsIDOMDocumentType, nsIDOMText,
|
|
* nsIDOMCDATASection, and nsIDOMProcessingInstruction nodes.
|
|
*/
|
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
#include "nsGenericDOMDataNode.h"
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
|
#include "mozilla/MemoryReporting.h"
|
|
#include "mozilla/dom/Element.h"
|
|
#include "mozilla/dom/ShadowRoot.h"
|
|
#include "nsIDocument.h"
|
|
#include "nsIDOMDocument.h"
|
|
#include "nsReadableUtils.h"
|
|
#include "mozilla/InternalMutationEvent.h"
|
|
#include "nsIURI.h"
|
|
#include "nsIDOMEvent.h"
|
|
#include "nsIDOMText.h"
|
|
#include "nsCOMPtr.h"
|
|
#include "nsDOMString.h"
|
|
#include "nsChangeHint.h"
|
|
#include "nsCOMArray.h"
|
|
#include "nsNodeUtils.h"
|
|
#include "mozilla/dom/DirectionalityUtils.h"
|
|
#include "nsBindingManager.h"
|
|
#include "nsCCUncollectableMarker.h"
|
|
#include "mozAutoDocUpdate.h"
|
|
|
|
#include "PLDHashTable.h"
|
|
#include "mozilla/Snprintf.h"
|
|
#include "nsWrapperCacheInlines.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom;
|
|
|
|
nsGenericDOMDataNode::nsGenericDOMDataNode(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
|
: nsIContent(aNodeInfo)
|
|
{
|
|
MOZ_ASSERT(mNodeInfo->NodeType() == nsIDOMNode::TEXT_NODE ||
|
|
mNodeInfo->NodeType() == nsIDOMNode::CDATA_SECTION_NODE ||
|
|
mNodeInfo->NodeType() == nsIDOMNode::COMMENT_NODE ||
|
|
mNodeInfo->NodeType() == nsIDOMNode::PROCESSING_INSTRUCTION_NODE ||
|
|
mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE,
|
|
"Bad NodeType in aNodeInfo");
|
|
}
|
|
|
|
nsGenericDOMDataNode::nsGenericDOMDataNode(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
: nsIContent(aNodeInfo)
|
|
{
|
|
MOZ_ASSERT(mNodeInfo->NodeType() == nsIDOMNode::TEXT_NODE ||
|
|
mNodeInfo->NodeType() == nsIDOMNode::CDATA_SECTION_NODE ||
|
|
mNodeInfo->NodeType() == nsIDOMNode::COMMENT_NODE ||
|
|
mNodeInfo->NodeType() == nsIDOMNode::PROCESSING_INSTRUCTION_NODE ||
|
|
mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE,
|
|
"Bad NodeType in aNodeInfo");
|
|
}
|
|
|
|
nsGenericDOMDataNode::~nsGenericDOMDataNode()
|
|
{
|
|
NS_PRECONDITION(!IsInUncomposedDoc(),
|
|
"Please remove this from the document properly");
|
|
if (GetParent()) {
|
|
NS_RELEASE(mParent);
|
|
}
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericDOMDataNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsGenericDOMDataNode)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsGenericDOMDataNode)
|
|
return Element::CanSkip(tmp, aRemovingAllowed);
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsGenericDOMDataNode)
|
|
return Element::CanSkipInCC(tmp);
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsGenericDOMDataNode)
|
|
return Element::CanSkipThis(tmp);
|
|
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGenericDOMDataNode)
|
|
if (MOZ_UNLIKELY(cb.WantDebugInfo())) {
|
|
char name[40];
|
|
snprintf_literal(name, "nsGenericDOMDataNode (len=%d)",
|
|
tmp->mText.GetLength());
|
|
cb.DescribeRefCountedNode(tmp->mRefCnt.get(), name);
|
|
} else {
|
|
NS_IMPL_CYCLE_COLLECTION_DESCRIBE(nsGenericDOMDataNode, tmp->mRefCnt.get())
|
|
}
|
|
|
|
// Always need to traverse script objects, so do that before we check
|
|
// if we're uncollectable.
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
if (!nsINode::Traverse(tmp, cb)) {
|
|
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
|
|
}
|
|
|
|
nsDataSlots *slots = tmp->GetExistingDataSlots();
|
|
if (slots) {
|
|
slots->Traverse(cb);
|
|
}
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericDOMDataNode)
|
|
nsINode::Unlink(tmp);
|
|
|
|
// Clear flag here because unlinking slots will clear the
|
|
// containing shadow root pointer.
|
|
tmp->UnsetFlags(NODE_IS_IN_SHADOW_TREE);
|
|
|
|
nsDataSlots *slots = tmp->GetExistingDataSlots();
|
|
if (slots) {
|
|
slots->Unlink();
|
|
}
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsGenericDOMDataNode)
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsGenericDOMDataNode)
|
|
NS_INTERFACE_MAP_ENTRY(nsIContent)
|
|
NS_INTERFACE_MAP_ENTRY(nsINode)
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
|
|
NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget)
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
|
|
new nsNodeSupportsWeakRefTearoff(this))
|
|
// DOM bindings depend on the identity pointer being the
|
|
// same as nsINode (which nsIContent inherits).
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
|
|
NS_INTERFACE_MAP_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsGenericDOMDataNode)
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(nsGenericDOMDataNode,
|
|
nsNodeUtils::LastRelease(this))
|
|
|
|
|
|
void
|
|
nsGenericDOMDataNode::GetNodeValueInternal(nsAString& aNodeValue)
|
|
{
|
|
DebugOnly<nsresult> rv = GetData(aNodeValue);
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "GetData() failed!");
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::SetNodeValueInternal(const nsAString& aNodeValue,
|
|
ErrorResult& aError)
|
|
{
|
|
aError = SetTextInternal(0, mText.GetLength(), aNodeValue.BeginReading(),
|
|
aNodeValue.Length(), true);
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation of nsIDOMCharacterData
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::GetData(nsAString& aData) const
|
|
{
|
|
if (mText.Is2b()) {
|
|
aData.Assign(mText.Get2b(), mText.GetLength());
|
|
} else {
|
|
// Must use Substring() since nsDependentCString() requires null
|
|
// terminated strings.
|
|
|
|
const char *data = mText.Get1b();
|
|
|
|
if (data) {
|
|
CopyASCIItoUTF16(Substring(data, data + mText.GetLength()), aData);
|
|
} else {
|
|
aData.Truncate();
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::SetData(const nsAString& aData)
|
|
{
|
|
return SetTextInternal(0, mText.GetLength(), aData.BeginReading(),
|
|
aData.Length(), true);
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::GetLength(uint32_t* aLength)
|
|
{
|
|
*aLength = mText.GetLength();
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::SubstringData(uint32_t aStart, uint32_t aCount,
|
|
nsAString& aReturn)
|
|
{
|
|
ErrorResult rv;
|
|
SubstringData(aStart, aCount, aReturn, rv);
|
|
return rv.StealNSResult();
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::SubstringData(uint32_t aStart, uint32_t aCount,
|
|
nsAString& aReturn, ErrorResult& rv)
|
|
{
|
|
aReturn.Truncate();
|
|
|
|
uint32_t textLength = mText.GetLength();
|
|
if (aStart > textLength) {
|
|
rv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
return;
|
|
}
|
|
|
|
uint32_t amount = aCount;
|
|
if (amount > textLength - aStart) {
|
|
amount = textLength - aStart;
|
|
}
|
|
|
|
if (mText.Is2b()) {
|
|
aReturn.Assign(mText.Get2b() + aStart, amount);
|
|
} else {
|
|
// Must use Substring() since nsDependentCString() requires null
|
|
// terminated strings.
|
|
|
|
const char *data = mText.Get1b() + aStart;
|
|
CopyASCIItoUTF16(Substring(data, data + amount), aReturn);
|
|
}
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsGenericDOMDataNode::MozRemove()
|
|
{
|
|
Remove();
|
|
return NS_OK;
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::AppendData(const nsAString& aData)
|
|
{
|
|
return SetTextInternal(mText.GetLength(), 0, aData.BeginReading(),
|
|
aData.Length(), true);
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::InsertData(uint32_t aOffset,
|
|
const nsAString& aData)
|
|
{
|
|
return SetTextInternal(aOffset, 0, aData.BeginReading(),
|
|
aData.Length(), true);
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::DeleteData(uint32_t aOffset, uint32_t aCount)
|
|
{
|
|
return SetTextInternal(aOffset, aCount, nullptr, 0, true);
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::ReplaceData(uint32_t aOffset, uint32_t aCount,
|
|
const nsAString& aData)
|
|
{
|
|
return SetTextInternal(aOffset, aCount, aData.BeginReading(),
|
|
aData.Length(), true);
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::SetTextInternal(uint32_t aOffset, uint32_t aCount,
|
|
const char16_t* aBuffer,
|
|
uint32_t aLength, bool aNotify,
|
|
CharacterDataChangeInfo::Details* aDetails)
|
|
{
|
|
NS_PRECONDITION(aBuffer || !aLength,
|
|
"Null buffer passed to SetTextInternal!");
|
|
|
|
// sanitize arguments
|
|
uint32_t textLength = mText.GetLength();
|
|
if (aOffset > textLength) {
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
}
|
|
|
|
if (aCount > textLength - aOffset) {
|
|
aCount = textLength - aOffset;
|
|
}
|
|
|
|
uint32_t endOffset = aOffset + aCount;
|
|
|
|
// Make sure the text fragment can hold the new data.
|
|
if (aLength > aCount && !mText.CanGrowBy(aLength - aCount)) {
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
|
|
nsIDocument *document = GetComposedDoc();
|
|
mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, aNotify);
|
|
|
|
bool haveMutationListeners = aNotify &&
|
|
nsContentUtils::HasMutationListeners(this,
|
|
NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED,
|
|
this);
|
|
|
|
nsCOMPtr<nsIAtom> oldValue;
|
|
if (haveMutationListeners) {
|
|
oldValue = GetCurrentValueAtom();
|
|
}
|
|
|
|
if (aNotify) {
|
|
CharacterDataChangeInfo info = {
|
|
aOffset == textLength,
|
|
aOffset,
|
|
endOffset,
|
|
aLength,
|
|
aDetails
|
|
};
|
|
nsNodeUtils::CharacterDataWillChange(this, &info);
|
|
}
|
|
|
|
Directionality oldDir = eDir_NotSet;
|
|
bool dirAffectsAncestor = (NodeType() == nsIDOMNode::TEXT_NODE &&
|
|
TextNodeWillChangeDirection(this, &oldDir, aOffset));
|
|
|
|
if (aOffset == 0 && endOffset == textLength) {
|
|
// 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.
|
|
bool ok = mText.SetTo(aBuffer, aLength, !document || !document->GetBidiEnabled());
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
|
}
|
|
else if (aOffset == textLength) {
|
|
// Appending to existing
|
|
bool ok = mText.Append(aBuffer, aLength, !document || !document->GetBidiEnabled());
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
|
}
|
|
else {
|
|
// Merging old and new
|
|
|
|
// Allocate new buffer
|
|
int32_t newLength = textLength - aCount + aLength;
|
|
char16_t* to = new char16_t[newLength];
|
|
|
|
// Copy over appropriate data
|
|
if (aOffset) {
|
|
mText.CopyTo(to, 0, aOffset);
|
|
}
|
|
if (aLength) {
|
|
memcpy(to + aOffset, aBuffer, aLength * sizeof(char16_t));
|
|
}
|
|
if (endOffset != textLength) {
|
|
mText.CopyTo(to + aOffset + aLength, endOffset, textLength - endOffset);
|
|
}
|
|
|
|
bool ok = mText.SetTo(to, newLength, !document || !document->GetBidiEnabled());
|
|
|
|
delete [] to;
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_OUT_OF_MEMORY);
|
|
}
|
|
|
|
UnsetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE);
|
|
|
|
if (document && mText.IsBidi()) {
|
|
// If we found bidi characters in mText.SetTo() above, indicate that the
|
|
// document contains bidi characters.
|
|
document->SetBidiEnabled();
|
|
}
|
|
|
|
if (dirAffectsAncestor) {
|
|
// dirAffectsAncestor being true implies that we have a text node, see
|
|
// above.
|
|
MOZ_ASSERT(NodeType() == nsIDOMNode::TEXT_NODE);
|
|
TextNodeChangedDirection(static_cast<nsTextNode*>(this), oldDir, aNotify);
|
|
}
|
|
|
|
// Notify observers
|
|
if (aNotify) {
|
|
CharacterDataChangeInfo info = {
|
|
aOffset == textLength,
|
|
aOffset,
|
|
endOffset,
|
|
aLength,
|
|
aDetails
|
|
};
|
|
nsNodeUtils::CharacterDataChanged(this, &info);
|
|
|
|
if (haveMutationListeners) {
|
|
InternalMutationEvent mutation(true, eLegacyCharacterDataModified);
|
|
|
|
mutation.mPrevAttrValue = oldValue;
|
|
if (aLength > 0) {
|
|
nsAutoString val;
|
|
mText.AppendTo(val);
|
|
mutation.mNewAttrValue = NS_Atomize(val);
|
|
}
|
|
|
|
mozAutoSubtreeModified subtree(OwnerDoc(), this);
|
|
(new AsyncEventDispatcher(this, mutation))->RunDOMEventWhenSafe();
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation of nsIContent
|
|
|
|
#ifdef DEBUG
|
|
void
|
|
nsGenericDOMDataNode::ToCString(nsAString& aBuf, int32_t aOffset,
|
|
int32_t aLen) const
|
|
{
|
|
if (mText.Is2b()) {
|
|
const char16_t* cp = mText.Get2b() + aOffset;
|
|
const char16_t* end = cp + aLen;
|
|
|
|
while (cp < end) {
|
|
char16_t ch = *cp++;
|
|
if (ch == '&') {
|
|
aBuf.AppendLiteral("&");
|
|
} else if (ch == '<') {
|
|
aBuf.AppendLiteral("<");
|
|
} else if (ch == '>') {
|
|
aBuf.AppendLiteral(">");
|
|
} else if ((ch < ' ') || (ch >= 127)) {
|
|
char buf[10];
|
|
snprintf_literal(buf, "\\u%04x", ch);
|
|
AppendASCIItoUTF16(buf, aBuf);
|
|
} else {
|
|
aBuf.Append(ch);
|
|
}
|
|
}
|
|
} else {
|
|
unsigned char* cp = (unsigned char*)mText.Get1b() + aOffset;
|
|
const unsigned char* end = cp + aLen;
|
|
|
|
while (cp < end) {
|
|
char16_t ch = *cp++;
|
|
if (ch == '&') {
|
|
aBuf.AppendLiteral("&");
|
|
} else if (ch == '<') {
|
|
aBuf.AppendLiteral("<");
|
|
} else if (ch == '>') {
|
|
aBuf.AppendLiteral(">");
|
|
} else if ((ch < ' ') || (ch >= 127)) {
|
|
char buf[10];
|
|
snprintf_literal(buf, "\\u%04x", ch);
|
|
AppendASCIItoUTF16(buf, aBuf);
|
|
} else {
|
|
aBuf.Append(ch);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
nsIContent* aBindingParent,
|
|
bool aCompileEventHandlers)
|
|
{
|
|
NS_PRECONDITION(aParent || aDocument, "Must have document if no parent!");
|
|
NS_PRECONDITION(NODE_FROM(aParent, aDocument)->OwnerDoc() == OwnerDoc(),
|
|
"Must have the same owner document");
|
|
NS_PRECONDITION(!aParent || aDocument == aParent->GetUncomposedDoc(),
|
|
"aDocument must be current doc of aParent");
|
|
NS_PRECONDITION(!GetUncomposedDoc() && !IsInUncomposedDoc(),
|
|
"Already have a document. Unbind first!");
|
|
// 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.
|
|
NS_PRECONDITION(!GetParent() || aParent == GetParent(),
|
|
"Already have a parent. Unbind first!");
|
|
NS_PRECONDITION(!GetBindingParent() ||
|
|
aBindingParent == GetBindingParent() ||
|
|
(!aBindingParent && aParent &&
|
|
aParent->GetBindingParent() == GetBindingParent()),
|
|
"Already have a binding parent. Unbind first!");
|
|
NS_PRECONDITION(aBindingParent != this,
|
|
"Content must not be its own binding parent");
|
|
NS_PRECONDITION(!IsRootOfNativeAnonymousSubtree() ||
|
|
aBindingParent == aParent,
|
|
"Native anonymous content must have its parent as its "
|
|
"own binding parent");
|
|
|
|
if (!aBindingParent && aParent) {
|
|
aBindingParent = aParent->GetBindingParent();
|
|
}
|
|
|
|
// First set the binding parent
|
|
if (aBindingParent) {
|
|
NS_ASSERTION(IsRootOfNativeAnonymousSubtree() ||
|
|
!HasFlag(NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE) ||
|
|
(aParent && aParent->IsInNativeAnonymousSubtree()),
|
|
"Trying to re-bind content from native anonymous subtree to "
|
|
"non-native anonymous parent!");
|
|
DataSlots()->mBindingParent = aBindingParent; // Weak, so no addref happens.
|
|
if (aParent->IsInNativeAnonymousSubtree()) {
|
|
SetFlags(NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE);
|
|
}
|
|
if (aParent->HasFlag(NODE_CHROME_ONLY_ACCESS)) {
|
|
SetFlags(NODE_CHROME_ONLY_ACCESS);
|
|
}
|
|
if (aParent->IsInShadowTree()) {
|
|
ClearSubtreeRootPointer();
|
|
SetFlags(NODE_IS_IN_SHADOW_TREE);
|
|
}
|
|
ShadowRoot* parentContainingShadow = aParent->GetContainingShadow();
|
|
if (parentContainingShadow) {
|
|
DataSlots()->mContainingShadow = parentContainingShadow;
|
|
}
|
|
}
|
|
|
|
bool hadParent = !!GetParentNode();
|
|
|
|
// Set parent
|
|
if (aParent) {
|
|
if (!GetParent()) {
|
|
NS_ADDREF(aParent);
|
|
}
|
|
mParent = aParent;
|
|
}
|
|
else {
|
|
mParent = aDocument;
|
|
}
|
|
SetParentIsContent(aParent);
|
|
|
|
// XXXbz sXBL/XBL2 issue!
|
|
|
|
// Set document
|
|
if (aDocument) {
|
|
// We no longer need to track the subtree pointer (and in fact we'll assert
|
|
// if we do this any later).
|
|
ClearSubtreeRootPointer();
|
|
|
|
// XXX See the comment in Element::BindToTree
|
|
SetInDocument();
|
|
if (mText.IsBidi()) {
|
|
aDocument->SetBidiEnabled();
|
|
}
|
|
// Clear the lazy frame construction bits.
|
|
UnsetFlags(NODE_NEEDS_FRAME | NODE_DESCENDANTS_NEED_FRAMES);
|
|
} else if (!IsInShadowTree()) {
|
|
// If we're not in the doc and not in a shadow tree,
|
|
// update our subtree pointer.
|
|
SetSubtreeRootPointer(aParent->SubtreeRoot());
|
|
}
|
|
|
|
nsNodeUtils::ParentChainChanged(this);
|
|
if (!hadParent && IsRootOfNativeAnonymousSubtree()) {
|
|
nsNodeUtils::NativeAnonymousChildListChange(this, false);
|
|
}
|
|
|
|
UpdateEditableState(false);
|
|
|
|
NS_POSTCONDITION(aDocument == GetUncomposedDoc(), "Bound to wrong document");
|
|
NS_POSTCONDITION(aParent == GetParent(), "Bound to wrong parent");
|
|
NS_POSTCONDITION(aBindingParent == GetBindingParent(),
|
|
"Bound to wrong binding parent");
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::UnbindFromTree(bool aDeep, bool aNullParent)
|
|
{
|
|
// Unset frame flags; if we need them again later, they'll get set again.
|
|
UnsetFlags(NS_CREATE_FRAME_IF_NON_WHITESPACE |
|
|
NS_REFRAME_IF_WHITESPACE);
|
|
|
|
nsIDocument* document =
|
|
HasFlag(NODE_FORCE_XBL_BINDINGS) ? OwnerDoc() : GetComposedDoc();
|
|
|
|
if (aNullParent) {
|
|
if (this->IsRootOfNativeAnonymousSubtree()) {
|
|
nsNodeUtils::NativeAnonymousChildListChange(this, true);
|
|
}
|
|
if (GetParent()) {
|
|
NS_RELEASE(mParent);
|
|
} else {
|
|
mParent = nullptr;
|
|
}
|
|
SetParentIsContent(false);
|
|
}
|
|
ClearInDocument();
|
|
|
|
if (aNullParent || !mParent->IsInShadowTree()) {
|
|
UnsetFlags(NODE_IS_IN_SHADOW_TREE);
|
|
|
|
// Begin keeping track of our subtree root.
|
|
SetSubtreeRootPointer(aNullParent ? this : mParent->SubtreeRoot());
|
|
}
|
|
|
|
if (document && !GetContainingShadow()) {
|
|
// Notify XBL- & nsIAnonymousContentCreator-generated
|
|
// anonymous content that the document is changing.
|
|
// Unlike XBL, bindings for web components shadow DOM
|
|
// do not get uninstalled.
|
|
if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
|
|
nsContentUtils::AddScriptRunner(
|
|
new RemoveFromBindingManagerRunnable(document->BindingManager(), this,
|
|
document));
|
|
}
|
|
}
|
|
|
|
nsDataSlots *slots = GetExistingDataSlots();
|
|
if (slots) {
|
|
slots->mBindingParent = nullptr;
|
|
if (aNullParent || !mParent->IsInShadowTree()) {
|
|
slots->mContainingShadow = nullptr;
|
|
}
|
|
}
|
|
|
|
nsNodeUtils::ParentChainChanged(this);
|
|
}
|
|
|
|
already_AddRefed<nsINodeList>
|
|
nsGenericDOMDataNode::GetChildren(uint32_t aFilter)
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::SetAttr(int32_t aNameSpaceID, nsIAtom* aAttr,
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
|
bool aNotify)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttr,
|
|
bool aNotify)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
const nsAttrName*
|
|
nsGenericDOMDataNode::GetAttrNameAt(uint32_t aIndex) const
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
uint32_t
|
|
nsGenericDOMDataNode::GetAttrCount() const
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
uint32_t
|
|
nsGenericDOMDataNode::GetChildCount() const
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
nsIContent *
|
|
nsGenericDOMDataNode::GetChildAt(uint32_t aIndex) const
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
nsIContent * const *
|
|
nsGenericDOMDataNode::GetChildArray(uint32_t* aChildCount) const
|
|
{
|
|
*aChildCount = 0;
|
|
return nullptr;
|
|
}
|
|
|
|
int32_t
|
|
nsGenericDOMDataNode::IndexOf(const nsINode* aPossibleChild) const
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::InsertChildAt(nsIContent* aKid, uint32_t aIndex,
|
|
bool aNotify)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::RemoveChildAt(uint32_t aIndex, bool aNotify)
|
|
{
|
|
}
|
|
|
|
nsIContent *
|
|
nsGenericDOMDataNode::GetBindingParent() const
|
|
{
|
|
nsDataSlots *slots = GetExistingDataSlots();
|
|
return slots ? slots->mBindingParent : nullptr;
|
|
}
|
|
|
|
ShadowRoot *
|
|
nsGenericDOMDataNode::GetShadowRoot() const
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
ShadowRoot *
|
|
nsGenericDOMDataNode::GetContainingShadow() const
|
|
{
|
|
nsDataSlots *slots = GetExistingDataSlots();
|
|
if (!slots) {
|
|
return nullptr;
|
|
}
|
|
return slots->mContainingShadow;
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::SetShadowRoot(ShadowRoot* aShadowRoot)
|
|
{
|
|
}
|
|
|
|
nsTArray<nsIContent*>&
|
|
nsGenericDOMDataNode::DestInsertionPoints()
|
|
{
|
|
nsDataSlots *slots = DataSlots();
|
|
return slots->mDestInsertionPoints;
|
|
}
|
|
|
|
nsTArray<nsIContent*>*
|
|
nsGenericDOMDataNode::GetExistingDestInsertionPoints() const
|
|
{
|
|
nsDataSlots *slots = GetExistingDataSlots();
|
|
if (slots) {
|
|
return &slots->mDestInsertionPoints;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
nsXBLBinding *
|
|
nsGenericDOMDataNode::GetXBLBinding() const
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::SetXBLBinding(nsXBLBinding* aBinding,
|
|
nsBindingManager* aOldBindingManager)
|
|
{
|
|
}
|
|
|
|
nsIContent *
|
|
nsGenericDOMDataNode::GetXBLInsertionParent() const
|
|
{
|
|
if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
|
|
nsDataSlots *slots = GetExistingDataSlots();
|
|
if (slots) {
|
|
return slots->mXBLInsertionParent;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::SetXBLInsertionParent(nsIContent* aContent)
|
|
{
|
|
if (aContent) {
|
|
nsDataSlots *slots = DataSlots();
|
|
SetFlags(NODE_MAY_BE_IN_BINDING_MNGR);
|
|
slots->mXBLInsertionParent = aContent;
|
|
} else {
|
|
nsDataSlots *slots = GetExistingDataSlots();
|
|
if (slots) {
|
|
slots->mXBLInsertionParent = nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
CustomElementData *
|
|
nsGenericDOMDataNode::GetCustomElementData() const
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::SetCustomElementData(CustomElementData* aData)
|
|
{
|
|
}
|
|
|
|
bool
|
|
nsGenericDOMDataNode::IsNodeOfType(uint32_t aFlags) const
|
|
{
|
|
return !(aFlags & ~(eCONTENT | eDATA_NODE));
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::SaveSubtreeState()
|
|
{
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
void
|
|
nsGenericDOMDataNode::List(FILE* out, int32_t aIndent) const
|
|
{
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::DumpContent(FILE* out, int32_t aIndent,
|
|
bool aDumpAll) const
|
|
{
|
|
}
|
|
#endif
|
|
|
|
bool
|
|
nsGenericDOMDataNode::IsLink(nsIURI** aURI) const
|
|
{
|
|
*aURI = nullptr;
|
|
return false;
|
|
}
|
|
|
|
nsINode::nsSlots*
|
|
nsGenericDOMDataNode::CreateSlots()
|
|
{
|
|
return new nsDataSlots();
|
|
}
|
|
|
|
nsGenericDOMDataNode::nsDataSlots::nsDataSlots()
|
|
: nsINode::nsSlots(), mBindingParent(nullptr)
|
|
{
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::nsDataSlots::Traverse(nsCycleCollectionTraversalCallback &cb)
|
|
{
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mXBLInsertionParent");
|
|
cb.NoteXPCOMChild(mXBLInsertionParent.get());
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mContainingShadow");
|
|
cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIContent*, mContainingShadow));
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::nsDataSlots::Unlink()
|
|
{
|
|
mXBLInsertionParent = nullptr;
|
|
mContainingShadow = nullptr;
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation of the nsIDOMText interface
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::SplitData(uint32_t aOffset, nsIContent** aReturn,
|
|
bool aCloneAfterOriginal)
|
|
{
|
|
*aReturn = nullptr;
|
|
nsresult rv = NS_OK;
|
|
nsAutoString cutText;
|
|
uint32_t length = TextLength();
|
|
|
|
if (aOffset > length) {
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
}
|
|
|
|
uint32_t cutStartOffset = aCloneAfterOriginal ? aOffset : 0;
|
|
uint32_t cutLength = aCloneAfterOriginal ? length - aOffset : aOffset;
|
|
rv = SubstringData(cutStartOffset, cutLength, cutText);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
|
|
nsIDocument* document = GetComposedDoc();
|
|
mozAutoDocUpdate updateBatch(document, UPDATE_CONTENT_MODEL, true);
|
|
|
|
// Use Clone for creating the new node so that the new node is of same class
|
|
// as this node!
|
|
nsCOMPtr<nsIContent> newContent = CloneDataNode(mNodeInfo, false);
|
|
if (!newContent) {
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
newContent->SetText(cutText, true); // XXX should be false?
|
|
|
|
CharacterDataChangeInfo::Details details = {
|
|
CharacterDataChangeInfo::Details::eSplit, newContent
|
|
};
|
|
rv = SetTextInternal(cutStartOffset, cutLength, nullptr, 0, true,
|
|
aCloneAfterOriginal ? &details : nullptr);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
|
|
nsCOMPtr<nsINode> parent = GetParentNode();
|
|
if (parent) {
|
|
int32_t insertionIndex = parent->IndexOf(this);
|
|
if (aCloneAfterOriginal) {
|
|
++insertionIndex;
|
|
}
|
|
parent->InsertChildAt(newContent, insertionIndex, true);
|
|
}
|
|
|
|
newContent.swap(*aReturn);
|
|
return rv;
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::SplitText(uint32_t aOffset, nsIDOMText** aReturn)
|
|
{
|
|
nsCOMPtr<nsIContent> newChild;
|
|
nsresult rv = SplitData(aOffset, getter_AddRefs(newChild));
|
|
if (NS_SUCCEEDED(rv)) {
|
|
rv = CallQueryInterface(newChild, aReturn);
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
/* static */ int32_t
|
|
nsGenericDOMDataNode::FirstLogicallyAdjacentTextNode(nsIContent* aParent,
|
|
int32_t aIndex)
|
|
{
|
|
while (aIndex-- > 0) {
|
|
nsIContent* sibling = aParent->GetChildAt(aIndex);
|
|
if (!sibling->IsNodeOfType(nsINode::eTEXT))
|
|
return aIndex + 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/* static */ int32_t
|
|
nsGenericDOMDataNode::LastLogicallyAdjacentTextNode(nsIContent* aParent,
|
|
int32_t aIndex,
|
|
uint32_t aCount)
|
|
{
|
|
while (++aIndex < int32_t(aCount)) {
|
|
nsIContent* sibling = aParent->GetChildAt(aIndex);
|
|
if (!sibling->IsNodeOfType(nsINode::eTEXT))
|
|
return aIndex - 1;
|
|
}
|
|
return aCount - 1;
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::GetWholeText(nsAString& aWholeText)
|
|
{
|
|
nsIContent* parent = GetParent();
|
|
|
|
// Handle parent-less nodes
|
|
if (!parent)
|
|
return GetData(aWholeText);
|
|
|
|
int32_t index = parent->IndexOf(this);
|
|
NS_WARN_IF_FALSE(index >= 0,
|
|
"Trying to use .wholeText with an anonymous"
|
|
"text node child of a binding parent?");
|
|
NS_ENSURE_TRUE(index >= 0, NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
int32_t first =
|
|
FirstLogicallyAdjacentTextNode(parent, index);
|
|
int32_t last =
|
|
LastLogicallyAdjacentTextNode(parent, index, parent->GetChildCount());
|
|
|
|
aWholeText.Truncate();
|
|
|
|
nsCOMPtr<nsIDOMText> node;
|
|
nsAutoString tmp;
|
|
do {
|
|
node = do_QueryInterface(parent->GetChildAt(first));
|
|
node->GetData(tmp);
|
|
aWholeText.Append(tmp);
|
|
} while (first++ < last);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation of the nsIContent interface text functions
|
|
|
|
const nsTextFragment *
|
|
nsGenericDOMDataNode::GetText()
|
|
{
|
|
return &mText;
|
|
}
|
|
|
|
uint32_t
|
|
nsGenericDOMDataNode::TextLength() const
|
|
{
|
|
return mText.GetLength();
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::SetText(const char16_t* aBuffer,
|
|
uint32_t aLength,
|
|
bool aNotify)
|
|
{
|
|
return SetTextInternal(0, mText.GetLength(), aBuffer, aLength, aNotify);
|
|
}
|
|
|
|
nsresult
|
|
nsGenericDOMDataNode::AppendText(const char16_t* aBuffer,
|
|
uint32_t aLength,
|
|
bool aNotify)
|
|
{
|
|
return SetTextInternal(mText.GetLength(), 0, aBuffer, aLength, aNotify);
|
|
}
|
|
|
|
bool
|
|
nsGenericDOMDataNode::TextIsOnlyWhitespace()
|
|
{
|
|
// FIXME: should this method take content language into account?
|
|
if (mText.Is2b()) {
|
|
// The fragment contains non-8bit characters and such characters
|
|
// are never considered whitespace.
|
|
return false;
|
|
}
|
|
|
|
if (HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE)) {
|
|
return HasFlag(NS_TEXT_IS_ONLY_WHITESPACE);
|
|
}
|
|
|
|
const char* cp = mText.Get1b();
|
|
const char* end = cp + mText.GetLength();
|
|
|
|
while (cp < end) {
|
|
char ch = *cp;
|
|
|
|
if (!dom::IsSpaceCharacter(ch)) {
|
|
UnsetFlags(NS_TEXT_IS_ONLY_WHITESPACE);
|
|
SetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE);
|
|
return false;
|
|
}
|
|
|
|
++cp;
|
|
}
|
|
|
|
SetFlags(NS_CACHED_TEXT_IS_ONLY_WHITESPACE | NS_TEXT_IS_ONLY_WHITESPACE);
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
nsGenericDOMDataNode::HasTextForTranslation()
|
|
{
|
|
if (NodeType() != nsIDOMNode::TEXT_NODE &&
|
|
NodeType() != nsIDOMNode::CDATA_SECTION_NODE) {
|
|
return false;
|
|
}
|
|
|
|
if (mText.Is2b()) {
|
|
// The fragment contains non-8bit characters which means there
|
|
// was at least one "interesting" character to trigger non-8bit.
|
|
return true;
|
|
}
|
|
|
|
if (HasFlag(NS_CACHED_TEXT_IS_ONLY_WHITESPACE) &&
|
|
HasFlag(NS_TEXT_IS_ONLY_WHITESPACE)) {
|
|
return false;
|
|
}
|
|
|
|
const char* cp = mText.Get1b();
|
|
const char* end = cp + mText.GetLength();
|
|
|
|
unsigned char ch;
|
|
for (; cp < end; cp++) {
|
|
ch = *cp;
|
|
|
|
// These are the characters that are letters
|
|
// in the first 256 UTF-8 codepoints.
|
|
if ((ch >= 'a' && ch <= 'z') ||
|
|
(ch >= 'A' && ch <= 'Z') ||
|
|
(ch >= 192 && ch <= 214) ||
|
|
(ch >= 216 && ch <= 246) ||
|
|
(ch >= 248)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void
|
|
nsGenericDOMDataNode::AppendTextTo(nsAString& aResult)
|
|
{
|
|
mText.AppendTo(aResult);
|
|
}
|
|
|
|
bool
|
|
nsGenericDOMDataNode::AppendTextTo(nsAString& aResult,
|
|
const mozilla::fallible_t& aFallible)
|
|
{
|
|
return mText.AppendTo(aResult, aFallible);
|
|
}
|
|
|
|
already_AddRefed<nsIAtom>
|
|
nsGenericDOMDataNode::GetCurrentValueAtom()
|
|
{
|
|
nsAutoString val;
|
|
GetData(val);
|
|
return NS_Atomize(val);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsGenericDOMDataNode::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
|
|
{
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP_(bool)
|
|
nsGenericDOMDataNode::IsAttributeMapped(const nsIAtom* aAttribute) const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
nsChangeHint
|
|
nsGenericDOMDataNode::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
|
int32_t aModType) const
|
|
{
|
|
NS_NOTREACHED("Shouldn't be calling this!");
|
|
return nsChangeHint(0);
|
|
}
|
|
|
|
size_t
|
|
nsGenericDOMDataNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
|
{
|
|
size_t n = nsIContent::SizeOfExcludingThis(aMallocSizeOf);
|
|
n += mText.SizeOfExcludingThis(aMallocSizeOf);
|
|
return n;
|
|
}
|
|
|