content/base/public/FragmentOrElement.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 * Base class for all element classes as well as nsDocumentFragment. This
michael@0 8 * provides an implementation of nsIDOMNode, implements nsIContent, provides
michael@0 9 * utility methods for subclasses, and so forth.
michael@0 10 */
michael@0 11
michael@0 12 #ifndef FragmentOrElement_h___
michael@0 13 #define FragmentOrElement_h___
michael@0 14
michael@0 15 #include "mozilla/Attributes.h"
michael@0 16 #include "mozilla/MemoryReporting.h"
michael@0 17 #include "nsAttrAndChildArray.h" // member
michael@0 18 #include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_*
michael@0 19 #include "nsIContent.h" // base class
michael@0 20 #include "nsIDOMXPathNSResolver.h" // base class
michael@0 21 #include "nsINodeList.h" // base class
michael@0 22 #include "nsIWeakReference.h" // base class
michael@0 23 #include "nsNodeUtils.h" // class member nsNodeUtils::CloneNodeImpl
michael@0 24 #include "nsIHTMLCollection.h"
michael@0 25
michael@0 26 class ContentUnbinder;
michael@0 27 class nsContentList;
michael@0 28 class nsDOMAttributeMap;
michael@0 29 class nsDOMTokenList;
michael@0 30 class nsIControllers;
michael@0 31 class nsICSSDeclaration;
michael@0 32 class nsIDocument;
michael@0 33 class nsDOMStringMap;
michael@0 34 class nsINodeInfo;
michael@0 35 class nsIURI;
michael@0 36
michael@0 37 /**
michael@0 38 * Class that implements the nsIDOMNodeList interface (a list of children of
michael@0 39 * the content), by holding a reference to the content and delegating GetLength
michael@0 40 * and Item to its existing child list.
michael@0 41 * @see nsIDOMNodeList
michael@0 42 */
michael@0 43 class nsChildContentList MOZ_FINAL : public nsINodeList
michael@0 44 {
michael@0 45 public:
michael@0 46 nsChildContentList(nsINode* aNode)
michael@0 47 : mNode(aNode)
michael@0 48 {
michael@0 49 SetIsDOMBinding();
michael@0 50 }
michael@0 51
michael@0 52 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 53 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsChildContentList)
michael@0 54
michael@0 55 // nsWrapperCache
michael@0 56 virtual JSObject* WrapObject(JSContext *cx) MOZ_OVERRIDE;
michael@0 57
michael@0 58 // nsIDOMNodeList interface
michael@0 59 NS_DECL_NSIDOMNODELIST
michael@0 60
michael@0 61 // nsINodeList interface
michael@0 62 virtual int32_t IndexOf(nsIContent* aContent) MOZ_OVERRIDE;
michael@0 63 virtual nsIContent* Item(uint32_t aIndex) MOZ_OVERRIDE;
michael@0 64
michael@0 65 void DropReference()
michael@0 66 {
michael@0 67 mNode = nullptr;
michael@0 68 }
michael@0 69
michael@0 70 virtual nsINode* GetParentObject() MOZ_OVERRIDE
michael@0 71 {
michael@0 72 return mNode;
michael@0 73 }
michael@0 74
michael@0 75 private:
michael@0 76 // The node whose children make up the list (weak reference)
michael@0 77 nsINode* mNode;
michael@0 78 };
michael@0 79
michael@0 80 /**
michael@0 81 * A tearoff class for FragmentOrElement to implement additional interfaces
michael@0 82 */
michael@0 83 class nsNode3Tearoff : public nsIDOMXPathNSResolver
michael@0 84 {
michael@0 85 public:
michael@0 86 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 87
michael@0 88 NS_DECL_CYCLE_COLLECTION_CLASS(nsNode3Tearoff)
michael@0 89
michael@0 90 NS_DECL_NSIDOMXPATHNSRESOLVER
michael@0 91
michael@0 92 nsNode3Tearoff(nsINode *aNode) : mNode(aNode)
michael@0 93 {
michael@0 94 }
michael@0 95
michael@0 96 protected:
michael@0 97 virtual ~nsNode3Tearoff() {}
michael@0 98
michael@0 99 private:
michael@0 100 nsCOMPtr<nsINode> mNode;
michael@0 101 };
michael@0 102
michael@0 103 /**
michael@0 104 * A class that implements nsIWeakReference
michael@0 105 */
michael@0 106
michael@0 107 class nsNodeWeakReference MOZ_FINAL : public nsIWeakReference
michael@0 108 {
michael@0 109 public:
michael@0 110 nsNodeWeakReference(nsINode* aNode)
michael@0 111 : mNode(aNode)
michael@0 112 {
michael@0 113 }
michael@0 114
michael@0 115 ~nsNodeWeakReference();
michael@0 116
michael@0 117 // nsISupports
michael@0 118 NS_DECL_ISUPPORTS
michael@0 119
michael@0 120 // nsIWeakReference
michael@0 121 NS_DECL_NSIWEAKREFERENCE
michael@0 122
michael@0 123 void NoticeNodeDestruction()
michael@0 124 {
michael@0 125 mNode = nullptr;
michael@0 126 }
michael@0 127
michael@0 128 private:
michael@0 129 nsINode* mNode;
michael@0 130 };
michael@0 131
michael@0 132 /**
michael@0 133 * Tearoff to use for nodes to implement nsISupportsWeakReference
michael@0 134 */
michael@0 135 class nsNodeSupportsWeakRefTearoff MOZ_FINAL : public nsISupportsWeakReference
michael@0 136 {
michael@0 137 public:
michael@0 138 nsNodeSupportsWeakRefTearoff(nsINode* aNode)
michael@0 139 : mNode(aNode)
michael@0 140 {
michael@0 141 }
michael@0 142
michael@0 143 // nsISupports
michael@0 144 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 145
michael@0 146 // nsISupportsWeakReference
michael@0 147 NS_DECL_NSISUPPORTSWEAKREFERENCE
michael@0 148
michael@0 149 NS_DECL_CYCLE_COLLECTION_CLASS(nsNodeSupportsWeakRefTearoff)
michael@0 150
michael@0 151 private:
michael@0 152 nsCOMPtr<nsINode> mNode;
michael@0 153 };
michael@0 154
michael@0 155 /**
michael@0 156 * A generic base class for DOM elements, implementing many nsIContent,
michael@0 157 * nsIDOMNode and nsIDOMElement methods.
michael@0 158 */
michael@0 159 namespace mozilla {
michael@0 160 namespace dom {
michael@0 161
michael@0 162 class ShadowRoot;
michael@0 163 class UndoManager;
michael@0 164
michael@0 165 class FragmentOrElement : public nsIContent
michael@0 166 {
michael@0 167 public:
michael@0 168 FragmentOrElement(already_AddRefed<nsINodeInfo>& aNodeInfo);
michael@0 169 FragmentOrElement(already_AddRefed<nsINodeInfo>&& aNodeInfo);
michael@0 170 virtual ~FragmentOrElement();
michael@0 171
michael@0 172 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 173
michael@0 174 NS_DECL_SIZEOF_EXCLUDING_THIS
michael@0 175
michael@0 176 // nsINode interface methods
michael@0 177 virtual uint32_t GetChildCount() const MOZ_OVERRIDE;
michael@0 178 virtual nsIContent *GetChildAt(uint32_t aIndex) const MOZ_OVERRIDE;
michael@0 179 virtual nsIContent * const * GetChildArray(uint32_t* aChildCount) const MOZ_OVERRIDE;
michael@0 180 virtual int32_t IndexOf(const nsINode* aPossibleChild) const MOZ_OVERRIDE;
michael@0 181 virtual nsresult InsertChildAt(nsIContent* aKid, uint32_t aIndex,
michael@0 182 bool aNotify) MOZ_OVERRIDE;
michael@0 183 virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) MOZ_OVERRIDE;
michael@0 184 virtual void GetTextContentInternal(nsAString& aTextContent) MOZ_OVERRIDE;
michael@0 185 virtual void SetTextContentInternal(const nsAString& aTextContent,
michael@0 186 mozilla::ErrorResult& aError) MOZ_OVERRIDE;
michael@0 187
michael@0 188 // nsIContent interface methods
michael@0 189 virtual already_AddRefed<nsINodeList> GetChildren(uint32_t aFilter) MOZ_OVERRIDE;
michael@0 190 virtual const nsTextFragment *GetText() MOZ_OVERRIDE;
michael@0 191 virtual uint32_t TextLength() const MOZ_OVERRIDE;
michael@0 192 virtual nsresult SetText(const char16_t* aBuffer, uint32_t aLength,
michael@0 193 bool aNotify) MOZ_OVERRIDE;
michael@0 194 // Need to implement this here too to avoid hiding.
michael@0 195 nsresult SetText(const nsAString& aStr, bool aNotify)
michael@0 196 {
michael@0 197 return SetText(aStr.BeginReading(), aStr.Length(), aNotify);
michael@0 198 }
michael@0 199 virtual nsresult AppendText(const char16_t* aBuffer, uint32_t aLength,
michael@0 200 bool aNotify) MOZ_OVERRIDE;
michael@0 201 virtual bool TextIsOnlyWhitespace() MOZ_OVERRIDE;
michael@0 202 virtual bool HasTextForTranslation() MOZ_OVERRIDE;
michael@0 203 virtual void AppendTextTo(nsAString& aResult) MOZ_OVERRIDE;
michael@0 204 virtual bool AppendTextTo(nsAString& aResult,
michael@0 205 const mozilla::fallible_t&) MOZ_OVERRIDE NS_WARN_UNUSED_RESULT;
michael@0 206 virtual nsIContent *GetBindingParent() const MOZ_OVERRIDE;
michael@0 207 virtual nsXBLBinding *GetXBLBinding() const MOZ_OVERRIDE;
michael@0 208 virtual void SetXBLBinding(nsXBLBinding* aBinding,
michael@0 209 nsBindingManager* aOldBindingManager = nullptr) MOZ_OVERRIDE;
michael@0 210 virtual ShadowRoot *GetShadowRoot() const MOZ_OVERRIDE;
michael@0 211 virtual ShadowRoot *GetContainingShadow() const MOZ_OVERRIDE;
michael@0 212 virtual void SetShadowRoot(ShadowRoot* aBinding) MOZ_OVERRIDE;
michael@0 213 virtual nsIContent *GetXBLInsertionParent() const MOZ_OVERRIDE;
michael@0 214 virtual void SetXBLInsertionParent(nsIContent* aContent) MOZ_OVERRIDE;
michael@0 215 virtual bool IsLink(nsIURI** aURI) const MOZ_OVERRIDE;
michael@0 216
michael@0 217 virtual CustomElementData *GetCustomElementData() const MOZ_OVERRIDE;
michael@0 218 virtual void SetCustomElementData(CustomElementData* aData) MOZ_OVERRIDE;
michael@0 219
michael@0 220 virtual void DestroyContent() MOZ_OVERRIDE;
michael@0 221 virtual void SaveSubtreeState() MOZ_OVERRIDE;
michael@0 222
michael@0 223 virtual const nsAttrValue* DoGetClasses() const MOZ_OVERRIDE;
michael@0 224 NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) MOZ_OVERRIDE;
michael@0 225
michael@0 226 nsIHTMLCollection* Children();
michael@0 227 uint32_t ChildElementCount()
michael@0 228 {
michael@0 229 return Children()->Length();
michael@0 230 }
michael@0 231
michael@0 232 public:
michael@0 233 /**
michael@0 234 * If there are listeners for DOMNodeInserted event, fires the event on all
michael@0 235 * aNodes
michael@0 236 */
michael@0 237 static void FireNodeInserted(nsIDocument* aDoc,
michael@0 238 nsINode* aParent,
michael@0 239 nsTArray<nsCOMPtr<nsIContent> >& aNodes);
michael@0 240
michael@0 241 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(FragmentOrElement)
michael@0 242
michael@0 243 /**
michael@0 244 * Fire a DOMNodeRemoved mutation event for all children of this node
michael@0 245 */
michael@0 246 void FireNodeRemovedForChildren();
michael@0 247
michael@0 248 virtual bool OwnedOnlyByTheDOMTree() MOZ_OVERRIDE
michael@0 249 {
michael@0 250 uint32_t rc = mRefCnt.get();
michael@0 251 if (GetParent()) {
michael@0 252 --rc;
michael@0 253 }
michael@0 254 rc -= mAttrsAndChildren.ChildCount();
michael@0 255 return rc == 0;
michael@0 256 }
michael@0 257
michael@0 258 virtual bool IsPurple() MOZ_OVERRIDE
michael@0 259 {
michael@0 260 return mRefCnt.IsPurple();
michael@0 261 }
michael@0 262
michael@0 263 virtual void RemovePurple() MOZ_OVERRIDE
michael@0 264 {
michael@0 265 mRefCnt.RemovePurple();
michael@0 266 }
michael@0 267
michael@0 268 static void ClearContentUnbinder();
michael@0 269 static bool CanSkip(nsINode* aNode, bool aRemovingAllowed);
michael@0 270 static bool CanSkipInCC(nsINode* aNode);
michael@0 271 static bool CanSkipThis(nsINode* aNode);
michael@0 272 static void RemoveBlackMarkedNode(nsINode* aNode);
michael@0 273 static void MarkNodeChildren(nsINode* aNode);
michael@0 274 static void InitCCCallbacks();
michael@0 275 static void MarkUserData(void* aObject, nsIAtom* aKey, void* aChild,
michael@0 276 void *aData);
michael@0 277 static void MarkUserDataHandler(void* aObject, nsIAtom* aKey, void* aChild,
michael@0 278 void* aData);
michael@0 279
michael@0 280 protected:
michael@0 281 /**
michael@0 282 * Copy attributes and state to another element
michael@0 283 * @param aDest the object to copy to
michael@0 284 */
michael@0 285 nsresult CopyInnerTo(FragmentOrElement* aDest);
michael@0 286
michael@0 287 public:
michael@0 288 // Because of a bug in MS C++ compiler nsDOMSlots must be declared public,
michael@0 289 // otherwise nsXULElement::nsXULSlots doesn't compile.
michael@0 290 /**
michael@0 291 * There are a set of DOM- and scripting-specific instance variables
michael@0 292 * that may only be instantiated when a content object is accessed
michael@0 293 * through the DOM. Rather than burn actual slots in the content
michael@0 294 * objects for each of these instance variables, we put them off
michael@0 295 * in a side structure that's only allocated when the content is
michael@0 296 * accessed through the DOM.
michael@0 297 */
michael@0 298 class nsDOMSlots : public nsINode::nsSlots
michael@0 299 {
michael@0 300 public:
michael@0 301 nsDOMSlots();
michael@0 302 virtual ~nsDOMSlots();
michael@0 303
michael@0 304 void Traverse(nsCycleCollectionTraversalCallback &cb, bool aIsXUL);
michael@0 305 void Unlink(bool aIsXUL);
michael@0 306
michael@0 307 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
michael@0 308
michael@0 309 /**
michael@0 310 * The .style attribute (an interface that forwards to the actual
michael@0 311 * style rules)
michael@0 312 * @see nsGenericHTMLElement::GetStyle
michael@0 313 */
michael@0 314 nsCOMPtr<nsICSSDeclaration> mStyle;
michael@0 315
michael@0 316 /**
michael@0 317 * The .dataset attribute.
michael@0 318 * @see nsGenericHTMLElement::GetDataset
michael@0 319 */
michael@0 320 nsDOMStringMap* mDataset; // [Weak]
michael@0 321
michael@0 322 /**
michael@0 323 * The .undoManager property.
michael@0 324 * @see nsGenericHTMLElement::GetUndoManager
michael@0 325 */
michael@0 326 nsRefPtr<UndoManager> mUndoManager;
michael@0 327
michael@0 328 /**
michael@0 329 * SMIL Overridde style rules (for SMIL animation of CSS properties)
michael@0 330 * @see nsIContent::GetSMILOverrideStyle
michael@0 331 */
michael@0 332 nsCOMPtr<nsICSSDeclaration> mSMILOverrideStyle;
michael@0 333
michael@0 334 /**
michael@0 335 * Holds any SMIL override style rules for this element.
michael@0 336 */
michael@0 337 nsRefPtr<mozilla::css::StyleRule> mSMILOverrideStyleRule;
michael@0 338
michael@0 339 /**
michael@0 340 * An object implementing nsIDOMMozNamedAttrMap for this content (attributes)
michael@0 341 * @see FragmentOrElement::GetAttributes
michael@0 342 */
michael@0 343 nsRefPtr<nsDOMAttributeMap> mAttributeMap;
michael@0 344
michael@0 345 union {
michael@0 346 /**
michael@0 347 * The nearest enclosing content node with a binding that created us.
michael@0 348 * @see FragmentOrElement::GetBindingParent
michael@0 349 */
michael@0 350 nsIContent* mBindingParent; // [Weak]
michael@0 351
michael@0 352 /**
michael@0 353 * The controllers of the XUL Element.
michael@0 354 */
michael@0 355 nsIControllers* mControllers; // [OWNER]
michael@0 356 };
michael@0 357
michael@0 358 /**
michael@0 359 * An object implementing the .children property for this element.
michael@0 360 */
michael@0 361 nsRefPtr<nsContentList> mChildrenList;
michael@0 362
michael@0 363 /**
michael@0 364 * An object implementing the .classList property for this element.
michael@0 365 */
michael@0 366 nsRefPtr<nsDOMTokenList> mClassList;
michael@0 367
michael@0 368 /**
michael@0 369 * ShadowRoot bound to the element.
michael@0 370 */
michael@0 371 nsRefPtr<ShadowRoot> mShadowRoot;
michael@0 372
michael@0 373 /**
michael@0 374 * The root ShadowRoot of this element if it is in a shadow tree.
michael@0 375 */
michael@0 376 nsRefPtr<ShadowRoot> mContainingShadow;
michael@0 377
michael@0 378 /**
michael@0 379 * XBL binding installed on the element.
michael@0 380 */
michael@0 381 nsRefPtr<nsXBLBinding> mXBLBinding;
michael@0 382
michael@0 383 /**
michael@0 384 * XBL binding installed on the lement.
michael@0 385 */
michael@0 386 nsCOMPtr<nsIContent> mXBLInsertionParent;
michael@0 387
michael@0 388 /**
michael@0 389 * Web components custom element data.
michael@0 390 */
michael@0 391 nsAutoPtr<CustomElementData> mCustomElementData;
michael@0 392 };
michael@0 393
michael@0 394 protected:
michael@0 395 void GetMarkup(bool aIncludeSelf, nsAString& aMarkup);
michael@0 396 void SetInnerHTMLInternal(const nsAString& aInnerHTML, ErrorResult& aError);
michael@0 397
michael@0 398 // Override from nsINode
michael@0 399 virtual nsINode::nsSlots* CreateSlots() MOZ_OVERRIDE;
michael@0 400
michael@0 401 nsDOMSlots *DOMSlots()
michael@0 402 {
michael@0 403 return static_cast<nsDOMSlots*>(Slots());
michael@0 404 }
michael@0 405
michael@0 406 nsDOMSlots *GetExistingDOMSlots() const
michael@0 407 {
michael@0 408 return static_cast<nsDOMSlots*>(GetExistingSlots());
michael@0 409 }
michael@0 410
michael@0 411 friend class ::ContentUnbinder;
michael@0 412 /**
michael@0 413 * Array containing all attributes and children for this element
michael@0 414 */
michael@0 415 nsAttrAndChildArray mAttrsAndChildren;
michael@0 416 };
michael@0 417
michael@0 418 } // namespace dom
michael@0 419 } // namespace mozilla
michael@0 420
michael@0 421 #define NS_ELEMENT_INTERFACE_TABLE_TO_MAP_SEGUE \
michael@0 422 if (NS_SUCCEEDED(rv)) \
michael@0 423 return rv; \
michael@0 424 \
michael@0 425 rv = FragmentOrElement::QueryInterface(aIID, aInstancePtr); \
michael@0 426 NS_INTERFACE_TABLE_TO_MAP_SEGUE
michael@0 427
michael@0 428 #endif /* FragmentOrElement_h___ */

mercurial