content/base/src/nsGenericDOMDataNode.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 DOM Core's nsIDOMComment, nsIDOMDocumentType, nsIDOMText,
michael@0 8 * nsIDOMCDATASection, and nsIDOMProcessingInstruction nodes.
michael@0 9 */
michael@0 10
michael@0 11 #ifndef nsGenericDOMDataNode_h___
michael@0 12 #define nsGenericDOMDataNode_h___
michael@0 13
michael@0 14 #include "mozilla/Attributes.h"
michael@0 15 #include "nsIContent.h"
michael@0 16
michael@0 17 #include "nsTextFragment.h"
michael@0 18 #include "nsError.h"
michael@0 19 #include "mozilla/dom/Element.h"
michael@0 20 #include "nsCycleCollectionParticipant.h"
michael@0 21
michael@0 22 #include "nsISMILAttr.h"
michael@0 23 #include "nsIDocument.h"
michael@0 24
michael@0 25 class nsIDOMAttr;
michael@0 26 class nsIDOMEventListener;
michael@0 27 class nsIDOMNodeList;
michael@0 28 class nsIFrame;
michael@0 29 class nsIDOMText;
michael@0 30 class nsINodeInfo;
michael@0 31 class nsURI;
michael@0 32
michael@0 33 #define DATA_NODE_FLAG_BIT(n_) NODE_FLAG_BIT(NODE_TYPE_SPECIFIC_BITS_OFFSET + (n_))
michael@0 34
michael@0 35 // Data node specific flags
michael@0 36 enum {
michael@0 37 // This bit is set to indicate that if the text node changes to
michael@0 38 // non-whitespace, we may need to create a frame for it. This bit must
michael@0 39 // not be set on nodes that already have a frame.
michael@0 40 NS_CREATE_FRAME_IF_NON_WHITESPACE = DATA_NODE_FLAG_BIT(0),
michael@0 41
michael@0 42 // This bit is set to indicate that if the text node changes to
michael@0 43 // whitespace, we may need to reframe it (or its ancestors).
michael@0 44 NS_REFRAME_IF_WHITESPACE = DATA_NODE_FLAG_BIT(1),
michael@0 45
michael@0 46 // This bit is set to indicate that we have a cached
michael@0 47 // TextIsOnlyWhitespace value
michael@0 48 NS_CACHED_TEXT_IS_ONLY_WHITESPACE = DATA_NODE_FLAG_BIT(2),
michael@0 49
michael@0 50 // This bit is only meaningful if the NS_CACHED_TEXT_IS_ONLY_WHITESPACE
michael@0 51 // bit is set, and if so it indicates whether we're only whitespace or
michael@0 52 // not.
michael@0 53 NS_TEXT_IS_ONLY_WHITESPACE = DATA_NODE_FLAG_BIT(3),
michael@0 54 };
michael@0 55
michael@0 56 // Make sure we have enough space for those bits
michael@0 57 ASSERT_NODE_FLAGS_SPACE(NODE_TYPE_SPECIFIC_BITS_OFFSET + 4);
michael@0 58
michael@0 59 #undef DATA_NODE_FLAG_BIT
michael@0 60
michael@0 61 class nsGenericDOMDataNode : public nsIContent
michael@0 62 {
michael@0 63 public:
michael@0 64 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 65
michael@0 66 NS_DECL_SIZEOF_EXCLUDING_THIS
michael@0 67
michael@0 68 nsGenericDOMDataNode(already_AddRefed<nsINodeInfo>& aNodeInfo);
michael@0 69 nsGenericDOMDataNode(already_AddRefed<nsINodeInfo>&& aNodeInfo);
michael@0 70 virtual ~nsGenericDOMDataNode();
michael@0 71
michael@0 72 virtual void GetNodeValueInternal(nsAString& aNodeValue) MOZ_OVERRIDE;
michael@0 73 virtual void SetNodeValueInternal(const nsAString& aNodeValue,
michael@0 74 mozilla::ErrorResult& aError) MOZ_OVERRIDE;
michael@0 75
michael@0 76 // Implementation for nsIDOMCharacterData
michael@0 77 nsresult GetData(nsAString& aData) const;
michael@0 78 nsresult SetData(const nsAString& aData);
michael@0 79 nsresult GetLength(uint32_t* aLength);
michael@0 80 nsresult SubstringData(uint32_t aOffset, uint32_t aCount,
michael@0 81 nsAString& aReturn);
michael@0 82 nsresult AppendData(const nsAString& aArg);
michael@0 83 nsresult InsertData(uint32_t aOffset, const nsAString& aArg);
michael@0 84 nsresult DeleteData(uint32_t aOffset, uint32_t aCount);
michael@0 85 nsresult ReplaceData(uint32_t aOffset, uint32_t aCount,
michael@0 86 const nsAString& aArg);
michael@0 87 NS_IMETHOD MozRemove();
michael@0 88
michael@0 89 // nsINode methods
michael@0 90 virtual uint32_t GetChildCount() const MOZ_OVERRIDE;
michael@0 91 virtual nsIContent *GetChildAt(uint32_t aIndex) const MOZ_OVERRIDE;
michael@0 92 virtual nsIContent * const * GetChildArray(uint32_t* aChildCount) const MOZ_OVERRIDE;
michael@0 93 virtual int32_t IndexOf(const nsINode* aPossibleChild) const MOZ_OVERRIDE;
michael@0 94 virtual nsresult InsertChildAt(nsIContent* aKid, uint32_t aIndex,
michael@0 95 bool aNotify) MOZ_OVERRIDE;
michael@0 96 virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) MOZ_OVERRIDE;
michael@0 97 virtual void GetTextContentInternal(nsAString& aTextContent) MOZ_OVERRIDE
michael@0 98 {
michael@0 99 GetNodeValue(aTextContent);
michael@0 100 }
michael@0 101 virtual void SetTextContentInternal(const nsAString& aTextContent,
michael@0 102 mozilla::ErrorResult& aError) MOZ_OVERRIDE
michael@0 103 {
michael@0 104 // Batch possible DOMSubtreeModified events.
michael@0 105 mozAutoSubtreeModified subtree(OwnerDoc(), nullptr);
michael@0 106 return SetNodeValue(aTextContent, aError);
michael@0 107 }
michael@0 108
michael@0 109 // Implementation for nsIContent
michael@0 110 virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
michael@0 111 nsIContent* aBindingParent,
michael@0 112 bool aCompileEventHandlers) MOZ_OVERRIDE;
michael@0 113 virtual void UnbindFromTree(bool aDeep = true,
michael@0 114 bool aNullParent = true) MOZ_OVERRIDE;
michael@0 115
michael@0 116 virtual already_AddRefed<nsINodeList> GetChildren(uint32_t aFilter) MOZ_OVERRIDE;
michael@0 117
michael@0 118 virtual nsIAtom *GetIDAttributeName() const MOZ_OVERRIDE;
michael@0 119
michael@0 120 nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
michael@0 121 const nsAString& aValue, bool aNotify)
michael@0 122 {
michael@0 123 return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
michael@0 124 }
michael@0 125 virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
michael@0 126 nsIAtom* aPrefix, const nsAString& aValue,
michael@0 127 bool aNotify) MOZ_OVERRIDE;
michael@0 128 virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
michael@0 129 bool aNotify) MOZ_OVERRIDE;
michael@0 130 virtual const nsAttrName* GetAttrNameAt(uint32_t aIndex) const MOZ_OVERRIDE;
michael@0 131 virtual uint32_t GetAttrCount() const MOZ_OVERRIDE;
michael@0 132 virtual const nsTextFragment *GetText() MOZ_OVERRIDE;
michael@0 133 virtual uint32_t TextLength() const MOZ_OVERRIDE;
michael@0 134 virtual nsresult SetText(const char16_t* aBuffer, uint32_t aLength,
michael@0 135 bool aNotify) MOZ_OVERRIDE;
michael@0 136 // Need to implement this here too to avoid hiding.
michael@0 137 nsresult SetText(const nsAString& aStr, bool aNotify)
michael@0 138 {
michael@0 139 return SetText(aStr.BeginReading(), aStr.Length(), aNotify);
michael@0 140 }
michael@0 141 virtual nsresult AppendText(const char16_t* aBuffer, uint32_t aLength,
michael@0 142 bool aNotify) MOZ_OVERRIDE;
michael@0 143 virtual bool TextIsOnlyWhitespace() MOZ_OVERRIDE;
michael@0 144 virtual bool HasTextForTranslation() MOZ_OVERRIDE;
michael@0 145 virtual void AppendTextTo(nsAString& aResult) MOZ_OVERRIDE;
michael@0 146 virtual bool AppendTextTo(nsAString& aResult,
michael@0 147 const mozilla::fallible_t&) MOZ_OVERRIDE NS_WARN_UNUSED_RESULT;
michael@0 148 virtual void DestroyContent() MOZ_OVERRIDE;
michael@0 149 virtual void SaveSubtreeState() MOZ_OVERRIDE;
michael@0 150
michael@0 151 #ifdef DEBUG
michael@0 152 virtual void List(FILE* out, int32_t aIndent) const MOZ_OVERRIDE;
michael@0 153 virtual void DumpContent(FILE* out, int32_t aIndent, bool aDumpAll) const MOZ_OVERRIDE;
michael@0 154 #endif
michael@0 155
michael@0 156 virtual nsIContent *GetBindingParent() const MOZ_OVERRIDE;
michael@0 157 virtual nsXBLBinding *GetXBLBinding() const MOZ_OVERRIDE;
michael@0 158 virtual void SetXBLBinding(nsXBLBinding* aBinding,
michael@0 159 nsBindingManager* aOldBindingManager = nullptr) MOZ_OVERRIDE;
michael@0 160 virtual mozilla::dom::ShadowRoot *GetContainingShadow() const MOZ_OVERRIDE;
michael@0 161 virtual mozilla::dom::ShadowRoot *GetShadowRoot() const MOZ_OVERRIDE;
michael@0 162 virtual void SetShadowRoot(mozilla::dom::ShadowRoot* aShadowRoot) MOZ_OVERRIDE;
michael@0 163 virtual nsIContent *GetXBLInsertionParent() const MOZ_OVERRIDE;
michael@0 164 virtual void SetXBLInsertionParent(nsIContent* aContent) MOZ_OVERRIDE;
michael@0 165 virtual bool IsNodeOfType(uint32_t aFlags) const MOZ_OVERRIDE;
michael@0 166 virtual bool IsLink(nsIURI** aURI) const MOZ_OVERRIDE;
michael@0 167
michael@0 168 virtual mozilla::dom::CustomElementData* GetCustomElementData() const MOZ_OVERRIDE;
michael@0 169 virtual void SetCustomElementData(mozilla::dom::CustomElementData* aData) MOZ_OVERRIDE;
michael@0 170
michael@0 171 virtual nsIAtom* DoGetID() const MOZ_OVERRIDE;
michael@0 172 virtual const nsAttrValue* DoGetClasses() const MOZ_OVERRIDE;
michael@0 173 NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) MOZ_OVERRIDE;
michael@0 174 NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
michael@0 175 virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
michael@0 176 int32_t aModType) const;
michael@0 177 virtual nsIAtom *GetClassAttributeName() const;
michael@0 178
michael@0 179 virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE
michael@0 180 {
michael@0 181 *aResult = CloneDataNode(aNodeInfo, true);
michael@0 182 if (!*aResult) {
michael@0 183 return NS_ERROR_OUT_OF_MEMORY;
michael@0 184 }
michael@0 185
michael@0 186 NS_ADDREF(*aResult);
michael@0 187
michael@0 188 return NS_OK;
michael@0 189 }
michael@0 190
michael@0 191 nsresult SplitData(uint32_t aOffset, nsIContent** aReturn,
michael@0 192 bool aCloneAfterOriginal = true);
michael@0 193
michael@0 194 // WebIDL API
michael@0 195 // Our XPCOM GetData is just fine for WebIDL
michael@0 196 virtual void SetData(const nsAString& aData, mozilla::ErrorResult& rv)
michael@0 197 {
michael@0 198 rv = SetData(aData);
michael@0 199 }
michael@0 200 // nsINode::Length() returns the right thing for our length attribute
michael@0 201 void SubstringData(uint32_t aStart, uint32_t aCount, nsAString& aReturn,
michael@0 202 mozilla::ErrorResult& rv);
michael@0 203 void AppendData(const nsAString& aData, mozilla::ErrorResult& rv)
michael@0 204 {
michael@0 205 rv = AppendData(aData);
michael@0 206 }
michael@0 207 void InsertData(uint32_t aOffset, const nsAString& aData,
michael@0 208 mozilla::ErrorResult& rv)
michael@0 209 {
michael@0 210 rv = InsertData(aOffset, aData);
michael@0 211 }
michael@0 212 void DeleteData(uint32_t aOffset, uint32_t aCount, mozilla::ErrorResult& rv)
michael@0 213 {
michael@0 214 rv = DeleteData(aOffset, aCount);
michael@0 215 }
michael@0 216 void ReplaceData(uint32_t aOffset, uint32_t aCount, const nsAString& aData,
michael@0 217 mozilla::ErrorResult& rv)
michael@0 218 {
michael@0 219 rv = ReplaceData(aOffset, aCount, aData);
michael@0 220 }
michael@0 221
michael@0 222 //----------------------------------------
michael@0 223
michael@0 224 #ifdef DEBUG
michael@0 225 void ToCString(nsAString& aBuf, int32_t aOffset, int32_t aLen) const;
michael@0 226 #endif
michael@0 227
michael@0 228 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsGenericDOMDataNode)
michael@0 229
michael@0 230 protected:
michael@0 231 virtual mozilla::dom::Element* GetNameSpaceElement()
michael@0 232 {
michael@0 233 nsINode *parent = GetParentNode();
michael@0 234
michael@0 235 return parent && parent->IsElement() ? parent->AsElement() : nullptr;
michael@0 236 }
michael@0 237
michael@0 238 /**
michael@0 239 * There are a set of DOM- and scripting-specific instance variables
michael@0 240 * that may only be instantiated when a content object is accessed
michael@0 241 * through the DOM. Rather than burn actual slots in the content
michael@0 242 * objects for each of these instance variables, we put them off
michael@0 243 * in a side structure that's only allocated when the content is
michael@0 244 * accessed through the DOM.
michael@0 245 */
michael@0 246 class nsDataSlots : public nsINode::nsSlots
michael@0 247 {
michael@0 248 public:
michael@0 249 nsDataSlots();
michael@0 250
michael@0 251 void Traverse(nsCycleCollectionTraversalCallback &cb);
michael@0 252 void Unlink();
michael@0 253
michael@0 254 /**
michael@0 255 * The nearest enclosing content node with a binding that created us.
michael@0 256 * @see nsIContent::GetBindingParent
michael@0 257 */
michael@0 258 nsIContent* mBindingParent; // [Weak]
michael@0 259
michael@0 260 /**
michael@0 261 * @see nsIContent::GetXBLInsertionParent
michael@0 262 */
michael@0 263 nsCOMPtr<nsIContent> mXBLInsertionParent;
michael@0 264
michael@0 265 /**
michael@0 266 * @see nsIContent::GetContainingShadow
michael@0 267 */
michael@0 268 nsRefPtr<mozilla::dom::ShadowRoot> mContainingShadow;
michael@0 269 };
michael@0 270
michael@0 271 // Override from nsINode
michael@0 272 virtual nsINode::nsSlots* CreateSlots() MOZ_OVERRIDE;
michael@0 273
michael@0 274 nsDataSlots* DataSlots()
michael@0 275 {
michael@0 276 return static_cast<nsDataSlots*>(Slots());
michael@0 277 }
michael@0 278
michael@0 279 nsDataSlots *GetExistingDataSlots() const
michael@0 280 {
michael@0 281 return static_cast<nsDataSlots*>(GetExistingSlots());
michael@0 282 }
michael@0 283
michael@0 284 nsresult SplitText(uint32_t aOffset, nsIDOMText** aReturn);
michael@0 285
michael@0 286 nsresult GetWholeText(nsAString& aWholeText);
michael@0 287
michael@0 288 static int32_t FirstLogicallyAdjacentTextNode(nsIContent* aParent,
michael@0 289 int32_t aIndex);
michael@0 290
michael@0 291 static int32_t LastLogicallyAdjacentTextNode(nsIContent* aParent,
michael@0 292 int32_t aIndex,
michael@0 293 uint32_t aCount);
michael@0 294
michael@0 295 nsresult SetTextInternal(uint32_t aOffset, uint32_t aCount,
michael@0 296 const char16_t* aBuffer, uint32_t aLength,
michael@0 297 bool aNotify,
michael@0 298 CharacterDataChangeInfo::Details* aDetails = nullptr);
michael@0 299
michael@0 300 /**
michael@0 301 * Method to clone this node. This needs to be overriden by all derived
michael@0 302 * classes. If aCloneText is true the text content will be cloned too.
michael@0 303 *
michael@0 304 * @param aOwnerDocument the ownerDocument of the clone
michael@0 305 * @param aCloneText if true the text content will be cloned too
michael@0 306 * @return the clone
michael@0 307 */
michael@0 308 virtual nsGenericDOMDataNode *CloneDataNode(nsINodeInfo *aNodeInfo,
michael@0 309 bool aCloneText) const = 0;
michael@0 310
michael@0 311 nsTextFragment mText;
michael@0 312
michael@0 313 public:
michael@0 314 virtual bool OwnedOnlyByTheDOMTree() MOZ_OVERRIDE
michael@0 315 {
michael@0 316 return GetParent() && mRefCnt.get() == 1;
michael@0 317 }
michael@0 318
michael@0 319 virtual bool IsPurple() MOZ_OVERRIDE
michael@0 320 {
michael@0 321 return mRefCnt.IsPurple();
michael@0 322 }
michael@0 323 virtual void RemovePurple() MOZ_OVERRIDE
michael@0 324 {
michael@0 325 mRefCnt.RemovePurple();
michael@0 326 }
michael@0 327
michael@0 328 private:
michael@0 329 already_AddRefed<nsIAtom> GetCurrentValueAtom();
michael@0 330 };
michael@0 331
michael@0 332 #endif /* nsGenericDOMDataNode_h___ */

mercurial