diff --git a/layout/base/public/nsContentPolicyUtils.h b/layout/base/public/nsContentPolicyUtils.h deleted file mode 100644 index ec557ba5528e..000000000000 --- a/layout/base/public/nsContentPolicyUtils.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla code. - * - * The Initial Developer of the Original Code is Zero-Knowledge Systems, - * Inc. Portions created by Zero-Knowledge are Copyright (C) 2000 - * Zero-Knowledge Systems, Inc. All Rights Reserved. - * - * Contributor(s): - */ - -/* - * Utility routines for checking content load/process policy settings. - */ - -#include "nsString.h" -#include "nsIContentPolicy.h" -#include "nsIMemory.h" -#include "nsIServiceManager.h" - -#ifndef __nsContentPolicyUtils_h__ -#define __nsContentPolicyUtils_h__ - -class nsIDOMElement; - -#define NS_CONTENTPOLICY_CONTRACTID "@mozilla.org/layout/content-policy;1" -#define NS_CONTENTPOLICY_CATEGORY "content-policy" -#define NS_CONTENTPOLICY_CID \ - {0x0e3afd3d, 0xeb60, 0x4c2b, \ - { 0x96, 0x3b, 0x56, 0xd7, 0xc4, 0x39, 0xf1, 0x24 }} - -/* takes contentType, aURL, and element from its context */ -#define CHECK_CONTENT_POLICY(action, result) \ -PR_BEGIN_MACRO \ - nsresult rv; \ - NS_WITH_SERVICE(nsIContentPolicy, policy, NS_CONTENTPOLICY_CONTRACTID, &rv); \ - if (NS_FAILED(rv)) \ - return rv; \ - \ - return policy->##action(contentType, element, aURL.GetUnicode(), result); \ -PR_END_MACRO - -inline nsresult -NS_CheckContentLoadPolicy(PRInt32 contentType, const nsString &aURL, - nsIDOMElement *element, PRBool *shouldLoad) -{ - CHECK_CONTENT_POLICY(ShouldLoad, shouldLoad); -} - -inline nsresult -NS_CheckContentProcessPolicy(PRInt32 contentType, nsString &aURL, - nsIDOMElement *element, PRBool *shouldProcess) -{ - CHECK_CONTENT_POLICY(ShouldProcess, shouldProcess); -} - -#undef CHECK_CONTENT_POLICY - -#endif /* __nsContentPolicyUtils_h__ */ diff --git a/layout/base/public/nsIAnonymousContent.h b/layout/base/public/nsIAnonymousContent.h deleted file mode 100644 index 91e1b93fae4a..000000000000 --- a/layout/base/public/nsIAnonymousContent.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - - -#ifndef nsIAnonymousContent_h___ -#define nsIAnonymousContent_h___ - -#include "nsISupports.h" -#include "nsIContent.h" -#include "nsCOMPtr.h" - -class nsISupportsArray; -class nsIAtom; - -#define NS_IANONYMOUS_CONTENT_IID { 0x41a69e00, 0x2d6d, 0x12d3, { 0xb0, 0x33, 0xa1, 0x38, 0x71, 0x39, 0x78, 0x7c } } - - -/** - * If a node is anonymous. Then it should implement this interface. - */ -class nsIAnonymousContent : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_IANONYMOUS_CONTENT_IID; return iid; } -}; - -#endif - diff --git a/layout/base/public/nsIContent.h b/layout/base/public/nsIContent.h deleted file mode 100644 index be917981ab86..000000000000 --- a/layout/base/public/nsIContent.h +++ /dev/null @@ -1,308 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsIContent_h___ -#define nsIContent_h___ - -#include -#include "nslayout.h" -#include "nsISupports.h" -#include "nsGUIEvent.h" -#include "nsAWritableString.h" - -// Forward declarations -class nsIAtom; -class nsIDocument; -class nsIPresContext; -class nsVoidArray; -class nsIDOMEvent; -class nsIContent; -class nsISupportsArray; -class nsIDOMRange; -class nsISizeOfHandler; -class nsINodeInfo; - -// IID for the nsIContent interface -#define NS_ICONTENT_IID \ -{ 0x78030220, 0x9447, 0x11d1, \ - {0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } - -// A node of content in a documents content model. This interface -// is supported by all content objects. -class nsIContent : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_ICONTENT_IID; return iid; } - - NS_IMETHOD GetDocument(nsIDocument*& aResult) const = 0; - - NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileEventHandlers) = 0; - - NS_IMETHOD GetParent(nsIContent*& aResult) const = 0; - - NS_IMETHOD SetParent(nsIContent* aParent) = 0; - - /** - * Get the namespace that this tag is defined in - */ - NS_IMETHOD GetNameSpaceID(PRInt32& aResult) const = 0; - - NS_IMETHOD GetTag(nsIAtom*& aResult) const = 0; - - NS_IMETHOD GetNodeInfo(nsINodeInfo*& aResult) const = 0; - - NS_IMETHOD CanContainChildren(PRBool& aResult) const = 0; - - NS_IMETHOD ChildCount(PRInt32& aResult) const = 0; - - NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const = 0; - - NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const = 0; - - NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, - PRBool aNotify) = 0; - - NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, - PRBool aNotify) = 0; - - NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) = 0; - - NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) = 0; - - /** - * Normalizes an attribute string into an atom that represents the - * qualified attribute name of the attribute. This method is intended - * for character case conversion if the content object is case - * insensitive (e.g. HTML). - * - * @param aStr the unparsed attribute string - * @param aName out parameter representing the complete name of the - * attribute - */ - NS_IMETHOD NormalizeAttributeString(const nsAReadableString& aStr, - nsINodeInfo*& aNodeInfo) = 0; - - /** - * Set attribute values. All attribute values are assumed to have a - * canonical String representation that can be used for these - * methods. The setAttribute method is assumed to perform a translation - * of the canonical form into the underlying content specific - * form. - * - * @param aName the name of the attribute - - * @param aValue may legitimately be the empty string. - * - * @param aUpdateMask specifies how whether or not the document should be - * notified of the attribute change. - */ - NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - const nsAReadableString& aValue, - PRBool aNotify) = 0; - - /** - * Set attribute values. All attribute values are assumed to have a - * canonical string representation that can be used for these - * methods. The setAttribute method is assumed to perform a translation - * of the canonical form into the underlying content specific - * form. - * - * @param aNodeInfo the node info (name, prefix, namespace id) of the - * attribute - * @param aValue may legitimately be the empty string. - * - * @param aNotify specifies whether or not the document should be - * notified of the attribute change. - */ - NS_IMETHOD SetAttribute(nsINodeInfo* aNodeInfo, - const nsAReadableString& aValue, - PRBool aNotify) = 0; - - /** - * Get the current value of the attribute. This returns a form that is - * suitable for passing back into setAttribute. - * - * - */ - NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - nsAWritableString& aResult) const = 0; - - /** - * Get the current value and prefix of the attribute. This returns a form - * that is suitable for passing back into setAttribute. - * - * - * - * NOTE! aPrefix is an OUT parameter. - */ - - NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - nsIAtom*& aPrefix, nsAWritableString& aResult) const = 0; - - /** - * Remove an attribute so that it is no longer explicitly specified. - * - * @param aAttribute the name of the attribute to unset - * - * @param aNotify specifies whether or not the document should be - * notified of the attribute change - * - */ - NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, - PRBool aNotify) = 0; - - - /** - * Get the namespace & name of a given attribute. - * - * @param aIndex the index of the attribute name - * @param aNameSpace an out param of the name space ID of the attribute name - * @param aName an out param if the attribute name - * - */ - NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, - PRInt32& aNameSpaceID, - nsIAtom*& aName, - nsIAtom*& aPrefix) const = 0; - - /** - * Get the number of all specified attributes. - * - * @param aCountResult an out parameter to be filled in with - * the number of attributes - * - */ - NS_IMETHOD GetAttributeCount(PRInt32& aCountResult) const = 0; - - /** - * Get the size of the content object. The size value should include - * all subordinate data referenced by the content that is not - * accounted for by child content. However, this value should not - * include the frame objects, style contexts, views or other data - * that lies logically outside the content model. - * - * If the implementation so chooses, instead of returning the total - * subordinate data it may instead use the sizeof handler to store - * away subordinate data under its own key so that the subordinate - * data may be tabulated independently of the frame itself. - * - * The caller is responsible for recursing over all children that - * the content contains. - */ - NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const = 0; - - /** - * List the content (and anything it contains) out to the given - * file stream. Use aIndent as the base indent during formatting. - * Returns NS_OK unless a file error occurs. - */ - NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0; - - /** - * Dump the content (and anything it contains) out to the given - * file stream. Use aIndent as the base indent during formatting. - * Returns NS_OK unless a file error occurs. - */ - NS_IMETHOD DumpContent(FILE* out = stdout, PRInt32 aIndent = 0,PRBool aDumpAll=PR_TRUE) const = 0; - - /** - * Inform content of range ownership changes. This allows content - * to do the right thing to ranges in the face of changes to the content - * model. - - * RangeAdd -- informs content that it owns one or both range endpoints - * RangeRemove -- informs content that it no longer owns a range endpoint - * GetRangeList -- returns the list of ranges that have one or both endpoints - * within this content item - */ - NS_IMETHOD RangeAdd(nsIDOMRange& aRange) = 0; - NS_IMETHOD RangeRemove(nsIDOMRange& aRange) = 0; - NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const = 0; - - /** - * Handle a DOM event for this piece of content. - */ - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus) = 0; - - /** - * Get and set a unique ID for this piece of content. - * This ID is used as a key to store state information - * about this content object and its associated frame object. - * The state information is stored in a dictionary that is - * manipulated by the frame manager (nsIFrameManager) inside layout. - * An opaque pointer to this dictionary is passed to the session - * history as a handle associated with the current document's state - */ - NS_IMETHOD GetContentID(PRUint32* aID) = 0; - NS_IMETHOD SetContentID(PRUint32 aID) = 0; - - /** - * All content elements are potentially focusable (according to CSS3). - * These methods are used to set and remove the focus on the content - * element. - */ - NS_IMETHOD SetFocus(nsIPresContext* aPresContext) = 0; - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) = 0; - - /** - * APIs for setting and obtaining the content node - * with the binding responsible for our construction (and existence) - * Used by anonymous content (XBL-generated). null for all explicit content. - */ - NS_IMETHOD SetBindingParent(nsIContent* aContent) = 0; - NS_IMETHOD GetBindingParent(nsIContent** aContent) = 0; -}; - -// nsresult codes for GetAttribute -#define NS_CONTENT_ATTR_HAS_VALUE NS_OK - -#define NS_CONTENT_ATTR_NO_VALUE \ - NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_LAYOUT,0) - -#define NS_CONTENT_ATTR_NOT_THERE \ - NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_LAYOUT,1) - -#endif /* nsIContent_h___ */ diff --git a/layout/base/public/nsIContentIterator.h b/layout/base/public/nsIContentIterator.h deleted file mode 100644 index 3f8cba4e8a33..000000000000 --- a/layout/base/public/nsIContentIterator.h +++ /dev/null @@ -1,113 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef __nsIContentIterator_h___ -#define __nsIContentIterator_h___ - -#include "nsISupports.h" - - -class nsIFocusTracker; -class nsIContent; -class nsIDOMRange; - -#define NS_ICONTENTITERTOR_IID \ -{0xa6cf90e4, 0x15b3, 0x11d2, \ -{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } - -// {B4BC9F63-D9BA-11d3-9938-00108301233C} -#define NS_IGENERATEDCONTENTITERTOR_IID \ -{ 0xb4bc9f63, 0xd9ba, 0x11d3, \ -{ 0x99, 0x38, 0x0, 0x10, 0x83, 0x1, 0x23, 0x3c } } - - -class nsIContentIterator : public nsISupports { -public: - - static const nsIID& GetIID() { static nsIID iid = NS_ICONTENTITERTOR_IID; return iid; } - - /* Initializes an iterator for the subtree rooted by the node aRoot - */ - NS_IMETHOD Init(nsIContent* aRoot)=0; - - /* Initializes an iterator for the subtree defined by the range aRange - */ - NS_IMETHOD Init(nsIDOMRange* aRange)=0; - - /** First will reset the list. will return NS_FAILED if no items - */ - NS_IMETHOD First()=0; - - /** Last will reset the list to the end. will return NS_FAILED if no items - */ - NS_IMETHOD Last()=0; - - /** Next will advance the list. will return failed if allready at end - */ - NS_IMETHOD Next()=0; - - /** Prev will decrement the list. will return failed if allready at beginning - */ - NS_IMETHOD Prev()=0; - - /** CurrentItem will return the CurrentItem item it will fail if the list is empty - * @param aItem return value - */ - NS_IMETHOD CurrentNode(nsIContent **aNode)=0; - - /** return if the collection is at the end. that is the beginning following a call to Prev - * and it is the end of the list following a call to next - * @param aItem return value - */ - NS_IMETHOD IsDone()=0; - - /** PositionAt will position the iterator to the supplied node - */ - NS_IMETHOD PositionAt(nsIContent* aCurNode)=0; - - /** MakePre will make the iterator a pre-order iterator - */ - NS_IMETHOD MakePre()=0; - - /** MakePost will make the iterator a post-order iterator - */ - NS_IMETHOD MakePost()=0; - -}; - -class nsIPresShell; - -class nsIGeneratedContentIterator : public nsISupports { -public: - - static const nsIID& GetIID() { static nsIID iid = NS_IGENERATEDCONTENTITERTOR_IID; return iid; } - - /* Initializes an iterator for the subtree rooted by the node aRoot - */ - NS_IMETHOD Init(nsIPresShell *aShell, nsIDOMRange* aRange)=0; - - NS_IMETHOD Init(nsIPresShell *aShell, nsIContent* aContent)=0; -}; - - -#endif // __nsIContentIterator_h___ - diff --git a/layout/base/public/nsIContentPolicy.idl b/layout/base/public/nsIContentPolicy.idl deleted file mode 100644 index e6fabf555896..000000000000 --- a/layout/base/public/nsIContentPolicy.idl +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla code. - * - * The Initial Developer of the Original Code is Zero-Knowledge Systems, - * Inc. Portions created by Zero-Knowledge are Copyright (C) 2000 - * Zero-Knowledge Systems, Inc. All Rights Reserved. - * - * Contributor(s): - */ - -#include "nsISupports.idl" -#include "nsIURL.idl" -#include "domstubs.idl" - -/** - * Interface for content policy mechanism. Implementations of this - * interface can be used to control loading of various types of out-of-line - * content, or processing of certain types of in-line content. - */ - -[scriptable,uuid(1cb4085d-5407-4169-bcfe-4c5ba013fa5b)] -interface nsIContentPolicy : nsISupports -{ - const short CONTENT_OTHER = 0; - const short CONTENT_SCRIPT = 1; - const short CONTENT_IMAGE = 2; - const short CONTENT_STYLESHEET = 3; - const short CONTENT_OBJECT = 4; - - /** - * Should the content at this location be loaded and processed? - * - * XXX Permit URL-rewriting? - * XXX Use MIME types for contentType? - * XXX Use nsIURL for location? - */ - boolean shouldLoad(in PRInt32 contentType, in nsIDOMElement element, - in wstring contentLocation); - - /** - * Should the contents of the element in question be processed? - */ - boolean shouldProcess(in PRInt32 contentType, in nsIDOMElement element, - in wstring documentLocation); -}; diff --git a/layout/base/public/nsIContentSerializer.h b/layout/base/public/nsIContentSerializer.h deleted file mode 100644 index df4db0a033e3..000000000000 --- a/layout/base/public/nsIContentSerializer.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef _nsIContentSerializer_h__ -#define _nsIContentSerializer_h__ - -#include "nsISupports.h" -#include "nsAWritableString.h" -#include "nsIAtom.h" - -class nsIDOMText; /* forward declaration */ -class nsIDOMCDATASection; /* forward declaration */ -class nsIDOMProcessingInstruction; /* forward declaration */ -class nsIDOMComment; /* forward declaration */ -class nsIDOMDocumentType; /* forward declaration */ -class nsIDOMElement; /* forward declaration */ - -/* starting interface: nsIContentSerializer */ -#define NS_ICONTENTSERIALIZER_IID_STR "61e9b9a3-d30c-429e-b0cf-ade73466df06" - -#define NS_ICONTENTSERIALIZER_IID \ - {0x61e9b9a3, 0xd30c, 0x429e, \ - { 0xb0, 0xcf, 0xad, 0xe7, 0x34, 0x66, 0xdf, 0x06 }} - -class nsIContentSerializer : public nsISupports { - public: - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICONTENTSERIALIZER_IID) - - NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn, - nsIAtom* aCharSet) = 0; - - NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset, - PRInt32 aEndOffset, nsAWritableString& aStr) = 0; - - NS_IMETHOD AppendCDATASection(nsIDOMCDATASection* aCDATASection, - PRInt32 aStartOffset, PRInt32 aEndOffset, - nsAWritableString& aStr) = 0; - - NS_IMETHOD AppendProcessingInstruction(nsIDOMProcessingInstruction* aPI, - PRInt32 aStartOffset, - PRInt32 aEndOffset, - nsAWritableString& aStr) = 0; - - NS_IMETHOD AppendComment(nsIDOMComment* aComment, PRInt32 aStartOffset, - PRInt32 aEndOffset, nsAWritableString& aStr) = 0; - - NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype, - nsAWritableString& aStr) = 0; - - NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, - nsAWritableString& aStr) = 0; - - NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, - nsAWritableString& aStr) = 0; - - NS_IMETHOD Flush(nsAWritableString& aStr) = 0; -}; - -#define NS_CONTENTSERIALIZER_CONTRACTID_PREFIX \ -"@mozilla.org/layout/contentserializer;1?mimetype=" - -#endif /* __gen_nsIContentSerializer_h__ */ diff --git a/layout/base/public/nsIDiskDocument.idl b/layout/base/public/nsIDiskDocument.idl deleted file mode 100644 index 06c5d70bb406..000000000000 --- a/layout/base/public/nsIDiskDocument.idl +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Original Author: Simon Fraser (sfraser@netscape.com) - * - * Contributor(s): - */ - -#include "nsISupports.idl" -#include "nsIFile.idl" - -// {dd038282-d5a2-11d4-aedb-e1c4b1c8b9fc} -[scriptable, uuid(dd038282-d5a2-11d4-aedb-e1c4b1c8b9fc)] -interface nsIDiskDocument : nsISupports -{ - /** An nsIFile pointing to the location of the file on disk. May be null if - * this document has not been saved yet - */ - readonly attribute nsIFile fileSpec; - - /** The modification count for the document. A +ve mod count indicates - * that the document is dirty, and needs saving. - */ - readonly attribute long modificationCount; - - /** Initialize the document output. This may be called on document - * creation, or lazily before the first save. For a document read - * in from disk, it should be called on document instantiation. - * - * @param aFile nsIFile for the file, if a disk version - * of the file exists already. Otherwise nsnull. - */ - void InitDiskDocument(in nsIFile aFile); - - - /** Save the file to disk. This will be called after the caller has - * displayed a put file dialog, which the user confirmed. The internal - * fileSpec of the document is only updated with the given fileSpec if inSaveCopy == PR_FALSE. - * - * @param aFile File to which to stream the document. - * @param aReplaceExisting true if replacing an existing file, otherwise false. - * If false and aFile exists, SaveFile returns an error. - * @param aSaveCopy True to save a copy of the file, without changing the file - * referenced internally. - * @param aFileType Mime type to save (text/plain or text/html) - * @param aFileCharset Charset to save the document in. If this is an empty - * string, or "UCS2", then the doc will be saved as Unicode. - * @param aSaveFlags Flags used by the document encoder (see nsIDocumentEncoder). - * @param inWrapColumn Wrap column, assuming that flags specify wrapping. - */ - void SaveFile(in nsIFile aFile, in boolean aReplaceExisting, in boolean aSaveCopy, - in wstring aFileType, in wstring aFileCharset, in unsigned long aSaveFlags, - in unsigned long aWrapColumn); - - /** Reset the modification count for the document. This marks the documents as - * 'clean' and not in need of saving. - */ - void ResetModificationCount(); - - /** Increment the modification count for the document by the given - * amount (which may be -ve). - */ - void IncrementModificationCount(in long aNumMods); - -}; - - diff --git a/layout/base/public/nsIDocument.h b/layout/base/public/nsIDocument.h deleted file mode 100644 index 20ed7c9ba820..000000000000 --- a/layout/base/public/nsIDocument.h +++ /dev/null @@ -1,336 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsIDocument_h___ -#define nsIDocument_h___ - -#include "nslayout.h" -#include "nsISupports.h" -#include "nsGUIEvent.h" -#include "nsAWritableString.h" - -class nsIAtom; -class nsIArena; -class nsIContent; -class nsIDocumentContainer; -class nsIDocumentObserver; -class nsIPresContext; -class nsIPresShell; - -class nsIStreamListener; -class nsIStreamObserver; -class nsIStyleSet; -class nsIStyleSheet; -class nsIStyleRule; -class nsIURI; -class nsILoadGroup; -class nsIViewManager; -class nsIScriptGlobalObject; -class nsIDOMEvent; -class nsIDeviceContext; -class nsIParser; -class nsIDOMNode; -class nsINameSpaceManager; -class nsIDOMDocumentFragment; -class nsILineBreaker; -class nsIWordBreaker; -class nsISelection; -class nsIChannel; -class nsIPrincipal; -class nsINodeInfoManager; -class nsIDOMDocument; -class nsIDOMDocumentType; -class nsIBindingManager; -class nsIObserver; -class nsISupportsArray; - -// IID for the nsIDocument interface -#define NS_IDOCUMENT_IID \ -{ 0x94c6ceb0, 0x9447, 0x11d1, \ - {0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } - -// The base value for the content ID counter. -// This counter is used by the document to -// assign a monotonically increasing ID to each content -// object it creates -#define NS_CONTENT_ID_COUNTER_BASE 10000 - -//---------------------------------------------------------------------- - -// Document interface -class nsIDocument : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_IID; return iid; } - - // All documents have a memory arena associated with them which is - // used for memory allocation during document creation. This call - // returns the arena associated with this document. - virtual nsIArena* GetArena() = 0; - - NS_IMETHOD StartDocumentLoad(const char* aCommand, - nsIChannel* aChannel, - nsILoadGroup* aLoadGroup, - nsISupports* aContainer, - nsIStreamListener **aDocListener, - PRBool aReset) = 0; - - NS_IMETHOD StopDocumentLoad() = 0; - - /** - * Return the title of the document. May return null. - */ - virtual const nsString* GetDocumentTitle() const = 0; - - /** - * Return the URL for the document. May return null. - */ - virtual nsIURI* GetDocumentURL() const = 0; - - /** - * Return the principal responsible for this document. - */ - NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal) = 0; - - /** - * Update principal responsible for this document to the intersection - * of its previous value and aPrincipal. - */ - NS_IMETHOD AddPrincipal(nsIPrincipal *aPrincipal) = 0; - - /** - * Return the LoadGroup for the document. May return null. - */ - NS_IMETHOD GetDocumentLoadGroup(nsILoadGroup** aGroup) const = 0; - - /** - * Return the base URL for realtive URLs in the document. May return null (or the document URL). - */ - NS_IMETHOD GetBaseURL(nsIURI*& aURL) const = 0; - - /** - * Return the content (mime) type of this document. - */ - NS_IMETHOD GetContentType(nsAWritableString& aContentType) const = 0; - - /** - * Return a standard name for the document's character set. This will - * trigger a startDocumentLoad if necessary to answer the question. - */ - NS_IMETHOD GetDocumentCharacterSet(nsAWritableString& oCharSetID) = 0; - NS_IMETHOD SetDocumentCharacterSet(const nsAReadableString& aCharSetID) = 0; - - /** - * Add an observer that gets notified whenever the charset changes. - */ - NS_IMETHOD AddCharSetObserver(nsIObserver* aObserver) = 0; - - /** - * Remove a charset observer. - */ - NS_IMETHOD RemoveCharSetObserver(nsIObserver* aObserver) = 0; - - /** - * Return the Line Breaker for the document - */ - NS_IMETHOD GetLineBreaker(nsILineBreaker** aResult) = 0; - NS_IMETHOD SetLineBreaker(nsILineBreaker* aLineBreaker) = 0; - NS_IMETHOD GetWordBreaker(nsIWordBreaker** aResult) = 0; - NS_IMETHOD SetWordBreaker(nsIWordBreaker* aWordBreaker) = 0; - - /** - * Access HTTP header data (this may also get set from other sources, like - * HTML META tags). - */ - NS_IMETHOD GetHeaderData(nsIAtom* aHeaderField, nsAWritableString& aData) const = 0; - NS_IMETHOD SetHeaderData(nsIAtom* aheaderField, const nsAReadableString& aData) = 0; - - /** - * Create a new presentation shell that will use aContext for - * it's presentation context (presentation context's must not be - * shared among multiple presentation shell's). - */ - NS_IMETHOD CreateShell(nsIPresContext* aContext, - nsIViewManager* aViewManager, - nsIStyleSet* aStyleSet, - nsIPresShell** aInstancePtrResult) = 0; - virtual PRBool DeleteShell(nsIPresShell* aShell) = 0; - virtual PRInt32 GetNumberOfShells() = 0; - virtual nsIPresShell* GetShellAt(PRInt32 aIndex) = 0; - - /** - * Return the parent document of this document. Will return null - * unless this document is within a compound document and has a parent. - */ - virtual nsIDocument* GetParentDocument() = 0; - virtual void SetParentDocument(nsIDocument* aParent) = 0; - virtual void AddSubDocument(nsIDocument* aSubDoc) = 0; - virtual PRInt32 GetNumberOfSubDocuments() = 0; - virtual nsIDocument* GetSubDocumentAt(PRInt32 aIndex) = 0; - - /** - * Return the root content object for this document. - */ - virtual nsIContent* GetRootContent() = 0; - virtual void SetRootContent(nsIContent* aRoot) = 0; - - /** - * Get the direct children of the document - content in - * the prolog, the root content and content in the epilog. - */ - NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const = 0; - NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const = 0; - NS_IMETHOD GetChildCount(PRInt32& aCount) = 0; - - /** - * Get the style sheets owned by this document. - * Style sheets are ordered, most significant last. - */ - virtual PRInt32 GetNumberOfStyleSheets() = 0; - virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex) = 0; - virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet) = 0; - virtual void AddStyleSheet(nsIStyleSheet* aSheet) = 0; - virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) = 0; - NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets) = 0; - - NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify) = 0; - virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet, - PRBool mDisabled) = 0; - - /** - * Set the object from which a document can get a script context. - * This is the context within which all scripts (during document - * creation and during event handling) will run. - */ - NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject** aGlobalObject) = 0; - NS_IMETHOD SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0; - - /** - * Get the name space manager for this document - */ - NS_IMETHOD GetNameSpaceManager(nsINameSpaceManager*& aManager) = 0; - - //---------------------------------------------------------------------- - - // Document notification API's - - /** - * Add a new observer of document change notifications. Whenever - * content is changed, appended, inserted or removed the observers are - * informed. - */ - virtual void AddObserver(nsIDocumentObserver* aObserver) = 0; - - /** - * Remove an observer of document change notifications. This will - * return false if the observer cannot be found. - */ - virtual PRBool RemoveObserver(nsIDocumentObserver* aObserver) = 0; - - // Observation hooks used by content nodes to propagate - // notifications to document observers. - NS_IMETHOD BeginUpdate() = 0; - NS_IMETHOD EndUpdate() = 0; - NS_IMETHOD BeginLoad() = 0; - NS_IMETHOD EndLoad() = 0; - NS_IMETHOD ContentChanged(nsIContent* aContent, - nsISupports* aSubContent) = 0; - // notify that one or two content nodes changed state - // either may be nsnull, but not both - NS_IMETHOD ContentStatesChanged(nsIContent* aContent1, - nsIContent* aContent2) = 0; - NS_IMETHOD AttributeChanged(nsIContent* aChild, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aHint) = 0; // See nsStyleConsts fot hint values - NS_IMETHOD ContentAppended(nsIContent* aContainer, - PRInt32 aNewIndexInContainer) = 0; - NS_IMETHOD ContentInserted(nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) = 0; - NS_IMETHOD ContentReplaced(nsIContent* aContainer, - nsIContent* aOldChild, - nsIContent* aNewChild, - PRInt32 aIndexInContainer) = 0; - NS_IMETHOD ContentRemoved(nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) = 0; - - // Observation hooks for style data to propogate notifications - // to document observers - NS_IMETHOD StyleRuleChanged(nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule, - PRInt32 aHint) = 0; // See nsStyleConsts fot hint values - NS_IMETHOD StyleRuleAdded(nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule) = 0; - NS_IMETHOD StyleRuleRemoved(nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule) = 0; - - /** - * Finds text in content - */ - NS_IMETHOD FindNext(const nsAReadableString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound) = 0; - - - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus) = 0; - - NS_IMETHOD FlushPendingNotifications(PRBool aFlushReflows=PR_TRUE) = 0; - - NS_IMETHOD GetAndIncrementContentID(PRInt32* aID) = 0; - - NS_IMETHOD GetBindingManager(nsIBindingManager** aResult) = 0; - - NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) = 0; -}; - - -// XXX These belong somewhere else -extern NS_LAYOUT nsresult - NS_NewHTMLDocument(nsIDocument** aInstancePtrResult); - -extern NS_LAYOUT nsresult - NS_NewXMLDocument(nsIDocument** aInstancePtrResult); - -extern NS_LAYOUT nsresult - NS_NewImageDocument(nsIDocument** aInstancePtrResult); - -extern NS_LAYOUT nsresult - NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult, - nsIDocument* aOwnerDocument); -extern NS_LAYOUT nsresult - NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult, - const nsAReadableString& aNamespaceURI, - const nsAReadableString& aQualifiedName, - nsIDOMDocumentType* aDoctype, - nsIURI* aBaseURI); - -// Note: The buffer passed into NewPostData(...) becomes owned by the IPostData -// instance and is freed when the instance is destroyed... -// -#if 0 -extern NS_LAYOUT nsresult - NS_NewPostData(PRBool aIsFile, char *aData, nsIPostData** aInstancePtrResult); -#endif - -#endif /* nsIDocument_h___ */ diff --git a/layout/base/public/nsIDocumentContainer.h b/layout/base/public/nsIDocumentContainer.h deleted file mode 100644 index c427ade6ffb6..000000000000 --- a/layout/base/public/nsIDocumentContainer.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsIDocumentContainer_h___ -#define nsIDocumentContainer_h___ - -#include "nsISupports.h" -class nsIScriptable; -class nsIScriptEnvironment; -class nsIURI; - -#define NS_IDOCUMENT_CONTAINER_IID \ -{ 0x8efd4470, 0x944d, 0x11d1, \ - {0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} } - -class nIDocumentContainer : public nsISupports { -public: - /** - * Display the specified URL with the given connection. - * - * @param url the URL to display - * @param connection the connection to use. - */ - virtual void Display(nsIURI* aURL) = 0; - - /** - * Returns a script environment for the specified language and version. - * The expectation is that the script environment already has been - * set up with a container object. If a script environment has already - * been requested for the given language, the same instance should - * be returned. - * - * @param language the scripting language for the environment. If this - * is null, returns the default scripting environment. - * @param majorVersion the major version number of the language - * @param minorVersion the minor version number of the language - * @return the script environment for the language - * @see mg.magellan.script.IScriptEnvrionment - */ - virtual nsIScriptEnvironment* - GetScriptEnvironment(nsString* aLanguage, - PRInt32 aMajorVersion, - PRInt32 aMinorVersion) = 0; - - /** - * Returns the scriptable container object for the document container. - * The scriptable object will be used as the scoping object in the - * definition of scriptable classes used in the Document Object Model. - * - * @return the scriptable container for the application - * @see mg.magellan.script.IScriptable - * @see mg.magellan.script.IScriptEnvrionment - */ - virtual nsIScriptable* GetScriptableContainer() = 0; -}; - -#endif /* nsIDocumentContainer_h___ */ diff --git a/layout/base/public/nsIDocumentEncoder.h b/layout/base/public/nsIDocumentEncoder.h deleted file mode 100644 index d36f53b2715d..000000000000 --- a/layout/base/public/nsIDocumentEncoder.h +++ /dev/null @@ -1,209 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsIDocumentEncoder_h__ -#define nsIDocumentEncoder_h__ - -#include "nsISupports.h" -#include "nsString.h" - -class nsIDocumentEncoder; -class nsIDocument; -class nsIDOMRange; -class nsISelection; -class nsIOutputStream; -class nsISupportsArray; -class nsIDOMNode; - - -#define NS_IDOCUMENT_ENCODER_IID \ -{ /* a6cf9103-15b3-11d2-932e-00805f8add32 */ \ - 0xa6cf9103, \ - 0x15b3, \ - 0x11d2, \ - {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} \ - } - -#define NS_TEXT_ENCODER_CID \ -{ /* e7ba1480-1dea-11d3-830f-00104bed045e */ \ - 0xe7ba1480, \ - 0x1dea, \ - 0x11d3, \ - {0x83, 0x0f, 0x00, 0x10, 0x4b, 0xed, 0x04, 0x5e} \ -} - -#define NS_DOC_ENCODER_CONTRACTID_BASE "@mozilla.org/layout/documentEncoder;1?type=" - -// {7f915b01-98fc-11d4-8eb0-a803f80ff1bc} -#define NS_HTMLCOPY_TEXT_ENCODER_CID \ -{ 0x7f915b01, 0x98fc, 0x11d4, { 0x8e, 0xb0, 0xa8, 0x03, 0xf8, 0x0f, 0xf1, 0xbc } } - -// {0BC1FAC0-B710-11d4-959F-0020183BF181} -#define NS_IDOCUMENTENCODERNODEFIXUP_IID \ -{ 0xbc1fac0, 0xb710, 0x11d4, { 0x95, 0x9f, 0x0, 0x20, 0x18, 0x3b, 0xf1, 0x81 } } - -#define NS_HTMLCOPY_ENCODER_CONTRACTID "@mozilla.org/layout/htmlCopyEncoder;1" - -class nsIDocumentEncoderNodeFixup : public nsISupports -{ -public: - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENTENCODERNODEFIXUP_IID) - - /** - * Create a fixed up version of a node. This method is called before - * each node in a document is about to be persisted. The implementor - * may return a new node with fixed up attributes or nsnull. - */ - NS_IMETHOD FixupNode(nsIDOMNode *aNode, nsIDOMNode **aOutNode) = 0; -}; - -class nsIDocumentEncoder : public nsISupports -{ -public: - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_ENCODER_IID) - - /** - * Output methods flag bits. - * - * There are a frightening number of these, - * because everyone wants something a little bit different! - * - * These should move to an idl file so that Javascript can - * have access to the symbols, not just the constants. - */ - enum { - // Output only the selection (as opposed to the whole document). - OutputSelectionOnly = 1, - - // Plaintext output: Convert html to plaintext that looks like the html. - // Implies wrap (except inside
), since html wraps.
-    // HTML output: always do prettyprinting, ignoring existing formatting.
-    // (Probably not well tested for HTML output.)
-    OutputFormatted     = 2,
-
-    // OutputRaw is used by copying text from widgets
-    OutputRaw           = 4,
-
-    // No html head tags
-    OutputBodyOnly      = 8,
-
-    // Wrap even if we're not doing formatted output (e.g. for text fields)
-    OutputPreformatted  = 16,
-
-    // Output as though the content is preformatted
-    // (e.g. maybe it's wrapped in a MOZ_PRE or MOZ_PRE_WRAP style tag)
-    OutputWrap          = 32,
-
-    // Output for format flowed (RFC 2646). This is used when converting
-    // to text for mail sending. This differs just slightly
-    // but in an important way from normal formatted, and that is that
-    // lines are space stuffed. This can't (correctly) be done later.
-    OutputFormatFlowed  = 64,
-
-    // Convert links, image src, and script src to absolute URLs when possible
-    OutputAbsoluteLinks = 128,
-
-    // Encode entities when outputting to a string.
-    // E.g. If set, we'll output   if clear, we'll output 0xa0.
-    OutputEncodeEntities = 256,
-
-    // LineBreak processing: we can do either platform line breaks,
-    // CR, LF, or CRLF.  If neither of these flags is set, then we
-    // will use platform line breaks.
-    OutputCRLineBreak = 512,
-    OutputLFLineBreak = 1024
-  };
-
-  /**
-   *  Initialize with a pointer to the document and the mime type.
-   */
-  NS_IMETHOD Init(nsIDocument* aDocument, const nsAReadableString& aMimeType,
-                  PRUint32 flags) = 0;
-
-  /**
-   *  If the selection is set to a non-null value, then the
-   *  selection is used for encoding, otherwise the entire
-   *  document is encoded.
-   */
-  NS_IMETHOD SetSelection(nsISelection* aSelection) = 0;
-
-  /**
-   *  If the range is set to a non-null value, then the
-   *  range is used for encoding, otherwise the entire
-   *  document or selection is encoded.
-   */
-  NS_IMETHOD SetRange(nsIDOMRange* aRange) = 0;
-
-  /**
-   *  Documents typically have an intrinsic character set.
-   *  If no intrinsic value is found, the platform character set
-   *  is used.
-   *  aCharset overrides the both the intrinsic or platform
-   *  character set when encoding the document.
-   *
-   *  Possible result codes: NS_ERROR_NO_CHARSET_CONVERTER
-   */
-  NS_IMETHOD SetCharset(const nsAReadableString& aCharset) = 0;
-
-  /**
-   *  Set a wrap column.  This may have no effect in some types of encoders.
-   */
-  NS_IMETHOD SetWrapColumn(PRUint32 aWC) = 0;
-
-  /**
-   *  Get the mime type preferred by the encoder.  This piece of api was
-   *  added because the copy encoder may need to switch mime types on you
-   *  if you ask it to copy html that really represents plaintext content.
-   *  Call this AFTER Init() and SetSelection() have both been called.
-   */
-  NS_IMETHOD GetMimeType(nsAWritableString& aMimeType) = 0;
-  
-  /**
-   *  The document is encoded, the result is sent to the 
-   *  to nsIOutputStream.
-   * 
-   *  Possible result codes are passing along whatever stream errors
-   *  might have been encountered.
-   */
-  NS_IMETHOD EncodeToStream(nsIOutputStream* aStream) = 0;
-  NS_IMETHOD EncodeToString(nsAWritableString& aOutputString) = 0;
-
-  /**
-   *  The document is encoded, the result is sent to the 
-   *  to aEncodedString.  Parent heirarchy information is encoded
-   *  to aContextString.  Extra context info is encoded in aInfoString.
-   * 
-   */
-  NS_IMETHOD EncodeToStringWithContext(nsAWritableString& aEncodedString, 
-                                       nsAWritableString& aContextString, 
-                                       nsAWritableString& aInfoString) = 0;
-
-  /**
-   * Set the fixup object associated with node persistence.
-   */
-  NS_IMETHOD SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup) = 0;
-};
-
-#endif /* nsIDocumentEncoder_h__ */
-
diff --git a/layout/base/public/nsIDocumentObserver.h b/layout/base/public/nsIDocumentObserver.h
deleted file mode 100644
index 73bb8a3f47e6..000000000000
--- a/layout/base/public/nsIDocumentObserver.h
+++ /dev/null
@@ -1,312 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * The contents of this file are subject to the Netscape Public
- * License Version 1.1 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.mozilla.org/NPL/
- *
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is Netscape
- * Communications Corporation.  Portions created by Netscape are
- * Copyright (C) 1998 Netscape Communications Corporation. All
- * Rights Reserved.
- *
- * Contributor(s): 
- */
-#ifndef nsIDocumentObserver_h___
-#define nsIDocumentObserver_h___
-
-#include "nsISupports.h"
-
-class nsIAtom;
-class nsIContent;
-class nsIPresShell;
-class nsIStyleSheet;
-class nsIStyleRule;
-class nsString;
-class nsIDocument;
-
-#define NS_IDOCUMENT_OBSERVER_IID \
-{ 0xb3f92460, 0x944c, 0x11d1, {0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
-
-// Document observer interface
-class nsIDocumentObserver : public nsISupports {
-public:
-  static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_OBSERVER_IID; return iid; }
-
-  /**
-   * Notify that a content model update is beginning. This call can be
-   * nested.
-   */
-  NS_IMETHOD BeginUpdate(nsIDocument *aDocument) = 0;
-
-  /**
-   * Notify that a content model update is finished. This call can be
-   * nested.
-   */
-  NS_IMETHOD EndUpdate(nsIDocument *aDocument) = 0;
-
-  /**
-   * Notify the observer that a document load is beginning.
-   */
-  NS_IMETHOD BeginLoad(nsIDocument *aDocument) = 0;
-
-  /**
-   * Notify the observer that a document load has finished. Note that
-   * the associated reflow of the document will be done before
-   * EndLoad is invoked, not after.
-   */
-  NS_IMETHOD EndLoad(nsIDocument *aDocument) = 0;
-
-  /**
-   * Notify the observer that the document is being reflowed in
-   * the given presentation shell.
-   */
-  NS_IMETHOD BeginReflow(nsIDocument *aDocument, nsIPresShell* aShell) = 0;
-
-  /**
-   * Notify the observer that the document is done being reflowed in
-   * the given presentation shell.
-   */
-  NS_IMETHOD EndReflow(nsIDocument *aDocument, nsIPresShell* aShell) = 0;
-
-  /**
-   * Notification that the content model has changed. This method is
-   * called automatically by content objects when their state is changed
-   * (therefore there is normally no need to invoke this method
-   * directly).  The notification is passed to any
-   * IDocumentObservers. The notification is passed on to all of the
-   * document observers. 

- * - * This notification is not sent when a piece of content is - * added/removed from the document (the other notifications are used - * for that). - * - * @param aDocument The document being observed - * @param aContent the piece of content that changed - * @param aSubContent subrange information about the piece of content - * that changed - */ - NS_IMETHOD ContentChanged(nsIDocument *aDocument, - nsIContent* aContent, - nsISupports* aSubContent) = 0; - - /** - * Notification that the state of a content node has changed. - * (ie: gained or lost focus, became active or hovered over) - * This method is called automatically by content objects - * when their state is changed (therefore there is normally - * no need to invoke this method directly). The notification - * is passed to any IDocumentObservers. The notification is - * passed on to all of the document observers.

- * - * This notification is not sent when a piece of content is - * added/removed from the document or the content itself changed - * (the other notifications are used for that). - * - * The optional second content node is to allow optimization - * of the case where state moves from one node to another - * (as is likely for :focus and :hover) - * - * Either content node may be nsnull, but not both - * - * @param aDocument The document being observed - * @param aContent1 the piece of content that changed - * @param aContent2 optional second piece of content that changed - */ - NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument, - nsIContent* aContent1, - nsIContent* aContent2) = 0; - - /** - * Notification that the content model has changed. This method is called - * automatically by content objects when an attribute's value has changed - * (therefore there is normally no need to invoke this method directly). The - * notification is passed to any IDocumentObservers document observers.

- * - * @param aDocument The document being observed - * @param aContent the piece of content whose attribute changed - * @param aAttribute the atom name of the attribute - */ - NS_IMETHOD AttributeChanged(nsIDocument *aDocument, - nsIContent* aContent, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aHint) = 0; // See nsStyleConsts fot hint values - - /** - * Notifcation that the content model has had data appended to the - * given content object. This method is called automatically by the - * content container objects when a new content object is appended to - * the container (therefore there is normally no need to invoke this - * method directly). The notification is passed on to all of the - * document observers. - * - * @param aDocument The document being observed - * @param aContainer the container that had a new child appended - * @param aNewIndexInContainer the index in the container of the first - * new child - */ - NS_IMETHOD ContentAppended(nsIDocument *aDocument, - nsIContent* aContainer, - PRInt32 aNewIndexInContainer) = 0; - - /** - * Notification that content has been inserted. This method is called - * automatically by the content container objects when a new content - * object is inserted in the container (therefore there is normally no - * need to invoke this method directly). The notification is passed on - * to all of the document observers. - * - * @param aDocument The document being observed - * @param aContainer the container that now contains aChild - * @param aChild the child that was inserted - * @param aIndexInContainer the index of the child in the container - */ - NS_IMETHOD ContentInserted(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) = 0; - - /** - * Notification that content has been replaced. This method is called - * automatically by the content container objects when a content object - * is replaced in the container (therefore there is normally no need to - * invoke this method directly). The notification is passed on to all - * of the document observers. - * - * @param aDocument The document being observed - * @param aContainer the container that now contains aChild - * @param aOldChild the child that was replaced - * @param aNewChild the child that replaced aOldChild - * @param aIndexInContainer the index of the old and new child in the - * container - */ - NS_IMETHOD ContentReplaced(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aOldChild, - nsIContent* aNewChild, - PRInt32 aIndexInContainer) = 0; - - /** - * Content has just been removed. This method is called automatically - * by content container objects when a content object has just been - * removed from the container (therefore there is normally no need to - * invoke this method directly). The notification is passed on to all - * of the document observers. - * - * @param aDocument The document being observed - * @param aContainer the container that had a child removed - * @param aChild the child that was just removed - * @param aIndexInContainer the index of the child in the container - * before it was removed - */ - NS_IMETHOD ContentRemoved(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) = 0; - - /** - * A StyleSheet has just been added to the document. - * This method is called automatically when a StyleSheet gets added - * to the document. The notification is passed on to all of the - * document observers. - * - * @param aDocument The document being observed - * @param aStyleSheet the StyleSheet that has been added - */ - NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet) = 0; - - /** - * A StyleSheet has just been removed from the document. - * This method is called automatically when a StyleSheet gets removed - * from the document. The notification is passed on to all of the - * document observers. - * - * @param aDocument The document being observed - * @param aStyleSheet the StyleSheet that has been removed - */ - NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet) = 0; - - /** - * A StyleSheet has just disabled or enabled. - * This method is called automatically when the disabled state - * of a StyleSheet gets changed. The style sheet passes this - * notification to the document. The notification is passed on - * to all of the document observers. - * - * @param aDocument The document being observed - * @param aStyleSheet the StyleSheet that has been added - * @param aDisabled PR_TRUE if the sheet is disabled, PR_FALSE if - * it is enabled - */ - NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - PRBool aDisabled) = 0; - - /** - * A StyleRule has just been modified within a style sheet. - * This method is called automatically when the rule gets - * modified. The style sheet passes this notification to - * the document. The notification is passed on to all of - * the document observers. - * - * @param aDocument The document being observed - * @param aStyleSheet the StyleSheet that contians the rule - * @param aStyleRule the rule that was modified - * @param aHint some possible info about the nature of the change - */ - NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule, - PRInt32 aHint) = 0; // See nsStyleConsts fot hint values - - /** - * A StyleRule has just been added to a style sheet. - * This method is called automatically when the rule gets - * added to the sheet. The style sheet passes this - * notification to the document. The notification is passed on - * to all of the document observers. - * - * @param aDocument The document being observed - * @param aStyleSheet the StyleSheet that has been modified - * @param aStyleRule the rule that was added - */ - NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule) = 0; - - /** - * A StyleRule has just been removed from a style sheet. - * This method is called automatically when the rule gets - * removed from the sheet. The style sheet passes this - * notification to the document. The notification is passed on - * to all of the document observers. - * - * @param aDocument The document being observed - * @param aStyleSheet the StyleSheet that has been modified - * @param aStyleRule the rule that was removed - */ - NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule) = 0; - - /** - * The document is in the process of being destroyed. - * This method is called automatically during document - * destruction. - * - * @param aDocument The document being observed - */ - NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument) = 0; -}; - -#endif /* nsIDocumentObserver_h___ */ diff --git a/layout/base/public/nsIDocumentViewer.h b/layout/base/public/nsIDocumentViewer.h deleted file mode 100644 index 6a1cd1b2adb5..000000000000 --- a/layout/base/public/nsIDocumentViewer.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsIDocumentViewer_h___ -#define nsIDocumentViewer_h___ - -#include "nsIContentViewer.h" - -class nsIDocument; -class nsIPresContext; -class nsIPresShell; -class nsIStyleSheet; -class nsITransformMediator; - -#define NS_IDOCUMENT_VIEWER_IID \ - { 0xa6cf9057, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} - -/** - * A document viewer is a kind of content viewer that uses NGLayout - * to manage the presentation of the content. - */ -class nsIDocumentViewer : public nsIContentViewer -{ -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_VIEWER_IID) - - NS_IMETHOD SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet) = 0; - - NS_IMETHOD GetDocument(nsIDocument*& aResult) = 0; - - NS_IMETHOD GetPresShell(nsIPresShell*& aResult) = 0; - - NS_IMETHOD GetPresContext(nsIPresContext*& aResult) = 0; - - NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext, - nsIDocumentViewer*& aResult) = 0; - - NS_IMETHOD SetTransformMediator(nsITransformMediator* aMediator)=0; -}; - -#endif /* nsIDocumentViewer_h___ */ diff --git a/layout/base/public/nsIElementFactory.h b/layout/base/public/nsIElementFactory.h deleted file mode 100644 index 207f0eea046c..000000000000 --- a/layout/base/public/nsIElementFactory.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsIElementFactory_h___ -#define nsIElementFactory_h___ - -#include "nsISupports.h" - -class nsIContent; -class nsINodeInfo; - -/* a6cf90fb-15b3-11d2-932e-00805f8add32 */ -#define NS_IELEMENT_FACTORY_IID \ - { 0xa6cf90fb, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} - -/** - * An API for creating html content objects - */ -class nsIElementFactory : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_IELEMENT_FACTORY_IID; return iid; } - - NS_IMETHOD CreateInstanceByTag(nsINodeInfo *aNodeInfo, - nsIContent** aResult) = 0; -}; - -// ContractIDs for element factory registration -#define NS_ELEMENT_FACTORY_CONTRACTID "@mozilla.org/layout/element-factory;1" -#define NS_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_ELEMENT_FACTORY_CONTRACTID "?namespace=" - -#define NS_HTML_NAMESPACE "http://www.w3.org/1999/xhtml" -#define NS_XML_NAMESPACE "http://www.w3.org/XML/1998/namespace" - -#define NS_HTML_ELEMENT_FACTORY_CONTRACTID NS_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_HTML_NAMESPACE -#define NS_XML_ELEMENT_FACTORY_CONTRACTID NS_ELEMENT_FACTORY_CONTRACTID_PREFIX NS_XML_NAMESPACE - -#endif /* nsIElementFactory_h___ */ diff --git a/layout/base/public/nsIHTMLToTextSink.h b/layout/base/public/nsIHTMLToTextSink.h deleted file mode 100644 index 3db28e5b8f25..000000000000 --- a/layout/base/public/nsIHTMLToTextSink.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef _nsIPlainTextSink_h__ -#define _nsIPlainTextSink_h__ - -#include "nsISupports.h" -#include "nsAWritableString.h" - -#define NS_PLAINTEXTSINK_CONTRACTID "@mozilla.org/layout/plaintextsink;1" - -/* starting interface: nsIContentSerializer */ -#define NS_IHTMLTOTEXTSINK_IID_STR "b12b5643-07cb-401e-aabb-64b2dcd2717f" - -#define NS_IHTMLTOTEXTSINK_IID \ - {0xb12b5643, 0x07cb, 0x401e, \ - { 0xaa, 0xbb, 0x64, 0xb2, 0xdc, 0xd2, 0x71, 0x7f }} - - -class nsIHTMLToTextSink : public nsISupports { - public: - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IHTMLTOTEXTSINK_IID) - - NS_IMETHOD Initialize(nsAWritableString* aOutString, - PRUint32 aFlags, PRUint32 aWrapCol) = 0; -}; - -#endif diff --git a/layout/base/public/nsINameSpace.h b/layout/base/public/nsINameSpace.h deleted file mode 100644 index 401f4c7037b5..000000000000 --- a/layout/base/public/nsINameSpace.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsINameSpace_h___ -#define nsINameSpace_h___ - -#include "nsISupports.h" -#include "nslayout.h" - -class nsIAtom; -class nsString; -class nsINameSpaceManager; - -#define NS_INAMESPACE_IID \ - { 0xa6cf90d4, 0x15b3, 0x11d2, \ - {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} - - -/** - * A nsINameSpace registers the NameSpace URI with the NameSpaceManager - * (creating or finding an ID), and manages the relationship between - * the NameSpace ID and the (optional) Prefix. - * - * New NameSpaces are created as a child of an existing NameSpace. Searches - * for NameSpaces based on prefix search up the chain of nested NameSpaces - * - * Each NameSpace keeps a live reference on its parent and its Manager. - * - */ -class nsINameSpace : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_INAMESPACE_IID; return iid; } - - NS_IMETHOD GetNameSpaceManager(nsINameSpaceManager*& aManager) const = 0; - - // Get data of this name space - NS_IMETHOD GetNameSpaceID(PRInt32& aID) const = 0; - NS_IMETHOD GetNameSpaceURI(nsAWritableString& aURI) const = 0; - NS_IMETHOD GetNameSpacePrefix(nsIAtom*& aPrefix) const = 0; - - NS_IMETHOD GetParentNameSpace(nsINameSpace*& aParent) const = 0; - - // find name space within self and parents (not children) - NS_IMETHOD FindNameSpace(nsIAtom* aPrefix, nsINameSpace*& aNameSpace) const = 0; - NS_IMETHOD FindNameSpaceID(nsIAtom* aPrefix, PRInt32& aNameSpaceID) const = 0; - NS_IMETHOD FindNameSpacePrefix(PRInt32 aNameSpaceID, nsIAtom*& aPrefix) const = 0; - - // create new child name space - NS_IMETHOD CreateChildNameSpace(nsIAtom* aPrefix, - const nsAReadableString& aURI, - nsINameSpace*& aChildNameSpace) = 0; - - NS_IMETHOD CreateChildNameSpace(nsIAtom* aPrefix, PRInt32 aNameSpaceID, - nsINameSpace*& aChildNameSpace) = 0; -}; - -#endif // nsINameSpace_h___ diff --git a/layout/base/public/nsINameSpaceManager.h b/layout/base/public/nsINameSpaceManager.h deleted file mode 100644 index 726ffa9422af..000000000000 --- a/layout/base/public/nsINameSpaceManager.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsINameSpaceManager_h___ -#define nsINameSpaceManager_h___ - -#include "nsISupports.h" -#include "nslayout.h" -#include "nsAWritableString.h" - -class nsIAtom; -class nsString; -class nsINameSpace; - -#define kNameSpaceID_Unknown -1 -#define kNameSpaceID_None 0 -#define kNameSpaceID_XMLNS 1 // not really a namespace, but it needs to play the game -#define kNameSpaceID_XML 2 -#define kNameSpaceID_HTML 3 -#define kNameSpaceID_XLink 4 - -// 'html' is by definition bound to the namespace name "urn:w3-org-ns:HTML" XXX ??? -// 'xml' is by definition bound to the namespace name "urn:Connolly:input:required" XXX - -#define NS_INAMESPACEMANAGER_IID \ - { 0xa6cf90d5, 0x15b3, 0x11d2, \ - {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} - -/** - * The Name Space Manager tracks the associtation between a NameSpace - * URI and the PRInt32 runtime id. Mappings between NameSpaces and - * NameSpace prefixes are managed by nsINameSpaces - * - * All NameSpace URIs are stored in a global table so that IDs are - * consistent accross the app. NameSpace IDs are only consistent at runtime - * ie: they are not guaranteed to be consistent accross app sessions. - * - * The nsINameSpaceManager needs to have a live reference for as long as - * the NameSpace IDs are needed. Generally, a document keeps a reference to - * a nsINameSpaceManager. Also, each nsINameSpace that comes from the manager - * keeps a reference to it. - * - * To create a stack of NameSpaces, call CreateRootNameSpace, and then create - * child NameSpaces from the root. - * - * The "html" and "xml" namespaces come "pre-canned" from the root. - * - */ -class nsINameSpaceManager : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_INAMESPACEMANAGER_IID; return iid; } - - NS_IMETHOD CreateRootNameSpace(nsINameSpace*& aRootNameSpace) = 0; - - NS_IMETHOD RegisterNameSpace(const nsAReadableString& aURI, - PRInt32& aNameSpaceID) = 0; - - NS_IMETHOD GetNameSpaceURI(PRInt32 aNameSpaceID, nsAWritableString& aURI) = 0; - NS_IMETHOD GetNameSpaceID(const nsAReadableString& aURI, PRInt32& aNameSpaceID) = 0; -}; - -extern NS_LAYOUT nsresult - NS_NewNameSpaceManager(nsINameSpaceManager** aInstancePtrResult); - - -#endif // nsINameSpaceManager_h___ diff --git a/layout/base/public/nsINodeInfo.h b/layout/base/public/nsINodeInfo.h deleted file mode 100644 index e56d1a47d53f..000000000000 --- a/layout/base/public/nsINodeInfo.h +++ /dev/null @@ -1,234 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -/* - * nsINodeInfo is an interface to node info, such as name, prefix, namespace - * ID and possibly other data that is shared between nodes (elements - * and attributes) that have the same name, prefix and namespace ID within - * the same document. - * - * nsINodeInfoManager is an interface to an object that manages a list of - * nsINodeInfo's, every document object should hold a strong reference to - * a nsINodeInfoManager and every nsINodeInfo also holds a strong reference - * to their owning manager. When a nsINodeInfo is no longer used it will - * automatically remove itself from its owner manager, and when all - * nsINodeInfo's have been removed from a nsINodeInfoManager and all external - * references are released the nsINodeInfoManager deletes itself. - * - * -- jst@netscape.com - */ - -#ifndef nsINodeInfo_h___ -#define nsINodeInfo_h___ - -#include "nsISupports.h" -#include "nsAWritableString.h" - -// Forward declarations -class nsIAtom; -class nsINodeInfoManager; -class nsINameSpaceManager; -class nsString; - - -// IID for the nsINodeInfo interface -#define NS_INODEINFO_IID \ -{ 0x93dbfd8c, 0x2fb3, 0x4ef5, \ - {0xa2, 0xa0, 0xcf, 0xf2, 0x69, 0x6f, 0x07, 0x88} } - -// IID for the nsINodeInfoManager interface -#define NS_INODEINFOMANAGER_IID \ -{ 0xb622469b, 0x4dcf, 0x45c4, \ - {0xb0, 0xb9, 0xa7, 0x32, 0xbc, 0xee, 0xa5, 0xcc} } - -#define NS_NODEINFOMANAGER_CONTRACTID "@mozilla.org/layout/nodeinfomanager;1" - - -class nsINodeInfo : public nsISupports -{ -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_INODEINFO_IID) - - /* - * Get the name from this node as a string, this does not include the prefix. - * - * For the HTML element "" this will return "body" and for the XML - * element "" this will return "body". - */ - NS_IMETHOD GetName(nsAWritableString& aName) = 0; - - /* - * Get the name from this node as an atom, this does not include the prefix. - * This function never returns a null atom. - * - * For the HTML element "" this will return the "body" atom and for - * the XML element "" this will return the "body" atom. - */ - NS_IMETHOD GetNameAtom(nsIAtom*& aAtom) = 0; - - /* - * Get the qualified name from this node as a string, the qualified name - * includes the prefix, if one exists. - * - * For the HTML element "" this will return "body" and for the XML - * element "" this will return "html:body". - */ - NS_IMETHOD GetQualifiedName(nsAWritableString& aQualifiedName) = 0; - - /* - * Get the local name from this node as a string, GetLocalName() gets the - * same string as GetName() but only if the node has a prefix and/or a - * namespace URI. If the node has neither a prefix nor a namespace URI the - * local name is a null string. - * - * For the HTML element "" in a HTML document this will return a null - * string and for the XML element "" this will return "body". - */ - NS_IMETHOD GetLocalName(nsAWritableString& aLocalName) = 0; - - /* - * Get the prefix from this node as a string. - * - * For the HTML element "" this will return a null string and for - * the XML element "" this will return the string "html". - */ - NS_IMETHOD GetPrefix(nsAWritableString& aPrefix) = 0; - - /* - * Get the prefix from this node as an atom. - * - * For the HTML element "" this will return a null atom and for - * the XML element "" this will return the "html" atom. - */ - NS_IMETHOD GetPrefixAtom(nsIAtom*& aAtom) = 0; - - /* - * Get the namespace URI for a node, if the node has a namespace URI. - * - * For the HTML element "" in a HTML document this will return a null - * string and for the XML element "" (assuming that this element, - * or one of it's ancestors has an - * xmlns:html='http://www.w3.org/1999/xhtml' attribute) this will return - * the string "http://www.w3.org/1999/xhtml". - */ - NS_IMETHOD GetNamespaceURI(nsAWritableString& aNameSpaceURI) = 0; - - /* - * Get the namespace ID for a node if the node has a namespace, if not this - * returns kNameSpaceID_None. - * - * For the HTML element "" in a HTML document this will return - * kNameSpaceID_None and for the XML element "" (assuming that - * this element, or one of it's ancestors has an - * xmlns:html='http://www.w3.org/1999/xhtml' attribute) this will return - * the namespace ID for "http://www.w3.org/1999/xhtml". - */ - NS_IMETHOD GetNamespaceID(PRInt32& aResult) = 0; - - /* - * Get and set the ID attribute atom for this node. - * See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types - * for the definition of an ID attribute. - * - */ - NS_IMETHOD GetIDAttributeAtom(nsIAtom** aResult) = 0; - NS_IMETHOD SetIDAttributeAtom(nsIAtom* aResult) = 0; - - /* - * Get the owning node info manager, this will never return null. - */ - NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) = 0; - - /* - * Utility functions that can be used to check if a nodeinfo holds a specific - * name, name and prefix, name and prefix and namespace ID, or just - * namespace ID. - */ - NS_IMETHOD_(PRBool) Equals(nsINodeInfo *aNodeInfo) = 0; - NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom) = 0; - NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName) = 0; - NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom) = 0; - NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName, - const nsAReadableString& aPrefix) = 0; - NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom, PRInt32 aNamespaceID) = 0; - NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName, PRInt32 aNamespaceID) = 0; - NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom, - PRInt32 aNamespaceID) = 0; - NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName, - const nsAReadableString& aPrefix, - PRInt32 aNamespaceID) = 0; - NS_IMETHOD_(PRBool) NamespaceEquals(PRInt32 aNamespaceID) = 0; - NS_IMETHOD_(PRBool) NamespaceEquals(const nsAReadableString& aNamespaceURI) = 0; - NS_IMETHOD_(PRBool) QualifiedNameEquals(const nsAReadableString& aQualifiedName) = 0; - - /* - * This is a convinience method that creates a new nsINodeInfo that differs - * only by name from the one this is called on. - */ - NS_IMETHOD NameChanged(nsIAtom *aName, nsINodeInfo*& aResult) = 0; - - /* - * This is a convinience method that creates a new nsINodeInfo that differs - * only by prefix from the one this is called on. - */ - NS_IMETHOD PrefixChanged(nsIAtom *aPrefix, nsINodeInfo*& aResult) = 0; -}; - - -class nsINodeInfoManager : public nsISupports -{ -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_INODEINFOMANAGER_IID) - - /* - * Initialize the nodeinfo manager with a namespace manager, this should - * allways be done. - */ - NS_IMETHOD Init(nsINameSpaceManager *aNameSpaceManager) = 0; - - /* - * Methods for creating nodeinfo's from atoms and/or strings. - */ - NS_IMETHOD GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, - PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo) = 0; - NS_IMETHOD GetNodeInfo(const nsAReadableString& aName, nsIAtom *aPrefix, - PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo) = 0; - NS_IMETHOD GetNodeInfo(const nsAReadableString& aName, - const nsAReadableString& aPrefix, - PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo) = 0; - NS_IMETHOD GetNodeInfo(const nsAReadableString& aName, - const nsAReadableString& aPrefix, - const nsAReadableString& aNamespaceURI, - nsINodeInfo*& aNodeInfo) = 0; - NS_IMETHOD GetNodeInfo(const nsAReadableString& aQualifiedName, - const nsAReadableString& aNamespaceURI, - nsINodeInfo*& aNodeInfo) = 0; - - /* - * Getter for the namespace manager used by this nodeinfo manager. - */ - NS_IMETHOD GetNamespaceManager(nsINameSpaceManager*& aNameSpaceManager) = 0; -}; - -extern nsresult NS_NewNodeInfoManager(nsINodeInfoManager** aResult); - -#endif /* nsINodeInfo_h___ */ diff --git a/layout/base/public/nsIPrivateDOMImplementation.h b/layout/base/public/nsIPrivateDOMImplementation.h deleted file mode 100644 index 54d4d581ce76..000000000000 --- a/layout/base/public/nsIPrivateDOMImplementation.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsIPrivateDOMImplementation_h__ -#define nsIPrivateDOMImplementation_h__ - -#include "nsISupports.h" - -class nsIURI; - -/* - * Event listener manager interface. - */ -#define NS_IPRIVATEDOMIMPLEMENTATION_IID \ -{ /* d3205fb8-2652-11d4-ba06-0060b0fc76dd */ \ -0xd3205fb8, 0x2652, 0x11d4, \ -{0xba, 0x06, 0x00, 0x60, 0xb0, 0xfc, 0x76, 0xdd} } - -class nsIPrivateDOMImplementation : public nsISupports { - -public: - static const nsIID& GetIID() { static nsIID iid = NS_IPRIVATEDOMIMPLEMENTATION_IID; return iid; } - - NS_IMETHOD Init(nsIURI* aBaseURI) = 0; -}; - -NS_LAYOUT nsresult -NS_NewDOMImplementation(nsIDOMDOMImplementation** aInstancePtrResult); - -#endif // nsIPrivateDOMImplementation_h__ diff --git a/layout/base/public/nsISelection.idl b/layout/base/public/nsISelection.idl deleted file mode 100644 index 92e056db32f6..000000000000 --- a/layout/base/public/nsISelection.idl +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsISupports.idl" -#include "domstubs.idl" -#include "nsISelectionListener.idl" -#include "nsIEnumerator.idl" - -%{C++ -class nsIDOMNode; -class nsIDOMRange; -class nsISelectionListener; -%} - -[scriptable, uuid(B2C7ED59-8634-4352-9E37-5484C8B6E4E1)] -interface nsISelection : nsISupports - { - readonly attribute nsIDOMNode anchorNode; - readonly attribute long anchorOffset; - - readonly attribute nsIDOMNode focusNode; - readonly attribute long focusOffset; - - readonly attribute boolean isCollapsed; - - readonly attribute long rangeCount; - - nsIDOMRange getRangeAt(in long index); - - void collapse(in nsIDOMNode parentNode, in long offset); - void extend(in nsIDOMNode parentNode, in long offset); - - void collapseToStart(); - void collapseToEnd(); - - boolean containsNode(in nsIDOMNode node, in boolean recursive); - - void selectAllChildren(in nsIDOMNode parentNode); - - void addRange(in nsIDOMRange range); - void removeRange(in nsIDOMRange range); - void removeAllRanges(); - - void deleteFromDocument(); - - wstring toString(); -}; diff --git a/layout/base/public/nsISelectionControler.h b/layout/base/public/nsISelectionControler.h deleted file mode 100644 index f83cb8a4a7c7..000000000000 --- a/layout/base/public/nsISelectionControler.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -/* - * !!Note this is for a javascriptable pres shell currently for accessing selection - * the selection refers only to that which listens to keybindings which is the "NORMAL" - * selection this will be IDLIZED LATER - */ - -#ifndef nsISelectionControler_h___ -#define nsISelectionControler_h___ - -#include "nsISupports.h" - - -#define NS_ISELECTIONCONTROLER_IID_STR "D2D1D179-85A7-11d3-9932-00108301233C" - -#define NS_ISELECTIONCONTROLER_IID \ -{ 0xd2d1d179, 0x85a7, 0x11d3, \ -{ 0x99, 0x32, 0x0, 0x10, 0x83, 0x1, 0x23, 0x3c }} - - -class nsISelectionControler : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_ISELECTIONCONTROLER_IID; return iid; } - - /** CharacterMove will move the selection one character forward/backward in the document. - * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE - * the "point" of selection that is extended is considered the "focus" point. - * or the last point adjusted by the selection. - * @param aForward forward or backward if PR_FALSE - * @param aExtend should it collapse the selection of extend it? - */ - NS_IMETHOD CharacterMove(PRBool aForward, PRBool aExtend) = 0; - - /** WordMove will move the selection one word forward/backward in the document. - * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE - * the "point" of selection that is extended is considered the "focus" point. - * or the last point adjusted by the selection. - * @param aForward forward or backward if PR_FALSE - * @param aExtend should it collapse the selection of extend it? - */ - NS_IMETHOD WordMove(PRBool aForward, PRBool aExtend) = 0; - - /** LineMove will move the selection one line forward/backward in the document. - * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE - * the "point" of selection that is extended is considered the "focus" point. - * or the last point adjusted by the selection. - * @param aForward forward or backward if PR_FALSE - * @param aExtend should it collapse the selection of extend it? - */ - NS_IMETHOD LineMove(PRBool aForward, PRBool aExtend) = 0; - - /** IntraLineMove will move the selection to the front of the line or end of the line - * in the document. - * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE - * the "point" of selection that is extended is considered the "focus" point. - * or the last point adjusted by the selection. - * @param aForward forward or backward if PR_FALSE - * @param aExtend should it collapse the selection of extend it? - */ - NS_IMETHOD IntraLineMove(PRBool aForward, PRBool aExtend) = 0; - - /** PageMove will move the selection one page forward/backward in the document. - * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE - * the "point" of selection that is extended is considered the "focus" point. - * or the last point adjusted by the selection. - * @param aForward forward or backward if PR_FALSE - * @param aExtend should it collapse the selection of extend it? - */ - NS_IMETHOD PageMove(PRBool aForward, PRBool aExtend) = 0; - - /** ScrollPage will scroll the page without affecting the selection. - * @param aForward scroll forward or backwards in selection - */ - NS_IMETHOD ScrollPage(PRBool aForward) = 0; - - /** SelectAll will select the whole page - */ - NS_IMETHOD SelectAll() = 0; -}; - - - -#endif /* nsISelectionControler_h___ */ diff --git a/layout/base/public/nsISelectionController.idl b/layout/base/public/nsISelectionController.idl deleted file mode 100644 index 158933213a8b..000000000000 --- a/layout/base/public/nsISelectionController.idl +++ /dev/null @@ -1,233 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Sammy Ford - */ - - -#include "nsISupports.idl" -#include "domstubs.idl" -#include "nsISelection.idl" - -%{C++ - -class nsISelection; -typedef short SelectionType; -typedef short SelectionRegion; -class nsIDOMNode; -%} - - -[scriptable, uuid(D2D1D179-85A7-11d3-9932-00108301233C)] -interface nsISelectionController : nsISupports -{ - const short SELECTION_NONE=0; - const short SELECTION_NORMAL=1; - const short SELECTION_SPELLCHECK=2; - const short SELECTION_IME_RAWINPUT=4; - const short SELECTION_IME_SELECTEDRAWTEXT=8; - const short SELECTION_IME_CONVERTEDTEXT=16; - const short SELECTION_IME_SELECTEDCONVERTEDTEXT=32; - const short NUM_SELECTIONTYPES=6; - - - const short SELECTION_ANCHOR_REGION = 0; - const short SELECTION_FOCUS_REGION = 1; - const short NUM_SELECTION_REGIONS = 2; - - const short SELECTION_OFF = 0; - const short SELECTION_HIDDEN =1;//>HIDDEN displays selection - const short SELECTION_ON = 2; - const short SELECTION_DISABLED = 3; - - /** - * SetDisplaySelection will set the display mode for the selection. OFF,ON,DISABLED - */ - void setDisplaySelection(in short toggle); - - /** - * GetDisplaySelection will get the display mode for the selection. OFF,ON,DISABLED - */ - short getDisplaySelection(); - - /** - * SetDisplayNonTextSelection used to set whether you want to see HRULES/IMAGES with border. - * also used to tell if the presshell is an editor right now. this should change - */ - void setDisplayNonTextSelection(in boolean toggle); - - /** - * GetDisplayNonTextSelection used to get whether you want to see HRULES/IMAGES with border. - * also used to tell if the presshell is an editor right now. this should change - */ - boolean getDisplayNonTextSelection(); - - /** - * GetSelection will return the selection that the presentation - * shell may implement. - * - * @param aType will hold the type of selection //SelectionType - * @param _return will hold the return value - */ - nsISelection getSelection(in short type); - - /** - * ScrollSelectionIntoView scrolls a region of the selection, - * so that it is visible in the scrolled view. - * - * @param aType the selection to scroll into view. //SelectionType - * @param aRegion the region inside the selection to scroll into view. //SelectionRegion - */ - void scrollSelectionIntoView(in short type, in short region); - /** - * RepaintSelection repaints the selection specified by aType. - * - * @param aType specifies the selection to repaint. - */ - void repaintSelection(in short type); - - /** - * Set the caret as enabled or disabled. An enabled caret will - * draw or blink when made visible. A disabled caret will never show up. - * Can be called any time. - * @param aEnable PR_TRUE to enable caret. PR_FALSE to disable. - * @return always NS_OK - */ - - void setCaretEnabled(in boolean enabled); - /** - * Set the carets width - * Can be called any time. - * @param pixels, the width of the caret in pixels - * @return always NS_OK if successful, NS_ERROR_FAILURE if not. - */ - void setCaretWidth(in short pixels); - - /** - * Set the caret readonly or not. An readonly caret will - * draw but not blink when made visible. - * @param aReadOnly PR_TRUE to enable caret. PR_FALSE to disable. - * @return always NS_OK - */ - void setCaretReadOnly(in boolean readOnly); - - /** - * Gets the current state of the caret. - * @param aEnabled [OUT] set to the current caret state, as set by SetCaretEnabled - * @return if aOutEnabled==null, returns NS_ERROR_INVALID_ARG - * else NS_OK - */ - boolean getCaretEnabled(); - - /** CharacterMove will move the selection one character forward/backward in the document. - * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE - * the "point" of selection that is extended is considered the "focus" point. - * or the last point adjusted by the selection. - * @param aForward forward or backward if PR_FALSE - * @param aExtend should it collapse the selection of extend it? - */ - void characterMove(in boolean forward, in boolean extend); - - /** WordMove will move the selection one word forward/backward in the document. - * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE - * the "point" of selection that is extended is considered the "focus" point. - * or the last point adjusted by the selection. - * @param aForward forward or backward if PR_FALSE - * @param aExtend should it collapse the selection of extend it? - */ - - void wordMove(in boolean forward, in boolean extend); - - /** LineMove will move the selection one line forward/backward in the document. - * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE - * the "point" of selection that is extended is considered the "focus" point. - * or the last point adjusted by the selection. - * @param aForward forward or backward if PR_FALSE - * @param aExtend should it collapse the selection of extend it? - */ - void lineMove(in boolean forward, in boolean extend); - - /** IntraLineMove will move the selection to the front of the line or end of the line - * in the document. - * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE - * the "point" of selection that is extended is considered the "focus" point. - * or the last point adjusted by the selection. - * @param aForward forward or backward if PR_FALSE - * @param aExtend should it collapse the selection of extend it? - */ - void intraLineMove(in boolean forward, in boolean extend); - - /** PageMove will move the selection one page forward/backward in the document. - * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE - * the "point" of selection that is extended is considered the "focus" point. - * or the last point adjusted by the selection. - * @param aForward forward or backward if PR_FALSE - * @param aExtend should it collapse the selection of extend it? - */ - void pageMove(in boolean forward, in boolean extend); - - /** CompleteScroll will move page view to the top or bottom of the document - * @param aForward forward or backward if PR_FALSE - */ - void completeScroll(in boolean forward); - - /** CompleteMove will move page view to the top or bottom of the document - * this will also have the effect of collapsing the selection if the aExtend = PR_FALSE - * the "point" of selection that is extended is considered the "focus" point. - * or the last point adjusted by the selection. - * @param aForward forward or backward if PR_FALSE - * @param aExtend should it collapse the selection of extend it? - */ - void completeMove(in boolean forward, in boolean extend); - - - /** ScrollPage will scroll the page without affecting the selection. - * @param aForward scroll forward or backwards in selection - */ - void scrollPage(in boolean forward); - - /** ScrolLine will scroll line up or down dependent on the boolean - * @param aForward scroll forward or backwards in selection - */ - void scrollLine(in boolean forward); - - /** ScrolHorizontal will scroll left or right dependent on the boolean - * @param aLeft if true will scroll left. if not will scroll right. - */ - void scrollHorizontal(in boolean left); - /** SelectAll will select the whole page - */ - void selectAll(); - - /** CheckVisibility will return true if textnode and offsets are actually rendered - * in the current precontext. - * @param aNode textNode to test - * @param aStartOffset offset in dom to first char of textnode to test - * @param aEndOffset offset in dom to last char of textnode to test - * @param aReturnBool boolean returned TRUE if visible FALSE if not - */ - boolean checkVisibility(in nsIDOMNode node, in short startOffset, in short endOffset); - -}; -%{ C++ - #define NS_ISELECTIONCONTROLLER_CID \ - { 0xd2d1d179, 0x85a7, 0x11d3, \ - { 0x99, 0x32, 0x0, 0x10, 0x83, 0x1, 0x23, 0x3c }} -%} diff --git a/layout/base/public/nsISelectionListener.idl b/layout/base/public/nsISelectionListener.idl deleted file mode 100644 index 75fb535dfac1..000000000000 --- a/layout/base/public/nsISelectionListener.idl +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsISupports.idl" -#include "domstubs.idl" - -%{C++ -class nsIDOMDocument; -%} -interface nsISelection; - -[scriptable, uuid(A6CF90E2-15B3-11d2-932E-00805F8ADD32)] -interface nsISelectionListener : nsISupports -{ - const short NO_REASON=0; - const short DRAG_REASON=1; - const short MOUSEDOWN_REASON=2;/*bitflags*/ - const short MOUSEUP_REASON=4;/*bitflags*/ - const short KEYPRESS_REASON=8;/*bitflags*/ - const short SELECTALL_REASON=16; - - void notifySelectionChanged(in nsIDOMDocument doc, in nsISelection sel, in short reason); -}; - - diff --git a/layout/base/public/nsISelectionPrivate.idl b/layout/base/public/nsISelectionPrivate.idl deleted file mode 100644 index ec3a409de2e5..000000000000 --- a/layout/base/public/nsISelectionPrivate.idl +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsISupports.idl" -#include "domstubs.idl" -#include "nsISelectionListener.idl" -#include "nsIEnumerator.idl" - -%{C++ -class nsIDOMNode; -class nsIDOMRange; -class nsISelectionListener; -%} - -[scriptable, uuid(2d5535e2-1dd2-11b2-8e38-d53ec833adf6)] -interface nsISelectionPrivate : nsISupports - { - const short ENDOFPRECEDINGLINE=0; - const short STARTOFNEXTLINE=1; - - attribute boolean interlinePosition; - - /* startBatchChanges - match this up with endbatchChanges. will stop ui updates while multiple selection methods are called - */ - void startBatchChanges(); - - /* endBatchChanges - match this up with startBatchChanges - */ - void endBatchChanges(); - - nsIEnumerator getEnumerator(); - wstring toStringWithFormat(in string formatType, in unsigned long flags, in PRInt32 wrapColumn); - void addSelectionListener(in nsISelectionListener newListener); - void removeSelectionListener(in nsISelectionListener listenerToRemove); - - /* Table selection stuff - We should probably move this and table-related - items in nsIFrameSelection to a - new nsITableSelection interface - */ - const long TABLESELECTION_NONE = 0; - const long TABLESELECTION_CELL = 1; - const long TABLESELECTION_ROW = 2; - const long TABLESELECTION_COLUMN = 3; - const long TABLESELECTION_TABLE = 4; - const long TABLESELECTION_ALLCELLS = 5; - - /** Test if supplied range points to a single table element: - * Result is one of above constants. "None" means - * a table element isn't selected. - */ - long getTableSelectionType(in nsIDOMRange range); -}; - diff --git a/layout/base/public/nsIStyleRule.h b/layout/base/public/nsIStyleRule.h deleted file mode 100644 index 4de54696d92a..000000000000 --- a/layout/base/public/nsIStyleRule.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsIStyleRule_h___ -#define nsIStyleRule_h___ - -#include - -#include "nslayout.h" -#include "nsISupports.h" - -class nsISizeOfHandler; - -class nsIStyleSheet; -class nsIMutableStyleContext; -class nsIPresContext; -class nsIContent; - -// IID for the nsIStyleRule interface {40ae5c90-ad6a-11d1-8031-006008159b5a} -#define NS_ISTYLE_RULE_IID \ -{0x40ae5c90, 0xad6a, 0x11d1, {0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}} - -class nsIStyleRule : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_ISTYLE_RULE_IID; return iid; } - - NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const = 0; - - // Strength is an out-of-band weighting, useful for mapping CSS ! important - NS_IMETHOD GetStrength(PRInt32& aStrength) const = 0; - - // Map only font data into style context - NS_IMETHOD MapFontStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext) = 0; - // Map all non-font info into style context - NS_IMETHOD MapStyleInto(nsIMutableStyleContext* aContext, nsIPresContext* aPresContext) = 0; - - NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0; - - virtual void SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize) = 0; -}; - - -#endif /* nsIStyleRule_h___ */ diff --git a/layout/base/public/nsIStyleRuleProcessor.h b/layout/base/public/nsIStyleRuleProcessor.h deleted file mode 100644 index 89c0d5598d22..000000000000 --- a/layout/base/public/nsIStyleRuleProcessor.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsIStyleRuleProcessor_h___ -#define nsIStyleRuleProcessor_h___ - -#include - -#include "nslayout.h" -#include "nsISupports.h" - -class nsISizeOfHandler; - -class nsIStyleSheet; -class nsIStyleContext; -class nsIPresContext; -class nsIContent; -class nsISupportsArray; -class nsIAtom; -class nsICSSPseudoComparator; - -// IID for the nsIStyleRuleProcessor interface {015575fe-7b6c-11d3-ba05-001083023c2b} -#define NS_ISTYLE_RULE_PROCESSOR_IID \ -{0x015575fe, 0x7b6c, 0x11d3, {0xba, 0x05, 0x00, 0x10, 0x83, 0x02, 0x3c, 0x2b}} - -/* The style rule processor interface is a mechanism to seperate the matching - * of style rules from style sheet instances. - * Simple style sheets can and will act as their own processor. - * Sheets where rule ordering interlaces between multiple sheets, will need to - * share a single rule processor between them (CSS sheets do this for cascading order) - */ -class nsIStyleRuleProcessor : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_ISTYLE_RULE_PROCESSOR_IID; return iid; } - - // populate supports array with nsIStyleRule* - // rules are ordered, those with higher precedence come last - NS_IMETHOD RulesMatching(nsIPresContext* aPresContext, - nsIAtom* aMedium, - nsIContent* aContent, - nsIStyleContext* aParentContext, - nsISupportsArray* aResults) = 0; - - NS_IMETHOD RulesMatching(nsIPresContext* aPresContext, - nsIAtom* aMedium, - nsIContent* aParentContent, - nsIAtom* aPseudoTag, - nsIStyleContext* aParentContext, - nsICSSPseudoComparator* aComparator, - nsISupportsArray* aResults) = 0; - - // Test if style is dependent on content state - NS_IMETHOD HasStateDependentStyle(nsIPresContext* aPresContext, - nsIAtom* aMedium, - nsIContent* aContent) = 0; - - virtual void SizeOf(nsISizeOfHandler *aSizeofHandler, PRUint32 &aSize) = 0; -}; - -#endif /* nsIStyleRuleProcessor_h___ */ diff --git a/layout/base/public/nsIStyleRuleSupplier.h b/layout/base/public/nsIStyleRuleSupplier.h deleted file mode 100644 index e00c7f03ec03..000000000000 --- a/layout/base/public/nsIStyleRuleSupplier.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _nsIStyleRuleSupplier_h -#define _nsIStyleRuleSupplier_h - -#include "nsISupports.h" -#include "nsISupportsArray.h" - -// {2D77A45B-4F3A-4203-A7D2-F4B84D0C1EE4} -#define NS_ISTYLERULESUPPLIER_IID \ -{ 0x2d77a45b, 0x4f3a, 0x4203, { 0xa7, 0xd2, 0xf4, 0xb8, 0x4d, 0xc, 0x1e, 0xe4 } } - -class nsIContent; -class nsIStyleSet; - -class nsIStyleRuleSupplier : public nsISupports { - public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISTYLERULESUPPLIER_IID) - - NS_IMETHOD UseDocumentRules(nsIContent* aContent, PRBool* aResult)=0; - NS_IMETHOD WalkRules(nsIStyleSet* aStyleSet, - nsISupportsArrayEnumFunc aFunc, void* aData, - nsIContent* aContent)=0; -}; - -#endif /* _nsIStyleRuleSupplier_h */ diff --git a/layout/base/public/nsIStyleSheet.h b/layout/base/public/nsIStyleSheet.h deleted file mode 100644 index a69e99ccd685..000000000000 --- a/layout/base/public/nsIStyleSheet.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsIStyleSheet_h___ -#define nsIStyleSheet_h___ - -#include -#include "nsISupports.h" - -class nsISizeOfHandler; - -class nsIAtom; -class nsString; -class nsIURI; -class nsIStyleRule; -class nsISupportsArray; -class nsIPresContext; -class nsIContent; -class nsIDocument; -class nsIStyleContext; -class nsIStyleRuleProcessor; - -// IID for the nsIStyleSheet interface {8c4a80a0-ad6a-11d1-8031-006008159b5a} -#define NS_ISTYLE_SHEET_IID \ -{0x8c4a80a0, 0xad6a, 0x11d1, {0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}} - -class nsIStyleSheet : public nsISupports { -public: - static const nsIID& GetIID() { static nsIID iid = NS_ISTYLE_SHEET_IID; return iid; } - - // basic style sheet data - NS_IMETHOD GetURL(nsIURI*& aURL) const = 0; - NS_IMETHOD GetTitle(nsString& aTitle) const = 0; - NS_IMETHOD GetType(nsString& aType) const = 0; - NS_IMETHOD GetMediumCount(PRInt32& aCount) const = 0; - NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const = 0; - NS_IMETHOD UseForMedium(nsIAtom* aMedium) const = 0; - - NS_IMETHOD GetEnabled(PRBool& aEnabled) const = 0; - NS_IMETHOD SetEnabled(PRBool aEnabled) = 0; - - // style sheet owner info - NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const = 0; // may be null - NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const = 0; // may be null - NS_IMETHOD SetOwningDocument(nsIDocument* aDocument) = 0; - - // style rule processor access - NS_IMETHOD GetStyleRuleProcessor(nsIStyleRuleProcessor*& aProcessor, - nsIStyleRuleProcessor* aPrevProcessor) = 0; - - // XXX style rule enumerations - - virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0; - - virtual void SizeOf(nsISizeOfHandler *aSizeofHandler, PRUint32 &aSize) = 0; - - // If changing the given attribute cannot affect style context, aAffects - // will be PR_FALSE on return. - NS_IMETHOD AttributeAffectsStyle(nsIAtom *aAttribute, nsIContent *aContent, - PRBool &aAffects) = 0; -}; - -#endif /* nsIStyleSheet_h___ */ diff --git a/layout/base/public/nsIStyleSheetLinkingElement.h b/layout/base/public/nsIStyleSheetLinkingElement.h deleted file mode 100644 index 1f2d049aa33a..000000000000 --- a/layout/base/public/nsIStyleSheetLinkingElement.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsIStyleSheetLinkingElement_h__ -#define nsIStyleSheetLinkingElement_h__ - - -#include "nsISupports.h" - -#define NS_ISTYLESHEETLINKINGELEMENT_IID \ - {0xa6cf90e9, 0x15b3, 0x11d2, \ - {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} - -class nsIStyleSheet; - -class nsIStyleSheetLinkingElement : public nsISupports { -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISTYLESHEETLINKINGELEMENT_IID) - - /** - * Used to make the association between a style sheet and - * the element that linked it to the document. - * - * @param aStyleSheet the style sheet associated with this - * element. - */ - NS_IMETHOD SetStyleSheet(nsIStyleSheet* aStyleSheet) = 0; - - /** - * Used to obtain the style sheet linked in by this element. - * - * @param aStyleSheet out parameter that returns the style - * sheet associated with this element. - */ - NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet) = 0; -}; - -#endif // nsILinkingElement_h__ diff --git a/layout/base/public/nsIStyledContent.h b/layout/base/public/nsIStyledContent.h deleted file mode 100644 index 51193223bef4..000000000000 --- a/layout/base/public/nsIStyledContent.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsIStyledContent_h___ -#define nsIStyledContent_h___ - -#include "nsIContent.h" - -class nsString; -class nsIStyleRule; -class nsIStyleContext; -class nsISupportsArray; - -// IID for the nsIStyledContent class -#define NS_ISTYLEDCONTENT_IID \ -{ 0xc1e84e01, 0xcd15, 0x11d2, { 0x96, 0xed, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } } - -// Abstract interface for all styled content (that supports ID, CLASS, STYLE, and -// the ability to specify style hints on an attribute change). -class nsIStyledContent : public nsIContent { -public: - static const nsIID& GetIID() { static nsIID iid = NS_ISTYLEDCONTENT_IID; return iid; } - - NS_IMETHOD GetID(nsIAtom*& aResult) const = 0; - NS_IMETHOD GetClasses(nsVoidArray& aArray) const = 0; - NS_IMETHOD HasClass(nsIAtom* aClass) const = 0; - - NS_IMETHOD GetContentStyleRules(nsISupportsArray* aRules) = 0; - NS_IMETHOD GetInlineStyleRules(nsISupportsArray* aRules) = 0; - - /** NRA *** - * Get a hint that tells the style system what to do when - * an attribute on this node changes. - * This only applies to attributes that map their value - * DIRECTLY into style contexts via NON-CSS style rules - * Only HTML currently does this. - * All other attributes return NS_STYLE_HINT_CONTENT - */ - NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute, - PRInt32& aHint) const = 0; - -}; - -#endif /* nsIStyledContent_h___ */ diff --git a/layout/base/public/nsITextContent.h b/layout/base/public/nsITextContent.h deleted file mode 100644 index 108e94b5e6f9..000000000000 --- a/layout/base/public/nsITextContent.h +++ /dev/null @@ -1,135 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsITextContent_h___ -#define nsITextContent_h___ - -#include "nslayout.h" -#include "nsIContent.h" -class nsString; -class nsTextFragment; - -// IID for the nsITextContent interface -#define NS_ITEXT_CONTENT_IID \ - {0xa6cf9065, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} - -/** - * Interface for textual content. This interface is used to provide - * an efficient access to text content. - */ -class nsITextContent : public nsIContent { -public: - static const nsIID& GetIID() { static nsIID iid = NS_ITEXT_CONTENT_IID; return iid; } - - /** - * Get direct access (but read only) to the text in the text content. - */ - NS_IMETHOD GetText(const nsTextFragment** aFragmentsResult) = 0; - - /** - * Get the length of the text content. - */ - NS_IMETHOD GetTextLength(PRInt32* aLengthResult) = 0; - - /** - * Make a copy of the text content in aResult. - */ - NS_IMETHOD CopyText(nsAWritableString& aResult) = 0; - - /** - * Set the text to the given value. If aNotify is PR_TRUE then - * the document is notified of the content change. - */ - NS_IMETHOD SetText(const PRUnichar* aBuffer, - PRInt32 aLength, - PRBool aNotify) = 0; - - /** - * Set the text to the given value. If aNotify is PR_TRUE then - * the document is notified of the content change. - */ - NS_IMETHOD SetText(const nsAReadableString& aStr, - PRBool aNotify) = 0; - - /** - * Set the text to the given value. If aNotify is PR_TRUE then - * the document is notified of the content change. - */ - NS_IMETHOD SetText(const char* aBuffer, - PRInt32 aLength, - PRBool aNotify) = 0; - - /** - * Query method to see if the frame is nothing but whitespace - */ - NS_IMETHOD IsOnlyWhitespace(PRBool* aResult) = 0; - - /** - * Clone this content node. Unlike the nsIDOMNode equivalent, this - * method allows you to specify whether to copy the text as well. - */ - NS_IMETHOD CloneContent(PRBool aCloneText, nsITextContent** aClone) = 0; -}; - -//---------------------------------------------------------------------- - -/* a6cf905e-15b3-11d2-932e-00805f8add32 */ -#define NS_ITEXT_CONTENT_CHANGE_DATA_IID \ - {0xa6cf905e, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} - -// Simple interface for encapsulating change data for a ContentChanged -// notification. -class nsITextContentChangeData : public nsISupports { -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITEXT_CONTENT_CHANGE_DATA_IID); - - enum ChangeType { - Insert, - Append, - Replace - }; - - /** - * Get the type of change associated with the ContentChanged - * notification. - */ - NS_IMETHOD GetChangeType(ChangeType* aResult) = 0; - - NS_IMETHOD GetInsertData(PRInt32* aOffset, - PRInt32* aInsertLength) = 0; - - NS_IMETHOD GetAppendData(PRInt32* aOffset, - PRInt32* aAppendLength) = 0; - - NS_IMETHOD GetReplaceData(PRInt32* aOffset, - PRInt32* aSourceLength, - PRInt32* aReplaceLength) = 0; -}; - -// XXX These belong elsewhere -extern nsresult -NS_NewTextNode(nsIContent** aResult); - -extern nsresult -NS_NewCommentNode(nsIContent** aResult); - - -#endif /* nsITextContent_h___ */ diff --git a/layout/base/public/nsTextFragment.h b/layout/base/public/nsTextFragment.h deleted file mode 100644 index 52ccecd47637..000000000000 --- a/layout/base/public/nsTextFragment.h +++ /dev/null @@ -1,242 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsTextFragment_h___ -#define nsTextFragment_h___ - -#include "nslayout.h" -#include "nsAWritableString.h" -class nsString; - -// XXX should this normalize the code to keep a \u0000 at the end? - -// XXX nsTextFragmentPool? - -// XXX these need I18N spankage -#define XP_IS_SPACE(_ch) \ - (((_ch) == ' ') || ((_ch) == '\t') || ((_ch) == '\n')) - -#define XP_IS_UPPERCASE(_ch) \ - (((_ch) >= 'A') && ((_ch) <= 'Z')) - -#define XP_IS_LOWERCASE(_ch) \ - (((_ch) >= 'a') && ((_ch) <= 'z')) - -#define XP_TO_LOWER(_ch) ((_ch) | 32) - -#define XP_TO_UPPER(_ch) ((_ch) & ~32) - -#define XP_IS_SPACE_W XP_IS_SPACE - -/** - * A fragment of text. If mIs2b is 1 then the m2b pointer is valid - * otherwise the m1b pointer is valid. If m1b is used then each byte - * of data represents a single ucs2 character with the high byte being - * zero. - * - * This class does not have a virtual destructor therefore it is not - * meant to be subclassed. - */ -class NS_LAYOUT nsTextFragment { -public: - /** - * Default constructor. Initialize the fragment to be empty. - */ - nsTextFragment() { - m1b = nsnull; - mAllBits = 0; - } - - ~nsTextFragment(); - - /** - * Initialize the contents of this fragment to be a copy of - * the argument fragment. - */ - nsTextFragment(const nsTextFragment& aOther); - - /** - * Initialize the contents of this fragment to be a copy of - * the argument 7bit ascii string. - */ - nsTextFragment(const char* aString); - - /** - * Initialize the contents of this fragment to be a copy of - * the argument ucs2 string. - */ - nsTextFragment(const PRUnichar* aString); - - /** - * Initialize the contents of this fragment to be a copy of - * the argument string. - */ - nsTextFragment(const nsString& aString); - - /** - * Change the contents of this fragment to be a copy of the - * the argument fragment. - */ - nsTextFragment& operator=(const nsTextFragment& aOther); - - /** - * Change the contents of this fragment to be a copy of the - * the argument 7bit ascii string. - */ - nsTextFragment& operator=(const char* aString); - - /** - * Change the contents of this fragment to be a copy of the - * the argument ucs2 string. - */ - nsTextFragment& operator=(const PRUnichar* aString); - - /** - * Change the contents of this fragment to be a copy of the - * the argument string. - */ - nsTextFragment& operator=(const nsAReadableString& aString); - - /** - * Return PR_TRUE if this fragment is represented by PRUnichar data - */ - PRBool Is2b() const { - return mState.mIs2b; - } - - /** - * Get a pointer to constant PRUnichar data. - */ - const PRUnichar* Get2b() const { - NS_ASSERTION(Is2b(), "not 2b text"); - return m2b; - } - - /** - * Get a pointer to constant char data. - */ - const char* Get1b() const { - NS_ASSERTION(!Is2b(), "not 1b text"); - return (const char*) m1b; - } - - /** - * Get the length of the fragment. The length is the number of logical - * characters, not the number of bytes to store the characters. - */ - PRInt32 GetLength() const { - return PRInt32(mState.mLength); - } - - /** - * Mutable version of Get2b. Only works for a non-const object. - * Returns a pointer to the PRUnichar data. - */ - PRUnichar* Get2b() { - NS_ASSERTION(Is2b(), "not 2b text"); - return m2b; - } - - /** - * Mutable version of Get1b. Only works for a non-const object. - * Returns a pointer to the char data. - */ - char* Get1b() { - NS_ASSERTION(!Is2b(), "not 1b text"); - return (char*) m1b; - } - - /** - * Change the contents of this fragment to be the given buffer and - * length. The memory becomes owned by the fragment. In addition, - * the memory for aBuffer must have been allocated using the - * nsIMemory interface. - */ - void SetTo(PRUnichar* aBuffer, PRInt32 aLength, PRBool aRelease); - - /** - * Change the contents of this fragment to be a copy of the given - * buffer. Like operator= except a length is specified instead of - * assuming 0 termination. - */ - void SetTo(const PRUnichar* aBuffer, PRInt32 aLength); - - /** - * Change the contents of this fragment to be a copy of the given - * buffer. Like operator= except a length is specified instead of - * assuming 0 termination. - */ - void SetTo(const char* aBuffer, PRInt32 aLength); - - /** - * Append the contents of this string fragment to aString - */ - void AppendTo(nsString& aString) const; - - /** - * Make a copy of the fragments contents starting at offset for - * count characters. The offset and count will be adjusted to - * lie within the fragments data. The fragments data is converted if - * necessary. - */ - void CopyTo(PRUnichar* aDest, PRInt32 aOffset, PRInt32 aCount); - - /** - * Make a copy of the fragments contents starting at offset for - * count characters. The offset and count will be adjusted to - * lie within the fragments data. The fragments data is converted if - * necessary. - */ - void CopyTo(char* aDest, PRInt32 aOffset, PRInt32 aCount); - - /** - * Return the character in the text-fragment at the given - * index. This always returns a PRUnichar. - */ - PRUnichar CharAt(PRInt32 aIndex) const { - NS_ASSERTION(PRUint32(aIndex) < mState.mLength, "bad index"); - return mState.mIs2b ? m2b[aIndex] : PRUnichar(m1b[aIndex]); - } - -protected: - union { - PRUnichar* m2b; - unsigned char* m1b; - }; - -public: - struct FragmentBits { - PRUint32 mInHeap : 1; - PRUint32 mIs2b : 1; - PRUint32 mLength : 30; - }; - -protected: - union { - PRUint32 mAllBits; - FragmentBits mState; - }; - - void ReleaseText(); -}; - -#endif /* nsTextFragment_h___ */ - diff --git a/layout/base/src/nsCommentNode.cpp b/layout/base/src/nsCommentNode.cpp deleted file mode 100644 index 60d92230fb23..000000000000 --- a/layout/base/src/nsCommentNode.cpp +++ /dev/null @@ -1,458 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#include "nsIDOMComment.h" -#include "nsGenericDOMDataNode.h" -#include "nsIScriptObjectOwner.h" -#include "nsIDOMEventReceiver.h" -#include "nsIContent.h" -#include "nsFrame.h" -#include "nsLayoutAtoms.h" -#include "nsISelection.h" -#include "nsISelectionPrivate.h" -#include "nsIDocument.h" -#include "nsIEnumerator.h" -#include "nsCOMPtr.h" -#include "nsIDOMRange.h" - -class nsCommentNode : public nsIDOMComment, - public nsIScriptObjectOwner, - public nsITextContent -{ -public: - nsCommentNode(); - virtual ~nsCommentNode(); - - // nsISupports - NS_DECL_ISUPPORTS - - // nsIDOMNode - NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner) - - // nsIDOMCharacterData - NS_IMPL_IDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(mInner) - - // nsIDOMComment - - // nsIScriptObjectOwner - NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC_DOM_DATA(mInner) - - // nsIContent - //NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner) - - NS_IMETHOD GetDocument(nsIDocument*& aResult) const { - return mInner.GetDocument(aResult); - } - NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileEventHandlers) { - return mInner.SetDocument(aDocument, aDeep, aCompileEventHandlers); - } - NS_IMETHOD GetParent(nsIContent*& aResult) const { - return mInner.GetParent(aResult); - } - NS_IMETHOD SetParent(nsIContent* aParent) { - return mInner.SetParent(aParent); - } - NS_IMETHOD CanContainChildren(PRBool& aResult) const { - return mInner.CanContainChildren(aResult); - } - NS_IMETHOD ChildCount(PRInt32& aResult) const { - return mInner.ChildCount(aResult); - } - NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const { - return mInner.ChildAt(aIndex, aResult); - } - NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const { - return mInner.IndexOf(aPossibleChild, aResult); - } - NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, - PRBool aNotify) { - return mInner.InsertChildAt(aKid, aIndex, aNotify); - } - NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, - PRBool aNotify) { - return mInner.ReplaceChildAt(aKid, aIndex, aNotify); - } - NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) { - return mInner.AppendChildTo(aKid, aNotify); - } - NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) { - return mInner.RemoveChildAt(aIndex, aNotify); - } - NS_IMETHOD GetNameSpaceID(PRInt32& aID) const { - return mInner.GetNameSpaceID(aID); - } - NS_IMETHOD GetTag(nsIAtom*& aResult) const; - NS_IMETHOD GetNodeInfo(nsINodeInfo*& aResult) const { - aResult = nsnull; return NS_OK; - } - NS_IMETHOD NormalizeAttributeString(const nsAReadableString& aStr, - nsINodeInfo*& aNodeInfo) { - aNodeInfo = nsnull; - return NS_OK; - } - NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute, - nsAWritableString& aResult) const { - return mInner.GetAttribute(aNameSpaceID, aAttribute, aResult); - } - NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute, - nsIAtom*& aPrefix, nsAWritableString& aResult) const { - return mInner.GetAttribute(aNameSpaceID, aAttribute, aPrefix, aResult); - } - NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, - const nsAReadableString& aValue, PRBool aNotify) { - return mInner.SetAttribute(aNameSpaceID, aAttribute, aValue, aNotify); - } - NS_IMETHOD SetAttribute(nsINodeInfo* aNodeInfo, - const nsAReadableString& aValue, PRBool aNotify) { - return mInner.SetAttribute(aNodeInfo, aValue, aNotify); - } - NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, - PRBool aNotify) { - return mInner.UnsetAttribute(aNameSpaceID, aAttribute, aNotify); - } - NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, - PRInt32& aNameSpaceID, - nsIAtom*& aName, - nsIAtom*& aPrefix) const { - return mInner.GetAttributeNameAt(aIndex, aNameSpaceID, aName, aPrefix); - } - NS_IMETHOD GetAttributeCount(PRInt32& aResult) const { - return mInner.GetAttributeCount(aResult); - } - NS_IMETHOD List(FILE* out, PRInt32 aIndent) const; - NS_IMETHOD DumpContent(FILE* out = stdout, PRInt32 aIndent = 0,PRBool aDumpAll=PR_TRUE) const { - return NS_OK; - } - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus); - - NS_IMETHOD GetContentID(PRUint32* aID) { - *aID = mContentID; - return NS_OK; - } - NS_IMETHOD SetContentID(PRUint32 aID) { - mContentID = aID; - return NS_OK; - } - - NS_IMETHOD RangeAdd(nsIDOMRange& aRange){ - return mInner.RangeAdd(aRange); - } - NS_IMETHOD RangeRemove(nsIDOMRange& aRange){ - return mInner.RangeRemove(aRange); - } - NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { - return mInner.GetRangeList(aResult); - } - NS_IMETHOD SetFocus(nsIPresContext* aContext) { - return mInner.SetFocus(aContext); - } - NS_IMETHOD RemoveFocus(nsIPresContext* aContext) { - return mInner.RemoveFocus(aContext); - } - - NS_IMETHOD GetBindingParent(nsIContent** aContent) { - return mInner.GetBindingParent(aContent); - } - - NS_IMETHOD SetBindingParent(nsIContent* aParent) { - return mInner.SetBindingParent(aParent); - } - - NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { - if (!aResult) { - return NS_ERROR_NULL_POINTER; - } -#ifdef DEBUG - *aResult = sizeof(*this); -#else - *aResult = 0; -#endif - return NS_OK; - } - - NS_IMETHOD GetText(const nsTextFragment** aFragmentsResult) - { return mInner.GetText(aFragmentsResult); } - NS_IMETHOD GetTextLength(PRInt32* aLengthResult) { - return mInner.GetTextLength(aLengthResult); - } - NS_IMETHOD CopyText(nsAWritableString& aResult) { - return mInner.CopyText(aResult); - } - NS_IMETHOD SetText(const PRUnichar* aBuffer, - PRInt32 aLength, - PRBool aNotify); - NS_IMETHOD SetText(const nsAReadableString& aStr, - PRBool aNotify); - NS_IMETHOD SetText(const char* aBuffer, - PRInt32 aLength, - PRBool aNotify); - NS_IMETHOD IsOnlyWhitespace(PRBool* aResult) - { return mInner.IsOnlyWhitespace(aResult); } - NS_IMETHOD CloneContent(PRBool aCloneText, nsITextContent** aClone); - -protected: - nsGenericDOMDataNode mInner; - PRUint32 mContentID; -}; - -nsresult -NS_NewCommentNode(nsIContent** aInstancePtrResult) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - nsIContent* it = new nsCommentNode(); - if (nsnull == it) { - return NS_ERROR_OUT_OF_MEMORY; - } - return it->QueryInterface(NS_GET_IID(nsIContent), (void **) aInstancePtrResult); -} - -nsCommentNode::nsCommentNode() -{ - NS_INIT_REFCNT(); - mContentID = 0; -} - -nsCommentNode::~nsCommentNode() -{ -} - -NS_IMPL_ADDREF(nsCommentNode) - -NS_IMPL_RELEASE(nsCommentNode) - -NS_IMETHODIMP -nsCommentNode::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - NS_IMPL_DOM_DATA_QUERY_INTERFACE(aIID, aInstancePtr, this) - if (aIID.Equals(NS_GET_IID(nsIDOMComment))) { - nsIDOMComment* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsITextContent))) { - nsITextContent* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} - -NS_IMETHODIMP -nsCommentNode::GetTag(nsIAtom*& aResult) const -{ - aResult = nsLayoutAtoms::commentTagName; - NS_ADDREF(aResult); - return NS_OK; -} - -NS_IMETHODIMP -nsCommentNode::GetNodeName(nsAWritableString& aNodeName) -{ - aNodeName.Assign(NS_LITERAL_STRING("#comment")); - return NS_OK; -} - -NS_IMETHODIMP -nsCommentNode::GetNodeType(PRUint16* aNodeType) -{ - *aNodeType = (PRUint16)nsIDOMNode::COMMENT_NODE; - return NS_OK; -} - -NS_IMETHODIMP -nsCommentNode::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) -{ - nsresult result = NS_OK; - nsCommentNode* it = new nsCommentNode(); - if (nsnull == it) { - return NS_ERROR_OUT_OF_MEMORY; - } - // XXX Increment the ref count before calling any - // methods. If they do a QI and then a Release() - // the instance will be deleted. - result = it->QueryInterface(NS_GET_IID(nsIDOMNode), (void**) aReturn); - if (NS_FAILED(result)) { - return result; - } - nsAutoString data; - result = GetData(data); - if (NS_FAILED(result)) { - NS_RELEASE(*aReturn); - return result; - } - result = it->SetData(data); - if (NS_FAILED(result)) { - NS_RELEASE(*aReturn); - return result; - } - return result; -} - -NS_IMETHODIMP -nsCommentNode::CloneContent(PRBool aCloneText, nsITextContent** aReturn) -{ - nsresult result = NS_OK; - nsCommentNode* it; - NS_NEWXPCOM(it, nsCommentNode); - if (nsnull == it) { - return NS_ERROR_OUT_OF_MEMORY; - } - result = it->QueryInterface(NS_GET_IID(nsITextContent), (void**) aReturn); - if (NS_FAILED(result) || !aCloneText) { - return result; - } - nsAutoString data; - result = GetData(data); - if (NS_FAILED(result)) { - NS_RELEASE(*aReturn); - return result; - } - result = it->SetData(data); - if (NS_FAILED(result)) { - NS_RELEASE(*aReturn); - return result; - } - return result; -} - -NS_IMETHODIMP -nsCommentNode::List(FILE* out, PRInt32 aIndent) const -{ - NS_PRECONDITION(nsnull != mInner.mDocument, "bad content"); - - PRInt32 indx; - for (indx = aIndent; --indx >= 0; ) fputs(" ", out); - - fprintf(out, "Comment@%p refcount=%d\n", out); - return NS_OK; -} - -NS_IMETHODIMP -nsCommentNode::HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus) -{ - return mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent, - aFlags, aEventStatus); -} - -nsresult NS_NewCommentFrame(nsIPresShell* aPresShell, nsIFrame*& aResult); -nsresult -NS_NewCommentFrame(nsIPresShell* aPresShell, nsIFrame*& aResult) -{ - nsIFrame* frame; - NS_NewEmptyFrame(aPresShell, &frame); - if (nsnull == frame) { - return NS_ERROR_OUT_OF_MEMORY; - } - aResult = frame; - return NS_OK; -} - - -// This would ideally be done by the parser, but for the sake -// of "genericity" it's being done in the comment content code -static void -StripCommentDelimiters(nsString& aCommentString) -{ - PRInt32 offset; - static char* kCommentStart = ""; - static char* kCommentAlternateEnd = "--!>"; - static char kMinus = '-'; - - offset = aCommentString.Find(kCommentStart); - if (-1 != offset) { - // Take up to 2 '-' characters - offset += strlen(kCommentStart); - if (kMinus == aCommentString.CharAt(offset)) { - offset++; - if (kMinus == aCommentString.CharAt(offset)) { - offset++; - } - } - aCommentString.Cut(0, offset); - } - - offset = aCommentString.RFind(kCommentEnd); - if (offset > 0) { - // Take up to 1 more '-' - if (kMinus == aCommentString.CharAt(offset-1)) { - offset--; - } - aCommentString.Cut(offset, aCommentString.Length()-offset); - } - else { - offset = aCommentString.RFind(kCommentAlternateEnd); - if (-1 != offset) { - aCommentString.Cut(offset, aCommentString.Length()-offset); - } - } -} - -NS_IMETHODIMP -nsCommentNode::SetText(const PRUnichar* aBuffer, - PRInt32 aLength, - PRBool aNotify) -{ - nsAutoString str(aBuffer); - - StripCommentDelimiters(str); - return mInner.SetText(this, str.GetUnicode(), str.Length(), aNotify); -} - -NS_IMETHODIMP -nsCommentNode::SetText(const nsAReadableString& aStr, - PRBool aNotify) -{ - nsAutoString str(aStr); - - StripCommentDelimiters(str); - return mInner.SetText(this, str.GetUnicode(), str.Length(), aNotify); -} - -NS_IMETHODIMP -nsCommentNode::SetText(const char* aBuffer, - PRInt32 aLength, - PRBool aNotify) -{ - nsAutoString str; str.AssignWithConversion(aBuffer); - - StripCommentDelimiters(str); - return mInner.SetText(this, str.GetUnicode(), str.Length(), aNotify); -} diff --git a/layout/base/src/nsContentIterator.cpp b/layout/base/src/nsContentIterator.cpp deleted file mode 100644 index 700f46f764ba..000000000000 --- a/layout/base/src/nsContentIterator.cpp +++ /dev/null @@ -1,1137 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Pierre Phaneuf - */ - -/* - * nsContentIterator.cpp: Implementation of the nsContentIterator object. - * This ite - */ - -#include "nsISupports.h" -#include "nsIDOMNodeList.h" -#include "nsIContentIterator.h" -#include "nsRange.h" -#include "nsIContent.h" -#include "nsIDOMText.h" -#include "nsISupportsArray.h" -#include "nsIFocusTracker.h" -#include "nsCOMPtr.h" -#include "nsIPresContext.h" -#include "nsIComponentManager.h" -#include "nsLayoutCID.h" -#include "nsVoidArray.h" - -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kCContentIteratorCID, NS_CONTENTITERATOR_CID); -static NS_DEFINE_IID(kCSubtreeIteratorCID, NS_SUBTREEITERATOR_CID); - -// couple of utility static functs - -/////////////////////////////////////////////////////////////////////////// -// GetNumChildren: returns the number of things inside aNode. -// -static PRUint32 -GetNumChildren(nsIDOMNode *aNode) -{ - PRUint32 numChildren = 0; - if (!aNode) - return 0; - - PRBool hasChildNodes; - aNode->HasChildNodes(&hasChildNodes); - if (hasChildNodes) - { - nsCOMPtrnodeList; - nsresult res = aNode->GetChildNodes(getter_AddRefs(nodeList)); - if (NS_SUCCEEDED(res) && nodeList) - nodeList->GetLength(&numChildren); - } - return numChildren; -} - -/////////////////////////////////////////////////////////////////////////// -// GetChildAt: returns the node at this position index in the parent -// -static nsCOMPtr -GetChildAt(nsIDOMNode *aParent, PRInt32 aOffset) -{ - nsCOMPtr resultNode; - - if (!aParent) - return resultNode; - - PRBool hasChildNodes; - aParent->HasChildNodes(&hasChildNodes); - if (PR_TRUE==hasChildNodes) - { - nsCOMPtrnodeList; - nsresult res = aParent->GetChildNodes(getter_AddRefs(nodeList)); - if (NS_SUCCEEDED(res) && nodeList) - nodeList->Item(aOffset, getter_AddRefs(resultNode)); - } - - return resultNode; -} - - - - -/* - * A simple iterator class for traversing the content in "close tag" order - */ -class nsContentIterator : public nsIContentIterator //, public nsIEnumerator -{ -public: - NS_DECL_ISUPPORTS - - nsContentIterator(); - virtual ~nsContentIterator(); - - // nsIContentIterator interface methods ------------------------------ - - NS_IMETHOD Init(nsIContent* aRoot); - - NS_IMETHOD Init(nsIDOMRange* aRange); - - NS_IMETHOD First(); - - NS_IMETHOD Last(); - - NS_IMETHOD Next(); - - NS_IMETHOD Prev(); - - NS_IMETHOD CurrentNode(nsIContent **aNode); - - NS_IMETHOD IsDone(); - - NS_IMETHOD PositionAt(nsIContent* aCurNode); - - NS_IMETHOD MakePre(); - - NS_IMETHOD MakePost(); - - - // nsIEnumertor interface methods ------------------------------ - - //NS_IMETHOD CurrentItem(nsISupports **aItem); - -protected: - - static nsCOMPtr GetDeepFirstChild(nsCOMPtr aRoot); - static nsCOMPtr GetDeepLastChild(nsCOMPtr aRoot); - - nsresult GetNextSibling(nsCOMPtr aNode, nsCOMPtr *aSibling); - nsresult GetPrevSibling(nsCOMPtr aNode, nsCOMPtr *aSibling); - - nsresult NextNode(nsCOMPtr *ioNextNode); - nsresult PrevNode(nsCOMPtr *ioPrevNode); - - void MakeEmpty(); - - nsCOMPtr mCurNode; - nsCOMPtr mFirst; - nsCOMPtr mLast; - nsCOMPtr mCommonParent; - nsCOMPtr mCachedNode; - PRInt32 mCachedIndex; - - PRBool mIsDone; - PRBool mPre; - -private: - - // no copy's or assigns FIX ME - nsContentIterator(const nsContentIterator&); - nsContentIterator& operator=(const nsContentIterator&); - -}; - - - -/****************************************************** - * repository cruft - ******************************************************/ - -nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult) -{ - nsContentIterator * iter = new nsContentIterator(); - if (iter) - return iter->QueryInterface(NS_GET_IID(nsIContentIterator), (void**) aInstancePtrResult); - return NS_ERROR_OUT_OF_MEMORY; -} - - -/****************************************************** - * XPCOM cruft - ******************************************************/ - -NS_IMPL_ADDREF(nsContentIterator) -NS_IMPL_RELEASE(nsContentIterator) - -nsresult nsContentIterator::QueryInterface(const nsIID& aIID, - void** aInstancePtrResult) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); - if (nsnull == aInstancePtrResult) - { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(kISupportsIID)) - { - *aInstancePtrResult = (void*)(nsISupports*)(nsIContentIterator*)this; - NS_ADDREF_THIS(); - return NS_OK; - } -/* if (aIID.Equals(NS_GET_IID(nsIEnumerator))) - { - *aInstancePtrResult = (void*)(nsIEnumerator*)this; - NS_ADDREF_THIS(); - return NS_OK; - } */ - if (aIID.Equals(NS_GET_IID(nsIContentIterator))) - { - *aInstancePtrResult = (void*)(nsIContentIterator*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} - - -/****************************************************** - * constructor/destructor - ******************************************************/ - -nsContentIterator::nsContentIterator() : - // don't need to explicitly initialize |nsCOMPtr|s, they will automatically be NULL - mIsDone(PR_FALSE), mPre(PR_FALSE) -{ - NS_INIT_REFCNT(); -} - - -nsContentIterator::~nsContentIterator() -{ -} - - -/****************************************************** - * Init routines - ******************************************************/ - - -nsresult nsContentIterator::Init(nsIContent* aRoot) -{ - if (!aRoot) - return NS_ERROR_NULL_POINTER; - mIsDone = PR_FALSE; - nsCOMPtr root( do_QueryInterface(aRoot) ); - mFirst = GetDeepFirstChild(root); - mLast = root; - mCommonParent = root; - mCurNode = mFirst; - return NS_OK; -} - - -nsresult nsContentIterator::Init(nsIDOMRange* aRange) -{ - if (!aRange) - return NS_ERROR_NULL_POINTER; - - nsCOMPtr dN; - nsCOMPtr cChild; - - nsCOMPtr startCon; - nsCOMPtr startDOM; - nsCOMPtr endCon; - nsCOMPtr endDOM; - PRInt32 startIndx; - PRInt32 endIndx; - - mIsDone = PR_FALSE; - - // get common content parent - if (NS_FAILED(aRange->GetCommonAncestorContainer(getter_AddRefs(dN))) || !dN) - return NS_ERROR_FAILURE; - mCommonParent = do_QueryInterface(dN); - - // get the start node and offset, convert to nsIContent - aRange->GetStartContainer(getter_AddRefs(startDOM)); - if (!startDOM) - return NS_ERROR_ILLEGAL_VALUE; - startCon = do_QueryInterface(startDOM); - if (!startCon) - return NS_ERROR_FAILURE; - - aRange->GetStartOffset(&startIndx); - - // get the end node and offset, convert to nsIContent - aRange->GetEndContainer(getter_AddRefs(endDOM)); - if (!endDOM) - return NS_ERROR_ILLEGAL_VALUE; - endCon = do_QueryInterface(endDOM); - if (!endCon) - return NS_ERROR_FAILURE; - - aRange->GetEndOffset(&endIndx); - - // short circuit when start node == end node - if (startDOM == endDOM) - { - startCon->ChildAt(0,*getter_AddRefs(cChild)); - - if (!cChild) // no children, must be a text node or empty container - { - mFirst = startCon; - mLast = startCon; - mCurNode = startCon; - return NS_OK; - } - else - { - if (startIndx == endIndx) // collapsed range - { - MakeEmpty(); - return NS_OK; - } - } - } - - // find first node in range - startCon->ChildAt(0,*getter_AddRefs(cChild)); - - if (!cChild) // no children, must be a text node - { - mFirst = startCon; - } - else - { - startCon->ChildAt(startIndx,*getter_AddRefs(cChild)); - if (!cChild) // offset after last child, parent is first node - { - mFirst = startCon; - } - else - { - mFirst = GetDeepFirstChild(cChild); - } - // Does that first node really intersect the range? - // the range could be collapsed, or the range could be - // 'degenerate', ie not collapsed but still containing - // no content. In this case, we want the iterator to - // be empty - - if (!IsNodeIntersectsRange(mFirst, aRange)) - { - MakeEmpty(); - return NS_OK; - } - } - - // find last node in range - endCon->ChildAt(0,*getter_AddRefs(cChild)); - - if (!cChild) // no children, must be a text node - { - mLast = endCon; - } - else if (endIndx == 0) // before first child, parent is last node - { - mLast = endCon; - } - else - { - endCon->ChildAt(--endIndx,*getter_AddRefs(cChild)); - if (!cChild) // offset after last child, last child is last node - { - endCon->ChildCount(endIndx); - endCon->ChildAt(--endIndx,*getter_AddRefs(cChild)); - if (!cChild) - { - NS_NOTREACHED("nsContentIterator::nsContentIterator"); - return NS_ERROR_FAILURE; - } - } - mLast = cChild; - } - - mCurNode = mFirst; - return NS_OK; -} - - -/****************************************************** - * Helper routines - ******************************************************/ - -void nsContentIterator::MakeEmpty() -{ - nsCOMPtr noNode; - mCurNode = noNode; - mFirst = noNode; - mLast = noNode; - mCommonParent = noNode; - mIsDone = PR_TRUE; -} - -nsCOMPtr nsContentIterator::GetDeepFirstChild(nsCOMPtr aRoot) -{ - nsCOMPtr deepFirstChild; - - if (aRoot) - { - nsCOMPtr cN = aRoot; - nsCOMPtr cChild; - cN->ChildAt(0,*getter_AddRefs(cChild)); - while ( cChild ) - { - cN = cChild; - cN->ChildAt(0,*getter_AddRefs(cChild)); - } - deepFirstChild = cN; - } - - return deepFirstChild; -} - -nsCOMPtr nsContentIterator::GetDeepLastChild(nsCOMPtr aRoot) -{ - nsCOMPtr deepFirstChild; - - if (aRoot) - { - nsCOMPtr cN = aRoot; - nsCOMPtr cChild; - PRInt32 numChildren; - - cN->ChildCount(numChildren); - - while ( numChildren ) - { - cN->ChildAt(--numChildren,*getter_AddRefs(cChild)); - if (cChild) - { - cChild->ChildCount(numChildren); - cN = cChild; - } - else - { - break; - } - } - deepFirstChild = cN; - } - - return deepFirstChild; -} - -// Get the next sibling, or parents next sibling, or grandpa's next sibling... -nsresult nsContentIterator::GetNextSibling(nsCOMPtr aNode, nsCOMPtr *aSibling) -{ - if (!aNode) - return NS_ERROR_NULL_POINTER; - if (!aSibling) - return NS_ERROR_NULL_POINTER; - - nsCOMPtr sib; - nsCOMPtr parent; - PRInt32 indx; - - if (NS_FAILED(aNode->GetParent(*getter_AddRefs(parent))) || !parent) - return NS_ERROR_FAILURE; - - if (mCachedNode == aNode) - indx = mCachedIndex; - else if (NS_FAILED(parent->IndexOf(aNode, indx))) - return NS_ERROR_FAILURE; - - if (NS_SUCCEEDED(parent->ChildAt(++indx, *getter_AddRefs(sib))) && sib) - { - *aSibling = sib; - mCachedNode = sib; - mCachedIndex = indx; - } - else if (parent != mCommonParent) - { - return GetNextSibling(parent, aSibling); - } - else - { - *aSibling = nsCOMPtr(); - } - - return NS_OK; -} - -// Get the prev sibling, or parents prev sibling, or grandpa's prev sibling... -nsresult nsContentIterator::GetPrevSibling(nsCOMPtr aNode, nsCOMPtr *aSibling) -{ - if (!aNode) - return NS_ERROR_NULL_POINTER; - if (!aSibling) - return NS_ERROR_NULL_POINTER; - - nsCOMPtr sib; - nsCOMPtr parent; - PRInt32 indx; - - if (NS_FAILED(aNode->GetParent(*getter_AddRefs(parent))) || !parent) - return NS_ERROR_FAILURE; - - if (NS_FAILED(parent->IndexOf(aNode, indx))) - return NS_ERROR_FAILURE; - - if (indx && NS_SUCCEEDED(parent->ChildAt(--indx, *getter_AddRefs(sib))) && sib) - { - *aSibling = sib; - } - else if (parent != mCommonParent) - { - return GetPrevSibling(parent, aSibling); - } - else - { - *aSibling = nsCOMPtr(); - } - - return NS_OK; -} - -nsresult nsContentIterator::NextNode(nsCOMPtr *ioNextNode) -{ - if (!ioNextNode) - return NS_ERROR_NULL_POINTER; - - if (mPre) // if we are a Pre-order iterator, use pre-order - { - nsCOMPtr cN = *ioNextNode; - nsCOMPtr cFirstChild; - PRInt32 numChildren; - - cN->ChildCount(numChildren); - - // if it has children then next node is first child - if (numChildren) - { - if (NS_FAILED(cN->ChildAt(0,*getter_AddRefs(cFirstChild)))) - return NS_ERROR_FAILURE; - if (!cFirstChild) - return NS_ERROR_FAILURE; - *ioNextNode = cFirstChild; - return NS_OK; - } - - // else next sibling is next - return GetNextSibling(cN, ioNextNode); - } - else // post-order - { - nsCOMPtr cN = *ioNextNode; - nsCOMPtr cSibling; - nsCOMPtr parent; - PRInt32 indx; - - // get next sibling if there is one - if (NS_FAILED(cN->GetParent(*getter_AddRefs(parent)))) - return NS_ERROR_FAILURE; - if (!parent || NS_FAILED(parent->IndexOf(cN, indx))) - { - // a little noise to catch some iterator usage bugs. - NS_NOTREACHED("nsContentIterator::NextNode() : no parent found"); - return NS_ERROR_FAILURE; - } - if (NS_SUCCEEDED(parent->ChildAt(++indx,*getter_AddRefs(cSibling))) && cSibling) - { - // next node is siblings "deep left" child - *ioNextNode = GetDeepFirstChild(cSibling); - return NS_OK; - } - - // else it's the parent - *ioNextNode = parent; - } - return NS_OK; -} - -nsresult nsContentIterator::PrevNode(nsCOMPtr *ioNextNode) -{ - if (!ioNextNode) - return NS_ERROR_NULL_POINTER; - - if (mPre) // if we are a Pre-order iterator, use pre-order - { - nsCOMPtr cN = *ioNextNode; - nsCOMPtr cSibling; - nsCOMPtr parent; - PRInt32 indx; - - // get prev sibling if there is one - if (NS_FAILED(cN->GetParent(*getter_AddRefs(parent)))) - return NS_ERROR_FAILURE; - if (!parent || NS_FAILED(parent->IndexOf(cN, indx))) - { - // a little noise to catch some iterator usage bugs. - NS_NOTREACHED("nsContentIterator::PrevNode() : no parent found"); - return NS_ERROR_FAILURE; - } - if (indx && NS_SUCCEEDED(parent->ChildAt(--indx,*getter_AddRefs(cSibling))) && cSibling) - { - // prev node is siblings "deep right" child - *ioNextNode = GetDeepLastChild(cSibling); - return NS_OK; - } - - // else it's the parent - *ioNextNode = parent; - } - else // post-order - { - nsCOMPtr cN = *ioNextNode; - nsCOMPtr cLastChild; - PRInt32 numChildren; - - cN->ChildCount(numChildren); - - // if it has children then prev node is last child - if (numChildren) - { - if (NS_FAILED(cN->ChildAt(--numChildren,*getter_AddRefs(cLastChild)))) - return NS_ERROR_FAILURE; - if (!cLastChild) - return NS_ERROR_FAILURE; - *ioNextNode = cLastChild; - return NS_OK; - } - - // else prev sibling is previous - return GetPrevSibling(cN, ioNextNode); - } - return NS_OK; -} - -/****************************************************** - * ContentIterator routines - ******************************************************/ - -nsresult nsContentIterator::First() -{ - if (!mFirst) - return NS_ERROR_FAILURE; - mIsDone = PR_FALSE; - if (mFirst == mCurNode) - return NS_OK; - mCurNode = mFirst; - return NS_OK; -} - - -nsresult nsContentIterator::Last() -{ - if (!mLast) - return NS_ERROR_FAILURE; - mIsDone = PR_FALSE; - if (mLast == mCurNode) - return NS_OK; - mCurNode = mLast; - return NS_OK; -} - - -nsresult nsContentIterator::Next() -{ - if (mIsDone) - return NS_OK; - if (!mCurNode) - return NS_OK; - if (mCurNode == mLast) - { - mIsDone = PR_TRUE; - return NS_OK; - } - - return NextNode(address_of(mCurNode)); -} - - -nsresult nsContentIterator::Prev() -{ - if (mIsDone) - return NS_OK; - if (!mCurNode) - return NS_OK; - if (mCurNode == mFirst) - { - mIsDone = PR_TRUE; - return NS_OK; - } - - return PrevNode(address_of(mCurNode)); -} - - -nsresult nsContentIterator::IsDone() -{ - if (mIsDone) - return NS_OK; - else - return NS_ENUMERATOR_FALSE; -} - - -nsresult nsContentIterator::PositionAt(nsIContent* aCurNode) -{ - // XXX need to confirm that aCurNode is within range - if (!aCurNode) - return NS_ERROR_NULL_POINTER; - mCurNode = do_QueryInterface(aCurNode); - mIsDone = PR_FALSE; - return NS_OK; -} - -nsresult nsContentIterator::MakePre() -{ - // XXX need to confirm mCurNode is within range - mPre = PR_TRUE; - return NS_OK; -} - -nsresult nsContentIterator::MakePost() -{ - // XXX need to confirm mCurNode is within range - mPre = PR_FALSE; - return NS_OK; -} - - -nsresult nsContentIterator::CurrentNode(nsIContent **aNode) -{ - if (!mCurNode) - return NS_ERROR_FAILURE; - if (mIsDone) - return NS_ERROR_FAILURE; - return mCurNode->QueryInterface(NS_GET_IID(nsIContent), (void**) aNode); -} - - - - - -/*====================================================================================*/ -/*====================================================================================*/ - - - - - - -/****************************************************** - * nsContentSubtreeIterator - ******************************************************/ - - -/* - * A simple iterator class for traversing the content in "top subtree" order - */ -class nsContentSubtreeIterator : public nsContentIterator -{ -public: - nsContentSubtreeIterator() {}; - virtual ~nsContentSubtreeIterator() {}; - - // nsContentIterator overrides ------------------------------ - - NS_IMETHOD Init(nsIContent* aRoot); - - NS_IMETHOD Init(nsIDOMRange* aRange); - - NS_IMETHOD Next(); - - NS_IMETHOD Prev(); - - NS_IMETHOD PositionAt(nsIContent* aCurNode); - - NS_IMETHOD MakePre(); - - NS_IMETHOD MakePost(); - -protected: - - nsresult GetTopAncestorInRange( nsCOMPtr aNode, - nsCOMPtr *outAnestor); - - // no copy's or assigns FIX ME - nsContentSubtreeIterator(const nsContentSubtreeIterator&); - nsContentSubtreeIterator& operator=(const nsContentSubtreeIterator&); - - nsCOMPtr mRange; - nsVoidArray mStartNodes; - nsVoidArray mStartOffsets; - nsVoidArray mEndNodes; - nsVoidArray mEndOffsets; -}; - -nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aInstancePtrResult); - - - - -/****************************************************** - * repository cruft - ******************************************************/ - -nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aInstancePtrResult) -{ - nsContentIterator * iter = new nsContentSubtreeIterator(); - if (iter) - return iter->QueryInterface(NS_GET_IID(nsIContentIterator), (void**) aInstancePtrResult); - return NS_ERROR_OUT_OF_MEMORY; -} - - - -/****************************************************** - * Init routines - ******************************************************/ - - -nsresult nsContentSubtreeIterator::Init(nsIContent* aRoot) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - - -nsresult nsContentSubtreeIterator::Init(nsIDOMRange* aRange) -{ - if (!aRange) - return NS_ERROR_NULL_POINTER; - - mIsDone = PR_FALSE; - - mRange = do_QueryInterface(aRange); - - // get the start node and offset, convert to nsIContent - nsCOMPtr commonParent; - nsCOMPtr startParent; - nsCOMPtr endParent; - nsCOMPtr cStartP; - nsCOMPtr cEndP; - nsCOMPtr cN; - nsCOMPtr firstCandidate; - nsCOMPtr lastCandidate; - nsCOMPtr dChild; - nsCOMPtr cChild; - PRInt32 indx, startIndx, endIndx; - PRInt32 numChildren; - - // get common content parent - if (NS_FAILED(aRange->GetCommonAncestorContainer(getter_AddRefs(commonParent))) || !commonParent) - return NS_ERROR_FAILURE; - mCommonParent = do_QueryInterface(commonParent); - - // get start content parent - if (NS_FAILED(aRange->GetStartContainer(getter_AddRefs(startParent))) || !startParent) - return NS_ERROR_FAILURE; - cStartP = do_QueryInterface(startParent); - aRange->GetStartOffset(&startIndx); - - // get end content parent - if (NS_FAILED(aRange->GetEndContainer(getter_AddRefs(endParent))) || !endParent) - return NS_ERROR_FAILURE; - cEndP = do_QueryInterface(endParent); - aRange->GetEndOffset(&endIndx); - - // short circuit when start node == end node - if (startParent == endParent) - { - cStartP->ChildAt(0,*getter_AddRefs(cChild)); - - if (!cChild) // no children, must be a text node or empty container - { - // all inside one text node - empty subtree iterator - MakeEmpty(); - return NS_OK; - } - else - { - if (startIndx == endIndx) // collapsed range - { - MakeEmpty(); - return NS_OK; - } - } - } - - // cache ancestors - nsRange::GetAncestorsAndOffsets(startParent, startIndx, &mStartNodes, &mStartOffsets); - nsRange::GetAncestorsAndOffsets(endParent, endIndx, &mEndNodes, &mEndOffsets); - - // find first node in range - aRange->GetStartOffset(&indx); - numChildren = GetNumChildren(startParent); - - if (!numChildren) // no children, must be a text node - { - cN = cStartP; - } - else - { - dChild = GetChildAt(startParent, indx); - cChild = do_QueryInterface(dChild); - if (!cChild) // offset after last child - { - cN = cStartP; - } - else - { - firstCandidate = cChild; - } - } - - if (!firstCandidate) - { - // then firstCandidate is next node after cN - if (NS_FAILED(GetNextSibling(cN, address_of(firstCandidate))) || !firstCandidate) - { - MakeEmpty(); - return NS_OK; - } - } - - firstCandidate = GetDeepFirstChild(firstCandidate); - - // confirm that this first possible contained node - // is indeed contained. Else we have a range that - // does not fully contain any node. - - PRBool nodeBefore, nodeAfter; - if (NS_FAILED(CompareNodeToRange(firstCandidate, aRange, &nodeBefore, &nodeAfter))) - return NS_ERROR_FAILURE; - if (nodeBefore || nodeAfter) - { - MakeEmpty(); - return NS_OK; - } - - // cool, we have the first node in the range. Now we walk - // up it's ancestors to find the most senior that is still - // in the range. That's the real first node. - if (NS_FAILED(GetTopAncestorInRange(firstCandidate, address_of(mFirst)))) - return NS_ERROR_FAILURE; - - - - // now to find the last node - aRange->GetEndOffset(&indx); - numChildren = GetNumChildren(endParent); - - if (indx > numChildren) indx = numChildren; - if (!indx) - { - cN = cEndP; - } - else - { - if (!numChildren) // no children, must be a text node - { - cN = cEndP; - } - else - { - dChild = GetChildAt(endParent, --indx); - cChild = do_QueryInterface(dChild); - if (!cChild) // shouldn't happen - { - NS_ASSERTION(0,"tree traversal trouble in nsContentSubtreeIterator::Init"); - return NS_ERROR_FAILURE; - } - else - { - lastCandidate = cChild; - } - } - } - - if (!lastCandidate) - { - // then lastCandidate is prev node before cN - if (NS_FAILED(GetPrevSibling(cN, address_of(lastCandidate)))) - { - MakeEmpty(); - return NS_OK; - } - } - - lastCandidate = GetDeepLastChild(lastCandidate); - - // confirm that this first possible contained node - // is indeed contained. Else we have a range that - // does not fully contain any node. - - if (NS_FAILED(CompareNodeToRange(lastCandidate, aRange, &nodeBefore, &nodeAfter))) - return NS_ERROR_FAILURE; - if (nodeBefore || nodeAfter) - { - MakeEmpty(); - return NS_OK; - } - - // cool, we have the last node in the range. Now we walk - // up it's ancestors to find the most senior that is still - // in the range. That's the real first node. - if (NS_FAILED(GetTopAncestorInRange(lastCandidate, address_of(mLast)))) - return NS_ERROR_FAILURE; - - mCurNode = mFirst; - - return NS_OK; -} - - -/**************************************************************** - * nsContentSubtreeIterator overrides of ContentIterator routines - ****************************************************************/ - -nsresult nsContentSubtreeIterator::Next() -{ - if (mIsDone) - return NS_OK; - if (!mCurNode) - return NS_OK; - if (mCurNode == mLast) - { - mIsDone = PR_TRUE; - return NS_OK; - } - - nsCOMPtr nextNode; - if (NS_FAILED(GetNextSibling(mCurNode, address_of(nextNode)))) - return NS_OK; -/* - nextNode = GetDeepFirstChild(nextNode); - return GetTopAncestorInRange(nextNode, address_of(mCurNode)); -*/ - PRInt32 i = mEndNodes.IndexOf((void*)nextNode); - while (i != -1) - { - // as long as we are finding ancestors of the endpoint of the range, - // dive down into their children - nsCOMPtr cChild; - nextNode->ChildAt(0,*getter_AddRefs(cChild)); - if (!cChild) return NS_ERROR_NULL_POINTER; - // should be impossible to get a null pointer. If we went all the - // down the child chain to the bottom without finding an interior node, - // then the previous node should have been the last, which was - // was tested at top of routine. - nextNode = cChild; - i = mEndNodes.IndexOf((void*)nextNode); - } - - mCurNode = do_QueryInterface(nextNode); - return NS_OK; -} - - -nsresult nsContentSubtreeIterator::Prev() -{ - if (mIsDone) - return NS_OK; - if (!mCurNode) - return NS_OK; - if (mCurNode == mFirst) - { - mIsDone = PR_TRUE; - return NS_OK; - } - - nsCOMPtr prevNode; - prevNode = GetDeepFirstChild(mCurNode); - if (NS_FAILED(PrevNode(address_of(prevNode)))) - return NS_OK; - prevNode = GetDeepLastChild(prevNode); - return GetTopAncestorInRange(prevNode, address_of(mCurNode)); -} - -nsresult nsContentSubtreeIterator::PositionAt(nsIContent* aCurNode) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -nsresult nsContentSubtreeIterator::MakePre() -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -nsresult nsContentSubtreeIterator::MakePost() -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/**************************************************************** - * nsContentSubtreeIterator helper routines - ****************************************************************/ - -nsresult nsContentSubtreeIterator::GetTopAncestorInRange( - nsCOMPtr aNode, - nsCOMPtr *outAnestor) -{ - if (!aNode) - return NS_ERROR_NULL_POINTER; - if (!outAnestor) - return NS_ERROR_NULL_POINTER; - - - // sanity check: aNode is itself in the range - PRBool nodeBefore, nodeAfter; - if (NS_FAILED(CompareNodeToRange(aNode, mRange, &nodeBefore, &nodeAfter))) - return NS_ERROR_FAILURE; - if (nodeBefore || nodeAfter) - return NS_ERROR_FAILURE; - - nsCOMPtr parent, tmp; - while (aNode) - { - if (NS_FAILED(aNode->GetParent(*getter_AddRefs(parent)))) - return NS_ERROR_FAILURE; - if (!parent) - { - if (tmp) - { - *outAnestor = tmp; - return NS_OK; - } - else return NS_ERROR_FAILURE; - } - if (NS_FAILED(CompareNodeToRange(parent, mRange, &nodeBefore, &nodeAfter))) - return NS_ERROR_FAILURE; - if (nodeBefore || nodeAfter) - { - *outAnestor = aNode; - return NS_OK; - } - tmp = aNode; - aNode = parent; - } - return NS_ERROR_FAILURE; -} - diff --git a/layout/base/src/nsContentList.cpp b/layout/base/src/nsContentList.cpp deleted file mode 100644 index cb08c0c7e59b..000000000000 --- a/layout/base/src/nsContentList.cpp +++ /dev/null @@ -1,565 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsContentList.h" -#include "nsIContent.h" -#include "nsIDOMNode.h" -#include "nsIScriptGlobalObject.h" -#include "nsIDocument.h" -#include "nsINameSpaceManager.h" -#include "nsIDOMScriptObjectFactory.h" -#include "nsGenericElement.h" - -#include "nsLayoutAtoms.h" -#include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms - -nsContentList::nsContentList(nsIDocument *aDocument) -{ - NS_INIT_REFCNT(); - mScriptObject = nsnull; - mFunc = nsnull; - mMatchAtom = nsnull; - mDocument = aDocument; - mData = nsnull; - mMatchAll = PR_FALSE; - mRootContent = nsnull; -} - -nsContentList::nsContentList(nsIDocument *aDocument, - nsIAtom* aMatchAtom, - PRInt32 aMatchNameSpaceId, - nsIContent* aRootContent) -{ - mMatchAtom = aMatchAtom; - NS_IF_ADDREF(mMatchAtom); - if (nsLayoutAtoms::wildcard == mMatchAtom) { - mMatchAll = PR_TRUE; - } - else { - mMatchAll = PR_FALSE; - } - mMatchNameSpaceId = aMatchNameSpaceId; - mFunc = nsnull; - mData = nsnull; - mRootContent = aRootContent; - Init(aDocument); -} - -nsContentList::nsContentList(nsIDocument *aDocument, - nsContentListMatchFunc aFunc, - const nsString* aData, - nsIContent* aRootContent) -{ - mFunc = aFunc; - if (nsnull != aData) { - mData = new nsString(*aData); - // If this fails, fail silently - } - else { - mData = nsnull; - } - mMatchAtom = nsnull; - mRootContent = aRootContent; - mMatchAll = PR_FALSE; - Init(aDocument); -} - -void nsContentList::Init(nsIDocument *aDocument) -{ - NS_INIT_REFCNT(); - mScriptObject = nsnull; - // We don't reference count the reference to the document - // If the document goes away first, we'll be informed and we - // can drop our reference. - // If we go away first, we'll get rid of ourselves from the - // document's observer list. - mDocument = aDocument; - if (nsnull != mDocument) { - mDocument->AddObserver(this); - } - PopulateSelf(); -} - -nsContentList::~nsContentList() -{ - if (nsnull != mDocument) { - mDocument->RemoveObserver(this); - } - - NS_IF_RELEASE(mMatchAtom); - - if (nsnull != mData) { - delete mData; - } -} - -nsresult nsContentList::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (nsnull == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsIDOMNodeList))) { - *aInstancePtr = (void*)(nsIDOMNodeList*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMHTMLCollection))) { - *aInstancePtr = (void*)(nsIDOMHTMLCollection*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - *aInstancePtr = (void*)(nsIScriptObjectOwner*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsISupports))) { - *aInstancePtr = (void*)(nsISupports*)(nsIDOMNodeList*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} - -NS_IMPL_ADDREF(nsContentList) -NS_IMPL_RELEASE(nsContentList) - -NS_IMETHODIMP -nsContentList::GetLength(PRUint32* aLength) -{ - nsresult result = CheckDocumentExistence(); - if (NS_OK == result) { - *aLength = mContent.Count(); - } - - return result; -} - -NS_IMETHODIMP -nsContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn) -{ - nsresult result = CheckDocumentExistence(); - if (NS_OK == result) { - if (nsnull != mDocument) { - mDocument->FlushPendingNotifications(PR_FALSE); // Flush pending content changes Bug 4891 - } - - nsISupports *element = (nsISupports *)mContent.ElementAt(aIndex); - - if (nsnull != element) { - result = element->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)aReturn); - } - else { - *aReturn = nsnull; - } - } - - return result; -} - -NS_IMETHODIMP -nsContentList::NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn) -{ - nsresult result = CheckDocumentExistence(); - - if (NS_OK == result) { - if (nsnull != mDocument) { - mDocument->FlushPendingNotifications(PR_FALSE); // Flush pending content changes Bug 4891 - } - - PRInt32 i, count = mContent.Count(); - - for (i = 0; i < count; i++) { - nsIContent *content = (nsIContent *)mContent.ElementAt(i); - if (nsnull != content) { - nsAutoString name; - // XXX Should it be an EqualsIgnoreCase? - if (((content->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::name, name) == NS_CONTENT_ATTR_HAS_VALUE) && - (aName.Equals(name))) || - ((content->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::id, name) == NS_CONTENT_ATTR_HAS_VALUE) && - (aName.Equals(name)))) { - return content->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)aReturn); - } - } - } - } - - *aReturn = nsnull; - return result; -} - -NS_IMETHODIMP -nsContentList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - nsIScriptGlobalObject *global = aContext->GetGlobalObject(); - - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - res = factory->NewScriptHTMLCollection(aContext, - (nsISupports*)(nsIDOMHTMLCollection*)this, - global, - (void**)&mScriptObject); - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - - NS_RELEASE(global); - return res; -} - -NS_IMETHODIMP -nsContentList::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - -NS_IMETHODIMP -nsContentList::ContentAppended(nsIDocument *aDocument, - nsIContent* aContainer, - PRInt32 aNewIndexInContainer) -{ - PRInt32 i, count; - aContainer->ChildCount(count); - if ((count > 0) && IsDescendantOfRoot(aContainer)) { - PRBool repopulate = PR_FALSE; - for (i = aNewIndexInContainer; i <= count-1; i++) { - nsIContent *content; - aContainer->ChildAt(i, content); - if (mMatchAll || MatchSelf(content)) { - repopulate = PR_TRUE; - } - NS_RELEASE(content); - } - if (repopulate) { - PopulateSelf(); - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsContentList::ContentInserted(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) -{ - if (IsDescendantOfRoot(aContainer)) { - if (mMatchAll || MatchSelf(aChild)) { - PopulateSelf(); - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsContentList::ContentReplaced(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aOldChild, - nsIContent* aNewChild, - PRInt32 aIndexInContainer) -{ - if (IsDescendantOfRoot(aContainer)) { - if (mMatchAll || MatchSelf(aOldChild) || MatchSelf(aNewChild)) { - PopulateSelf(); - } - } - else if (ContainsRoot(aOldChild)) { - DisconnectFromDocument(); - } - - return NS_OK; -} - -NS_IMETHODIMP -nsContentList::ContentRemoved(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) -{ - if (IsDescendantOfRoot(aContainer) && MatchSelf(aChild)) { - PopulateSelf(); - } - else if (ContainsRoot(aChild)) { - DisconnectFromDocument(); - } - - return NS_OK; -} - -NS_IMETHODIMP -nsContentList::DocumentWillBeDestroyed(nsIDocument *aDocument) -{ - if (nsnull != mDocument) { - aDocument->RemoveObserver(this); - mDocument = nsnull; - } - Reset(); - - return NS_OK; -} - - -// Returns whether the content element matches the -// criterion -nsresult -nsContentList::Match(nsIContent *aContent, PRBool *aMatch) -{ - *aMatch = PR_FALSE; - - if (!aContent) { - return NS_OK; - } - - if (mMatchAtom) { - nsCOMPtr ni; - aContent->GetNodeInfo(*getter_AddRefs(ni)); - - if (!ni) - return NS_OK; - - nsCOMPtr node(do_QueryInterface(aContent)); - - if (!node) - return NS_OK; - - PRUint16 type; - node->GetNodeType(&type); - - if (type != nsIDOMNode::ELEMENT_NODE) - return NS_OK; - - if (mMatchNameSpaceId == kNameSpaceID_Unknown) { - if (mMatchAll || ni->Equals(mMatchAtom)) { - *aMatch = PR_TRUE; - } - } else if ((mMatchAll && ni->NamespaceEquals(mMatchNameSpaceId)) || - ni->Equals(mMatchAtom, mMatchNameSpaceId)) { - *aMatch = PR_TRUE; - } - } - else if (nsnull != mFunc) { - *aMatch = (*mFunc)(aContent, mData); - } - - return NS_OK; -} - -nsresult -nsContentList::Add(nsIContent *aContent) -{ - // Shouldn't hold a reference since we'll be - // told when the content leaves the document or - // the document will be destroyed. - mContent.AppendElement(aContent); - - return NS_OK; -} - -nsresult -nsContentList::Remove(nsIContent *aContent) -{ - mContent.RemoveElement(aContent); - - return NS_OK; -} - -nsresult -nsContentList::IndexOf(nsIContent *aContent, PRInt32& aIndex) -{ - aIndex = mContent.IndexOf(aContent); - - return NS_OK; -} - -nsresult -nsContentList::Reset() -{ - mContent.Clear(); - - return NS_OK; -} - -// If we were created outside the context of a document and we -// have root content, then check if our content has been added -// to a document yet. If so, we'll become an observer of the document. -nsresult -nsContentList::CheckDocumentExistence() -{ - nsresult result = NS_OK; - if ((nsnull == mDocument) && (nsnull != mRootContent)) { - result = mRootContent->GetDocument(mDocument); - if (nsnull != mDocument) { - mDocument->AddObserver(this); - PopulateSelf(); - } - } - - return result; -} - -// Match recursively. See if anything in the subtree -// matches the criterion. -PRBool -nsContentList::MatchSelf(nsIContent *aContent) -{ - PRBool match; - PRInt32 i, count; - - Match(aContent, &match); - if (match) { - return PR_TRUE; - } - - aContent->ChildCount(count); - for (i = 0; i < count; i++) { - nsIContent *child; - aContent->ChildAt(i, child); - if (MatchSelf(child)) { - NS_RELEASE(child); - return PR_TRUE; - } - NS_RELEASE(child); - } - - return PR_FALSE; -} - -// Add all elements in this subtree that match to -// our list. -void -nsContentList::PopulateWith(nsIContent *aContent, PRBool aIncludeRoot) -{ - PRBool match; - PRInt32 i, count; - - if (aIncludeRoot) { - Match(aContent, &match); - if (match) { - Add(aContent); - } - } - - aContent->ChildCount(count); - for (i = 0; i < count; i++) { - nsIContent *child; - aContent->ChildAt(i, child); - PopulateWith(child, PR_TRUE); - NS_RELEASE(child); - } -} - -// Clear out our old list and build up a new one -void -nsContentList::PopulateSelf() -{ - Reset(); - if (nsnull != mRootContent) { - PopulateWith(mRootContent, PR_FALSE); - } - else if (nsnull != mDocument) { - nsIContent *root; - root = mDocument->GetRootContent(); - if (root) { - PopulateWith(root, PR_TRUE); - NS_RELEASE(root); - } - } -} - -// Is the specified element a descendant of the root? If there -// is no root, then yes. Otherwise keep tracing up the tree from -// the element till we find our root, or until we reach the -// document root. -PRBool -nsContentList::IsDescendantOfRoot(nsIContent* aContainer) -{ - if (nsnull == mRootContent) { - return PR_TRUE; - } - else if (mRootContent == aContainer) { - return PR_TRUE; - } - else if (nsnull == aContainer) { - return PR_FALSE; - } - else { - nsIContent* parent; - PRBool ret; - - aContainer->GetParent(parent); - ret = IsDescendantOfRoot(parent); - NS_IF_RELEASE(parent); - - return ret; - } -} - -// Does this subtree contain the root? -PRBool -nsContentList::ContainsRoot(nsIContent* aContent) -{ - if (nsnull == mRootContent) { - return PR_FALSE; - } - else if (mRootContent == aContent) { - return PR_TRUE; - } - else { - PRInt32 i, count; - - aContent->ChildCount(count); - for (i = 0; i < count; i++) { - nsIContent *child; - aContent->ChildAt(i, child); - if (ContainsRoot(child)) { - NS_RELEASE(child); - return PR_TRUE; - } - NS_RELEASE(child); - } - - return PR_FALSE; - } -} - -// Our root content has been disconnected from the -// document, so stop observing. The list then becomes -// a snapshot rather than a dynamic list. -void -nsContentList::DisconnectFromDocument() -{ - if (nsnull != mDocument) { - mDocument->RemoveObserver(this); - mDocument = nsnull; - } -} diff --git a/layout/base/src/nsContentList.h b/layout/base/src/nsContentList.h deleted file mode 100644 index 8d0d557e4bd0..000000000000 --- a/layout/base/src/nsContentList.h +++ /dev/null @@ -1,148 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsContentList_h___ -#define nsContentList_h___ - -#include "nsISupports.h" -#include "nsVoidArray.h" -#include "nsString.h" -#include "nsIDOMHTMLCollection.h" -#include "nsIDOMNodeList.h" -#include "nsIDocumentObserver.h" -#include "nsIScriptObjectOwner.h" - -typedef PRBool (*nsContentListMatchFunc)(nsIContent* aContent, nsString* aData); - -class nsIDocument; - -class nsContentList : public nsIDOMNodeList, - public nsIDOMHTMLCollection, - public nsIScriptObjectOwner, - public nsIDocumentObserver { -public: - nsContentList(nsIDocument *aDocument); - nsContentList(nsIDocument *aDocument, - nsIAtom* aMatchAtom, - PRInt32 aMatchNameSpaceId, - nsIContent* aRootContent=nsnull); - nsContentList(nsIDocument *aDocument, - nsContentListMatchFunc aFunc, - const nsString* aData, - nsIContent* aRootContent=nsnull); - virtual ~nsContentList(); - - NS_DECL_ISUPPORTS - - // nsIDOMHTMLCollection - NS_IMETHOD GetLength(PRUint32* aLength); - - NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn); - - NS_IMETHOD NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn); - - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - - // nsIDocumentObserver - NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; } - NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; } - NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; } - NS_IMETHOD EndLoad(nsIDocument *aDocument) { return NS_OK; } - NS_IMETHOD BeginReflow(nsIDocument *aDocument, - nsIPresShell* aShell) { return NS_OK; } - NS_IMETHOD EndReflow(nsIDocument *aDocument, - nsIPresShell* aShell) { return NS_OK; } - NS_IMETHOD ContentChanged(nsIDocument *aDocument, - nsIContent* aContent, - nsISupports* aSubContent) { return NS_OK; } - NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument, - nsIContent* aContent1, - nsIContent* aContent2) { return NS_OK; } - NS_IMETHOD AttributeChanged(nsIDocument *aDocument, - nsIContent* aContent, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aHint) { return NS_OK; } - NS_IMETHOD ContentAppended(nsIDocument *aDocument, - nsIContent* aContainer, - PRInt32 aNewIndexInContainer); - NS_IMETHOD ContentInserted(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer); - NS_IMETHOD ContentReplaced(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aOldChild, - nsIContent* aNewChild, - PRInt32 aIndexInContainer); - NS_IMETHOD ContentRemoved(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer); - NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet) { return NS_OK; } - NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet) { return NS_OK; } - NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - PRBool aDisabled) { return NS_OK; } - NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule, - PRInt32 aHint) { return NS_OK; } - NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule) { return NS_OK; } - NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule) { return NS_OK; } - NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument); - - nsresult Add(nsIContent *aContent); - nsresult Remove(nsIContent *aContent); - nsresult IndexOf(nsIContent *aContent, PRInt32& aIndex); - -protected: - nsresult Match(nsIContent *aContent, PRBool *aMatch); - nsresult Reset(); - void Init(nsIDocument *aDocument); - void PopulateWith(nsIContent *aContent, PRBool aIncludeRoot); - PRBool MatchSelf(nsIContent *aContent); - void PopulateSelf(); - void DisconnectFromDocument(); - PRBool IsDescendantOfRoot(nsIContent* aContainer); - PRBool ContainsRoot(nsIContent* aContent); - nsresult CheckDocumentExistence(); - - nsIAtom* mMatchAtom; - PRInt32 mMatchNameSpaceId; - nsContentListMatchFunc mFunc; - nsString* mData; - nsVoidArray mContent; - void *mScriptObject; - nsIDocument* mDocument; - nsIContent* mRootContent; - PRBool mMatchAll; -}; - -#endif // nsContentList_h___ diff --git a/layout/base/src/nsContentPolicy.cpp b/layout/base/src/nsContentPolicy.cpp deleted file mode 100644 index 0e129563294b..000000000000 --- a/layout/base/src/nsContentPolicy.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla code. - * - * The Initial Developer of the Original Code is Zero-Knowledge Systems, - * Inc. Portions created by Zero-Knowledge are Copyright (C) 2000 - * Zero-Knowledge Systems, Inc. All Rights Reserved. - * - * Contributor(s): - */ - -#include "nsISupports.h" -#include "nsISupportsPrimitives.h" -#include "nsXPIDLString.h" -#include "nsContentPolicyUtils.h" -#include "nsContentPolicy.h" -#include "nsICategoryManager.h" - -NS_IMPL_ISUPPORTS1(nsContentPolicy, nsIContentPolicy) - -nsresult -NS_NewContentPolicy(nsIContentPolicy **aResult) -{ - *aResult = new nsContentPolicy; - if (!*aResult) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(*aResult); - return NS_OK; -} - -/* - * This constructor does far too much. I wish there was a way to get - * an Init method called by the service manager after the factory - * returned the new object, so that errors could be propagated back to - * the caller correctly. - */ -nsContentPolicy::nsContentPolicy() -{ - NS_INIT_REFCNT(); - nsresult rv; - NS_WITH_SERVICE(nsICategoryManager, catman, NS_CATEGORYMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) - /* log an error? */ - return; - - /* - * I'd like to use GetCategoryContents, so that I can size the array - * correctly on the first go and avoid the enumerator overhead, but it's - * not yet implemented (see nsCategoryManager.cpp). No biggie, I guess. - */ - nsCOMPtr catEnum; - if (NS_FAILED(catman->EnumerateCategory(NS_CONTENTPOLICY_CATEGORY, - getter_AddRefs(catEnum)))) { - /* no category, no problem */ - return; - } - - PRBool hasMore; - if (NS_FAILED(catEnum->HasMoreElements(&hasMore)) || !hasMore || - NS_FAILED(NS_NewISupportsArray(getter_AddRefs(mPolicies)))) { - return; - } - - /* - * Populate mPolicies with policy services named by contractids in the - * "content-policy" category. - */ - nsCOMPtr item; - while (NS_SUCCEEDED(catEnum->GetNext(getter_AddRefs(item)))) { - nsCOMPtr string = do_QueryInterface(item, &rv); - if (NS_FAILED(rv)) - continue; - - nsXPIDLCString contractid; - if (NS_FAILED(string->GetData(getter_Copies(contractid)))) - continue; - -#ifdef DEBUG_shaver - fprintf(stderr, "POLICY: loading %s\n", (const char *)contractid); -#endif - /* - * Create this policy service and add to mPolicies. - * - * Should we try to parse as a CID, in case the component prefers to be - * registered that way? - */ - nsCOMPtr policy = do_GetService(contractid, &rv); - if (NS_SUCCEEDED(rv)) - mPolicies->AppendElement(policy); - } - -} - -nsContentPolicy::~nsContentPolicy() -{ -} - -#define POLICY_LOAD 0 -#define POLICY_PROCESS 1 - -NS_IMETHODIMP -nsContentPolicy::CheckPolicy(PRInt32 policyType, PRInt32 contentType, - nsIDOMElement *element, - const PRUnichar *contentLocation, - PRBool *shouldProceed) -{ - *shouldProceed = PR_TRUE; - if (!mPolicies) - return NS_OK; - - /* - * Enumerate mPolicies and ask each of them, taking the logical AND of - * their permissions. - */ - nsresult rv; - nsCOMPtr policy; - PRUint32 count; - if (NS_FAILED(rv = mPolicies->Count(&count))) - return NS_OK; - - for (PRUint32 i = 0; i < count; i++) { - rv = mPolicies->QueryElementAt(i, NS_GET_IID(nsIContentPolicy), - getter_AddRefs(policy)); - if (NS_FAILED(rv)) - continue; - - /* check the appropriate policy */ - if (policyType == POLICY_LOAD) - rv = policy->ShouldLoad(contentType, element, contentLocation, - shouldProceed); - else - rv = policy->ShouldProcess(contentType, element, contentLocation, - shouldProceed); - - if (NS_SUCCEEDED(rv) && !*shouldProceed) - /* policy says no, no point continuing to check */ - return NS_OK; - } - - /* - * One of the policy objects might be misbehaving and setting shouldProceed - * to PR_FALSE before returning an error, so force it back to PR_TRUE - * here. - */ - *shouldProceed = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -nsContentPolicy::ShouldLoad(PRInt32 contentType, nsIDOMElement *element, - const PRUnichar *contentLocation, - PRBool *shouldLoad) -{ - return CheckPolicy(POLICY_LOAD, contentType, element, contentLocation, - shouldLoad); -} - -NS_IMETHODIMP -nsContentPolicy::ShouldProcess(PRInt32 contentType, nsIDOMElement *element, - const PRUnichar *contentLocation, - PRBool *shouldProcess) -{ - return CheckPolicy(POLICY_PROCESS, contentType, element, contentLocation, - shouldProcess); -} - diff --git a/layout/base/src/nsContentPolicy.h b/layout/base/src/nsContentPolicy.h deleted file mode 100644 index 4d28c150a04f..000000000000 --- a/layout/base/src/nsContentPolicy.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla code. - * - * The Initial Developer of the Original Code is Zero-Knowledge Systems, - * Inc. Portions created by Zero-Knowledge are Copyright (C) 2000 - * Zero-Knowledge Systems, Inc. All Rights Reserved. - * - * Contributor(s): - */ - -#include "nsIContentPolicy.h" -#include "nsISupportsArray.h" - -#ifndef __nsContentPolicy_h__ -#define __nsContentPolicy_h__ - -class nsContentPolicy : public nsIContentPolicy -{ - public: - NS_DECL_ISUPPORTS - NS_DECL_NSICONTENTPOLICY - nsContentPolicy(); - virtual ~nsContentPolicy(); - private: - nsCOMPtr mPolicies; - NS_IMETHOD CheckPolicy(PRInt32 policyType, PRInt32 contentType, - nsIDOMElement *element, - const PRUnichar *contentLocation, - PRBool *shouldProceed); -}; - -nsresult -NS_NewContentPolicy(nsIContentPolicy **aResult); - -#endif /* __nsContentPolicy_h__ */ diff --git a/layout/base/src/nsDOMAttribute.cpp b/layout/base/src/nsDOMAttribute.cpp deleted file mode 100644 index 4829cda18e75..000000000000 --- a/layout/base/src/nsDOMAttribute.cpp +++ /dev/null @@ -1,575 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsDOMAttribute.h" -#include "nsGenericElement.h" -#include "nsIContent.h" -#include "nsIDOMScriptObjectFactory.h" -#include "nsITextContent.h" -#include "nsINameSpaceManager.h" -#include "nsDOMError.h" - -//---------------------------------------------------------------------- - -nsDOMAttribute::nsDOMAttribute(nsIContent* aContent, - nsINodeInfo *aNodeInfo, - const nsAReadableString& aValue) - : mNodeInfo(aNodeInfo), mValue(aValue) -{ - NS_ABORT_IF_FALSE(mNodeInfo, "We must get a nodeinfo here!"); - - NS_INIT_REFCNT(); - // We don't add a reference to our content. It will tell us - // to drop our reference when it goes away. - mContent = aContent; - mScriptObject = nsnull; - mChild = nsnull; - mChildList = nsnull; -} - -nsDOMAttribute::~nsDOMAttribute() -{ - NS_IF_RELEASE(mChild); - NS_IF_RELEASE(mChildList); -} - -nsresult -nsDOMAttribute::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsIDOMAttr))) { - nsIDOMAttr* tmp = this; - *aInstancePtr = (void*)tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - nsIScriptObjectOwner* tmp = this; - *aInstancePtr = (void*)tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMAttributePrivate))) { - nsIDOMAttributePrivate* tmp = this; - *aInstancePtr = (void*)tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDOMNode))) { - nsIDOMNode* tmp = this; - *aInstancePtr = (void*)tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsISupports))) { - nsIDOMAttr* tmp1 = this; - nsISupports* tmp2 = tmp1; - *aInstancePtr = (void*)tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} - -NS_IMPL_ADDREF(nsDOMAttribute) -NS_IMPL_RELEASE(nsDOMAttribute) - -NS_IMETHODIMP -nsDOMAttribute::DropReference() -{ - mContent = nsnull; - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::SetContent(nsIContent* aContent) -{ - mContent = aContent; - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::GetContent(nsIContent** aContent) -{ - *aContent = mContent; - NS_IF_ADDREF(*aContent); - - return NS_OK; -} - -nsresult -nsDOMAttribute::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - res = factory->NewScriptAttr(aContext, - (nsISupports *)(nsIDOMAttr *)this, - (nsISupports *)mContent, - (void **)&mScriptObject); - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - return res; -} - -nsresult -nsDOMAttribute::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - -nsresult -nsDOMAttribute::GetName(nsAWritableString& aName) -{ - NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_FAILURE); - - return mNodeInfo->GetQualifiedName(aName); -} - -nsresult -nsDOMAttribute::GetValue(nsAWritableString& aValue) -{ - NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_FAILURE); - - nsresult result = NS_OK; - if (nsnull != mContent) { - nsresult attrResult; - PRInt32 nameSpaceID; - nsCOMPtr name; - - mNodeInfo->GetNameAtom(*getter_AddRefs(name)); - mNodeInfo->GetNamespaceID(nameSpaceID); - - nsAutoString tmpValue; - attrResult = mContent->GetAttribute(nameSpaceID, name, tmpValue); - if (NS_CONTENT_ATTR_NOT_THERE != attrResult) { - mValue = tmpValue; - } - } - aValue=mValue; - return result; -} - -nsresult -nsDOMAttribute::SetValue(const nsAReadableString& aValue) -{ - NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_FAILURE); - - nsresult result = NS_OK; - if (nsnull != mContent) { - result = mContent->SetAttribute(mNodeInfo, aValue, PR_TRUE); - } - mValue=aValue; - - return result; -} - -nsresult -nsDOMAttribute::GetSpecified(PRBool* aSpecified) -{ - NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_FAILURE); - NS_ENSURE_ARG_POINTER(aSpecified); - - nsresult result = NS_OK; - if (nsnull == mContent) { - *aSpecified = PR_FALSE; - } else { - nsAutoString value; - nsresult attrResult; - PRInt32 nameSpaceID; - nsCOMPtr name; - - mNodeInfo->GetNameAtom(*getter_AddRefs(name)); - mNodeInfo->GetNamespaceID(nameSpaceID); - - attrResult = mContent->GetAttribute(nameSpaceID, name, value); - if (NS_CONTENT_ATTR_HAS_VALUE == attrResult) { - *aSpecified = PR_TRUE; - } - else { - *aSpecified = PR_FALSE; - } - } - - return result; -} - -NS_IMETHODIMP -nsDOMAttribute::GetOwnerElement(nsIDOMElement** aOwnerElement) -{ - NS_ENSURE_ARG_POINTER(aOwnerElement); - - if (mContent) { - return mContent->QueryInterface(NS_GET_IID(nsIDOMElement), - (void **)aOwnerElement); - } - - *aOwnerElement = nsnull; - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::GetNodeName(nsAWritableString& aNodeName) -{ - return GetName(aNodeName); -} - -NS_IMETHODIMP -nsDOMAttribute::GetNodeValue(nsAWritableString& aNodeValue) -{ - return GetValue(aNodeValue); -} - -NS_IMETHODIMP -nsDOMAttribute::SetNodeValue(const nsAReadableString& aNodeValue) -{ - return SetValue(aNodeValue); -} - -NS_IMETHODIMP -nsDOMAttribute::GetNodeType(PRUint16* aNodeType) -{ - NS_ENSURE_ARG_POINTER(aNodeType); - - *aNodeType = (PRUint16)nsIDOMNode::ATTRIBUTE_NODE; - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::GetParentNode(nsIDOMNode** aParentNode) -{ - NS_ENSURE_ARG_POINTER(aParentNode); - - *aParentNode = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::GetChildNodes(nsIDOMNodeList** aChildNodes) -{ - if (nsnull == mChildList) { - mChildList = new nsAttributeChildList(this); - if (nsnull == mChildList) { - return NS_ERROR_OUT_OF_MEMORY; - } - NS_ADDREF(mChildList); - } - - return mChildList->QueryInterface(NS_GET_IID(nsIDOMNodeList), (void**)aChildNodes); -} - -NS_IMETHODIMP -nsDOMAttribute::HasChildNodes(PRBool* aHasChildNodes) -{ - *aHasChildNodes = PR_FALSE; - if (nsnull != mChild) { - *aHasChildNodes = PR_TRUE; - } - else if (nsnull != mContent) { - nsAutoString value; - - GetValue(value); - if (0 < value.Length()) { - *aHasChildNodes = PR_TRUE; - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::HasAttributes(PRBool* aHasAttributes) -{ - NS_ENSURE_ARG_POINTER(aHasAttributes); - - *aHasAttributes = PR_FALSE; - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::GetFirstChild(nsIDOMNode** aFirstChild) -{ - nsAutoString value; - nsresult result; - - result = GetValue(value); - if (NS_OK != result) { - return result; - } - if (0 < value.Length()) { - if (nsnull == mChild) { - nsIContent* content; - - result = NS_NewTextNode(&content); - if (NS_OK != result) { - return result; - } - result = content->QueryInterface(NS_GET_IID(nsIDOMText), (void**)&mChild); - NS_RELEASE(content); - } - mChild->SetData(value); - result = mChild->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aFirstChild); - } - else { - *aFirstChild = nsnull; - } - return result; -} - -NS_IMETHODIMP -nsDOMAttribute::GetLastChild(nsIDOMNode** aLastChild) -{ - return GetFirstChild(aLastChild); -} - -NS_IMETHODIMP -nsDOMAttribute::GetPreviousSibling(nsIDOMNode** aPreviousSibling) -{ - NS_ENSURE_ARG_POINTER(aPreviousSibling); - - *aPreviousSibling = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::GetNextSibling(nsIDOMNode** aNextSibling) -{ - NS_ENSURE_ARG_POINTER(aNextSibling); - - *aNextSibling = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::GetAttributes(nsIDOMNamedNodeMap** aAttributes) -{ - NS_ENSURE_ARG_POINTER(aAttributes); - - *aAttributes = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn) -{ - return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; -} - -NS_IMETHODIMP -nsDOMAttribute::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn) -{ - return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; -} - -NS_IMETHODIMP -nsDOMAttribute::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) -{ - return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; -} - -NS_IMETHODIMP -nsDOMAttribute::AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn) -{ - return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; -} - -NS_IMETHODIMP -nsDOMAttribute::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) -{ - nsDOMAttribute* newAttr; - - if (nsnull != mContent) { - nsAutoString value; - PRInt32 nameSpaceID; - nsCOMPtr name; - - mNodeInfo->GetNameAtom(*getter_AddRefs(name)); - mNodeInfo->GetNamespaceID(nameSpaceID); - - mContent->GetAttribute(nameSpaceID, name, value); - newAttr = new nsDOMAttribute(nsnull, mNodeInfo, value); - } - else { - newAttr = new nsDOMAttribute(nsnull, mNodeInfo, mValue); - } - - if (nsnull == newAttr) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return newAttr->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aReturn); -} - -NS_IMETHODIMP -nsDOMAttribute::GetOwnerDocument(nsIDOMDocument** aOwnerDocument) -{ - nsresult result = NS_OK; - if (nsnull != mContent) { - nsIDOMNode* node; - result = mContent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node); - if (NS_SUCCEEDED(result)) { - result = node->GetOwnerDocument(aOwnerDocument); - NS_RELEASE(node); - } - } - else { - *aOwnerDocument = nsnull; - } - - return result; -} - -NS_IMETHODIMP -nsDOMAttribute::GetNamespaceURI(nsAWritableString& aNamespaceURI) -{ - NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_FAILURE); - - return mNodeInfo->GetNamespaceURI(aNamespaceURI); -} - -NS_IMETHODIMP -nsDOMAttribute::GetPrefix(nsAWritableString& aPrefix) -{ - NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_FAILURE); - - return mNodeInfo->GetPrefix(aPrefix); -} - -NS_IMETHODIMP -nsDOMAttribute::SetPrefix(const nsAReadableString& aPrefix) -{ - NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_FAILURE); - nsCOMPtr newNodeInfo; - nsCOMPtr prefix; - nsresult rv = NS_OK; - - if (aPrefix.Length()) - prefix = dont_AddRef(NS_NewAtom(aPrefix)); - - rv = mNodeInfo->PrefixChanged(prefix, *getter_AddRefs(newNodeInfo)); - NS_ENSURE_SUCCESS(rv, rv); - - if (mContent) { - nsCOMPtr name; - PRInt32 nameSpaceID; - nsAutoString tmpValue; - - mNodeInfo->GetNameAtom(*getter_AddRefs(name)); - mNodeInfo->GetNamespaceID(nameSpaceID); - - rv = mContent->GetAttribute(nameSpaceID, name, tmpValue); - if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - mContent->UnsetAttribute(nameSpaceID, name, PR_TRUE); - - mContent->SetAttribute(newNodeInfo, tmpValue, PR_TRUE); - } - } - - mNodeInfo = newNodeInfo; - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::GetLocalName(nsAWritableString& aLocalName) -{ - NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_FAILURE); - - return mNodeInfo->GetLocalName(aLocalName); -} - -NS_IMETHODIMP -nsDOMAttribute::Normalize() -{ - // Nothing to do here - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::IsSupported(const nsAReadableString& aFeature, - const nsAReadableString& aVersion, - PRBool* aReturn) -{ - return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn); -} - - -//---------------------------------------------------------------------- - -nsAttributeChildList::nsAttributeChildList(nsDOMAttribute* aAttribute) -{ - // Don't increment the reference count. The attribute will tell - // us when it's going away - mAttribute = aAttribute; -} - -nsAttributeChildList::~nsAttributeChildList() -{ -} - -NS_IMETHODIMP -nsAttributeChildList::GetLength(PRUint32* aLength) -{ - nsAutoString value; - - *aLength = 0; - if (nsnull != mAttribute) { - mAttribute->GetValue(value); - if (0 < value.Length()) { - *aLength = 1; - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsAttributeChildList::Item(PRUint32 aIndex, nsIDOMNode** aReturn) -{ - *aReturn = nsnull; - if ((nsnull != mAttribute) && (0 == aIndex)) { - mAttribute->GetFirstChild(aReturn); - } - - return NS_OK; -} - -void -nsAttributeChildList::DropReference() -{ - mAttribute = nsnull; -} diff --git a/layout/base/src/nsDOMAttribute.h b/layout/base/src/nsDOMAttribute.h deleted file mode 100644 index 188420e64411..000000000000 --- a/layout/base/src/nsDOMAttribute.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsDOMAttribute_h___ -#define nsDOMAttribute_h___ - -#include "nsIDOMAttr.h" -#include "nsIDOMText.h" -#include "nsIDOMNodeList.h" -#include "nsIScriptObjectOwner.h" -#include "nsGenericDOMNodeList.h" -#include "nsString.h" -#include "nsCOMPtr.h" -#include "nsINodeInfo.h" - -class nsIContent; -class nsDOMAttribute; - -#define NS_IDOMATTRIBUTEPRIVATE_IID \ - {0xa6cf90dd, 0x15b3, 0x11d2, \ - {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}} - -class nsIDOMAttributePrivate : public nsISupports { -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOMATTRIBUTEPRIVATE_IID) - - NS_IMETHOD DropReference() = 0; - NS_IMETHOD SetContent(nsIContent* aContent) = 0; - NS_IMETHOD GetContent(nsIContent** aContent) = 0; -}; - -// bogus child list for an attribute -class nsAttributeChildList : public nsGenericDOMNodeList -{ -public: - nsAttributeChildList(nsDOMAttribute* aAttribute); - virtual ~nsAttributeChildList(); - - // interface nsIDOMNodeList - NS_IMETHOD GetLength(PRUint32* aLength); - NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn); - - void DropReference(); - -protected: - nsDOMAttribute* mAttribute; -}; - -// Attribute helper class used to wrap up an attribute with a dom -// object that implements nsIDOMAttr and nsIDOMNode and -// nsIScriptObjectOwner -class nsDOMAttribute : public nsIDOMAttr, - public nsIScriptObjectOwner, - public nsIDOMAttributePrivate -{ -public: - nsDOMAttribute(nsIContent* aContent, nsINodeInfo *aNodeInfo, - const nsAReadableString& aValue); - virtual ~nsDOMAttribute(); - - NS_DECL_ISUPPORTS - - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - - // nsIDOMAttr interface - NS_DECL_IDOMATTR - - // nsIDOMNode interface - NS_DECL_IDOMNODE - - // nsIDOMAttributePrivate interface - NS_IMETHOD DropReference(); - NS_IMETHOD SetContent(nsIContent* aContent); - NS_IMETHOD GetContent(nsIContent** aContent); - -private: - nsIContent* mContent; - nsCOMPtr mNodeInfo; - nsString mValue; - // XXX For now, there's only a single child - a text - // element representing the value - nsIDOMText* mChild; - nsAttributeChildList* mChildList; - void* mScriptObject; -}; - - -#endif /* nsDOMAttribute_h___ */ diff --git a/layout/base/src/nsDOMAttributeMap.cpp b/layout/base/src/nsDOMAttributeMap.cpp deleted file mode 100644 index 913c9066742b..000000000000 --- a/layout/base/src/nsDOMAttributeMap.cpp +++ /dev/null @@ -1,478 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsDOMAttributeMap.h" -#include "nsDOMAttribute.h" -#include "nsGenericElement.h" -#include "nsIContent.h" -#include "nsIDOMScriptObjectFactory.h" -#include "nsINameSpaceManager.h" -#include "nsDOMError.h" - - -//---------------------------------------------------------------------- - -nsDOMAttributeMap::nsDOMAttributeMap(nsIContent* aContent) - : mContent(aContent) -{ - NS_INIT_REFCNT(); - mScriptObject = nsnull; - // We don't add a reference to our content. If it goes away, - // we'll be told to drop our reference -} - -nsDOMAttributeMap::~nsDOMAttributeMap() -{ -} - -void -nsDOMAttributeMap::DropReference() -{ - mContent = nsnull; -} - -NS_INTERFACE_MAP_BEGIN(nsDOMAttributeMap) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNamedNodeMap) - NS_INTERFACE_MAP_ENTRY(nsIDOMNamedNodeMap) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) -NS_INTERFACE_MAP_END - -NS_IMPL_ADDREF(nsDOMAttributeMap) -NS_IMPL_RELEASE(nsDOMAttributeMap) - -nsresult -nsDOMAttributeMap::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - res = factory->NewScriptNamedNodeMap(aContext, - (nsISupports *)(nsIDOMNamedNodeMap *)this, - (nsISupports *)mContent, - (void**)&mScriptObject); - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - return res; -} - -nsresult -nsDOMAttributeMap::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - -nsresult -nsDOMAttributeMap::GetNamedItem(const nsAReadableString& aAttrName, - nsIDOMNode** aAttribute) -{ - NS_ENSURE_ARG_POINTER(aAttribute); - *aAttribute = nsnull; - - nsresult rv = NS_OK; - if (mContent) { - nsCOMPtr ni; - mContent->NormalizeAttributeString(aAttrName, *getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - PRInt32 nsid; - nsCOMPtr nameAtom; - - ni->GetNamespaceID(nsid); - ni->GetNameAtom(*getter_AddRefs(nameAtom)); - - nsresult attrResult; - - nsAutoString value; - attrResult = mContent->GetAttribute(nsid, nameAtom, value); - - if (NS_CONTENT_ATTR_NOT_THERE != attrResult && NS_SUCCEEDED(attrResult)) { - nsDOMAttribute* domAttribute; - domAttribute = new nsDOMAttribute(mContent, ni, value); - NS_ENSURE_TRUE(domAttribute, NS_ERROR_OUT_OF_MEMORY); - - rv = domAttribute->QueryInterface(NS_GET_IID(nsIDOMAttr), - (void **)aAttribute); - } - } - - return rv; -} - -nsresult -nsDOMAttributeMap::SetNamedItem(nsIDOMNode *aNode, nsIDOMNode **aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - - if (!aNode) { - return NS_ERROR_NULL_POINTER; - } - - nsresult rv = NS_OK; - *aReturn = nsnull; - - if (mContent) { - nsCOMPtr attribute(do_QueryInterface(aNode)); - - if (!attribute) { - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - nsAutoString name, value; - - attribute->GetName(name); - - nsCOMPtr ni; - mContent->NormalizeAttributeString(name, *getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - nsCOMPtr nameAtom; - PRInt32 nsid; - - ni->GetNamespaceID(nsid); - ni->GetNameAtom(*getter_AddRefs(nameAtom)); - - nsresult attrResult = mContent->GetAttribute(nsid, nameAtom, value); - - if (NS_CONTENT_ATTR_NOT_THERE != attrResult && NS_SUCCEEDED(attrResult)) { - nsDOMAttribute* domAttribute; - // We pass a null content here since the attr node we return isn't - // tied to this content anymore. - domAttribute = new nsDOMAttribute(nsnull, ni, value); - if (!domAttribute) { - return NS_ERROR_OUT_OF_MEMORY; - } - - rv = domAttribute->QueryInterface(NS_GET_IID(nsIDOMAttr), - (void **)aReturn); - } - - attribute->GetValue(value); - - rv = mContent->SetAttribute(ni, value, PR_TRUE); - } - - return rv; -} - -NS_IMETHODIMP -nsDOMAttributeMap::RemoveNamedItem(const nsAReadableString& aName, - nsIDOMNode** aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - *aReturn = nsnull; - - nsresult rv = NS_OK; - - if (mContent) { - nsCOMPtr ni; - mContent->NormalizeAttributeString(aName, *getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - nsCOMPtr nameAtom; - PRInt32 nsid; - - ni->GetNamespaceID(nsid); - ni->GetNameAtom(*getter_AddRefs(nameAtom)); - - nsCOMPtr attribute; - - nsresult attrResult; - nsAutoString value; - attrResult = mContent->GetAttribute(nsid, nameAtom, value); - - if (NS_CONTENT_ATTR_NOT_THERE != attrResult && NS_SUCCEEDED(attrResult)) { - nsDOMAttribute* domAttribute; - domAttribute = new nsDOMAttribute(nsnull, ni, value); - if (!domAttribute) { - return NS_ERROR_OUT_OF_MEMORY; - } - - rv = domAttribute->QueryInterface(NS_GET_IID(nsIDOMAttr), - (void **)aReturn); - } else { - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - - rv = mContent->UnsetAttribute(nsid, nameAtom, PR_TRUE); - } - - return rv; -} - - -nsresult -nsDOMAttributeMap::Item(PRUint32 aIndex, nsIDOMNode** aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - PRInt32 nameSpaceID; - nsCOMPtr nameAtom, prefix; - - nsresult rv = NS_OK; - if (mContent && - NS_SUCCEEDED(mContent->GetAttributeNameAt(aIndex, - nameSpaceID, - *getter_AddRefs(nameAtom), - *getter_AddRefs(prefix)))) { - nsAutoString value, name; - mContent->GetAttribute(nameSpaceID, nameAtom, value); - - nsCOMPtr ni; - mContent->GetNodeInfo(*getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - nsCOMPtr nimgr; - ni->GetNodeInfoManager(*getter_AddRefs(nimgr)); - NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); - - nimgr->GetNodeInfo(nameAtom, prefix, nameSpaceID, *getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - nsDOMAttribute* domAttribute = new nsDOMAttribute(mContent, ni, value); - NS_ENSURE_TRUE(domAttribute, NS_ERROR_OUT_OF_MEMORY); - - rv = domAttribute->QueryInterface(NS_GET_IID(nsIDOMAttr), - (void **)aReturn); - } - else { - *aReturn = nsnull; - } - - return rv; -} - -nsresult -nsDOMAttributeMap::GetLength(PRUint32 *aLength) -{ - NS_ENSURE_ARG_POINTER(aLength); - - PRInt32 n; - nsresult rv = NS_OK; - - if (nsnull != mContent) { - rv = mContent->GetAttributeCount(n); - *aLength = PRUint32(n); - } else { - *aLength = 0; - } - return rv; -} - -nsresult -nsDOMAttributeMap::GetNamedItemNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - nsIDOMNode** aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - *aReturn = nsnull; - - nsresult rv = NS_OK; - if (mContent) { - nsCOMPtr nameAtom(dont_AddRef(NS_NewAtom(aLocalName))); - PRInt32 nameSpaceID = kNameSpaceID_None; - nsCOMPtr prefix; - - nsCOMPtr ni; - mContent->GetNodeInfo(*getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - nsCOMPtr nimgr; - ni->GetNodeInfoManager(*getter_AddRefs(nimgr)); - NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); - - if (aNamespaceURI.Length()) { - nsCOMPtr nsmgr; - nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); - NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); - - nsmgr->GetNameSpaceID(aNamespaceURI, nameSpaceID); - - if (nameSpaceID == kNameSpaceID_Unknown) - return NS_OK; - } - - nsresult attrResult; - nsAutoString value; - - attrResult = mContent->GetAttribute(nameSpaceID, nameAtom, - *getter_AddRefs(prefix), value); - - if (NS_CONTENT_ATTR_NOT_THERE != attrResult && NS_SUCCEEDED(attrResult)) { - nimgr->GetNodeInfo(nameAtom, prefix, nameSpaceID, *getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - nsDOMAttribute* domAttribute; - domAttribute = new nsDOMAttribute(mContent, ni, value); - NS_ENSURE_TRUE(domAttribute, NS_ERROR_OUT_OF_MEMORY); - - rv = domAttribute->QueryInterface(NS_GET_IID(nsIDOMAttr), - (void **)aReturn); - } - } - - return rv; -} - -nsresult -nsDOMAttributeMap::SetNamedItemNS(nsIDOMNode* aArg, nsIDOMNode** aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - - nsresult rv = NS_OK; - *aReturn = nsnull; - - if (mContent) { - nsCOMPtr attribute(do_QueryInterface(aArg)); - - if (!attribute) { - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - nsAutoString name, nsURI, value; - nsCOMPtr nameAtom; - PRInt32 nameSpaceID; - - attribute->GetName(name); - attribute->GetPrefix(name); - attribute->GetNamespaceURI(nsURI); - - nsCOMPtr ni; - mContent->GetNodeInfo(*getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - nsCOMPtr nimgr; - ni->GetNodeInfoManager(*getter_AddRefs(nimgr)); - NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); - - nimgr->GetNodeInfo(name, nsURI, *getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - ni->GetNameAtom(*getter_AddRefs(nameAtom)); - ni->GetNamespaceID(nameSpaceID); - - nsresult attrResult = mContent->GetAttribute(nameSpaceID, nameAtom, value); - - if (NS_CONTENT_ATTR_NOT_THERE != attrResult && NS_SUCCEEDED(attrResult)) { - nsDOMAttribute* domAttribute; - // We pass a null content here since the attr node we return isn't - // tied to this content anymore. - domAttribute = new nsDOMAttribute(nsnull, ni, value); - if (!domAttribute) { - return NS_ERROR_OUT_OF_MEMORY; - } - - rv = domAttribute->QueryInterface(NS_GET_IID(nsIDOMAttr), - (void **)aReturn); - } - - attribute->GetValue(value); - - rv = mContent->SetAttribute(ni, value, PR_TRUE); - } - - return rv; -} - -nsresult -nsDOMAttributeMap::RemoveNamedItemNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - nsIDOMNode** aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - *aReturn = nsnull; - - nsresult rv = NS_OK; - - if (mContent) { - nsCOMPtr nameAtom(dont_AddRef(NS_NewAtom(aLocalName))); - PRInt32 nameSpaceID = kNameSpaceID_None; - nsCOMPtr attribute; - nsCOMPtr prefix; - - nsCOMPtr ni; - mContent->GetNodeInfo(*getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - nsCOMPtr nimgr; - ni->GetNodeInfoManager(*getter_AddRefs(nimgr)); - NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); - - if (aNamespaceURI.Length()) { - nsCOMPtr nsmgr; - nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); - NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); - - nsmgr->GetNameSpaceID(aNamespaceURI, nameSpaceID); - - if (nameSpaceID == kNameSpaceID_Unknown) - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - - nsresult attrResult; - nsAutoString value; - attrResult = mContent->GetAttribute(nameSpaceID, nameAtom, - *getter_AddRefs(prefix), value); - - if (NS_CONTENT_ATTR_NOT_THERE != attrResult && NS_SUCCEEDED(attrResult)) { - nimgr->GetNodeInfo(nameAtom, prefix, nameSpaceID, *getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - nsDOMAttribute* domAttribute; - domAttribute = new nsDOMAttribute(nsnull, ni, value); - if (!domAttribute) { - return NS_ERROR_OUT_OF_MEMORY; - } - - rv = domAttribute->QueryInterface(NS_GET_IID(nsIDOMAttr), - (void **)aReturn); - } else { - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - - rv = mContent->UnsetAttribute(nameSpaceID, nameAtom, PR_TRUE); - } - - return rv; -} - - -#ifdef DEBUG -nsresult -nsDOMAttributeMap::SizeOfNamedNodeMap(nsIDOMNamedNodeMap* aMap, - nsISizeOfHandler* aSizer, - PRUint32* aResult) -{ - if (!aResult) return NS_ERROR_NULL_POINTER; - nsDOMAttributeMap* map = (nsDOMAttributeMap*) aMap; - PRUint32 sum = sizeof(nsDOMAttributeMap); - *aResult = sum; - return NS_OK; -} -#endif diff --git a/layout/base/src/nsDOMAttributeMap.h b/layout/base/src/nsDOMAttributeMap.h deleted file mode 100644 index 32aeb4001861..000000000000 --- a/layout/base/src/nsDOMAttributeMap.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsDOMAttributeMap_h___ -#define nsDOMAttributeMap_h___ - -#include "nsIDOMNamedNodeMap.h" -#include "nsIScriptObjectOwner.h" -#include "nsVoidArray.h" -#include "nsString.h" -#include "plhash.h" - -class nsIContent; - -// Helper class that implements the nsIDOMNamedNodeMap interface. -class nsDOMAttributeMap : public nsIDOMNamedNodeMap, - public nsIScriptObjectOwner -{ -public: - nsDOMAttributeMap(nsIContent* aContent); - virtual ~nsDOMAttributeMap(); - - NS_DECL_ISUPPORTS - - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - - // nsIDOMNamedNodeMap interface - NS_IMETHOD GetLength(PRUint32* aSize); - NS_IMETHOD GetNamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn); - NS_IMETHOD SetNamedItem(nsIDOMNode* aNode, nsIDOMNode** aReturn); - NS_IMETHOD RemoveNamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn); - NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn); - NS_IMETHOD GetNamedItemNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, nsIDOMNode** aReturn); - NS_IMETHOD SetNamedItemNS(nsIDOMNode* aArg, nsIDOMNode** aReturn); - NS_IMETHOD RemoveNamedItemNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - nsIDOMNode** aReturn); - - void DropReference(); - -#ifdef DEBUG - static nsresult SizeOfNamedNodeMap(nsIDOMNamedNodeMap* aMap, - nsISizeOfHandler* aSizer, - PRUint32* aResult); -#endif - -private: - nsIContent* mContent; - void* mScriptObject; -}; - - -#endif /* nsDOMAttributeMap_h___ */ diff --git a/layout/base/src/nsDOMDocumentType.cpp b/layout/base/src/nsDOMDocumentType.cpp deleted file mode 100644 index d1ba310150cc..000000000000 --- a/layout/base/src/nsDOMDocumentType.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsDOMDocumentType.h" -#include "nsDOMAttributeMap.h" -#include "nsIDOMNamedNodeMap.h" -#include "nsIDOMScriptObjectFactory.h" -#include "nsLayoutAtoms.h" -#include "nsCOMPtr.h" - -nsresult -NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, - const nsAReadableString& aName, - nsIDOMNamedNodeMap *aEntities, - nsIDOMNamedNodeMap *aNotations, - const nsAReadableString& aPublicId, - const nsAReadableString& aSystemId, - const nsAReadableString& aInternalSubset) -{ - NS_ENSURE_ARG_POINTER(aDocType); - - *aDocType = new nsDOMDocumentType(aName, aEntities, aNotations, - aPublicId, aSystemId, aInternalSubset); - if (!*aDocType) { - return NS_ERROR_OUT_OF_MEMORY; - } - - NS_ADDREF(*aDocType); - - return NS_OK; -} - -nsDOMDocumentType::nsDOMDocumentType(const nsAReadableString& aName, - nsIDOMNamedNodeMap *aEntities, - nsIDOMNamedNodeMap *aNotations, - const nsAReadableString& aPublicId, - const nsAReadableString& aSystemId, - const nsAReadableString& aInternalSubset) : - mName(aName), - mPublicId(aPublicId), - mSystemId(aSystemId), - mInternalSubset(aInternalSubset) -{ - NS_INIT_REFCNT(); - - mEntities = aEntities; - mNotations = aNotations; - - NS_IF_ADDREF(mEntities); - NS_IF_ADDREF(mNotations); -} - -nsDOMDocumentType::~nsDOMDocumentType() -{ - NS_IF_RELEASE(mEntities); - NS_IF_RELEASE(mNotations); -} - -NS_IMPL_ADDREF(nsDOMDocumentType) -NS_IMPL_RELEASE(nsDOMDocumentType) - -NS_INTERFACE_MAP_BEGIN(nsDOMDocumentType) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMDocumentType) - NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentType) - NS_INTERFACE_MAP_ENTRY(nsIDOMNode) - NS_INTERFACE_MAP_ENTRY(nsIContent) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) -NS_INTERFACE_MAP_END_THREADSAFE - -NS_IMETHODIMP -nsDOMDocumentType::GetName(nsAWritableString& aName) -{ - aName=mName; - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMDocumentType::GetEntities(nsIDOMNamedNodeMap** aEntities) -{ - NS_ENSURE_ARG_POINTER(aEntities); - - *aEntities = mEntities; - - NS_IF_ADDREF(*aEntities); - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMDocumentType::GetNotations(nsIDOMNamedNodeMap** aNotations) -{ - NS_ENSURE_ARG_POINTER(aNotations); - - *aNotations = mNotations; - - NS_IF_ADDREF(*aNotations); - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMDocumentType::GetPublicId(nsAWritableString& aPublicId) -{ - aPublicId = mPublicId; - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMDocumentType::GetSystemId(nsAWritableString& aSystemId) -{ - aSystemId = mSystemId; - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMDocumentType::GetInternalSubset(nsAWritableString& aInternalSubset) -{ - aInternalSubset = mInternalSubset; - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMDocumentType::GetTag(nsIAtom*& aResult) const -{ - aResult = NS_NewAtom(mName.GetUnicode()); - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMDocumentType::GetNodeInfo(nsINodeInfo*& aResult) const -{ - aResult = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsDOMDocumentType::GetNodeName(nsAWritableString& aNodeName) -{ - aNodeName=mName; - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMDocumentType::GetNodeType(PRUint16* aNodeType) -{ - *aNodeType = nsIDOMNode::DOCUMENT_TYPE_NODE; - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMDocumentType::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) -{ - nsDOMDocumentType* it = new nsDOMDocumentType(mName, - mEntities, - mNotations, - mPublicId, - mSystemId, - mInternalSubset); - if (nsnull == it) { - return NS_ERROR_OUT_OF_MEMORY; - } - return it->QueryInterface(NS_GET_IID(nsIDOMNode), (void**) aReturn); -} - -NS_IMETHODIMP -nsDOMDocumentType::List(FILE* out, PRInt32 aIndent) const -{ - NS_PRECONDITION(nsnull != mInner.mDocument, "bad content"); - - PRInt32 index; - for (index = aIndent; --index >= 0; ) fputs(" ", out); - - fprintf(out, "Document type refcount: %d\n", mRefCnt); - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMDocumentType::DumpContent(FILE* out = stdout, PRInt32 aIndent = 0,PRBool aDumpAll=PR_TRUE) const { - return NS_OK; -} - -NS_IMETHODIMP -nsDOMDocumentType::HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus) -{ - // We should never be getting events - NS_ASSERTION(0, "event handler called for document type"); - return mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent, - aFlags, aEventStatus); -} - -NS_IMETHODIMP -nsDOMDocumentType::GetContentID(PRUint32* aID) -{ - NS_ENSURE_ARG_POINTER(aID); - - *aID = 0; - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDOMDocumentType::SetContentID(PRUint32 aID) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDOMDocumentType::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const -{ - NS_ENSURE_ARG_POINTER(aResult); - -#ifdef DEBUG - PRUint32 sum; - mInner.SizeOf(aSizer, &sum, sizeof(*this)); - PRUint32 ssize; - mName.SizeOf(aSizer, &ssize); - sum = sum - sizeof(mName) + ssize; - if (mEntities) { - PRBool recorded; - aSizer->RecordObject((void*) mEntities, &recorded); - if (!recorded) { - PRUint32 size; - nsDOMAttributeMap::SizeOfNamedNodeMap(mEntities, aSizer, &size); - aSizer->AddSize(nsLayoutAtoms::xml_document_entities, size); - } - } - if (mNotations) { - PRBool recorded; - aSizer->RecordObject((void*) mNotations, &recorded); - if (!recorded) { - PRUint32 size; - nsDOMAttributeMap::SizeOfNamedNodeMap(mNotations, aSizer, &size); - aSizer->AddSize(nsLayoutAtoms::xml_document_notations, size); - } - } -#endif - return NS_OK; -} diff --git a/layout/base/src/nsDOMDocumentType.h b/layout/base/src/nsDOMDocumentType.h deleted file mode 100644 index def8ba0f6365..000000000000 --- a/layout/base/src/nsDOMDocumentType.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsDOMDocumentType_h___ -#define nsDOMDocumentType_h___ - -#include "nsIDOMDocumentType.h" -#include "nsIScriptObjectOwner.h" -#include "nsIContent.h" -#include "nsGenericDOMDataNode.h" -#include "nsString.h" -#include "nsISizeOfHandler.h" - -class nsIDOMNamedNodeMap; - -class nsDOMDocumentType : public nsIDOMDocumentType, - public nsIScriptObjectOwner, - public nsIContent -{ -public: - nsDOMDocumentType(const nsAReadableString& aName, - nsIDOMNamedNodeMap *aEntities, - nsIDOMNamedNodeMap *aNotations, - const nsAReadableString& aPublicId, - const nsAReadableString& aSystemId, - const nsAReadableString& aInternalSubset); - - virtual ~nsDOMDocumentType(); - - // nsISupports - NS_DECL_ISUPPORTS - - // nsIDOMNode - NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner) - - // nsIDOMDocumentType - NS_DECL_IDOMDOCUMENTTYPE - - // nsIScriptObjectOwner interface - NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC_DOM_DATA(mInner); - - // nsIContent - NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(mInner) - - NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const; - -protected: - // XXX DocumentType is currently implemented by using the generic - // CharacterData inner object, even though DocumentType is not - // character data. This is done simply for convenience and should - // be changed if this restricts what should be done for character data. - nsGenericDOMDataNode mInner; - nsString mName; - nsIDOMNamedNodeMap* mEntities; - nsIDOMNamedNodeMap* mNotations; - nsString mPublicId; - nsString mSystemId; - nsString mInternalSubset; -}; - -extern nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, - const nsAReadableString& aName, - nsIDOMNamedNodeMap *aEntities, - nsIDOMNamedNodeMap *aNotations, - const nsAReadableString& aPublicId, - const nsAReadableString& aSystemId, - const nsAReadableString& aInternalSubset); - -#endif // nsDOMDocument_h___ diff --git a/layout/base/src/nsDocument.cpp b/layout/base/src/nsDocument.cpp deleted file mode 100644 index 49e697362bcd..000000000000 --- a/layout/base/src/nsDocument.cpp +++ /dev/null @@ -1,3268 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * L. David Baron - * Pierre Phaneuf - */ -#include "plstr.h" - -#include "nsCOMPtr.h" -#include "nsIInterfaceRequestor.h" -#include "nsDocument.h" -#include "nsIArena.h" -#include "nsIURL.h" -#include "nsILoadGroup.h" -#include "nsIChannel.h" -#include "nsString.h" -#include "nsIContent.h" -#include "nsIDocumentObserver.h" -#include "nsIStyleSet.h" -#include "nsIStyleSheet.h" -#include "nsIPresShell.h" -#include "nsIPresContext.h" -#include "nsIDocumentObserver.h" -#include "nsIEventListenerManager.h" -#include "nsIScriptGlobalObject.h" -#include "nsIScriptEventListener.h" -#include "nsIDOMEvent.h" -#include "nsIPrivateDOMEvent.h" -#include "nsIEventStateManager.h" -#include "nsContentList.h" -#include "nsIObserver.h" - -#include "nsIDOMEventListener.h" -#include "nsIDOMFormListener.h" -#include "nsIDOMPaintListener.h" -#include "nsIDOMMouseListener.h" -#include "nsIDOMMouseMotionListener.h" -#include "nsIDOMKeyListener.h" -#include "nsIDOMFocusListener.h" -#include "nsIDOMLoadListener.h" - -#include "nsIDOMStyleSheet.h" -#include "nsIDOMStyleSheetList.h" -#include "nsDOMAttribute.h" -#include "nsDOMCID.h" -#include "nsIDOMScriptObjectFactory.h" -#include "nsIDOMDOMImplementation.h" -#include "nsIDOMDocumentView.h" -#include "nsIDOMAbstractView.h" -#include "nsIDOMDocumentXBL.h" -#include "nsIDOMNavigator.h" -#include "nsGenericElement.h" - -#include "nsICSSStyleSheet.h" - -#include "nsITextContent.h" -#include "nsIDocumentEncoder.h" -#include "nsIHTMLContentSink.h" -#include "nsIParser.h" -#include "nsParserCIID.h" -#include "nsIFileStreams.h" - -#include "nsRange.h" -#include "nsIDOMText.h" -#include "nsIDOMComment.h" -#include "nsDOMDocumentType.h" - -#include "nsINameSpaceManager.h" -#include "nsIServiceManager.h" - -#include "nsLayoutAtoms.h" -#include "nsLayoutCID.h" -#include "nsIDOMRange.h" -#include "nsIEnumerator.h" -#include "nsDOMError.h" -#include "nsIScrollableView.h" -#include "nsIFrame.h" -#include "nsLayoutUtils.h" -#include "nsNodeInfoManager.h" -#include "nsIXBLService.h" - -#include "nsNetUtil.h" // for NS_MakeAbsoluteURI - -#include "nsIScriptSecurityManager.h" -#include "nsIAggregatePrincipal.h" -#include "nsIPrivateDOMImplementation.h" - -#include "nsIInterfaceRequestor.h" -#include "nsIDOMWindowInternal.h" - -#include "nsIDOMElement.h" - -#include "nsIBoxObject.h" -#include "nsPIBoxObject.h" -#include "nsXULAtoms.h" - -static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); - -static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); - -#include "nsILineBreakerFactory.h" -#include "nsIWordBreakerFactory.h" -#include "nsLWBrkCIID.h" - -#include "nsIHTMLDocument.h" - -class nsDOMStyleSheetList : public nsIDOMStyleSheetList, - public nsIScriptObjectOwner, - public nsIDocumentObserver -{ -public: - nsDOMStyleSheetList(nsIDocument *aDocument); - virtual ~nsDOMStyleSheetList(); - - NS_DECL_ISUPPORTS - NS_DECL_IDOMSTYLESHEETLIST - - NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; } - NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; } - NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; } - NS_IMETHOD EndLoad(nsIDocument *aDocument) { return NS_OK; } - NS_IMETHOD BeginReflow(nsIDocument *aDocument, - nsIPresShell* aShell) { return NS_OK; } - NS_IMETHOD EndReflow(nsIDocument *aDocument, - nsIPresShell* aShell) { return NS_OK; } - NS_IMETHOD ContentChanged(nsIDocument *aDocument, - nsIContent* aContent, - nsISupports* aSubContent) { return NS_OK; } - NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument, - nsIContent* aContent1, - nsIContent* aContent2) { return NS_OK; } - NS_IMETHOD AttributeChanged(nsIDocument *aDocument, - nsIContent* aContent, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aHint) { return NS_OK; } - NS_IMETHOD ContentAppended(nsIDocument *aDocument, - nsIContent* aContainer, - PRInt32 aNewIndexInContainer) - { return NS_OK; } - NS_IMETHOD ContentInserted(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) { return NS_OK; } - NS_IMETHOD ContentReplaced(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aOldChild, - nsIContent* aNewChild, - PRInt32 aIndexInContainer) { return NS_OK; } - NS_IMETHOD ContentRemoved(nsIDocument *aDocument, - nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) { return NS_OK; } - NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet); - NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet); - NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - PRBool aDisabled) { return NS_OK; } - NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule, - PRInt32 aHint) { return NS_OK; } - NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule) { return NS_OK; } - NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule) { return NS_OK; } - NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument); - - // nsIScriptObjectOwner interface - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void* aScriptObject); - -protected: - PRInt32 mLength; - nsIDocument* mDocument; - void* mScriptObject; -}; - -nsDOMStyleSheetList::nsDOMStyleSheetList(nsIDocument *aDocument) -{ - NS_INIT_REFCNT(); - mLength = -1; - // Not reference counted to avoid circular references. - // The document will tell us when its going away. - mDocument = aDocument; - mDocument->AddObserver(this); - mScriptObject = nsnull; -} - -nsDOMStyleSheetList::~nsDOMStyleSheetList() -{ - if (nsnull != mDocument) { - mDocument->RemoveObserver(this); - } - mDocument = nsnull; -} - -NS_IMPL_ADDREF(nsDOMStyleSheetList) -NS_IMPL_RELEASE(nsDOMStyleSheetList) - -NS_INTERFACE_MAP_BEGIN(nsDOMStyleSheetList) - NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheetList) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) - NS_INTERFACE_MAP_ENTRY(nsIDocumentObserver) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMStyleSheetList) -NS_INTERFACE_MAP_END - -NS_IMETHODIMP -nsDOMStyleSheetList::GetLength(PRUint32* aLength) -{ - if (nsnull != mDocument) { - // XXX Find the number and then cache it. We'll use the - // observer notification to figure out if new ones have - // been added or removed. - if (-1 == mLength) { - PRUint32 count = 0; - PRInt32 i, imax = mDocument->GetNumberOfStyleSheets(); - - for (i = 0; i < imax; i++) { - nsCOMPtr sheet(dont_AddRef(mDocument->GetStyleSheetAt(i))); - if (!sheet) - continue; - nsCOMPtr domss(do_QueryInterface(sheet)); - - if (domss) { - count++; - } - } - mLength = count; - } - *aLength = mLength; - } - else { - *aLength = 0; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMStyleSheetList::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn) -{ - *aReturn = nsnull; - if (nsnull != mDocument) { - PRUint32 count = 0; - PRInt32 i, imax = mDocument->GetNumberOfStyleSheets(); - - // XXX Not particularly efficient, but does anyone care? - for (i = 0; (i < imax) && (nsnull == *aReturn); i++) { - nsCOMPtr sheet(dont_AddRef(mDocument->GetStyleSheetAt(i))); - if (!sheet) - continue; - nsCOMPtr domss(do_QueryInterface(sheet)); - - if (domss) { - if (count++ == aIndex) { - *aReturn = domss; - NS_IF_ADDREF(*aReturn); - } - } - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMStyleSheetList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - - if (nsnull == mScriptObject) { - nsISupports *supports = (nsISupports *)(nsIDOMStyleSheetList *)this; - nsISupports *parent = (nsISupports *)mDocument; - - // XXX Should be done through factory - res = NS_NewScriptStyleSheetList(aContext, - supports, - parent, - (void**)&mScriptObject); - } - *aScriptObject = mScriptObject; - - return res; -} - -NS_IMETHODIMP -nsDOMStyleSheetList::SetScriptObject(void* aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - -NS_IMETHODIMP -nsDOMStyleSheetList::StyleSheetAdded(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet) -{ - if (-1 != mLength) { - nsCOMPtr domss(do_QueryInterface(aStyleSheet)); - if (domss) { - mLength++; - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDOMStyleSheetList::StyleSheetRemoved(nsIDocument *aDocument, - nsIStyleSheet* aStyleSheet) -{ - if (-1 != mLength) { - nsCOMPtr domss(do_QueryInterface(aStyleSheet)); - if (domss) { - mLength--; - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDOMStyleSheetList::DocumentWillBeDestroyed(nsIDocument *aDocument) -{ - if (nsnull != mDocument) { - aDocument->RemoveObserver(this); - mDocument = nsnull; - } - - return NS_OK; -} - -// ================================================================== -// = -// ================================================================== - -class nsDOMImplementation : public nsIDOMDOMImplementation, - public nsIScriptObjectOwner, - public nsIPrivateDOMImplementation -{ -public: - nsDOMImplementation(nsIURI* aBaseURI = nsnull); - virtual ~nsDOMImplementation(); - - NS_DECL_ISUPPORTS - - // nsIDOMDOMImplementation - NS_IMETHOD HasFeature(const nsAReadableString& aFeature, - const nsAReadableString& aVersion, - PRBool* aReturn); - NS_IMETHOD CreateDocumentType(const nsAReadableString& aQualifiedName, - const nsAReadableString& aPublicId, - const nsAReadableString& aSystemId, - nsIDOMDocumentType** aReturn); - - NS_IMETHOD CreateDocument(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aQualifiedName, - nsIDOMDocumentType* aDoctype, - nsIDOMDocument** aReturn); - - // nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - - //nsIPrivateDOMImplementation - NS_IMETHOD Init(nsIURI* aBaseURI); - -protected: - void *mScriptObject; - nsCOMPtr mBaseURI; -}; - - -NS_LAYOUT nsresult -NS_NewDOMImplementation(nsIDOMDOMImplementation** aInstancePtrResult) -{ - nsDOMImplementation* domImpl = new nsDOMImplementation(); - if (domImpl == nsnull) - return NS_ERROR_OUT_OF_MEMORY; - return domImpl->QueryInterface(NS_GET_IID(nsIDOMDOMImplementation), (void**) aInstancePtrResult); -} - -nsDOMImplementation::nsDOMImplementation(nsIURI* aBaseURI) -{ - NS_INIT_REFCNT(); - mScriptObject = nsnull; - mBaseURI = aBaseURI; -} - -nsDOMImplementation::~nsDOMImplementation() -{ -} - -NS_IMPL_ISUPPORTS4(nsDOMImplementation, nsIDOMDOMImplementation, nsIPrivateDOMImplementation, nsIScriptObjectOwner, nsIDOMDOMImplementation) - - -NS_IMETHODIMP -nsDOMImplementation::HasFeature(const nsAReadableString& aFeature, - const nsAReadableString& aVersion, - PRBool* aReturn) -{ - return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn); -} - -NS_IMETHODIMP -nsDOMImplementation::CreateDocumentType(const nsAReadableString& aQualifiedName, - const nsAReadableString& aPublicId, - const nsAReadableString& aSystemId, - nsIDOMDocumentType** aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - - return NS_NewDOMDocumentType(aReturn, aQualifiedName, nsnull, nsnull, - aPublicId, aSystemId, nsString()); -} - -NS_IMETHODIMP -nsDOMImplementation::CreateDocument(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aQualifiedName, - nsIDOMDocumentType* aDoctype, - nsIDOMDocument** aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - - *aReturn = nsnull; - - return NS_NewDOMDocument(aReturn, aNamespaceURI, aQualifiedName, aDoctype, - mBaseURI); -} - -NS_IMETHODIMP -nsDOMImplementation::GetScriptObject(nsIScriptContext *aContext, - void** aScriptObject) -{ - nsresult result = NS_OK; - - if (!mScriptObject) { - nsCOMPtr factory(do_GetService(kDOMScriptObjectFactoryCID, &result)); - - if (NS_OK == result) { - nsCOMPtr global(dont_AddRef(aContext->GetGlobalObject())); - - result = factory->NewScriptDOMImplementation(aContext, (nsISupports*)(nsIDOMDOMImplementation*)this, - global, &mScriptObject); - } - } - - *aScriptObject = mScriptObject; - return result; -} - -NS_IMETHODIMP -nsDOMImplementation::SetScriptObject(void *aScriptObject) -{ - mScriptObject = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsDOMImplementation::Init(nsIURI* aBaseURI) -{ - mBaseURI = aBaseURI; - return NS_OK; -} - -// ================================================================== -// = -// ================================================================== - -MOZ_DECL_CTOR_COUNTER(nsDocumentChildNodes) - -nsDocumentChildNodes::nsDocumentChildNodes(nsIDocument* aDocument) -{ - MOZ_COUNT_CTOR(nsDocumentChildNodes); - - // We don't reference count our document reference (to avoid circular - // references). We'll be told when the document goes away. - mDocument = aDocument; -} - -nsDocumentChildNodes::~nsDocumentChildNodes() -{ - MOZ_COUNT_DTOR(nsDocumentChildNodes); -} - -NS_IMETHODIMP -nsDocumentChildNodes::GetLength(PRUint32* aLength) -{ - if (nsnull != mDocument) { - PRInt32 count; - mDocument->GetChildCount(count); - *aLength = (PRUint32)count; - } - else { - *aLength = 0; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDocumentChildNodes::Item(PRUint32 aIndex, nsIDOMNode** aReturn) -{ - nsresult result = NS_OK; - nsCOMPtr content; - - *aReturn = nsnull; - if (nsnull != mDocument) { - result = mDocument->ChildAt(aIndex, *getter_AddRefs(content)); - if ((NS_OK == result) && (nsnull != content)) { - result = content->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aReturn); - } - } - - return result; -} - -void -nsDocumentChildNodes::DropReference() -{ - mDocument = nsnull; -} - -// ================================================================== -// = -// ================================================================== - -nsDocument::nsDocument() -{ - NS_INIT_REFCNT(); - - mArena = nsnull; - mDocumentTitle = nsnull; - mDocumentURL = nsnull; - mCharacterSet.AssignWithConversion("ISO-8859-1"); - mParentDocument = nsnull; - mRootContent = nsnull; - mScriptObject = nsnull; - mListenerManager = nsnull; - mInDestructor = PR_FALSE; - mDOMStyleSheets = nsnull; - mNameSpaceManager = nsnull; - mHeaderData = nsnull; - mChildNodes = nsnull; - mModCount = 0; - mPrincipal = nsnull; - mNextContentID = NS_CONTENT_ID_COUNTER_BASE; - mDTD = 0; - mBoxObjectTable = nsnull; - - // Force initialization. - mBindingManager = do_CreateInstance("@mozilla.org/xbl/binding-manager;1"); - nsCOMPtr observer(do_QueryInterface(mBindingManager)); - if (observer) // We must always be the first observer of the document. - mObservers.InsertElementAt(observer, 0); - - Init();/* XXX */ -} - -nsDocument::~nsDocument() -{ - // XXX Inform any remaining observers that we are going away. - // Note that this currently contradicts the rule that all - // observers must hold on to live references to the document. - // This notification will occur only after the reference has - // been dropped. - mInDestructor = PR_TRUE; - PRInt32 index; - for (index = 0; index < mObservers.Count(); index++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index); - observer->DocumentWillBeDestroyed(this); - if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) { - index--; - } - } - - if (nsnull != mDocumentTitle) { - delete mDocumentTitle; - mDocumentTitle = nsnull; - } - NS_IF_RELEASE(mDocumentURL); - NS_IF_RELEASE(mPrincipal); - mDocumentLoadGroup = null_nsCOMPtr(); - - mParentDocument = nsnull; - - // Delete references to sub-documents - index = mSubDocuments.Count(); - while (--index >= 0) { - nsIDocument* subdoc = (nsIDocument*) mSubDocuments.ElementAt(index); - NS_RELEASE(subdoc); - } - - - mRootContent = nsnull; - mChildren->Clear(); - - // Delete references to style sheets - index = mStyleSheets.Count(); - while (--index >= 0) { - nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(index); - sheet->SetOwningDocument(nsnull); - NS_RELEASE(sheet); - } - - if (nsnull != mChildNodes) { - mChildNodes->DropReference(); - NS_RELEASE(mChildNodes); - } - - NS_IF_RELEASE(mArena); - NS_IF_RELEASE(mListenerManager); - NS_IF_RELEASE(mDOMStyleSheets); - NS_IF_RELEASE(mNameSpaceManager); - if (nsnull != mHeaderData) { - delete mHeaderData; - mHeaderData = nsnull; - } - - NS_IF_RELEASE(mDTD); - - delete mBoxObjectTable; -} - -NS_INTERFACE_MAP_BEGIN(nsDocument) - NS_INTERFACE_MAP_ENTRY(nsIDocument) - NS_INTERFACE_MAP_ENTRY(nsIDOMDocument) - NS_INTERFACE_MAP_ENTRY(nsIDOMNSDocument) - NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentEvent) - NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentStyle) - NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentView) - NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentXBL) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) - NS_INTERFACE_MAP_ENTRY(nsIJSScriptObject) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal) - NS_INTERFACE_MAP_ENTRY(nsIDOMEventReceiver) - NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget) - NS_INTERFACE_MAP_ENTRY(nsIDOMNode) - NS_INTERFACE_MAP_ENTRY(nsIDiskDocument) - NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocument) -NS_INTERFACE_MAP_END - -NS_IMPL_ADDREF(nsDocument) -NS_IMPL_RELEASE(nsDocument) - -nsresult nsDocument::Init() -{ - if (mNameSpaceManager) { - return NS_ERROR_ALREADY_INITIALIZED; - } - - nsresult rv; - - rv = NS_NewISupportsArray(getter_AddRefs(mChildren)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = NS_NewHeapArena(&mArena, nsnull); - NS_ENSURE_SUCCESS(rv, rv); - - rv = NS_NewNameSpaceManager(&mNameSpaceManager); - NS_ENSURE_SUCCESS(rv, rv); - - mNodeInfoManager = new nsNodeInfoManager(); - NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_OUT_OF_MEMORY); - - mNodeInfoManager->Init(mNameSpaceManager); - - return rv; -} - -nsIArena* nsDocument::GetArena() -{ - if (nsnull != mArena) { - NS_ADDREF(mArena); - } - return mArena; -} - -nsresult -nsDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) -{ - nsresult rv = NS_OK; - - if (nsnull != mDocumentTitle) { - delete mDocumentTitle; - mDocumentTitle = nsnull; - } - NS_IF_RELEASE(mDocumentURL); - NS_IF_RELEASE(mPrincipal); - mDocumentLoadGroup = null_nsCOMPtr(); - - // Delete references to sub-documents - PRInt32 index = mSubDocuments.Count(); - while (--index >= 0) { - nsIDocument* subdoc = (nsIDocument*) mSubDocuments.ElementAt(index); - NS_RELEASE(subdoc); - } - - mRootContent = nsnull; - PRUint32 count, i; - mChildren->Count(&count); - for (i = 0; i < count; i++) { - nsCOMPtr content(dont_AddRef(NS_STATIC_CAST(nsIContent*,mChildren->ElementAt(i)))); - content->SetDocument(nsnull, PR_TRUE, PR_TRUE); - ContentRemoved(nsnull, content, index); - } - mChildren->Clear(); - - // Delete references to style sheets - index = mStyleSheets.Count(); - while (--index >= 0) { - nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(index); - sheet->SetOwningDocument(nsnull); - - PRInt32 pscount = mPresShells.Count(); - PRInt32 psindex; - for (psindex = 0; psindex < pscount; psindex++) { - nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(psindex); - nsCOMPtr set; - if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) { - if (set) { - set->RemoveDocStyleSheet(sheet); - } - } - } - - // XXX Tell observers? - - NS_RELEASE(sheet); - } - mStyleSheets.Clear(); - - NS_IF_RELEASE(mListenerManager); - NS_IF_RELEASE(mDOMStyleSheets); - - NS_IF_RELEASE(mNameSpaceManager); - - if (aChannel) { - - nsCOMPtr uri; - (void) aChannel->GetOriginalURI(getter_AddRefs(uri)); - - PRBool isChrome = PR_FALSE; - PRBool isRes = PR_FALSE; - (void)uri->SchemeIs(nsIURI::CHROME, &isChrome); - (void)uri->SchemeIs(nsIURI::RESOURCE, &isRes); - - if (isChrome || isRes) - (void)aChannel->GetOriginalURI(&mDocumentURL); - else - (void)aChannel->GetURI(&mDocumentURL); - - nsCOMPtr owner; - aChannel->GetOwner(getter_AddRefs(owner)); - if (owner) - owner->QueryInterface(NS_GET_IID(nsIPrincipal), (void**)&mPrincipal); - } - - if (aLoadGroup) { - mDocumentLoadGroup = getter_AddRefs(NS_GetWeakReference(aLoadGroup)); - // there was an assertion here that aLoadGroup was not null. This is no longer valid - // nsWebShell::SetDocument does not create a load group, and it works just fine. - } - - if (NS_OK == rv) { - rv = NS_NewNameSpaceManager(&mNameSpaceManager); - } - - return rv; -} - -nsresult -nsDocument::SetDocumentURL(nsIURI* aURI) -{ - NS_IF_RELEASE(mDocumentURL); - mDocumentURL = aURI; - NS_IF_ADDREF(mDocumentURL); - - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::StartDocumentLoad(const char* aCommand, - nsIChannel* aChannel, - nsILoadGroup* aLoadGroup, - nsISupports* aContainer, - nsIStreamListener **aDocListener, - PRBool aReset) -{ - nsresult rv = NS_OK; - if (aReset) - rv = Reset(aChannel, aLoadGroup); - return rv; -} - -NS_IMETHODIMP -nsDocument::StopDocumentLoad() -{ - return NS_OK; -} - -const nsString* nsDocument::GetDocumentTitle() const -{ - return mDocumentTitle; -} - -nsIURI* nsDocument::GetDocumentURL() const -{ - nsIURI* url = mDocumentURL; - NS_IF_ADDREF(url); - return url; -} - -NS_IMETHODIMP -nsDocument::GetPrincipal(nsIPrincipal **aPrincipal) -{ - if (!mPrincipal) { - nsresult rv; - NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, - NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return rv; - if (NS_FAILED(rv = securityManager->GetCodebasePrincipal(mDocumentURL, - &mPrincipal))) - return rv; - } - - if(aPrincipal) - { - *aPrincipal = mPrincipal; - NS_ADDREF(*aPrincipal); - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::AddPrincipal(nsIPrincipal *aNewPrincipal) -{ - nsresult rv; - if (!mPrincipal) - GetPrincipal(nsnull); - - nsCOMPtr agg(do_QueryInterface(mPrincipal, &rv)); - if (NS_SUCCEEDED(rv)) { - rv = agg->Intersect(aNewPrincipal); - if (NS_FAILED(rv)) - return rv; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetContentType(nsAWritableString& aContentType) const -{ - // Must be implemented by derived class. - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDocument::GetDocumentLoadGroup(nsILoadGroup **aGroup) const -{ - nsCOMPtr group(do_QueryReferent(mDocumentLoadGroup)); - - *aGroup = group; - NS_IF_ADDREF(*aGroup); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetBaseURL(nsIURI*& aURL) const -{ - aURL = mDocumentURL; - NS_IF_ADDREF(aURL); - return NS_OK; -} - -NS_IMETHODIMP nsDocument::GetDocumentCharacterSet(nsAWritableString& oCharSetID) -{ - oCharSetID = mCharacterSet; - return NS_OK; -} - -NS_IMETHODIMP nsDocument::SetDocumentCharacterSet(const nsAReadableString& aCharSetID) -{ - if (!mCharacterSet.Equals(aCharSetID)) { - mCharacterSet = aCharSetID; - PRInt32 n = mCharSetObservers.Count(); - for (PRInt32 i = 0; i < n; i++) { - nsIObserver* observer = (nsIObserver*) mCharSetObservers.ElementAt(i); - observer->Observe((nsIDocument*) this, NS_LITERAL_STRING("charset").get(), - nsPromiseFlatString(aCharSetID).get()); - } - } - return NS_OK; -} - -NS_IMETHODIMP nsDocument::AddCharSetObserver(nsIObserver* aObserver) -{ - NS_ENSURE_ARG_POINTER(aObserver); - NS_ENSURE_TRUE(mCharSetObservers.AppendElement(aObserver), NS_ERROR_FAILURE); - return NS_OK; -} - -NS_IMETHODIMP nsDocument::RemoveCharSetObserver(nsIObserver* aObserver) -{ - NS_ENSURE_ARG_POINTER(aObserver); - NS_ENSURE_TRUE(mCharSetObservers.RemoveElement(aObserver), NS_ERROR_FAILURE); - return NS_OK; -} - -NS_IMETHODIMP nsDocument::GetLineBreaker(nsILineBreaker** aResult) -{ - if (!mLineBreaker) { - // no line breaker, find a default one - nsresult result; - nsCOMPtr lbf(do_GetService(NS_LWBRK_CONTRACTID, &result)); - - if (NS_SUCCEEDED(result)) { - nsAutoString lbarg; - lbf->GetBreaker(lbarg, getter_AddRefs(mLineBreaker)); - } - } - *aResult = mLineBreaker; - NS_IF_ADDREF(*aResult); - return NS_OK; // XXX we should do error handling here -} - -NS_IMETHODIMP nsDocument::SetLineBreaker(nsILineBreaker* aLineBreaker) -{ - mLineBreaker = aLineBreaker; - return NS_OK; -} - -NS_IMETHODIMP nsDocument::GetWordBreaker(nsIWordBreaker** aResult) -{ - if (!mWordBreaker) { - // no word breaker, find a default one - nsresult result; - nsCOMPtr wbf(do_GetService(NS_LWBRK_CONTRACTID, &result)); - - if (NS_SUCCEEDED(result)) { - nsAutoString wbarg; - wbf->GetBreaker(wbarg, getter_AddRefs(mWordBreaker)); - } - } - *aResult = mWordBreaker; - NS_IF_ADDREF(*aResult); - return NS_OK; // XXX we should do error handling here -} - -NS_IMETHODIMP nsDocument::SetWordBreaker(nsIWordBreaker* aWordBreaker) -{ - mWordBreaker = aWordBreaker; - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetHeaderData(nsIAtom* aHeaderField, nsAWritableString& aData) const -{ - aData.Truncate(); - const nsDocHeaderData* data = mHeaderData; - while (nsnull != data) { - if (data->mField == aHeaderField) { - aData = data->mData; - break; - } - data = data->mNext; - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::SetHeaderData(nsIAtom* aHeaderField, const nsAReadableString& aData) -{ - if (nsnull != aHeaderField) { - if (nsnull == mHeaderData) { - if (0 < aData.Length()) { // don't bother storing empty string - mHeaderData = new nsDocHeaderData(aHeaderField, aData); - } - } - else { - nsDocHeaderData* data = mHeaderData; - nsDocHeaderData** lastPtr = &mHeaderData; - do { // look for existing and replace - if (data->mField == aHeaderField) { - if (0 < aData.Length()) { - data->mData.Assign(aData); - } - else { // don't store empty string - (*lastPtr)->mNext = data->mNext; - data->mNext = nsnull; - delete data; - } - return NS_OK; - } - lastPtr = &(data->mNext); - data = data->mNext; - } while (nsnull != data); - // didn't find, append - if (0 < aData.Length()) { - *lastPtr = new nsDocHeaderData(aHeaderField, aData); - } - } - return NS_OK; - } - return NS_ERROR_NULL_POINTER; -} - -#if 0 -// XXX Temp hack: moved to nsMarkupDocument -NS_IMETHODIMP -nsDocument::CreateShell(nsIPresContext* aContext, - nsIViewManager* aViewManager, - nsIStyleSet* aStyleSet, - nsIPresShell** aInstancePtrResult) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - if (nsnull == aInstancePtrResult) { - return NS_ERROR_NULL_POINTER; - } - - nsIPresShell* shell; - nsresult rv = NS_NewPresShell(&shell); - if (NS_OK != rv) { - return rv; - } - - if (NS_OK != shell->Init(this, aContext, aViewManager, aStyleSet)) { - NS_RELEASE(shell); - return rv; - } - - // Note: we don't hold a ref to the shell (it holds a ref to us) - mPresShells.AppendElement(shell); - *aInstancePtrResult = shell; - return NS_OK; -} -#endif - -PRBool nsDocument::DeleteShell(nsIPresShell* aShell) -{ - return mPresShells.RemoveElement(aShell); -} - -PRInt32 nsDocument::GetNumberOfShells() -{ - return mPresShells.Count(); -} - -nsIPresShell* nsDocument::GetShellAt(PRInt32 aIndex) -{ - nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(aIndex); - if (nsnull != shell) { - NS_ADDREF(shell); - } - return shell; -} - -nsIDocument* nsDocument::GetParentDocument() -{ - if (nsnull != mParentDocument) { - NS_ADDREF(mParentDocument); - } - return mParentDocument; -} - -/** - * Note that we do *not* AddRef our parent because that would - * create a circular reference. - */ -void nsDocument::SetParentDocument(nsIDocument* aParent) -{ - mParentDocument = aParent; -} - -void nsDocument::AddSubDocument(nsIDocument* aSubDoc) -{ - NS_ADDREF(aSubDoc); - mSubDocuments.AppendElement(aSubDoc); -} - -PRInt32 nsDocument::GetNumberOfSubDocuments() -{ - return mSubDocuments.Count(); -} - -nsIDocument* nsDocument::GetSubDocumentAt(PRInt32 aIndex) -{ - nsIDocument* doc = (nsIDocument*) mSubDocuments.ElementAt(aIndex); - if (nsnull != doc) { - NS_ADDREF(doc); - } - return doc; -} - -nsIContent* nsDocument::GetRootContent() -{ - if (nsnull != mRootContent) { - NS_ADDREF(mRootContent); - } - return mRootContent; -} - -void nsDocument::SetRootContent(nsIContent* aRoot) -{ - if (mRootContent) { - PRInt32 index = mChildren->IndexOf(mRootContent); - if (aRoot) { - mChildren->ReplaceElementAt(aRoot, index); - } else { - mChildren->RemoveElementAt(index); - } - } else if (aRoot) { - mChildren->AppendElement(aRoot); - } - - mRootContent = aRoot; -} - -NS_IMETHODIMP -nsDocument::ChildAt(PRInt32 aIndex, nsIContent*& aResult) const -{ - nsCOMPtr content( dont_AddRef(NS_STATIC_CAST(nsIContent*, mChildren->ElementAt(aIndex))) ); - NS_IF_ADDREF(aResult = content); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const -{ - aIndex = mChildren->IndexOf(aPossibleChild); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetChildCount(PRInt32& aCount) -{ - PRUint32 count; - mChildren->Count(&count); - aCount = NS_STATIC_CAST(PRInt32, count); - return NS_OK; -} - -PRInt32 nsDocument::GetNumberOfStyleSheets() -{ - return mStyleSheets.Count(); -} - -nsIStyleSheet* nsDocument::GetStyleSheetAt(PRInt32 aIndex) -{ - nsIStyleSheet* sheet = (nsIStyleSheet*)mStyleSheets.ElementAt(aIndex); - NS_IF_ADDREF(sheet); - return sheet; -} - -PRInt32 nsDocument::GetIndexOfStyleSheet(nsIStyleSheet* aSheet) -{ - return mStyleSheets.IndexOf(aSheet); -} - -void nsDocument::InternalAddStyleSheet(nsIStyleSheet* aSheet) // subclass hook for sheet ordering -{ - mStyleSheets.AppendElement(aSheet); -} - -void nsDocument::AddStyleSheetToStyleSets(nsIStyleSheet* aSheet) -{ - PRInt32 count = mPresShells.Count(); - PRInt32 index; - for (index = 0; index < count; index++) { - nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index); - nsCOMPtr set; - if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) { - if (set) { - set->AddDocStyleSheet(aSheet, this); - } - } - } -} - -void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet) -{ - NS_PRECONDITION(nsnull != aSheet, "null arg"); - InternalAddStyleSheet(aSheet); - NS_ADDREF(aSheet); - aSheet->SetOwningDocument(this); - - PRBool enabled = PR_TRUE; - aSheet->GetEnabled(enabled); - - if (enabled) { - AddStyleSheetToStyleSets(aSheet); - - // XXX should observers be notified for disabled sheets??? I think not, but I could be wrong - for (PRInt32 index = 0; index < mObservers.Count(); index++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index); - observer->StyleSheetAdded(this, aSheet); - if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) { - index--; - } - } - } -} - -void nsDocument::RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet) -{ - PRInt32 count = mPresShells.Count(); - PRInt32 index; - for (index = 0; index < count; index++) { - nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index); - nsCOMPtr set; - if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) { - if (set) { - set->RemoveDocStyleSheet(aSheet); - } - } - } -} - -void nsDocument::RemoveStyleSheet(nsIStyleSheet* aSheet) -{ - NS_PRECONDITION(nsnull != aSheet, "null arg"); - mStyleSheets.RemoveElement(aSheet); - - PRBool enabled = PR_TRUE; - aSheet->GetEnabled(enabled); - - if (enabled) { - RemoveStyleSheetFromStyleSets(aSheet); - - // XXX should observers be notified for disabled sheets??? I think not, but I could be wrong - for (PRInt32 index = 0; index < mObservers.Count(); index++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index); - observer->StyleSheetRemoved(this, aSheet); - if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) { - index--; - } - } - } - - aSheet->SetOwningDocument(nsnull); - NS_RELEASE(aSheet); -} - -NS_IMETHODIMP -nsDocument::UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets) -{ - PRUint32 oldCount; - aOldSheets->Count(&oldCount); - nsCOMPtr sheet; - PRUint32 i; - for (i = 0; i < oldCount; i++) { - nsCOMPtr supp; - aOldSheets->GetElementAt(i, getter_AddRefs(supp)); - sheet = do_QueryInterface(supp); - if (sheet) { - mStyleSheets.RemoveElement(sheet); - PRBool enabled = PR_TRUE; - sheet->GetEnabled(enabled); - if (enabled) { - RemoveStyleSheetFromStyleSets(sheet); - } - - sheet->SetOwningDocument(nsnull); - nsIStyleSheet* sheetPtr = sheet.get(); - NS_RELEASE(sheetPtr); - } - } - - PRUint32 newCount; - aNewSheets->Count(&newCount); - for (i = 0; i < newCount; i++) { - nsCOMPtr supp; - aNewSheets->GetElementAt(i, getter_AddRefs(supp)); - sheet = do_QueryInterface(supp); - if (sheet) { - InternalAddStyleSheet(sheet); - nsIStyleSheet* sheetPtr = sheet; - NS_ADDREF(sheetPtr); - sheet->SetOwningDocument(this); - - PRBool enabled = PR_TRUE; - sheet->GetEnabled(enabled); - if (enabled) { - AddStyleSheetToStyleSets(sheet); - sheet->SetOwningDocument(nsnull); - } - } - } - - for (PRInt32 index = 0; index < mObservers.Count(); index++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index); - observer->StyleSheetRemoved(this, sheet); - if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) { - index--; - } - } - - return NS_OK; -} - - -void -nsDocument::InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex) -{ // subclass hook for sheet ordering - mStyleSheets.InsertElementAt(aSheet, aIndex); -} - -NS_IMETHODIMP -nsDocument::InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify) -{ - NS_PRECONDITION(nsnull != aSheet, "null ptr"); - InternalInsertStyleSheetAt(aSheet, aIndex); - - NS_ADDREF(aSheet); - aSheet->SetOwningDocument(this); - - PRBool enabled = PR_TRUE; - aSheet->GetEnabled(enabled); - - PRInt32 count; - PRInt32 index; - if (enabled) { - count = mPresShells.Count(); - for (index = 0; index < count; index++) { - nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index); - nsCOMPtr set; - shell->GetStyleSet(getter_AddRefs(set)); - if (set) { - set->AddDocStyleSheet(aSheet, this); - } - } - } - if (aNotify) { // notify here even if disabled, there may have been others that weren't notified - for (index = 0; index < mObservers.Count(); index++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index); - observer->StyleSheetAdded(this, aSheet); - if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) { - index--; - } - } - } - return NS_OK; -} - - -void nsDocument::SetStyleSheetDisabledState(nsIStyleSheet* aSheet, - PRBool aDisabled) -{ - NS_PRECONDITION(nsnull != aSheet, "null arg"); - PRInt32 index = mStyleSheets.IndexOf((void *)aSheet); - PRInt32 count; - // If we're actually in the document style sheet list - if (-1 != index) { - count = mPresShells.Count(); - for (index = 0; index < count; index++) { - nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index); - nsCOMPtr set; - if (NS_SUCCEEDED(shell->GetStyleSet(getter_AddRefs(set)))) { - if (set) { - if (aDisabled) { - set->RemoveDocStyleSheet(aSheet); - } - else { - set->AddDocStyleSheet(aSheet, this); - } - } - } - } - } - - for (index = 0; index < mObservers.Count(); index++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index); - observer->StyleSheetDisabledStateChanged(this, aSheet, aDisabled); - if (observer != (nsIDocumentObserver*)mObservers.ElementAt(index)) { - index--; - } - } -} - -NS_IMETHODIMP -nsDocument::GetScriptGlobalObject(nsIScriptGlobalObject** aScriptGlobalObject) -{ - NS_ENSURE_ARG_POINTER(aScriptGlobalObject); - - *aScriptGlobalObject = mScriptGlobalObject; - NS_IF_ADDREF(*aScriptGlobalObject); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject) -{ - // XXX HACK ALERT! If the script context owner is null, the document - // will soon be going away. So tell our content that to lose its - // reference to the document. This has to be done before we - // actually set the script context owner to null so that the - // content elements can remove references to their script objects. - if (!aScriptGlobalObject) { - PRUint32 ucount, index; - mChildren->Count(&ucount); - for (index = 0; index < ucount; index++) { - nsCOMPtr content(dont_AddRef(NS_STATIC_CAST(nsIContent*,mChildren->ElementAt(index)))); - content->SetDocument(nsnull, PR_TRUE, PR_TRUE); - } - - // Propagate the out-of-band notification to each PresShell's - // anonymous content as well. This ensures that there aren't any - // accidental script references left in anonymous content keeping - // the document alive. (While not strictly necessary -- the - // PresShell owns us -- it's tidy.) - PRInt32 count; - for (count = mPresShells.Count() - 1; count >= 0; --count) { - nsIPresShell* shell = NS_STATIC_CAST(nsIPresShell*, mPresShells[count]); - if (! shell) - continue; - - shell->ReleaseAnonymousContent(); - } - } - - mScriptGlobalObject = aScriptGlobalObject; - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetNameSpaceManager(nsINameSpaceManager*& aManager) -{ - aManager = mNameSpaceManager; - NS_IF_ADDREF(aManager); - return NS_OK; -} - - -// Note: We don't hold a reference to the document observer; we assume -// that it has a live reference to the document. -void nsDocument::AddObserver(nsIDocumentObserver* aObserver) -{ - // XXX Make sure the observer isn't already in the list - if (mObservers.IndexOf(aObserver) == -1) { - mObservers.AppendElement(aObserver); - } -} - -PRBool nsDocument::RemoveObserver(nsIDocumentObserver* aObserver) -{ - // If we're in the process of destroying the document (and we're - // informing the observers of the destruction), don't remove the - // observers from the list. This is not a big deal, since we - // don't hold a live reference to the observers. - if (!mInDestructor) - return mObservers.RemoveElement(aObserver); - else - return (mObservers.IndexOf(aObserver) != -1); -} - -NS_IMETHODIMP -nsDocument::BeginUpdate() -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i]; - observer->BeginUpdate(this); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::EndUpdate() -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i]; - observer->EndUpdate(this); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::BeginLoad() -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i]; - observer->BeginLoad(this); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::EndLoad() -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i]; - observer->EndLoad(this); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::ContentChanged(nsIContent* aContent, - nsISupports* aSubContent) -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i]; - observer->ContentChanged(this, aContent, aSubContent); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::ContentStatesChanged(nsIContent* aContent1, - nsIContent* aContent2) -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i]; - observer->ContentStatesChanged(this, aContent1, aContent2); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - } - return NS_OK; -} - - -NS_IMETHODIMP -nsDocument::ContentAppended(nsIContent* aContainer, - PRInt32 aNewIndexInContainer) -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i]; - observer->ContentAppended(this, aContainer, aNewIndexInContainer); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::ContentInserted(nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i]; - observer->ContentInserted(this, aContainer, aChild, aIndexInContainer); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::ContentReplaced(nsIContent* aContainer, - nsIContent* aOldChild, - nsIContent* aNewChild, - PRInt32 aIndexInContainer) -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i]; - observer->ContentReplaced(this, aContainer, aOldChild, aNewChild, - aIndexInContainer); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::ContentRemoved(nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer) -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i]; - observer->ContentRemoved(this, aContainer, - aChild, aIndexInContainer); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::AttributeChanged(nsIContent* aChild, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aHint) -{ - PRInt32 i; - nsresult result = NS_OK; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i]; - nsresult rv = observer->AttributeChanged(this, aChild, aNameSpaceID, aAttribute, aHint); - if (NS_FAILED(rv) && NS_SUCCEEDED(result)) - result = rv; - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - } - return result; -} - - -NS_IMETHODIMP -nsDocument::StyleRuleChanged(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule, - PRInt32 aHint) -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i]; - observer->BeginUpdate(this); - observer->StyleRuleChanged(this, aStyleSheet, aStyleRule, aHint); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - else { - observer->EndUpdate(this); - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::StyleRuleAdded(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule) -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i]; - observer->BeginUpdate(this); - observer->StyleRuleAdded(this, aStyleSheet, aStyleRule); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - else { - observer->EndUpdate(this); - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::StyleRuleRemoved(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule) -{ - PRInt32 i; - // Get new value of count for every iteration in case - // observers remove themselves during the loop. - for (i = 0; i < mObservers.Count(); i++) { - nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i]; - observer->BeginUpdate(this); - observer->StyleRuleRemoved(this, aStyleSheet, aStyleRule); - // Make sure that the observer didn't remove itself during the - // notification. If it did, update our index and count. - if (observer != (nsIDocumentObserver*)mObservers[i]) { - i--; - } - else { - observer->EndUpdate(this); - } - } - return NS_OK; -} - - -nsresult nsDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - nsCOMPtr global; - - if (nsnull == mScriptObject) { - // XXX We make the (possibly erroneous) assumption that the first - // presentation shell represents the "primary view" of the document - // and that the JS parent chain should incorporate just that view. - // This is done for lack of a better model when we have multiple - // views. - nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(0); - if (shell) { - nsCOMPtr cx; - shell->GetPresContext(getter_AddRefs(cx)); - nsCOMPtr container; - - res = cx->GetContainer(getter_AddRefs(container)); - if (NS_SUCCEEDED(res) && container) { - global = do_GetInterface(container); - } - } - // XXX If we can't find a view, parent to the calling context's - // global object. This may not be right either, but we need - // something. - else { - global = getter_AddRefs(aContext->GetGlobalObject()); - } - - if (NS_SUCCEEDED(res)) { - res = NS_NewScriptDocument(aContext, - (nsISupports *)(nsIDOMDocument *)this, - (nsISupports *)global, - (void**)&mScriptObject); - } - } - - *aScriptObject = mScriptObject; - - return res; -} - -nsresult nsDocument::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - - -// -// nsIDOMDocument interface -// -NS_IMETHODIMP -nsDocument::GetDoctype(nsIDOMDocumentType** aDoctype) -{ - NS_ENSURE_ARG_POINTER(aDoctype); - - *aDoctype = nsnull; - PRUint32 i, count; - mChildren->Count(&count); - nsCOMPtr rootContentNode( do_QueryInterface(mRootContent) ); - nsCOMPtr node; - - for (i = 0; i < count; i++) { - mChildren->QueryElementAt(i, NS_GET_IID(nsIDOMNode), getter_AddRefs(node)); - - NS_ASSERTION(node, "null element of mChildren"); - - // doctype can't be after the root - // XXX Do we really want to enforce this when we don't enforce - // anything else? - if (node == rootContentNode) - return NS_OK; - - if (node) { - PRUint16 nodeType; - - node->GetNodeType(&nodeType); - - if (nodeType == nsIDOMNode::DOCUMENT_TYPE_NODE) { - return node->QueryInterface(NS_GET_IID(nsIDOMDocumentType), - (void **)aDoctype); - } - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetImplementation(nsIDOMDOMImplementation** aImplementation) -{ - // For now, create a new implementation every time. This shouldn't - // be a high bandwidth operation - nsDOMImplementation* impl = new nsDOMImplementation(mDocumentURL); - if (nsnull == impl) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return impl->QueryInterface(NS_GET_IID(nsIDOMDOMImplementation), (void**)aImplementation); -} - -NS_IMETHODIMP -nsDocument::GetDocumentElement(nsIDOMElement** aDocumentElement) -{ - if (nsnull == aDocumentElement) { - return NS_ERROR_NULL_POINTER; - } - - nsresult res = NS_OK; - - if (nsnull != mRootContent) { - res = mRootContent->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aDocumentElement); - NS_ASSERTION(NS_OK == res, "Must be a DOM Element"); - } else { - *aDocumentElement = nsnull; - } - - return res; -} - -NS_IMETHODIMP -nsDocument::CreateElement(const nsAReadableString& aTagName, - nsIDOMElement** aReturn) -{ - // Should be implemented by subclass - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDocument::CreateTextNode(const nsAReadableString& aData, nsIDOMText** aReturn) -{ - nsCOMPtr text; - nsresult rv = NS_NewTextNode(getter_AddRefs(text)); - - if (NS_OK == rv) { - rv = text->QueryInterface(NS_GET_IID(nsIDOMText), (void**)aReturn); - (*aReturn)->AppendData(aData); - } - - return rv; -} - -NS_IMETHODIMP -nsDocument::CreateDocumentFragment(nsIDOMDocumentFragment** aReturn) -{ - return NS_NewDocumentFragment(aReturn, this); -} - -NS_IMETHODIMP -nsDocument::CreateComment(const nsAReadableString& aData, nsIDOMComment** aReturn) -{ - nsCOMPtr comment; - nsresult rv = NS_NewCommentNode(getter_AddRefs(comment)); - - if (NS_OK == rv) { - rv = comment->QueryInterface(NS_GET_IID(nsIDOMComment), (void**)aReturn); - (*aReturn)->AppendData(aData); - } - - return rv; -} - -NS_IMETHODIMP -nsDocument::CreateCDATASection(const nsAReadableString& aData, nsIDOMCDATASection** aReturn) -{ - // Should be implemented by subclass - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDocument::CreateProcessingInstruction(const nsAReadableString& aTarget, - const nsAReadableString& aData, - nsIDOMProcessingInstruction** aReturn) -{ - // Should be implemented by subclass - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDocument::CreateAttribute(const nsAReadableString& aName, - nsIDOMAttr** aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_NOT_INITIALIZED); - - nsAutoString value; - nsDOMAttribute* attribute; - - nsCOMPtr nodeInfo; - nsresult rv = mNodeInfoManager->GetNodeInfo(aName, nsnull, kNameSpaceID_None, - *getter_AddRefs(nodeInfo)); - NS_ENSURE_SUCCESS(rv, rv); - - attribute = new nsDOMAttribute(nsnull, nodeInfo, value); - NS_ENSURE_TRUE(attribute, NS_ERROR_OUT_OF_MEMORY); - - return attribute->QueryInterface(NS_GET_IID(nsIDOMAttr), (void**)aReturn); -} - -NS_IMETHODIMP -nsDocument::CreateEntityReference(const nsAReadableString& aName, - nsIDOMEntityReference** aReturn) -{ - // Should be implemented by subclass - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDocument::GetElementsByTagName(const nsAReadableString& aTagname, - nsIDOMNodeList** aReturn) -{ - nsCOMPtr nameAtom(dont_AddRef(NS_NewAtom(aTagname))); - - nsContentList* list = new nsContentList(this, nameAtom, kNameSpaceID_Unknown); - NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY); - - return list->QueryInterface(NS_GET_IID(nsIDOMNodeList), (void **)aReturn); -} - -NS_IMETHODIMP -nsDocument::GetElementsByTagNameNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - nsIDOMNodeList** aReturn) -{ - - PRInt32 nameSpaceId = kNameSpaceID_Unknown; - - nsContentList* list = nsnull; - - if (!aNamespaceURI.Equals(NS_LITERAL_STRING("*"))) { - mNameSpaceManager->GetNameSpaceID(aNamespaceURI, nameSpaceId); - - if (nameSpaceId == kNameSpaceID_Unknown) { - // Unkonwn namespace means no matches, we create an empty list... - list = new nsContentList(this, nsnull, kNameSpaceID_None); - NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY); - } - } - - if (!list) { - nsCOMPtr nameAtom(dont_AddRef(NS_NewAtom(aLocalName))); - list = new nsContentList(this, nameAtom, nameSpaceId); - NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY); - } - - return list->QueryInterface(NS_GET_IID(nsIDOMNodeList), (void **)aReturn); -} - -NS_IMETHODIMP -nsDocument::GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets) -{ - if (nsnull == mDOMStyleSheets) { - mDOMStyleSheets = new nsDOMStyleSheetList(this); - if (nsnull == mDOMStyleSheets) { - return NS_ERROR_OUT_OF_MEMORY; - } - NS_ADDREF(mDOMStyleSheets); - } - - *aStyleSheets = mDOMStyleSheets; - NS_ADDREF(mDOMStyleSheets); - - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetCharacterSet(nsAWritableString& aCharacterSet) -{ - return GetDocumentCharacterSet(aCharacterSet); -} - -NS_IMETHODIMP -nsDocument::ImportNode(nsIDOMNode* aImportedNode, - PRBool aDeep, - nsIDOMNode** aReturn) -{ - NS_ENSURE_ARG(aImportedNode); - NS_ENSURE_ARG_POINTER(aReturn); - - return aImportedNode->CloneNode(aDeep, aReturn); -} - -NS_IMETHODIMP -nsDocument::AddBinding(nsIDOMElement* aContent, const nsAReadableString& aURL) -{ - nsCOMPtr bm; - GetBindingManager(getter_AddRefs(bm)); - nsCOMPtr content(do_QueryInterface(aContent)); - - return bm->AddLayeredBinding(content, aURL); -} - -NS_IMETHODIMP -nsDocument::RemoveBinding(nsIDOMElement* aContent, const nsAReadableString& aURL) -{ - if (mBindingManager) { - nsCOMPtr content(do_QueryInterface(aContent)); - return mBindingManager->RemoveLayeredBinding(content, aURL); - } - - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsDocument::LoadBindingDocument(const nsAReadableString& aURL, nsIDOMDocument** aResult) -{ - if (mBindingManager) { - nsCOMPtr doc; - mBindingManager->LoadBindingDocument(this, aURL, getter_AddRefs(doc)); - nsCOMPtr domDoc(do_QueryInterface(doc)); - *aResult = domDoc; - NS_IF_ADDREF(*aResult); - return NS_OK; - } - - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsDocument::GetBindingParent(nsIDOMNode* aNode, nsIDOMElement** aResult) -{ - *aResult = nsnull; - nsCOMPtr content(do_QueryInterface(aNode)); - if (!content) - return NS_ERROR_FAILURE; - - nsCOMPtr result; - content->GetBindingParent(getter_AddRefs(result)); - nsCOMPtr elt(do_QueryInterface(result)); - *aResult = elt; - NS_IF_ADDREF(*aResult); - return NS_OK; -} - -static nsresult -GetElementByAttribute(nsIContent* aContent, - nsIAtom* aAttrName, - const nsAReadableString& aAttrValue, - PRBool aUniversalMatch, - nsIDOMElement** aResult) -{ - nsAutoString value; - nsresult rv = aContent->GetAttribute(kNameSpaceID_None, aAttrName, value); - if (rv == NS_CONTENT_ATTR_HAS_VALUE) { - if (aUniversalMatch || value.Equals(aAttrValue)) - return aContent->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aResult); - } - - PRInt32 childCount; - aContent->ChildCount(childCount); - - for (PRInt32 i = 0; i < childCount; ++i) { - nsCOMPtr current; - current->ChildAt(i, *getter_AddRefs(current)); - - GetElementByAttribute(current, aAttrName, aAttrValue, aUniversalMatch, aResult); - - if (*aResult) - return NS_OK; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetAnonymousElementByAttribute(nsIDOMElement* aElement, - const nsAReadableString& aAttrName, - const nsAReadableString& aAttrValue, - nsIDOMElement** aResult) -{ - *aResult = nsnull; - - nsCOMPtr nodeList; - GetAnonymousNodes(aElement, getter_AddRefs(nodeList)); - - if (!nodeList) - return NS_OK; - - nsCOMPtr attribute = getter_AddRefs(NS_NewAtom(aAttrName)); - - PRUint32 length; - nodeList->GetLength(&length); - - PRBool universalMatch = aAttrValue.Equals(NS_LITERAL_STRING("*")); - - for (PRUint32 i = 0; i < length; ++i) { - nsCOMPtr current; - nodeList->Item(i, getter_AddRefs(current)); - - nsCOMPtr content(do_QueryInterface(current)); - - GetElementByAttribute(content, attribute, aAttrValue, universalMatch, aResult); - if (*aResult) - return NS_OK; - } - - return NS_OK; -} - - -NS_IMETHODIMP -nsDocument::GetAnonymousNodes(nsIDOMElement* aElement, - nsIDOMNodeList** aResult) -{ - *aResult = nsnull; - if (mBindingManager) { - nsCOMPtr content(do_QueryInterface(aElement)); - return mBindingManager->GetAnonymousNodesFor(content, aResult); - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetLocation(jsval* aLocation) -{ - if (mScriptGlobalObject) { - nsCOMPtr window(do_QueryInterface(mScriptGlobalObject)); - if(window) { - return window->GetLocation(aLocation); - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::SetLocation(jsval aLocation) -{ - if (mScriptGlobalObject) { - nsCOMPtr window(do_QueryInterface(mScriptGlobalObject)); - if(window) { - return window->SetLocation(aLocation); - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::CreateRange(nsIDOMRange** aReturn) -{ - return NS_NewRange(aReturn); -} - - -NS_IMETHODIMP -nsDocument::GetDefaultView(nsIDOMAbstractView** aDefaultView) -{ - NS_ENSURE_ARG_POINTER(aDefaultView); - *aDefaultView = nsnull; - - nsIPresShell *shell = NS_STATIC_CAST(nsIPresShell *, - mPresShells.ElementAt(0)); - NS_ENSURE_TRUE(shell, NS_OK); - - nsCOMPtr ctx; - nsresult rv = shell->GetPresContext(getter_AddRefs(ctx)); - NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && ctx, rv); - - nsCOMPtr container; - rv = ctx->GetContainer(getter_AddRefs(container)); - NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && container, rv); - - nsCOMPtr ifrq(do_QueryInterface(container)); - NS_ENSURE_TRUE(ifrq, NS_OK); - - nsCOMPtr window; - ifrq->GetInterface(NS_GET_IID(nsIDOMWindowInternal), getter_AddRefs(window)); - NS_ENSURE_TRUE(window, NS_OK); - - window->QueryInterface(NS_GET_IID(nsIDOMAbstractView), - (void **)aDefaultView); - - return NS_OK; -} - - -NS_IMETHODIMP -nsDocument::Load (const nsAReadableString& aUrl) -{ - // Should be implemented by subclass - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDocument::GetPlugins(nsIDOMPluginArray** aPlugins) -{ - NS_ENSURE_ARG_POINTER(aPlugins); - *aPlugins = nsnull; - - // XXX Could also get this through mScriptGlobalObject - nsIPresShell *shell = NS_STATIC_CAST(nsIPresShell *, - mPresShells.ElementAt(0)); - NS_ENSURE_TRUE(shell, NS_OK); - - nsCOMPtr ctx; - nsresult rv = shell->GetPresContext(getter_AddRefs(ctx)); - NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && ctx, rv); - - nsCOMPtr container; - rv = ctx->GetContainer(getter_AddRefs(container)); - NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && container, rv); - - nsCOMPtr ifrq(do_QueryInterface(container)); - NS_ENSURE_TRUE(ifrq, NS_OK); - - nsCOMPtr window; - ifrq->GetInterface(NS_GET_IID(nsIDOMWindowInternal), getter_AddRefs(window)); - NS_ENSURE_TRUE(window, NS_OK); - - nsCOMPtr navigator; - window->GetNavigator(getter_AddRefs(navigator)); - NS_ENSURE_TRUE(navigator, NS_OK); - - return navigator->GetPlugins(aPlugins); -} - -NS_IMETHODIMP -nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult) -{ - nsresult rv; - - *aResult = nsnull; - - if (!mBoxObjectTable) - mBoxObjectTable = new nsSupportsHashtable; - else { - nsISupportsKey key(aElement); - nsCOMPtr supports(dont_AddRef(NS_STATIC_CAST(nsISupports*, mBoxObjectTable->Get(&key)))); - nsCOMPtr boxObject(do_QueryInterface(supports)); - if (boxObject) { - *aResult = boxObject; - NS_ADDREF(*aResult); - return NS_OK; - } - } - - nsCOMPtr shell(getter_AddRefs(GetShellAt(0))); - if (!shell) - return NS_ERROR_FAILURE; - - PRInt32 namespaceID; - nsCOMPtr tag; - NS_WITH_SERVICE(nsIXBLService, xblService, "@mozilla.org/xbl;1", &rv); - nsCOMPtr content(do_QueryInterface(aElement)); - xblService->ResolveTag(content, &namespaceID, getter_AddRefs(tag)); - - nsCAutoString contractID("@mozilla.org/layout/xul-boxobject"); - if (namespaceID == nsXULAtoms::nameSpaceID) { - if (tag.get() == nsXULAtoms::browser) - contractID += "-browser"; - else if (tag.get() == nsXULAtoms::editor) - contractID += "-editor"; - else if (tag.get() == nsXULAtoms::iframe) - contractID += "-iframe"; - else if (tag.get() == nsXULAtoms::menu) - contractID += "-menu"; - else if (tag.get() == nsXULAtoms::popupset) - contractID += "-popupset"; - else if (tag.get() == nsXULAtoms::tree) - contractID += "-tree"; - else if (tag.get() == nsXULAtoms::scrollbox) - contractID += "-scrollbox"; - else if (tag.get() == nsXULAtoms::outliner) - contractID += "-outliner"; - } - contractID += ";1"; - - nsCOMPtr boxObject(do_CreateInstance(contractID.get())); - if (!boxObject) - return NS_ERROR_FAILURE; - - nsCOMPtr privateBox(do_QueryInterface(boxObject)); - if (NS_FAILED(rv = privateBox->Init(content, shell))) - return rv; - - SetBoxObjectFor(aElement, boxObject); - - *aResult = boxObject; - NS_ADDREF(*aResult); - - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::SetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject* aBoxObject) -{ - if (!mBoxObjectTable) { - if (!aBoxObject) - return NS_OK; - mBoxObjectTable = new nsSupportsHashtable(12); - } - - nsISupportsKey key(aElement); - - if (aBoxObject) - mBoxObjectTable->Put(&key, aBoxObject); - else { - nsCOMPtr supp; - mBoxObjectTable->Remove(&key, getter_AddRefs(supp)); - nsCOMPtr boxObject(do_QueryInterface(supp)); - if (boxObject) - boxObject->SetDocument(nsnull); - } - - return NS_OK; -} - -// -// nsIDOMNode methods -// -NS_IMETHODIMP -nsDocument::GetNodeName(nsAWritableString& aNodeName) -{ - aNodeName.Assign(NS_LITERAL_STRING("#document")); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetNodeValue(nsAWritableString& aNodeValue) -{ - aNodeValue.Truncate(); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::SetNodeValue(const nsAReadableString& aNodeValue) -{ - return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; -} - -NS_IMETHODIMP -nsDocument::GetNodeType(PRUint16* aNodeType) -{ - *aNodeType = nsIDOMNode::DOCUMENT_NODE; - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetParentNode(nsIDOMNode** aParentNode) -{ - *aParentNode = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetChildNodes(nsIDOMNodeList** aChildNodes) -{ - if (nsnull == mChildNodes) { - mChildNodes = new nsDocumentChildNodes(this); - if (nsnull == mChildNodes) { - return NS_ERROR_OUT_OF_MEMORY; - } - NS_ADDREF(mChildNodes); - } - - return mChildNodes->QueryInterface(NS_GET_IID(nsIDOMNodeList), (void**)aChildNodes); -} - -NS_IMETHODIMP -nsDocument::HasChildNodes(PRBool* aHasChildNodes) -{ - NS_ENSURE_ARG(aHasChildNodes); - - PRUint32 count; - mChildren->Count(&count); - *aHasChildNodes = (count != 0); - - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::HasAttributes(PRBool* aHasAttributes) -{ - NS_ENSURE_ARG(aHasAttributes); - - *aHasAttributes = PR_FALSE; - - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetFirstChild(nsIDOMNode** aFirstChild) -{ - nsresult result = NS_OK; - - PRUint32 count; - mChildren->Count(&count); - if (count) { - result = mChildren->QueryElementAt(0, NS_GET_IID(nsIDOMNode), - NS_REINTERPRET_CAST(void**, aFirstChild)); - } else { - *aFirstChild = nsnull; - } - - return result; -} - -NS_IMETHODIMP -nsDocument::GetLastChild(nsIDOMNode** aLastChild) -{ - nsresult result = NS_OK; - - PRUint32 count; - mChildren->Count(&count); - if (count) { - result = mChildren->QueryElementAt(count-1, NS_GET_IID(nsIDOMNode), - NS_REINTERPRET_CAST(void**, aLastChild)); - } else { - *aLastChild = nsnull; - } - - return result; -} - -NS_IMETHODIMP -nsDocument::GetPreviousSibling(nsIDOMNode** aPreviousSibling) -{ - *aPreviousSibling = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetNextSibling(nsIDOMNode** aNextSibling) -{ - *aNextSibling = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetAttributes(nsIDOMNamedNodeMap** aAttributes) -{ - *aAttributes = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetNamespaceURI(nsAWritableString& aNamespaceURI) -{ - aNamespaceURI.Truncate(); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetPrefix(nsAWritableString& aPrefix) -{ - aPrefix.Truncate(); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::SetPrefix(const nsAReadableString& aPrefix) -{ - return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; -} - -NS_IMETHODIMP -nsDocument::GetLocalName(nsAWritableString& aLocalName) -{ - aLocalName.Truncate(); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn) -{ - NS_ASSERTION(nsnull != aNewChild, "null ptr"); - PRInt32 index; - PRUint16 nodeType; - - *aReturn = nsnull; // Do we need to do this? - - if (nsnull == aNewChild) { - return NS_ERROR_NULL_POINTER; - } - - // If it's a child type we can't handle (per DOM spec), or if it's an - // element and we already have a root (our addition to DOM spec), throw - // HIERARCHY_REQUEST_ERR. - aNewChild->GetNodeType(&nodeType); - if (((COMMENT_NODE != nodeType) && - (TEXT_NODE != nodeType) && - (PROCESSING_INSTRUCTION_NODE != nodeType) && - (DOCUMENT_TYPE_NODE != nodeType) && - (ELEMENT_NODE != nodeType)) || - ((ELEMENT_NODE == nodeType) && mRootContent)){ - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - nsCOMPtr content( do_QueryInterface(aNewChild) ); - if (!content) { - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - if (!aRefChild) { - PRUint32 count; - mChildren->Count(&count); - index = count; - mChildren->AppendElement(content); - } - else { - nsCOMPtr refContent( do_QueryInterface(aRefChild) ); - - if (!refContent) { - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - - index = mChildren->IndexOf(refContent); - if (index != -1) { - mChildren->InsertElementAt(content, index); - } else { - // couldn't find refChild - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - } - - // If we get here, we've succesfully inserted content into the - // index-th spot in mChildren. - if (ELEMENT_NODE == nodeType) - mRootContent = content; - ContentInserted(nsnull, content, index); - - content->SetDocument(this, PR_TRUE, PR_TRUE); - *aReturn = aNewChild; - NS_ADDREF(aNewChild); - - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn) -{ - NS_ASSERTION(((nsnull != aNewChild) && (nsnull != aOldChild)), "null ptr"); - nsresult result = NS_OK; - PRInt32 index; - PRUint16 nodeType; - - *aReturn = nsnull; // is this necessary? - - if ((nsnull == aNewChild) || (nsnull == aOldChild)) { - return NS_ERROR_NULL_POINTER; - } - - aNewChild->GetNodeType(&nodeType); - - if ((COMMENT_NODE != nodeType) && - (TEXT_NODE != nodeType) && - (PROCESSING_INSTRUCTION_NODE != nodeType) && - (DOCUMENT_TYPE_NODE != nodeType) && - (ELEMENT_NODE != nodeType)) { - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - nsCOMPtr content( do_QueryInterface(aNewChild) ); - nsCOMPtr refContent( do_QueryInterface(aOldChild) ); - if (!content || !refContent) { - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - if ((ELEMENT_NODE == nodeType) && - mRootContent && - (mRootContent != refContent.get())) - { - // Caller attempted to add a second element as a child. - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - index = mChildren->IndexOf(refContent); - if (-1 == index) { - // The reference child is not a child of the document. - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - - refContent->SetDocument(nsnull, PR_TRUE, PR_TRUE); - ContentRemoved(nsnull, refContent, index); - - mChildren->ReplaceElementAt(content, index); - // This is OK because we checked above. - if (ELEMENT_NODE == nodeType) - mRootContent = content; - - ContentInserted(nsnull, content, index); - content->SetDocument(this, PR_TRUE, PR_TRUE); - *aReturn = aOldChild; - NS_ADDREF(aOldChild); - - return result; -} - -NS_IMETHODIMP -nsDocument::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) -{ - NS_ASSERTION(nsnull != aOldChild, "null ptr"); - - *aReturn = nsnull; // do we need to do this? - - if (nsnull == aOldChild) { - return NS_ERROR_NULL_POINTER; - } - - nsCOMPtr content( do_QueryInterface(aOldChild) ); - if (!content) { - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - PRInt32 index = mChildren->IndexOf(content); - if (-1 == index) { - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - - ContentRemoved(nsnull, content, index); - - mChildren->RemoveElementAt(index); - if (content.get() == mRootContent) - mRootContent = nsnull; - - content->SetDocument(nsnull, PR_TRUE, PR_TRUE); - - *aReturn = aOldChild; - NS_ADDREF(aOldChild); - - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn) -{ - return InsertBefore(aNewChild, nsnull, aReturn); -} - -NS_IMETHODIMP -nsDocument::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) -{ - // XXX should be implemented by subclass - *aReturn = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::Normalize() -{ - // XXX Not completely correct, since you can still have unnormalized - // text nodes as immediate children of the document. - if (mRootContent) { - nsCOMPtr node(do_QueryInterface(mRootContent)); - - if (node) { - return node->Normalize(); - } - } - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::IsSupported(const nsAReadableString& aFeature, - const nsAReadableString& aVersion, - PRBool* aReturn) -{ - return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn); -} - -NS_IMETHODIMP -nsDocument::GetOwnerDocument(nsIDOMDocument** aOwnerDocument) -{ - *aOwnerDocument = nsnull; - return NS_OK; -} - -nsresult nsDocument::GetListenerManager(nsIEventListenerManager **aInstancePtrResult) -{ - if (nsnull != mListenerManager) { - return mListenerManager->QueryInterface(NS_GET_IID(nsIEventListenerManager), (void**) aInstancePtrResult); - } - if (NS_OK == GetNewListenerManager(aInstancePtrResult)) { - mListenerManager = *aInstancePtrResult; - NS_ADDREF(mListenerManager); - return NS_OK; - } - return NS_ERROR_FAILURE; -} - -nsresult nsDocument::GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult) -{ - return NS_NewEventListenerManager(aInstancePtrResult); -} - -nsresult nsDocument::HandleEvent(nsIDOMEvent *aEvent) -{ - return DispatchEvent(aEvent); -} - -nsresult nsDocument::HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus) -{ - nsresult mRet = NS_OK; - - nsIDOMEvent* domEvent = nsnull; - - if (NS_EVENT_FLAG_INIT & aFlags) { - if (!aDOMEvent) { - aDOMEvent = &domEvent; - } - aEvent->flags = aFlags; - aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); - } - - //Capturing stage - if (NS_EVENT_FLAG_BUBBLE != aFlags && nsnull != mScriptGlobalObject) { - mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); - } - - //Local handling stage - if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) && - !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) { - aEvent->flags |= aFlags; - mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, this, aFlags, aEventStatus); - aEvent->flags &= ~aFlags; - } - - //Bubbling stage - if (NS_EVENT_FLAG_CAPTURE != aFlags && nsnull != mScriptGlobalObject) { - mScriptGlobalObject->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_BUBBLE, aEventStatus); - } - - if (NS_EVENT_FLAG_INIT & aFlags) { - // We're leaving the DOM event loop so if we created a DOM event, release here. - if (nsnull != *aDOMEvent) { - nsrefcnt rc; - NS_RELEASE2(*aDOMEvent, rc); - if (0 != rc) { - //Okay, so someone in the DOM loop (a listener, JS object) still has a ref to the DOM Event but - //the internal data hasn't been malloc'd. Force a copy of the data here so the DOM Event is still valid. - nsIPrivateDOMEvent *mPrivateEvent; - if (NS_OK == (*aDOMEvent)->QueryInterface(NS_GET_IID(nsIPrivateDOMEvent), (void**)&mPrivateEvent)) { - mPrivateEvent->DuplicatePrivateData(); - NS_RELEASE(mPrivateEvent); - } - } - } - aDOMEvent = nsnull; - } - - return mRet; -} - -nsresult nsDocument::AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID) -{ - nsCOMPtr manager; - - GetListenerManager(getter_AddRefs(manager)); - if (manager) { - manager->AddEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE); - return NS_OK; - } - return NS_ERROR_FAILURE; -} - -nsresult nsDocument::RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID) -{ - if (nsnull != mListenerManager) { - mListenerManager->RemoveEventListenerByIID(aListener, aIID, NS_EVENT_FLAG_BUBBLE); - return NS_OK; - } - return NS_ERROR_FAILURE; -} - -nsresult nsDocument::AddEventListener(const nsAReadableString& aType, nsIDOMEventListener* aListener, - PRBool aUseCapture) -{ - nsCOMPtr manager; - - GetListenerManager(getter_AddRefs(manager)); - if (manager) { - PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE; - - manager->AddEventListenerByType(aListener, aType, flags); - return NS_OK; - } - return NS_ERROR_FAILURE; -} - -nsresult nsDocument::RemoveEventListener(const nsAReadableString& aType, nsIDOMEventListener* aListener, - PRBool aUseCapture) -{ - if (nsnull != mListenerManager) { - PRInt32 flags = aUseCapture ? NS_EVENT_FLAG_CAPTURE : NS_EVENT_FLAG_BUBBLE; - - mListenerManager->RemoveEventListenerByType(aListener, aType, flags); - return NS_OK; - } - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsDocument::DispatchEvent(nsIDOMEvent* aEvent) -{ - // Obtain a presentation context - PRInt32 count = GetNumberOfShells(); - if (count == 0) - return NS_OK; - - nsCOMPtr shell(getter_AddRefs(GetShellAt(0))); - - // Retrieve the context - nsCOMPtr presContext; - shell->GetPresContext(getter_AddRefs(presContext)); - - nsCOMPtr esm; - if (NS_SUCCEEDED(presContext->GetEventStateManager(getter_AddRefs(esm)))) { - return esm->DispatchNewEvent((nsISupports *)(nsIDOMDocument *)this, aEvent); - } - - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsDocument::CreateEvent(const nsAReadableString& aEventType, nsIDOMEvent** aReturn) -{ - // Obtain a presentation context - PRInt32 count = GetNumberOfShells(); - if (count == 0) - return NS_OK; - - nsCOMPtr shell(getter_AddRefs(GetShellAt(0))); - - // Retrieve the context - nsCOMPtr presContext; - shell->GetPresContext(getter_AddRefs(presContext)); - - if (presContext) { - nsCOMPtr manager; - GetListenerManager(getter_AddRefs(manager)); - if (manager) { - return manager->CreateEvent(presContext, nsnull, aEventType, aReturn); - } - } - - return NS_ERROR_FAILURE; -} - -PRBool nsDocument::AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) -{ - return PR_TRUE; -} - -PRBool nsDocument::DeleteProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) -{ - return PR_TRUE; -} - -PRBool nsDocument::GetProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) -{ - return PR_TRUE; -} - -PRBool nsDocument::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) -{ - PRBool result = PR_TRUE; - - if (JS_TypeOfValue(aContext, *aVp) == JSTYPE_FUNCTION && JSVAL_IS_STRING(aID)) { - const PRUnichar* str = NS_REINTERPRET_CAST(const PRUnichar *, JS_GetStringChars(JS_ValueToString(aContext, aID))); - - if (str && str[0] == 'o' && str[1] == 'n' && str[2]) { - PRBool iidFound = PR_TRUE; - nsIID theIID; - nsCOMPtr atom(dont_AddRef(NS_NewAtom(str))); - - if (atom.get() == nsLayoutAtoms::onmousedown || atom.get() == nsLayoutAtoms::onmouseup || atom.get() == nsLayoutAtoms::onclick || - atom.get() == nsLayoutAtoms::onmouseover || atom.get() == nsLayoutAtoms::onmouseout) { - theIID = NS_GET_IID(nsIDOMMouseListener); - } - else if (atom.get() == nsLayoutAtoms::onkeydown || atom.get() == nsLayoutAtoms::onkeyup || atom.get() == nsLayoutAtoms::onkeypress) { - theIID = NS_GET_IID(nsIDOMKeyListener); - } - else if (atom.get() == nsLayoutAtoms::onmousemove) { - theIID = NS_GET_IID(nsIDOMMouseMotionListener); - } - else if (atom.get() == nsLayoutAtoms::onfocus || atom.get() == nsLayoutAtoms::onblur) { - theIID = NS_GET_IID(nsIDOMFocusListener); - } - else if (atom.get() == nsLayoutAtoms::onsubmit || atom.get() == nsLayoutAtoms::onreset || atom.get() == nsLayoutAtoms::onchange || - atom.get() == nsLayoutAtoms::onselect) { - theIID = NS_GET_IID(nsIDOMFormListener); - } - else if (atom.get() == nsLayoutAtoms::onload || atom.get() == nsLayoutAtoms::onunload || atom.get() == nsLayoutAtoms::onabort || - atom.get() == nsLayoutAtoms::onerror) { - theIID = NS_GET_IID(nsIDOMLoadListener); - } - else if (atom.get() == nsLayoutAtoms::onpaint) { - theIID = NS_GET_IID(nsIDOMPaintListener); - } - else { - iidFound = PR_FALSE; - } - - if (iidFound) { - nsCOMPtr manager; - GetListenerManager(getter_AddRefs(manager)); - - if (manager) { - nsCOMPtr scriptContext; - nsresult rv = nsLayoutUtils::GetStaticScriptContext(aContext, NS_REINTERPRET_CAST(JSObject*, mScriptObject), - getter_AddRefs(scriptContext)); - if (NS_SUCCEEDED(rv) && scriptContext) { - rv = manager->RegisterScriptEventListener(scriptContext, this, atom, theIID); - } - if (NS_FAILED(rv)) - result = PR_FALSE; - } - } - } - } - - return result; -} - -PRBool nsDocument::EnumerateProperty(JSContext *aContext, JSObject *aObj) -{ - return PR_TRUE; -} - -PRBool nsDocument::Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty) -{ - *aDidDefineProperty = PR_FALSE; - - return PR_TRUE; -} - -PRBool nsDocument::Convert(JSContext *aContext, JSObject *aObj, jsval aID) -{ - return PR_TRUE; -} - -void nsDocument::Finalize(JSContext *aContext, JSObject *aObj) -{ -} - -/** - * Finds text in content - */ -NS_IMETHODIMP nsDocument::FindNext(const nsAReadableString& aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound) -{ - aIsFound = PR_FALSE; - return NS_ERROR_FAILURE; -} - - -NS_IMETHODIMP -nsDocument::InitDiskDocument(nsIFile *aFile) -{ - // aFile may be nsnull here - mFileSpec = nsnull; // delete if we have one - - if (aFile) - { - // we clone the nsIFile here, rather than just holding onto a ref, - // in case the caller does something to aFile later - nsresult rv = aFile->Clone(getter_AddRefs(mFileSpec)); - if (NS_FAILED(rv)) return rv; - } - - mModCount = 0; - return NS_OK; -} - - - -NS_IMETHODIMP -nsDocument::SaveFile( nsIFile* aFile, - PRBool aReplaceExisting, - PRBool aSaveCopy, - const PRUnichar* aFileType, // MIME type of file to save - const PRUnichar* aFileCharset, - PRUint32 aSaveFlags, - PRUint32 aWrapColumn) -{ - NS_ENSURE_ARG_POINTER(aFile); - NS_ENSURE_ARG_POINTER(aFileType); - NS_ENSURE_ARG_POINTER(aFileCharset); - - nsresult rv = NS_OK; - - // if we're not replacing an existing file but the file - // exists, somethine is wrong - PRBool fileExists; - rv = aFile->Exists(&fileExists); - if (NS_FAILED(rv)) return rv; - - if (!aReplaceExisting && fileExists) - return NS_ERROR_FAILURE; // where are the file I/O errors? - - - nsCOMPtr outputStream(do_CreateInstance(NS_LOCALFILEOUTPUTSTREAM_CONTRACTID, &rv)); - if (NS_FAILED(rv)) return rv; - - rv = outputStream->Init(aFile, -1, -1); - if (NS_FAILED(rv)) return rv; - - // Get a document encoder instance - nsCAutoString contractID(NS_DOC_ENCODER_CONTRACTID_BASE); - contractID.AppendWithConversion(aFileType); - - nsCOMPtr encoder(do_CreateInstance(contractID.get(), &rv)); - if (NS_FAILED(rv)) - return rv; - - nsAutoString fileType(aFileType); // sucky copy - rv = encoder->Init(this, fileType, aSaveFlags); - if (NS_FAILED(rv)) - return rv; - - if (aSaveFlags & nsIDocumentEncoder::OutputWrap) - encoder->SetWrapColumn(aWrapColumn); - - nsAutoString charsetStr(aFileCharset); - if (charsetStr.Length() == 0) - { - rv = GetDocumentCharacterSet(charsetStr); - if(NS_FAILED(rv)) { - charsetStr.AssignWithConversion("ISO-8859-1"); - } - } - encoder->SetCharset(charsetStr); - - rv = encoder->EncodeToStream(outputStream); - - if (NS_SUCCEEDED(rv)) - { - // if everything went OK and we're not just saving off a copy, - // store the new fileSpec in the doc - if (!aSaveCopy) - { - // we clone the nsIFile here, rather than just holding onto a ref, - // in case the caller does something to aFile later - rv = aFile->Clone(getter_AddRefs(mFileSpec)); - - if (NS_SUCCEEDED(rv)) - { - // and mark the document as clean - ResetModificationCount(); - } - } - } - - return rv; -} - -NS_IMETHODIMP -nsDocument::GetFileSpec(nsIFile * *aFileSpec) -{ - NS_ENSURE_ARG_POINTER(aFileSpec); - - if (!mFileSpec) - return NS_ERROR_NOT_INITIALIZED; - - NS_IF_ADDREF(*aFileSpec = mFileSpec); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::FlushPendingNotifications(PRBool aFlushReflows) -{ - if (aFlushReflows) { - - PRInt32 i, count = mPresShells.Count(); - - for (i = 0; i < count; i++) { - nsIPresShell* shell = NS_STATIC_CAST(nsIPresShell*, mPresShells[i]); - if (shell) { - shell->FlushPendingNotifications(); - } - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetAndIncrementContentID(PRInt32* aID) -{ - *aID = mNextContentID++; - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::GetBindingManager(nsIBindingManager** aResult) -{ - *aResult = mBindingManager; - NS_IF_ADDREF(*aResult); - return NS_OK; -} - - -NS_IMETHODIMP -nsDocument::GetModificationCount(PRInt32 *outModCount) -{ - if (!outModCount) - return NS_ERROR_NULL_POINTER; - - *outModCount = mModCount; - return NS_OK; -} - - -NS_IMETHODIMP -nsDocument::ResetModificationCount() -{ - mModCount = 0; - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::IncrementModificationCount(PRInt32 aNumMods) -{ - mModCount += aNumMods; - //NS_ASSERTION(mModCount >= 0, "Modification count went negative"); - return NS_OK; -} - - -NS_IMETHODIMP -nsDocument::GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) -{ - NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_NOT_INITIALIZED); - - aNodeInfoManager = mNodeInfoManager; - NS_ADDREF(aNodeInfoManager); - - return NS_OK; -} - - -// -// FindContent does a depth-first search from aStartNode -// and returns the first of aTest1 or aTest2 which it finds. -// I think. -// -nsIContent* nsDocument::FindContent(const nsIContent* aStartNode, - const nsIContent* aTest1, - const nsIContent* aTest2) const -{ - PRInt32 count; - aStartNode->ChildCount(count); - PRInt32 index; - - for(index = 0; index < count;index++) - { - nsIContent* child; - aStartNode->ChildAt(index, child); - nsIContent* content = FindContent(child,aTest1,aTest2); - if (content != nsnull) { - NS_IF_RELEASE(child); - return content; - } - if (child == aTest1 || child == aTest2) { - NS_IF_RELEASE(content); - return child; - } - NS_IF_RELEASE(child); - NS_IF_RELEASE(content); - } - return nsnull; -} - - -NS_IMETHODIMP -nsDocument::GetDTD(nsIDTD** aDTD) const -{ - if (!aDTD) - return NS_ERROR_INVALID_ARG; - if (!mDTD) - { - nsCOMPtr doctype; - // Wish for mutable: - nsresult rv = NS_CONST_CAST(nsDocument* , this)->GetDoctype(getter_AddRefs(doctype)); - if (NS_FAILED(rv)) return rv; - if (!doctype) return NS_ERROR_FAILURE; - nsAutoString doctypename; - rv = doctype->GetName(doctypename); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr parser( do_CreateInstance(kCParserCID, &rv) ); - if (NS_FAILED(rv)) return rv; - if (!parser) return NS_ERROR_FAILURE; - - nsIDTD* dtd = 0; - rv = parser->CreateCompatibleDTD(&dtd, &doctypename, eViewNormal, - 0, eDTDMode_unknown); - if (NS_FAILED(rv)) return rv; - if (!dtd) return NS_ERROR_FAILURE; - - // Wish again for mutable: - NS_CONST_CAST(nsDocument* , this)->mDTD = dtd; - } - - NS_ADDREF(mDTD); - *aDTD = mDTD; - return NS_OK; -} - - diff --git a/layout/base/src/nsDocument.h b/layout/base/src/nsDocument.h deleted file mode 100644 index 978bd3fdce6f..000000000000 --- a/layout/base/src/nsDocument.h +++ /dev/null @@ -1,490 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsDocument_h___ -#define nsDocument_h___ - -#include "nsIDocument.h" -#include "nsWeakReference.h" -#include "nsWeakPtr.h" -#include "nsVoidArray.h" -#include "nsIDOMDocument.h" -#include "nsIDOMDocumentView.h" -#include "nsIDOMDocumentXBL.h" -#include "nsIDOMNSDocument.h" -#include "nsIDOMDocumentStyle.h" -#include "nsIDOMEventReceiver.h" -#include "nsIDiskDocument.h" -#include "nsIScriptObjectOwner.h" -#include "nsIScriptGlobalObject.h" -#include "nsIDOMEventTarget.h" -#include "nsIJSScriptObject.h" -#include "nsIContent.h" -#include "nsGenericDOMNodeList.h" -#include "nsIPrincipal.h" -#include "nsIBindingManager.h" -#include "nsINodeInfo.h" -#include "nsIDOMDocumentEvent.h" -#include "nsISupportsArray.h" -#include "nsHashtable.h" -#include "nsIWordBreakerFactory.h" -#include "nsILineBreakerFactory.h" - -class nsIEventListenerManager; -class nsDOMStyleSheetList; -class nsIOutputStream; -class nsDocument; -class nsIDTD; - -#if 0 -class nsPostData : public nsIPostData { -public: - nsPostData(PRBool aIsFile, char* aData); - - NS_DECL_ISUPPORTS - - virtual PRBool IsFile(); - virtual const char* GetData(); - virtual PRInt32 GetDataLength(); - -protected: - virtual ~nsPostData(); - - PRBool mIsFile; - char* mData; - PRInt32 mDataLen; -}; -#endif - -class nsDocHeaderData -{ -public: - nsDocHeaderData(nsIAtom* aField, const nsAReadableString& aData) - { - mField = aField; - NS_IF_ADDREF(mField); - mData.Assign(aData); - mNext = nsnull; - } - ~nsDocHeaderData(void) - { - NS_IF_RELEASE(mField); - if (nsnull != mNext) { - delete mNext; - mNext = nsnull; - } - } - - nsIAtom* mField; - nsString mData; - nsDocHeaderData* mNext; -}; - -// Represents the children of a document (prolog, epilog and -// document element) -class nsDocumentChildNodes : public nsGenericDOMNodeList -{ -public: - nsDocumentChildNodes(nsIDocument* aDocument); - ~nsDocumentChildNodes(); - - NS_IMETHOD GetLength(PRUint32* aLength); - NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn); - - void DropReference(); - -protected: - nsIDocument* mDocument; -}; - -// Base class for our document implementations -class nsDocument : public nsIDocument, - public nsIDOMDocument, - public nsIDOMNSDocument, - public nsIDOMDocumentEvent, - public nsIDOMDocumentStyle, - public nsIDOMDocumentView, - public nsIDOMDocumentXBL, - public nsIDiskDocument, - public nsIJSScriptObject, - public nsSupportsWeakReference, - public nsIDOMEventReceiver, - public nsIScriptObjectPrincipal -{ -public: - NS_DECL_ISUPPORTS - - virtual nsIArena* GetArena(); - - NS_IMETHOD StartDocumentLoad(const char* aCommand, - nsIChannel* aChannel, - nsILoadGroup* aLoadGroup, - nsISupports* aContainer, - nsIStreamListener **aDocListener, - PRBool aReset = PR_TRUE); - - NS_IMETHOD StopDocumentLoad(); - - /** - * Return the title of the document. May return null. - */ - virtual const nsString* GetDocumentTitle() const; - - /** - * Return the URL for the document. May return null. - */ - virtual nsIURI* GetDocumentURL() const; - - /** - * Return the principal responsible for this document. - */ - NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal); - - /** - * Update principal responsible for this document to the intersection - * of its previous value and aPrincipal, and return its new value. - */ - NS_IMETHOD AddPrincipal(nsIPrincipal *aPrincipal); - - /** - * Return the content (mime) type of this document. - */ - NS_IMETHOD GetContentType(nsAWritableString& aContentType) const; - - /** - * Return the LoadGroup for the document. May return null. - */ - NS_IMETHOD GetDocumentLoadGroup(nsILoadGroup **aGroup) const; - - /** - * Return the base URL for realtive URLs in the document. May return null (or the document URL). - */ - NS_IMETHOD GetBaseURL(nsIURI*& aURL) const; - - /** - * Return a standard name for the document's character set. This will - * trigger a startDocumentLoad if necessary to answer the question. - */ - NS_IMETHOD GetDocumentCharacterSet(nsAWritableString& oCharsetID); - NS_IMETHOD SetDocumentCharacterSet(const nsAReadableString& aCharSetID); - - /** - * Add an observer that gets notified whenever the charset changes. - */ - NS_IMETHOD AddCharSetObserver(nsIObserver* aObserver); - - /** - * Remove a charset observer. - */ - NS_IMETHOD RemoveCharSetObserver(nsIObserver* aObserver); - - /** - * Return the Line Breaker for the document - */ - NS_IMETHOD GetLineBreaker(nsILineBreaker** aResult) ; - NS_IMETHOD SetLineBreaker(nsILineBreaker* aLineBreaker) ; - NS_IMETHOD GetWordBreaker(nsIWordBreaker** aResult) ; - NS_IMETHOD SetWordBreaker(nsIWordBreaker* aWordBreaker) ; - - /** - * Access HTTP header data (this may also get set from other sources, like - * HTML META tags). - */ - NS_IMETHOD GetHeaderData(nsIAtom* aHeaderField, nsAWritableString& aData) const; - NS_IMETHOD SetHeaderData(nsIAtom* aheaderField, const nsAReadableString& aData); - - /** - * Create a new presentation shell that will use aContext for - * it's presentation context (presentation context's must not be - * shared among multiple presentation shell's). - */ -#if 0 - // XXX Temp hack: moved to nsMarkupDocument - NS_IMETHOD CreateShell(nsIPresContext* aContext, - nsIViewManager* aViewManager, - nsIStyleSet* aStyleSet, - nsIPresShell** aInstancePtrResult); -#endif - virtual PRBool DeleteShell(nsIPresShell* aShell); - virtual PRInt32 GetNumberOfShells(); - virtual nsIPresShell* GetShellAt(PRInt32 aIndex); - - /** - * Return the parent document of this document. Will return null - * unless this document is within a compound document and has a parent. - */ - virtual nsIDocument* GetParentDocument(); - virtual void SetParentDocument(nsIDocument* aParent); - virtual void AddSubDocument(nsIDocument* aSubDoc); - virtual PRInt32 GetNumberOfSubDocuments(); - virtual nsIDocument* GetSubDocumentAt(PRInt32 aIndex); - - /** - * Return the root content object for this document. - */ - virtual nsIContent* GetRootContent(); - virtual void SetRootContent(nsIContent* aRoot); - - /** - * Get the direct children of the document - content in - * the prolog, the root content and content in the epilog. - */ - NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const; - NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const; - NS_IMETHOD GetChildCount(PRInt32& aCount); - - /** - * Get the style sheets owned by this document. - * These are ordered, highest priority last - */ - virtual PRInt32 GetNumberOfStyleSheets(); - virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex); - virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet); - virtual void AddStyleSheet(nsIStyleSheet* aSheet); - virtual void RemoveStyleSheet(nsIStyleSheet* aSheet); - - NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets); - virtual void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet); - virtual void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet); - - NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify); - virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet, - PRBool mDisabled); - - /** - * Set the object from which a document can get a script context. - * This is the context within which all scripts (during document - * creation and during event handling) will run. - */ - NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject** aGlobalObject); - NS_IMETHOD SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject); - - /** - * Get the name space manager for this document - */ - NS_IMETHOD GetNameSpaceManager(nsINameSpaceManager*& aManager); - - /** - * Add a new observer of document change notifications. Whenever - * content is changed, appended, inserted or removed the observers are - * informed. - */ - virtual void AddObserver(nsIDocumentObserver* aObserver); - - /** - * Remove an observer of document change notifications. This will - * return false if the observer cannot be found. - */ - virtual PRBool RemoveObserver(nsIDocumentObserver* aObserver); - - // Observation hooks used by content nodes to propagate - // notifications to document observers. - NS_IMETHOD BeginUpdate(); - NS_IMETHOD EndUpdate(); - NS_IMETHOD BeginLoad(); - NS_IMETHOD EndLoad(); - NS_IMETHOD ContentChanged(nsIContent* aContent, - nsISupports* aSubContent); - NS_IMETHOD ContentStatesChanged(nsIContent* aContent1, nsIContent* aContent2); - NS_IMETHOD AttributeChanged(nsIContent* aChild, - PRInt32 aNameSpaceID, - nsIAtom* aAttribute, - PRInt32 aHint); - NS_IMETHOD ContentAppended(nsIContent* aContainer, - PRInt32 aNewIndexInContainer); - NS_IMETHOD ContentInserted(nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer); - NS_IMETHOD ContentReplaced(nsIContent* aContainer, - nsIContent* aOldChild, - nsIContent* aNewChild, - PRInt32 aIndexInContainer); - NS_IMETHOD ContentRemoved(nsIContent* aContainer, - nsIContent* aChild, - PRInt32 aIndexInContainer); - - NS_IMETHOD StyleRuleChanged(nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule, - PRInt32 aHint); // See nsStyleConsts fot hint values - NS_IMETHOD StyleRuleAdded(nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule); - NS_IMETHOD StyleRuleRemoved(nsIStyleSheet* aStyleSheet, - nsIStyleRule* aStyleRule); - - /** - * Finds text in content - */ - NS_IMETHOD FindNext(const nsAReadableString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound); - - NS_IMETHOD FlushPendingNotifications(PRBool aFlushReflows = PR_TRUE); - NS_IMETHOD GetAndIncrementContentID(PRInt32* aID); - NS_IMETHOD GetBindingManager(nsIBindingManager** aResult); - NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager); - -public: - - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - - // nsIDOMDocument interface - NS_IMETHOD GetDoctype(nsIDOMDocumentType** aDoctype); - NS_IMETHOD GetImplementation(nsIDOMDOMImplementation** aImplementation); - NS_IMETHOD GetDocumentElement(nsIDOMElement** aDocumentElement); - - NS_IMETHOD CreateElement(const nsAReadableString& aTagName, nsIDOMElement** aReturn); - NS_IMETHOD CreateDocumentFragment(nsIDOMDocumentFragment** aReturn); - NS_IMETHOD CreateTextNode(const nsAReadableString& aData, nsIDOMText** aReturn); - NS_IMETHOD CreateComment(const nsAReadableString& aData, nsIDOMComment** aReturn); - NS_IMETHOD CreateCDATASection(const nsAReadableString& aData, nsIDOMCDATASection** aReturn); - NS_IMETHOD CreateProcessingInstruction(const nsAReadableString& aTarget, const nsAReadableString& aData, nsIDOMProcessingInstruction** aReturn); - NS_IMETHOD CreateAttribute(const nsAReadableString& aName, nsIDOMAttr** aReturn); - NS_IMETHOD CreateEntityReference(const nsAReadableString& aName, nsIDOMEntityReference** aReturn); - NS_IMETHOD GetElementsByTagName(const nsAReadableString& aTagname, nsIDOMNodeList** aReturn); - NS_IMETHOD GetElementsByTagNameNS(const nsAReadableString& aNamespaceURI, const nsAReadableString& aLocalName, nsIDOMNodeList** aReturn); - NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetList** aStyleSheets); - NS_IMETHOD GetCharacterSet(nsAWritableString& aCharacterSet); - NS_IMETHOD ImportNode(nsIDOMNode* aImportedNode, - PRBool aDeep, - nsIDOMNode** aReturn); - NS_IMETHOD GetLocation(jsval* aLocation); - NS_IMETHOD SetLocation(jsval aLocation); - NS_IMETHOD CreateRange(nsIDOMRange** aReturn); - NS_IMETHOD Load (const nsAReadableString& aUrl); - NS_IMETHOD GetPlugins(nsIDOMPluginArray** aPlugins); - NS_IMETHOD GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult); - NS_IMETHOD SetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject* aBoxObject); - - // nsIDOMNode interface - NS_DECL_IDOMNODE - - // nsIDOMDocumentView - NS_DECL_IDOMDOCUMENTVIEW - - // nsIDOMDocumentXBL - NS_DECL_IDOMDOCUMENTXBL - - // nsIDOMDocumentEvent - NS_DECL_IDOMDOCUMENTEVENT - - // nsIDOMEventReceiver interface - NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); - NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID); - NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult); - NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult); - NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent); - - // nsIDiskDocument inteface - NS_DECL_NSIDISKDOCUMENT - - // nsIDOMEventTarget interface - NS_IMETHOD AddEventListener(const nsAReadableString& aType, nsIDOMEventListener* aListener, - PRBool aUseCapture); - NS_IMETHOD RemoveEventListener(const nsAReadableString& aType, nsIDOMEventListener* aListener, - PRBool aUseCapture); - NS_IMETHOD DispatchEvent(nsIDOMEvent* aEvent); - - - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus); - - - // nsIJSScriptObject interface - virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool DeleteProperty(JSContext *aContext, - JSObject *aObj, jsval aID, jsval *aVp); - virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool EnumerateProperty(JSContext *aContext, JSObject *aObj); - virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty); - virtual PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID); - virtual void Finalize(JSContext *aContext, JSObject *aObj); - - virtual nsresult Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup); - virtual nsresult SetDocumentURL(nsIURI* aURI); - -protected: - nsIContent* FindContent(const nsIContent* aStartNode, - const nsIContent* aTest1, - const nsIContent* aTest2) const; - NS_IMETHOD GetDTD(nsIDTD** aDTD) const; - -protected: - - virtual void InternalAddStyleSheet(nsIStyleSheet* aSheet); // subclass hooks for sheet ordering - virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex); - - nsDocument(); - virtual ~nsDocument(); - nsresult Init(); - - nsIArena* mArena; - nsString* mDocumentTitle; - nsIURI* mDocumentURL; - nsIPrincipal* mPrincipal; - nsWeakPtr mDocumentLoadGroup; - nsString mCharacterSet; - nsVoidArray mCharSetObservers; - nsIDocument* mParentDocument; - nsVoidArray mSubDocuments; - nsVoidArray mPresShells; - nsCOMPtr mChildren; // contains owning references - nsIContent* mRootContent; // a weak reference to the only element in - // mChildren, or null if no such element exists. - nsVoidArray mStyleSheets; - nsVoidArray mObservers; - void* mScriptObject; - nsCOMPtr mScriptGlobalObject; - nsIEventListenerManager* mListenerManager; - PRBool mInDestructor; - nsDOMStyleSheetList *mDOMStyleSheets; - nsINameSpaceManager* mNameSpaceManager; - nsDocHeaderData* mHeaderData; - nsCOMPtr mLineBreaker; - nsCOMPtr mWordBreaker; - nsDocumentChildNodes* mChildNodes; - // A content ID counter used to give a monotonically increasing ID to the content - // objects in the document's content model - PRInt32 mNextContentID; - - // disk file members - nsCOMPtr mFileSpec; - PRInt32 mModCount; - - nsIDTD* mDTD; - - nsCOMPtr mBindingManager; - nsCOMPtr mNodeInfoManager; // OWNER - nsSupportsHashtable* mBoxObjectTable; - -private: - // These are not implemented and not supported. - nsDocument(const nsDocument& aOther); - nsDocument& operator=(const nsDocument& aOther); -}; - -#endif /* nsDocument_h___ */ diff --git a/layout/base/src/nsDocumentEncoder.cpp b/layout/base/src/nsDocumentEncoder.cpp deleted file mode 100644 index 5f18a6b3750f..000000000000 --- a/layout/base/src/nsDocumentEncoder.cpp +++ /dev/null @@ -1,1672 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Pierre Phaneuf - */ - -#include "nsIDocumentEncoder.h" - -#include "nscore.h" -#include "nsIFactory.h" -#include "nsISupports.h" -#include "nsIComponentManager.h" -#include "nsIServiceManager.h" -#include "nsIDocument.h" -#include "nsIHTMLDocument.h" -#include "nsISelection.h" -#include "nsCOMPtr.h" -#include "nsIContentSerializer.h" -#include "nsIUnicodeEncoder.h" -#include "nsIOutputStream.h" -#include "nsIDOMElement.h" -#include "nsIDOMText.h" -#include "nsIDOMCDATASection.h" -#include "nsIDOMComment.h" -#include "nsIDOMProcessingInstruction.h" -#include "nsIDOMDocumentType.h" -#include "nsIDOMNodeList.h" -#include "nsIDOMRange.h" -#include "nsRange.h" -#include "nsICharsetConverterManager.h" -#include "nsICharsetConverterManager2.h" -#include "nsHTMLAtoms.h" -#include "nsITextContent.h" -#include "nsIEnumerator.h" -#include "nsISelectionPrivate.h" -#include "nsIFrameSelection.h" -#include "nsIContentIterator.h" -#include "nsISupportsArray.h" -#include "nsIParserService.h" -#include "nsParserCIID.h" - -static NS_DEFINE_CID(kCharsetConverterManagerCID, - NS_ICHARSETCONVERTERMANAGER_CID); -static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID); - -nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aInstancePtrResult); -nsresult NS_NewDomSelection(nsISelection **aDomSelection); - -enum nsRangeIterationDirection { - kDirectionOut = -1, - kDirectionIn = 1 -}; - -#ifdef XP_MAC -#pragma mark - -#pragma mark nsDocumentEncoder declaration -#pragma mark - -#endif - -class nsDocumentEncoder : public nsIDocumentEncoder -{ -public: - static const nsIID& GetIID() { static nsIID iid = NS_IDOCUMENT_ENCODER_IID; return iid; } - - nsDocumentEncoder(); - virtual ~nsDocumentEncoder(); - - NS_IMETHOD Init(nsIDocument* aDocument, const nsAReadableString& aMimeType, PRUint32 aFlags); - - /* Interfaces for addref and release and queryinterface */ - NS_DECL_ISUPPORTS - - // Inherited methods from nsIDocumentEncoder - NS_IMETHOD SetSelection(nsISelection* aSelection); - NS_IMETHOD SetRange(nsIDOMRange* aRange); - NS_IMETHOD SetWrapColumn(PRUint32 aWC); - NS_IMETHOD SetCharset(const nsAReadableString& aCharset); - NS_IMETHOD GetMimeType(nsAWritableString& aMimeType); - NS_IMETHOD EncodeToStream(nsIOutputStream* aStream); - NS_IMETHOD EncodeToString(nsAWritableString& aOutputString); - NS_IMETHOD EncodeToStringWithContext(nsAWritableString& aEncodedString, - nsAWritableString& aContextString, - nsAWritableString& aInfoString); - NS_IMETHOD SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup); - -protected: - nsresult SerializeNodeStart(nsIDOMNode* aNode, PRInt32 aStartOffset, - PRInt32 aEndOffset, nsAWritableString& aStr); - nsresult SerializeToStringRecursive(nsIDOMNode* aNode, - nsAWritableString& aStr); - nsresult SerializeNodeEnd(nsIDOMNode* aNode, nsAWritableString& aStr); - nsresult SerializeRangeToString(nsIDOMRange *aRange, - nsAWritableString& aOutputString); - nsresult SerializeRangeNodes(nsIDOMRange* aRange, - nsIDOMNode* aNode, - nsAWritableString& aString, - PRInt32 aDepth); - nsresult SerializeRangeContextStart(const nsVoidArray& aAncestorArray, - nsAWritableString& aString); - nsresult SerializeRangeContextEnd(const nsVoidArray& aAncestorArray, - nsAWritableString& aString); - - nsresult FlushText(nsAWritableString& aString, PRBool aForce); - - static PRBool IsTag(nsIDOMNode* aNode, nsIAtom* aAtom); - static nsresult AdjustCommonParent(nsCOMPtr *aCommPar); - - virtual PRBool IncludeInContext(nsIDOMNode *aNode); - - nsCOMPtr mDocument; - nsCOMPtr mSelection; - nsCOMPtr mRange; - nsCOMPtr mStream; - nsCOMPtr mSerializer; - nsCOMPtr mUnicodeEncoder; - nsCOMPtr mCommonParent; - nsCOMPtr mNodeFixup; - nsCOMPtr mCharsetConverterManager; - - nsString mMimeType; - nsString mCharset; - PRUint32 mFlags; - PRUint32 mWrapColumn; - PRUint32 mStartDepth; - PRUint32 mEndDepth; - PRInt32 mStartRootIndex; - PRInt32 mEndRootIndex; - PRBool mHaltRangeHint; - nsVoidArray mCommonAncestors; - nsVoidArray mStartNodes; - nsVoidArray mStartOffsets; - nsVoidArray mEndNodes; - nsVoidArray mEndOffsets; -}; - -#ifdef XP_MAC -#pragma mark nsDocumentEncoder implementation -#pragma mark - -#endif - -NS_IMPL_ADDREF(nsDocumentEncoder) -NS_IMPL_RELEASE(nsDocumentEncoder) - -NS_INTERFACE_MAP_BEGIN(nsDocumentEncoder) - NS_INTERFACE_MAP_ENTRY(nsIDocumentEncoder) - NS_INTERFACE_MAP_ENTRY(nsISupports) -NS_INTERFACE_MAP_END - -nsDocumentEncoder::nsDocumentEncoder() -{ - NS_INIT_REFCNT(); - - mMimeType.AssignWithConversion("text/plain"); - - mFlags = 0; - mWrapColumn = 72; - mStartDepth = 0; - mEndDepth = 0; - mHaltRangeHint = PR_FALSE; -} - -nsDocumentEncoder::~nsDocumentEncoder() -{ -} - -NS_IMETHODIMP -nsDocumentEncoder::Init(nsIDocument* aDocument, - const nsAReadableString& aMimeType, - PRUint32 aFlags) -{ - if (!aDocument) - return NS_ERROR_INVALID_ARG; - - mDocument = aDocument; - - mMimeType = aMimeType; - - mFlags = aFlags; - - return NS_OK; -} - -NS_IMETHODIMP -nsDocumentEncoder::SetWrapColumn(PRUint32 aWC) -{ - mWrapColumn = aWC; - return NS_OK; -} - -NS_IMETHODIMP -nsDocumentEncoder::SetSelection(nsISelection* aSelection) -{ - mSelection = aSelection; - return NS_OK; -} - -NS_IMETHODIMP -nsDocumentEncoder::SetRange(nsIDOMRange* aRange) -{ - mRange = aRange; - return NS_OK; -} - -NS_IMETHODIMP -nsDocumentEncoder::SetCharset(const nsAReadableString& aCharset) -{ - mCharset = aCharset; - return NS_OK; -} - -NS_IMETHODIMP -nsDocumentEncoder::GetMimeType(nsAWritableString& aMimeType) -{ - aMimeType = mMimeType; - return NS_OK; -} - - -PRBool -nsDocumentEncoder::IncludeInContext(nsIDOMNode *aNode) -{ - return PR_FALSE; -} - -nsresult -nsDocumentEncoder::SerializeNodeStart(nsIDOMNode* aNode, PRInt32 aStartOffset, - PRInt32 aEndOffset, - nsAWritableString& aStr) -{ - PRUint16 type; - - nsCOMPtr node; - if (mNodeFixup) - { - mNodeFixup->FixupNode(aNode, getter_AddRefs(node)); - } - if (!node) - { - node = do_QueryInterface(aNode); - } - - node->GetNodeType(&type); - switch (type) { - case nsIDOMNode::ELEMENT_NODE: - { - nsCOMPtr element = do_QueryInterface(node); - mSerializer->AppendElementStart(element, aStr); - break; - } - case nsIDOMNode::TEXT_NODE: - { - nsCOMPtr text = do_QueryInterface(node); - mSerializer->AppendText(text, aStartOffset, aEndOffset, aStr); - break; - } - case nsIDOMNode::CDATA_SECTION_NODE: - { - nsCOMPtr cdata = do_QueryInterface(node); - mSerializer->AppendCDATASection(cdata, aStartOffset, aEndOffset, aStr); - break; - } - case nsIDOMNode::PROCESSING_INSTRUCTION_NODE: - { - nsCOMPtr pi = do_QueryInterface(node); - mSerializer->AppendProcessingInstruction(pi, aStartOffset, aEndOffset, - aStr); - break; - } - case nsIDOMNode::COMMENT_NODE: - { - nsCOMPtr comment = do_QueryInterface(node); - mSerializer->AppendComment(comment, aStartOffset, aEndOffset, aStr); - break; - } - case nsIDOMNode::DOCUMENT_TYPE_NODE: - { - nsCOMPtr doctype = do_QueryInterface(node); - mSerializer->AppendDoctype(doctype, aStr); - break; - } - } - - return NS_OK; -} - -nsresult -nsDocumentEncoder::SerializeNodeEnd(nsIDOMNode* aNode, - nsAWritableString& aStr) -{ - PRUint16 type; - - aNode->GetNodeType(&type); - switch (type) { - case nsIDOMNode::ELEMENT_NODE: - { - nsCOMPtr element = do_QueryInterface(aNode); - mSerializer->AppendElementEnd(element, aStr); - break; - } - } - - return NS_OK; -} - -nsresult -nsDocumentEncoder::SerializeToStringRecursive(nsIDOMNode* aNode, - nsAWritableString& aStr) -{ - nsresult rv = SerializeNodeStart(aNode, 0, -1, aStr); - NS_ENSURE_SUCCESS(rv, rv); - - PRBool hasChildren = PR_FALSE; - - aNode->HasChildNodes(&hasChildren); - - if (hasChildren) { - nsCOMPtr childNodes; - rv = aNode->GetChildNodes(getter_AddRefs(childNodes)); - NS_ENSURE_TRUE(childNodes, NS_SUCCEEDED(rv) ? NS_ERROR_FAILURE : rv); - - PRInt32 index, count; - - childNodes->GetLength((PRUint32*)&count); - for (index = 0; index < count; index++) { - nsCOMPtr child; - - rv = childNodes->Item(index, getter_AddRefs(child)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = SerializeToStringRecursive(child, aStr); - NS_ENSURE_SUCCESS(rv, rv); - } - } - - rv = SerializeNodeEnd(aNode, aStr); - NS_ENSURE_SUCCESS(rv, rv); - - return FlushText(aStr, PR_FALSE); -} - -PRBool -nsDocumentEncoder::IsTag(nsIDOMNode* aNode, nsIAtom* aAtom) -{ - if (aNode) - { - nsCOMPtr atom; - nsCOMPtr content = do_QueryInterface(aNode); - if (content) - content->GetTag(*getter_AddRefs(atom)); - if (atom) - { - if (atom.get() == aAtom) - { - return PR_TRUE; - } - } - } - return PR_FALSE; -} - -nsresult -nsDocumentEncoder::AdjustCommonParent(nsCOMPtr *aCommPar) -{ - // if common parent is a table section other than - // td or th, look for the parent of the enclosing - // table and use that instead. - if (IsTag(*aCommPar, nsHTMLAtoms::tr) || - IsTag(*aCommPar, nsHTMLAtoms::tbody) || - IsTag(*aCommPar, nsHTMLAtoms::tfoot) || - IsTag(*aCommPar, nsHTMLAtoms::thead) || - IsTag(*aCommPar, nsHTMLAtoms::table)) - { - nsCOMPtr parent, tmp=*aCommPar; - while (tmp) - { - if (IsTag(parent, nsHTMLAtoms::table)) - { - // return parent of table - parent->GetParentNode(getter_AddRefs(tmp)); - *aCommPar = tmp; - break; - } - tmp->GetParentNode(getter_AddRefs(parent)); - tmp = parent; - } - } - return NS_OK; -} - -static nsresult -ConvertAndWrite(nsAReadableString& aString, - nsIOutputStream* aStream, - nsIUnicodeEncoder* aEncoder) -{ - NS_ENSURE_ARG_POINTER(aStream); - NS_ENSURE_ARG_POINTER(aEncoder); - nsresult rv; - PRInt32 charLength, startCharLength; - const PRUnichar* unicodeBuf = (const PRUnichar*)nsPromiseFlatString(aString); - PRInt32 unicodeLength = aString.Length(); - PRInt32 startLength = unicodeLength; - - rv = aEncoder->GetMaxLength(unicodeBuf, unicodeLength, &charLength); - startCharLength = charLength; - NS_ENSURE_SUCCESS(rv, rv); - - nsCAutoString charXferString; - charXferString.SetCapacity(charLength); - char* charXferBuf = (char*)charXferString.GetBuffer(); - nsresult convert_rv = NS_OK; - - do { - unicodeLength = startLength; - charLength = startCharLength; - - convert_rv = aEncoder->Convert(unicodeBuf, &unicodeLength, charXferBuf, &charLength); - NS_ENSURE_SUCCESS(convert_rv, convert_rv); - - PRUint32 written; - rv = aStream->Write(charXferBuf, charLength, &written); - NS_ENSURE_SUCCESS(rv, rv); - - // If the converter couldn't convert a chraacer we replace the - // character with a characre entity. - if (convert_rv == NS_ERROR_UENC_NOMAPPING) { - // Finishes the conversion. - // The converter has the possibility to write some extra data and flush its final state. - char finish_buf[32]; - charLength = 32; - rv = aEncoder->Finish(finish_buf, &charLength); - NS_ENSURE_SUCCESS(rv, rv); - rv = aStream->Write(finish_buf, charLength, &written); - NS_ENSURE_SUCCESS(rv, rv); - - nsCAutoString entString("&#"); - entString.AppendInt(unicodeBuf[unicodeLength - 1]); - entString.Append(';'); - - rv = aStream->Write(entString.GetBuffer(), entString.Length(), &written); - NS_ENSURE_SUCCESS(rv, rv); - - unicodeBuf += unicodeLength; - startLength -= unicodeLength; - } - } while (convert_rv == NS_ERROR_UENC_NOMAPPING); - - return rv; -} - -nsresult -nsDocumentEncoder::FlushText(nsAWritableString& aString, PRBool aForce) -{ - if (!mStream) - return NS_OK; - - nsresult rv = NS_OK; - - if (aString.Length() > 1024 || aForce) { - rv = ConvertAndWrite(aString, mStream, mUnicodeEncoder); - - aString.Truncate(); - } - - return rv; -} - -#if 0 // This code is really fast at serializing a range, but unfortunately - // there are problems with it so we don't use it now, maybe later... -static nsresult ChildAt(nsIDOMNode* aNode, PRInt32 aIndex, nsIDOMNode*& aChild) -{ - nsCOMPtr node(do_QueryInterface(aNode)); - nsCOMPtr child; - - aChild = nsnull; - - NS_ENSURE_TRUE(node, NS_ERROR_FAILURE); - - node->ChildAt(aIndex, *getter_AddRefs(child)); - - if (child) - child->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)&aChild); - - return NS_OK; -} - -static PRInt32 IndexOf(nsIDOMNode* aParent, nsIDOMNode* aChild) -{ - nsCOMPtr parent(do_QueryInterface(aParent)); - nsCOMPtr child(do_QueryInterface(aChild)); - - if (!parent || !child) - return -1; - - PRInt32 indx = 0; - - parent->IndexOf(child, indx); - - return indx; -} - -static inline PRInt32 GetIndex(nsVoidArray& aIndexArray) -{ - PRInt32 count = aIndexArray.Count(); - - if (count) { - return (PRInt32)aIndexArray.ElementAt(count - 1); - } - - return 0; -} - -static nsresult GetNextNode(nsIDOMNode* aNode, nsVoidArray& aIndexArray, - nsIDOMNode*& aNextNode, - nsRangeIterationDirection& aDirection) -{ - PRBool hasChildren; - - aNextNode = nsnull; - - aNode->HasChildNodes(&hasChildren); - - if (hasChildren && aDirection == kDirectionIn) { - ChildAt(aNode, 0, aNextNode); - NS_ENSURE_TRUE(aNextNode, NS_ERROR_FAILURE); - - aIndexArray.AppendElement((void *)0); - - aDirection = kDirectionIn; - } else if (aDirection == kDirectionIn) { - aNextNode = aNode; - - NS_ADDREF(aNextNode); - - aDirection = kDirectionOut; - } else { - nsCOMPtr parent; - - aNode->GetParentNode(getter_AddRefs(parent)); - NS_ENSURE_TRUE(parent, NS_ERROR_FAILURE); - - PRInt32 count = aIndexArray.Count(); - - if (count) { - PRInt32 indx = (PRInt32)aIndexArray.ElementAt(count - 1); - - ChildAt(parent, indx + 1, aNextNode); - - if (aNextNode) - aIndexArray.ReplaceElementAt((void *)(indx + 1), count - 1); - else - aIndexArray.RemoveElementAt(count - 1); - } else { - PRInt32 indx = IndexOf(parent, aNode); - - if (indx >= 0) { - ChildAt(parent, indx + 1, aNextNode); - - if (aNextNode) - aIndexArray.AppendElement((void *)(indx + 1)); - } - } - - if (aNextNode) { - aDirection = kDirectionIn; - } else { - aDirection = kDirectionOut; - - aNextNode = parent; - - NS_ADDREF(aNextNode); - } - } - - return NS_OK; -} -#endif - -static PRBool IsTextNode(nsIDOMNode *aNode) -{ - if (!aNode) return PR_FALSE; - PRUint16 nodeType; - aNode->GetNodeType(&nodeType); - if (nodeType == nsIDOMNode::TEXT_NODE) - return PR_TRUE; - return PR_FALSE; -} - -static nsresult GetLengthOfDOMNode(nsIDOMNode *aNode, PRUint32 &aCount) -{ - aCount = 0; - if (!aNode) { return NS_ERROR_NULL_POINTER; } - nsresult result=NS_OK; - nsCOMPtrnodeAsChar; - nodeAsChar = do_QueryInterface(aNode); - if (nodeAsChar) { - nodeAsChar->GetLength(&aCount); - } - else - { - PRBool hasChildNodes; - aNode->HasChildNodes(&hasChildNodes); - if (PR_TRUE==hasChildNodes) - { - nsCOMPtrnodeList; - result = aNode->GetChildNodes(getter_AddRefs(nodeList)); - if (NS_SUCCEEDED(result) && nodeList) { - nodeList->GetLength(&aCount); - } - } - } - return result; -} - -nsresult -nsDocumentEncoder::SerializeRangeNodes(nsIDOMRange* aRange, - nsIDOMNode* aNode, - nsAWritableString& aString, - PRInt32 aDepth) -{ - nsCOMPtr content = do_QueryInterface(aNode); - NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); - - nsresult rv=NS_OK; - - // get start and end nodes for this recursion level - nsCOMPtr startNode, endNode; - startNode = NS_STATIC_CAST(nsIContent *, mStartNodes[mStartRootIndex - aDepth]); - endNode = NS_STATIC_CAST(nsIContent *, mEndNodes[mEndRootIndex - aDepth]); - - if ((startNode != content) && (endNode != content)) - { - // node is completely contained in range. Serialize the whole subtree - // rooted by this node. - rv = SerializeToStringRecursive(aNode, aString); - NS_ENSURE_SUCCESS(rv, rv); - } - else - { - // due to implementation it is impossible for text node to be both start and end of - // range. We would have handled that case without getting here. - if (IsTextNode(aNode)) - { - if (startNode == content) - { - PRInt32 startOffset; - aRange->GetStartOffset(&startOffset); - rv = SerializeNodeStart(aNode, startOffset, -1, aString); - NS_ENSURE_SUCCESS(rv, rv); - } - else - { - PRInt32 endOffset; - aRange->GetEndOffset(&endOffset); - rv = SerializeNodeStart(aNode, 0, endOffset, aString); - NS_ENSURE_SUCCESS(rv, rv); - } - } - else - { - if (aNode != mCommonParent.get()) - { - if (IncludeInContext(aNode)) - { - // halt the incrementing of mStartDepth/mEndDepth. This is - // so paste client will include this node in paste. - mHaltRangeHint = PR_TRUE; - } - if ((startNode == content) && !mHaltRangeHint) mStartDepth++; - if ((endNode == content) && !mHaltRangeHint) mEndDepth++; - - // serialize the start of this node - rv = SerializeNodeStart(aNode, 0, -1, aString); - NS_ENSURE_SUCCESS(rv, rv); - } - - // do some calculations that will tell us which children of this node are in the range. - nsCOMPtr child; - nsCOMPtr childAsNode; - PRInt32 startOffset = 0, endOffset = -1; - if (startNode == content) - startOffset = NS_REINTERPRET_CAST(PRInt32, mStartOffsets[mStartRootIndex - aDepth]); - if (endNode == content) - endOffset = NS_REINTERPRET_CAST(PRInt32, mEndOffsets[mEndRootIndex - aDepth]); - // generated content will cause offset values of -1 to be returned. - PRInt32 j, childCount=0; - rv = content->ChildCount(childCount); - NS_ENSURE_SUCCESS(rv, rv); - if (startOffset == -1) startOffset = 0; - if (endOffset == -1) endOffset = childCount; - else - { - // if we are at the "tip" of the selection, endOffset is fine. - // otherwise, we need to add one. This is because of the semantics - // of the offset list created by GetAncestorsAndOffsets(). The - // intermediate points on the list use the endOffset of the - // location of the ancestor, rather than just past it. So we need - // to add one here in order to include it in the children we serialize. - nsCOMPtr endParent; - aRange->GetEndContainer(getter_AddRefs(endParent)); - if (aNode != endParent.get()) - { - endOffset++; - } - } - // serialize the children of this node that are in the range - for (j=startOffset; jChildAt(j, *getter_AddRefs(child)); - childAsNode = do_QueryInterface(child); - NS_ENSURE_SUCCESS(rv, rv); - if ((j==startOffset) || (j==endOffset-1)) - rv = SerializeRangeNodes(aRange, childAsNode, aString, aDepth+1); - else - rv = SerializeToStringRecursive(childAsNode, aString); - NS_ENSURE_SUCCESS(rv, rv); - } - - // serialize the end of this node - if (aNode != mCommonParent.get()) - { - rv = SerializeNodeEnd(aNode, aString); - NS_ENSURE_SUCCESS(rv, rv); - } - } - } - return NS_OK; -} - -nsresult -nsDocumentEncoder::SerializeRangeContextStart(const nsVoidArray& aAncestorArray, - nsAWritableString& aString) -{ - PRInt32 i = 0; - nsresult rv = NS_OK; - - while (1) { - nsIDOMNode *node = (nsIDOMNode *)aAncestorArray.ElementAt(i++); - - if (!node) - break; - - if (IncludeInContext(node)) { - rv = SerializeNodeStart(node, 0, -1, aString); - - if (NS_FAILED(rv)) - break; - } - } - - return rv; -} - -nsresult -nsDocumentEncoder::SerializeRangeContextEnd(const nsVoidArray& aAncestorArray, - nsAWritableString& aString) -{ - PRInt32 i = aAncestorArray.Count(); - nsresult rv = NS_OK; - - while (i) { - nsIDOMNode *node = (nsIDOMNode *)aAncestorArray.ElementAt(--i); - - if (!node) - break; - - if (IncludeInContext(node)) { - rv = SerializeNodeEnd(node, aString); - - if (NS_FAILED(rv)) - break; - } - } - - return rv; -} - -nsresult -nsDocumentEncoder::SerializeRangeToString(nsIDOMRange *aRange, - nsAWritableString& aOutputString) -{ - if (!aRange) - return NS_OK; - - PRBool collapsed; - - aRange->GetCollapsed(&collapsed); - - if (collapsed) - return NS_OK; - - nsCOMPtr startParent, endParent; - PRInt32 startOffset, endOffset; - - aRange->GetCommonAncestorContainer(getter_AddRefs(mCommonParent)); - - if (!mCommonParent) - return NS_OK; - - aRange->GetStartContainer(getter_AddRefs(startParent)); - NS_ENSURE_TRUE(startParent, NS_ERROR_FAILURE); - aRange->GetStartOffset(&startOffset); - - aRange->GetEndContainer(getter_AddRefs(endParent)); - NS_ENSURE_TRUE(endParent, NS_ERROR_FAILURE); - aRange->GetEndOffset(&endOffset); - - mCommonAncestors.Clear(); - mStartNodes.Clear(); - mStartOffsets.Clear(); - mEndNodes.Clear(); - mEndOffsets.Clear(); - - nsRange::FillArrayWithAncestors(&mCommonAncestors, mCommonParent); - nsRange::GetAncestorsAndOffsets(startParent, startOffset, &mStartNodes, &mStartOffsets); - nsRange::GetAncestorsAndOffsets(endParent, endOffset, &mEndNodes, &mEndOffsets); - nsCOMPtr commonContent = do_QueryInterface(mCommonParent); - mStartRootIndex = mStartNodes.IndexOf(commonContent); - mEndRootIndex = mEndNodes.IndexOf(commonContent); - - nsresult rv = NS_OK; - - rv = SerializeRangeContextStart(mCommonAncestors, aOutputString); - NS_ENSURE_SUCCESS(rv, rv); - - if ((startParent == endParent) && IsTextNode(startParent)) - { - rv = SerializeNodeStart(startParent, startOffset, endOffset, aOutputString); - NS_ENSURE_SUCCESS(rv, rv); - } - else - { - rv = SerializeRangeNodes(aRange, mCommonParent, aOutputString, 0); - NS_ENSURE_SUCCESS(rv, rv); - } - rv = SerializeRangeContextEnd(mCommonAncestors, aOutputString); - NS_ENSURE_SUCCESS(rv, rv); - - return rv; -} - -NS_IMETHODIMP -nsDocumentEncoder::EncodeToString(nsAWritableString& aOutputString) -{ - if (!mDocument) - return NS_ERROR_NOT_INITIALIZED; - - aOutputString.Truncate(); - - // xxx Also make sure mString is a mime type "text/html" or "text/plain" - - nsCAutoString progId(NS_CONTENTSERIALIZER_CONTRACTID_PREFIX); - progId.AppendWithConversion(mMimeType); - - mSerializer = do_CreateInstance(NS_STATIC_CAST(const char *, progId)); - NS_ENSURE_TRUE(mSerializer, NS_ERROR_NOT_IMPLEMENTED); - - nsresult rv = NS_OK; - - nsCOMPtr charsetAtom; - if (!mCharset.IsEmpty()) { - if (!mCharsetConverterManager) { - mCharsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - } - rv = mCharsetConverterManager->GetCharsetAtom(mCharset.GetUnicode(), getter_AddRefs(charsetAtom)); - NS_ENSURE_SUCCESS(rv, rv); - } - mSerializer->Init(mFlags, mWrapColumn, charsetAtom); - - if (mSelection) { - nsCOMPtr range; - PRInt32 i, count = 0; - - rv = mSelection->GetRangeCount(&count); - NS_ENSURE_SUCCESS(rv, rv); - - for (i = 0; i < count; i++) { - mSelection->GetRangeAt(i, getter_AddRefs(range)); - - rv = SerializeRangeToString(range, aOutputString); - NS_ENSURE_SUCCESS(rv, rv); - } - - mSelection = nsnull; - } else if (mRange) { - rv = SerializeRangeToString(mRange, aOutputString); - - mRange = nsnull; - } else { - nsCOMPtr doc(do_QueryInterface(mDocument)); - - rv = SerializeToStringRecursive(doc, aOutputString); - } - - NS_ENSURE_SUCCESS(rv, rv); - rv = mSerializer->Flush(aOutputString); - - return rv; -} - -NS_IMETHODIMP -nsDocumentEncoder::EncodeToStream(nsIOutputStream* aStream) -{ - nsresult rv = NS_OK; - - if (!mDocument) - return NS_ERROR_NOT_INITIALIZED; - - if (!mCharsetConverterManager) { - mCharsetConverterManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - } - - nsCOMPtr charsetAtom; - rv = mCharsetConverterManager->GetCharsetAtom(mCharset.GetUnicode(), getter_AddRefs(charsetAtom)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mCharsetConverterManager->GetUnicodeEncoder(charsetAtom, - getter_AddRefs(mUnicodeEncoder)); - NS_ENSURE_SUCCESS(rv, rv); - - // xxx Also make sure mString is a mime type "text/html" or "text/plain" - - mStream = aStream; - - nsAutoString buf; - - rv = EncodeToString(buf); - - // Force a flush of the last chunk of data. - FlushText(buf, PR_TRUE); - - mStream = nsnull; - mUnicodeEncoder = nsnull; - - return rv; -} - -NS_IMETHODIMP -nsDocumentEncoder::EncodeToStringWithContext(nsAWritableString& aEncodedString, - nsAWritableString& aContextString, - nsAWritableString& aInfoString) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsDocumentEncoder::SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup) -{ - mNodeFixup = aFixup; - return NS_OK; -} - - -nsresult NS_NewTextEncoder(nsIDocumentEncoder** aResult); // make mac compiler happy - -nsresult -NS_NewTextEncoder(nsIDocumentEncoder** aResult) -{ - *aResult = new nsDocumentEncoder; - if (!*aResult) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(*aResult); - return NS_OK; -} - - -#ifdef XP_MAC -#pragma mark - -#pragma mark nsDocumentEncoder declaration -#pragma mark - -#endif - -class nsHTMLCopyEncoder : public nsDocumentEncoder -{ -public: - - nsHTMLCopyEncoder(); - virtual ~nsHTMLCopyEncoder(); - - NS_IMETHOD Init(nsIDocument* aDocument, const nsAReadableString& aMimeType, PRUint32 aFlags); - - // overridden methods from nsDocumentEncoder - NS_IMETHOD SetSelection(nsISelection* aSelection); - NS_IMETHOD EncodeToStringWithContext(nsAWritableString& aEncodedString, - nsAWritableString& aContextString, - nsAWritableString& aInfoString); - -protected: - - enum Endpoint - { - kStart, - kEnd - }; - - nsresult PromoteRange(nsIDOMRange *inRange); - nsresult GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, PRInt32 aOffset, - nsCOMPtr *outNode, PRInt32 *outOffset); - nsCOMPtr GetChildAt(nsIDOMNode *aParent, PRInt32 aOffset); - PRBool IsMozBR(nsIDOMNode* aNode); - nsresult GetNodeLocation(nsIDOMNode *inChild, nsCOMPtr *outParent, PRInt32 *outOffset); - PRBool IsRoot(nsIDOMNode* aNode); - PRBool IsFirstNode(nsIDOMNode *aNode); - PRBool IsLastNode(nsIDOMNode *aNode); - PRBool IsEmptyTextContent(nsIDOMNode* aNode); - virtual PRBool IncludeInContext(nsIDOMNode *aNode); - - nsCOMPtr mParserService; - PRBool mIsTextWidget; -}; - -#ifdef XP_MAC -#pragma mark nsDocumentEncoder implementation -#pragma mark - -#endif - -nsHTMLCopyEncoder::nsHTMLCopyEncoder() -{ - mIsTextWidget = PR_FALSE; -} - -nsHTMLCopyEncoder::~nsHTMLCopyEncoder() -{ -} - -NS_IMETHODIMP -nsHTMLCopyEncoder::Init(nsIDocument* aDocument, - const nsAReadableString& aMimetype, - PRUint32 aFlags) -{ - if (!aDocument) - return NS_ERROR_INVALID_ARG; - - mDocument = aDocument; - - mMimeType = NS_LITERAL_STRING("text/html"); - - // Make all links absolute when copying - // (see related bugs #57296, #41924, #58646, #32768) - mFlags = aFlags | OutputAbsoluteLinks; - - nsresult rv; - mParserService = do_GetService(kParserServiceCID, &rv); - return rv; -} - -NS_IMETHODIMP -nsHTMLCopyEncoder::SetSelection(nsISelection* aSelection) -{ - // check for text widgets: we need to recognize these so that - // we don't tweak the selection to be outside of the magic - // div that ender-lite text widgets are embedded in. - - if (!aSelection) - return NS_ERROR_NULL_POINTER; - - nsCOMPtr range; - nsCOMPtr commonParent; - PRInt32 count = 0; - - nsresult rv = aSelection->GetRangeCount(&count); - NS_ENSURE_SUCCESS(rv, rv); - - // if selection is uninitialized return - if (!count) - return NS_ERROR_FAILURE; - - // we'll just use the common parent of the first range. Implicit assumption - // here that multi-range selections are table cell selections, in which case - // the common parent is somewhere in the table and we don't really care where. - rv = aSelection->GetRangeAt(0, getter_AddRefs(range)); - NS_ENSURE_SUCCESS(rv, rv); - if (!range) - return NS_ERROR_NULL_POINTER; - range->GetCommonAncestorContainer(getter_AddRefs(commonParent)); - - nsCOMPtr tmp, selContent( do_QueryInterface(commonParent) ); - while (selContent) - { - // checking for selection inside a plaintext form widget - nsCOMPtr atom; - selContent->GetTag(*getter_AddRefs(atom)); - if (atom.get() == nsHTMLAtoms::input || - atom.get() == nsHTMLAtoms::textarea) - { - mIsTextWidget = PR_TRUE; - break; - } - else if (atom.get() == nsHTMLAtoms::body) - { - // check for moz prewrap style on body. If it's there we are - // in a plaintext editor. This is pretty cheezy but I haven't - // found a good way to tell if we are in a plaintext editor. - nsCOMPtr bodyElem = do_QueryInterface(selContent); - nsAutoString wsVal; - rv = bodyElem->GetAttribute(NS_LITERAL_STRING("white-space"), wsVal); - if (NS_SUCCEEDED(rv) && (kNotFound != wsVal.Find(NS_LITERAL_STRING("-moz-pre-wrap").get()))) - { - mIsTextWidget = PR_TRUE; - break; - } - } - selContent->GetParent(*getter_AddRefs(tmp)); - selContent = tmp; - } - - // also consider ourselves in a text widget if we can't find an html document - nsCOMPtr htmlDoc = do_QueryInterface(mDocument); - if (!htmlDoc) mIsTextWidget = PR_TRUE; - - // normalize selection if we are not in a widget - if (mIsTextWidget) - { - mSelection = aSelection; - mMimeType = NS_LITERAL_STRING("text/plain"); - return NS_OK; - } - - // there's no Clone() for selection! fix... - //nsresult rv = aSelection->Clone(getter_AddRefs(mSelection); - //NS_ENSURE_SUCCESS(rv, rv); - NS_NewDomSelection(getter_AddRefs(mSelection)); - NS_ENSURE_TRUE(mSelection, NS_ERROR_FAILURE); - nsCOMPtr privSelection( do_QueryInterface(aSelection) ); - NS_ENSURE_TRUE(privSelection, NS_ERROR_FAILURE); - - // get selection range enumerator - nsCOMPtr enumerator; - rv = privSelection->GetEnumerator(getter_AddRefs(enumerator)); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(enumerator, NS_ERROR_FAILURE); - - // loop thru the ranges in the selection - enumerator->First(); - nsCOMPtr currentItem; - while ((NS_ENUMERATOR_FALSE == enumerator->IsDone())) - { - rv = enumerator->CurrentItem(getter_AddRefs(currentItem)); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_TRUE(currentItem, NS_ERROR_FAILURE); - - nsCOMPtr range( do_QueryInterface(currentItem) ); - NS_ENSURE_TRUE(range, NS_ERROR_FAILURE); - nsCOMPtr myRange; - range->CloneRange(getter_AddRefs(myRange)); - NS_ENSURE_TRUE(myRange, NS_ERROR_FAILURE); - - // adjust range to include any ancestors who's children are entirely selected - rv = PromoteRange(myRange); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mSelection->AddRange(myRange); - NS_ENSURE_SUCCESS(rv, rv); - - enumerator->Next(); - } - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLCopyEncoder::EncodeToStringWithContext(nsAWritableString& aEncodedString, - nsAWritableString& aContextString, - nsAWritableString& aInfoString) -{ - nsresult rv = EncodeToString(aEncodedString); - NS_ENSURE_SUCCESS(rv, rv); - - // do not encode any context info or range hints if we are in a text widget. - if (mIsTextWidget) return NS_OK; - - // now encode common ancestors into aContextString. Note that the common ancestors - // will be for the last range in the selection in the case of multirange selections. - // encoding ancestors every range in a multirange selection in a way that could be - // understood by the paste code would be a lot more work to do. As a practical matter, - // selections are single range, and the ones that aren't are table cell selections - // where all the cells are in the same table. - - // leaf of ancestors might be text node. If so discard it. - nsCOMPtr node; - node = NS_STATIC_CAST(nsIDOMNode *, mCommonAncestors.ElementAt(0)); - if (node && IsTextNode(node)) mCommonAncestors.RemoveElementAt(0); - - PRInt32 i = mCommonAncestors.Count(); - - node = NS_STATIC_CAST(nsIDOMNode *, mCommonAncestors.ElementAt(--i)); - - while (node) - { - SerializeNodeStart(node, 0, -1, aContextString); - node = NS_STATIC_CAST(nsIDOMNode *, mCommonAncestors.ElementAt(--i)); - } - - i = 0; - node = NS_STATIC_CAST(nsIDOMNode *, mCommonAncestors.ElementAt(i)); - - while (node) - { - SerializeNodeEnd(node, aContextString); - node = NS_STATIC_CAST(nsIDOMNode *, mCommonAncestors.ElementAt(++i)); - } - - // encode range info : the start and end depth of the selection, where the depth is - // distance down in the parent heirarchy. Later we will need to add leading/trainlig - // whitespace info to this. - nsAutoString infoString; - infoString.AppendInt(mStartDepth); - infoString.AppendWithConversion(','); - infoString.AppendInt(mEndDepth); - aInfoString = infoString; - - return NS_OK; -} - - -PRBool -nsHTMLCopyEncoder::IncludeInContext(nsIDOMNode *aNode) -{ - nsCOMPtr content(do_QueryInterface(aNode)); - - if (!content) - return PR_FALSE; - - nsCOMPtr tag; - - content->GetTag(*getter_AddRefs(tag)); - - if (tag.get() == nsHTMLAtoms::b || - tag.get() == nsHTMLAtoms::i || - tag.get() == nsHTMLAtoms::u || - tag.get() == nsHTMLAtoms::tt || - tag.get() == nsHTMLAtoms::s || - tag.get() == nsHTMLAtoms::strike || - tag.get() == nsHTMLAtoms::em || - tag.get() == nsHTMLAtoms::strong || - tag.get() == nsHTMLAtoms::dfn || - tag.get() == nsHTMLAtoms::code || - tag.get() == nsHTMLAtoms::cite || - tag.get() == nsHTMLAtoms::variable || - tag.get() == nsHTMLAtoms::abbr || - tag.get() == nsHTMLAtoms::font || - tag.get() == nsHTMLAtoms::script || - tag.get() == nsHTMLAtoms::span || - tag.get() == nsHTMLAtoms::pre || - tag.get() == nsHTMLAtoms::h1 || - tag.get() == nsHTMLAtoms::h2 || - tag.get() == nsHTMLAtoms::h3 || - tag.get() == nsHTMLAtoms::h4 || - tag.get() == nsHTMLAtoms::h5 || - tag.get() == nsHTMLAtoms::h6) { - return PR_TRUE; - } - - return PR_FALSE; -} - - -nsresult -nsHTMLCopyEncoder::PromoteRange(nsIDOMRange *inRange) -{ - if (!inRange) return NS_ERROR_NULL_POINTER; - nsresult rv; - nsCOMPtr startNode, endNode; - PRInt32 startOffset, endOffset; - - rv = inRange->GetStartContainer(getter_AddRefs(startNode)); - NS_ENSURE_SUCCESS(rv, rv); - rv = inRange->GetStartOffset(&startOffset); - NS_ENSURE_SUCCESS(rv, rv); - rv = inRange->GetEndContainer(getter_AddRefs(endNode)); - NS_ENSURE_SUCCESS(rv, rv); - rv = inRange->GetEndOffset(&endOffset); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr opStartNode; - nsCOMPtr opEndNode; - PRInt32 opStartOffset, opEndOffset; - nsCOMPtr opRange; - - rv = GetPromotedPoint( kStart, startNode, startOffset, address_of(opStartNode), &opStartOffset); - NS_ENSURE_SUCCESS(rv, rv); - rv = GetPromotedPoint( kEnd, endNode, endOffset, address_of(opEndNode), &opEndOffset); - NS_ENSURE_SUCCESS(rv, rv); - rv = inRange->SetStart(opStartNode, opStartOffset); - NS_ENSURE_SUCCESS(rv, rv); - rv = inRange->SetEnd(opEndNode, opEndOffset); - return rv; -} - -nsresult -nsHTMLCopyEncoder::GetPromotedPoint(Endpoint aWhere, nsIDOMNode *aNode, PRInt32 aOffset, - nsCOMPtr *outNode, PRInt32 *outOffset) -{ - nsresult rv = NS_OK; - nsCOMPtr node = aNode; - nsCOMPtr parent = aNode; - PRInt32 offset = aOffset; - PRBool bResetPromotion = PR_FALSE; - - // defualt values - *outNode = node; - *outOffset = offset; - - if (aWhere == kStart) - { - // some special casing for text nodes - if (IsTextNode(aNode)) - { - // if not at beginning of text node, we are done - if (offset > 0) - { - // unless everything before us in just whitespace. NOTE: we need a more - // general solution that truly detects all cases of non-significant - // whitesace with no false alarms. - nsCOMPtr nodeAsText = do_QueryInterface(aNode); - nsAutoString text; - nodeAsText->SubstringData(0, offset, text); - text.CompressWhitespace(); - if (text.Length()) - return NS_OK; - bResetPromotion = PR_TRUE; - } - // else - rv = GetNodeLocation(aNode, address_of(parent), &offset); - NS_ENSURE_SUCCESS(rv, rv); - } - else - { - node = GetChildAt(parent,offset); - } - if (!node) node = parent; - - // finding the real start for this point. look up the tree for as long as we are the - // first node in the container, and as long as we haven't hit the body node. - if (!IsRoot(node)) - { - rv = GetNodeLocation(node, address_of(parent), &offset); - NS_ENSURE_SUCCESS(rv, rv); - if (offset == -1) return NS_OK; // we hit generated content; STOP - while ((IsFirstNode(node)) && (!IsRoot(parent))) - { - if (bResetPromotion) - { - nsAutoString tag; - nsCOMPtr atom; - nsCOMPtr content = do_QueryInterface(parent); - if (content) - { - PRBool isBlock = PR_FALSE; - PRInt32 id; - content->GetTag(*getter_AddRefs(atom)); - atom->ToString(tag); - mParserService->HTMLStringTagToId(tag, &id); - mParserService->IsBlock(id, isBlock); - if (isBlock) - { - bResetPromotion = PR_FALSE; - } - } - } - - node = parent; - rv = GetNodeLocation(node, address_of(parent), &offset); - NS_ENSURE_SUCCESS(rv, rv); - if (offset == -1) // we hit generated content; STOP - { - // back up a bit - parent = node; - offset = 0; - break; - } - } - if (bResetPromotion) - { - *outNode = aNode; - *outOffset = aOffset; - } - else - { - *outNode = parent; - *outOffset = offset; - } - return rv; - } - } - - if (aWhere == kEnd) - { - // some special casing for text nodes - if (IsTextNode(aNode)) - { - // if not at end of text node, we are done - PRUint32 len; - GetLengthOfDOMNode(aNode, len); - if (offset < (PRInt32)len) - { - // unless everything after us in just whitespace. NOTE: we need a more - // general solution that truly detects all cases of non-significant - // whitesace with no false alarms. - nsCOMPtr nodeAsText = do_QueryInterface(aNode); - nsAutoString text; - nodeAsText->SubstringData(offset, len-offset, text); - text.CompressWhitespace(); - if (text.Length()) - return NS_OK; - bResetPromotion = PR_TRUE; - } - rv = GetNodeLocation(aNode, address_of(parent), &offset); - NS_ENSURE_SUCCESS(rv, rv); - } - else - { - if (offset) offset--; // we want node _before_ offset - node = GetChildAt(parent,offset); - } - if (!node) node = parent; - - // finding the real end for this point. look up the tree for as long as we are the - // last node in the container, and as long as we haven't hit the body node. - if (!IsRoot(node)) - { - rv = GetNodeLocation(node, address_of(parent), &offset); - NS_ENSURE_SUCCESS(rv, rv); - if (offset == -1) return NS_OK; // we hit generated content; STOP - while ((IsLastNode(node)) && (!IsRoot(parent))) - { - if (bResetPromotion) - { - nsAutoString tag; - nsCOMPtr atom; - nsCOMPtr content = do_QueryInterface(parent); - if (content) - { - PRBool isBlock = PR_FALSE; - PRInt32 id; - content->GetTag(*getter_AddRefs(atom)); - atom->ToString(tag); - mParserService->HTMLStringTagToId(tag, &id); - mParserService->IsBlock(id, isBlock); - if (isBlock) - { - bResetPromotion = PR_FALSE; - } - } - } - - node = parent; - rv = GetNodeLocation(node, address_of(parent), &offset); - NS_ENSURE_SUCCESS(rv, rv); - if (offset == -1) // we hit generated content; STOP - { - // back up a bit - parent = node; - offset = 0; - break; - } - } - if (bResetPromotion) - { - *outNode = aNode; - *outOffset = aOffset; - } - else - { - *outNode = parent; - offset++; // add one since this in an endpoint - want to be AFTER node. - *outOffset = offset; - } - return rv; - } - } - - return rv; -} - -nsCOMPtr -nsHTMLCopyEncoder::GetChildAt(nsIDOMNode *aParent, PRInt32 aOffset) -{ - nsCOMPtr resultNode; - - if (!aParent) - return resultNode; - - nsCOMPtr content = do_QueryInterface(aParent); - nsCOMPtr cChild; - NS_PRECONDITION(content, "null content in nsHTMLCopyEncoder::GetChildAt"); - - if (NS_FAILED(content->ChildAt(aOffset, *getter_AddRefs(cChild)))) - return resultNode; - - resultNode = do_QueryInterface(cChild); - return resultNode; -} - -PRBool -nsHTMLCopyEncoder::IsMozBR(nsIDOMNode* aNode) -{ - if (IsTag(aNode, nsHTMLAtoms::br)) - { - nsCOMPtr elem = do_QueryInterface(aNode); - if (elem) - { - nsAutoString typeAttrName; typeAttrName.AssignWithConversion("type"); - nsAutoString typeAttrVal; - nsresult rv = elem->GetAttribute(typeAttrName, typeAttrVal); - typeAttrVal.ToLowerCase(); - if (NS_SUCCEEDED(rv) && (typeAttrVal.EqualsWithConversion("_moz"))) - return PR_TRUE; - } - return PR_FALSE; - } - return PR_FALSE; -} - -nsresult -nsHTMLCopyEncoder::GetNodeLocation(nsIDOMNode *inChild, nsCOMPtr *outParent, PRInt32 *outOffset) -{ - NS_ASSERTION((inChild && outParent && outOffset), "bad args"); - nsresult result = NS_ERROR_NULL_POINTER; - if (inChild && outParent && outOffset) - { - result = inChild->GetParentNode(getter_AddRefs(*outParent)); - if ((NS_SUCCEEDED(result)) && (*outParent)) - { - nsCOMPtr content = do_QueryInterface(*outParent); - nsCOMPtr cChild = do_QueryInterface(inChild); - if (!cChild || !content) return NS_ERROR_NULL_POINTER; - result = content->IndexOf(cChild, *outOffset); - } - } - return result; -} - -PRBool -nsHTMLCopyEncoder::IsRoot(nsIDOMNode* aNode) -{ - if (aNode) - { - if (mIsTextWidget) - return (IsTag(aNode, nsHTMLAtoms::div)); - else - return (IsTag(aNode, nsHTMLAtoms::body) || - IsTag(aNode, nsHTMLAtoms::td) || - IsTag(aNode, nsHTMLAtoms::th)); - } - return PR_FALSE; -} - -PRBool -nsHTMLCopyEncoder::IsFirstNode(nsIDOMNode *aNode) -{ - nsCOMPtr parent; - PRInt32 offset, j=0; - nsresult rv = GetNodeLocation(aNode, address_of(parent), &offset); - if (NS_FAILED(rv)) - { - NS_NOTREACHED("failure in IsFirstNode"); - return PR_FALSE; - } - if (offset == 0) // easy case, we are first dom child - return PR_TRUE; - if (!parent) - return PR_TRUE; - - // need to check if any nodes before us are really visible. - // Mike wrote something for me along these lines in nsSelectionController, - // but I don't think it's ready for use yet - revisit. - // HACK: for now, simply consider all whitespace text nodes to be - // invisible formatting nodes. - nsCOMPtr childList; - nsCOMPtr child; - - rv = parent->GetChildNodes(getter_AddRefs(childList)); - if (NS_FAILED(rv) || !childList) - { - NS_NOTREACHED("failure in IsFirstNode"); - return PR_TRUE; - } - while (j < offset) - { - childList->Item(j, getter_AddRefs(child)); - if (!IsEmptyTextContent(child)) - return PR_FALSE; - j++; - } - return PR_TRUE; -} - - -PRBool -nsHTMLCopyEncoder::IsLastNode(nsIDOMNode *aNode) -{ - nsCOMPtr parent; - PRInt32 offset,j; - PRUint32 numChildren; - nsresult rv = GetNodeLocation(aNode, address_of(parent), &offset); - if (NS_FAILED(rv)) - { - NS_NOTREACHED("failure in IsLastNode"); - return PR_FALSE; - } - GetLengthOfDOMNode(parent, numChildren); - if (offset+1 == (PRInt32)numChildren) // easy case, we are last dom child - return PR_TRUE; - if (!parent) - return PR_TRUE; - // need to check if any nodes after us are really visible. - // Mike wrote something for me along these lines in nsSelectionController, - // but I don't think it's ready for use yet - revisit. - // HACK: for now, simply consider all whitespace text nodes to be - // invisible formatting nodes. - j = (PRInt32)numChildren-1; - nsCOMPtrchildList; - nsCOMPtr child; - rv = parent->GetChildNodes(getter_AddRefs(childList)); - if (NS_FAILED(rv) || !childList) - { - NS_NOTREACHED("failure in IsLastNode"); - return PR_TRUE; - } - while (j > offset) - { - childList->Item(j, getter_AddRefs(child)); - j--; - if (IsMozBR(child)) // we ignore trailing moz BRs. - continue; - if (!IsEmptyTextContent(child)) - return PR_FALSE; - } - return PR_TRUE; -} - -PRBool -nsHTMLCopyEncoder::IsEmptyTextContent(nsIDOMNode* aNode) -{ - PRBool result = PR_FALSE; - nsCOMPtr tc(do_QueryInterface(aNode)); - if (tc) { - tc->IsOnlyWhitespace(&result); - } - return result; -} - -nsresult NS_NewHTMLCopyTextEncoder(nsIDocumentEncoder** aResult); // make mac compiler happy - -nsresult -NS_NewHTMLCopyTextEncoder(nsIDocumentEncoder** aResult) -{ - *aResult = new nsHTMLCopyEncoder; - if (!*aResult) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(*aResult); - return NS_OK; -} diff --git a/layout/base/src/nsDocumentFragment.cpp b/layout/base/src/nsDocumentFragment.cpp deleted file mode 100644 index 9ea143223820..000000000000 --- a/layout/base/src/nsDocumentFragment.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsISupports.h" -#include "nsIContent.h" -#include "nsIDOMDocumentFragment.h" -#include "nsIScriptObjectOwner.h" -#include "nsGenericElement.h" -#include "nsINameSpaceManager.h" -#include "nsINodeInfo.h" -#include "nsNodeInfoManager.h" -#include "nsIDocument.h" -#include "nsIDOMDocument.h" -#include "nsIDOMScriptObjectFactory.h" -#include "nsDOMError.h" - - -class nsDocumentFragment : public nsGenericContainerElement, - public nsIDOMDocumentFragment -{ -public: - nsDocumentFragment(nsIDocument* aOwnerDocument); - virtual ~nsDocumentFragment(); - - // nsISupports - NS_DECL_ISUPPORTS_INHERITED - - // interface nsIDOMDocumentFragment - NS_IMETHOD GetNodeName(nsAWritableString& aNodeName) - { return nsGenericContainerElement::GetNodeName(aNodeName); } - NS_IMETHOD GetNodeValue(nsAWritableString& aNodeValue) - { return nsGenericContainerElement::GetNodeValue(aNodeValue); } - NS_IMETHOD SetNodeValue(const nsAReadableString& aNodeValue) - { return nsGenericContainerElement::SetNodeValue(aNodeValue); } - NS_IMETHOD GetNodeType(PRUint16* aNodeType); - NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode) - { return nsGenericContainerElement::GetParentNode(aParentNode); } - NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes) - { return nsGenericContainerElement::GetChildNodes(aChildNodes); } - NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild) - { return nsGenericContainerElement::GetFirstChild(aFirstChild); } - NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild) - { return nsGenericContainerElement::GetLastChild(aLastChild); } - NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling) - { return nsGenericContainerElement::GetPreviousSibling(aPreviousSibling); } - NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling) - { return nsGenericContainerElement::GetNextSibling(aNextSibling); } - NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes) - { - *aAttributes = nsnull; - return NS_OK; - } - NS_IMETHOD GetOwnerDocument(nsIDOMDocument** aOwnerDocument); - NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, - nsIDOMNode** aReturn) - { return nsGenericContainerElement::InsertBefore(aNewChild, aRefChild, - aReturn); } - NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, - nsIDOMNode** aReturn) - { return nsGenericContainerElement::ReplaceChild(aNewChild, aOldChild, - aReturn); } - NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) - { return nsGenericContainerElement::RemoveChild(aOldChild, aReturn); } - NS_IMETHOD AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn) - { return nsGenericContainerElement::AppendChild(aNewChild, aReturn); } - NS_IMETHOD HasChildNodes(PRBool* aReturn) - { return nsGenericContainerElement::HasChildNodes(aReturn); } - NS_IMETHOD HasAttributes(PRBool* aReturn) - { return nsGenericContainerElement::HasAttributes(aReturn); } - NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn); - NS_IMETHOD GetPrefix(nsAWritableString& aPrefix) - { return nsGenericContainerElement::GetPrefix(aPrefix); } - NS_IMETHOD SetPrefix(const nsAReadableString& aPrefix); - NS_IMETHOD GetNamespaceURI(nsAWritableString& aNamespaceURI) - { return nsGenericContainerElement::GetNamespaceURI(aNamespaceURI); } - NS_IMETHOD GetLocalName(nsAWritableString& aLocalName) - { return nsGenericContainerElement::GetLocalName(aLocalName); } - NS_IMETHOD Normalize() - { return nsGenericContainerElement::Normalize(); } - NS_IMETHOD IsSupported(const nsAReadableString& aFeature, - const nsAReadableString& aVersion, - PRBool* aReturn) - { return nsGenericContainerElement::IsSupported(aFeature, aVersion, - aReturn); } - - // interface nsIScriptObjectOwner - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - - NS_IMETHOD SetParent(nsIContent* aParent) - { return NS_OK; } - NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - const nsAReadableString& aValue, - PRBool aNotify) - { return NS_OK; } - NS_IMETHOD SetAttribute(nsINodeInfo* aNodeInfo, - const nsAReadableString& aValue, - PRBool aNotify) - { return NS_OK; } - NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - nsAWritableString& aResult) const - { return NS_CONTENT_ATTR_NOT_THERE; } - NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - nsIAtom*& aPrefix, nsAWritableString& aResult) const - { return NS_CONTENT_ATTR_NOT_THERE; } - NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, - PRBool aNotify) - { return NS_OK; } - NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, - PRInt32& aNameSpaceID, - nsIAtom*& aName, - nsIAtom*& aPrefix) const - { - aName = nsnull; - aPrefix = nsnull; - return NS_ERROR_ILLEGAL_VALUE; - } - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus) - { - NS_ENSURE_ARG_POINTER(aEventStatus); - *aEventStatus = nsEventStatus_eIgnore; - return NS_OK; - } - - NS_IMETHOD SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { - if (!aResult) { - return NS_ERROR_NULL_POINTER; - } -#ifdef DEBUG - *aResult = sizeof(*this); -#else - *aResult = 0; -#endif - return NS_OK; - } - -protected: - nsCOMPtr mOwnerDocument; -}; - -nsresult -NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult, - nsIDocument* aOwnerDocument) -{ - NS_ENSURE_ARG_POINTER(aInstancePtrResult); - - nsCOMPtr nimgr; - nsCOMPtr nodeInfo; - - nsresult rv; - - if (aOwnerDocument) { - rv = aOwnerDocument->GetNodeInfoManager(*getter_AddRefs(nimgr)); - } else { - rv = nsNodeInfoManager::GetAnonymousManager(*getter_AddRefs(nimgr)); - } - NS_ENSURE_SUCCESS(rv, rv); - - rv = nimgr->GetNodeInfo(NS_ConvertASCIItoUCS2("#document-fragment"), - nsnull, kNameSpaceID_None, - *getter_AddRefs(nodeInfo)); - NS_ENSURE_SUCCESS(rv, rv); - - nsDocumentFragment* it = new nsDocumentFragment(aOwnerDocument); - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - - rv = it->Init(nodeInfo); - - if (NS_FAILED(rv)) { - delete it; - - return rv; - } - - *aInstancePtrResult = NS_STATIC_CAST(nsIDOMDocumentFragment *, it); - - NS_ADDREF(*aInstancePtrResult); - - return NS_OK; -} - -nsDocumentFragment::nsDocumentFragment(nsIDocument* aOwnerDocument) -{ - mOwnerDocument = aOwnerDocument; -} - -nsDocumentFragment::~nsDocumentFragment() -{ -} - -NS_IMPL_ADDREF(nsDocumentFragment) -NS_IMPL_RELEASE(nsDocumentFragment) - - -NS_INTERFACE_MAP_BEGIN(nsDocumentFragment) - NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentFragment) - NS_INTERFACE_MAP_ENTRY(nsIDOMNode) - NS_INTERFACE_MAP_ENTRY(nsIContent) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent) -NS_INTERFACE_MAP_END - - -NS_IMETHODIMP -nsDocumentFragment::GetNodeType(PRUint16* aNodeType) -{ - *aNodeType = (PRUint16)nsIDOMNode::DOCUMENT_FRAGMENT_NODE; - return NS_OK; -} - -NS_IMETHODIMP -nsDocumentFragment::GetOwnerDocument(nsIDOMDocument** aOwnerDocument) -{ - NS_ENSURE_ARG_POINTER(aOwnerDocument); - - if (!mOwnerDocument) { - *aOwnerDocument = nsnull; - return NS_OK; - } - - return mOwnerDocument->QueryInterface(NS_GET_IID(nsIDOMDocument), - (void **)aOwnerDocument); -} - -NS_IMETHODIMP -nsDocumentFragment::SetPrefix(const nsAReadableString& aPrefix) -{ - return NS_ERROR_DOM_NAMESPACE_ERR; -} - -NS_IMETHODIMP -nsDocumentFragment::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) -{ - nsDocumentFragment* it; - it = new nsDocumentFragment(mOwnerDocument); - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - - nsCOMPtr kungFuDeathGrip(it); - -//XXX CopyInnerTo(this, &it->mInner); ??? Why is this commented out? - - nsresult rv = it->Init(mNodeInfo); - - if (NS_FAILED(rv)) { - delete it; - - return rv; - } - - *aReturn = NS_STATIC_CAST(nsIDOMNode *, it); - - NS_ADDREF(*aReturn); - - return NS_OK; -} - -NS_IMETHODIMP -nsDocumentFragment::GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - - *aScriptObject = nsnull; - - nsDOMSlots *slots = GetDOMSlots(); - - if (slots && !mDOMSlots->mScriptObject) { - nsCOMPtr factory; - - res = GetScriptObjectFactory(getter_AddRefs(factory)); - if (NS_OK != res) { - return res; - } - - res = factory->NewScriptDocumentFragment(aContext, - NS_STATIC_CAST(nsIDOMDocumentFragment *, this), - mOwnerDocument, - (void**)&slots->mScriptObject); - } - - if (slots) { - *aScriptObject = slots->mScriptObject; - } - - return res; -} diff --git a/layout/base/src/nsDocumentViewer.cpp b/layout/base/src/nsDocumentViewer.cpp deleted file mode 100644 index 5c87e374af45..000000000000 --- a/layout/base/src/nsDocumentViewer.cpp +++ /dev/null @@ -1,3114 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#include "nslayout.h" -#include "nsCOMPtr.h" -#include "nsCRT.h" -#include "nsString.h" -#include "nsISupports.h" -#include "nsIContent.h" -#include "nsIContentViewerContainer.h" -#include "nsIDocumentViewer.h" -#include "nsIDOMWindowInternal.h" - -#include "nsIImageGroup.h" -#include "nsIImageObserver.h" - -#include "nsIDocument.h" -#include "nsIPresContext.h" -#include "nsIPresShell.h" -#include "nsIStyleSet.h" -#include "nsIStyleSheet.h" -#include "nsICSSStyleSheet.h" -#include "nsIStyleContext.h" -#include "nsIFrame.h" - -#include "nsIScriptGlobalObjectOwner.h" -#include "nsIScriptGlobalObject.h" -#include "nsILinkHandler.h" -#include "nsIDOMDocument.h" -#include "nsISelectionListener.h" -#include "nsISelectionPrivate.h" -#include "nsIDOMHTMLDocument.h" -#include "nsIDOMHTMLElement.h" -#include "nsIDOMRange.h" -#include "nsLayoutCID.h" -#include "nsHTMLParts.h" - -#include "nsViewsCID.h" -#include "nsWidgetsCID.h" -#include "nsGfxCIID.h" -#include "nsIDeviceContext.h" -#include "nsIDeviceContextSpec.h" -#include "nsIDeviceContextSpecFactory.h" -#include "nsIViewManager.h" -#include "nsIView.h" - -#include "nsIPref.h" -#include "nsIPageSequenceFrame.h" -#include "nsIURL.h" -#include "nsIWebShell.h" -#include "nsIContentViewerEdit.h" -#include "nsIContentViewerFile.h" -#include "nsIMarkupDocumentViewer.h" -#include "nsIInterfaceRequestor.h" -#include "nsIDocShellTreeItem.h" -#include "nsIDocShellTreeNode.h" -#include "nsIDocShellTreeOwner.h" -#include "nsIDocShell.h" -#include "nsIFrameDebug.h" -#include "nsILayoutHistoryState.h" -#include "nsLayoutAtoms.h" -#include "nsIDOMHTMLFrameSetElement.h" -#include "nsIFrameManager.h" -#include "nsIParser.h" -#include "nsIPrintContext.h" - -#include "nsIChromeRegistry.h" - -#include "nsIServiceManager.h" -#include "nsIEventQueueService.h" -#include "nsIEventQueue.h" - -#include "nsPIDOMWindow.h" -#include "nsIFocusController.h" - -// Print Options -#include "nsIPrintOptions.h" -#include "nsGfxCIID.h" -#include "nsIServiceManager.h" -static NS_DEFINE_CID(kPrintOptionsCID, NS_PRINTOPTIONS_CID); -#include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms - -// FrameSet -#include "nsINodeInfo.h" -#include "nsIDocument.h" -#include "nsHTMLAtoms.h" -#include "nsIHTMLContent.h" -#include "nsINameSpaceManager.h" -#include "nsIWebShell.h" - -//focus -#include "nsIDOMEventReceiver.h" -#include "nsIDOMFocusListener.h" -#include "nsISelectionController.h" - -#include "nsITransformMediator.h" - -static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID); - -#ifdef NS_DEBUG -#undef NOISY_VIEWER -#else -#undef NOISY_VIEWER -#endif - -//#define SPOOL_TO_ONE_DOC 1 - -class DocumentViewerImpl; - -// a small delegate class used to avoid circular references - -#ifdef XP_MAC -#pragma mark ** nsDocViwerSelectionListener ** -#endif - -class nsDocViwerSelectionListener : public nsISelectionListener -{ -public: - - // nsISupports interface... - NS_DECL_ISUPPORTS - - // nsISelectionListerner interface - NS_DECL_NSISELECTIONLISTENER - - nsDocViwerSelectionListener() - : mDocViewer(NULL) - , mGotSelectionState(PR_FALSE) - , mSelectionWasCollapsed(PR_FALSE) - { - NS_INIT_REFCNT(); - } - - virtual ~nsDocViwerSelectionListener() {} - - nsresult Init(DocumentViewerImpl *aDocViewer); - -protected: - - DocumentViewerImpl* mDocViewer; - PRPackedBool mGotSelectionState; - PRPackedBool mSelectionWasCollapsed; - -}; - - -/** editor Implementation of the FocusListener interface - */ -class nsDocViewerFocusListener : public nsIDOMFocusListener -{ -public: - /** default constructor - */ - nsDocViewerFocusListener(); - /** default destructor - */ - virtual ~nsDocViewerFocusListener(); - - -/*interfaces for addref and release and queryinterface*/ - NS_DECL_ISUPPORTS - -/*BEGIN implementations of focus event handler interface*/ - virtual nsresult HandleEvent(nsIDOMEvent* aEvent); - virtual nsresult Focus(nsIDOMEvent* aEvent); - virtual nsresult Blur(nsIDOMEvent* aEvent); -/*END implementations of focus event handler interface*/ - nsresult Init(DocumentViewerImpl *aDocViewer); - -private: - DocumentViewerImpl* mDocViewer; -}; - - - -#ifdef XP_MAC -#pragma mark ** DocumentViewerImpl ** -#endif - - -class DocumentViewerImpl : public nsIDocumentViewer, - public nsIContentViewerEdit, - public nsIContentViewerFile, - public nsIMarkupDocumentViewer, - public nsIImageGroupObserver -{ - friend class nsDocViwerSelectionListener; - -public: - DocumentViewerImpl(); - DocumentViewerImpl(nsIPresContext* aPresContext); - - NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW - - // nsISupports interface... - NS_DECL_ISUPPORTS - - // nsIContentViewer interface... - NS_IMETHOD Init(nsIWidget* aParentWidget, - nsIDeviceContext* aDeviceContext, - const nsRect& aBounds); - NS_IMETHOD BindToDocument(nsISupports* aDoc, const char* aCommand); - NS_IMETHOD SetContainer(nsISupports* aContainer); - NS_IMETHOD GetContainer(nsISupports** aContainerResult); - NS_IMETHOD LoadComplete(nsresult aStatus); - NS_IMETHOD Destroy(void); - NS_IMETHOD Stop(void); - NS_IMETHOD GetDOMDocument(nsIDOMDocument **aResult); - NS_IMETHOD SetDOMDocument(nsIDOMDocument *aDocument); - NS_IMETHOD GetBounds(nsRect& aResult); - NS_IMETHOD SetBounds(const nsRect& aBounds); - NS_IMETHOD Move(PRInt32 aX, PRInt32 aY); - NS_IMETHOD Show(); - NS_IMETHOD Hide(); - NS_IMETHOD SetEnableRendering(PRBool aOn); - NS_IMETHOD GetEnableRendering(PRBool* aResult); - - // nsIDocumentViewer interface... - NS_IMETHOD SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet); - NS_IMETHOD GetDocument(nsIDocument*& aResult); - NS_IMETHOD GetPresShell(nsIPresShell*& aResult); - NS_IMETHOD GetPresContext(nsIPresContext*& aResult); - NS_IMETHOD CreateDocumentViewerUsing(nsIPresContext* aPresContext, - nsIDocumentViewer*& aResult); - NS_IMETHOD SetTransformMediator(nsITransformMediator* aMediator); - - // nsIContentViewerEdit - NS_DECL_NSICONTENTVIEWEREDIT - - // nsIContentViewerFile - NS_DECL_NSICONTENTVIEWERFILE - - // nsIMarkupDocumentViewer - NS_DECL_NSIMARKUPDOCUMENTVIEWER - - typedef void (*CallChildFunc)(nsIMarkupDocumentViewer* aViewer, - void* aClosure); - nsresult CallChildren(CallChildFunc aFunc, void* aClosure); - - // nsIImageGroupObserver interface - virtual void Notify(nsIImageGroup *aImageGroup, - nsImageGroupNotification aNotificationType); - -protected: - virtual ~DocumentViewerImpl(); - -private: - void ForceRefresh(void); - nsresult CreateStyleSet(nsIDocument* aDocument, nsIStyleSet** aStyleSet); - nsresult MakeWindow(nsIWidget* aParentWidget, - const nsRect& aBounds); - - nsresult GetDocumentSelection(nsISelection **aSelection, nsIPresShell * aPresShell = nsnull); - nsresult FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID); - PRBool IsThereASelection(nsIDOMWindowInternal * aDOMWin); - PRBool DoesContainFrameSet(nsIWebShell * aParent); - PRBool IsThereAnIFrameSelected(nsIWebShell* aWebShell, - nsIDOMWindowInternal * aDOMWin, - PRBool& aDoesContainFrameset); - PRBool IsWindowsInOurSubTree(nsIDOMWindowInternal * aDOMWindow); - - // get the currently infocus frame for the document viewer - nsIDOMWindowInternal * FindFocusedDOMWindowInternal(); - // get the DOM window for a given document viewer - nsIDOMWindow * GetDOMWindowForThisDV(); - - // - // The following three methods are used for printing... - // - void DocumentReadyForPrinting(); - //nsresult PrintSelection(nsIDeviceContextSpec * aDevSpec); - nsresult GetSelectionDocument(nsIDeviceContextSpec * aDevSpec, nsIDocument ** aNewDoc); - - PRUnichar* GetWebShellTitle(nsIWebShell * aWebShell); - - static void PR_CALLBACK HandlePLEvent(PLEvent* aEvent); - static void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent); - -protected: - // IMPORTANT: The ownership implicit in the following member - // variables has been explicitly checked and set using nsCOMPtr - // for owning pointers and raw COM interface pointers for weak - // (ie, non owning) references. If you add any members to this - // class, please make the ownership explicit (pinkerton, scc). - - nsISupports* mContainer; // [WEAK] it owns me! - nsCOMPtr mDeviceContext; // ??? can't hurt, but... - nsIView* mView; // [WEAK] cleaned up by view mgr - - // the following seven items are explicitly in this order - // so they will be destroyed in the reverse order (pinkerton, scc) - nsCOMPtr mTransformMediator; - nsCOMPtr mDocument; - nsCOMPtr mWindow; // ??? should we really own it? - nsCOMPtr mViewManager; - nsCOMPtr mPresContext; - nsCOMPtr mPresShell; - - nsCOMPtr mUAStyleSheet; - - nsCOMPtr mSelectionListener; - nsCOMPtr mFocusListener; - - PRBool mEnableRendering; - PRInt16 mNumURLStarts; - PRBool mIsPrinting; - - - - // printing members - nsIDeviceContext *mPrintDC; - nsIPresContext *mPrintPC; - nsIStyleSet *mPrintSS; - nsIPresShell *mPrintPS; - nsIViewManager *mPrintVM; - nsIView *mPrintView; - FILE *mFilePointer; // a file where information can go to when printing - - nsCOMPtr mPrintListener; // An observer for printing... - - // document management data - // these items are specific to markup documents (html and xml) - // may consider splitting these out into a subclass - PRBool mAllowPlugins; - /* character set member data */ - nsString mDefaultCharacterSet; - nsString mHintCharset; - nsCharsetSource mHintCharsetSource; - nsString mForceCharacterSet; -}; - -// Class IDs -static NS_DEFINE_CID(kViewManagerCID, NS_VIEW_MANAGER_CID); -static NS_DEFINE_CID(kScrollingViewCID, NS_SCROLLING_VIEW_CID); -static NS_DEFINE_CID(kWidgetCID, NS_CHILD_CID); -static NS_DEFINE_CID(kViewCID, NS_VIEW_CID); - -nsresult -NS_NewDocumentViewer(nsIDocumentViewer** aResult) -{ - NS_PRECONDITION(aResult, "null OUT ptr"); - if (!aResult) { - return NS_ERROR_NULL_POINTER; - } - DocumentViewerImpl* it = new DocumentViewerImpl(); - if (nsnull == it) { - *aResult = nsnull; - return NS_ERROR_OUT_OF_MEMORY; - } - return it->QueryInterface(NS_GET_IID(nsIDocumentViewer), (void**) aResult); -} - -// Note: operator new zeros our memory -DocumentViewerImpl::DocumentViewerImpl() -{ - NS_INIT_REFCNT(); - mEnableRendering = PR_TRUE; - mFilePointer = nsnull; - mPrintListener = nsnull; -} - -DocumentViewerImpl::DocumentViewerImpl(nsIPresContext* aPresContext) - : mPresContext(dont_QueryInterface(aPresContext)) -{ - NS_INIT_REFCNT(); - mHintCharsetSource = kCharsetUninitialized; - mAllowPlugins = PR_TRUE; - mEnableRendering = PR_TRUE; - mFilePointer = nsnull; - -} - -// ISupports implementation... -NS_IMPL_ADDREF(DocumentViewerImpl) -NS_IMPL_RELEASE(DocumentViewerImpl) - -nsresult -DocumentViewerImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - - if (aIID.Equals(NS_GET_IID(nsIContentViewer))) { - nsIContentViewer* tmp = this; - *aInstancePtr = (void*)tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIDocumentViewer))) { - nsIDocumentViewer* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIMarkupDocumentViewer))) { - nsIMarkupDocumentViewer* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIContentViewerFile))) { - nsIContentViewerFile* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIContentViewerEdit))) { - nsIContentViewerEdit* tmp = this; - *aInstancePtr = (void*) tmp; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsISupports))) { - nsIContentViewer* tmp1 = this; - nsISupports* tmp2 = tmp1; - *aInstancePtr = (void*) tmp2; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} - -DocumentViewerImpl::~DocumentViewerImpl() -{ - nsresult rv; - - if (mDocument) { - // Break global object circular reference on the document created - // in the DocViewer Init - nsCOMPtr globalObject; - mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if (globalObject) { - globalObject->SetNewDocument(nsnull); - } - // out of band cleanup of webshell - mDocument->SetScriptGlobalObject(nsnull); - if (mFocusListener) { - // get the DOM event receiver - nsCOMPtr erP; - rv = mDocument->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), getter_AddRefs(erP)); - if(NS_SUCCEEDED(rv) && erP) - erP->RemoveEventListenerByIID(mFocusListener, NS_GET_IID(nsIDOMFocusListener)); - } - } - - if (mPresContext) { - mPresContext->SetContainer(nsnull); - mPresContext->SetLinkHandler(nsnull); - } - - if (mDeviceContext) - mDeviceContext->FlushFontCache(); - - if (mPresShell) { - // Break circular reference (or something) - mPresShell->EndObservingDocument(); - nsCOMPtr selection; - rv = GetDocumentSelection(getter_AddRefs(selection)); - nsCOMPtr selPrivate(do_QueryInterface(selection)); - if (NS_FAILED(rv) || !selPrivate) - return; - if (mSelectionListener) - selPrivate->RemoveSelectionListener(mSelectionListener); - } - -} - -/* - * This method is called by the Document Loader once a document has - * been created for a particular data stream... The content viewer - * must cache this document for later use when Init(...) is called. - */ -NS_IMETHODIMP -DocumentViewerImpl::BindToDocument(nsISupports *aDoc, const char *aCommand) -{ - NS_PRECONDITION(!mDocument, "Viewer is already bound to a document!"); - -#ifdef NOISY_VIEWER - printf("DocumentViewerImpl::BindToDocument\n"); -#endif - - nsresult rv; - mDocument = do_QueryInterface(aDoc,&rv); - return rv; -} - -NS_IMETHODIMP -DocumentViewerImpl::SetContainer(nsISupports* aContainer) -{ - mContainer = aContainer; - if (mPresContext) { - mPresContext->SetContainer(aContainer); - } - return NS_OK; -} - -NS_IMETHODIMP -DocumentViewerImpl::GetContainer(nsISupports** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - - *aResult = mContainer; - NS_IF_ADDREF(*aResult); - - return NS_OK; -} - -NS_IMETHODIMP -DocumentViewerImpl::Init(nsIWidget* aParentWidget, - nsIDeviceContext* aDeviceContext, - const nsRect& aBounds) -{ - nsresult rv; - - if (!mDocument) { - return NS_ERROR_NULL_POINTER; - } - - mDeviceContext = dont_QueryInterface(aDeviceContext); - - PRBool makeCX = PR_FALSE; - if (!mPresContext) { - // Create presentation context -#if 1 - rv = NS_NewGalleyContext(getter_AddRefs(mPresContext)); -#else // turn on print preview for debugging until print preview is fixed - rv = NS_NewPrintPreviewContext(getter_AddRefs(mPresContext)); -#endif - if (NS_FAILED(rv)) return rv; - - mPresContext->Init(aDeviceContext); - makeCX = PR_TRUE; - } - - nsCOMPtr requestor(do_QueryInterface(mContainer)); - if (requestor) { - nsCOMPtr linkHandler; - requestor->GetInterface(NS_GET_IID(nsILinkHandler), - getter_AddRefs(linkHandler)); - mPresContext->SetContainer(mContainer); - mPresContext->SetLinkHandler(linkHandler); - - // Set script-context-owner in the document - nsCOMPtr owner; - requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner), - getter_AddRefs(owner)); - if (nsnull != owner) { - nsCOMPtr global; - rv = owner->GetScriptGlobalObject(getter_AddRefs(global)); - if (NS_SUCCEEDED(rv) && (nsnull != global)) { - mDocument->SetScriptGlobalObject(global); - nsCOMPtr domdoc(do_QueryInterface(mDocument)); - if (nsnull != domdoc) { - global->SetNewDocument(domdoc); - } - } - } - } - - // Create the ViewManager and Root View... - rv = MakeWindow(aParentWidget, aBounds); - if (NS_FAILED(rv)) return rv; - - // Create the style set... - nsIStyleSet* styleSet; - rv = CreateStyleSet(mDocument, &styleSet); - if (NS_FAILED(rv)) return rv; - - // Now make the shell for the document - rv = mDocument->CreateShell(mPresContext, mViewManager, styleSet, - getter_AddRefs(mPresShell)); - NS_RELEASE(styleSet); - if (NS_FAILED(rv)) return rv; - mPresShell->BeginObservingDocument(); - - // Initialize our view manager - nsRect bounds; - mWindow->GetBounds(bounds); - nscoord width = bounds.width; - nscoord height = bounds.height; - float p2t; - mPresContext->GetPixelsToTwips(&p2t); - width = NSIntPixelsToTwips(width, p2t); - height = NSIntPixelsToTwips(height, p2t); - mViewManager->DisableRefresh(); - mViewManager->SetWindowDimensions(width, height); - - if (!makeCX) { - // Make shell an observer for next time - // XXX - we observe the docuement always, see above after preshell is created - // mPresShell->BeginObservingDocument(); - -//XXX I don't think this should be done *here*; and why paint nothing -//(which turns out to cause black flashes!)??? - // Resize-reflow this time - mPresShell->InitialReflow(width, height); - - // Now trigger a refresh - if (mEnableRendering) { - mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - } - } - - // now register ourselves as a selection listener, so that we get called - // when the selection changes in the window - nsDocViwerSelectionListener *selectionListener; - NS_NEWXPCOM(selectionListener, nsDocViwerSelectionListener); - if (!selectionListener) return NS_ERROR_OUT_OF_MEMORY; - selectionListener->Init(this); - - // this is the owning reference. The nsCOMPtr will take care of releasing - // our ref to the listener on destruction. - NS_ADDREF(selectionListener); - rv = selectionListener->QueryInterface(NS_GET_IID(nsISelectionListener), getter_AddRefs(mSelectionListener)); - NS_RELEASE(selectionListener); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr selection; - rv = GetDocumentSelection(getter_AddRefs(selection)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr selPrivate(do_QueryInterface(selection)); - rv = selPrivate->AddSelectionListener(mSelectionListener); - if (NS_FAILED(rv)) return rv; - - //focus listener - // now register ourselves as a focus listener, so that we get called - // when the focus changes in the window - nsDocViewerFocusListener *focusListener; - NS_NEWXPCOM(focusListener, nsDocViewerFocusListener); - if (!focusListener) return NS_ERROR_OUT_OF_MEMORY; - focusListener->Init(this); - - // this is the owning reference. The nsCOMPtr will take care of releasing - // our ref to the listener on destruction. - NS_ADDREF(focusListener); - rv = focusListener->QueryInterface(NS_GET_IID(nsIDOMFocusListener), getter_AddRefs(mFocusListener)); - NS_RELEASE(focusListener); - if (NS_FAILED(rv)) - return rv; - - if(mDocument) - { - // get the DOM event receiver - nsCOMPtr erP; - rv = mDocument->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), getter_AddRefs(erP)); - if(NS_FAILED(rv) || !erP) - return rv?rv:NS_ERROR_FAILURE; - - rv = erP->AddEventListenerByIID(mFocusListener, NS_GET_IID(nsIDOMFocusListener)); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener"); - } - return rv; -} - -// -// LoadComplete(aStatus) -// -// aStatus - The status returned from loading the document. -// -// This method is called by the container when the document has been -// completely loaded. -// -NS_IMETHODIMP -DocumentViewerImpl::LoadComplete(nsresult aStatus) -{ - nsresult rv = NS_OK; - - nsCOMPtr global; - - // First, get the script global object from the document... - if (mDocument) { - rv = mDocument->GetScriptGlobalObject(getter_AddRefs(global)); - } - - // Fail if no ScriptGlobalObject is available... - NS_ASSERTION(global, "nsIScriptGlobalObject not set for document!"); - if (!global) return NS_ERROR_NULL_POINTER; - - // Now, fire either an OnLoad or OnError event to the document... - if(NS_SUCCEEDED(aStatus)) { - nsEventStatus status = nsEventStatus_eIgnore; - nsEvent event; - - event.eventStructType = NS_EVENT; - event.message = NS_PAGE_LOAD; - rv = global->HandleDOMEvent(mPresContext, &event, nsnull, - NS_EVENT_FLAG_INIT, &status); - } else { - // XXX: Should fire error event to the document... - } - - return rv; -} - -NS_IMETHODIMP -DocumentViewerImpl::Destroy(void) -{ - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -DocumentViewerImpl::Stop(void) -{ - if (mDocument) { - mDocument->StopDocumentLoad(); - } - - if (mPresContext) { - // stop everything but the chrome. - mPresContext->Stop(PR_FALSE); - } - return NS_OK; -} - -NS_IMETHODIMP -DocumentViewerImpl::GetDOMDocument(nsIDOMDocument **aResult) -{ - return CallQueryInterface(mDocument.get(), aResult); -} - -NS_IMETHODIMP -DocumentViewerImpl::SetDOMDocument(nsIDOMDocument *aDocument) -{ - // Assumptions: - // - // 1) this document viewer has been initialized with a call to Init(). - // 2) the stylesheets associated with the document have been added to the document. - - // XXX Right now, this method assumes that the layout of the current document - // hasn't started yet. More cleanup will probably be necessary to make this - // method work for the case when layout *has* occurred for the current document. - // That work can happen when and if it is needed. - - nsresult rv; - if (nsnull == aDocument) - return NS_ERROR_NULL_POINTER; - - nsCOMPtr newDoc = do_QueryInterface(aDocument, &rv); - if (NS_FAILED(rv)) return rv; - - // 0) Replace the old document with the new one - mDocument = newDoc; - - // 1) Set the script global object on the new document - nsCOMPtr requestor(do_QueryInterface(mContainer)); - if (requestor) { - nsCOMPtr owner; - requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObjectOwner), - getter_AddRefs(owner)); - if (nsnull != owner) { - nsCOMPtr global; - rv = owner->GetScriptGlobalObject(getter_AddRefs(global)); - if (NS_SUCCEEDED(rv) && (nsnull != global)) { - mDocument->SetScriptGlobalObject(global); - global->SetNewDocument(aDocument); - } - } - } - - // 2) Create a new style set for the document - nsCOMPtr styleSet; - rv = CreateStyleSet(mDocument, getter_AddRefs(styleSet)); - if (NS_FAILED(rv)) return rv; - - // 3) Replace the current pres shell with a new shell for the new document - mPresShell->EndObservingDocument(); - - mPresShell = nsnull; - rv = newDoc->CreateShell(mPresContext, mViewManager, styleSet, - getter_AddRefs(mPresShell)); - if (NS_FAILED(rv)) return rv; - - mPresShell->BeginObservingDocument(); - - // 4) Register the focus listener on the new document - if(mDocument) - { - nsCOMPtr erP; - rv = mDocument->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), getter_AddRefs(erP)); - if(NS_FAILED(rv) || !erP) - return rv ? rv : NS_ERROR_FAILURE; - - rv = erP->AddEventListenerByIID(mFocusListener, NS_GET_IID(nsIDOMFocusListener)); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register focus listener"); - } - - return rv; -} - -NS_IMETHODIMP -DocumentViewerImpl::SetUAStyleSheet(nsIStyleSheet* aUAStyleSheet) -{ - mUAStyleSheet = dont_QueryInterface(aUAStyleSheet); - return NS_OK; -} - -NS_IMETHODIMP -DocumentViewerImpl::GetDocument(nsIDocument*& aResult) -{ - aResult = mDocument; - NS_IF_ADDREF(aResult); - return NS_OK; -} - -NS_IMETHODIMP -DocumentViewerImpl::GetPresShell(nsIPresShell*& aResult) -{ - aResult = mPresShell; - NS_IF_ADDREF(aResult); - return NS_OK; -} - -NS_IMETHODIMP -DocumentViewerImpl::GetPresContext(nsIPresContext*& aResult) -{ - aResult = mPresContext; - NS_IF_ADDREF(aResult); - return NS_OK; -} - -NS_IMETHODIMP -DocumentViewerImpl::GetBounds(nsRect& aResult) -{ - NS_PRECONDITION(mWindow, "null window"); - if (mWindow) { - mWindow->GetBounds(aResult); - } - else { - aResult.SetRect(0, 0, 0, 0); - } - return NS_OK; -} - -NS_IMETHODIMP -DocumentViewerImpl::SetBounds(const nsRect& aBounds) -{ - NS_PRECONDITION(mWindow, "null window"); - if (mWindow) { - // Don't have the widget repaint. Layout will generate repaint requests - // during reflow - mWindow->Resize(aBounds.x, aBounds.y, aBounds.width, aBounds.height, - PR_FALSE); - } - return NS_OK; -} - -NS_IMETHODIMP -DocumentViewerImpl::Move(PRInt32 aX, PRInt32 aY) -{ - NS_PRECONDITION(mWindow, "null window"); - if (mWindow) { - mWindow->Move(aX, aY); - } - return NS_OK; -} - -NS_IMETHODIMP -DocumentViewerImpl::Show(void) -{ - NS_PRECONDITION(mWindow, "null window"); - if (mWindow) { - mWindow->Show(PR_TRUE); - } - return NS_OK; -} - -NS_IMETHODIMP -DocumentViewerImpl::Hide(void) -{ - NS_PRECONDITION(mWindow, "null window"); - if (mWindow) { - mWindow->Show(PR_FALSE); - } - return NS_OK; -} - -nsresult -DocumentViewerImpl::FindFrameSetWithIID(nsIContent * aParentContent, const nsIID& aIID) -{ - PRInt32 numChildren; - aParentContent->ChildCount(numChildren); - - // do a breadth search across all siblings - PRInt32 inx; - for (inx=0;inx child; - if (NS_SUCCEEDED(aParentContent->ChildAt(inx, *getter_AddRefs(child))) && child) { - nsCOMPtr temp; - if (NS_SUCCEEDED(child->QueryInterface(aIID, (void**)getter_AddRefs(temp)))) { - return NS_OK; - } - } - } - - return NS_ERROR_FAILURE; -} - -//--------------------------------------------------------------- -//--------------------------------------------------------------- -//-- Debug helper routines -//--------------------------------------------------------------- -//--------------------------------------------------------------- -#if defined(DEBUG_rods) || defined(DEBUG_dcone) - -/** --------------------------------------------------- - * Dumps Frames for Printing - */ -static void DumpFrames(FILE* out, - nsIPresContext* aPresContext, - nsIRenderingContext * aRendContext, - nsIFrame * aFrame, - PRInt32 aLevel) -{ - nsIFrame * child; - aFrame->FirstChild(aPresContext, nsnull, &child); - while (child != nsnull) { - for (PRInt32 i=0;iQueryInterface(NS_GET_IID(nsIFrameDebug), (void**)&frameDebug))) { - frameDebug->GetFrameName(tmp); - } - fputs(tmp, out); - nsFrameState state; - child->GetFrameState(&state); - PRBool isSelected; - if (NS_SUCCEEDED(child->IsVisibleForPainting(aPresContext, *aRendContext, PR_TRUE, &isSelected))) { - fprintf(out, " %p %s", child, isSelected?"VIS":"UVS"); - nsRect rect; - child->GetRect(rect); - fprintf(out, "[%d,%d,%d,%d] ", rect.x, rect.y, rect.width, rect.height); - nsIView * view; - child->GetView(aPresContext, &view); - fprintf(out, "v: %p ", view); - fprintf(out, "\n"); - DumpFrames(out, aPresContext, aRendContext, child, aLevel+1); - child->GetNextSibling(&child); - } - } -} - -/** --------------------------------------------------- - * Helper function needed for "DumpViews" - */ -static nsIPresShell* -GetPresShellFor(nsIDocShell* aDocShell) -{ - nsIPresShell* shell = nsnull; - if (nsnull != aDocShell) { - nsIContentViewer* cv = nsnull; - aDocShell->GetContentViewer(&cv); - if (nsnull != cv) { - nsIDocumentViewer* docv = nsnull; - cv->QueryInterface(NS_GET_IID(nsIDocumentViewer), (void**) &docv); - if (nsnull != docv) { - nsIPresContext* cx; - docv->GetPresContext(cx); - if (nsnull != cx) { - cx->GetShell(&shell); - NS_RELEASE(cx); - } - NS_RELEASE(docv); - } - NS_RELEASE(cv); - } - } - return shell; -} - -/** --------------------------------------------------- - * Dumps the Views from the DocShell - */ -static void -DumpViews(nsIDocShell* aDocShell, FILE* out) -{ - if (nsnull != aDocShell) { - fprintf(out, "docshell=%p \n", aDocShell); - nsIPresShell* shell = GetPresShellFor(aDocShell); - if (nsnull != shell) { - nsCOMPtr vm; - shell->GetViewManager(getter_AddRefs(vm)); - if (vm) { - nsIView* root; - vm->GetRootView(root); - if (nsnull != root) { - root->List(out); - } - } - NS_RELEASE(shell); - } - else { - fputs("null pres shell\n", out); - } - - // dump the views of the sub documents - PRInt32 i, n; - nsCOMPtr docShellAsNode(do_QueryInterface(aDocShell)); - docShellAsNode->GetChildCount(&n); - for (i = 0; i < n; i++) { - nsCOMPtr child; - docShellAsNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - if (childAsShell) { - DumpViews(childAsShell, out); - } - } - } -} - -/** --------------------------------------------------- - * Dumps the Views and Frames - */ -void DumpLayoutData(nsIPresContext* aPresContext, - nsIDeviceContext * aDC, - nsIFrame * aRootFrame, - nsIWebShell * aWebShell) -{ - // Dump all the frames and view to a a file - FILE * fd = fopen("dump.txt", "w"); - if (fd) { - fprintf(fd, "--------------- Frames ----------------\n"); - nsCOMPtr renderingContext; - aDC->CreateRenderingContext(*getter_AddRefs(renderingContext)); - DumpFrames(fd, aPresContext, renderingContext, aRootFrame, 0); - fprintf(fd, "---------------------------------------\n\n"); - fprintf(fd, "--------------- Views From Root Frame----------------\n"); - nsIView * v; - aRootFrame->GetView(aPresContext, &v); - if (v) { - v->List(fd); - } else { - printf("View is null!\n"); - } - nsCOMPtr docShell(do_QueryInterface(aWebShell)); - if (docShell) { - fprintf(fd, "--------------- All Views ----------------\n"); - DumpViews(docShell, fd); - fprintf(fd, "---------------------------------------\n\n"); - } - fclose(fd); - } -} - -#endif -//--------------------------------------------------------------- -//--------------------------------------------------------------- -//-- End of debug helper routines -//--------------------------------------------------------------- -//--------------------------------------------------------------- - -/** --------------------------------------------------- - * Giving a child frame it searches "up" the tree until it - * finds a "Page" frame. - */ -static nsIFrame * GetPageFrame(nsIFrame * aFrame) -{ - nsIFrame * frame = aFrame; - while (frame != nsnull) { - nsCOMPtr type; - frame->GetFrameType(getter_AddRefs(type)); - if (type.get() == nsLayoutAtoms::pageFrame) { - return frame; - } - frame->GetParent(&frame); - } - return nsnull; -} - - -/** --------------------------------------------------- - * Find by checking content's tag type - */ -static nsIFrame * FindFrameByType(nsIPresContext* aPresContext, - nsIFrame * aParentFrame, - nsIAtom * aType, - nsRect& aRect, - nsRect& aChildRect) -{ - nsIFrame * child; - nsRect rect; - aParentFrame->GetRect(rect); - aRect.x += rect.x; - aRect.y += rect.y; - aParentFrame->FirstChild(aPresContext, nsnull, &child); - while (child != nsnull) { - nsCOMPtr content; - child->GetContent(getter_AddRefs(content)); - if (content) { - nsCOMPtr type; - content->GetTag(*getter_AddRefs(type)); - if (type.get() == aType) { - nsRect r; - child->GetRect(r); - aChildRect.SetRect(aRect.x + r.x, aRect.y + r.y, r.width, r.height); - aRect.x -= rect.x; - aRect.y -= rect.y; - return child; - } - } - nsIFrame * fndFrame = FindFrameByType(aPresContext, child, aType, aRect, aChildRect); - if (fndFrame != nsnull) { - return fndFrame; - } - child->GetNextSibling(&child); - } - aRect.x -= rect.x; - aRect.y -= rect.y; - return nsnull; -} - -/** --------------------------------------------------- - * Find by checking frames type - */ -static nsresult FindSelectionBounds(nsIPresContext* aPresContext, - nsIRenderingContext& aRC, - nsIFrame * aParentFrame, - nsRect& aRect, - nsIFrame *& aStartFrame, - nsRect& aStartRect, - nsIFrame *& aEndFrame, - nsRect& aEndRect) -{ - nsIFrame * child; - aParentFrame->FirstChild(aPresContext, nsnull, &child); - nsRect rect; - aParentFrame->GetRect(rect); - aRect.x += rect.x; - aRect.y += rect.y; - while (child != nsnull) { - nsFrameState state; - child->GetFrameState(&state); - // only leaf frames have this bit flipped - // then check the hard way - PRBool isSelected = (state & NS_FRAME_SELECTED_CONTENT) == NS_FRAME_SELECTED_CONTENT; - if (isSelected) { - if (NS_FAILED(child->IsVisibleForPainting(aPresContext, aRC, PR_TRUE, &isSelected))) { - return NS_ERROR_FAILURE; - } - } - - if (isSelected) { - nsRect r; - child->GetRect(r); - if (aStartFrame == nsnull) { - aStartFrame = child; - aStartRect.SetRect(aRect.x + r.x, aRect.y + r.y, r.width, r.height); - } else { - child->GetRect(r); - aEndFrame = child; - aEndRect.SetRect(aRect.x + r.x, aRect.y + r.y, r.width, r.height); - } - } - FindSelectionBounds(aPresContext, aRC, child, aRect, aStartFrame, aStartRect, aEndFrame, aEndRect); - child->GetNextSibling(&child); - } - aRect.x -= rect.x; - aRect.y -= rect.y; - return NS_OK; -} - -/** --------------------------------------------------- - * This method finds the starting and ending page numbers - * of the selection and also returns rect for each where - * the x,y of the rect is relative to the very top of the - * frame tree (absolutely positioned) - */ -static nsresult GetPageRangeForSelection(nsIPresShell * aPresShell, - nsIPresContext* aPresContext, - nsIRenderingContext& aRC, - nsISelection* aSelection, - nsIPageSequenceFrame* aPageSeqFrame, - nsIFrame** aStartFrame, - PRInt32& aStartPageNum, - nsRect& aStartRect, - nsIFrame** aEndFrame, - PRInt32& aEndPageNum, - nsRect& aEndRect) -{ - nsIFrame * seqFrame; - if (NS_FAILED(aPageSeqFrame->QueryInterface(NS_GET_IID(nsIFrame), (void **)&seqFrame))) { - return NS_ERROR_FAILURE; - } - - nsIFrame * startFrame = nsnull; - nsIFrame * endFrame = nsnull; - nsRect rect; - seqFrame->GetRect(rect); - - // start out with the sequence frame and search the entire frame tree - // capturing the the starting and ending child frames of the selection - // and their rects - FindSelectionBounds(aPresContext, aRC, seqFrame, rect, startFrame, aStartRect, endFrame, aEndRect); - -#ifdef DEBUG_rods - printf("Start Frame: %p\n", startFrame); - printf("End Frame: %p\n", endFrame); -#endif - - // initial the page numbers here - // in case we don't find and frames - aStartPageNum = -1; - aEndPageNum = -1; - - nsIFrame * startPageFrame; - nsIFrame * endPageFrame; - - // check to make sure we found a starting frame - if (startFrame != nsnull) { - // Now search up the tree to find what page the - // start/ending selections frames are on - // - // Check to see if start should be same as end if - // the end frame comes back null - if (endFrame == nsnull) { - // XXX the "GetPageFrame" step could be integrated into - // the FindSelectionBounds step, but walking up to find - // the parent of a child frame isn't expensive and it makes - // FindSelectionBounds a little easier to understand - startPageFrame = GetPageFrame(startFrame); - endPageFrame = startPageFrame; - aEndRect = aStartRect; - } else { - startPageFrame = GetPageFrame(startFrame); - endPageFrame = GetPageFrame(endFrame); - } - } else { - return NS_ERROR_FAILURE; - } - -#ifdef DEBUG_rods - printf("Start Page: %p\n", startPageFrame); - printf("End Page: %p\n", endPageFrame); - - // dump all the pages and their pointers - { - PRInt32 pageNum = 1; - nsIFrame * child; - seqFrame->FirstChild(aPresContext, nsnull, &child); - while (child != nsnull) { - printf("Page: %d - %p\n", pageNum, child); - pageNum++; - child->GetNextSibling(&child); - } - } -#endif - - // Now that we have the page frames - // find out what the page numbers are for each frame - PRInt32 pageNum = 1; - nsIFrame * page; - seqFrame->FirstChild(aPresContext, nsnull, &page); - while (page != nsnull) { - if (page == startPageFrame) { - aStartPageNum = pageNum; - } - if (page == endPageFrame) { - aEndPageNum = pageNum; - } - pageNum++; - page->GetNextSibling(&page); - } - -#ifdef DEBUG_rods - printf("Start Page No: %d\n", aStartPageNum); - printf("End Page No: %d\n", aEndPageNum); -#endif - - *aStartFrame = startPageFrame; - *aEndFrame = endPageFrame; - - return NS_OK; -} - -//------------------------------------------------------- -PRBool -DocumentViewerImpl::DoesContainFrameSet(nsIWebShell * aParent) -{ - // See if if the incoming doc is the root document - nsCOMPtr parentAsItem(do_QueryInterface(aParent)); - nsCOMPtr parentsParentDoc; - parentAsItem->GetParent(getter_AddRefs(parentsParentDoc)); - - // When it is the top level document we need to check - // to see if it contains a frameset. If it does, then - // we only want to print the doc's children and not the document itself - // For anything else we always print all the children and the document - // for example, if the doc contains an IFRAME we eant to print the child - // document (the IFRAME) and then the rest of the document. - // - // XXX we really need to search the frame tree, and not the content - // but there is no way to distinguish between IFRAMEs and FRAMEs - // with the GetFrameType call. - // Bug 53459 has been files so we can eventually distinguish - // between IFRAME frames and FRAME frames - PRBool doesContainFrameSet = PR_FALSE; - // only check to see if there is a frameset if there is - // NO parent doc for this doc. meaning this parent is the root doc - //if (!parentsParentDoc) { - nsCOMPtr shell; - mPresContext->GetShell(getter_AddRefs(shell)); - if (shell) { - nsCOMPtr doc; - shell->GetDocument(getter_AddRefs(doc)); - if (doc) { - nsCOMPtr rootContent = getter_AddRefs(doc->GetRootContent()); - if (rootContent) { - if (NS_SUCCEEDED(FindFrameSetWithIID(rootContent, NS_GET_IID(nsIDOMHTMLFrameSetElement)))) { - doesContainFrameSet = PR_TRUE; - } - } - } - } - //} - return doesContainFrameSet; -} - -//------------------------------------------------------- -PRUnichar* -DocumentViewerImpl::GetWebShellTitle(nsIWebShell * aWebShell) -{ - NS_ASSERTION(aWebShell != nsnull, "Must have a valid webshell!"); - - PRUnichar * docTitleStr = nsnull; - - nsCOMPtr docShell(do_QueryInterface(aWebShell)); - if (docShell) { - nsCOMPtr presShell; - docShell->GetPresShell(getter_AddRefs(presShell)); - if (presShell) { - nsCOMPtr doc; - presShell->GetDocument(getter_AddRefs(doc)); - if (doc) { - const nsString* docTitle = doc->GetDocumentTitle(); - if (docTitle != nsnull) { - docTitleStr = docTitle->ToNewUnicode(); - } - } - } - } - return docTitleStr; -} - -//------------------------------------------------------- -nsresult -DocumentViewerImpl::PrintContent(nsIWebShell * aParent, - nsIDeviceContext * aDContext, - nsIDOMWindow * aDOMWin, - PRBool aIsSubDoc) -{ - - NS_ENSURE_ARG_POINTER(aParent); - NS_ENSURE_ARG_POINTER(aDContext); - - nsCOMPtr ss; - nsCOMPtr vm; - PRInt32 width, height; - nsresult rv; - PRInt32 i; - nsCOMPtr viewer; - nsCOMPtr parentAsNode(do_QueryInterface(aParent)); - nsCOMPtr domWinIntl(do_QueryInterface(aDOMWin)); - - PRInt16 printFrameType = nsIPrintOptions::kSelectedFrame; // XXX later this default to kFramesAsIs - PRInt16 printHowEnable = nsIPrintOptions::kFrameEnableNone; - PRInt16 printRangeType = nsIPrintOptions::kRangeAllPages; - NS_WITH_SERVICE(nsIPrintOptions, printService, kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv) && printService) { - printService->GetPrintFrameType(&printFrameType); - printService->GetHowToEnableFrameUI(&printHowEnable); - printService->GetPrintRange(&printRangeType); - } - - - PRBool doesContainFrameSet; - PRBool isIFrameSelection = IsThereAnIFrameSelected(aParent, domWinIntl, doesContainFrameSet); - - PRBool isSelection = IsThereASelection(domWinIntl); - - // the root webshell is responsible for - // starting and ending the printing -#if SPOOL_TO_ONE_DOC // this will fix all frames being painted to the same spooling document - // (this part needs to be added) - if (aIsSubDoc == nsnull) { - PRUnichar *docTitleStr = GetWebShellTitle(aparent); - NS_ENSURE_SUCCESS( aDContext->BeginDocument(docTitleStr), NS_ERROR_FAILURE ); - if(docTitleStr) { - nsMemory::Free(docTitleStr); - } - } -#endif - - if (printFrameType == nsIPrintOptions::kFramesAsIs) { - // print frameset "as is " here and return - return NS_OK; - } - - // print any child documents - // like frameset frames or iframes - PRInt32 childWebshellCount; - parentAsNode->GetChildCount(&childWebshellCount); - if(childWebshellCount > 0) { - for(i=0;i child; - parentAsNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - childAsShell->GetContentViewer(getter_AddRefs(viewer)); - nsCOMPtr viewerFile(do_QueryInterface(viewer)); - if (viewerFile) { - nsCOMPtr childWebShell(do_QueryInterface(child)); - NS_ENSURE_SUCCESS(viewerFile->PrintContent(childWebShell, aDContext, aDOMWin, PR_TRUE), NS_ERROR_FAILURE); - } - } -#if SPOOL_TO_ONE_DOC // this will fix all frames being painted to the same spooling document - // (this part needs to be added) - if (aIsSubDoc == nsnull) { - aDContext->EndDocument(); - } -#endif - if (doesContainFrameSet || (!doesContainFrameSet && isIFrameSelection)) { - return NS_OK; - } - } - - //----------------------------------------------------- - // Now check to see if we can print this WebShell - //----------------------------------------------------- - - // Check to see if printing frames is not on - // and that we are printing a range or all pages - PRBool printAllPages = (printRangeType == nsIPrintOptions::kRangeAllPages || - printRangeType == nsIPrintOptions::kRangeSpecifiedPageRange) && - printHowEnable == nsIPrintOptions::kFrameEnableNone; - - // See if we are printing the selected frame - PRBool printEachFrame = printFrameType == nsIPrintOptions::kEachFrameSep; - - // This is for when the current root WebShell is a Frameset - // and we need to see if the webshell being passed in - // is the currently selected frame of the frameset - // - // The aDOMWin is the currently selected DOM window, - // which could be a frameset frame or a IFrame - PRBool thisWebShellIsSelected = PR_FALSE; - nsCOMPtr scriptObj(do_QueryInterface(aDOMWin)); - if (scriptObj) { - nsCOMPtr docShell; - scriptObj->GetDocShell(getter_AddRefs(docShell)); - if (docShell) { - nsCOMPtr webShellForParent(do_QueryInterface(docShell)); - if (webShellForParent.get() == aParent) { - thisWebShellIsSelected = PR_TRUE; - } - } - } - - // Check to make we can print the currently selected frame of a frameset - PRBool printSelectedFrame = thisWebShellIsSelected && - printFrameType == nsIPrintOptions::kSelectedFrame; - - // Now see if we can print the selected IFrame - // When IFrames are selected all the frame UI is turned off - // and theuser prints it by selected the "Selection" radiobutton - // which turns on kRangeSelection - PRBool printSelectedIFrame = PR_FALSE; - if (printHowEnable == nsIPrintOptions::kFrameEnableNone && - printRangeType == nsIPrintOptions::kRangeSelection && - thisWebShellIsSelected) { - printSelectedIFrame = PR_TRUE; - // check to see if we have a range selection, - // as oppose to a insert selection - // this means if the user just clicked on the IFrame then - // there will not be a selection so we want the entire page to print - // - // XXX this is sort of a hack right here to make the page - // not try to reposition itself when printing selection - if (!IsThereASelection(domWinIntl)) { - printRangeType = nsIPrintOptions::kRangeAllPages; - printService->SetPrintRange(printRangeType); - } - } - - - PRBool canPrintFrame = printAllPages || printEachFrame || printSelectedFrame || printSelectedIFrame; - - if (!aIsSubDoc || (aIsSubDoc && canPrintFrame)) { -#ifndef SPOOL_TO_ONE_DOC // this will fix all frames being painted to the same spooling document - // (this part needs to be removed) - - PRUnichar * docTitleStr = GetWebShellTitle(aParent); - NS_ENSURE_SUCCESS( aDContext->BeginDocument(docTitleStr), NS_ERROR_FAILURE ); - if (docTitleStr != nsnull) { - nsMemory::Free(docTitleStr); - } -#endif - - aDContext->GetDeviceSurfaceDimensions(width, height); - - // XXX - Hack Alert - // OK, so ther eis a selection, we will print the entire selection - // on one page and then crop the page. - // This means you can never print any selection that is longer than one page - // put it keeps it from page breaking in the middle of your print of the selection - // (see also nsSimplePageSequence.cpp) - if (IsThereASelection(domWinIntl)) { - height = 0x0FFFFFFF; - } - - nsCOMPtr cx; - nsCOMPtr printcon; - rv = NS_NewPrintContext(getter_AddRefs(printcon)); - if (NS_FAILED(rv)) { - return rv; - } else { - rv = printcon->QueryInterface(NS_GET_IID(nsIPresContext), getter_AddRefs(cx)); - if (NS_FAILED(rv)) { - return rv; - } - } - - cx->Init(aDContext); - - CreateStyleSet(mDocument, getter_AddRefs(ss)); - - nsCOMPtr ps; - rv = NS_NewPresShell(getter_AddRefs(ps)); - if (NS_FAILED(rv)) { - return rv; - } - - rv = nsComponentManager::CreateInstance(kViewManagerCID, - nsnull, - NS_GET_IID(nsIViewManager), - (void **)getter_AddRefs(vm)); - if (NS_FAILED(rv)) { - return rv; - } - rv = vm->Init(aDContext); - if (NS_FAILED(rv)) { - return rv; - } - - nsRect tbounds = nsRect(0, 0, width, height); - - // Create a child window of the parent that is our "root view/window" - nsIView* rootView; - rv = nsComponentManager::CreateInstance(kViewCID, nsnull, NS_GET_IID(nsIView), (void **)&rootView); - if (NS_FAILED(rv)) { - return rv; - } - rv = rootView->Init(vm, tbounds, nsnull); - if (NS_FAILED(rv)) { - return rv; - } - - // Setup hierarchical relationship in view manager - vm->SetRootView(rootView); - - ps->Init(mDocument, cx, vm, ss); - - nsCompatibility mode; - mPresContext->GetCompatibilityMode(&mode); - cx->SetCompatibilityMode(mode); - cx->SetContainer(aParent); - - - // get the old history - nsCOMPtr presShell; - nsCOMPtr layoutState; - NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE); - presShell->CaptureHistoryState(getter_AddRefs(layoutState),PR_TRUE); - - - ps->BeginObservingDocument(); - //lay it out... - ps->InitialReflow(width, height); - - // Transfer Selection Ranges to the new Print PresShell - nsCOMPtr selection; - nsCOMPtr selectionPS; - GetDocumentSelection(getter_AddRefs(selection)); - if (selection) { - GetDocumentSelection(getter_AddRefs(selectionPS), ps); - if (selectionPS) { - PRInt32 cnt; - selection->GetRangeCount(&cnt); - PRInt32 inx; - for (inx=0;inx range; - if (NS_SUCCEEDED(selection->GetRangeAt(inx, getter_AddRefs(range)))) { - selectionPS->AddRange(range); - } - } - } - } - - // update the history from the old presentation shell - nsCOMPtr fm; - rv = ps->GetFrameManager(getter_AddRefs(fm)); - if(NS_SUCCEEDED(rv) && fm) { - nsIFrame* root; - ps->GetRootFrame(&root); - fm->RestoreFrameState(cx, root, layoutState); - } - ps->EndObservingDocument(); - - // Ask the page sequence frame to print all the pages - nsIPageSequenceFrame* pageSequence; - - // - ps->GetPageSequenceFrame(&pageSequence); - NS_ASSERTION(nsnull != pageSequence, "no page sequence frame"); - - - if (nsnull != mFilePointer) { - // output the regression test - nsIFrameDebug* fdbg; - nsIFrame* root; - ps->GetRootFrame(&root); - - if (NS_SUCCEEDED(root->QueryInterface(NS_GET_IID(nsIFrameDebug), (void**) &fdbg))) { - fdbg->DumpRegressionData(cx, mFilePointer, 0, PR_TRUE); - } - fclose(mFilePointer); - } else { - nsIFrame* rootFrame; - ps->GetRootFrame(&rootFrame); - -#if defined(DEBUG_rods) || defined(DEBUG_dcone) - DumpLayoutData(cx, aDContext, rootFrame, aParent); -#endif - - if (printService) { - // get the document title - const nsString* docTitle = mDocument->GetDocumentTitle(); - if( docTitle != nsnull) { - PRUnichar * docStr = docTitle->ToNewUnicode(); - printService->SetTitle(docStr); - nsMemory::Free(docStr); - } - - // Get Document URL String - nsCOMPtr url(getter_AddRefs(mDocument->GetDocumentURL())); - char * urlCStr; - url->GetSpec(&urlCStr); - nsAutoString urlStr; - urlStr.AssignWithConversion(urlCStr); - PRUnichar * urlUStr = urlStr.ToNewUnicode(); - printService->SetDocURL(urlUStr); - nsMemory::Free(urlUStr); - nsMemory::Free(urlCStr); - - if (nsIPrintOptions::kRangeSelection == printRangeType) { - cx->SetIsRenderingOnlySelection(PR_TRUE); - - // temporarily creating rendering context - // which is needed to dinf the selection frames - nsCOMPtr rc; - aDContext->CreateRenderingContext(*getter_AddRefs(rc)); - - // find the starting and ending page numbers - // via the selection - nsIFrame* startFrame; - nsIFrame* endFrame; - PRInt32 startPageNum; - PRInt32 endPageNum; - nsRect startRect; - nsRect endRect; - rv = GetPageRangeForSelection(ps, cx, *rc, selectionPS, pageSequence, - &startFrame, startPageNum, startRect, - &endFrame, endPageNum, endRect); - if (NS_SUCCEEDED(rv)) { - printService->SetStartPageRange(startPageNum); - printService->SetEndPageRange(endPageNum); - if (startPageNum == endPageNum) { - nsIFrame * seqFrame; - if (NS_FAILED(pageSequence->QueryInterface(NS_GET_IID(nsIFrame), (void **)&seqFrame))) { - return NS_ERROR_FAILURE; - } - nsRect rect(0,0,0,0); - nsRect areaRect; - nsIFrame * areaFrame = FindFrameByType(cx, startFrame, nsHTMLAtoms::body, rect, areaRect); - if (areaFrame) { - areaRect.y = areaRect.y - startRect.y; - areaFrame->SetRect(cx, areaRect); - } - } - } - } - - nsIFrame * seqFrame; - if (NS_FAILED(pageSequence->QueryInterface(NS_GET_IID(nsIFrame), (void **)&seqFrame))) { - return NS_ERROR_FAILURE; - } - - nsRect srect; - seqFrame->GetRect(srect); - - nsRect r; - rootView->GetBounds(r); - r.height = srect.height; - rootView->SetBounds(r); - - rootFrame->GetRect(r); - r.height = srect.height; - rootFrame->SetRect(cx, r); - - pageSequence->Print(cx, printService, nsnull); - - } else { - // not sure what to do here! - return NS_ERROR_FAILURE; - } - } -#ifndef SPOOL_TO_ONE_DOC // this will fix all frames being painted to the same spooling document - // (this part needs to be removed) - aDContext->EndDocument(); -#endif - ps->EndObservingDocument(); - } - - if (printSelectedIFrame) { - printService->SetPrintRange(nsIPrintOptions::kRangeSelection); - } - -#if SPOOL_TO_ONE_DOC // this will fix all frames being painted to the same spooling document - // (this part needs to be added) - // Only root webshells/docs get to start and end - // the printing of the entire document - if (aIsSubDoc == nsnull) { - aDContext->EndDocument(); - } -#endif - - return NS_OK; - -} - -void DocumentViewerImpl::Notify(nsIImageGroup *aImageGroup, - nsImageGroupNotification aNotificationType) -{ - // - // Image are being loaded... Set the flag to delay printing until - // all images are loaded. - // - if (aNotificationType == nsImageGroupNotification_kStartedLoading) { - mIsPrinting = PR_TRUE; - } - // - // All the images have been loaded, so the document is ready to print. - // - // However, at this point we are unable to release the resources that - // were allocated for printing... This is because ImgLib resources will - // be deleted and *this* is an ImgLib notification routine. So, fire an - // event to do the actual printing. - // - else if(aNotificationType == nsImageGroupNotification_kFinishedLoading) { - nsresult rv; - nsCOMPtr eventQ; - - // Get the event queue of the current thread... - NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv); - if (NS_FAILED(rv)) return; - - rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, - getter_AddRefs(eventQ)); - if (NS_FAILED(rv)) return; - - PRStatus status; - PLEvent *event = new PLEvent; - - if (!event) return; - - // - // AddRef this because it is being placed in the PLEvent struct. - // It will be Released when DestroyPLEvent is called... - // - NS_ADDREF_THIS(); - PL_InitEvent(event, - this, - (PLHandleEventProc) DocumentViewerImpl::HandlePLEvent, - (PLDestroyEventProc) DocumentViewerImpl::DestroyPLEvent); - - status = eventQ->PostEvent(event); - } -} - - -NS_IMETHODIMP -DocumentViewerImpl::SetEnableRendering(PRBool aOn) -{ - mEnableRendering = aOn; - if (mViewManager) { - if (aOn) { - mViewManager->EnableRefresh(NS_VMREFRESH_IMMEDIATE); - nsIView* view; - mViewManager->GetRootView(view); // views are not refCounted - if (view) { - mViewManager->UpdateView(view, NS_VMREFRESH_IMMEDIATE); - } - } - else { - mViewManager->DisableRefresh(); - } - } - return NS_OK; -} - -NS_IMETHODIMP -DocumentViewerImpl::GetEnableRendering(PRBool* aResult) -{ - NS_PRECONDITION(nsnull != aResult, "null OUT ptr"); - if (aResult) { - *aResult = mEnableRendering; - } - return NS_OK; -} - -void -DocumentViewerImpl::ForceRefresh() -{ - mWindow->Invalidate(PR_TRUE); -} - -nsresult -DocumentViewerImpl::CreateStyleSet(nsIDocument* aDocument, - nsIStyleSet** aStyleSet) -{ - // this should eventually get expanded to allow for creating - // different sets for different media - nsresult rv; - - if (!mUAStyleSheet) { - NS_WARNING("unable to load UA style sheet"); - } - - rv = NS_NewStyleSet(aStyleSet); - if (NS_OK == rv) { - PRInt32 index = aDocument->GetNumberOfStyleSheets(); - - while (0 < index--) { - nsCOMPtr sheet(getter_AddRefs(aDocument->GetStyleSheetAt(index))); - - /* - * GetStyleSheetAt will return all style sheets in the document but - * we're only interested in the ones that are enabled. - */ - - PRBool styleEnabled; - sheet->GetEnabled(styleEnabled); - - if (styleEnabled) { - (*aStyleSet)->AddDocStyleSheet(sheet, aDocument); - } - } - - NS_WITH_SERVICE(nsIChromeRegistry, chromeRegistry, "@mozilla.org/chrome/chrome-registry;1", &rv); - if (NS_SUCCEEDED(rv) && chromeRegistry) { - nsCOMPtr sheets; - chromeRegistry->GetBackstopSheets(getter_AddRefs(sheets)); - if(sheets){ - nsCOMPtr sheet; - PRUint32 count; - sheets->Count(&count); - for(PRUint32 i=0; iGetElementAt(i, getter_AddRefs(sheet)); - (*aStyleSet)->AppendBackstopStyleSheet(sheet); - } - } - - // Now handle the user sheets. - nsCOMPtr docShell(do_QueryInterface(mContainer)); - PRInt32 shellType; - docShell->GetItemType(&shellType); - PRBool isChrome = (shellType == nsIDocShellTreeItem::typeChrome); - sheets = nsnull; - chromeRegistry->GetUserSheets(isChrome, getter_AddRefs(sheets)); - if(sheets){ - nsCOMPtr sheet; - PRUint32 count; - sheets->Count(&count); - for(PRUint32 i=0; iGetElementAt(i, getter_AddRefs(sheet)); - // XXX For now, append as backstop until we figure out something - // better to do. - (*aStyleSet)->AppendBackstopStyleSheet(sheet); - } - } - } - - if (mUAStyleSheet) { - (*aStyleSet)->AppendBackstopStyleSheet(mUAStyleSheet); - } - } - return NS_OK; -} - -nsresult -DocumentViewerImpl::MakeWindow(nsIWidget* aParentWidget, - const nsRect& aBounds) -{ - nsresult rv; - - rv = nsComponentManager::CreateInstance(kViewManagerCID, - nsnull, - NS_GET_IID(nsIViewManager), - getter_AddRefs(mViewManager)); - - nsCOMPtr dx; - mPresContext->GetDeviceContext(getter_AddRefs(dx)); - - - nsRect tbounds = aBounds; - float p2t; - mPresContext->GetPixelsToTwips(&p2t); - tbounds *= p2t; - - // Initialize the view manager with an offset. This allows the viewmanager - // to manage a coordinate space offset from (0,0) - if ((NS_OK != rv) || (NS_OK != mViewManager->Init(dx, tbounds.x, tbounds.y))) { - return rv; - } - // Reset the bounds offset so the root view is set to 0,0. The offset is - // specified in nsIViewManager::Init above. - // Besides, layout will reset the root view to (0,0) during reflow, - // so changing it to 0,0 eliminates placing - // the root view in the wrong place initially. - tbounds.x = 0; - tbounds.y = 0; - - // Create a child window of the parent that is our "root view/window" - // Create a view - rv = nsComponentManager::CreateInstance(kViewCID, - nsnull, - NS_GET_IID(nsIView), - (void**)&mView); - if ((NS_OK != rv) || (NS_OK != mView->Init(mViewManager, - tbounds, - nsnull))) { - return rv; - } - - rv = mView->CreateWidget(kWidgetCID, nsnull, aParentWidget->GetNativeData(NS_NATIVE_WIDGET)); - - if (rv != NS_OK) - return rv; - - // Setup hierarchical relationship in view manager - mViewManager->SetRootView(mView); - - mView->GetWidget(*getter_AddRefs(mWindow)); - - // This SetFocus is necessary so the Arrow Key and Page Key events - // go to the scrolled view as soon as the Window is created instead of going to - // the browser window (this enables keyboard scrolling of the document) - // mWindow->SetFocus(); - - return rv; -} - -nsresult DocumentViewerImpl::GetDocumentSelection(nsISelection **aSelection, nsIPresShell * aPresShell) -{ - if (aPresShell == nsnull) { - if (!mPresShell) { - return NS_ERROR_NOT_INITIALIZED; - } - aPresShell = mPresShell; - } - if (!aSelection) return NS_ERROR_NULL_POINTER; - if (!aPresShell) return NS_ERROR_NULL_POINTER; - - nsCOMPtr selcon; - selcon = do_QueryInterface(aPresShell); - if (selcon) - return selcon->GetSelection(nsISelectionController::SELECTION_NORMAL, aSelection); - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -DocumentViewerImpl::CreateDocumentViewerUsing(nsIPresContext* aPresContext, - nsIDocumentViewer*& aResult) -{ - if (!mDocument) { - // XXX better error - return NS_ERROR_NULL_POINTER; - } - if (nsnull == aPresContext) { - return NS_ERROR_NULL_POINTER; - } - - // Create new viewer - DocumentViewerImpl* viewer = new DocumentViewerImpl(aPresContext); - if (nsnull == viewer) { - return NS_ERROR_OUT_OF_MEMORY; - } - NS_ADDREF(viewer); - - // XXX make sure the ua style sheet is used (for now; need to be - // able to specify an alternate) - viewer->SetUAStyleSheet(mUAStyleSheet); - - // Bind the new viewer to the old document - nsresult rv = viewer->BindToDocument(mDocument, "create");/* XXX verb? */ - - aResult = viewer; - - return rv; -} - - - -void PR_CALLBACK DocumentViewerImpl::HandlePLEvent(PLEvent* aEvent) -{ - DocumentViewerImpl *viewer; - - viewer = (DocumentViewerImpl*)PL_GetEventOwner(aEvent); - - NS_ASSERTION(viewer, "The event owner is null."); - if (viewer) { - viewer->DocumentReadyForPrinting(); - } -} - -void PR_CALLBACK DocumentViewerImpl::DestroyPLEvent(PLEvent* aEvent) -{ - DocumentViewerImpl *viewer; - - viewer = (DocumentViewerImpl*)PL_GetEventOwner(aEvent); - NS_IF_RELEASE(viewer); - - delete aEvent; -} - - -void DocumentViewerImpl::DocumentReadyForPrinting() -{ -nsCOMPtr webContainer; - - webContainer = do_QueryInterface(mContainer); - if(webContainer) { - // - // Remove ourselves as an image group observer... - // - nsCOMPtr imageGroup; - mPrintPC->GetImageGroup(getter_AddRefs(imageGroup)); - if (imageGroup) { - imageGroup->RemoveObserver(this); - } - - // get the focused DOMWindow - nsCOMPtr curFocusDOMWin = getter_AddRefs(FindFocusedDOMWindowInternal()); - nsCOMPtr domWin(do_QueryInterface(curFocusDOMWin)); - - // - // Send the document to the printer... - // - - - nsresult rv = PrintContent(webContainer, mPrintDC, domWin, PR_FALSE); - NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "bad result from PrintConent"); - - // printing is complete, clean up now - mIsPrinting = PR_FALSE; - - mPrintPS->EndObservingDocument(); - - if (mPrintListener) - mPrintListener->OnEndPrinting(NS_OK); - - NS_RELEASE(mPrintPS); - NS_RELEASE(mPrintVM); - NS_RELEASE(mPrintSS); - NS_RELEASE(mPrintDC); - NS_RELEASE(mPrintPC); - } -} - -NS_IMETHODIMP -DocumentViewerImpl::SetTransformMediator(nsITransformMediator* aMediator) -{ - NS_ASSERTION(nsnull == mTransformMediator, "nsXMLDocument::SetTransformMediator(): \ - Cannot set a second transform mediator\n"); - mTransformMediator = aMediator; - return NS_OK; -} - -#ifdef XP_MAC -#pragma mark - -#endif - -/* ======================================================================================== - * nsIContentViewerEdit - * ======================================================================================== */ - -NS_IMETHODIMP DocumentViewerImpl::Search() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP DocumentViewerImpl::GetSearchable(PRBool *aSearchable) -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP DocumentViewerImpl::ClearSelection() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP DocumentViewerImpl::SelectAll() -{ - // XXX this is a temporary implementation copied from nsWebShell - // for now. I think nsDocument and friends should have some helper - // functions to make this easier. - nsCOMPtr selection; - nsresult rv; - rv = GetDocumentSelection(getter_AddRefs(selection)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr htmldoc = do_QueryInterface(mDocument); - nsCOMPtr bodyNode; - - if (htmldoc) - { - nsCOMPtrbodyElement; - rv = htmldoc->GetBody(getter_AddRefs(bodyElement)); - if (NS_FAILED(rv) || !bodyElement) return rv; - - bodyNode = do_QueryInterface(bodyElement); - } - else if (mDocument) - { - nsCOMPtr rootContent = getter_AddRefs(mDocument->GetRootContent()); - bodyNode = do_QueryInterface(rootContent); - } - if (!bodyNode) return NS_ERROR_FAILURE; - - rv = selection->RemoveAllRanges(); - if (NS_FAILED(rv)) return rv; - - static NS_DEFINE_CID(kCDOMRangeCID, NS_RANGE_CID); - nsCOMPtr range; - rv = nsComponentManager::CreateInstance(kCDOMRangeCID, nsnull, - NS_GET_IID(nsIDOMRange), - getter_AddRefs(range)); - - rv = range->SelectNodeContents(bodyNode); - if (NS_FAILED(rv)) return rv; - - rv = selection->AddRange(range); - return rv; -} - -NS_IMETHODIMP DocumentViewerImpl::CopySelection() -{ - if (!mPresShell) return NS_ERROR_NOT_INITIALIZED; - return mPresShell->DoCopy(); -} - -NS_IMETHODIMP DocumentViewerImpl::GetCopyable(PRBool *aCopyable) -{ - nsCOMPtr selection; - nsresult rv; - rv = GetDocumentSelection(getter_AddRefs(selection)); - if (NS_FAILED(rv)) return rv; - - PRBool isCollapsed; - selection->GetIsCollapsed(&isCollapsed); - - *aCopyable = !isCollapsed; - return NS_OK; -} - -NS_IMETHODIMP DocumentViewerImpl::CutSelection() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP DocumentViewerImpl::GetCutable(PRBool *aCutable) -{ - *aCutable = PR_FALSE; // mm, will this ever be called for an editable document? - return NS_OK; -} - -NS_IMETHODIMP DocumentViewerImpl::Paste() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP DocumentViewerImpl::GetPasteable(PRBool *aPasteable) -{ - *aPasteable = PR_FALSE; - return NS_OK; -} - -#ifdef XP_MAC -#pragma mark - -#endif - -/* ======================================================================================== - * nsIContentViewerFile - * ======================================================================================== */ -NS_IMETHODIMP -DocumentViewerImpl::Save() -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -DocumentViewerImpl::GetSaveable(PRBool *aSaveable) -{ - NS_ASSERTION(0, "NOT IMPLEMENTED"); - return NS_ERROR_NOT_IMPLEMENTED; -} - -static NS_DEFINE_IID(kDeviceContextSpecFactoryCID, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID); - -nsresult DocumentViewerImpl::GetSelectionDocument(nsIDeviceContextSpec * aDevSpec, nsIDocument ** aNewDoc) -{ - //NS_ENSURE_ARG_POINTER(*aDevSpec); - NS_ENSURE_ARG_POINTER(aNewDoc); - - // create document - nsCOMPtr doc; - nsresult rv = NS_NewHTMLDocument(getter_AddRefs(doc)); - if (NS_FAILED(rv)) { return rv; } - if (!doc) { return NS_ERROR_NULL_POINTER; } - - nsCOMPtr nimgr; - rv = doc->GetNodeInfoManager(*getter_AddRefs(nimgr)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr nodeInfo; - nimgr->GetNodeInfo(nsHTMLAtoms::html, nsnull, kNameSpaceID_None, - *getter_AddRefs(nodeInfo)); - - // create document content - nsCOMPtr htmlElement; - nsCOMPtr headElement; - nsCOMPtr bodyElement; - // create the root - rv = NS_NewHTMLHtmlElement(getter_AddRefs(htmlElement), nodeInfo); - if (NS_FAILED(rv)) { return rv; } - if (!htmlElement) { return NS_ERROR_NULL_POINTER; } - // create the head - - nimgr->GetNodeInfo(NS_ConvertASCIItoUCS2("head"), nsnull, - kNameSpaceID_None, *getter_AddRefs(nodeInfo)); - - rv = NS_NewHTMLHeadElement(getter_AddRefs(headElement), nodeInfo); - if (NS_FAILED(rv)) { return rv; } - if (!headElement) { return NS_ERROR_NULL_POINTER; } - headElement->SetDocument(doc, PR_FALSE, PR_TRUE); - // create the body - - nimgr->GetNodeInfo(nsHTMLAtoms::body, nsnull, kNameSpaceID_None, - *getter_AddRefs(nodeInfo)); - - rv = NS_NewHTMLBodyElement(getter_AddRefs(bodyElement), nodeInfo); - if (NS_FAILED(rv)) { return rv; } - if (!bodyElement) { return NS_ERROR_NULL_POINTER; } - bodyElement->SetDocument(doc, PR_FALSE, PR_TRUE); - // put the head and body into the root - rv = htmlElement->AppendChildTo(headElement, PR_FALSE); - if (NS_FAILED(rv)) { return rv; } - rv = htmlElement->AppendChildTo(bodyElement, PR_FALSE); - if (NS_FAILED(rv)) { return rv; } - - // load the document into the docshell - nsCOMPtr domDoc = do_QueryInterface(doc); - if (!domDoc) { return NS_ERROR_NULL_POINTER; } - nsCOMPtr htmlDOMElement = do_QueryInterface(htmlElement); - if (!htmlDOMElement) { return NS_ERROR_NULL_POINTER; } - - //nsCOMPtr rootContent(do_QueryInterface(htmlElement)); - //doc->SetRootContent(rootContent); - - *aNewDoc = doc.get(); - NS_ADDREF(*aNewDoc); - - return rv; - -} - -PRBool -DocumentViewerImpl::IsThereAnIFrameSelected(nsIWebShell* aWebShell, - nsIDOMWindowInternal * aDOMWin, - PRBool& aDoesContainFrameset) -{ - aDoesContainFrameset = DoesContainFrameSet(aWebShell); - PRBool iFrameIsSelected = PR_FALSE; - // First, check to see if we are a frameset - if (!aDoesContainFrameset) { - // Check to see if there is a currenlt focused frame - // if so, it means the selected frame is either the main webshell - // or an IFRAME - if (aDOMWin != nsnull) { - // Get the main webshell's DOMWin to see if it matches - // the frame that is selected - nsIDOMWindow* theDOMWindow = GetDOMWindowForThisDV(); - if (aDOMWin != nsnull && theDOMWindow != aDOMWin) { - // we have a selected IFRAME - iFrameIsSelected = PR_TRUE; - } - NS_IF_RELEASE(theDOMWindow); - } - } - return iFrameIsSelected; -} - - -PRBool -DocumentViewerImpl::IsThereASelection(nsIDOMWindowInternal * aDOMWin) -{ - nsCOMPtr presShell; - if (aDOMWin != nsnull) { - nsCOMPtr scriptObj(do_QueryInterface(aDOMWin)); - nsCOMPtr docShell; - scriptObj->GetDocShell(getter_AddRefs(docShell)); - docShell->GetPresShell(getter_AddRefs(presShell)); - } - - // check here to see if there is a range selection - // so we know whether to turn on the "Selection" radio button - nsCOMPtr selection; - GetDocumentSelection(getter_AddRefs(selection), presShell); - if (selection) { - PRInt32 count; - selection->GetRangeCount(&count); - if (count == 1) { - nsCOMPtr range; - if (NS_SUCCEEDED(selection->GetRangeAt(0, getter_AddRefs(range)))) { - // check to make sure it isn't an insertion selection - PRBool isCollapsed; - selection->GetIsCollapsed(&isCollapsed); - return !isCollapsed; - } - } - } - return PR_FALSE; -} - -/** --------------------------------------------------- - * See documentation above in the nsIContentViewerfile class definition - * @update 01/24/00 dwc - */ -NS_IMETHODIMP -DocumentViewerImpl::Print(PRBool aSilent,FILE *aFile, nsIPrintListener *aPrintListener) -{ - nsCOMPtr webContainer; - nsCOMPtr factory; - PRInt32 width,height; - - nsCOMPtr curFocusDOMWin = getter_AddRefs(FindFocusedDOMWindowInternal()); - - // Get the webshell for this documentviewer - webContainer = do_QueryInterface(mContainer); - - // first check to see if there is a "regular" selection - PRBool isSelection = IsThereASelection(curFocusDOMWin); - - // Get whether the doc contains a frameset - // Also, check to see if the currently focus webshell - // is a child of this webshell - PRBool doesContainFrameSet; - PRBool isIFrameSelection = IsThereAnIFrameSelected(webContainer, curFocusDOMWin, doesContainFrameSet); - - // Setup print options for UI - nsresult rv = NS_ERROR_FAILURE; - NS_WITH_SERVICE(nsIPrintOptions, printService, kPrintOptionsCID, &rv); - if (NS_SUCCEEDED(rv) && printService) { - if (doesContainFrameSet) { - if (curFocusDOMWin) { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAll); - } else { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableAsIsAndEach); - } - } else { - printService->SetHowToEnableFrameUI(nsIPrintOptions::kFrameEnableNone); - } - // Now determine how to set up the Frame print UI - printService->SetPrintOptions(nsIPrintOptions::kPrintOptionsEnableSelectionRB, isSelection || isIFrameSelection); - } - - nsComponentManager::CreateInstance(kDeviceContextSpecFactoryCID, - nsnull, - NS_GET_IID(nsIDeviceContextSpecFactory), - (void **)getter_AddRefs(factory)); - - if (factory) { - -#ifdef DEBUG_dcone - printf("PRINT JOB STARTING\n"); -#endif - - nsIDeviceContextSpec *devspec = nsnull; - nsCOMPtr dx; - mPrintDC = nsnull; - mFilePointer = aFile; - - factory->CreateDeviceContextSpec(mWindow, devspec, aSilent); - if (nsnull != devspec) { - mPresContext->GetDeviceContext(getter_AddRefs(dx)); - rv = dx->GetDeviceContextFor(devspec, mPrintDC); - if (NS_SUCCEEDED(rv)) { - - NS_RELEASE(devspec); - - if(webContainer) { - // load the document and do the initial reflow on the entire document - nsCOMPtr printcon; - rv = NS_NewPrintContext(getter_AddRefs(printcon)); - if (NS_FAILED(rv)) { - return rv; - } else { - rv = printcon->QueryInterface(NS_GET_IID(nsIPresContext), (void**)&mPrintPC); - if (NS_FAILED(rv)) { - return rv; - } - } - - - mPrintDC->GetDeviceSurfaceDimensions(width,height); - // XXX - Hack Alert - // OK, so ther eis a selection, we will print the entire selection - // on one page and then crop the page. - // This means you can never print any selection that is longer than one page - // put it keeps it from page breaking in the middle of your print of the selection - if (isSelection) { - height = 0x0FFFFFFF; - } - - mPrintPC->Init(mPrintDC); - mPrintPC->SetContainer(webContainer); - CreateStyleSet(mDocument,&mPrintSS); - - rv = NS_NewPresShell(&mPrintPS); - if(NS_FAILED(rv)){ - return rv; - } - - rv = nsComponentManager::CreateInstance(kViewManagerCID, nsnull, NS_GET_IID(nsIViewManager),(void**)&mPrintVM); - if(NS_FAILED(rv)) { - return rv; - } - - rv = mPrintVM->Init(mPrintDC); - if(NS_FAILED(rv)) { - return rv; - } - - rv = nsComponentManager::CreateInstance(kViewCID, nsnull, NS_GET_IID(nsIView),(void**)&mPrintView); - if(NS_FAILED(rv)) { - return rv; - } - - nsRect tbounds = nsRect(0,0,width,height); - rv = mPrintView->Init(mPrintVM,tbounds,nsnull); - if(NS_FAILED(rv)) { - return rv; - } - - // setup hierarchical relationship in view manager - mPrintVM->SetRootView(mPrintView); - mPrintPS->Init(mDocument,mPrintPC,mPrintVM,mPrintSS); - - nsCOMPtr imageGroup; - mPrintPC->GetImageGroup(getter_AddRefs(imageGroup)); - if (imageGroup) { - imageGroup->AddObserver(this); - } - - mPrintPS->InitialReflow(width,height); - -#ifdef DEBUG_dcone - float a1,a2; - PRInt32 i1,i2; - - printf("CRITICAL PRINTING INFORMATION\n"); - printf("PRESSHELL(%x) PRESCONTEXT(%x)\nVIEWMANAGER(%x) VIEW(%x)\n", - mPrintPS, mPrintPC,mPrintDC,mPrintVM,mPrintView); - - // DEVICE CONTEXT INFORMATION from PresContext - printf("DeviceContext of Presentation Context(%x)\n",dx); - dx->GetDevUnitsToTwips(a1); - dx->GetTwipsToDevUnits(a2); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - dx->GetAppUnitsToDevUnits(a1); - dx->GetDevUnitsToAppUnits(a2); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - dx->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - dx->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - dx->GetZoom(a1); - printf(" Zoom = %f\n",a1); - dx->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - dx->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); - - - // DEVICE CONTEXT INFORMATION - printf("DeviceContext created for print(%x)\n",mPrintDC); - mPrintDC->GetDevUnitsToTwips(a1); - mPrintDC->GetTwipsToDevUnits(a2); - printf(" DevToTwips = %f TwipToDev = %f\n",a1,a2); - mPrintDC->GetAppUnitsToDevUnits(a1); - mPrintDC->GetDevUnitsToAppUnits(a2); - printf(" AppUnitsToDev = %f DevUnitsToApp = %f\n",a1,a2); - mPrintDC->GetCanonicalPixelScale(a1); - printf(" GetCanonicalPixelScale = %f\n",a1); - mPrintDC->GetScrollBarDimensions(a1, a2); - printf(" ScrollBar x = %f y = %f\n",a1,a2); - mPrintDC->GetZoom(a1); - printf(" Zoom = %f\n",a1); - mPrintDC->GetDepth((PRUint32&)i1); - printf(" Depth = %d\n",i1); - mPrintDC->GetDeviceSurfaceDimensions(i1,i2); - printf(" DeviceDimension w = %d h = %d\n",i1,i2); - -#endif - // Print listener setup... - if (aPrintListener) - { - mPrintListener = aPrintListener; - mPrintListener->OnStartPrinting(); - /* RICHIE mPrintListener->OnProgressPrinting(PRUint32 aProgress, PRUint32 aProgressMax); */ - } - - // - // The mIsPrinting flag is set when the ImageGroup observer is - // notified that images must be loaded as a result of the - // InitialReflow... - // - if(!mIsPrinting){ - DocumentReadyForPrinting(); -#ifdef DEBUG_dcone - printf("PRINT JOB ENDING, OBSERVER WAS NOT CALLED\n"); -#endif - } else { - // use the observer mechanism to finish the printing -#ifdef DEBUG_dcone - printf("PRINTING OBSERVER STARTED\n"); -#endif - } - } - } - } - else - { - return NS_ERROR_FAILURE; - } - - } - - return NS_OK; -} - - -NS_IMETHODIMP -DocumentViewerImpl::GetPrintable(PRBool *aPrintable) -{ - NS_ENSURE_ARG_POINTER(aPrintable); - - *aPrintable = PR_TRUE; - return NS_OK; -} - -#ifdef XP_MAC -#pragma mark - -#endif - -//***************************************************************************** -// nsIMarkupDocumentViewer -//***************************************************************************** - -NS_IMETHODIMP DocumentViewerImpl::ScrollToNode(nsIDOMNode* aNode) -{ - NS_ENSURE_ARG(aNode); - nsCOMPtr presShell; - NS_ENSURE_SUCCESS(GetPresShell(*(getter_AddRefs(presShell))), NS_ERROR_FAILURE); - - // Get the nsIContent interface, because that's what we need to - // get the primary frame - - nsCOMPtr content(do_QueryInterface(aNode)); - NS_ENSURE_TRUE(content, NS_ERROR_FAILURE); - - // Get the primary frame - nsIFrame* frame; // Remember Frames aren't ref-counted. They are in their - // own special little world. - - NS_ENSURE_SUCCESS(presShell->GetPrimaryFrameFor(content, &frame), - NS_ERROR_FAILURE); - - // tell the pres shell to scroll to the frame - NS_ENSURE_SUCCESS(presShell->ScrollFrameIntoView(frame, - NS_PRESSHELL_SCROLL_TOP, - NS_PRESSHELL_SCROLL_ANYWHERE), - NS_ERROR_FAILURE); - return NS_OK; -} - -NS_IMETHODIMP DocumentViewerImpl::GetAllowPlugins(PRBool* aAllowPlugins) -{ - NS_ENSURE_ARG_POINTER(aAllowPlugins); - - *aAllowPlugins = mAllowPlugins; - return NS_OK; -} - -NS_IMETHODIMP DocumentViewerImpl::SetAllowPlugins(PRBool aAllowPlugins) -{ - mAllowPlugins = aAllowPlugins; - return NS_OK; -} - -nsresult -DocumentViewerImpl::CallChildren(CallChildFunc aFunc, void* aClosure) -{ - nsCOMPtr docShellNode(do_QueryInterface(mContainer)); - if (docShellNode) - { - PRInt32 i; - PRInt32 n; - docShellNode->GetChildCount(&n); - for (i=0; i < n; i++) - { - nsCOMPtr child; - docShellNode->GetChildAt(i, getter_AddRefs(child)); - nsCOMPtr childAsShell(do_QueryInterface(child)); - NS_ASSERTION(childAsShell, "null child in docshell"); - if (childAsShell) - { - nsCOMPtr childCV; - childAsShell->GetContentViewer(getter_AddRefs(childCV)); - if (childCV) - { - nsCOMPtr markupCV = do_QueryInterface(childCV); - if (markupCV) { - (*aFunc)(markupCV, aClosure); - } - } - } - } - } - return NS_OK; -} - -struct TextZoomInfo -{ - float mTextZoom; -}; - -static void -SetChildTextZoom(nsIMarkupDocumentViewer* aChild, void* aClosure) -{ - struct TextZoomInfo* textZoomInfo = (struct TextZoomInfo*) aClosure; - aChild->SetTextZoom(textZoomInfo->mTextZoom); -} - -NS_IMETHODIMP DocumentViewerImpl::SetTextZoom(float aTextZoom) -{ - if (mDeviceContext) { - mDeviceContext->SetTextZoom(aTextZoom); - if (mPresContext) { - mPresContext->RemapStyleAndReflow(); - } - } - - // now set the text zoom on all children of mContainer - struct TextZoomInfo textZoomInfo = { aTextZoom }; - return CallChildren(SetChildTextZoom, &textZoomInfo); -} - -NS_IMETHODIMP DocumentViewerImpl::GetTextZoom(float* aTextZoom) -{ - NS_ENSURE_ARG_POINTER(aTextZoom); - - if (mDeviceContext) { - return mDeviceContext->GetTextZoom(*aTextZoom); - } - - *aTextZoom = 1.0; - return NS_OK; -} - -// XXX: SEMANTIC CHANGE! -// returns a copy of the string. Caller is responsible for freeing result -// using Recycle(aDefaultCharacterSet) -NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(PRUnichar** aDefaultCharacterSet) -{ - NS_ENSURE_ARG_POINTER(aDefaultCharacterSet); - NS_ENSURE_STATE(mContainer); - - static PRUnichar *gDefCharset = nsnull; // XXX: memory leak! - - if (0 == mDefaultCharacterSet.Length()) - { - if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) - { - nsCOMPtr webShell; - webShell = do_QueryInterface(mContainer); - if (webShell) - { - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - if(prefs) - prefs->GetLocalizedUnicharPref("intl.charset.default", &gDefCharset); - } - } - if ((nsnull == gDefCharset) || (nsnull == *gDefCharset)) - mDefaultCharacterSet.AssignWithConversion("ISO-8859-1"); - else - mDefaultCharacterSet.Assign(gDefCharset); - } - *aDefaultCharacterSet = mDefaultCharacterSet.ToNewUnicode(); - return NS_OK; -} - -static void -SetChildDefaultCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure) -{ - aChild->SetDefaultCharacterSet((PRUnichar*) aClosure); -} - -NS_IMETHODIMP DocumentViewerImpl::SetDefaultCharacterSet(const PRUnichar* aDefaultCharacterSet) -{ - mDefaultCharacterSet = aDefaultCharacterSet; // this does a copy of aDefaultCharacterSet - // now set the default char set on all children of mContainer - return CallChildren(SetChildDefaultCharacterSet, - (void*) aDefaultCharacterSet); -} - -// XXX: SEMANTIC CHANGE! -// returns a copy of the string. Caller is responsible for freeing result -// using Recycle(aForceCharacterSet) -NS_IMETHODIMP DocumentViewerImpl::GetForceCharacterSet(PRUnichar** aForceCharacterSet) -{ - NS_ENSURE_ARG_POINTER(aForceCharacterSet); - - nsAutoString emptyStr; - if (mForceCharacterSet.Equals(emptyStr)) { - *aForceCharacterSet = nsnull; - } - else { - *aForceCharacterSet = mForceCharacterSet.ToNewUnicode(); - } - return NS_OK; -} - -static void -SetChildForceCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure) -{ - aChild->SetForceCharacterSet((PRUnichar*) aClosure); -} - -NS_IMETHODIMP DocumentViewerImpl::SetForceCharacterSet(const PRUnichar* aForceCharacterSet) -{ - mForceCharacterSet = aForceCharacterSet; - // now set the force char set on all children of mContainer - return CallChildren(SetChildForceCharacterSet, (void*) aForceCharacterSet); -} - -// XXX: SEMANTIC CHANGE! -// returns a copy of the string. Caller is responsible for freeing result -// using Recycle(aHintCharacterSet) -NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSet(PRUnichar * *aHintCharacterSet) -{ - NS_ENSURE_ARG_POINTER(aHintCharacterSet); - - if(kCharsetUninitialized == mHintCharsetSource) { - *aHintCharacterSet = nsnull; - } else { - *aHintCharacterSet = mHintCharset.ToNewUnicode(); - // this can't possibly be right. we can't set a value just because somebody got a related value! - //mHintCharsetSource = kCharsetUninitialized; - } - return NS_OK; -} - -NS_IMETHODIMP DocumentViewerImpl::GetHintCharacterSetSource(PRInt32 *aHintCharacterSetSource) -{ - NS_ENSURE_ARG_POINTER(aHintCharacterSetSource); - - *aHintCharacterSetSource = mHintCharsetSource; - return NS_OK; -} - -static void -SetChildHintCharacterSetSource(nsIMarkupDocumentViewer* aChild, void* aClosure) -{ - aChild->SetHintCharacterSetSource((PRInt32) aClosure); -} - -NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSetSource(PRInt32 aHintCharacterSetSource) -{ - mHintCharsetSource = (nsCharsetSource)aHintCharacterSetSource; - // now set the hint char set source on all children of mContainer - return CallChildren(SetChildHintCharacterSetSource, - (void*) aHintCharacterSetSource); -} - -static void -SetChildHintCharacterSet(nsIMarkupDocumentViewer* aChild, void* aClosure) -{ - aChild->SetHintCharacterSet((PRUnichar*) aClosure); -} - -NS_IMETHODIMP DocumentViewerImpl::SetHintCharacterSet(const PRUnichar* aHintCharacterSet) -{ - mHintCharset = aHintCharacterSet; - // now set the hint char set on all children of mContainer - return CallChildren(SetChildHintCharacterSet, (void*) aHintCharacterSet); -} - -NS_IMETHODIMP DocumentViewerImpl::SizeToContent() -{ - nsCOMPtr docShellAsItem(do_QueryInterface(mContainer)); - NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); - - nsCOMPtr docShellParent; - docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent)); - - // It's only valid to access this from a top frame. Doesn't work from - // sub-frames. - NS_ENSURE_TRUE(!docShellParent, NS_ERROR_FAILURE); - - nsCOMPtr presShell; - GetPresShell(*getter_AddRefs(presShell)); - NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE); - - NS_ENSURE_SUCCESS(presShell->ResizeReflow(NS_UNCONSTRAINEDSIZE, - NS_UNCONSTRAINEDSIZE), NS_ERROR_FAILURE); - - nsCOMPtr presContext; - GetPresContext(*getter_AddRefs(presContext)); - NS_ENSURE_TRUE(presContext, NS_ERROR_FAILURE); - - nsRect shellArea; - PRInt32 width, height; - float pixelScale; - - // so how big is it? - presContext->GetVisibleArea(shellArea); - presContext->GetTwipsToPixels(&pixelScale); - width = PRInt32((float)shellArea.width*pixelScale); - height = PRInt32((float)shellArea.height*pixelScale); - - nsCOMPtr treeOwner; - docShellAsItem->GetTreeOwner(getter_AddRefs(treeOwner)); - NS_ENSURE_TRUE(treeOwner, NS_ERROR_FAILURE); - - NS_ENSURE_SUCCESS(treeOwner->SizeShellTo(docShellAsItem, width, height), - NS_ERROR_FAILURE); - - return NS_OK; -} - - - -#ifdef XP_MAC -#pragma mark - -#endif - -NS_IMPL_ISUPPORTS(nsDocViwerSelectionListener, NS_GET_IID(nsISelectionListener)); - -nsresult nsDocViwerSelectionListener::Init(DocumentViewerImpl *aDocViewer) -{ - mDocViewer = aDocViewer; - return NS_OK; -} - - -NS_IMETHODIMP nsDocViwerSelectionListener::NotifySelectionChanged(nsIDOMDocument *, nsISelection *, short) -{ - NS_ASSERTION(mDocViewer, "Should have doc viewer!"); - - // get the selection state - nsCOMPtr selection; - nsresult rv = mDocViewer->GetDocumentSelection(getter_AddRefs(selection)); - if (NS_FAILED(rv)) return rv; - - PRBool selectionCollapsed; - selection->GetIsCollapsed(&selectionCollapsed); - // we only call UpdateCommands when the selection changes from collapsed - // to non-collapsed or vice versa. We might need another update string - // for simple selection changes, but that would be expenseive. - if (!mGotSelectionState || mSelectionWasCollapsed != selectionCollapsed) - { - nsCOMPtr theDoc; - mDocViewer->GetDocument(*getter_AddRefs(theDoc)); - if (!theDoc) return NS_ERROR_FAILURE; - - nsCOMPtr scriptGlobalObject; - theDoc->GetScriptGlobalObject(getter_AddRefs(scriptGlobalObject)); - - nsCOMPtr domWindow = do_QueryInterface(scriptGlobalObject); - if (!domWindow) return NS_ERROR_FAILURE; - - domWindow->UpdateCommands(NS_ConvertToString("select")); - mGotSelectionState = PR_TRUE; - mSelectionWasCollapsed = selectionCollapsed; - } - - return NS_OK; -} - -//nsDocViewerFocusListener -NS_IMPL_ISUPPORTS(nsDocViewerFocusListener, NS_GET_IID(nsIDOMFocusListener)); - -nsDocViewerFocusListener::nsDocViewerFocusListener() -:mDocViewer(nsnull) -{ - NS_INIT_REFCNT(); -} - -nsDocViewerFocusListener::~nsDocViewerFocusListener(){} - -nsresult -nsDocViewerFocusListener::HandleEvent(nsIDOMEvent* aEvent) -{ - return NS_OK; -} - -nsresult -nsDocViewerFocusListener::Focus(nsIDOMEvent* aEvent) -{ - nsCOMPtr shell; - if(!mDocViewer) - return NS_ERROR_FAILURE; - - nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref - if(NS_FAILED(result) || !shell) - return result?result:NS_ERROR_FAILURE; - nsCOMPtr selCon; - selCon = do_QueryInterface(shell); - PRInt16 selectionStatus; - selCon->GetDisplaySelection( &selectionStatus); - - //if selection was nsISelectionController::SELECTION_OFF, do nothing - //otherwise re-enable it. - if(selectionStatus == nsISelectionController::SELECTION_DISABLED) - { - selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON); - selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); - } - return result; -} - -nsresult -nsDocViewerFocusListener::Blur(nsIDOMEvent* aEvent) -{ - nsCOMPtr shell; - if(!mDocViewer) - return NS_ERROR_FAILURE; - - nsresult result = mDocViewer->GetPresShell(*getter_AddRefs(shell));//deref once cause it take a ptr ref - if(NS_FAILED(result) || !shell) - return result?result:NS_ERROR_FAILURE; - nsCOMPtr selCon; - selCon = do_QueryInterface(shell); - PRInt16 selectionStatus; - selCon->GetDisplaySelection(&selectionStatus); - - //if selection was nsISelectionController::SELECTION_OFF, do nothing - //otherwise re-enable it. - if(selectionStatus == nsISelectionController::SELECTION_ON) - { - selCon->SetDisplaySelection(nsISelectionController::SELECTION_DISABLED); - selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL); - } - return result; -} - - -nsresult -nsDocViewerFocusListener::Init(DocumentViewerImpl *aDocViewer) -{ - mDocViewer = aDocViewer; - return NS_OK; -} - - -PRBool -DocumentViewerImpl::IsWindowsInOurSubTree(nsIDOMWindowInternal * aDOMWindow) -{ - PRBool found = PR_FALSE; - if(aDOMWindow) { - // now check to make sure it is in "our" tree of webshells - nsCOMPtr scriptObj(do_QueryInterface(aDOMWindow)); - if (scriptObj) { - nsCOMPtr docShell; - scriptObj->GetDocShell(getter_AddRefs(docShell)); - if (docShell) { - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); - if (docShellAsItem) { - // get this DocViewer webshell - nsCOMPtr thisDVWebShell(do_QueryInterface(mContainer)); - while (!found) { - nsCOMPtr docShellParent; - docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent)); - if (docShellParent) { - nsCOMPtr parentWebshell(do_QueryInterface(docShellParent)); - if (parentWebshell) { - if (parentWebshell.get() == thisDVWebShell.get()) { - found = PR_TRUE; - break; - } - } - } else { - break; // at top of tree - } - docShellAsItem = docShellParent; - } // while - } - } // docshell - } // scriptobj - } // domWindow - - return found; -} - -/** --------------------------------------------------- - * Get the Focused Frame for a documentviewer - * - */ -nsIDOMWindowInternal* -DocumentViewerImpl::FindFocusedDOMWindowInternal() -{ - nsCOMPtr theDOMWin; - nsCOMPtr theDoc; - nsCOMPtr theSGO; - nsCOMPtr focusController; - nsIDOMWindowInternal * domWin = nsnull; - - this->GetDocument(*getter_AddRefs(theDoc)); - if(theDoc){ - theDoc->GetScriptGlobalObject(getter_AddRefs(theSGO)); - if(theSGO){ - nsCOMPtr theDOMWindow = do_QueryInterface(theSGO); - if(theDOMWindow){ - theDOMWindow->GetRootFocusController(getter_AddRefs(focusController)); - if(focusController){ - focusController->GetFocusedWindow(getter_AddRefs(theDOMWin)); - domWin = theDOMWin.get(); - if(domWin != nsnull) { - if (IsWindowsInOurSubTree(domWin)){ - NS_ADDREF(domWin); - } else { - domWin = nsnull; - } - } - } - } - } - } - return domWin; -} - -/** --------------------------------------------------- - * Get DOM Window represented by the document viewer - * - */ -nsIDOMWindow* -DocumentViewerImpl::GetDOMWindowForThisDV() -{ - nsCOMPtr theDoc; - nsCOMPtr theSGO; - nsCOMPtr focusController; - nsIDOMWindow * domWin = nsnull; - - this->GetDocument(*getter_AddRefs(theDoc)); - if (theDoc){ - theDoc->GetScriptGlobalObject(getter_AddRefs(theSGO)); - if (theSGO){ - nsCOMPtr theDOMWindow = do_QueryInterface(theSGO); - if(theDOMWindow){ - domWin = theDOMWindow.get(); - NS_ADDREF(domWin); - } - } - } - - return domWin; -} diff --git a/layout/base/src/nsGeneratedIterator.cpp b/layout/base/src/nsGeneratedIterator.cpp deleted file mode 100644 index 30a462b36a21..000000000000 --- a/layout/base/src/nsGeneratedIterator.cpp +++ /dev/null @@ -1,1285 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Pierre Phaneuf - */ - -/* - * nsContentIterator.cpp: Implementation of the nsContentIterator object. - * This ite - */ -#include "nsISupports.h" -#include "nsIDOMNodeList.h" -#include "nsIContentIterator.h" -#include "nsRange.h" -#include "nsIContent.h" -#include "nsIDOMText.h" -#include "nsISupportsArray.h" -#include "nsIFocusTracker.h" -#include "nsCOMPtr.h" -#include "nsIPresContext.h" -#include "nsIComponentManager.h" -#include "nsLayoutCID.h" -#include "nsIPresShell.h" - -#define DO_AFTER 1 -#define DO_BEFORE 1 - -/////////////////////////////////////////////////////////////////////////// -// GetNumChildren: returns the number of things inside aNode. -// -static PRUint32 -GetNumChildren(nsIDOMNode *aNode) -{ - PRUint32 numChildren = 0; - if (!aNode) - return 0; - - PRBool hasChildNodes; - aNode->HasChildNodes(&hasChildNodes); - if (hasChildNodes) - { - nsCOMPtrnodeList; - nsresult res = aNode->GetChildNodes(getter_AddRefs(nodeList)); - if (NS_SUCCEEDED(res) && nodeList) - nodeList->GetLength(&numChildren); - } - return numChildren; -} - -/////////////////////////////////////////////////////////////////////////// -// GetChildAt: returns the node at this position index in the parent -// -static nsCOMPtr -GetChildAt(nsIDOMNode *aParent, PRInt32 aOffset) -{ - nsCOMPtr resultNode; - - if (!aParent) - return resultNode; - - PRBool hasChildNodes; - aParent->HasChildNodes(&hasChildNodes); - if (PR_TRUE==hasChildNodes) - { - nsCOMPtrnodeList; - nsresult res = aParent->GetChildNodes(getter_AddRefs(nodeList)); - if (NS_SUCCEEDED(res) && nodeList) - nodeList->Item(aOffset, getter_AddRefs(resultNode)); - } - - return resultNode; -} - - -/* - * A simple iterator class for traversing the generated content in "close tag" order - */ -class nsGeneratedContentIterator : public nsIContentIterator ,public nsIGeneratedContentIterator//, public nsIEnumerator -{ -public: - NS_DECL_ISUPPORTS - - nsGeneratedContentIterator(); - virtual ~nsGeneratedContentIterator(); - - // nsIContentIterator interface methods ------------------------------ - - NS_IMETHOD Init(nsIContent* aRoot); - - NS_IMETHOD Init(nsIDOMRange* aRange); - - NS_IMETHOD First(); - - NS_IMETHOD Last(); - - NS_IMETHOD Next(); - - NS_IMETHOD Prev(); - - NS_IMETHOD CurrentNode(nsIContent **aNode); - - NS_IMETHOD IsDone(); - - NS_IMETHOD PositionAt(nsIContent* aCurNode); - - NS_IMETHOD MakePre(); - - NS_IMETHOD MakePost(); - - - // nsIEnumertor interface methods ------------------------------ - - //NS_IMETHOD CurrentItem(nsISupports **aItem); - - //nsIGeneratedContentIterator - NS_IMETHOD Init(nsIPresShell *aShell, nsIDOMRange* aRange); - NS_IMETHOD Init(nsIPresShell *aShell, nsIContent* aContent); - -protected: - - // Do these cause too much refcounting??? - nsCOMPtr GetDeepFirstChild(nsCOMPtr aRoot); - nsCOMPtr GetDeepLastChild(nsCOMPtr aRoot); - - nsresult GetNextSibling(nsCOMPtr aNode, nsCOMPtr *aSibling); - nsresult GetPrevSibling(nsCOMPtr aNode, nsCOMPtr *aSibling); - - nsresult NextNode(nsCOMPtr *ioNextNode); - nsresult PrevNode(nsCOMPtr *ioPrevNode); - - void MakeEmpty(); - - nsCOMPtr mCurNode; - nsCOMPtr mFirst; - nsCOMPtr mLast; - nsCOMPtr mCommonParent; - - nsCOMPtr mFirstIter; - nsCOMPtr mLastIter; - nsCOMPtr mGenIter; - nsIPresShell::GeneratedContentType mIterType; - nsIPresShell::GeneratedContentType mFirstIterType; - nsIPresShell::GeneratedContentType mLastIterType; - nsCOMPtr mPresShell; - PRBool mIsDone; - PRBool mPre; - -private: - - // no copy's or assigns FIX ME - nsGeneratedContentIterator(const nsGeneratedContentIterator&); - nsGeneratedContentIterator& operator=(const nsGeneratedContentIterator&); - -}; - - -/****************************************************** - * repository cruft - ******************************************************/ - -nsresult NS_NewGenRegularIterator(nsIContentIterator ** aInstancePtrResult) -{ - nsGeneratedContentIterator * iter = new nsGeneratedContentIterator(); - if (iter) - return iter->QueryInterface(NS_GET_IID(nsIContentIterator), (void**) aInstancePtrResult); - return NS_ERROR_OUT_OF_MEMORY; -} - - -/****************************************************** - * XPCOM cruft - ******************************************************/ - -NS_IMPL_ADDREF(nsGeneratedContentIterator) -NS_IMPL_RELEASE(nsGeneratedContentIterator) - -nsresult nsGeneratedContentIterator::QueryInterface(const nsIID& aIID, - void** aInstancePtrResult) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); - if (nsnull == aInstancePtrResult) - { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsISupports))) - { - *aInstancePtrResult = (void*)(nsISupports*)(nsIContentIterator*)this; - NS_ADDREF_THIS(); - return NS_OK; - } -/* if (aIID.Equals(NS_GET_IID(nsIEnumerator))) - { - *aInstancePtrResult = (void*)(nsIEnumerator*)this; - NS_ADDREF_THIS(); - return NS_OK; - } */ - if (aIID.Equals(NS_GET_IID(nsIContentIterator))) - { - *aInstancePtrResult = (void*)(nsIContentIterator*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIGeneratedContentIterator))) - { - *aInstancePtrResult = (void*)(nsIGeneratedContentIterator*)this; - NS_ADDREF_THIS(); - return NS_OK; - } - return NS_NOINTERFACE; -} - - -/****************************************************** - * constructor/destructor - ******************************************************/ - -nsGeneratedContentIterator::nsGeneratedContentIterator() : - // don't need to explicitly initialize |nsCOMPtr|s, they will automatically be NULL - mIsDone(PR_FALSE), mPre(PR_FALSE) -{ - NS_INIT_REFCNT(); -} - - -nsGeneratedContentIterator::~nsGeneratedContentIterator() -{ -} - - -/****************************************************** - * Init routines - ******************************************************/ - - -nsresult nsGeneratedContentIterator::Init(nsIContent* aRoot) -{ - if (!aRoot) - return NS_ERROR_NULL_POINTER; - mIsDone = PR_FALSE; - nsCOMPtr root( do_QueryInterface(aRoot) ); - mFirst = GetDeepFirstChild(root); - if (mGenIter)//we have generated - { - mFirstIter = mGenIter; - mFirstIterType = mIterType; - } - mLast = root; - mCommonParent = root; - mCurNode = mFirst; - return NS_OK; -} - -NS_IMETHODIMP -nsGeneratedContentIterator::Init(nsIPresShell *aShell, nsIDOMRange* aRange) -{ - mPresShell = aShell; - return Init(aRange); -} - -NS_IMETHODIMP -nsGeneratedContentIterator::Init(nsIPresShell *aShell, nsIContent* aContent) -{ - mPresShell = aShell; - return Init(aContent); -} - - -nsresult nsGeneratedContentIterator::Init(nsIDOMRange* aRange) -{ - if (!aRange) - return NS_ERROR_NULL_POINTER; - - nsCOMPtr dN; - nsCOMPtr cChild; - - nsCOMPtr startCon; - nsCOMPtr startDOM; - nsCOMPtr endCon; - nsCOMPtr endDOM; - PRInt32 startIndx; - PRInt32 endIndx; - - mIsDone = PR_FALSE; - - // get common content parent - if (NS_FAILED(aRange->GetCommonAncestorContainer(getter_AddRefs(dN))) || !dN) - return NS_ERROR_FAILURE; - mCommonParent = do_QueryInterface(dN); - - // get the start node and offset, convert to nsIContent - aRange->GetStartContainer(getter_AddRefs(startDOM)); - if (!startDOM) - return NS_ERROR_ILLEGAL_VALUE; - startCon = do_QueryInterface(startDOM); - if (!startCon) - return NS_ERROR_FAILURE; - - aRange->GetStartOffset(&startIndx); - - // get the end node and offset, convert to nsIContent - aRange->GetEndContainer(getter_AddRefs(endDOM)); - if (!endDOM) - return NS_ERROR_ILLEGAL_VALUE; - endCon = do_QueryInterface(endDOM); - if (!endCon) - return NS_ERROR_FAILURE; - - aRange->GetEndOffset(&endIndx); - - // short circuit when start node == end node - if (startDOM == endDOM) - { - startCon->ChildAt(0,*getter_AddRefs(cChild)); - - if (!cChild) // no children, must be a text node or empty container - { - mFirst = startCon; - mLast = startCon; - mCurNode = startCon; - return NS_OK; - } - else - { - if (startIndx == endIndx) // collapsed range - { - MakeEmpty(); - return NS_OK; - } - } - } - - // find first node in range - startCon->ChildAt(0,*getter_AddRefs(cChild)); - - if (!cChild) // no children, must be a text node - { - mFirst = startCon; - } - else - { - startCon->ChildAt(startIndx,*getter_AddRefs(cChild)); - if (!cChild) // offset after last child, parent is first node - { - mFirst = startCon; - } - else - { - mFirst = GetDeepFirstChild(cChild); - if (mGenIter) - { - mFirstIter = mGenIter; - mFirstIterType = mIterType; - } - } - // Does that first node really intersect the range? - // the range could be collapsed, or the range could be - // 'degenerate', ie not collapsed but still containing - // no content. In this case, we want the iterator to - // be empty - - if (!IsNodeIntersectsRange(mFirst, aRange)) - { - MakeEmpty(); - return NS_OK; - } - } - - // find last node in range - endCon->ChildAt(0,*getter_AddRefs(cChild)); - - if (!cChild) // no children, must be a text node - { - mLast = endCon; - } - else if (endIndx == 0) // before first child, parent is last node - { - mLast = endCon; - } - else - { - endCon->ChildAt(--endIndx,*getter_AddRefs(cChild)); - if (!cChild) // offset after last child, last child is last node - { - endCon->ChildCount(endIndx); - endCon->ChildAt(--endIndx,*getter_AddRefs(cChild)); - if (!cChild) - { - NS_NOTREACHED("nsGeneratedContentIterator::nsGeneratedContentIterator"); - return NS_ERROR_FAILURE; - } - } - mLast = cChild; - } - - mCurNode = mFirst; - return NS_OK; -} - - -/****************************************************** - * Helper routines - ******************************************************/ - -void nsGeneratedContentIterator::MakeEmpty() -{ - nsCOMPtr noNode; - mCurNode = noNode; - mFirst = noNode; - mLast = noNode; - mCommonParent = noNode; - mIsDone = PR_TRUE; - mGenIter = 0; - mFirstIter = 0; - mIterType = nsIPresShell::Before; -} - -nsCOMPtr nsGeneratedContentIterator::GetDeepFirstChild(nsCOMPtr aRoot) -{ - nsCOMPtr deepFirstChild; - - if (aRoot) - { - nsCOMPtr cN = aRoot; - nsCOMPtr cChild; - -#if DO_BEFORE - //CHECK FOR BEFORESTUFF - nsresult result = NS_ERROR_FAILURE; - if (mPresShell) - result = mPresShell->GetGeneratedContentIterator(cN,nsIPresShell::Before,getter_AddRefs(mGenIter)); - if (NS_SUCCEEDED(result) && mGenIter) - { //ok we have a generated iter all bets are off - mIterType = nsIPresShell::Before; - mGenIter->First(); - return cN; - } -#endif - cN->ChildAt(0,*getter_AddRefs(cChild)); - while ( cChild ) - { - cN = cChild; - -#if DO_BEFORE - //CHECK FOR BEFORESTUFF - if (mPresShell) - result = mPresShell->GetGeneratedContentIterator(cN,nsIPresShell::Before,getter_AddRefs(mGenIter)); - if (NS_SUCCEEDED(result) && mGenIter) - { //ok we have a generated iter all bets are off - mIterType = nsIPresShell::Before; - mGenIter->First(); - return cN; - } -#endif - - cN->ChildAt(0,*getter_AddRefs(cChild)); - } - deepFirstChild = cN; - } - - return deepFirstChild; -} - -nsCOMPtr nsGeneratedContentIterator::GetDeepLastChild(nsCOMPtr aRoot) -{ - nsCOMPtr deepFirstChild; - - if (aRoot) - { - nsCOMPtr cN = aRoot; - nsCOMPtr cChild; - PRInt32 numChildren; - -#if DO_AFTER - //CHECK FOR AFTER STUFF - nsresult result = NS_ERROR_FAILURE; - if (mPresShell) - result = mPresShell->GetGeneratedContentIterator(cN,nsIPresShell::After,getter_AddRefs(mGenIter)); - if (NS_SUCCEEDED(result) && mGenIter) - { //ok we have a generated iter all bets are off - mIterType = nsIPresShell::After; - mGenIter->First(); - return cN; - } -#endif - - cN->ChildCount(numChildren); - - while ( numChildren ) - { - cN->ChildAt(--numChildren,*getter_AddRefs(cChild)); - if (cChild) - { -#if DO_AFTER - //CHECK FOR AFTER STUFF - if (mPresShell) - result = mPresShell->GetGeneratedContentIterator(cChild,nsIPresShell::After,getter_AddRefs(mGenIter)); - if (NS_SUCCEEDED(result) && mGenIter) - { //ok we have a generated iter all bets are off - mGenIter->Last(); - mIterType = nsIPresShell::After; - return cChild; - } -#endif - cChild->ChildCount(numChildren); - cN = cChild; - } - else - { - break; - } - } - deepFirstChild = cN; - } - - return deepFirstChild; -} - -// Get the next sibling, or parents next sibling, or grandpa's next sibling... -nsresult nsGeneratedContentIterator::GetNextSibling(nsCOMPtr aNode, nsCOMPtr *aSibling) -{ - if (!aNode) - return NS_ERROR_NULL_POINTER; - if (!aSibling) - return NS_ERROR_NULL_POINTER; - - nsCOMPtr sib; - nsCOMPtr parent; - PRInt32 indx; - - if (NS_FAILED(aNode->GetParent(*getter_AddRefs(parent))) || !parent) - return NS_ERROR_FAILURE; - - if (NS_FAILED(parent->IndexOf(aNode, indx))) - return NS_ERROR_FAILURE; - - if (NS_SUCCEEDED(parent->ChildAt(++indx, *getter_AddRefs(sib))) && sib) - { - *aSibling = sib; - } - else //CHECK AFTER CONTEXT ON PARENT - { -#if DO_AFTER - //CHECK FOR AFTERESTUFF - nsresult result = NS_ERROR_FAILURE; - if (mPresShell) - result = mPresShell->GetGeneratedContentIterator(parent,nsIPresShell::After,getter_AddRefs(mGenIter)); - if (NS_SUCCEEDED(result) && mGenIter) - { //ok we have a generated iter all bets are off - mGenIter->First(); - mIterType = nsIPresShell::After; - *aSibling = parent; - return result; - } -#endif - if (parent != mCommonParent) - { - return GetNextSibling(parent, aSibling); - } - else - { - *aSibling = nsCOMPtr(); - } - } - - return NS_OK; -} - -// Get the prev sibling, or parents prev sibling, or grandpa's prev sibling... -nsresult nsGeneratedContentIterator::GetPrevSibling(nsCOMPtr aNode, nsCOMPtr *aSibling) -{ - if (!aNode) - return NS_ERROR_NULL_POINTER; - if (!aSibling) - return NS_ERROR_NULL_POINTER; - - nsCOMPtr sib; - nsCOMPtr parent; - PRInt32 indx; - - if (NS_FAILED(aNode->GetParent(*getter_AddRefs(parent))) || !parent) - return NS_ERROR_FAILURE; - - if (NS_FAILED(parent->IndexOf(aNode, indx))) - return NS_ERROR_FAILURE; - - if (indx && NS_SUCCEEDED(parent->ChildAt(--indx, *getter_AddRefs(sib))) && sib) - { - *aSibling = sib; - } - else - { -#if DO_BEFORE - //CHECK FOR BEFORESTUFF - nsresult result = NS_ERROR_FAILURE; - if (mPresShell) - result = mPresShell->GetGeneratedContentIterator(parent,nsIPresShell::Before,getter_AddRefs(mGenIter)); - if (NS_SUCCEEDED(result) && mGenIter) - { //ok we have a generated iter all bets are off - mGenIter->Last(); - *aSibling = parent; - mIterType = nsIPresShell::Before; - return result; - } - else -#endif - if (parent != mCommonParent) - { - return GetPrevSibling(parent, aSibling); - } - else - { - *aSibling = nsCOMPtr(); - } - } - return NS_OK; -} - -nsresult nsGeneratedContentIterator::NextNode(nsCOMPtr *ioNextNode) -{ - if (!ioNextNode) - return NS_ERROR_NULL_POINTER; - - if (mPre) // if we are a Pre-order iterator, use pre-order - { - return NS_ERROR_NOT_IMPLEMENTED; - } - else // post-order*/ - if (mGenIter) - { - if (mGenIter->IsDone()) - mGenIter = 0; - else - return mGenIter->Next(); - if (nsIPresShell::After == mIterType)//answer is parent - { - //*ioNextNode = parent; leave it the same - return NS_OK; - } - nsCOMPtrcN; - (*ioNextNode)->ChildAt(0,*getter_AddRefs(cN)); - if (cN) - { - *ioNextNode=GetDeepFirstChild(cN); - return NS_OK; - } - } - - { - nsCOMPtr cN = *ioNextNode; - nsCOMPtr cSibling; - nsCOMPtr parent; - PRInt32 indx; - - // get next sibling if there is one - if (NS_FAILED(cN->GetParent(*getter_AddRefs(parent)))) - return NS_ERROR_FAILURE; - if (!parent || NS_FAILED(parent->IndexOf(cN, indx))) - { - // a little noise to catch some iterator usage bugs. - NS_NOTREACHED("nsGeneratedContentIterator::NextNode() : no parent found"); - return NS_ERROR_FAILURE; - } - if (NS_SUCCEEDED(parent->ChildAt(++indx,*getter_AddRefs(cSibling))) && cSibling) - { - // next node is siblings "deep left" child - *ioNextNode = GetDeepFirstChild(cSibling); - return NS_OK; - } - //CHECK FOR AFTERSTUFF - if (mGenIter)//we allready had an afteriter. it must be done! - { - mGenIter = 0; - } - else//check for after node. - { - nsresult result = NS_ERROR_FAILURE; - if (mPresShell) - result = mPresShell->GetGeneratedContentIterator(parent,nsIPresShell::After,getter_AddRefs(mGenIter)); - if (NS_SUCCEEDED(result) && mGenIter) - { //ok we have a generated iter all bets are off - mGenIter->First(); - mIterType = nsIPresShell::After; - } - else - mGenIter = 0; - } - - // else it's the parent - *ioNextNode = parent; - } - return NS_OK; -} - - -//THIS NEEDS TO USE A GENERATED SUBTREEITER HERE -nsresult nsGeneratedContentIterator::PrevNode(nsCOMPtr *ioNextNode) -{ - if (!ioNextNode) - return NS_ERROR_NULL_POINTER; - - if (mPre) // if we are a Pre-order iterator, use pre-order - { - return NS_ERROR_NOT_IMPLEMENTED; - } - else // post-order - { - nsCOMPtr cN = *ioNextNode; - nsCOMPtr cLastChild; - PRInt32 numChildren; - - cN->ChildCount(numChildren); - - // if it has children then prev node is last child - if (numChildren) - { - if (NS_FAILED(cN->ChildAt(--numChildren,*getter_AddRefs(cLastChild)))) - return NS_ERROR_FAILURE; - if (!cLastChild) - return NS_ERROR_FAILURE; - *ioNextNode = cLastChild; - return NS_OK; - } - - // else prev sibling is previous - return GetPrevSibling(cN, ioNextNode); - } - return NS_OK; -} - -/****************************************************** - * ContentIterator routines - ******************************************************/ - -nsresult nsGeneratedContentIterator::First() -{ - if (!mFirst) - return NS_ERROR_FAILURE; - mIsDone = PR_FALSE; - mCurNode = mFirst; - mGenIter = mFirstIter; - if (mGenIter)//set directionback to before... - mGenIter->First(); - return NS_OK; -} - - -nsresult nsGeneratedContentIterator::Last() -{ - if (!mLast) - return NS_ERROR_FAILURE; - mIsDone = PR_FALSE; - mGenIter = mLastIter; - mCurNode = mLast; - return NS_OK; -} - - -nsresult nsGeneratedContentIterator::Next() -{ - if (mIsDone) - return NS_OK; - if (!mCurNode) - return NS_OK; - nsCOMPtr curnode; - CurrentNode(getter_AddRefs(curnode)); - if (curnode == mLast) - { - mIsDone = PR_TRUE; - return NS_OK; - } - - return NextNode(address_of(mCurNode)); -} - - -nsresult nsGeneratedContentIterator::Prev() -{ - if (mIsDone) - return NS_OK; - if (!mCurNode) - return NS_OK; - if (mCurNode == mFirst) - { - mIsDone = PR_TRUE; - return NS_OK; - } - - return PrevNode(address_of(mCurNode)); -} - - -nsresult nsGeneratedContentIterator::IsDone() -{ - if (mIsDone) - return NS_OK; - else - return NS_ENUMERATOR_FALSE; -} - - -nsresult nsGeneratedContentIterator::PositionAt(nsIContent* aCurNode) -{ - // XXX need to confirm that aCurNode is within range - if (!aCurNode) - return NS_ERROR_NULL_POINTER; - mCurNode = do_QueryInterface(aCurNode); - mIsDone = PR_FALSE; - return NS_OK; -} - -nsresult nsGeneratedContentIterator::MakePre() -{ - // XXX need to confirm mCurNode is within range - mPre = PR_TRUE; - return NS_OK; -} - -nsresult nsGeneratedContentIterator::MakePost() -{ - // XXX need to confirm mCurNode is within range - mPre = PR_FALSE; - return NS_OK; -} - - -nsresult nsGeneratedContentIterator::CurrentNode(nsIContent **aNode) -{ - if (!mCurNode) - return NS_ERROR_FAILURE; - if (mIsDone) - return NS_ERROR_FAILURE; - if (mGenIter) - return mGenIter->CurrentNode(aNode); - return mCurNode->QueryInterface(NS_GET_IID(nsIContent), (void**) aNode); -} - - - - - -/*====================================================================================*/ -//SUBTREE ITERATOR -/*====================================================================================*/ -/****************************************************** - * nsGeneratedSubtreeIterator - ******************************************************/ - - -/* - * A simple iterator class for traversing the content in "top subtree" order - */ -class nsGeneratedSubtreeIterator : public nsGeneratedContentIterator -{ -public: - nsGeneratedSubtreeIterator() {}; - virtual ~nsGeneratedSubtreeIterator() {}; - - // nsContentIterator overrides ------------------------------ - - NS_IMETHOD Init(nsIContent* aRoot); - - NS_IMETHOD Init(nsIDOMRange* aRange); - - NS_IMETHOD Next(); - - NS_IMETHOD Prev(); - - NS_IMETHOD PositionAt(nsIContent* aCurNode); - - NS_IMETHOD MakePre(); - - NS_IMETHOD MakePost(); - - //nsIGeneratedContentIterator - NS_IMETHOD Init(nsIPresShell *aShell, nsIDOMRange* aRange); - NS_IMETHOD Init(nsIPresShell *aShell, nsIContent* aContent); -protected: - - nsresult GetTopAncestorInRange( nsCOMPtr aNode, - nsCOMPtr *outAnestor); - - // no copy's or assigns FIX ME - nsGeneratedSubtreeIterator(const nsGeneratedSubtreeIterator&); - nsGeneratedSubtreeIterator& operator=(const nsGeneratedSubtreeIterator&); - nsCOMPtr mRange; -}; - -nsresult NS_NewGenSubtreeIterator(nsIContentIterator** aInstancePtrResult); - - - - -/****************************************************** - * repository cruft - ******************************************************/ - -nsresult NS_NewGenSubtreeIterator(nsIContentIterator** aInstancePtrResult) -{ - nsGeneratedSubtreeIterator * iter = new nsGeneratedSubtreeIterator(); - if (iter) - return iter->QueryInterface(NS_GET_IID(nsIContentIterator), (void**) aInstancePtrResult); - return NS_ERROR_OUT_OF_MEMORY; -} - - - -/****************************************************** - * Init routines - ******************************************************/ - - -nsresult nsGeneratedSubtreeIterator::Init(nsIContent* aRoot) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsGeneratedSubtreeIterator::Init(nsIPresShell *aShell, nsIDOMRange* aRange) -{ - mPresShell = aShell; - return Init(aRange); -} - -NS_IMETHODIMP -nsGeneratedSubtreeIterator::Init(nsIPresShell *aShell, nsIContent* aContent) -{ - mPresShell = aShell; - return Init(aContent); -} - -nsresult nsGeneratedSubtreeIterator::Init(nsIDOMRange* aRange) -{ - if (!aRange) - return NS_ERROR_NULL_POINTER; - - mIsDone = PR_FALSE; - - mRange = do_QueryInterface(aRange); - - // get the start node and offset, convert to nsIContent - nsCOMPtr commonParent; - nsCOMPtr startParent; - nsCOMPtr endParent; - nsCOMPtr cStartP; - nsCOMPtr cEndP; - nsCOMPtr cN; - nsCOMPtr firstCandidate; - nsCOMPtr lastCandidate; - nsCOMPtr dChild; - nsCOMPtr cChild; - PRInt32 indx, startIndx, endIndx; - PRInt32 numChildren; - - // get common content parent - if (NS_FAILED(aRange->GetCommonAncestorContainer(getter_AddRefs(commonParent))) || !commonParent) - return NS_ERROR_FAILURE; - mCommonParent = do_QueryInterface(commonParent); - - // get start content parent - if (NS_FAILED(aRange->GetStartContainer(getter_AddRefs(startParent))) || !startParent) - return NS_ERROR_FAILURE; - cStartP = do_QueryInterface(startParent); - aRange->GetStartOffset(&startIndx); - - // get end content parent - if (NS_FAILED(aRange->GetEndContainer(getter_AddRefs(endParent))) || !endParent) - return NS_ERROR_FAILURE; - cEndP = do_QueryInterface(endParent); - aRange->GetEndOffset(&endIndx); - - // short circuit when start node == end node - if (startParent == endParent) - { - cStartP->ChildAt(0,*getter_AddRefs(cChild)); - - if (!cChild) // no children, must be a text node or empty container - { - // all inside one text node - empty subtree iterator - MakeEmpty(); - return NS_OK; - } - else - { - if (startIndx == endIndx) // collapsed range - { - MakeEmpty(); - return NS_OK; - } - } - } - - // find first node in range - aRange->GetStartOffset(&indx); - numChildren = GetNumChildren(startParent); - - if (!numChildren) // no children, must be a text node - { - cN = cStartP; - } - else - { - dChild = GetChildAt(startParent, indx); - cChild = do_QueryInterface(dChild); - if (!cChild) // offset after last child - { - cN = cStartP; - } - else - { - firstCandidate = cChild; - } - } - - if (!firstCandidate) - { - // then firstCandidate is next node after cN - if (NS_FAILED(GetNextSibling(cN, address_of(firstCandidate)))) - { - MakeEmpty(); - return NS_OK; - } - } - if (mGenIter) - { - mFirstIter = mGenIter; - mFirstIterType = mIterType; - } - if (!mFirstIter) - { - firstCandidate = GetDeepFirstChild(firstCandidate); - if (mGenIter) - { - mFirstIter = mGenIter; - mFirstIterType = mIterType; - } - } - // confirm that this first possible contained node - // is indeed contained. Else we have a range that - // does not fully contain any node. - - PRBool nodeBefore(PR_FALSE), nodeAfter(PR_FALSE); - if (!mFirstIter && NS_FAILED(CompareNodeToRange(firstCandidate, aRange, &nodeBefore, &nodeAfter))) - return NS_ERROR_FAILURE; - if (nodeBefore || nodeAfter) - { - MakeEmpty(); - return NS_OK; - } - - // cool, we have the first node in the range. Now we walk - // up it's ancestors to find the most senior that is still - // in the range. That's the real first node. - if (NS_SUCCEEDED(GetTopAncestorInRange(firstCandidate, address_of(mFirst)))) - { - mFirstIter = 0;//ancestor has one no - mGenIter = 0; - } - else if (!mFirstIter) //something bad happened and its not generated content iterators fault - return NS_ERROR_FAILURE; - else - mFirst = firstCandidate;//setting last candidate to parent of generated content this is ok - - - - // now to find the last node - aRange->GetEndOffset(&indx); - numChildren = GetNumChildren(endParent); - - if (indx > numChildren) indx = numChildren; - if (!indx) - { - cN = cEndP; - } - else - { - if (!numChildren) // no children, must be a text node - { - cN = cEndP; - } - else - { - dChild = GetChildAt(endParent, --indx); - cChild = do_QueryInterface(dChild); - if (!cChild) // shouldn't happen - { - NS_ASSERTION(0,"tree traversal trouble in nsGeneratedSubtreeIterator::Init"); - return NS_ERROR_FAILURE; - } - else - { - lastCandidate = cChild; - } - } - } - - if (!lastCandidate) - { - // then lastCandidate is prev node before cN - if (NS_FAILED(GetPrevSibling(cN, address_of(lastCandidate)))) - { - MakeEmpty(); - return NS_OK; - } - } - if (mGenIter) - { - mLastIter = mGenIter; - mLastIterType = mIterType; - } - if (!mLastIter)//dont ever set last candidate to a generated node! - { - lastCandidate = GetDeepLastChild(lastCandidate); - if (mGenIter) - { - mLastIter = mGenIter; - mLastIterType = mIterType; - } - } - - // confirm that this first possible contained node - // is indeed contained. Else we have a range that - // does not fully contain any node. - - if (!mLastIter && NS_FAILED(CompareNodeToRange(lastCandidate, aRange, &nodeBefore, &nodeAfter))) - return NS_ERROR_FAILURE; - - - if (nodeBefore || nodeAfter) - { - MakeEmpty(); - return NS_OK; - } - - // cool, we have the last node in the range. Now we walk - // up it's ancestors to find the most senior that is still - // in the range. That's the real first node. - if (NS_SUCCEEDED(GetTopAncestorInRange(lastCandidate, address_of(mLast)))) - { - mLastIter = 0;//ancestor has one no - mGenIter = 0; - } - else if (!mLastIter) //something bad happened and its not generated content iterators fault - return NS_ERROR_FAILURE; - else - mLast = lastCandidate;//setting last candidate to parent of generated content this is ok - - mCurNode = mFirst; - mGenIter = mFirstIter; - mIterType = mFirstIterType ; - return NS_OK; -} - - -/**************************************************************** - * nsGeneratedSubtreeIterator overrides of ContentIterator routines - ****************************************************************/ - -nsresult nsGeneratedSubtreeIterator::Next() -{ - if (mIsDone) - return NS_OK; - nsCOMPtr curnode; - nsCOMPtr nextNode; - if (mGenIter) - { - if (mGenIter->IsDone()) - { - mGenIter = 0; - if (mIterType == nsIPresShell::After || NS_FAILED(mCurNode->ChildAt(0,*getter_AddRefs(nextNode)))) - { - if (NS_FAILED(GetNextSibling(mCurNode, address_of(nextNode)))) - return NS_OK; - } - } - else - return mGenIter->Next(); - } - else - { - if (mCurNode == mLast) - { - mIsDone = PR_TRUE; - return NS_OK; - } - if (NS_FAILED(GetNextSibling(mCurNode, address_of(nextNode)))) - return NS_OK; - } - - - - if (!mGenIter) - nextNode = GetDeepFirstChild(nextNode); - if (NS_SUCCEEDED(GetTopAncestorInRange(nextNode, address_of(mCurNode)))) - { - mGenIter = 0; - } - else if (!mGenIter) //something bad happened and its not generated content iterators fault - return NS_ERROR_FAILURE; - else - mCurNode = nextNode;//setting last candidate to parent of generated content this is ok - return NS_OK; -} - - -nsresult nsGeneratedSubtreeIterator::Prev() -{ -//notimplemented - return NS_ERROR_NOT_IMPLEMENTED; -} - -nsresult nsGeneratedSubtreeIterator::PositionAt(nsIContent* aCurNode) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -nsresult nsGeneratedSubtreeIterator::MakePre() -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -nsresult nsGeneratedSubtreeIterator::MakePost() -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -/**************************************************************** - * nsGeneratedSubtreeIterator helper routines - ****************************************************************/ - -nsresult nsGeneratedSubtreeIterator::GetTopAncestorInRange( - nsCOMPtr aNode, - nsCOMPtr *outAnestor) -{ - if (!aNode) - return NS_ERROR_NULL_POINTER; - if (!outAnestor) - return NS_ERROR_NULL_POINTER; - - - // sanity check: aNode is itself in the range - PRBool nodeBefore, nodeAfter; - if (NS_FAILED(CompareNodeToRange(aNode, mRange, &nodeBefore, &nodeAfter))) - return NS_ERROR_FAILURE; - if (nodeBefore || nodeAfter) - return NS_ERROR_FAILURE; - - nsCOMPtr parent; - while (aNode) - { - if (NS_FAILED(aNode->GetParent(*getter_AddRefs(parent))) || !parent) - return NS_ERROR_FAILURE; - if (NS_FAILED(CompareNodeToRange(parent, mRange, &nodeBefore, &nodeAfter))) - return NS_ERROR_FAILURE; - if (nodeBefore || nodeAfter) - { - *outAnestor = aNode; - return NS_OK; - } - aNode = parent; - } - return NS_ERROR_FAILURE; -} - - - - - - diff --git a/layout/base/src/nsGenericCaretProperties.cpp b/layout/base/src/nsGenericCaretProperties.cpp deleted file mode 100644 index 9bb7a76a3161..000000000000 --- a/layout/base/src/nsGenericCaretProperties.cpp +++ /dev/null @@ -1,22 +0,0 @@ - - -#include "nscore.h" - -#include "nsCaretProperties.h" - - - -//----------------------------------------------------------------------------- -nsCaretProperties::nsCaretProperties() -: mCaretWidth(eDefaultCaretWidth) -, mBlinkRate(eDefaulBlinkRate) -{ - // in your platform-specific class, get data from the OS in your constructor -} - - -//----------------------------------------------------------------------------- -nsCaretProperties* NewCaretProperties() -{ - return new nsCaretProperties(); -} diff --git a/layout/base/src/nsGenericDOMDataNode.cpp b/layout/base/src/nsGenericDOMDataNode.cpp deleted file mode 100644 index 476bafdcdce8..000000000000 --- a/layout/base/src/nsGenericDOMDataNode.cpp +++ /dev/null @@ -1,1046 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#include "nsGenericDOMDataNode.h" -#include "nsGenericElement.h" -#include "nsIDocument.h" -#include "nsIEventListenerManager.h" -#include "nsIDocument.h" -#include "nsIDOMRange.h" -#include "nsIDOMDocument.h" -#include "nsIDOMDocumentFragment.h" -#include "nsRange.h" -#include "nsTextContentChangeData.h" -#include "nsISelection.h" -#include "nsISelectionPrivate.h" -#include "nsIEnumerator.h" -#include "nsReadableUtils.h" -#include "nsMutationEvent.h" -#include "nsPIDOMWindow.h" - -#include "nsCRT.h" -#include "nsIEventStateManager.h" -#include "nsIPrivateDOMEvent.h" -#include "nsISizeOfHandler.h" -#include "nsIDOMEvent.h" -#include "nsIDOMText.h" -#include "nsIDOMScriptObjectFactory.h" -#include "nsIScriptGlobalObject.h" -#include "prprf.h" -#include "nsCOMPtr.h" - - -//---------------------------------------------------------------------- - -nsGenericDOMDataNode::nsGenericDOMDataNode() - : mText() -{ - mDocument = nsnull; - mParent = nsnull; - mScriptObject = nsnull; - mListenerManager = nsnull; - mRangeList = nsnull; - mCapturer = nsnull; -} - -nsGenericDOMDataNode::~nsGenericDOMDataNode() -{ - if (mListenerManager) { - mListenerManager->SetListenerTarget(nsnull); - NS_RELEASE(mListenerManager); - } - delete mRangeList; -} - -nsresult -nsGenericDOMDataNode::GetNodeValue(nsAWritableString& aNodeValue) -{ - return GetData(aNodeValue); -} - -nsresult -nsGenericDOMDataNode::SetNodeValue(nsIContent *aOuterContent, - const nsAReadableString& aNodeValue) -{ - return SetData(aOuterContent, aNodeValue); -} - -nsresult -nsGenericDOMDataNode::GetParentNode(nsIDOMNode** aParentNode) -{ - nsresult res = NS_OK; - - if (nsnull != mParent) { - res = mParent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aParentNode); - NS_ASSERTION(NS_OK == res, "Must be a DOM Node"); - } - else if (nsnull == mDocument) { - *aParentNode = nsnull; - } - else { - // If we don't have a parent, but we're in the document, we must - // be the root node of the document. The DOM says that the root - // is the document. - res = mDocument->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aParentNode); - } - - return res; -} - -nsresult -nsGenericDOMDataNode::GetPreviousSibling(nsIContent *aOuterContent, - nsIDOMNode** aPrevSibling) -{ - nsIContent* sibling = nsnull; - nsresult result = NS_OK; - - if (nsnull != mParent) { - PRInt32 pos; - mParent->IndexOf(aOuterContent, pos); - if (pos > -1 ) { - mParent->ChildAt(--pos, sibling); - } - } - else if (nsnull != mDocument) { - // Nodes that are just below the document (their parent is the - // document) need to go to the document to find their next sibling. - PRInt32 pos; - mDocument->IndexOf(aOuterContent, pos); - if (pos > -1 ) { - mDocument->ChildAt(--pos, sibling); - } - } - - if (nsnull != sibling) { - result = sibling->QueryInterface(NS_GET_IID(nsIDOMNode),(void**)aPrevSibling); - NS_ASSERTION(NS_OK == result, "Must be a DOM Node"); - NS_RELEASE(sibling); // balance the AddRef in ChildAt() - } - else { - *aPrevSibling = nsnull; - } - - return result; -} - -nsresult -nsGenericDOMDataNode::GetNextSibling(nsIContent *aOuterContent, - nsIDOMNode** aNextSibling) -{ - nsIContent* sibling = nsnull; - nsresult result = NS_OK; - - if (nsnull != mParent) { - PRInt32 pos; - mParent->IndexOf(aOuterContent, pos); - if (pos > -1 ) { - mParent->ChildAt(++pos, sibling); - } - } - else if (nsnull != mDocument) { - // Nodes that are just below the document (their parent is the - // document) need to go to the document to find their next sibling. - PRInt32 pos; - mDocument->IndexOf(aOuterContent, pos); - if (pos > -1 ) { - mDocument->ChildAt(++pos, sibling); - } - } - - if (nsnull != sibling) { - result = sibling->QueryInterface(NS_GET_IID(nsIDOMNode),(void**)aNextSibling); - NS_ASSERTION(NS_OK == result, "Must be a DOM Node"); - NS_RELEASE(sibling); // balance the AddRef in ChildAt() - } - else { - *aNextSibling = nsnull; - } - - return result; -} - -nsresult -nsGenericDOMDataNode::GetChildNodes(nsIDOMNodeList** aChildNodes) -{ - // XXX Since we believe this won't be done very often, we won't - // burn another slot in the data node and just create a new - // (empty) childNodes list every time we're asked. - nsChildContentList* list = new nsChildContentList(nsnull); - if (nsnull == list) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return list->QueryInterface(NS_GET_IID(nsIDOMNodeList), (void**)aChildNodes); -} - -nsresult -nsGenericDOMDataNode::GetOwnerDocument(nsIDOMDocument** aOwnerDocument) -{ - // XXX Actually the owner document is the document in whose context - // the node has been created. We should be able to get at it - // whether or not we are attached to the document. - if (nsnull != mDocument) { - return mDocument->QueryInterface(NS_GET_IID(nsIDOMDocument), (void **)aOwnerDocument); - } - else { - *aOwnerDocument = nsnull; - return NS_OK; - } -} - -nsresult -nsGenericDOMDataNode::GetNamespaceURI(nsAWritableString& aNamespaceURI) -{ - aNamespaceURI.Truncate(); - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::GetPrefix(nsAWritableString& aPrefix) -{ - aPrefix.Truncate(); - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::SetPrefix(const nsAReadableString& aPrefix) -{ - return NS_ERROR_DOM_NAMESPACE_ERR; -} - -nsresult -nsGenericDOMDataNode::Normalize() -{ - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::IsSupported(const nsAReadableString& aFeature, - const nsAReadableString& aVersion, - PRBool* aReturn) -{ - return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn); -} - -#if 0 -nsresult -nsGenericDOMDataNode::Equals(nsIDOMNode* aNode, PRBool aDeep, PRBool* aReturn) -{ - *aReturn = PR_FALSE; - PRInt32 nt1, nt2; - GetNodeType(&nt1); - aNode->GetNodeType(&nt2); - if (nt1 != nt2) { - return NS_OK; - } - return NS_OK; -} -#endif - -//---------------------------------------------------------------------- - -// Implementation of nsIDOMCharacterData - -nsresult -nsGenericDOMDataNode::GetData(nsAWritableString& aData) -{ - if (mText.Is2b()) { - aData.Assign(mText.Get2b(), mText.GetLength()); - } - else { - aData.Assign(NS_ConvertASCIItoUCS2(mText.Get1b(), mText.GetLength())); - } - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::SetData(nsIContent *aOuterContent, const nsAReadableString& aData) -{ - // inform any enclosed ranges of change - // we can lie and say we are deleting all the text, since in a total - // text replacement we should just collapse all the ranges. - if (mRangeList) nsRange::TextOwnerChanged(aOuterContent, 0, - mText.GetLength(), 0); - - nsresult result; - nsCOMPtr textContent = do_QueryInterface(aOuterContent, - &result); - - // If possible, let the container content object have a go at it. - if (NS_SUCCEEDED(result)) { - result = textContent->SetText(aData, PR_TRUE); - } - else { - result = SetText(aOuterContent, aData, PR_TRUE); - } - - return result; -} - -nsresult -nsGenericDOMDataNode::GetLength(PRUint32* aLength) -{ - *aLength = mText.GetLength(); - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::SubstringData(PRUint32 aStart, - PRUint32 aCount, - nsAWritableString& aReturn) -{ - aReturn.Truncate(); - - // XXX add <0 checks if types change - PRUint32 textLength = PRUint32( mText.GetLength() ); - if (aStart > textLength) { - return NS_ERROR_DOM_INDEX_SIZE_ERR; - } - - PRUint32 amount = aCount; - if (aStart + amount > textLength) { - amount = textLength - aStart; - } - if (mText.Is2b()) { - aReturn.Assign(mText.Get2b() + aStart, amount); - } - else { - aReturn.Assign(NS_ConvertASCIItoUCS2(mText.Get1b() + aStart, amount).get(), amount); - } - - return NS_OK; -} - -//---------------------------------------------------------------------- - -nsresult -nsGenericDOMDataNode::AppendData(nsIContent *aOuterContent, - const nsAReadableString& aData) -{ -#if 1 - // Allocate new buffer - nsresult result = NS_OK; - PRUint32 dataLength = aData.Length(); - PRInt32 textLength = mText.GetLength(); - PRInt32 newSize = textLength + dataLength; - PRUnichar* to = new PRUnichar[newSize + 1]; - if (nsnull == to) { - return NS_ERROR_OUT_OF_MEMORY; - } - - // XXX This is slow... - - // Fill new buffer with old data and new data - if (textLength) { - mText.CopyTo(to, 0, textLength); - } - CopyUnicodeTo(aData, 0, to + textLength, dataLength); - - // Null terminate the new buffer... - to[newSize] = (PRUnichar)0; - - nsCOMPtr textContent(do_QueryInterface(aOuterContent, - &result)); - - // Switch to new buffer - // Dont do notification in SetText, since we will do it later - if (NS_SUCCEEDED(result)) { - result = textContent->SetText(to, newSize, PR_FALSE); - } - else { - result = SetText(aOuterContent, to, newSize, PR_FALSE); - } - - delete [] to; - - // Trigger a reflow - if (nsnull != mDocument) { - nsTextContentChangeData* tccd = nsnull; - result = NS_NewTextContentChangeData(&tccd); - if (NS_SUCCEEDED(result)) { - tccd->SetData(nsITextContentChangeData::Append, textLength, dataLength); - result = mDocument->ContentChanged(aOuterContent, tccd); - NS_RELEASE(tccd); - } - else { - result = mDocument->ContentChanged(aOuterContent, nsnull); - } - } - - return result; -#else - return ReplaceData(mText.GetLength(), 0, aData); -#endif -} - -nsresult -nsGenericDOMDataNode::InsertData(nsIContent *aOuterContent, PRUint32 aOffset, - const nsAReadableString& aData) -{ - return ReplaceData(aOuterContent, aOffset, 0, aData); -} - -nsresult -nsGenericDOMDataNode::DeleteData(nsIContent *aOuterContent, PRUint32 aOffset, - PRUint32 aCount) -{ - nsAutoString empty; - return ReplaceData(aOuterContent, aOffset, aCount, empty); -} - -nsresult -nsGenericDOMDataNode::ReplaceData(nsIContent *aOuterContent, PRUint32 aOffset, - PRUint32 aCount, const nsAReadableString& aData) -{ - nsresult result = NS_OK; - - // sanitize arguments - PRUint32 textLength = mText.GetLength(); - if ((aOffset > textLength) || (aOffset < 0) || (aCount < 0)) { - return NS_ERROR_DOM_INDEX_SIZE_ERR; - } - - // Allocate new buffer - PRUint32 endOffset = aOffset + aCount; - if (endOffset > textLength) { - aCount = textLength - aOffset; - endOffset = textLength; - } - PRInt32 dataLength = aData.Length(); - PRInt32 newLength = textLength - aCount + dataLength; - PRUnichar* to = new PRUnichar[newLength ? newLength+1 : 1]; - if (nsnull == to) { - return NS_ERROR_OUT_OF_MEMORY; - } - - // inform any enclosed ranges of change - if (mRangeList) nsRange::TextOwnerChanged(aOuterContent, aOffset, - endOffset, dataLength); - - // Copy over appropriate data - if (0 != aOffset) { - mText.CopyTo(to, 0, aOffset); - } - if (0 != dataLength) { - CopyUnicodeTo(aData, 0, to+aOffset, dataLength); - } - if (endOffset != textLength) { - mText.CopyTo(to + aOffset + dataLength, endOffset, textLength - endOffset); - } - - // Null terminate the new buffer... - to[newLength] = (PRUnichar)0; - - // Switch to new buffer - nsCOMPtr textContent(do_QueryInterface(aOuterContent, - &result)); - - // If possible, let the container content object have a go at it. - if (NS_SUCCEEDED(result)) { - result = textContent->SetText(to, newLength, PR_TRUE); - } - else { - result = SetText(aOuterContent, to, newLength, PR_TRUE); - } - delete [] to; - - return result; -} - -//---------------------------------------------------------------------- - -// nsIScriptObjectOwner implementation - -nsresult -nsGenericDOMDataNode::GetScriptObject(nsIContent *aOuterContent, - nsIScriptContext* aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - nsIDOMNode* node; - PRUint16 nodeType; - - res = aOuterContent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node); - if (NS_OK != res) { - return res; - } - - node->GetNodeType(&nodeType); - res = factory->NewScriptCharacterData(nodeType, - aContext, aOuterContent, - mParent, (void**)&mScriptObject); - if (nsnull != mDocument) { - aContext->AddNamedReference((void *)&mScriptObject, - mScriptObject, - "nsGenericDOMDataNode::mScriptObject"); - } - NS_RELEASE(node); - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - return res; -} - -nsresult -nsGenericDOMDataNode::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} - -//---------------------------------------------------------------------- - -nsresult -nsGenericDOMDataNode::GetListenerManager(nsIContent* aOuterContent, nsIEventListenerManager** aResult) -{ - if (nsnull != mListenerManager) { - NS_ADDREF(mListenerManager); - *aResult = mListenerManager; - return NS_OK; - } - nsresult rv = NS_NewEventListenerManager(aResult); - if (NS_OK == rv) { - mListenerManager = *aResult; - NS_ADDREF(mListenerManager); - mListenerManager->SetListenerTarget(aOuterContent); - } - return rv; -} - -//---------------------------------------------------------------------- - -// Implementation of nsIContent - - -void -nsGenericDOMDataNode::ToCString(nsAWritableString& aBuf, PRInt32 aOffset, - PRInt32 aLen) const -{ - if (mText.Is2b()) { - const PRUnichar* cp = mText.Get2b() + aOffset; - const PRUnichar* end = cp + aLen; - while (cp < end) { - PRUnichar ch = *cp++; - if (ch == '\r') { - aBuf.Append(NS_LITERAL_STRING("\\r")); - } else if (ch == '\n') { - aBuf.Append(NS_LITERAL_STRING("\\n")); - } else if (ch == '\t') { - aBuf.Append(NS_LITERAL_STRING("\\t")); - } else if ((ch < ' ') || (ch >= 127)) { - char buf[10]; - PR_snprintf(buf, sizeof(buf), "\\u%04x", ch); - aBuf.Append(NS_ConvertASCIItoUCS2(buf)); - } else { - aBuf.Append(ch); - } - } - } - else { - unsigned char* cp = (unsigned char*)mText.Get1b() + aOffset; - const unsigned char* end = cp + aLen; - while (cp < end) { - PRUnichar ch = *cp++; - if (ch == '\r') { - aBuf.Append(NS_LITERAL_STRING("\\r")); - } else if (ch == '\n') { - aBuf.Append(NS_LITERAL_STRING("\\n")); - } else if (ch == '\t') { - aBuf.Append(NS_LITERAL_STRING("\\t")); - } else if ((ch < ' ') || (ch >= 127)) { - char buf[10]; - PR_snprintf(buf, sizeof(buf), "\\u%04x", ch); - aBuf.Append(NS_ConvertASCIItoUCS2(buf)); - } else { - aBuf.Append(ch); - } - } - } -} - -nsresult -nsGenericDOMDataNode::GetDocument(nsIDocument*& aResult) const -{ - aResult = mDocument; - NS_IF_ADDREF(mDocument); - return NS_OK; -} - - -nsresult -nsGenericDOMDataNode::SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileEventHandlers) -{ - // If we were part of a document, make sure we get rid of the - // script context reference to our script object so that our - // script object can be freed (or collected). - if ((nsnull != mDocument) && (nsnull != mScriptObject)) { - nsCOMPtr globalObject; - mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if (globalObject) { - nsCOMPtr context; - if (NS_OK == globalObject->GetContext(getter_AddRefs(context)) && context) { - context->RemoveReference((void *)&mScriptObject, - mScriptObject); - } - } - } - - mDocument = aDocument; - - // If we already have a script object and now we're being added - // to a document, make sure that the script context adds a - // reference to our script object. This will ensure that it - // won't be freed (or collected) out from under us. - if ((nsnull != mDocument) && (nsnull != mScriptObject)) { - nsCOMPtr globalObject; - mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if (globalObject) { - nsCOMPtr context; - if (NS_OK == globalObject->GetContext(getter_AddRefs(context)) && context) { - context->AddNamedReference((void *)&mScriptObject, - mScriptObject, - "Text"); - } - } - } - - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::GetParent(nsIContent*& aResult) const -{ - NS_IF_ADDREF(mParent); - aResult = mParent; - return NS_OK;; -} - -nsresult -nsGenericDOMDataNode::SetParent(nsIContent* aParent) -{ - mParent = aParent; - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus) -{ - nsresult ret = NS_OK; - nsIDOMEvent* domEvent = nsnull; - - if (NS_EVENT_FLAG_INIT & aFlags) { - if (!aDOMEvent) { - aDOMEvent = &domEvent; - } - aEvent->flags = aFlags; - aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); - - //Initiate capturing phase. Special case first call to document - if (nsnull != mDocument) { - mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); - } - } - - //Capturing stage evaluation - //Always pass capturing up the tree before local evaulation - if (NS_EVENT_FLAG_BUBBLE != aFlags && nsnull != mCapturer) { - mCapturer->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); - } - - //Local handling stage - if (mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) && - !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) { - aEvent->flags |= aFlags; - mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, nsnull, aFlags, aEventStatus); - aEvent->flags &= ~aFlags; - } - - //Bubbling stage - if (NS_EVENT_FLAG_CAPTURE != aFlags && mParent != nsnull) { - ret = mParent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, - NS_EVENT_FLAG_BUBBLE, aEventStatus); - } - - if (NS_EVENT_FLAG_INIT & aFlags) { - // We're leaving the DOM event loop so if we created a DOM event, - // release here. - if (nsnull != *aDOMEvent) { - if (0 != (*aDOMEvent)->Release()) { - // Okay, so someone in the DOM loop (a listener, JS object) - // still has a ref to the DOM Event but the internal data - // hasn't been malloc'd. Force a copy of the data here so the - // DOM Event is still valid. - nsIPrivateDOMEvent *privateEvent; - if (NS_OK == (*aDOMEvent)->QueryInterface(NS_GET_IID(nsIPrivateDOMEvent), (void**)&privateEvent)) { - privateEvent->DuplicatePrivateData(); - NS_RELEASE(privateEvent); - } - } - } - aDOMEvent = nsnull; - } - return ret; -} - - -nsresult -nsGenericDOMDataNode::RangeAdd(nsIDOMRange& aRange) -{ - // lazy allocation of range list - if (nsnull == mRangeList) { - mRangeList = new nsVoidArray(); - } - if (nsnull == mRangeList) { - return NS_ERROR_OUT_OF_MEMORY; - } - - // Make sure we don't add a range that is already - // in the list! - PRInt32 i = mRangeList->IndexOf(&aRange); - if (i >= 0) { - // Range is already in the list, so there - // is nothing to do! - return NS_OK; - } - - // dont need to addref - this call is made by the range object itself - PRBool rv = mRangeList->AppendElement(&aRange); - if (rv) return NS_OK; - return NS_ERROR_FAILURE; -} - - -nsresult -nsGenericDOMDataNode::RangeRemove(nsIDOMRange& aRange) -{ - if (mRangeList) { - // dont need to release - this call is made by the range object itself - PRBool rv = mRangeList->RemoveElement(&aRange); - if (rv) { - if (mRangeList->Count() == 0) { - delete mRangeList; - mRangeList = nsnull; - } - return NS_OK; - } - } - return NS_ERROR_FAILURE; -} - - -nsresult -nsGenericDOMDataNode::GetRangeList(nsVoidArray*& aResult) const -{ - aResult = mRangeList; - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::SetFocus(nsIPresContext* aPresContext) -{ - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::RemoveFocus(nsIPresContext* aPresContext) -{ - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::GetBindingParent(nsIContent** aContent) -{ - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::SetBindingParent(nsIContent* aParent) -{ - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, - size_t aInstanceSize) const -{ - if (!aResult) { - return NS_ERROR_NULL_POINTER; - } - PRUint32 sum = 0; -#ifdef DEBUG - sum += (PRUint32) aInstanceSize; - sum += mText.GetLength() * - (mText.Is2b() ? sizeof(PRUnichar) : sizeof(char)); -#endif - *aResult = sum; - return NS_OK; -} - -//---------------------------------------------------------------------- - -// Implementation of the nsIDOMText interface - -nsresult -nsGenericDOMDataNode::SplitText(nsIContent *aOuterContent, PRUint32 aOffset, - nsIDOMText** aReturn) -{ - nsresult rv = NS_OK; - nsAutoString cutText; - PRUint32 length; - - GetLength(&length); - if (aOffset > length) { - return NS_ERROR_DOM_INDEX_SIZE_ERR; - } - - rv = SubstringData(aOffset, length-aOffset, cutText); - if (NS_FAILED(rv)) { - return rv; - } - - rv = DeleteData(aOuterContent, aOffset, length-aOffset); - if (NS_FAILED(rv)) { - return rv; - } - - /* - * Use CloneContent() for creating the new node so that the new node is of - * same class as this node! - */ - - nsCOMPtr tmpContent(do_QueryInterface(aOuterContent, &rv)); - nsCOMPtr newContent; - if (NS_FAILED(rv)) { - return rv; - } - - rv = tmpContent->CloneContent(PR_FALSE, getter_AddRefs(newContent)); - if (NS_FAILED(rv)) { - return rv; - } - - - nsCOMPtr newNode = do_QueryInterface(newContent, &rv); - if (NS_FAILED(rv)) { - return rv; - } - - rv = newNode->SetNodeValue(cutText); - if (NS_FAILED(rv)) { - return rv; - } - - nsCOMPtr parentNode; - GetParent(*getter_AddRefs(parentNode)); - - if (parentNode) { - PRInt32 index; - - rv = parentNode->IndexOf(aOuterContent, index); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr content(do_QueryInterface(newNode)); - - rv = parentNode->InsertChildAt(content, index+1, PR_TRUE); - } - } - - return newNode->QueryInterface(NS_GET_IID(nsIDOMText), (void**)aReturn); -} - -//---------------------------------------------------------------------- - -// Implementation of the nsITextContent interface - -nsresult -nsGenericDOMDataNode::GetText(const nsTextFragment** aFragmentsResult) -{ - *aFragmentsResult = &mText; - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::GetTextLength(PRInt32* aLengthResult) -{ - if (!aLengthResult) { - return NS_ERROR_NULL_POINTER; - } - *aLengthResult = mText.GetLength(); - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::CopyText(nsAWritableString& aResult) -{ - if (mText.Is2b()) { - aResult.Assign(mText.Get2b(), mText.GetLength()); - } - else { - aResult.Assign(NS_ConvertASCIItoUCS2(mText.Get1b(), mText.GetLength()).get(), - mText.GetLength()); - } - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::SetText(nsIContent *aOuterContent, - const PRUnichar* aBuffer, - PRInt32 aLength, - PRBool aNotify) -{ - NS_PRECONDITION((aLength >= 0) && (nsnull != aBuffer), "bad args"); - if (aLength < 0) { - return NS_ERROR_ILLEGAL_VALUE; - } - if (nsnull == aBuffer) { - return NS_ERROR_NULL_POINTER; - } - if (aNotify && (nsnull != mDocument)) { - mDocument->BeginUpdate(); - } - mText.SetTo(aBuffer, aLength); - - if (mDocument && nsGenericElement::HasMutationListeners(aOuterContent, NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED)) { - nsCOMPtr node(do_QueryInterface(aOuterContent)); - nsMutationEvent mutation; - mutation.eventStructType = NS_MUTATION_EVENT; - mutation.message = NS_MUTATION_CHARACTERDATAMODIFIED; - mutation.mTarget = node; - - // XXX Handle the setting of prevValue! - nsAutoString newVal(aBuffer); - if (!newVal.IsEmpty()) - mutation.mNewAttrValue = getter_AddRefs(NS_NewAtom(newVal)); - nsEventStatus status = nsEventStatus_eIgnore; - nsCOMPtr domEvent; - HandleDOMEvent(nsnull, &mutation, getter_AddRefs(domEvent), - NS_EVENT_FLAG_INIT, &status); - } - - // Trigger a reflow - if (aNotify && (nsnull != mDocument)) { - mDocument->ContentChanged(aOuterContent, nsnull); - mDocument->EndUpdate(); - } - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::SetText(nsIContent *aOuterContent, const char* aBuffer, - PRInt32 aLength, PRBool aNotify) -{ - NS_PRECONDITION((aLength >= 0) && (nsnull != aBuffer), "bad args"); - if (aLength < 0) { - return NS_ERROR_ILLEGAL_VALUE; - } - if (nsnull == aBuffer) { - return NS_ERROR_NULL_POINTER; - } - if (aNotify && (nsnull != mDocument)) { - mDocument->BeginUpdate(); - } - mText.SetTo(aBuffer, aLength); - - if (mDocument && nsGenericElement::HasMutationListeners(aOuterContent, NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED)) { - nsCOMPtr node(do_QueryInterface(aOuterContent)); - nsMutationEvent mutation; - mutation.eventStructType = NS_MUTATION_EVENT; - mutation.message = NS_MUTATION_CHARACTERDATAMODIFIED; - mutation.mTarget = node; - - // XXX Handle the setting of prevValue! - nsAutoString newVal; newVal.AssignWithConversion(aBuffer); - if (!newVal.IsEmpty()) - mutation.mNewAttrValue = getter_AddRefs(NS_NewAtom(newVal)); - nsEventStatus status = nsEventStatus_eIgnore; - nsCOMPtr domEvent; - HandleDOMEvent(nsnull, &mutation, getter_AddRefs(domEvent), - NS_EVENT_FLAG_INIT, &status); - } - - // Trigger a reflow - if (aNotify && (nsnull != mDocument)) { - mDocument->ContentChanged(aOuterContent, nsnull); - mDocument->EndUpdate(); - } - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::SetText(nsIContent *aOuterContent, - const nsAReadableString& aStr, - PRBool aNotify) -{ - if (aNotify && (nsnull != mDocument)) { - mDocument->BeginUpdate(); - } - mText = aStr; - - // Trigger a reflow - if (aNotify && (nsnull != mDocument)) { - mDocument->ContentChanged(aOuterContent, nsnull); - mDocument->EndUpdate(); - } - return NS_OK; -} - -nsresult -nsGenericDOMDataNode::IsOnlyWhitespace(PRBool* aResult) -{ - nsTextFragment& frag = mText; - if (frag.Is2b()) { - const PRUnichar* cp = frag.Get2b(); - const PRUnichar* end = cp + frag.GetLength(); - while (cp < end) { - PRUnichar ch = *cp++; - if (!XP_IS_SPACE(ch)) { - *aResult = PR_FALSE; - return NS_OK; - } - } - } - else { - const char* cp = frag.Get1b(); - const char* end = cp + frag.GetLength(); - while (cp < end) { - PRUnichar ch = PRUnichar(*(unsigned char*)cp); - cp++; - if (!XP_IS_SPACE(ch)) { - *aResult = PR_FALSE; - return NS_OK; - } - } - } - - *aResult = PR_TRUE; - return NS_OK; -} diff --git a/layout/base/src/nsGenericDOMDataNode.h b/layout/base/src/nsGenericDOMDataNode.h deleted file mode 100644 index 60694c8523c2..000000000000 --- a/layout/base/src/nsGenericDOMDataNode.h +++ /dev/null @@ -1,638 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsGenericDOMDataNode_h___ -#define nsGenericDOMDataNode_h___ - -#include "nsCOMPtr.h" -#include "nsIDOMCharacterData.h" -#include "nsIScriptObjectOwner.h" -#include "nsIDOMEventReceiver.h" -#include "nsIContent.h" -#include "nsTextFragment.h" -#include "nsVoidArray.h" -#include "nsINameSpaceManager.h" -#include "nsITextContent.h" -#include "nsDOMError.h" -#include "nsIEventListenerManager.h" - - -class nsIDOMAttr; -class nsIDOMEventListener; -class nsIDOMNodeList; -class nsIFrame; -class nsIStyleContext; -class nsIStyleRule; -class nsISupportsArray; -class nsIDOMText; -class nsINodeInfo; - -struct nsGenericDOMDataNode { - nsGenericDOMDataNode(); - virtual ~nsGenericDOMDataNode(); - - // Implementation for nsIDOMNode - nsresult GetNodeValue(nsAWritableString& aNodeValue); - nsresult SetNodeValue(nsIContent *aOuterContent, - const nsAReadableString& aNodeValue); - nsresult GetParentNode(nsIDOMNode** aParentNode); - nsresult GetAttributes(nsIDOMNamedNodeMap** aAttributes) { - NS_ENSURE_ARG_POINTER(aAttributes); - *aAttributes = nsnull; - return NS_OK; - } - nsresult GetPreviousSibling(nsIContent *aOuterContent, - nsIDOMNode** aPreviousSibling); - nsresult GetNextSibling(nsIContent *aOuterContent, - nsIDOMNode** aNextSibling); - nsresult GetChildNodes(nsIDOMNodeList** aChildNodes); - nsresult HasChildNodes(PRBool* aHasChildNodes) { - NS_ENSURE_ARG_POINTER(aHasChildNodes); - *aHasChildNodes = PR_FALSE; - return NS_OK; - } - nsresult HasAttributes(PRBool* aHasAttributes) { - NS_ENSURE_ARG_POINTER(aHasAttributes); - *aHasAttributes = PR_FALSE; - return NS_OK; - } - nsresult GetFirstChild(nsIDOMNode** aFirstChild) { - NS_ENSURE_ARG_POINTER(aFirstChild); - *aFirstChild = nsnull; - return NS_OK; - } - nsresult GetLastChild(nsIDOMNode** aLastChild) { - NS_ENSURE_ARG_POINTER(aLastChild); - *aLastChild = nsnull; - return NS_OK; - } - nsresult InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, - nsIDOMNode** aReturn) { - NS_ENSURE_ARG_POINTER(aReturn); - *aReturn = nsnull; - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - nsresult ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, - nsIDOMNode** aReturn) { - NS_ENSURE_ARG_POINTER(aReturn); - *aReturn = nsnull; - - /* - * Data nodes can't have children, i.e. aOldChild can't be a child of - * this node. - */ - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - nsresult RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { - NS_ENSURE_ARG_POINTER(aReturn); - *aReturn = nsnull; - - /* - * Data nodes can't have children, i.e. aOldChild can't be a child of - * this node. - */ - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - nsresult AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn) { - NS_ENSURE_ARG_POINTER(aReturn); - *aReturn = nsnull; - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - nsresult GetOwnerDocument(nsIDOMDocument** aOwnerDocument); - nsresult GetNamespaceURI(nsAWritableString& aNamespaceURI); - nsresult GetPrefix(nsAWritableString& aPrefix); - nsresult SetPrefix(const nsAReadableString& aPrefix); - nsresult Normalize(); - nsresult IsSupported(const nsAReadableString& aFeature, - const nsAReadableString& aVersion, - PRBool* aReturn); - - // Implementation for nsIDOMCharacterData - nsresult GetData(nsAWritableString& aData); - nsresult SetData(nsIContent *aOuterContent, const nsAReadableString& aData); - nsresult GetLength(PRUint32* aLength); - nsresult SubstringData(PRUint32 aOffset, PRUint32 aCount, nsAWritableString& aReturn); - nsresult AppendData(nsIContent *aOuterContent, const nsAReadableString& aArg); - nsresult InsertData(nsIContent *aOuterContent, PRUint32 aOffset, - const nsAReadableString& aArg); - nsresult DeleteData(nsIContent *aOuterContent, PRUint32 aOffset, - PRUint32 aCount); - nsresult ReplaceData(nsIContent *aOuterContent, PRUint32 aOffset, - PRUint32 aCount, const nsAReadableString& aArg); - - - // nsIScriptObjectOwner interface - nsresult GetScriptObject(nsIContent *aOuterContent, - nsIScriptContext* aContext, void** aScriptObject); - nsresult SetScriptObject(void *aScriptObject); - - // Implementation for nsIContent - nsresult GetDocument(nsIDocument*& aResult) const; - nsresult SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileEventHandlers); - nsresult GetParent(nsIContent*& aResult) const; - nsresult SetParent(nsIContent* aParent); - nsresult GetNameSpaceID(PRInt32& aID) const { - aID = kNameSpaceID_None; - return NS_OK; - } - nsresult NormalizeAttributeString(const nsAReadableString& aStr, - nsINodeInfo*& aNodeInfo) { - aNodeInfo = nsnull; - return NS_OK; - } - nsresult SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, const nsAReadableString& aValue, - PRBool aNotify) { - return NS_OK; - } - nsresult SetAttribute(nsINodeInfo *aNodeInfo, const nsAReadableString& aValue, - PRBool aNotify) { - return NS_OK; - } - nsresult UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRBool aNotify) { - return NS_OK; - } - nsresult GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute, nsAWritableString& aResult) const { - return NS_CONTENT_ATTR_NOT_THERE; - } - nsresult GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute, nsIAtom*& aPrefix, nsAWritableString& aResult) const { - aPrefix = nsnull; - return NS_CONTENT_ATTR_NOT_THERE; - } - nsresult GetAttributeNameAt(PRInt32 aIndex, PRInt32& aNameSpaceID, - nsIAtom*& aName, nsIAtom*& aPrefix) const { - aNameSpaceID = kNameSpaceID_None; - aName = nsnull; - aPrefix = nsnull; - return NS_ERROR_ILLEGAL_VALUE; - } - nsresult GetAttributeCount(PRInt32& aResult) const { - aResult = 0; - return NS_OK; - } - nsresult List(FILE* out, PRInt32 aIndent) const; - nsresult DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) const; - nsresult HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus); - nsresult RangeAdd(nsIDOMRange& aRange); - nsresult RangeRemove(nsIDOMRange& aRange); - nsresult GetRangeList(nsVoidArray*& aResult) const; - nsresult SetFocus(nsIPresContext *aPresContext); - nsresult RemoveFocus(nsIPresContext *aPresContext); - - nsresult GetBindingParent(nsIContent** aContent); - nsresult SetBindingParent(nsIContent* aParent); - - nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult, - size_t aInstanceSize) const; - - nsresult CanContainChildren(PRBool& aResult) const { - aResult = PR_FALSE; - return NS_OK; - } - nsresult ChildCount(PRInt32& aResult) const { - aResult = 0; - return NS_OK; - } - nsresult ChildAt(PRInt32 aIndex, nsIContent*& aResult) const { - aResult = nsnull; - return NS_OK; - } - nsresult IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const { - aResult = -1; - return NS_OK; - } - nsresult InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) { - return NS_OK; - } - nsresult ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) { - return NS_OK; - } - nsresult AppendChildTo(nsIContent* aKid, PRBool aNotify) { - return NS_OK; - } - nsresult RemoveChildAt(PRInt32 aIndex, PRBool aNotify) { - return NS_OK; - } - - nsresult SplitText(nsIContent *aOuterContent, PRUint32 aOffset, - nsIDOMText** aReturn); - - nsresult GetText(const nsTextFragment** aFragmentsResult); - nsresult GetTextLength(PRInt32* aLengthResult); - nsresult CopyText(nsAWritableString& aResult); - nsresult SetText(nsIContent *aOuterContent, - const PRUnichar* aBuffer, - PRInt32 aLength, - PRBool aNotify); - nsresult SetText(nsIContent *aOuterContent, - const nsAReadableString& aStr, - PRBool aNotify); - nsresult SetText(nsIContent *aOuterContent, - const char* aBuffer, - PRInt32 aLength, - PRBool aNotify); - nsresult IsOnlyWhitespace(PRBool* aResult); - - //---------------------------------------- - - nsresult GetListenerManager(nsIContent* aOuterContent, nsIEventListenerManager** aInstancePtrResult); - - void ToCString(nsAWritableString& aBuf, PRInt32 aOffset, PRInt32 aLen) const; - - nsIDocument* mDocument; - nsIContent* mParent; - void* mScriptObject; - nsIEventListenerManager* mListenerManager; - nsIContent* mCapturer; - - nsTextFragment mText; - nsVoidArray *mRangeList; -}; - -//---------------------------------------------------------------------- - -/** - * Mostly implement the nsIDOMNode API by forwarding the methods to a - * generic content object (either nsGenericHTMLLeafElement or - * nsGenericHTMLContainerContent) - * - * Note that classes using this macro will need to implement: - * NS_IMETHOD GetNodeType(PRUint16* aNodeType); - * NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn); - */ -#define NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(_g) \ - NS_IMETHOD GetNodeName(nsAWritableString& aNodeName); \ - NS_IMETHOD GetLocalName(nsAWritableString& aLocalName) { \ - return GetNodeName(aLocalName); \ - } \ - NS_IMETHOD GetNodeValue(nsAWritableString& aNodeValue) { \ - return _g.GetNodeValue(aNodeValue); \ - } \ - NS_IMETHOD SetNodeValue(const nsAReadableString& aNodeValue) { \ - return _g.SetNodeValue(this, aNodeValue); \ - } \ - NS_IMETHOD GetNodeType(PRUint16* aNodeType); \ - NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode) { \ - return _g.GetParentNode(aParentNode); \ - } \ - NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes) { \ - return _g.GetChildNodes(aChildNodes); \ - } \ - NS_IMETHOD HasChildNodes(PRBool* aHasChildNodes) { \ - return _g.HasChildNodes(aHasChildNodes); \ - } \ - NS_IMETHOD HasAttributes(PRBool* aHasAttributes) { \ - return _g.HasAttributes(aHasAttributes); \ - } \ - NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild) { \ - return _g.GetFirstChild(aFirstChild); \ - } \ - NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild) { \ - return _g.GetLastChild(aLastChild); \ - } \ - NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling) { \ - return _g.GetPreviousSibling(this, aPreviousSibling); \ - } \ - NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling) { \ - return _g.GetNextSibling(this, aNextSibling); \ - } \ - NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes) { \ - return _g.GetAttributes(aAttributes); \ - } \ - NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, \ - nsIDOMNode** aReturn) { \ - return _g.InsertBefore(aNewChild, aRefChild, aReturn); \ - } \ - NS_IMETHOD AppendChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { \ - return _g.AppendChild(aOldChild, aReturn); \ - } \ - NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, \ - nsIDOMNode** aReturn) { \ - return _g.ReplaceChild(aNewChild, aOldChild, aReturn); \ - } \ - NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { \ - return _g.RemoveChild(aOldChild, aReturn); \ - } \ - NS_IMETHOD GetOwnerDocument(nsIDOMDocument** aOwnerDocument) { \ - return _g.GetOwnerDocument(aOwnerDocument); \ - } \ - NS_IMETHOD GetNamespaceURI(nsAWritableString& aNamespaceURI) { \ - return _g.GetNamespaceURI(aNamespaceURI); \ - } \ - NS_IMETHOD GetPrefix(nsAWritableString& aPrefix) { \ - return _g.GetPrefix(aPrefix); \ - } \ - NS_IMETHOD SetPrefix(const nsAReadableString& aPrefix) { \ - return _g.SetPrefix(aPrefix); \ - } \ - NS_IMETHOD Normalize() { \ - return NS_OK; \ - } \ - NS_IMETHOD IsSupported(const nsAReadableString& aFeature, \ - const nsAReadableString& aVersion, \ - PRBool* aReturn) { \ - return _g.IsSupported(aFeature, aVersion, aReturn); \ - } \ - NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn); - -#define NS_IMPL_IDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(_g) \ - NS_IMETHOD GetData(nsAWritableString& aData) { \ - return _g.GetData(aData); \ - } \ - NS_IMETHOD SetData(const nsAReadableString& aData) { \ - return _g.SetData(this, aData); \ - } \ - NS_IMETHOD GetLength(PRUint32* aLength) { \ - return _g.GetLength(aLength); \ - } \ - NS_IMETHOD SubstringData(PRUint32 aStart, PRUint32 aEnd, nsAWritableString& aReturn) { \ - return _g.SubstringData(aStart, aEnd, aReturn); \ - } \ - NS_IMETHOD AppendData(const nsAReadableString& aData) { \ - return _g.AppendData(this, aData); \ - } \ - NS_IMETHOD InsertData(PRUint32 aOffset, const nsAReadableString& aData) { \ - return _g.InsertData(this, aOffset, aData); \ - } \ - NS_IMETHOD DeleteData(PRUint32 aOffset, PRUint32 aCount) { \ - return _g.DeleteData(this, aOffset, aCount); \ - } \ - NS_IMETHOD ReplaceData(PRUint32 aOffset, PRUint32 aCount, \ - const nsAReadableString& aData) { \ - return _g.ReplaceData(this, aOffset, aCount, aData); \ - } - - -/** - * Implement the nsIDOMEventReceiver API by forwarding the methods to a - * generic content object (either nsGenericHTMLLeafElement or - * nsGenericHTMLContainerContent) - */ -#define NS_IMPL_IDOMEVENTRECEIVER_USING_GENERIC_DOM_DATA(_g) \ - NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, \ - const nsIID& aIID) { \ - return _g.AddEventListenerByIID(aListener, aIID); \ - } \ - NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, \ - const nsIID& aIID) { \ - return _g.RemoveEventListenerByIID(aListener, aIID); \ - } \ - NS_IMETHOD GetListenerManager(nsIEventListenerManager** aResult) { \ - return _g.GetListenerManager(aResult); \ - } \ - NS_IMETHOD GetNewListenerManager(nsIEventListenerManager** aResult) { \ - return _g.GetNewListenerManager(aResult); \ - } \ - NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent) { \ - return _g.HandleEvent(aEvent); \ - } \ - NS_IMETHOD AddEventListener(const nsAReadableString& aType, \ - nsIDOMEventListener* aListener, \ - PRBool aUseCapture) { \ - return _g.AddEventListener(aType, aListener, aUseCapture); \ - } \ - NS_IMETHOD RemoveEventListener(const nsAReadableString& aType, \ - nsIDOMEventListener* aListener, \ - PRBool aUseCapture) { \ - return _g.RemoveEventListener(aType, aListener, aUseCapture); \ - } - -/** - * Implement the nsIScriptObjectOwner API by forwarding the methods to a - * generic content object (either nsGenericHTMLLeafElement or - * nsGenericHTMLContainerContent) - */ -#define NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC_DOM_DATA(_g) \ - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, \ - void** aScriptObject) { \ - return _g.GetScriptObject(this, aContext, aScriptObject); \ - } \ - NS_IMETHOD SetScriptObject(void *aScriptObject) { \ - return _g.SetScriptObject(aScriptObject); \ - } - -#define NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(_g) \ - NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \ - return _g.GetDocument(aResult); \ - } \ - NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileEventHandlers) { \ - return _g.SetDocument(aDocument, aDeep, aCompileEventHandlers); \ - } \ - NS_IMETHOD GetParent(nsIContent*& aResult) const { \ - return _g.GetParent(aResult); \ - } \ - NS_IMETHOD SetParent(nsIContent* aParent) { \ - return _g.SetParent(aParent); \ - } \ - NS_IMETHOD CanContainChildren(PRBool& aResult) const { \ - return _g.CanContainChildren(aResult); \ - } \ - NS_IMETHOD ChildCount(PRInt32& aResult) const { \ - return _g.ChildCount(aResult); \ - } \ - NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const { \ - return _g.ChildAt(aIndex, aResult); \ - } \ - NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const { \ - return _g.IndexOf(aPossibleChild, aResult); \ - } \ - NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, \ - PRBool aNotify) { \ - return _g.InsertChildAt(aKid, aIndex, aNotify); \ - } \ - NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, \ - PRBool aNotify) { \ - return _g.ReplaceChildAt(aKid, aIndex, aNotify); \ - } \ - NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) { \ - return _g.AppendChildTo(aKid, aNotify); \ - } \ - NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) { \ - return _g.RemoveChildAt(aIndex, aNotify); \ - } \ - NS_IMETHOD GetNameSpaceID(PRInt32& aID) const { \ - return _g.GetNameSpaceID(aID); \ - } \ - NS_IMETHOD GetTag(nsIAtom*& aResult) const; \ - NS_IMETHOD GetNodeInfo(nsINodeInfo*& aResult) const; \ - NS_IMETHOD NormalizeAttributeString(const nsAReadableString& aStr, \ - nsINodeInfo*& aNodeInfo) { \ - return _g.NormalizeAttributeString(aStr, aNodeInfo); \ - } \ - NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute, \ - nsAWritableString& aResult) const { \ - return _g.GetAttribute(aNameSpaceID, aAttribute, aResult); \ - } \ - NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom *aAttribute, \ - nsIAtom*& aPrefix, nsAWritableString& aResult) const { \ - return _g.GetAttribute(aNameSpaceID, aAttribute, aPrefix, aResult); \ - } \ - NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, \ - const nsAReadableString& aValue, PRBool aNotify) { \ - return _g.SetAttribute(aNameSpaceID, aAttribute, aValue, aNotify); \ - } \ - NS_IMETHOD SetAttribute(nsINodeInfo* aNodeInfo, \ - const nsAReadableString& aValue, PRBool aNotify) { \ - return _g.SetAttribute(aNodeInfo, aValue, aNotify); \ - } \ - NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, \ - PRBool aNotify) { \ - return _g.UnsetAttribute(aNameSpaceID, aAttribute, aNotify); \ - } \ - NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, \ - PRInt32& aNameSpaceID, \ - nsIAtom*& aName, \ - nsIAtom*& aPrefix) const { \ - return _g.GetAttributeNameAt(aIndex, aNameSpaceID, aName, aPrefix); \ - } \ - NS_IMETHOD GetAttributeCount(PRInt32& aResult) const { \ - return _g.GetAttributeCount(aResult); \ - } \ - NS_IMETHOD List(FILE* out, PRInt32 aIndent) const; \ - NS_IMETHOD DumpContent(FILE* out, \ - PRInt32 aIndent, \ - PRBool aDumpAll) const; \ - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, \ - nsEvent* aEvent, \ - nsIDOMEvent** aDOMEvent, \ - PRUint32 aFlags, \ - nsEventStatus* aEventStatus); \ - NS_IMETHOD GetContentID(PRUint32* aID); \ - NS_IMETHOD SetContentID(PRUint32 aID); \ - NS_IMETHOD RangeAdd(nsIDOMRange& aRange){ \ - return _g.RangeAdd(aRange); \ - } \ - NS_IMETHOD RangeRemove(nsIDOMRange& aRange){ \ - return _g.RangeRemove(aRange); \ - } \ - NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const { \ - return _g.GetRangeList(aResult); \ - } \ - NS_IMETHOD SetFocus(nsIPresContext* aPresContext) { \ - return _g.SetFocus(aPresContext); \ - } \ - NS_IMETHOD RemoveFocus(nsIPresContext* aPresContext) { \ - return _g.RemoveFocus(aPresContext); \ - } \ - NS_IMETHOD GetBindingParent(nsIContent** aContent) { \ - return _g.GetBindingParent(aContent); \ - } \ - NS_IMETHOD SetBindingParent(nsIContent* aParent) { \ - return _g.SetBindingParent(aParent); \ - } - -/** - * Implement the nsIDOMText API by forwarding the methods to a - * generic character data content object. - */ -#define NS_IMPL_IDOMTEXT_USING_GENERIC_DOM_DATA(_g) \ - NS_IMETHOD SplitText(PRUint32 aOffset, nsIDOMText** aReturn){ \ - return _g.SplitText(this, aOffset, aReturn); \ - } - -/** - * Implement the nsITextContent API by forwarding the methods to a - * generic character data content object. - */ -#define NS_IMPL_ITEXTCONTENT_USING_GENERIC_DOM_DATA(_g) \ - NS_IMETHOD GetText(const nsTextFragment** aFragmentsResult) { \ - return mInner.GetText(aFragmentsResult); \ - } \ - NS_IMETHOD GetTextLength(PRInt32* aLengthResult) { \ - return mInner.GetTextLength(aLengthResult); \ - } \ - NS_IMETHOD CopyText(nsAWritableString& aResult) { \ - return mInner.CopyText(aResult); \ - } \ - NS_IMETHOD SetText(const PRUnichar* aBuffer, \ - PRInt32 aLength, \ - PRBool aNotify){ \ - return mInner.SetText(this, aBuffer, aLength, aNotify); \ - } \ - NS_IMETHOD SetText(const nsAReadableString& aStr, \ - PRBool aNotify){ \ - return mInner.SetText(this, aStr, aNotify); \ - } \ - NS_IMETHOD SetText(const char* aBuffer, \ - PRInt32 aLength, \ - PRBool aNotify){ \ - return mInner.SetText(this, aBuffer, aLength, aNotify); \ - } \ - NS_IMETHOD IsOnlyWhitespace(PRBool* aResult){ \ - return mInner.IsOnlyWhitespace(aResult); \ - } \ - NS_IMETHOD CloneContent(PRBool aCloneText, nsITextContent** aClone); - -/** - * This macro implements the portion of query interface that is - * generic to all html content objects. - */ -#define NS_IMPL_DOM_DATA_QUERY_INTERFACE(_id, _iptr, _this) \ - if (_id.Equals(NS_GET_IID(nsISupports))) { \ - nsIContent* tmp = _this; \ - nsISupports* tmp2 = tmp; \ - *_iptr = (void*) tmp2; \ - NS_ADDREF_THIS(); \ - return NS_OK; \ - } \ - if (_id.Equals(NS_GET_IID(nsIDOMNode))) { \ - nsIDOMNode* tmp = _this; \ - *_iptr = (void*) tmp; \ - NS_ADDREF_THIS(); \ - return NS_OK; \ - } \ - if (_id.Equals(NS_GET_IID(nsIDOMCharacterData))) { \ - nsIDOMCharacterData* tmp = _this; \ - *_iptr = (void*) tmp; \ - NS_ADDREF_THIS(); \ - return NS_OK; \ - } \ - if (_id.Equals(NS_GET_IID(nsIDOMEventReceiver))) { \ - nsCOMPtr man; \ - if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ \ - return man->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), (void**)_iptr); \ - } \ - return NS_NOINTERFACE; \ - } \ - if (_id.Equals(NS_GET_IID(nsIDOMEventTarget))) { \ - nsCOMPtr man; \ - if (NS_SUCCEEDED(mInner.GetListenerManager(this, getter_AddRefs(man)))){ \ - return man->QueryInterface(NS_GET_IID(nsIDOMEventTarget), (void**)_iptr); \ - } \ - return NS_NOINTERFACE; \ - } \ - if (_id.Equals(NS_GET_IID(nsIScriptObjectOwner))) { \ - nsIScriptObjectOwner* tmp = _this; \ - *_iptr = (void*) tmp; \ - NS_ADDREF_THIS(); \ - return NS_OK; \ - } \ - if (_id.Equals(NS_GET_IID(nsIContent))) { \ - nsIContent* tmp = _this; \ - *_iptr = (void*) tmp; \ - NS_ADDREF_THIS(); \ - return NS_OK; \ - } - -#endif /* nsGenericDOMDataNode_h___ */ diff --git a/layout/base/src/nsGenericDOMNodeList.cpp b/layout/base/src/nsGenericDOMNodeList.cpp deleted file mode 100644 index e624bf0067af..000000000000 --- a/layout/base/src/nsGenericDOMNodeList.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsGenericDOMNodeList.h" -#include "nsIDOMScriptObjectFactory.h" -#include "nsGenericElement.h" - -nsGenericDOMNodeList::nsGenericDOMNodeList() -{ - NS_INIT_REFCNT(); - mScriptObject = nsnull; -} - -nsGenericDOMNodeList::~nsGenericDOMNodeList() -{ -} - -nsresult -nsGenericDOMNodeList::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } - if (aIID.Equals(NS_GET_IID(nsIDOMNodeList))) { - *aInstancePtr = (void*)(nsIDOMNodeList*)this; - AddRef(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - *aInstancePtr = (void*)(nsIScriptObjectOwner*)this; - AddRef(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsISupports))) { - *aInstancePtr = (void*)(nsISupports*)(nsIDOMNodeList*)this; - AddRef(); - return NS_OK; - } - return NS_NOINTERFACE; -} - -NS_IMPL_ADDREF(nsGenericDOMNodeList) -NS_IMPL_RELEASE(nsGenericDOMNodeList) - -NS_IMETHODIMP -nsGenericDOMNodeList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) -{ - nsresult res = NS_OK; - if (nsnull == mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = nsGenericElement::GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - res = factory->NewScriptNodeList(aContext, (nsISupports *)(nsIDOMNodeList *)this, nsnull, (void**)&mScriptObject); - NS_RELEASE(factory); - } - *aScriptObject = mScriptObject; - return res; -} - -NS_IMETHODIMP -nsGenericDOMNodeList::SetScriptObject(void *aScriptObject) -{ - mScriptObject = aScriptObject; - return NS_OK; -} diff --git a/layout/base/src/nsGenericDOMNodeList.h b/layout/base/src/nsGenericDOMNodeList.h deleted file mode 100644 index bc5322798fdf..000000000000 --- a/layout/base/src/nsGenericDOMNodeList.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsGenericDOMNodeList_h__ -#define nsGenericDOMNodeList_h__ - -#include "nsISupports.h" -#include "nsIDOMNodeList.h" -#include "nsIScriptObjectOwner.h" - -/** - * This is a base class for a generic DOM Node List. The base class - * provides implementations for nsISupports and nsIScriptObjectOwner, - * but it is up to the subclass to implement the core node list - * methods: - * GetLength - * Item - * - */ -class nsGenericDOMNodeList : public nsIDOMNodeList, - public nsIScriptObjectOwner -{ -public: - nsGenericDOMNodeList(); - virtual ~nsGenericDOMNodeList(); - - NS_DECL_ISUPPORTS - - NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - - // The following need to be defined in the subclass - // nsIDOMNodeList interface - NS_IMETHOD GetLength(PRUint32* aLength)=0; - NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn)=0; - -protected: - void* mScriptObject; -}; - -#endif // nsGenericDOMNodeList_h__ diff --git a/layout/base/src/nsGenericElement.cpp b/layout/base/src/nsGenericElement.cpp deleted file mode 100644 index 06f874ec09cc..000000000000 --- a/layout/base/src/nsGenericElement.cpp +++ /dev/null @@ -1,3505 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#include "nsGenericElement.h" - -#include "nsDOMAttribute.h" -#include "nsDOMAttributeMap.h" -#include "nsIAtom.h" -#include "nsINodeInfo.h" -#include "nsIDocument.h" -#include "nsIDOMNodeList.h" -#include "nsIDOMDocument.h" -#include "nsIDOMRange.h" -#include "nsIDOMText.h" -#include "nsIDOMEventReceiver.h" -#include "nsRange.h" -#include "nsIEventListenerManager.h" -#include "nsILinkHandler.h" -#include "nsIScriptGlobalObject.h" -#include "nsISizeOfHandler.h" -#include "nsISupportsArray.h" -#include "nsIURL.h" -#include "nsNetUtil.h" -#include "nsIFrame.h" -#include "nsIPresShell.h" -#include "nsIPresContext.h" -#include "nsIView.h" -#include "nsIViewManager.h" -#include "nsString.h" -#include "nsDOMEventsIIDs.h" -#include "nsIEventStateManager.h" -#include "nsIDOMEvent.h" -#include "nsIPrivateDOMEvent.h" -#include "nsDOMCID.h" -#include "nsIServiceManager.h" -#include "nsIDOMScriptObjectFactory.h" -#include "nsIDOMCSSStyleDeclaration.h" -#include "nsDOMCSSDeclaration.h" -#include "nsINameSpaceManager.h" -#include "nsContentList.h" -#include "nsDOMError.h" -#include "nsScriptSecurityManager.h" -#include "nsIDOMMutationEvent.h" -#include "nsMutationEvent.h" - -#include "nsIBindingManager.h" -#include "nsIXBLBinding.h" -#include "nsIDOMCSSStyleDeclaration.h" -#include "nsIDOMViewCSS.h" -#include "nsIXBLService.h" -#include "nsPIDOMWindow.h" -#include "nsIBoxObject.h" -#include "nsPIBoxObject.h" -#include "nsIDOMNSDocument.h" - -#include "nsLayoutAtoms.h" -#include "nsHTMLAtoms.h" -#include "nsLayoutUtils.h" -#include "nsIJSContextStack.h" - -#include "nsIServiceManager.h" - -//---------------------------------------------------------------------- - -nsChildContentList::nsChildContentList(nsIContent *aContent) -{ - // This reference is not reference-counted. The content - // object tells us when its about to go away. - mContent = aContent; -} - -nsChildContentList::~nsChildContentList() -{ -} - -NS_IMETHODIMP -nsChildContentList::GetLength(PRUint32* aLength) -{ - if (nsnull != mContent) { - PRInt32 length; - mContent->ChildCount(length); - *aLength = (PRUint32)length; - } - else { - *aLength = 0; - } - return NS_OK; -} - -NS_IMETHODIMP -nsChildContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn) -{ - nsIContent *content; - nsresult res = NS_OK; - - if (nsnull != mContent) { - mContent->ChildAt(aIndex, content); - if (nsnull != content) { - res = content->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aReturn); - NS_RELEASE(content); - } - else { - *aReturn = nsnull; - } - } - else { - *aReturn = nsnull; - } - - return res; -} - -void -nsChildContentList::DropReference() -{ - mContent = nsnull; -} - -//---------------------------------------------------------------------- - -nsCheapVoidArray::nsCheapVoidArray() -{ - mChildren = nsnull; -} - -nsCheapVoidArray::~nsCheapVoidArray() -{ - if (!HasSingleChild()) { - nsVoidArray* vector = GetChildVector(); - if (vector) { - delete vector; - } - } -} - -PRInt32 -nsCheapVoidArray::Count() const -{ - if (HasSingleChild()) { - return 1; - } - else { - nsVoidArray* vector = GetChildVector(); - if (vector) { - return vector->Count(); - } - } - - return 0; -} - -void* -nsCheapVoidArray::ElementAt(PRInt32 aIndex) const -{ - if (HasSingleChild()) { - if (0 == aIndex) { - return (void*)GetSingleChild(); - } - } - else { - nsVoidArray* vector = GetChildVector(); - if (vector) { - return vector->ElementAt(aIndex); - } - } - - return nsnull; -} - -PRInt32 -nsCheapVoidArray::IndexOf(void* aPossibleElement) const -{ - if (HasSingleChild()) { - if (aPossibleElement == (void*)GetSingleChild()) { - return 0; - } - } - else { - nsVoidArray* vector = GetChildVector(); - if (vector) { - return vector->IndexOf(aPossibleElement); - } - } - - return -1; -} - -PRBool -nsCheapVoidArray::InsertElementAt(void* aElement, PRInt32 aIndex) -{ - nsVoidArray* vector; - if (HasSingleChild()) { - vector = SwitchToVector(); - } - else { - vector = GetChildVector(); - if (!vector) { - if (0 == aIndex) { - SetSingleChild(aElement); - return PR_TRUE; - } - else { - return PR_FALSE; - } - } - } - - return vector->InsertElementAt(aElement, aIndex); -} - -PRBool -nsCheapVoidArray::ReplaceElementAt(void* aElement, PRInt32 aIndex) -{ - if (HasSingleChild()) { - if (aIndex == 0) { - SetSingleChild(aElement); - return PR_TRUE; - } - else { - return PR_FALSE; - } - } - else { - nsVoidArray* vector = GetChildVector(); - if (vector) { - return vector->ReplaceElementAt(aElement, aIndex); - } - else { - return PR_FALSE; - } - } -} - -PRBool -nsCheapVoidArray::AppendElement(void* aElement) -{ - nsVoidArray* vector; - if (HasSingleChild()) { - vector = SwitchToVector(); - } - else { - vector = GetChildVector(); - if (!vector) { - SetSingleChild(aElement); - return PR_TRUE; - } - } - - return vector->AppendElement(aElement); -} - -PRBool -nsCheapVoidArray::RemoveElement(void* aElement) -{ - if (HasSingleChild()) { - if (aElement == GetSingleChild()) { - SetSingleChild(nsnull); - return PR_TRUE; - } - } - else { - nsVoidArray* vector = GetChildVector(); - if (vector) { - return vector->RemoveElement(aElement); - } - } - - return PR_FALSE; -} - -PRBool -nsCheapVoidArray::RemoveElementAt(PRInt32 aIndex) -{ - if (HasSingleChild()) { - if (0 == aIndex) { - SetSingleChild(nsnull); - return PR_TRUE; - } - } - else { - nsVoidArray* vector = GetChildVector(); - if (vector) { - return vector->RemoveElementAt(aIndex); - } - } - - return PR_FALSE; -} - -void -nsCheapVoidArray::Compact() -{ - if (!HasSingleChild()) { - nsVoidArray* vector = GetChildVector(); - if (vector) { - vector->Compact(); - } - } -} - -void -nsCheapVoidArray::SetSingleChild(void* aChild) -{ - if (aChild) - mChildren = (void*)(PtrBits(aChild) | 0x1); - else - mChildren = nsnull; -} - -nsVoidArray* -nsCheapVoidArray::SwitchToVector() -{ - void* child = GetSingleChild(); - - mChildren = (void*)new nsVoidArray(); - nsVoidArray* vector = GetChildVector(); - if (vector && child) { - vector->AppendElement(child); - } - - return vector; -} - -//---------------------------------------------------------------------- - -// XXX Currently, the script object factory is global. The way we -// obtain it should, at least, be made thread-safe later. Ideally, -// we'd find a better way. -nsIDOMScriptObjectFactory* nsGenericElement::gScriptObjectFactory = nsnull; - -static NS_DEFINE_IID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); - -nsresult -nsGenericElement::GetScriptObjectFactory(nsIDOMScriptObjectFactory **aResult) -{ - nsresult result = NS_OK; - - if (nsnull == gScriptObjectFactory) { - result = nsServiceManager::GetService(kDOMScriptObjectFactoryCID, - NS_GET_IID(nsIDOMScriptObjectFactory), - (nsISupports **)&gScriptObjectFactory); - if (result != NS_OK) { - return result; - } - } - - *aResult = gScriptObjectFactory; - NS_ADDREF(gScriptObjectFactory); - return result; -} - -/* static */ void -nsGenericElement::Shutdown() -{ - NS_IF_RELEASE(gScriptObjectFactory); // assigns null -} - -nsGenericElement::nsGenericElement() : mDocument(nsnull), mParent(nsnull), - mNodeInfo(nsnull), mDOMSlots(nsnull), - mContentID(0) -{ - NS_INIT_REFCNT(); -} - -nsGenericElement::~nsGenericElement() -{ - // pop any enclosed ranges out - // nsRange::OwnerGone(mContent); not used for now - if (mDOMSlots) { - if (mDOMSlots->mChildNodes) { - mDOMSlots->mChildNodes->DropReference(); - NS_RELEASE(mDOMSlots->mChildNodes); - delete mDOMSlots->mRangeList; - } - if (mDOMSlots->mStyle) { - mDOMSlots->mStyle->DropReference(); - NS_RELEASE(mDOMSlots->mStyle); - } - if (mDOMSlots->mAttributeMap) { - mDOMSlots->mAttributeMap->DropReference(); - NS_RELEASE(mDOMSlots->mAttributeMap); - } - if (mDOMSlots->mListenerManager) { - mDOMSlots->mListenerManager->SetListenerTarget(nsnull); - NS_RELEASE(mDOMSlots->mListenerManager); - } - - // XXX Should really be arena managed - delete mDOMSlots; - mDOMSlots = nsnull; - } - - NS_IF_RELEASE(mNodeInfo); -} - -nsDOMSlots * -nsGenericElement::GetDOMSlots() -{ - if (!mDOMSlots) { - mDOMSlots = new nsDOMSlots; - - if (!mDOMSlots) - return nsnull; - - mDOMSlots->mScriptObject = nsnull; - mDOMSlots->mChildNodes = nsnull; - mDOMSlots->mStyle = nsnull; - mDOMSlots->mAttributeMap = nsnull; - mDOMSlots->mRangeList = nsnull; - mDOMSlots->mCapturer = nsnull; - mDOMSlots->mListenerManager = nsnull; - mDOMSlots->mBindingParent = nsnull; - } - - return mDOMSlots; -} - -void -nsGenericElement::MaybeClearDOMSlots() -{ - if (mDOMSlots && - !mDOMSlots->mScriptObject && - !mDOMSlots->mChildNodes && - !mDOMSlots->mStyle && - !mDOMSlots->mAttributeMap && - !mDOMSlots->mRangeList && - !mDOMSlots->mCapturer && - !mDOMSlots->mListenerManager && - !mDOMSlots->mBindingParent) { - - delete mDOMSlots; - mDOMSlots = nsnull; - } -} - -nsresult -nsGenericElement::Init(nsINodeInfo *aNodeInfo) -{ - NS_ENSURE_ARG(aNodeInfo); - - mNodeInfo = aNodeInfo; - NS_ADDREF(mNodeInfo); - - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::GetNodeName(nsAWritableString& aNodeName) -{ - return mNodeInfo->GetQualifiedName(aNodeName); -} - -NS_IMETHODIMP -nsGenericElement::GetLocalName(nsAWritableString& aLocalName) -{ - return mNodeInfo->GetLocalName(aLocalName); -} - -NS_IMETHODIMP -nsGenericElement::GetNodeValue(nsAWritableString& aNodeValue) -{ - aNodeValue.Truncate(); - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::SetNodeValue(const nsAReadableString& aNodeValue) -{ - // The node value can't be modified - return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR; -} - -NS_IMETHODIMP -nsGenericElement::GetNodeType(PRUint16* aNodeType) -{ - *aNodeType = (PRUint16)nsIDOMNode::ELEMENT_NODE; - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::GetParentNode(nsIDOMNode** aParentNode) -{ - nsresult res = NS_OK; - - if (nsnull != mParent) { - res = mParent->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)aParentNode); - NS_ASSERTION(NS_OK == res, "Must be a DOM Node"); - } - else if (nsnull == mDocument) { - *aParentNode = nsnull; - } - else { - // If we don't have a parent, but we're in the document, we must - // be the root node of the document. The DOM says that the root - // is the document. - res = mDocument->QueryInterface(NS_GET_IID(nsIDOMNode), - (void**)aParentNode); - } - - return res; -} - -NS_IMETHODIMP -nsGenericElement::GetPreviousSibling(nsIDOMNode** aPrevSibling) -{ - nsIContent* sibling = nsnull; - nsresult result = NS_OK; - - if (nsnull != mParent) { - PRInt32 pos; - mParent->IndexOf(this, pos); - if (pos > -1 ) { - mParent->ChildAt(--pos, sibling); - } - } - else if (nsnull != mDocument) { - // Nodes that are just below the document (their parent is the - // document) need to go to the document to find their next sibling. - PRInt32 pos; - mDocument->IndexOf(this, pos); - if (pos > -1 ) { - mDocument->ChildAt(--pos, sibling); - } - } - - if (nsnull != sibling) { - result = sibling->QueryInterface(NS_GET_IID(nsIDOMNode), - (void**)aPrevSibling); - NS_ASSERTION(NS_OK == result, "Must be a DOM Node"); - NS_RELEASE(sibling); // balance the AddRef in ChildAt() - } - else { - *aPrevSibling = nsnull; - } - - return result; -} - -NS_IMETHODIMP -nsGenericElement::GetNextSibling(nsIDOMNode** aNextSibling) -{ - nsIContent* sibling = nsnull; - nsresult result = NS_OK; - - if (nsnull != mParent) { - PRInt32 pos; - mParent->IndexOf(this, pos); - if (pos > -1 ) { - mParent->ChildAt(++pos, sibling); - } - } - else if (nsnull != mDocument) { - // Nodes that are just below the document (their parent is the - // document) need to go to the document to find their next sibling. - PRInt32 pos; - mDocument->IndexOf(this, pos); - if (pos > -1 ) { - mDocument->ChildAt(++pos, sibling); - } - } - - if (nsnull != sibling) { - result = sibling->QueryInterface(NS_GET_IID(nsIDOMNode), - (void**)aNextSibling); - NS_ASSERTION(NS_OK == result, "Must be a DOM Node"); - NS_RELEASE(sibling); // balance the AddRef in ChildAt() - } - else { - *aNextSibling = nsnull; - } - - return result; -} - -NS_IMETHODIMP -nsGenericElement::GetOwnerDocument(nsIDOMDocument** aOwnerDocument) -{ - // XXX Actually the owner document is the document in whose context - // the element has been created. We should be able to get at it - // whether or not we are attached to the document. - if (nsnull != mDocument) { - return mDocument->QueryInterface(NS_GET_IID(nsIDOMDocument), - (void **)aOwnerDocument); - } - else { - *aOwnerDocument = nsnull; - return NS_OK; - } -} - -NS_IMETHODIMP -nsGenericElement::GetNamespaceURI(nsAWritableString& aNamespaceURI) -{ - return mNodeInfo->GetNamespaceURI(aNamespaceURI); -} - -NS_IMETHODIMP -nsGenericElement::GetPrefix(nsAWritableString& aPrefix) -{ - return mNodeInfo->GetPrefix(aPrefix); -} - -NS_IMETHODIMP -nsGenericElement::SetPrefix(const nsAReadableString& aPrefix) -{ - // XXX: Validate the prefix string! - - nsINodeInfo *newNodeInfo = nsnull; - nsCOMPtr prefix; - - if (aPrefix.Length()) { - prefix = dont_AddRef(NS_NewAtom(aPrefix)); - NS_ENSURE_TRUE(prefix, NS_ERROR_OUT_OF_MEMORY); - } - - nsresult rv = mNodeInfo->PrefixChanged(prefix, newNodeInfo); - NS_ENSURE_SUCCESS(rv, rv); - - NS_RELEASE(mNodeInfo); - - mNodeInfo = newNodeInfo; - - return NS_OK; -} - -nsresult -nsGenericElement::InternalIsSupported(const nsAReadableString& aFeature, - const nsAReadableString& aVersion, - PRBool* aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - *aReturn = PR_FALSE; - nsAutoString feature(aFeature); - - if (feature.EqualsWithConversion("XML", PR_TRUE) || - feature.EqualsWithConversion("HTML", PR_TRUE)) { - if (!aVersion.Length() || - aVersion.Equals(NS_LITERAL_STRING("1.0")) || - aVersion.Equals(NS_LITERAL_STRING("2.0"))) { - *aReturn = PR_TRUE; - } - } else if (feature.EqualsWithConversion("Views", PR_TRUE) || - feature.EqualsWithConversion("StyleSheets", PR_TRUE) || - feature.EqualsWithConversion("CSS", PR_TRUE) || -// feature.EqualsWithConversion("CSS2", PR_TRUE) || - feature.EqualsWithConversion("Events", PR_TRUE) || -// feature.EqualsWithConversion("UIEvents", PR_TRUE) || - feature.EqualsWithConversion("MouseEvents", PR_TRUE) || - feature.EqualsWithConversion("HTMLEvents", PR_TRUE) || - feature.EqualsWithConversion("Range", PR_TRUE)) { - if (!aVersion.Length() || aVersion.Equals(NS_LITERAL_STRING("2.0"))) { - *aReturn = PR_TRUE; - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::IsSupported(const nsAReadableString& aFeature, - const nsAReadableString& aVersion, - PRBool* aReturn) -{ - return InternalIsSupported(aFeature, aVersion, aReturn); -} - -NS_IMETHODIMP -nsGenericElement::HasAttributes(PRBool* aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - PRInt32 attrCount = 0; - - GetAttributeCount(attrCount); - - *aReturn = !!attrCount; - - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::GetAttributes(nsIDOMNamedNodeMap** aAttributes) -{ - NS_PRECONDITION(nsnull != aAttributes, "null pointer argument"); - nsDOMSlots *slots = GetDOMSlots(); - - if (nsnull == slots->mAttributeMap) { - slots->mAttributeMap = new nsDOMAttributeMap(this); - if (nsnull == slots->mAttributeMap) { - return NS_ERROR_OUT_OF_MEMORY; - } - NS_ADDREF(slots->mAttributeMap); - } - - return slots->mAttributeMap->QueryInterface(NS_GET_IID(nsIDOMNamedNodeMap), - (void **)aAttributes); -} - -NS_IMETHODIMP -nsGenericElement::GetTagName(nsAWritableString& aTagName) -{ - aTagName.Truncate(); - if (mNodeInfo) { - mNodeInfo->GetName(aTagName); - } - return NS_OK; -} - -nsresult -nsGenericElement::GetAttribute(const nsAReadableString& aName, - nsAWritableString& aReturn) -{ - nsCOMPtr ni; - NormalizeAttributeString(aName, *getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - PRInt32 nsid; - nsCOMPtr nameAtom; - - ni->GetNamespaceID(nsid); - ni->GetNameAtom(*getter_AddRefs(nameAtom)); - - NS_STATIC_CAST(nsIContent *, this)->GetAttribute(nsid, nameAtom, aReturn); - - return NS_OK; -} - -nsresult -nsGenericElement::SetAttribute(const nsAReadableString& aName, - const nsAReadableString& aValue) -{ - nsCOMPtr ni; - NormalizeAttributeString(aName, *getter_AddRefs(ni)); - return NS_STATIC_CAST(nsIContent *, this)->SetAttribute(ni, aValue, PR_TRUE); -} - -nsresult -nsGenericElement::RemoveAttribute(const nsAReadableString& aName) -{ - nsCOMPtr ni; - NormalizeAttributeString(aName, *getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - PRInt32 nsid; - nsCOMPtr tag; - - ni->GetNamespaceID(nsid); - ni->GetNameAtom(*getter_AddRefs(tag)); - - return UnsetAttribute(nsid, tag, PR_TRUE); -} - -nsresult -nsGenericElement::GetAttributeNode(const nsAReadableString& aName, - nsIDOMAttr** aReturn) -{ - if (nsnull == aReturn) { - return NS_ERROR_NULL_POINTER; - } - nsIDOMNamedNodeMap* map; - nsresult result = GetAttributes(&map); - - *aReturn = nsnull; - if (NS_OK == result) { - nsIDOMNode* node; - result = map->GetNamedItem(aName, &node); - if ((NS_OK == result) && (nsnull != node)) { - result = node->QueryInterface(NS_GET_IID(nsIDOMAttr), (void **)aReturn); - NS_IF_RELEASE(node); - } - NS_RELEASE(map); - } - - return result; -} - -nsresult -nsGenericElement::SetAttributeNode(nsIDOMAttr* aAttribute, - nsIDOMAttr** aReturn) -{ - if ((nsnull == aReturn) || (nsnull == aAttribute)) { - return NS_ERROR_NULL_POINTER; - } - nsIDOMNamedNodeMap* map; - nsresult result = GetAttributes(&map); - - *aReturn = nsnull; - if (NS_OK == result) { - nsIDOMNode *node, *returnNode; - result = aAttribute->QueryInterface(NS_GET_IID(nsIDOMNode), - (void **)&node); - if (NS_OK == result) { - result = map->SetNamedItem(node, &returnNode); - if ((NS_OK == result) && (nsnull != returnNode)) { - result = returnNode->QueryInterface(NS_GET_IID(nsIDOMAttr), - (void **)aReturn); - NS_IF_RELEASE(returnNode); - } - NS_RELEASE(node); - } - NS_RELEASE(map); - } - - return result; -} - -nsresult -nsGenericElement::RemoveAttributeNode(nsIDOMAttr* aAttribute, - nsIDOMAttr** aReturn) -{ - if ((nsnull == aReturn) || (nsnull == aAttribute)) { - return NS_ERROR_NULL_POINTER; - } - nsIDOMNamedNodeMap* map; - nsresult result = GetAttributes(&map); - - *aReturn = nsnull; - if (NS_OK == result) { - nsAutoString name; - - result = aAttribute->GetName(name); - if (NS_OK == result) { - nsIDOMNode* node; - result = map->RemoveNamedItem(name, &node); - if ((NS_OK == result) && (nsnull != node)) { - result = node->QueryInterface(NS_GET_IID(nsIDOMAttr), - (void **)aReturn); - NS_RELEASE(node); - } - } - NS_RELEASE(map); - } - - return result; -} - -nsresult -nsGenericElement::GetElementsByTagName(const nsAReadableString& aTagname, - nsIDOMNodeList** aReturn) -{ - nsCOMPtr nameAtom; - - nameAtom = dont_AddRef(NS_NewAtom(aTagname)); - - nsContentList* list = new nsContentList(mDocument, - nameAtom, - kNameSpaceID_Unknown, - this); - - if (!list) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return list->QueryInterface(NS_GET_IID(nsIDOMNodeList), (void **)aReturn); -} - -nsresult -nsGenericElement::GetAttributeNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - nsAWritableString& aReturn) -{ - nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); - PRInt32 nsid; - - nsCOMPtr nimgr; - mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); - NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); - - nsCOMPtr nsmgr; - nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); - NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); - - nsmgr->GetNameSpaceID(aNamespaceURI, nsid); - - if (nsid == kNameSpaceID_Unknown) { - // Unkonwn namespace means no attr... - - aReturn.Truncate(); - return NS_OK; - } - - NS_STATIC_CAST(nsIContent *, this)->GetAttribute(nsid, name, aReturn); - - return NS_OK; -} - -nsresult -nsGenericElement::SetAttributeNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aQualifiedName, - const nsAReadableString& aValue) -{ - nsCOMPtr nimgr; - mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); - NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); - - nsCOMPtr ni; - nsresult rv = nimgr->GetNodeInfo(aQualifiedName, aNamespaceURI, - *getter_AddRefs(ni)); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_STATIC_CAST(nsIContent *, this)->SetAttribute(ni, aValue, PR_TRUE); -} - -nsresult -nsGenericElement::RemoveAttributeNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName) -{ - nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); - PRInt32 nsid; - - nsCOMPtr nimgr; - mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); - NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); - - nsCOMPtr nsmgr; - nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); - NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); - - nsmgr->GetNameSpaceID(aNamespaceURI, nsid); - - if (nsid == kNameSpaceID_Unknown) { - // Unkonwn namespace means no attr... - - return NS_OK; - } - - nsAutoString tmp; - UnsetAttribute(nsid, name, PR_TRUE); - - return NS_OK; -} - -nsresult -nsGenericElement::GetAttributeNodeNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - nsIDOMAttr** aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - - nsIDOMNamedNodeMap* map; - nsresult result = GetAttributes(&map); - - *aReturn = nsnull; - if (NS_OK == result) { - nsIDOMNode* node; - result = map->GetNamedItemNS(aNamespaceURI, aLocalName, &node); - if ((NS_OK == result) && (nsnull != node)) { - result = node->QueryInterface(NS_GET_IID(nsIDOMAttr), (void **)aReturn); - NS_IF_RELEASE(node); - } - NS_RELEASE(map); - } - - return result; -} - -nsresult -nsGenericElement::SetAttributeNodeNS(nsIDOMAttr* aNewAttr, - nsIDOMAttr** aReturn) -{ - if ((nsnull == aReturn) || (nsnull == aNewAttr)) { - return NS_ERROR_NULL_POINTER; - } - nsIDOMNamedNodeMap* map; - nsresult result = GetAttributes(&map); - - *aReturn = nsnull; - if (NS_OK == result) { - nsIDOMNode *node, *returnNode; - result = aNewAttr->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)&node); - if (NS_OK == result) { - result = map->SetNamedItemNS(node, &returnNode); - if ((NS_OK == result) && (nsnull != returnNode)) { - result = returnNode->QueryInterface(NS_GET_IID(nsIDOMAttr), - (void **)aReturn); - NS_IF_RELEASE(returnNode); - } - NS_RELEASE(node); - } - NS_RELEASE(map); - } - - return NS_OK; -} - -nsresult -nsGenericElement::GetElementsByTagNameNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - nsIDOMNodeList** aReturn) -{ - nsCOMPtr nameAtom(dont_AddRef(NS_NewAtom(aLocalName))); - PRInt32 nameSpaceId = kNameSpaceID_Unknown; - - nsContentList* list = nsnull; - - if (!aNamespaceURI.Equals(NS_LITERAL_STRING("*"))) { - nsCOMPtr nimgr; - mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); - NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); - - nsCOMPtr nsmgr; - nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); - NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); - - nsmgr->GetNameSpaceID(aNamespaceURI, nameSpaceId); - - if (nameSpaceId == kNameSpaceID_Unknown) { - // Unkonwn namespace means no matches, we create an empty list... - list = new nsContentList(mDocument, nsnull, kNameSpaceID_None); - NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY); - } - } - - if (!list) { - list = new nsContentList(mDocument, nameAtom, nameSpaceId, this); - NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY); - } - - return list->QueryInterface(NS_GET_IID(nsIDOMNodeList), (void **)aReturn); -} - -nsresult -nsGenericElement::HasAttribute(const nsAReadableString& aName, PRBool* aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - - nsCOMPtr ni; - NormalizeAttributeString(aName, *getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); - - PRInt32 nsid; - nsCOMPtr nameAtom; - - ni->GetNamespaceID(nsid); - ni->GetNameAtom(*getter_AddRefs(nameAtom)); - - nsAutoString tmp; - nsresult rv = NS_STATIC_CAST(nsIContent *, this)->GetAttribute(nsid, - nameAtom, - tmp); - - *aReturn = rv == NS_CONTENT_ATTR_NOT_THERE ? PR_FALSE : PR_TRUE; - - return NS_OK; -} - -nsresult -nsGenericElement::HasAttributeNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - PRBool* aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - - nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); - PRInt32 nsid; - - nsCOMPtr nimgr; - mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); - NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); - - nsCOMPtr nsmgr; - nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); - NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); - - nsmgr->GetNameSpaceID(aNamespaceURI, nsid); - - if (nsid == kNameSpaceID_Unknown) { - // Unkonwn namespace means no attr... - - *aReturn = PR_FALSE; - return NS_OK; - } - - nsAutoString tmp; - nsresult rv = NS_STATIC_CAST(nsIContent *, this)->GetAttribute(nsid, name, - tmp); - - *aReturn = rv == NS_CONTENT_ATTR_NOT_THERE ? PR_FALSE : PR_TRUE; - - return NS_OK; -} - -nsresult -nsGenericElement::JoinTextNodes(nsIContent* aFirst, - nsIContent* aSecond) -{ - nsresult rv = NS_OK; - nsCOMPtr firstText(do_QueryInterface(aFirst, &rv)); - - if (NS_SUCCEEDED(rv)) { - nsCOMPtr secondText(do_QueryInterface(aSecond, &rv)); - - if (NS_SUCCEEDED(rv)) { - nsAutoString str; - - rv = secondText->GetData(str); - if (NS_SUCCEEDED(rv)) { - rv = firstText->AppendData(str); - } - } - } - - return rv; -} - -nsresult -nsGenericElement::Normalize() -{ - nsresult result = NS_OK; - PRInt32 index, count; - - ChildCount(count); - for (index = 0; (index < count) && (NS_OK == result); index++) { - nsCOMPtr child; - - result = ChildAt(index, *getter_AddRefs(child)); - if (NS_FAILED(result)) { - return result; - } - - nsCOMPtr node = do_QueryInterface(child); - if (node) { - PRUint16 nodeType; - node->GetNodeType(&nodeType); - - switch (nodeType) { - case nsIDOMNode::TEXT_NODE: - - if (index+1 < count) { - nsCOMPtr sibling; - - // Get the sibling. If it's also a text node, then - // remove it from the tree and join the two text - // nodes. - result = ChildAt(index+1, *getter_AddRefs(sibling)); - if (NS_FAILED(result)) { - return result; - } - - nsCOMPtr siblingNode = do_QueryInterface(sibling); - - if (sibling) { - PRUint16 siblingNodeType; - siblingNode->GetNodeType(&siblingNodeType); - - if (siblingNodeType == nsIDOMNode::TEXT_NODE) { - result = RemoveChildAt(index+1, PR_TRUE); - if (NS_FAILED(result)) { - return result; - } - - result = JoinTextNodes(child, sibling); - if (NS_FAILED(result)) { - return result; - } - count--; - index--; - } - } - } - break; - - case nsIDOMNode::ELEMENT_NODE: - nsCOMPtr element = do_QueryInterface(child); - - if (element) { - result = element->Normalize(); - } - break; - } - } - } - - return result; -} - - -nsresult -nsGenericElement::GetDocument(nsIDocument*& aResult) const -{ - NS_IF_ADDREF(mDocument); - aResult = mDocument; - return NS_OK; -} - - -void -nsGenericElement::SetDocumentInChildrenOf(nsIContent* aContent, - nsIDocument* aDocument, - PRBool aCompileEventHandlers) -{ - PRInt32 i, n; - aContent->ChildCount(n); - for (i = 0; i < n; i++) { - nsIContent* child; - aContent->ChildAt(i, child); - if (nsnull != child) { - child->SetDocument(aDocument, PR_TRUE, aCompileEventHandlers); - NS_RELEASE(child); - } - } -} - -nsresult -nsGenericElement::SetDocument(nsIDocument* aDocument, PRBool aDeep, - PRBool aCompileEventHandlers) -{ - if (aDocument != mDocument) { - // If we were part of a document, make sure we get rid of the - // script context reference to our script object so that our - // script object can be freed (or collected). - if (mDocument && mDOMSlots && mDOMSlots->mScriptObject) { - nsCOMPtr globalObject; - mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if (globalObject) { - nsCOMPtr context; - if (NS_OK == globalObject->GetContext(getter_AddRefs(context)) && context) { - context->RemoveReference((void *)&mDOMSlots->mScriptObject, - mDOMSlots->mScriptObject); - } - } - } - - if (mDocument && aDeep) { - // Notify XBL- & nsIAnonymousContentCreator-generated - // anonymous content that the document is changing. - nsCOMPtr bindingManager; - mDocument->GetBindingManager(getter_AddRefs(bindingManager)); - NS_ASSERTION(bindingManager, "No binding manager."); - if (bindingManager) { - bindingManager->ChangeDocumentFor(this, mDocument, aDocument); - } - - nsCOMPtr domElement; - QueryInterface(NS_GET_IID(nsIDOMElement), getter_AddRefs(domElement)); - - if (domElement) { - nsCOMPtr nsDoc(do_QueryInterface(mDocument)); - nsDoc->SetBoxObjectFor(domElement, nsnull); - } - } - - mDocument = aDocument; - - // If we already have a script object and now we're being added - // to a document, make sure that the script context adds a - // reference to our script object. This will ensure that it - // won't be freed (or collected) out from under us. - if (mDocument && mDOMSlots && mDOMSlots->mScriptObject) { - nsCOMPtr globalObject; - mDocument->GetScriptGlobalObject(getter_AddRefs(globalObject)); - if (globalObject) { - nsCOMPtr context; - if (NS_OK == globalObject->GetContext(getter_AddRefs(context)) && context) { - context->AddNamedReference((void *)&mDOMSlots->mScriptObject, - mDOMSlots->mScriptObject, - "nsGenericElement::mScriptObject"); - } - } - } - } - - if (PR_TRUE == aDeep) { - SetDocumentInChildrenOf(this, aDocument, aCompileEventHandlers); - } - - return NS_OK; -} - - -nsresult -nsGenericElement::GetParent(nsIContent*& aResult) const -{ - aResult = mParent; - NS_IF_ADDREF(aResult); - return NS_OK; -} - -nsresult -nsGenericElement::SetParent(nsIContent* aParent) -{ - mParent = aParent; - return NS_OK; -} - -nsresult -nsGenericElement::GetNameSpaceID(PRInt32& aNameSpaceID) const -{ - return mNodeInfo->GetNamespaceID(aNameSpaceID); -} - -nsresult -nsGenericElement::GetTag(nsIAtom*& aResult) const -{ - return mNodeInfo->GetNameAtom(aResult); -} - -nsresult -nsGenericElement::GetNodeInfo(nsINodeInfo*& aResult) const -{ - aResult = mNodeInfo; - NS_IF_ADDREF(aResult); - - return NS_OK; -} - - -nsresult -nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus) -{ - nsresult ret = NS_OK; - PRBool retarget = PR_FALSE; - nsCOMPtr oldTarget; - - nsIDOMEvent* domEvent = nsnull; - if (NS_EVENT_FLAG_INIT & aFlags) { - if (!aDOMEvent) { - aDOMEvent = &domEvent; - } - aEvent->flags = aFlags; - aFlags &= ~(NS_EVENT_FLAG_CANT_BUBBLE | NS_EVENT_FLAG_CANT_CANCEL); - } - - // Find out if we're anonymous. - nsCOMPtr bindingParent; - GetBindingParent(getter_AddRefs(bindingParent)); - if (bindingParent) { - // We're anonymous. We may potentially need to retarget - // our event if our parent is in a different scope. - if (mParent) { - nsCOMPtr parentScope; - mParent->GetBindingParent(getter_AddRefs(parentScope)); - if (parentScope != bindingParent) - retarget = PR_TRUE; - } - } - - if (retarget) { - if (!*aDOMEvent) { - // We haven't made a DOMEvent yet. Force making one now. - nsCOMPtr listenerManager; - if (NS_FAILED(ret = GetListenerManager(getter_AddRefs(listenerManager)))) { - return ret; - } - nsAutoString empty; - if (NS_FAILED(ret = listenerManager->CreateEvent(aPresContext, aEvent, empty, aDOMEvent))) - return ret; - } - - if (!*aDOMEvent) { - return NS_ERROR_FAILURE; - } - nsCOMPtr privateEvent = do_QueryInterface(*aDOMEvent); - if (!privateEvent) { - return NS_ERROR_FAILURE; - } - - (*aDOMEvent)->GetTarget(getter_AddRefs(oldTarget)); - - PRBool hasOriginal; - privateEvent->HasOriginalTarget(&hasOriginal); - - if (!hasOriginal) { - privateEvent->SetOriginalTarget(oldTarget); - } - - nsCOMPtr target = do_QueryInterface(mParent); - privateEvent->SetTarget(target); - } - - //Capturing stage evaluation - //Always pass capturing up the tree before local evaulation - if (NS_EVENT_FLAG_BUBBLE != aFlags) { - // XXX: Bring on the more optimized version of capturing at some point - //if (nsnull != mDOMSlots && nsnull != mDOMSlots->mCapturer) { - //mDOMSlots->mCapturer->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); - //} else { - // Node capturing stage - if (mParent) { - // Pass off to our parent. - mParent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); - } else { - //Initiate capturing phase. Special case first call to document - if (nsnull != mDocument) { - mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, NS_EVENT_FLAG_CAPTURE, aEventStatus); - } - } - //} - } - - if (retarget) { - // The event originated beneath us, and we performed a retargeting. - // We need to restore the original target of the event. - nsCOMPtr privateEvent = do_QueryInterface(*aDOMEvent); - if (privateEvent) - privateEvent->SetTarget(oldTarget); - } - - //Local handling stage - if (mDOMSlots && mDOMSlots->mListenerManager && !(aEvent->flags & NS_EVENT_FLAG_STOP_DISPATCH) && - !(NS_EVENT_FLAG_BUBBLE & aFlags && NS_EVENT_FLAG_CANT_BUBBLE & aEvent->flags)) { - aEvent->flags |= aFlags; - nsCOMPtr curTarg(do_QueryInterface(NS_STATIC_CAST(nsIHTMLContent *, this))); - mDOMSlots->mListenerManager->HandleEvent(aPresContext, aEvent, aDOMEvent, curTarg, aFlags, aEventStatus); - aEvent->flags &= ~aFlags; - } - - if (retarget) { - // The event originated beneath us, and we need to perform a retargeting. - nsCOMPtr privateEvent = do_QueryInterface(*aDOMEvent); - if (privateEvent) { - nsCOMPtr parentTarget(do_QueryInterface(mParent)); - privateEvent->SetTarget(parentTarget); - } - } - - //Bubbling stage - if (NS_EVENT_FLAG_CAPTURE != aFlags && mDocument) { - if (mParent) { - /* - * If there's a parent we pass the event to the parent... - */ - ret = mParent->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, - NS_EVENT_FLAG_BUBBLE, aEventStatus); - } else { - /* - * If there's no parent but there is a document (i.e. this is the - * root node) we pass the event to the document... - */ - ret = mDocument->HandleDOMEvent(aPresContext, aEvent, aDOMEvent, - NS_EVENT_FLAG_BUBBLE, aEventStatus); - } - } - - if (retarget) { - // The event originated beneath us, and we performed a retargeting. - // We need to restore the original target of the event. - nsCOMPtr privateEvent = do_QueryInterface(*aDOMEvent); - if (privateEvent) - privateEvent->SetTarget(oldTarget); - } - - if (NS_EVENT_FLAG_INIT & aFlags) { - // We're leaving the DOM event loop so if we created a DOM event, - // release here. - if (nsnull != *aDOMEvent) { - nsrefcnt rc; - NS_RELEASE2(*aDOMEvent, rc); - if (0 != rc) { - // Okay, so someone in the DOM loop (a listener, JS object) - // still has a ref to the DOM Event but the internal data - // hasn't been malloc'd. Force a copy of the data here so the - // DOM Event is still valid. - nsIPrivateDOMEvent *privateEvent; - if (NS_OK == (*aDOMEvent)->QueryInterface(NS_GET_IID(nsIPrivateDOMEvent), (void**)&privateEvent)) { - privateEvent->DuplicatePrivateData(); - NS_RELEASE(privateEvent); - } - } - } - aDOMEvent = nsnull; - } - - return ret; -} - -PRUint32 -nsGenericElement::BaseSizeOf(nsISizeOfHandler *aSizer) const -{ - return 0; -} - -NS_IMETHODIMP -nsGenericElement::GetContentID(PRUint32* aID) -{ - *aID = mContentID; - - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::SetContentID(PRUint32 aID) -{ - mContentID = aID; - - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::SetContainingNameSpace(nsINameSpace* aNameSpace) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::GetContainingNameSpace(nsINameSpace*& aNameSpace) const -{ - aNameSpace = nsnull; - - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::MaybeTriggerAutoLink(nsIWebShell *aShell) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::GetID(nsIAtom*& aResult) const -{ - aResult = nsnull; - - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::GetClasses(nsVoidArray& aArray) const -{ - aArray.Clear(); - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsGenericElement::HasClass(nsIAtom* aClass) const -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsGenericElement::GetContentStyleRules(nsISupportsArray* aRules) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::GetInlineStyleRules(nsISupportsArray* aRules) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsGenericElement::GetMappedAttributeImpact(const nsIAtom* aAttribute, - PRInt32& aHint) const -{ - aHint = NS_STYLE_HINT_CONTENT; // by default, never map attributes to style - return NS_OK; -} - - -NS_IMETHODIMP -nsGenericElement::Compact() -{ - return NS_OK; -} - -NS_IMETHODIMP -nsGenericElement::SetHTMLAttribute(nsIAtom* aAttribute, - const nsHTMLValue& aValue, - PRBool aNotify) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsGenericElement::GetHTMLAttribute(nsIAtom* aAttribute, - nsHTMLValue& aValue) const -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsGenericElement::GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc, - nsMapAttributesFunc& aMapFunc) const -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsGenericElement::AttributeToString(nsIAtom* aAttribute, - const nsHTMLValue& aValue, - nsAWritableString& aResult) const -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsGenericElement::StringToAttribute(nsIAtom* aAttribute, - const nsAReadableString& aValue, - nsHTMLValue& aResult) -{ - return NS_CONTENT_ATTR_NOT_THERE; -} - -NS_IMETHODIMP -nsGenericElement::GetBaseURL(nsIURI*& aBaseURL) const -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsGenericElement::GetBaseTarget(nsAWritableString& aBaseTarget) const -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -nsresult -nsGenericElement::RangeAdd(nsIDOMRange& aRange) -{ - if (!mDOMSlots) - GetDOMSlots(); - - // lazy allocation of range list - if (!mDOMSlots->mRangeList) { - mDOMSlots->mRangeList = new nsVoidArray(); - } - if (!mDOMSlots->mRangeList) { - return NS_ERROR_OUT_OF_MEMORY; - } - - // Make sure we don't add a range that is already - // in the list! - PRInt32 i = mDOMSlots->mRangeList->IndexOf(&aRange); - if (i >= 0) { - // Range is already in the list, so there - // is nothing to do! - return NS_OK; - } - - // dont need to addref - this call is made by the range object itself - PRBool rv = mDOMSlots->mRangeList->AppendElement(&aRange); - if (rv) - return NS_OK; - - return NS_ERROR_FAILURE; -} - - -nsresult -nsGenericElement::RangeRemove(nsIDOMRange& aRange) -{ - if (mDOMSlots && mDOMSlots->mRangeList) { - // dont need to release - this call is made by the range object itself - PRBool rv = mDOMSlots->mRangeList->RemoveElement(&aRange); - if (rv) { - if (mDOMSlots->mRangeList->Count() == 0) { - delete mDOMSlots->mRangeList; - mDOMSlots->mRangeList = nsnull; - MaybeClearDOMSlots(); - } - return NS_OK; - } - } - return NS_ERROR_FAILURE; -} - - -nsresult -nsGenericElement::GetRangeList(nsVoidArray*& aResult) const -{ - if (mDOMSlots && mDOMSlots->mRangeList) { - aResult = mDOMSlots->mRangeList; - } - else { - aResult = nsnull; - } - return NS_OK; -} - -nsresult -nsGenericElement::SetFocus(nsIPresContext* aPresContext) -{ - nsAutoString disabled; - if (NS_CONTENT_ATTR_HAS_VALUE == NS_STATIC_CAST(nsIContent *, this)->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, disabled)) { - return NS_OK; - } - - nsIEventStateManager* esm; - if (NS_OK == aPresContext->GetEventStateManager(&esm)) { - - esm->SetContentState(this, NS_EVENT_STATE_FOCUS); - NS_RELEASE(esm); - } - - return NS_OK; -} - -nsresult -nsGenericElement::RemoveFocus(nsIPresContext* aPresContext) -{ - return NS_OK; -} - -nsresult -nsGenericElement::GetBindingParent(nsIContent** aContent) -{ - *aContent = mDOMSlots ? mDOMSlots->mBindingParent : nsnull; - NS_IF_ADDREF(*aContent); - return NS_OK; -} - -nsresult -nsGenericElement::SetBindingParent(nsIContent* aParent) -{ - if (!mDOMSlots) - GetDOMSlots(); - - mDOMSlots->mBindingParent = aParent; // Weak, so no addref happens. - - if (aParent) { - PRInt32 count; - ChildCount(count); - for (PRInt32 i = 0; i < count; i++) { - nsCOMPtr child; - ChildAt(i, *getter_AddRefs(child)); - child->SetBindingParent(aParent); - } - } - - return NS_OK; -} - - -//---------------------------------------------------------------------- - -nsresult -nsGenericElement::RenderFrame(nsIPresContext* aPresContext) -{ - nsPoint offset; - nsRect bounds; - - // Trigger damage repairs for each frame that maps the given content - PRInt32 i, n; - n = mDocument->GetNumberOfShells(); - for (i = 0; i < n; i++) { - nsIPresShell* shell; - shell = mDocument->GetShellAt(i); - nsIFrame* frame; - shell->GetPrimaryFrameFor(this, &frame); - while (nsnull != frame) { - nsIViewManager* vm; - nsIView* view; - - // Determine damaged area and tell view manager to redraw it - frame->GetRect(bounds); - bounds.x = bounds.y = 0; - - // XXX We should tell the frame the damage area and let it invalidate - // itself. Add some API calls to nsIFrame to allow a caller to invalidate - // parts of the frame... - frame->GetOffsetFromView(aPresContext, offset, &view); - view->GetViewManager(vm); - bounds.x += offset.x; - bounds.y += offset.y; - - vm->UpdateView(view, bounds, NS_VMREFRESH_IMMEDIATE); - NS_RELEASE(vm); - - // If frame has a next-in-flow, repaint it too - frame->GetNextInFlow(&frame); - } - NS_RELEASE(shell); - } - - return NS_OK; -} - -//---------------------------------------------------------------------- - -// nsIScriptObjectOwner implementation - -nsresult -nsGenericElement::GetScriptObject(nsIScriptContext* aContext, - void** aScriptObject) -{ - nsresult res = NS_OK; - nsDOMSlots *slots = GetDOMSlots(); - - if (!slots->mScriptObject) { - nsIDOMScriptObjectFactory *factory; - - res = GetScriptObjectFactory(&factory); - if (NS_OK != res) { - return res; - } - - nsAutoString tag; - mNodeInfo->GetName(tag); - res = factory->NewScriptElement(tag, aContext, - NS_STATIC_CAST(nsIHTMLContent *, this), - mParent ? (nsISupports*)mParent : (nsISupports*)mDocument, - (void**)&slots->mScriptObject); - NS_RELEASE(factory); - - NS_WARN_IF_FALSE(slots->mScriptObject, - "Eeek! Cound't create script object!"); - - if (mDocument && slots->mScriptObject) { - aContext->AddNamedReference((void *)&slots->mScriptObject, - slots->mScriptObject, - "nsGenericElement::mScriptObject"); - - // See if we have a frame. - nsCOMPtr shell = getter_AddRefs(mDocument->GetShellAt(0)); - if (shell) { - nsIFrame* frame; - shell->GetPrimaryFrameFor(this, &frame); - if (!frame) { - // We must ensure that the XBL Binding is installed before we hand - // back this object. - nsCOMPtr bindingManager; - mDocument->GetBindingManager(getter_AddRefs(bindingManager)); - nsCOMPtr binding; - bindingManager->GetBinding(this, getter_AddRefs(binding)); - if (!binding) { - nsCOMPtr global; - mDocument->GetScriptGlobalObject(getter_AddRefs(global)); - nsCOMPtr viewCSS(do_QueryInterface(global)); - if (viewCSS) { - nsCOMPtr cssDecl; - nsAutoString empty; - nsCOMPtr elt(do_QueryInterface(NS_STATIC_CAST(nsIHTMLContent *, this))); - viewCSS->GetComputedStyle(elt, empty, getter_AddRefs(cssDecl)); - if (cssDecl) { - nsAutoString behavior; behavior.Assign(NS_LITERAL_STRING("-moz-binding")); - nsAutoString value; - cssDecl->GetPropertyValue(behavior, value); - if (!value.IsEmpty()) { - // We have a binding that must be installed. - nsresult rv; - PRBool dummy; - NS_WITH_SERVICE(nsIXBLService, xblService, "@mozilla.org/xbl;1", &rv); - xblService->LoadBindings(this, value, PR_FALSE, getter_AddRefs(binding), &dummy); - if (binding) { - binding->ExecuteAttachedHandler(); - } - } - } - } - } - } - } - } - } - - *aScriptObject = slots->mScriptObject; - return res; -} - -nsresult -nsGenericElement::SetScriptObject(void *aScriptObject) -{ - nsDOMSlots *slots = GetDOMSlots(); - - slots->mScriptObject = aScriptObject; - - if (!aScriptObject) { - if (slots->mListenerManager) { - slots->mListenerManager->RemoveAllListeners(PR_TRUE); - } - MaybeClearDOMSlots(); - } - - return NS_OK; -} - -//---------------------------------------------------------------------- - -nsresult -nsGenericElement::GetListenerManager(nsIEventListenerManager** aResult) -{ - nsDOMSlots *slots = GetDOMSlots(); - - if (nsnull != slots->mListenerManager) { - NS_ADDREF(slots->mListenerManager); - *aResult = slots->mListenerManager; - return NS_OK; - } - nsresult rv = NS_NewEventListenerManager(aResult); - if (NS_OK == rv) { - slots->mListenerManager = *aResult; - NS_ADDREF(slots->mListenerManager); - slots->mListenerManager->SetListenerTarget(NS_STATIC_CAST(nsIHTMLContent *, this)); - } - return rv; -} - -//---------------------------------------------------------------------- - -// nsIJSScriptObject implementation - -PRBool -nsGenericElement::AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, - jsval *aVp) -{ - return PR_TRUE; -} - -PRBool -nsGenericElement::DeleteProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp) -{ - return PR_TRUE; -} - -PRBool -nsGenericElement::GetProperty(JSContext *aContext, JSObject *aObj, jsval aID, - jsval *aVp) -{ - return PR_TRUE; -} - -PRBool -nsGenericElement::SetProperty(JSContext *aContext, JSObject *aObj, jsval aID, - jsval *aVp) -{ - if (JS_TypeOfValue(aContext, *aVp) == JSTYPE_FUNCTION && - JSVAL_IS_STRING(aID)) { - nsAutoString propName, prefix; - propName.Assign(NS_REINTERPRET_CAST(const PRUnichar*, JS_GetStringChars(JS_ValueToString(aContext, aID)))); - if (propName.Length() > 2) - prefix.Assign(propName.GetUnicode(), 2); - if (prefix.Equals(NS_LITERAL_STRING("on"))) { - nsCOMPtr atom = getter_AddRefs(NS_NewAtom(propName)); - nsIEventListenerManager *manager = nsnull; - - if (atom.get() == nsLayoutAtoms::onmousedown || atom.get() == nsLayoutAtoms::onmouseup || atom.get() == nsLayoutAtoms::onclick || - atom.get() == nsLayoutAtoms::onmouseover || atom.get() == nsLayoutAtoms::onmouseout) { - if (NS_OK == GetListenerManager(&manager)) { - nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || - NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMMouseListenerIID)) { - NS_RELEASE(manager); - return PR_FALSE; - } - } - } - else if (atom.get() == nsLayoutAtoms::onkeydown || atom.get() == nsLayoutAtoms::onkeyup || atom.get() == nsLayoutAtoms::onkeypress) { - if (NS_OK == GetListenerManager(&manager)) { - nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || - NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMKeyListenerIID)) { - NS_RELEASE(manager); - return PR_FALSE; - } - } - } - else if (atom.get() == nsLayoutAtoms::onmousemove) { - if (NS_OK == GetListenerManager(&manager)) { - nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || - NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMMouseMotionListenerIID)) { - NS_RELEASE(manager); - return PR_FALSE; - } - } - } - else if (atom.get() == nsLayoutAtoms::onfocus || atom.get() == nsLayoutAtoms::onblur) { - if (NS_OK == GetListenerManager(&manager)) { - nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || - NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMFocusListenerIID)) { - NS_RELEASE(manager); - return PR_FALSE; - } - } - } - else if (atom.get() == nsLayoutAtoms::onsubmit || atom.get() == nsLayoutAtoms::onreset || atom.get() == nsLayoutAtoms::onchange || - atom.get() == nsLayoutAtoms::onselect) { - if (NS_OK == GetListenerManager(&manager)) { - nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || - NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMFormListenerIID)) { - NS_RELEASE(manager); - return PR_FALSE; - } - } - } - else if (atom.get() == nsLayoutAtoms::onload || atom.get() == nsLayoutAtoms::onunload || atom.get() == nsLayoutAtoms::onabort || - atom.get() == nsLayoutAtoms::onerror) { - if (NS_OK == GetListenerManager(&manager)) { - nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || - NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, atom, kIDOMLoadListenerIID)) { - NS_RELEASE(manager); - return PR_FALSE; - } - } - } - else if (atom.get() == nsLayoutAtoms::onpaint || atom.get() == nsLayoutAtoms::onresize || - atom.get() == nsLayoutAtoms::onscroll) { - if (NS_OK == GetListenerManager(&manager)) { - nsCOMPtr mScriptCX; - if (NS_FAILED(nsLayoutUtils::GetStaticScriptContext(aContext, (JSObject*)GetDOMSlots()->mScriptObject, getter_AddRefs(mScriptCX))) || - NS_OK != manager->RegisterScriptEventListener(mScriptCX, this, - atom, kIDOMPaintListenerIID)) { - NS_RELEASE(manager); - return PR_FALSE; - } - } - } - NS_IF_RELEASE(manager); - } - } - - return PR_TRUE; -} - -PRBool -nsGenericElement::EnumerateProperty(JSContext *aContext, JSObject *aObj) -{ - return PR_TRUE; -} - -PRBool -nsGenericElement::Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool* aDidDefineProperty) -{ - *aDidDefineProperty = PR_FALSE; - - return PR_TRUE; -} - -PRBool -nsGenericElement::Convert(JSContext *aContext, JSObject *aObj, jsval aID) -{ - return PR_TRUE; -} - -void -nsGenericElement::Finalize(JSContext *aContext, JSObject *aObj) -{ -} - -// Generic DOMNode implementations - -/* - * This helper function checks if aChild is the same as aNode or if - * aChild is one of aNode's ancestors. -- jst@citec.fi - */ - -static PRBool isSelfOrAncestor(nsIContent *aNode, nsIContent *aChild) -{ - if (aNode == aChild) - return PR_TRUE; - - nsCOMPtr parent, tmpNode; - PRInt32 childCount = 0; - - /* - * If aChild doesn't have children it can't be our ancestor - */ - aChild->ChildCount(childCount); - - if (childCount <= 0) { - return PR_FALSE; - } - - aNode->GetParent(*getter_AddRefs(parent)); - - while (parent) { - if (parent.get() == aChild) { - /* - * We found aChild as one of our ancestors - */ - return PR_TRUE; - } - - parent->GetParent(*getter_AddRefs(tmpNode)); - - parent = tmpNode; - } - - return PR_FALSE; -} - - -nsresult -nsGenericElement::doInsertBefore(nsIDOMNode* aNewChild, - nsIDOMNode* aRefChild, - nsIDOMNode** aReturn) -{ - if (!aReturn) { - return NS_ERROR_NULL_POINTER; - } - - *aReturn = nsnull; - - if (!aNewChild) { - return NS_ERROR_NULL_POINTER; - } - - nsCOMPtr refContent; - nsresult res = NS_OK; - PRInt32 refPos = 0; - - if (aRefChild) { - refContent = do_QueryInterface(aRefChild, &res); - - if (NS_FAILED(res)) { - /* - * If aRefChild doesn't support the nsIContent interface it can't be - * an existing child of this node. - */ - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - - IndexOf(refContent, refPos); - - if (refPos < 0) { - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - } else { - ChildCount(refPos); - } - - PRUint16 nodeType = 0; - - res = aNewChild->GetNodeType(&nodeType); - - if (NS_FAILED(res)) { - return res; - } - - switch (nodeType) { - case nsIDOMNode::ELEMENT_NODE : - case nsIDOMNode::TEXT_NODE : - case nsIDOMNode::CDATA_SECTION_NODE : - case nsIDOMNode::ENTITY_REFERENCE_NODE : - case nsIDOMNode::PROCESSING_INSTRUCTION_NODE : - case nsIDOMNode::COMMENT_NODE : - break; - case nsIDOMNode::DOCUMENT_FRAGMENT_NODE : - break; - default: - /* - * aNewChild is of invalid type. - */ - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - nsCOMPtr newContent(do_QueryInterface(aNewChild, &res)); - - if (NS_FAILED(res)) { - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - /* - * Make sure the new child is not "this" node or one of this nodes - * ancestors. Doing this check here should be safe even if newContent - * is a document fragment. - */ - if (isSelfOrAncestor(this, newContent)) { - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - /* - * Check if this is a document fragment. If it is, we need - * to remove the children of the document fragment and add them - * individually (i.e. we don't add the actual document fragment). - */ - if (nodeType == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) { - nsCOMPtr childContent; - PRInt32 count, i; - - newContent->ChildCount(count); - - /* - * Iterate through the fragments children, removing each from - * the fragment and inserting it into the child list of its - * new parent. - */ - for (i = 0; i < count; i++) { - // Always get and remove the first child, since the child indexes - // change as we go along. - res = newContent->ChildAt(0, *getter_AddRefs(childContent)); - if (NS_FAILED(res)) { - return res; - } - - res = newContent->RemoveChildAt(0, PR_FALSE); - - if (NS_FAILED(res)) { - return res; - } - - childContent->SetDocument(mDocument, PR_TRUE, PR_TRUE); - - // Insert the child and increment the insertion position - res = InsertChildAt(childContent, refPos++, PR_TRUE); - - if (NS_FAILED(res)) { - return res; - } - } - } else { - nsCOMPtr oldParent; - res = aNewChild->GetParentNode(getter_AddRefs(oldParent)); - - if (NS_FAILED(res)) { - return res; - } - - /* - * Remove the element from the old parent if one exists, since oldParent - * is a nsIDOMNode this will do the right thing even if the parent of - * aNewChild is a document. This code also handles the case where the - * new child is alleady a child of this node-- jst@citec.fi - */ - if (oldParent) { - nsCOMPtr tmpNode; - - PRInt32 origChildCount, newChildCount; - - ChildCount(origChildCount); - - /* - * We don't care here if the return fails or not. - */ - oldParent->RemoveChild(aNewChild, getter_AddRefs(tmpNode)); - - ChildCount(newChildCount); - - /* - * Check if our child count changed during the RemoveChild call, if - * it did then oldParent is most likely this node. In this case we - * must check if refPos is still correct (unless it's zero). - */ - if (refPos && origChildCount != newChildCount) { - if (refContent) { - /* - * If we did get aRefChild we check if that is now at refPos - 1, - * this will happend if the new child was one of aRefChilds' - * previous siblings. - */ - nsCOMPtr tmpContent; - - ChildAt(refPos - 1, *getter_AddRefs(tmpContent)); - - if (refContent == tmpContent) { - refPos--; - } - } else { - /* - * If we didn't get aRefChild we simply decrement refPos. - */ - refPos--; - } - } - } - - newContent->SetDocument(mDocument, PR_TRUE, PR_TRUE); - - res = InsertChildAt(newContent, refPos, PR_TRUE); - - if (NS_FAILED(res)) { - return res; - } - } - - *aReturn = aNewChild; - NS_ADDREF(*aReturn); - - return res; -} - - -nsresult -nsGenericElement::doReplaceChild(nsIDOMNode* aNewChild, - nsIDOMNode* aOldChild, - nsIDOMNode** aReturn) -{ - if (!aReturn) { - return NS_ERROR_NULL_POINTER; - } - - *aReturn = nsnull; - - if (!aNewChild || !aOldChild) { - return NS_ERROR_NULL_POINTER; - } - - nsresult res = NS_OK; - PRInt32 oldPos = 0; - - nsCOMPtr oldContent(do_QueryInterface(aOldChild, &res)); - - if (NS_FAILED(res)) { - /* - * If aOldChild doesn't support the nsIContent interface it can't be - * an existing child of this node. - */ - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - - IndexOf(oldContent, oldPos); - - if (oldPos < 0) { - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - - nsCOMPtr replacedChild; - - ChildAt(oldPos, *getter_AddRefs(replacedChild)); - - PRUint16 nodeType = 0; - - res = aNewChild->GetNodeType(&nodeType); - - if (NS_FAILED(res)) { - return res; - } - - switch (nodeType) { - case nsIDOMNode::ELEMENT_NODE : - case nsIDOMNode::TEXT_NODE : - case nsIDOMNode::CDATA_SECTION_NODE : - case nsIDOMNode::ENTITY_REFERENCE_NODE : - case nsIDOMNode::PROCESSING_INSTRUCTION_NODE : - case nsIDOMNode::COMMENT_NODE : - case nsIDOMNode::DOCUMENT_FRAGMENT_NODE : - break; - default: - /* - * aNewChild is of invalid type. - */ - - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - nsCOMPtr newContent(do_QueryInterface(aNewChild, &res)); - - if (NS_FAILED(res)) { - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - nsCOMPtr document; - - GetDocument(*getter_AddRefs(document)); - - /* - * Make sure the new child is not "this" node or one of this nodes - * ancestors. Doing this check here should be safe even if newContent - * is a document fragment. - */ - if (isSelfOrAncestor(this, newContent)) { - return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; - } - - /* - * Check if this is a document fragment. If it is, we need - * to remove the children of the document fragment and add them - * individually (i.e. we don't add the actual document fragment). - */ - if (nodeType == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) { - nsCOMPtr childContent; - PRInt32 count, i; - - newContent->ChildCount(count); - - /* - * Iterate through the fragments children, removing each from - * the fragment and inserting it into the child list of its - * new parent. - */ - for (i =0; i < count; i++) { - // Always get and remove the first child, since the child indexes - // change as we go along. - res = newContent->ChildAt(0, *getter_AddRefs(childContent)); - if (NS_FAILED(res)) { - return res; - } - - res = newContent->RemoveChildAt(0, PR_FALSE); - - if (NS_FAILED(res)) { - return res; - } - - childContent->SetDocument(document, PR_TRUE, PR_TRUE); - - // Insert the child and increment the insertion position - if (i) { - res = InsertChildAt(childContent, oldPos++, PR_TRUE); - } else { - res = ReplaceChildAt(childContent, oldPos++, PR_TRUE); - } - - if (NS_FAILED(res)) { - return res; - } - } - } else { - nsCOMPtr oldParent; - res = aNewChild->GetParentNode(getter_AddRefs(oldParent)); - - if (NS_FAILED(res)) { - return res; - } - - /* - * Remove the element from the old parent if one exists, since oldParent - * is a nsIDOMNode this will do the right thing even if the parent of - * aNewChild is a document. This code also handles the case where the - * new child is alleady a child of this node-- jst@citec.fi - */ - if (oldParent) { - nsCOMPtr tmpNode; - - PRInt32 origChildCount, newChildCount; - - ChildCount(origChildCount); - - /* - * We don't care here if the return fails or not. - */ - oldParent->RemoveChild(aNewChild, getter_AddRefs(tmpNode)); - - ChildCount(newChildCount); - - /* - * Check if our child count changed during the RemoveChild call, if - * it did then oldParent is most likely this node. In this case we - * must check if oldPos is still correct (unless it's zero). - */ - if (oldPos && origChildCount != newChildCount) { - /* - * Check if aOldChild is now at oldPos - 1, this will happend if - * the new child was one of aOldChilds' previous siblings. - */ - nsCOMPtr tmpContent; - - ChildAt(oldPos - 1, *getter_AddRefs(tmpContent)); - - if (oldContent == tmpContent) { - oldPos--; - } - } - } - - newContent->SetDocument(document, PR_TRUE, PR_TRUE); - - res = ReplaceChildAt(newContent, oldPos, PR_TRUE); - - if (NS_FAILED(res)) { - return res; - } - } - - return replacedChild->QueryInterface(NS_GET_IID(nsIDOMNode), - (void **)aReturn); -} - - -nsresult -nsGenericElement::doRemoveChild(nsIDOMNode* aOldChild, - nsIDOMNode** aReturn) -{ - *aReturn = nsnull; - - if (!aOldChild) { - return NS_ERROR_NULL_POINTER; - } - - nsresult res; - - nsCOMPtr content(do_QueryInterface(aOldChild, &res)); - - if (NS_FAILED(res)) { - /* - * If we're asked to remove something that doesn't support nsIContent - * it can not be one of our children, i.e. we return NOT_FOUND_ERR. - */ - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - - PRInt32 pos; - IndexOf(content, pos); - - if (pos < 0) { - /* - * aOldChild isn't one of our children. - */ - return NS_ERROR_DOM_NOT_FOUND_ERR; - } - - res = RemoveChildAt(pos, PR_TRUE); - - *aReturn = aOldChild; - NS_ADDREF(aOldChild); - - return res; -} - -//---------------------------------------------------------------------- - -// nsISupports implementation - -NS_IMETHODIMP -nsGenericElement::QueryInterface(REFNSIID aIID, void** aInstancePtr) -{ - nsISupports *inst = nsnull; - - if (aIID.Equals(NS_GET_IID(nsISupports))) { - inst = NS_STATIC_CAST(nsIContent *, this); - } else if (aIID.Equals(NS_GET_IID(nsIContent))) { - inst = NS_STATIC_CAST(nsIContent *, this); - } else if (aIID.Equals(NS_GET_IID(nsIStyledContent))) { - inst = NS_STATIC_CAST(nsIStyledContent *, this); - } else if (aIID.Equals(NS_GET_IID(nsIDOMEventReceiver)) || - aIID.Equals(NS_GET_IID(nsIDOMEventTarget))) { - nsCOMPtr man; - - GetListenerManager(getter_AddRefs(man)); - - if (man) { - return man->QueryInterface(aIID, aInstancePtr); - } - - return NS_NOINTERFACE; - } else if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) { - inst = NS_STATIC_CAST(nsIScriptObjectOwner *, this); - } else if (aIID.Equals(NS_GET_IID(nsIJSScriptObject))) { - inst = NS_STATIC_CAST(nsIJSScriptObject *, this); - } else { - return NS_NOINTERFACE; - } - - NS_ADDREF(inst); - - *aInstancePtr = inst; - - return NS_OK; -} - -NS_IMPL_ADDREF(nsGenericElement) -NS_IMPL_RELEASE(nsGenericElement) - -//---------------------------------------------------------------------- - -nsresult -nsGenericElement::TriggerLink(nsIPresContext* aPresContext, - nsLinkVerb aVerb, - nsIURI* aBaseURL, - const nsString& aURLSpec, - const nsString& aTargetSpec, - PRBool aClick) -{ - nsCOMPtr handler; - nsresult rv = aPresContext->GetLinkHandler(getter_AddRefs(handler)); - if (NS_FAILED(rv) || (nsnull == handler)) return rv; - - // Resolve url to an absolute url - nsAutoString absURLSpec; - if (nsnull != aBaseURL) { - rv = NS_MakeAbsoluteURI(absURLSpec, aURLSpec, aBaseURL); - if (NS_FAILED(rv)) return rv; - } - else { - absURLSpec.Assign(aURLSpec); - } - - // Now pass on absolute url to the click handler - if (aClick) { - nsresult proceed = NS_OK; - // Check that this page is allowed to load this URI. - NS_WITH_SERVICE(nsIScriptSecurityManager, securityManager, - NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); - nsCOMPtr absURI; - if (NS_SUCCEEDED(rv)) - rv = NS_NewURI(getter_AddRefs(absURI), absURLSpec, aBaseURL); - if (NS_SUCCEEDED(rv)) - proceed = securityManager->CheckLoadURI(aBaseURL, absURI, nsIScriptSecurityManager::STANDARD); - - // Only pass off the click event if the script security manager - // says it's ok. - if (NS_SUCCEEDED(proceed)) - handler->OnLinkClick(this, aVerb, absURLSpec.GetUnicode(), - aTargetSpec.GetUnicode()); - } - else { - handler->OnOverLink(this, absURLSpec.GetUnicode(), - aTargetSpec.GetUnicode()); - } - return rv; -} - -nsresult -nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, - const nsAReadableString& aValue, - REFNSIID aIID) -{ - nsresult ret = NS_OK; - nsCOMPtr context = nsnull; - nsCOMPtr global = nsnull; - JSContext* cx = nsnull; - - //Try to get context from doc - if (mDocument) { - if (NS_SUCCEEDED(mDocument->GetScriptGlobalObject(getter_AddRefs(global))) && global) { - NS_ENSURE_SUCCESS(global->GetContext(getter_AddRefs(context)), NS_ERROR_FAILURE); - } - } - - if (!context) { - // Get JSContext from stack. - nsCOMPtr stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1")); - NS_ENSURE_TRUE(stack, NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(stack->Peek(&cx), NS_ERROR_FAILURE); - - if(!cx) { - stack->GetSafeJSContext(&cx); - NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE); - } - - nsLayoutUtils::GetDynamicScriptContext(cx, getter_AddRefs(context)); - NS_ENSURE_TRUE(context, NS_ERROR_FAILURE); - } - - //Attributes on the body and frameset tags get set on the global object - if (mNodeInfo->Equals(nsHTMLAtoms::body) || - mNodeInfo->Equals(nsHTMLAtoms::frameset)) { - if (!global && cx) { - nsLayoutUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(global)); - - NS_ENSURE_TRUE(global, NS_ERROR_FAILURE); - } - nsCOMPtr receiver(do_QueryInterface(global)); - NS_ENSURE_TRUE(receiver, NS_ERROR_FAILURE); - - nsCOMPtr manager; - - receiver->GetListenerManager(getter_AddRefs(manager)); - - if (manager) { - nsCOMPtr objOwner(do_QueryInterface(global)); - if (objOwner) { - ret = manager->AddScriptEventListener(context, objOwner, aAttribute, - aValue, aIID, PR_FALSE); - } - } - } - else { - nsCOMPtr manager; - GetListenerManager(getter_AddRefs(manager)); - - if (manager) { - ret = manager->AddScriptEventListener(context, this, aAttribute, aValue, - aIID, PR_TRUE); - } - } - - return ret; -} - - -//---------------------------------------------------------------------- - -struct nsGenericAttribute -{ - nsGenericAttribute(nsINodeInfo *aNodeInfo, const nsAReadableString& aValue) - : mNodeInfo(aNodeInfo), - mValue(aValue) - { - NS_IF_ADDREF(mNodeInfo); - } - - ~nsGenericAttribute(void) - { - NS_IF_RELEASE(mNodeInfo); - } - -#ifdef DEBUG - nsresult SizeOf(nsISizeOfHandler* aSizer, PRUint32* aResult) const { - if (!aResult) { - return NS_ERROR_NULL_POINTER; - } - PRUint32 sum = sizeof(*this) - sizeof(mValue); - PRUint32 ssize; - mValue.SizeOf(aSizer, &ssize); - sum += ssize; - *aResult = sum; - return NS_OK; - } -#endif - - nsINodeInfo* mNodeInfo; - nsString mValue; -}; - -nsGenericContainerElement::nsGenericContainerElement() -{ - mAttributes = nsnull; -} - -nsGenericContainerElement::~nsGenericContainerElement() -{ - PRInt32 count = mChildren.Count(); - PRInt32 index; - for (index = 0; index < count; index++) { - nsIContent* kid = (nsIContent *)mChildren.ElementAt(index); - kid->SetParent(nsnull); - NS_RELEASE(kid); - } - if (nsnull != mAttributes) { - count = mAttributes->Count(); - for (index = 0; index < count; index++) { - nsGenericAttribute* attr = (nsGenericAttribute*)mAttributes->ElementAt(index); - delete attr; - } - delete mAttributes; - } -} - -nsresult -nsGenericContainerElement::NormalizeAttributeString(const nsAReadableString& aStr, nsINodeInfo*& aNodeInfo) -{ - if (mAttributes) { - PRInt32 indx, count = mAttributes->Count(); - for (indx = 0; indx < count; indx++) { - nsGenericAttribute* attr = (nsGenericAttribute*)mAttributes->ElementAt(indx); - if (attr->mNodeInfo->QualifiedNameEquals(aStr)) { - aNodeInfo = attr->mNodeInfo; - NS_ADDREF(aNodeInfo); - - return NS_OK; - } - } - } - - nsCOMPtr nimgr; - mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); - NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); - - return nimgr->GetNodeInfo(aStr, nsnull, kNameSpaceID_None, aNodeInfo); -} - -nsresult -nsGenericContainerElement::CopyInnerTo(nsIContent* aSrcContent, - nsGenericContainerElement* aDst, - PRBool aDeep) -{ - nsresult result = NS_OK; - - if (nsnull != mAttributes) { - nsGenericAttribute* attr; - PRInt32 index; - PRInt32 count = mAttributes->Count(); - for (index = 0; index < count; index++) { - attr = (nsGenericAttribute*)mAttributes->ElementAt(index); - // XXX Not very efficient, since SetAttribute does a linear search - // through its attributes before setting each attribute. - result = aDst->SetAttribute(attr->mNodeInfo, attr->mValue, PR_FALSE); - if (NS_OK != result) { - return result; - } - } - } - - if (aDeep) { - PRInt32 index; - PRInt32 count = mChildren.Count(); - for (index = 0; index < count; index++) { - nsIContent* child = (nsIContent*)mChildren.ElementAt(index); - if (nsnull != child) { - nsIDOMNode* node; - result = child->QueryInterface(NS_GET_IID(nsIDOMNode), (void**)&node); - if (NS_OK == result) { - nsIDOMNode* newNode; - - result = node->CloneNode(aDeep, &newNode); - if (NS_OK == result) { - nsIContent* newContent; - - result = newNode->QueryInterface(NS_GET_IID(nsIContent), - (void**)&newContent); - if (NS_OK == result) { - result = aDst->AppendChildTo(newContent, PR_FALSE); - NS_RELEASE(newContent); - } - NS_RELEASE(newNode); - } - NS_RELEASE(node); - } - - if (NS_OK != result) { - return result; - } - } - } - } - - return result; -} - -nsresult -nsGenericContainerElement::GetChildNodes(nsIDOMNodeList** aChildNodes) -{ - nsDOMSlots *slots = GetDOMSlots(); - - if (nsnull == slots->mChildNodes) { - slots->mChildNodes = new nsChildContentList(this); - if (nsnull == slots->mChildNodes) { - return NS_ERROR_OUT_OF_MEMORY; - } - NS_ADDREF(slots->mChildNodes); - } - - return slots->mChildNodes->QueryInterface(NS_GET_IID(nsIDOMNodeList), - (void **)aChildNodes); -} - -nsresult -nsGenericContainerElement::HasChildNodes(PRBool* aReturn) -{ - if (0 != mChildren.Count()) { - *aReturn = PR_TRUE; - } - else { - *aReturn = PR_FALSE; - } - return NS_OK; -} - -nsresult -nsGenericContainerElement::GetFirstChild(nsIDOMNode** aNode) -{ - nsIContent *child = (nsIContent *)mChildren.ElementAt(0); - if (nsnull != child) { - nsresult res = child->QueryInterface(NS_GET_IID(nsIDOMNode), - (void**)aNode); - NS_ASSERTION(NS_OK == res, "Must be a DOM Node"); // must be a DOM Node - return res; - } - *aNode = nsnull; - return NS_OK; -} - -nsresult -nsGenericContainerElement::GetLastChild(nsIDOMNode** aNode) -{ - nsIContent *child = (nsIContent *)mChildren.ElementAt(mChildren.Count()-1); - if (nsnull != child) { - nsresult res = child->QueryInterface(NS_GET_IID(nsIDOMNode), - (void**)aNode); - NS_ASSERTION(NS_OK == res, "Must be a DOM Node"); // must be a DOM Node - return res; - } - *aNode = nsnull; - return NS_OK; -} - -nsresult -nsGenericContainerElement::SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - const nsAReadableString& aValue, - PRBool aNotify) -{ - nsresult rv; - nsCOMPtr nimgr; - rv = mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr ni; - rv = nimgr->GetNodeInfo(aName, nsnull, aNameSpaceID, - *getter_AddRefs(ni)); - NS_ENSURE_SUCCESS(rv, rv); - - return SetAttribute(ni, aValue, aNotify); -} - -// Static helper method - -PRBool nsGenericElement::HasMutationListeners(nsIContent* aContent, - PRUint32 aType) -{ - nsCOMPtr doc; - aContent->GetDocument(*getter_AddRefs(doc)); - if (!doc) - return PR_FALSE; - - nsCOMPtr global; - doc->GetScriptGlobalObject(getter_AddRefs(global)); - if (!global) - return PR_FALSE; - - nsCOMPtr window(do_QueryInterface(global)); - if (!window) - return PR_FALSE; - - PRBool set; - window->HasMutationListeners(aType, &set); - if (!set) - return PR_FALSE; - - // We know a mutation listener is registered, but it might not - // be in our chain. Check quickly to see. - nsCOMPtr curr = aContent; - nsCOMPtr manager; - - while (curr) { - nsCOMPtr rec(do_QueryInterface(curr)); - if (rec) { - rec->GetListenerManager(getter_AddRefs(manager)); - if (manager) { - PRBool hasMutationListeners = PR_FALSE; - manager->HasMutationListeners(&hasMutationListeners); - if (hasMutationListeners) - return PR_TRUE; - } - } - - nsCOMPtr prev = curr; - prev->GetParent(*getter_AddRefs(curr)); - } - - nsCOMPtr rec(do_QueryInterface(doc)); - if (rec) { - rec->GetListenerManager(getter_AddRefs(manager)); - if (manager) { - PRBool hasMutationListeners = PR_FALSE; - manager->HasMutationListeners(&hasMutationListeners); - if (hasMutationListeners) - return PR_TRUE; - } - } - - rec = do_QueryInterface(window); - if (rec) { - rec->GetListenerManager(getter_AddRefs(manager)); - if (manager) { - PRBool hasMutationListeners = PR_FALSE; - manager->HasMutationListeners(&hasMutationListeners); - if (hasMutationListeners) - return PR_TRUE; - } - } - - return PR_FALSE; -} - -nsresult -nsGenericContainerElement::SetAttribute(nsINodeInfo* aNodeInfo, - const nsAReadableString& aValue, - PRBool aNotify) -{ - NS_ENSURE_ARG_POINTER(aNodeInfo); - - PRBool modification = PR_FALSE; - nsAutoString oldValue; - - nsresult rv = NS_ERROR_OUT_OF_MEMORY; - - if (!mAttributes) { - mAttributes = new nsVoidArray(); - NS_ENSURE_TRUE(mAttributes, NS_ERROR_OUT_OF_MEMORY); - } - - if (aNotify && (nsnull != mDocument)) { - mDocument->BeginUpdate(); - } - - nsGenericAttribute* attr; - PRInt32 index; - PRInt32 count = mAttributes->Count(); - for (index = 0; index < count; index++) { - attr = (nsGenericAttribute*)mAttributes->ElementAt(index); - if (attr->mNodeInfo == aNodeInfo) { - oldValue = attr->mValue; - modification = PR_TRUE; - attr->mValue = aValue; - rv = NS_OK; - break; - } - } - - if (index >= count) { // didn't find it - attr = new nsGenericAttribute(aNodeInfo, aValue); - NS_ENSURE_TRUE(attr, NS_ERROR_OUT_OF_MEMORY); - - mAttributes->AppendElement(attr); - rv = NS_OK; - } - - if (mDocument && NS_SUCCEEDED(rv)) { - nsCOMPtr name; - PRInt32 nameSpaceID; - - aNodeInfo->GetNameAtom(*getter_AddRefs(name)); - aNodeInfo->GetNamespaceID(nameSpaceID); - - nsCOMPtr bindingManager; - mDocument->GetBindingManager(getter_AddRefs(bindingManager)); - nsCOMPtr binding; - bindingManager->GetBinding(this, getter_AddRefs(binding)); - if (binding) - binding->AttributeChanged(name, nameSpaceID, PR_FALSE); - - if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_ATTRMODIFIED)) { - nsCOMPtr node(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this))); - nsMutationEvent mutation; - mutation.eventStructType = NS_MUTATION_EVENT; - mutation.message = NS_MUTATION_ATTRMODIFIED; - mutation.mTarget = node; - - nsAutoString attrName; - name->ToString(attrName); - nsCOMPtr attrNode; - GetAttributeNode(attrName, getter_AddRefs(attrNode)); - mutation.mRelatedNode = attrNode; - - mutation.mAttrName = name; - if (!oldValue.IsEmpty()) - mutation.mPrevAttrValue = getter_AddRefs(NS_NewAtom(oldValue)); - if (!aValue.IsEmpty()) - mutation.mNewAttrValue = getter_AddRefs(NS_NewAtom(aValue)); - mutation.mAttrChange = modification ? nsIDOMMutationEvent::MODIFICATION : - nsIDOMMutationEvent::ADDITION; - nsEventStatus status = nsEventStatus_eIgnore; - nsCOMPtr domEvent; - HandleDOMEvent(nsnull, &mutation, getter_AddRefs(domEvent), - NS_EVENT_FLAG_INIT, &status); - } - - if (aNotify) { - mDocument->AttributeChanged(this, nameSpaceID, name, - NS_STYLE_HINT_UNKNOWN); - mDocument->EndUpdate(); - } - } - - return rv; -} - -nsresult -nsGenericContainerElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - nsAWritableString& aResult) const -{ - nsCOMPtr prefix; - return GetAttribute(aNameSpaceID, aName, *getter_AddRefs(prefix), aResult); -} - -nsresult -nsGenericContainerElement::GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - nsIAtom*& aPrefix, - nsAWritableString& aResult) const -{ - NS_ASSERTION(nsnull != aName, "must have attribute name"); - if (nsnull == aName) { - return NS_ERROR_NULL_POINTER; - } - - nsresult rv = NS_CONTENT_ATTR_NOT_THERE; - - if (nsnull != mAttributes) { - PRInt32 count = mAttributes->Count(); - PRInt32 index; - for (index = 0; index < count; index++) { - const nsGenericAttribute* attr = (const nsGenericAttribute*)mAttributes->ElementAt(index); - if ((aNameSpaceID == kNameSpaceID_Unknown || - attr->mNodeInfo->NamespaceEquals(aNameSpaceID)) && - (attr->mNodeInfo->Equals(aName))) { - attr->mNodeInfo->GetPrefixAtom(aPrefix); - aResult.Assign(attr->mValue); - if (0 < aResult.Length()) { - rv = NS_CONTENT_ATTR_HAS_VALUE; - } - else { - rv = NS_CONTENT_ATTR_NO_VALUE; - } - break; - } - } - } - - if (rv == NS_CONTENT_ATTR_NOT_THERE) { - // In other cases we already set the out param. - // Since we are returning a success code we'd better do - // something about the out parameters (someone may have - // given us a non-empty string). - aResult.Truncate(); - } - - return rv; -} - -nsresult -nsGenericContainerElement::UnsetAttribute(PRInt32 aNameSpaceID, - nsIAtom* aName, PRBool aNotify) -{ - NS_ASSERTION(nsnull != aName, "must have attribute name"); - if (nsnull == aName) { - return NS_ERROR_NULL_POINTER; - } - - nsresult rv = NS_OK; - - if (nsnull != mAttributes) { - PRInt32 count = mAttributes->Count(); - PRInt32 index; - PRBool found = PR_FALSE; - for (index = 0; index < count; index++) { - nsGenericAttribute* attr = (nsGenericAttribute*)mAttributes->ElementAt(index); - if ((aNameSpaceID == kNameSpaceID_Unknown || - attr->mNodeInfo->NamespaceEquals(aNameSpaceID)) && - attr->mNodeInfo->Equals(aName)) { - if (aNotify && (nsnull != mDocument)) { - mDocument->BeginUpdate(); - } - - if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_ATTRMODIFIED)) { - nsCOMPtr node(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this))); - nsMutationEvent mutation; - mutation.eventStructType = NS_MUTATION_EVENT; - mutation.message = NS_MUTATION_ATTRMODIFIED; - mutation.mTarget = node; - - nsAutoString attrName; - aName->ToString(attrName); - nsCOMPtr attrNode; - GetAttributeNode(attrName, getter_AddRefs(attrNode)); - mutation.mRelatedNode = attrNode; - - mutation.mAttrName = aName; - if (!attr->mValue.IsEmpty()) - mutation.mPrevAttrValue = getter_AddRefs(NS_NewAtom(attr->mValue)); - mutation.mAttrChange = nsIDOMMutationEvent::REMOVAL; - - nsEventStatus status = nsEventStatus_eIgnore; - nsCOMPtr domEvent; - this->HandleDOMEvent(nsnull, &mutation, getter_AddRefs(domEvent), - NS_EVENT_FLAG_INIT, &status); - } - - mAttributes->RemoveElementAt(index); - delete attr; - found = PR_TRUE; - break; - } - } - - if (NS_SUCCEEDED(rv) && found && mDocument) { - nsCOMPtr bindingManager; - mDocument->GetBindingManager(getter_AddRefs(bindingManager)); - nsCOMPtr binding; - bindingManager->GetBinding(this, getter_AddRefs(binding)); - if (binding) - binding->AttributeChanged(aName, aNameSpaceID, PR_TRUE); - - if (aNotify) { - mDocument->AttributeChanged(this, aNameSpaceID, aName, - NS_STYLE_HINT_UNKNOWN); - mDocument->EndUpdate(); - } - } - } - - return rv; -} - -nsresult -nsGenericContainerElement::GetAttributeNameAt(PRInt32 aIndex, - PRInt32& aNameSpaceID, - nsIAtom*& aName, - nsIAtom*& aPrefix) const -{ - if (nsnull != mAttributes) { - nsGenericAttribute* attr = (nsGenericAttribute*)mAttributes->ElementAt(aIndex); - if (nsnull != attr) { - attr->mNodeInfo->GetNamespaceID(aNameSpaceID); - attr->mNodeInfo->GetNameAtom(aName); - attr->mNodeInfo->GetPrefixAtom(aPrefix); - - return NS_OK; - } - } - aNameSpaceID = kNameSpaceID_None; - aName = nsnull; - return NS_ERROR_ILLEGAL_VALUE; -} - -nsresult -nsGenericContainerElement::GetAttributeCount(PRInt32& aResult) const -{ - if (nsnull != mAttributes) { - aResult = mAttributes->Count(); - } - else { - aResult = 0; - } - return NS_OK; -} - -void -nsGenericContainerElement::ListAttributes(FILE* out) const -{ - PRInt32 index, count; - GetAttributeCount(count); - - for (index = 0; index < count; index++) { - const nsGenericAttribute* attr = (const nsGenericAttribute*)mAttributes->ElementAt(index); - nsAutoString buffer; - - // name - nsAutoString name; - attr->mNodeInfo->GetQualifiedName(name); - buffer.Append(name); - - // value - buffer.AppendWithConversion("="); - buffer.Append(attr->mValue); - - fputs(" ", out); - fputs(buffer, out); - } -} - -nsresult -nsGenericContainerElement::List(FILE* out, PRInt32 aIndent) const -{ - NS_PRECONDITION(nsnull != mDocument, "bad content"); - - PRInt32 index; - for (index = aIndent; --index >= 0; ) fputs(" ", out); - - nsAutoString buf; - mNodeInfo->GetQualifiedName(buf); - fputs(buf, out); - - fprintf(out, "@%p", this); - - ListAttributes(out); - - fprintf(out, " refcount=%d<", mRefCnt); - - PRBool canHaveKids; - CanContainChildren(canHaveKids); - if (canHaveKids) { - fputs("\n", out); - PRInt32 kids; - ChildCount(kids); - for (index = 0; index < kids; index++) { - nsIContent* kid; - ChildAt(index, kid); - kid->List(out, aIndent + 1); - NS_RELEASE(kid); - } - for (index = aIndent; --index >= 0; ) fputs(" ", out); - } - fputs(">\n", out); - - return NS_OK; -} - -nsresult -nsGenericContainerElement::DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) const { - return NS_OK; -} - -nsresult -nsGenericContainerElement::CanContainChildren(PRBool& aResult) const -{ - aResult = PR_TRUE; - return NS_OK; -} - -nsresult -nsGenericContainerElement::ChildCount(PRInt32& aCount) const -{ - aCount = mChildren.Count(); - return NS_OK; -} - -nsresult -nsGenericContainerElement::ChildAt(PRInt32 aIndex, - nsIContent*& aResult) const -{ - nsIContent *child = (nsIContent *)mChildren.ElementAt(aIndex); - if (nsnull != child) { - NS_ADDREF(child); - } - aResult = child; - return NS_OK; -} - -nsresult -nsGenericContainerElement::IndexOf(nsIContent* aPossibleChild, - PRInt32& aIndex) const -{ - NS_PRECONDITION(nsnull != aPossibleChild, "null ptr"); - aIndex = mChildren.IndexOf(aPossibleChild); - return NS_OK; -} - -nsresult -nsGenericContainerElement::InsertChildAt(nsIContent* aKid, - PRInt32 aIndex, - PRBool aNotify) -{ - NS_PRECONDITION(nsnull != aKid, "null ptr"); - nsIDocument* doc = mDocument; - if (aNotify && (nsnull != doc)) { - doc->BeginUpdate(); - } - PRBool rv = mChildren.InsertElementAt(aKid, aIndex);/* XXX fix up void array api to use nsresult's*/ - if (rv) { - NS_ADDREF(aKid); - aKid->SetParent(this); - nsRange::OwnerChildInserted(this, aIndex); - if (nsnull != doc) { - aKid->SetDocument(doc, PR_FALSE, PR_TRUE); - if (aNotify) { - doc->ContentInserted(this, aKid, aIndex); - } - - if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_NODEINSERTED)) { - nsCOMPtr node(do_QueryInterface(aKid)); - nsMutationEvent mutation; - mutation.eventStructType = NS_MUTATION_EVENT; - mutation.message = NS_MUTATION_NODEINSERTED; - mutation.mTarget = node; - - nsCOMPtr relNode(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this))); - mutation.mRelatedNode = relNode; - - nsEventStatus status = nsEventStatus_eIgnore; - nsCOMPtr domEvent; - aKid->HandleDOMEvent(nsnull, &mutation, getter_AddRefs(domEvent), - NS_EVENT_FLAG_INIT, &status); - } - } - } - if (aNotify && (nsnull != doc)) { - doc->EndUpdate(); - } - return NS_OK; -} - -nsresult -nsGenericContainerElement::ReplaceChildAt(nsIContent* aKid, - PRInt32 aIndex, - PRBool aNotify) -{ - NS_PRECONDITION(nsnull != aKid, "null ptr"); - nsIDocument* doc = mDocument; - if (aNotify && (nsnull != mDocument)) { - doc->BeginUpdate(); - } - nsIContent* oldKid = (nsIContent *)mChildren.ElementAt(aIndex); - nsRange::OwnerChildReplaced(this, aIndex, oldKid); - PRBool rv = mChildren.ReplaceElementAt(aKid, aIndex); - if (rv) { - NS_ADDREF(aKid); - aKid->SetParent(this); - if (nsnull != doc) { - aKid->SetDocument(doc, PR_FALSE, PR_TRUE); - if (aNotify) { - doc->ContentReplaced(this, oldKid, aKid, aIndex); - } - } - oldKid->SetDocument(nsnull, PR_TRUE, PR_TRUE); - oldKid->SetParent(nsnull); - NS_RELEASE(oldKid); - } - if (aNotify && (nsnull != mDocument)) { - doc->EndUpdate(); - } - return NS_OK; -} - -nsresult -nsGenericContainerElement::AppendChildTo(nsIContent* aKid, PRBool aNotify) -{ - NS_PRECONDITION(nsnull != aKid, "null ptr"); - nsIDocument* doc = mDocument; - if (aNotify && (nsnull != doc)) { - doc->BeginUpdate(); - } - PRBool rv = mChildren.AppendElement(aKid); - if (rv) { - NS_ADDREF(aKid); - aKid->SetParent(this); - // ranges don't need adjustment since new child is at end of list - if (nsnull != doc) { - aKid->SetDocument(doc, PR_FALSE, PR_TRUE); - if (aNotify) { - doc->ContentAppended(this, mChildren.Count() - 1); - } - - if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_NODEINSERTED)) { - nsCOMPtr node(do_QueryInterface(aKid)); - nsMutationEvent mutation; - mutation.eventStructType = NS_MUTATION_EVENT; - mutation.message = NS_MUTATION_NODEINSERTED; - mutation.mTarget = node; - - nsCOMPtr relNode(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this))); - mutation.mRelatedNode = relNode; - - nsEventStatus status = nsEventStatus_eIgnore; - nsCOMPtr domEvent; - aKid->HandleDOMEvent(nsnull, &mutation, getter_AddRefs(domEvent), - NS_EVENT_FLAG_INIT, &status); - } - } - } - if (aNotify && (nsnull != doc)) { - doc->EndUpdate(); - } - return NS_OK; -} - -nsresult -nsGenericContainerElement::RemoveChildAt(PRInt32 aIndex, PRBool aNotify) -{ - nsIContent* oldKid = (nsIContent *)mChildren.ElementAt(aIndex); - if (nsnull != oldKid ) { - nsIDocument* doc = mDocument; - if (aNotify && (nsnull != doc)) { - doc->BeginUpdate(); - } - - if (HasMutationListeners(this, NS_EVENT_BITS_MUTATION_NODEREMOVED)) { - nsCOMPtr node(do_QueryInterface(oldKid)); - nsMutationEvent mutation; - mutation.eventStructType = NS_MUTATION_EVENT; - mutation.message = NS_MUTATION_NODEREMOVED; - mutation.mTarget = node; - - nsCOMPtr relNode(do_QueryInterface(NS_STATIC_CAST(nsIContent *, this))); - mutation.mRelatedNode = relNode; - - nsEventStatus status = nsEventStatus_eIgnore; - nsCOMPtr domEvent; - oldKid->HandleDOMEvent(nsnull, &mutation, getter_AddRefs(domEvent), - NS_EVENT_FLAG_INIT, &status); - } - - nsRange::OwnerChildRemoved(this, aIndex, oldKid); - - mChildren.RemoveElementAt(aIndex); - if (aNotify) { - if (nsnull != doc) { - doc->ContentRemoved(this, oldKid, aIndex); - } - } - oldKid->SetDocument(nsnull, PR_TRUE, PR_TRUE); - oldKid->SetParent(nsnull); - NS_RELEASE(oldKid); - if (aNotify && (nsnull != doc)) { - doc->EndUpdate(); - } - } - - return NS_OK; -} - -PRUint32 -nsGenericContainerElement::BaseSizeOf(nsISizeOfHandler *aSizer) const -{ - PRUint32 sum = 0; -#ifdef DEBUG - if (mAttributes) { - // Add in array of attributes size - PRUint32 asize; - mAttributes->SizeOf(aSizer, &asize); - sum += asize; - - // Add in each attributes size - PRInt32 i, n = mAttributes->Count(); - for (i = 0; i < n; i++) { - const nsGenericAttribute* attr = (const nsGenericAttribute*) - mAttributes->ElementAt(i); - if (attr) { - PRUint32 asum = 0; - attr->SizeOf(aSizer, &asum); - sum += asum; - } - } - } -#endif - - return sum; -} - diff --git a/layout/base/src/nsGenericElement.h b/layout/base/src/nsGenericElement.h deleted file mode 100644 index 4332844a5c98..000000000000 --- a/layout/base/src/nsGenericElement.h +++ /dev/null @@ -1,475 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is Netscape Communications - * Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#ifndef nsGenericElement_h___ -#define nsGenericElement_h___ - -#include "nsCOMPtr.h" -#include "nsIHTMLContent.h" -#include "nsIDOMAttr.h" -#include "nsIDOMNamedNodeMap.h" -#include "nsIDOMElement.h" -#include "nsIDOMNodeList.h" -#include "nsIDOMLinkStyle.h" -#include "nsIStyleSheetLinkingElement.h" -#include "nsICSSStyleSheet.h" -#include "nsICSSLoaderObserver.h" -#include "nsVoidArray.h" -#include "nsIScriptObjectOwner.h" -#include "nsIJSScriptObject.h" -#include "nsILinkHandler.h" -#include "nsGenericDOMNodeList.h" -#include "nsIEventListenerManager.h" -#include "nsINodeInfo.h" -#include "nsIParser.h" - -class nsIDOMAttr; -class nsIDOMEventListener; -class nsIFrame; -class nsISupportsArray; -class nsIDOMScriptObjectFactory; -class nsDOMCSSDeclaration; -class nsIDOMCSSStyleDeclaration; -class nsDOMAttributeMap; -class nsIURI; -class nsINodeInfo; - - -// Class that holds the child list of a content element and also -// implements the nsIDOMNodeList interface. -class nsChildContentList : public nsGenericDOMNodeList -{ -public: - nsChildContentList(nsIContent *aContent); - virtual ~nsChildContentList(); - - // nsIDOMNodeList interface - NS_DECL_IDOMNODELIST - - void DropReference(); - -private: - nsIContent *mContent; -}; - -class nsCheapVoidArray { -public: - nsCheapVoidArray(); - ~nsCheapVoidArray(); - - PRInt32 Count() const; - void* ElementAt(PRInt32 aIndex) const; - PRInt32 IndexOf(void* aPossibleElement) const; - PRBool InsertElementAt(void* aElement, PRInt32 aIndex); - PRBool ReplaceElementAt(void* aElement, PRInt32 aIndex); - PRBool AppendElement(void* aElement); - PRBool RemoveElement(void* aElement); - PRBool RemoveElementAt(PRInt32 aIndex); - void Compact(); - -private: - typedef unsigned long PtrBits; - - PRBool HasSingleChild() const - { - return (mChildren && (PtrBits(mChildren) & 0x1)); - } - void* GetSingleChild() const - { - return (mChildren ? ((void*)(PtrBits(mChildren) & ~0x1)) : nsnull); - } - void SetSingleChild(void *aChild); - nsVoidArray* GetChildVector() const - { - return (nsVoidArray*)mChildren; - } - nsVoidArray* SwitchToVector(); - - // A tagged pointer that's either a pointer to a single child - // or a pointer to a vector of multiple children. This is a space - // optimization since a large number of containers have only a - // single child. - void *mChildren; -}; - -// There are a set of DOM- and scripting-specific instance variables -// that may only be instantiated when a content object is accessed -// through the DOM. Rather than burn actual slots in the content -// objects for each of these instance variables, we put them off -// in a side structure that's only allocated when the content is -// accessed through the DOM. -typedef struct { - void *mScriptObject; - nsChildContentList *mChildNodes; - nsDOMCSSDeclaration *mStyle; - nsDOMAttributeMap* mAttributeMap; - nsVoidArray *mRangeList; - nsIContent* mCapturer; - nsIEventListenerManager* mListenerManager; - nsIContent* mBindingParent; // The nearest enclosing content node with a binding - // that created us. [Weak] -} nsDOMSlots; - -class nsGenericElement : public nsIHTMLContent, - public nsIJSScriptObject -{ -public: - nsGenericElement(); - virtual ~nsGenericElement(); - - NS_DECL_ISUPPORTS - - nsresult Init(nsINodeInfo *aNodeInfo); - - // Free globals, to be called from module destructor - static void Shutdown(); - - // nsIContent interface methods - NS_IMETHOD GetDocument(nsIDocument*& aResult) const; - NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep, - PRBool aCompileEventHandlers); - NS_IMETHOD GetParent(nsIContent*& aResult) const; - NS_IMETHOD SetParent(nsIContent* aParent); - NS_IMETHOD GetNameSpaceID(PRInt32& aNameSpaceID) const; - NS_IMETHOD GetTag(nsIAtom*& aResult) const; - NS_IMETHOD GetNodeInfo(nsINodeInfo*& aResult) const; - // NS_IMETHOD CanContainChildren(PRBool& aResult) const; - // NS_IMETHOD ChildCount(PRInt32& aResult) const; - // NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const; - // NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const; - // NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, - // PRBool aNotify); - // NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, - // PRBool aNotify); - // NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify); - // NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify); - // NS_IMETHOD NormalizeAttributeString(const nsAReadableString& aStr, - // nsINodeInfo*& aNodeInfo); - // NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - // const nsAReadableString& aValue, - // PRBool aNotify); - // NS_IMETHOD SetAttribute(nsINodeInfo* aNodeInfo, - // const nsAReadableString& aValue, - // PRBool aNotify); - // NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - // nsAWritableString& aResult) const; - // NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - // nsIAtom*& aPrefix, - // nsAWritableString& aResult) const; - // NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, - // PRBool aNotify); - // NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, - // PRInt32& aNameSpaceID, - // nsIAtom*& aName, - // nsIAtom*& aPrefix) const; - // NS_IMETHOD GetAttributeCount(PRInt32& aResult) const; - // NS_IMETHOD List(FILE* out, PRInt32 aIndent) const; - // NS_IMETHOD DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) const; - NS_IMETHOD RangeAdd(nsIDOMRange& aRange); - NS_IMETHOD RangeRemove(nsIDOMRange& aRange); - NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const; - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus); - NS_IMETHOD GetContentID(PRUint32* aID); - NS_IMETHOD SetContentID(PRUint32 aID); - NS_IMETHOD SetFocus(nsIPresContext* aContext); - NS_IMETHOD RemoveFocus(nsIPresContext* aContext); - NS_IMETHOD GetBindingParent(nsIContent** aContent); - NS_IMETHOD SetBindingParent(nsIContent* aParent); - - // nsIStyledContent interface methods - NS_IMETHOD GetID(nsIAtom*& aResult) const; - NS_IMETHOD GetClasses(nsVoidArray& aArray) const; - NS_IMETHOD HasClass(nsIAtom* aClass) const; - NS_IMETHOD GetContentStyleRules(nsISupportsArray* aRules); - NS_IMETHOD GetInlineStyleRules(nsISupportsArray* aRules); - NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute, - PRInt32& aHint) const; - - // nsIXMLContent interface methods - NS_IMETHOD SetContainingNameSpace(nsINameSpace* aNameSpace); - NS_IMETHOD GetContainingNameSpace(nsINameSpace*& aNameSpace) const; - NS_IMETHOD MaybeTriggerAutoLink(nsIWebShell *aShell); - - // nsIHTMLContent interface methods - NS_IMETHOD Compact(); - NS_IMETHOD SetHTMLAttribute(nsIAtom* aAttribute, - const nsHTMLValue& aValue, - PRBool aNotify); - NS_IMETHOD GetHTMLAttribute(nsIAtom* aAttribute, - nsHTMLValue& aValue) const; - NS_IMETHOD GetAttributeMappingFunctions(nsMapAttributesFunc& aFontMapFunc, - nsMapAttributesFunc& aMapFunc) const; - NS_IMETHOD AttributeToString(nsIAtom* aAttribute, - const nsHTMLValue& aValue, - nsAWritableString& aResult) const; - NS_IMETHOD StringToAttribute(nsIAtom* aAttribute, - const nsAReadableString& aValue, - nsHTMLValue& aResult); - NS_IMETHOD GetBaseURL(nsIURI*& aBaseURL) const; - NS_IMETHOD GetBaseTarget(nsAWritableString& aBaseTarget) const; - - - // nsIScriptObjectOwner interface methods - NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); - NS_IMETHOD SetScriptObject(void *aScriptObject); - - // nsIJSScriptObject interface methods - virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool DeleteProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj, - jsval aID, jsval *aVp); - virtual PRBool EnumerateProperty(JSContext *aContext, JSObject *aObj); - virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID, - PRBool *aDidDefineProperty); - virtual PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID); - virtual void Finalize(JSContext *aContext, JSObject *aObj); - - - // nsIDOMNode method implementation - NS_IMETHOD GetNodeName(nsAWritableString& aNodeName); - NS_IMETHOD GetLocalName(nsAWritableString& aLocalName); - NS_IMETHOD GetNodeValue(nsAWritableString& aNodeValue); - NS_IMETHOD SetNodeValue(const nsAReadableString& aNodeValue); - NS_IMETHOD GetNodeType(PRUint16* aNodeType); - NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode); - NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes); - NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling); - NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling); - NS_IMETHOD GetOwnerDocument(nsIDOMDocument** aOwnerDocument); - NS_IMETHOD GetNamespaceURI(nsAWritableString& aNamespaceURI); - NS_IMETHOD GetPrefix(nsAWritableString& aPrefix); - NS_IMETHOD SetPrefix(const nsAReadableString& aPrefix); - NS_IMETHOD Normalize(); - NS_IMETHOD IsSupported(const nsAReadableString& aFeature, - const nsAReadableString& aVersion, PRBool* aReturn); - NS_IMETHOD HasAttributes(PRBool* aHasAttributes); - - // nsIDOMElement method implementation - NS_IMETHOD GetTagName(nsAWritableString& aTagName); - NS_IMETHOD GetAttribute(const nsAReadableString& aName, - nsAWritableString& aReturn); - NS_IMETHOD SetAttribute(const nsAReadableString& aName, - const nsAReadableString& aValue); - NS_IMETHOD RemoveAttribute(const nsAReadableString& aName); - NS_IMETHOD GetAttributeNode(const nsAReadableString& aName, - nsIDOMAttr** aReturn); - NS_IMETHOD SetAttributeNode(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn); - NS_IMETHOD RemoveAttributeNode(nsIDOMAttr* aOldAttr, nsIDOMAttr** aReturn); - NS_IMETHOD GetElementsByTagName(const nsAReadableString& aTagname, - nsIDOMNodeList** aReturn); - NS_IMETHOD GetAttributeNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - nsAWritableString& aReturn); - NS_IMETHOD SetAttributeNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aQualifiedName, - const nsAReadableString& aValue); - NS_IMETHOD RemoveAttributeNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName); - NS_IMETHOD GetAttributeNodeNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - nsIDOMAttr** aReturn); - NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn); - NS_IMETHOD GetElementsByTagNameNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - nsIDOMNodeList** aReturn); - NS_IMETHOD HasAttribute(const nsAReadableString& aName, PRBool* aReturn); - NS_IMETHOD HasAttributeNS(const nsAReadableString& aNamespaceURI, - const nsAReadableString& aLocalName, - PRBool* aReturn); - - // Generic DOMNode implementations - nsresult doInsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, - nsIDOMNode** aReturn); - nsresult doReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, - nsIDOMNode** aReturn); - nsresult doRemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn); - - //---------------------------------------- - - nsresult GetListenerManager(nsIEventListenerManager** aInstancePtrResult); - - nsresult RenderFrame(nsIPresContext*); - - nsresult AddScriptEventListener(nsIAtom* aAttribute, - const nsAReadableString& aValue, - REFNSIID aIID); - - nsresult TriggerLink(nsIPresContext* aPresContext, - nsLinkVerb aVerb, - nsIURI* aBaseURL, - const nsString& aURLSpec, - const nsString& aTargetSpec, - PRBool aClick); - - nsresult JoinTextNodes(nsIContent* aFirst, - nsIContent* aSecond); - - static void SetDocumentInChildrenOf(nsIContent* aContent, - nsIDocument* aDocument, PRBool aCompileEventHandlers); - - static nsresult GetScriptObjectFactory(nsIDOMScriptObjectFactory **aFactory); - - static nsIDOMScriptObjectFactory *gScriptObjectFactory; - - static nsresult InternalIsSupported(const nsAReadableString& aFeature, - const nsAReadableString& aVersion, - PRBool* aReturn); - - static PRBool HasMutationListeners(nsIContent* aContent, - PRUint32 aType); - -protected: - virtual PRUint32 BaseSizeOf(nsISizeOfHandler *aSizer) const; - - nsDOMSlots *GetDOMSlots(); - void MaybeClearDOMSlots(); - - nsIDocument* mDocument; // WEAK - nsIContent* mParent; // WEAK - - nsINodeInfo* mNodeInfo; // OWNER - nsDOMSlots *mDOMSlots; // OWNER - PRUint32 mContentID; -}; - -class nsGenericContainerElement : public nsGenericElement { -public: - nsGenericContainerElement(); - virtual ~nsGenericContainerElement(); - - NS_IMETHOD CopyInnerTo(nsIContent* aSrcContent, - nsGenericContainerElement* aDest, - PRBool aDeep); - - // nsIDOMElement methods - NS_METHOD GetAttribute(const nsAReadableString& aName, - nsAWritableString& aReturn) - { - return nsGenericElement::GetAttribute(aName, aReturn); - } - NS_METHOD SetAttribute(const nsAReadableString& aName, - const nsAReadableString& aValue) - { - return nsGenericElement::SetAttribute(aName, aValue); - } - - // Remainder of nsIDOMHTMLElement (and nsIDOMNode) - NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes); - NS_IMETHOD HasChildNodes(PRBool* aHasChildNodes); - NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild); - NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild); - - NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, - nsIDOMNode** aReturn) - { - return nsGenericElement::doInsertBefore(aNewChild, aRefChild, aReturn); - } - NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, - nsIDOMNode** aReturn) - { - return nsGenericElement::doReplaceChild(aNewChild, aOldChild, aReturn); - } - NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) - { - return nsGenericElement::doRemoveChild(aOldChild, aReturn); - } - NS_IMETHOD AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn) - { - return nsGenericElement::doInsertBefore(aNewChild, nsnull, aReturn); - } - - // Remainder of nsIContent - NS_IMETHOD NormalizeAttributeString(const nsAReadableString& aStr, - nsINodeInfo*& aNodeInfo); - NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - const nsAReadableString& aValue, - PRBool aNotify); - NS_IMETHOD SetAttribute(nsINodeInfo* aNodeInfo, - const nsAReadableString& aValue, - PRBool aNotify); - NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - nsAWritableString& aResult) const; - NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, - nsIAtom*& aPrefix, nsAWritableString& aResult) const; - NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aAttribute, - PRBool aNotify); - NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, - PRInt32& aNameSpaceID, - nsIAtom*& aName, - nsIAtom*& aPrefix) const; - NS_IMETHOD GetAttributeCount(PRInt32& aResult) const; - NS_IMETHOD List(FILE* out, PRInt32 aIndent) const; - NS_IMETHOD DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) const; - NS_IMETHOD CanContainChildren(PRBool& aResult) const; - NS_IMETHOD ChildCount(PRInt32& aResult) const; - NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const; - NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const; - NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify); - NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify); - NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify); - NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify); - - void ListAttributes(FILE* out) const; - -protected: - virtual PRUint32 BaseSizeOf(nsISizeOfHandler *aSizer) const; - - nsVoidArray* mAttributes; - nsCheapVoidArray mChildren; -}; - - -#define NS_FORWARD_IDOMNODE_NO_CLONENODE(_to) \ - NS_IMETHOD GetNodeName(nsAWritableString& aNodeName) { return _to GetNodeName(aNodeName); } \ - NS_IMETHOD GetNodeValue(nsAWritableString& aNodeValue) { return _to GetNodeValue(aNodeValue); } \ - NS_IMETHOD SetNodeValue(const nsAReadableString& aNodeValue) { return _to SetNodeValue(aNodeValue); } \ - NS_IMETHOD GetNodeType(PRUint16* aNodeType) { return _to GetNodeType(aNodeType); } \ - NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode) { return _to GetParentNode(aParentNode); } \ - NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes) { return _to GetChildNodes(aChildNodes); } \ - NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild) { return _to GetFirstChild(aFirstChild); } \ - NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild) { return _to GetLastChild(aLastChild); } \ - NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling) { return _to GetPreviousSibling(aPreviousSibling); } \ - NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling) { return _to GetNextSibling(aNextSibling); } \ - NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes) { return _to GetAttributes(aAttributes); } \ - NS_IMETHOD GetOwnerDocument(nsIDOMDocument** aOwnerDocument) { return _to GetOwnerDocument(aOwnerDocument); } \ - NS_IMETHOD GetNamespaceURI(nsAWritableString& aNamespaceURI) { return _to GetNamespaceURI(aNamespaceURI); } \ - NS_IMETHOD GetPrefix(nsAWritableString& aPrefix) { return _to GetPrefix(aPrefix); } \ - NS_IMETHOD SetPrefix(const nsAReadableString& aPrefix) { return _to SetPrefix(aPrefix); } \ - NS_IMETHOD GetLocalName(nsAWritableString& aLocalName) { return _to GetLocalName(aLocalName); } \ - NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, nsIDOMNode** aReturn) { return _to InsertBefore(aNewChild, aRefChild, aReturn); } \ - NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { return _to ReplaceChild(aNewChild, aOldChild, aReturn); } \ - NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { return _to RemoveChild(aOldChild, aReturn); } \ - NS_IMETHOD AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn) { return _to AppendChild(aNewChild, aReturn); } \ - NS_IMETHOD HasChildNodes(PRBool* aReturn) { return _to HasChildNodes(aReturn); } \ - NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn); \ - NS_IMETHOD Normalize() { return _to Normalize(); } \ - NS_IMETHOD IsSupported(const nsAReadableString& aFeature, const nsAReadableString& aVersion, PRBool* aReturn) { return _to IsSupported(aFeature, aVersion, aReturn); } \ - NS_IMETHOD HasAttributes(PRBool* aReturn) { return _to HasAttributes(aReturn); } \ - -#endif /* nsGenericElement_h___ */ diff --git a/layout/base/src/nsHTMLContentSerializer.cpp b/layout/base/src/nsHTMLContentSerializer.cpp deleted file mode 100644 index d8dc13b904c4..000000000000 --- a/layout/base/src/nsHTMLContentSerializer.cpp +++ /dev/null @@ -1,792 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsHTMLContentSerializer.h" - -#include "nsIDOMElement.h" -#include "nsIContent.h" -#include "nsIDocument.h" -#include "nsINameSpaceManager.h" -#include "nsString.h" -#include "nsXPIDLString.h" -#include "nsParserCIID.h" -#include "nsIServiceManager.h" -#include "nsIDocumentEncoder.h" -#include "nsLayoutAtoms.h" -#include "nsHTMLAtoms.h" -#include "nsIURI.h" -#include "nsNetUtil.h" -#include "nsEscape.h" - -static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID); - -#define kIndentStr NS_LITERAL_STRING(" ") -#define kMozStr "_moz" -#define kLessThan NS_LITERAL_STRING("<") -#define kGreaterThan NS_LITERAL_STRING(">") -#define kEndTag NS_LITERAL_STRING("QueryInterface(NS_GET_IID(nsIContentSerializer), (void**)aSerializer); -} - -nsHTMLContentSerializer::nsHTMLContentSerializer() -{ - mColPos = 0; - mIndent = 0; - mInBody = PR_FALSE; - mInCDATA = PR_FALSE; -} - -nsHTMLContentSerializer::~nsHTMLContentSerializer() -{ -} - -nsresult -nsHTMLContentSerializer::GetParserService(nsIParserService** aParserService) -{ - if (!mParserService) { - nsresult rv; - mParserService = do_GetService(kParserServiceCID, &rv); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - } - - CallQueryInterface(mParserService.get(), aParserService); - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLContentSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn, - nsIAtom* aCharSet) -{ - mFlags = aFlags; - if (!aWrapColumn) { - mMaxColumn = 72; - } - else { - mMaxColumn = aWrapColumn; - } - - mDoFormat = (mFlags & nsIDocumentEncoder::OutputFormatted) ? PR_TRUE - : PR_FALSE; - mBodyOnly = (mFlags & nsIDocumentEncoder::OutputBodyOnly) ? PR_TRUE - : PR_FALSE; - // Set the line break character: - if ((mFlags & nsIDocumentEncoder::OutputCRLineBreak) - && (mFlags & nsIDocumentEncoder::OutputLFLineBreak)) { // Windows/mail - mLineBreak.AssignWithConversion("\r\n"); - } - else if (mFlags & nsIDocumentEncoder::OutputCRLineBreak) { // Mac - mLineBreak.AssignWithConversion("\r"); - } - else if (mFlags & nsIDocumentEncoder::OutputLFLineBreak) { // Unix/DOM - mLineBreak.AssignWithConversion("\n"); - } - else { - mLineBreak.AssignWithConversion(NS_LINEBREAK); // Platform/default - } - - mPreLevel = 0; - - mIsLatin1 = PR_FALSE; - if (aCharSet) { - const PRUnichar *charset; - aCharSet->GetUnicode(&charset); - - if (NS_LITERAL_STRING("ISO-8859-1").Equals(charset)) { - mIsLatin1 = PR_TRUE; - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLContentSerializer::AppendText(nsIDOMText* aText, - PRInt32 aStartOffset, - PRInt32 aEndOffset, - nsAWritableString& aStr) -{ - NS_ENSURE_ARG(aText); - - nsAutoString data; - - nsresult rv; - rv = AppendTextData((nsIDOMNode*)aText, aStartOffset, - aEndOffset, data, PR_TRUE, PR_FALSE); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - - PRInt32 lastNewlineOffset = kNotFound; - PRBool hasLongLines = HasLongLines(data, lastNewlineOffset); - - if (mPreLevel || (!mDoFormat && !hasLongLines) || - (mFlags & nsIDocumentEncoder::OutputRaw)) { - AppendToString(data, aStr); - - if (lastNewlineOffset != kNotFound) { - mColPos = data.Length() - lastNewlineOffset; - } - } - else { - AppendToStringWrapped(data, aStr, PR_FALSE); - } - - return NS_OK; -} - - -void -nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent, - nsIAtom* aTagName, - nsAWritableString& aStr) -{ - nsresult rv; - PRInt32 index, count; - nsAutoString nameStr, valueStr; - PRInt32 namespaceID; - nsCOMPtr attrName, attrPrefix; - - aContent->GetAttributeCount(count); - - for (index = 0; index < count; index++) { - aContent->GetAttributeNameAt(index, - namespaceID, - *getter_AddRefs(attrName), - *getter_AddRefs(attrPrefix)); - - // Filter out any attribute starting with _moz - nsXPIDLString sharedName; - attrName->GetUnicode(getter_Shares(sharedName)); - if (nsCRT::strncmp(sharedName, - NS_ConvertASCIItoUCS2(kMozStr), - sizeof(kMozStr)-1) == 0) { - continue; - } - - aContent->GetAttribute(namespaceID, attrName, valueStr); - - // - // Filter out special case of
or
, - // used by the editor. Bug 16988. Yuck. - // - if ((aTagName == nsHTMLAtoms::br) && - (attrName.get() == nsHTMLAtoms::type) && - (valueStr.EqualsWithConversion(kMozStr, PR_FALSE, sizeof(kMozStr)-1))) { - continue; - } - - // Make all links absolute when converting only the selection: - if ((mFlags & nsIDocumentEncoder::OutputAbsoluteLinks) && - ((attrName.get() == nsHTMLAtoms::href) || - (attrName.get() == nsHTMLAtoms::src))) { - // Would be nice to handle OBJECT and APPLET tags, - // but that gets more complicated since we have to - // search the tag list for CODEBASE as well. - // For now, just leave them relative. - nsCOMPtr document; - aContent->GetDocument(*getter_AddRefs(document)); - if (document) { - nsCOMPtr uri = dont_AddRef(document->GetDocumentURL()); - if (uri) { - nsAutoString absURI; - rv = NS_MakeAbsoluteURI(absURI, valueStr, uri); - if (NS_SUCCEEDED(rv)) { - valueStr = absURI; - } - } - } - } - - attrName->ToString(nameStr); - - SerializeAttr(nsAutoString(), nameStr, valueStr, aStr); - } -} - -NS_IMETHODIMP -nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, - nsAWritableString& aStr) -{ - NS_ENSURE_ARG(aElement); - - nsCOMPtr content = do_QueryInterface(aElement); - if (!content) return NS_ERROR_FAILURE; - - // The _moz_dirty attribute is emitted by the editor to - // indicate that this element should be pretty printed - // even if we're not in pretty printing mode - PRBool hasDirtyAttr = HasDirtyAttr(content); - - nsCOMPtr name; - content->GetTag(*getter_AddRefs(name)); - - if (name.get() == nsHTMLAtoms::body) { - mInBody = PR_TRUE; - } - - if (LineBreakBeforeOpen(name, hasDirtyAttr)) { - AppendToString(mLineBreak, aStr); - mColPos = 0; - } - - StartIndentation(name, hasDirtyAttr, aStr); - - if ((name.get() == nsHTMLAtoms::pre) || - (name.get() == nsHTMLAtoms::script) || - (name.get() == nsHTMLAtoms::style)) { - mPreLevel++; - } - - AppendToString(kLessThan, aStr); - - nsXPIDLString sharedName; - name->GetUnicode(getter_Shares(sharedName)); - AppendToString(sharedName, -1, aStr); - - SerializeAttributes(content, name, aStr); - - AppendToString(kGreaterThan, aStr); - - if (LineBreakAfterOpen(name, hasDirtyAttr)) { - AppendToString(mLineBreak, aStr); - mColPos = 0; - } - - if ((name.get() == nsHTMLAtoms::script) || - (name.get() == nsHTMLAtoms::style) || - (name.get() == nsHTMLAtoms::noscript)) { - mInCDATA = PR_TRUE; - } - - return NS_OK; -} - -NS_IMETHODIMP -nsHTMLContentSerializer::AppendElementEnd(nsIDOMElement *aElement, - nsAWritableString& aStr) -{ - NS_ENSURE_ARG(aElement); - - nsCOMPtr content = do_QueryInterface(aElement); - if (!content) return NS_ERROR_FAILURE; - - PRBool hasDirtyAttr = HasDirtyAttr(content); - - nsCOMPtr name; - content->GetTag(*getter_AddRefs(name)); - - if ((name.get() == nsHTMLAtoms::pre) || - (name.get() == nsHTMLAtoms::script) || - (name.get() == nsHTMLAtoms::style)) { - mPreLevel--; - } - - nsXPIDLString sharedName; - name->GetUnicode(getter_Shares(sharedName)); - - nsCOMPtr parserService; - GetParserService(getter_AddRefs(parserService)); - - if (parserService && (name.get() != nsHTMLAtoms::style)) { - nsAutoString nameStr(sharedName); - PRBool isContainer; - PRInt32 id; - - parserService->HTMLStringTagToId(nameStr, &id); - parserService->IsContainer(id, isContainer); - if (!isContainer) return NS_OK; - } - - if (LineBreakBeforeClose(name, hasDirtyAttr)) { - AppendToString(mLineBreak, aStr); - mColPos = 0; - } - - EndIndentation(name, hasDirtyAttr, aStr); - - AppendToString(kEndTag, aStr); - AppendToString(sharedName, -1, aStr); - AppendToString(kGreaterThan, aStr); - - if (LineBreakAfterClose(name, hasDirtyAttr)) { - AppendToString(mLineBreak, aStr); - mColPos = 0; - } - - mInCDATA = PR_FALSE; - - return NS_OK; -} - -void -nsHTMLContentSerializer::AppendToString(const PRUnichar* aStr, - PRInt32 aLength, - nsAWritableString& aOutputStr) -{ - if (mBodyOnly && !mInBody) { - return; - } - - PRInt32 length = (aLength == -1) ? nsCRT::strlen(aStr) : aLength; - - mColPos += length; - - aOutputStr.Append(aStr, length); -} - -void -nsHTMLContentSerializer::AppendToString(const PRUnichar aChar, - nsAWritableString& aOutputStr) -{ - if (mBodyOnly && !mInBody) { - return; - } - - mColPos += 1; - - aOutputStr.Append(aChar); -} - -void -nsHTMLContentSerializer::AppendToStringWrapped(const nsAReadableString& aStr, - nsAWritableString& aOutputStr, - PRBool aTranslateEntities) -{ - PRInt32 length = aStr.Length(); - - nsAutoString line; - PRBool done = PR_FALSE; - PRInt32 indx = 0; - PRInt32 strOffset = 0; - PRInt32 lineLength, oldLineEnd; - - // Make sure we haven't gone too far already - if (mColPos > mMaxColumn) { - AppendToString(mLineBreak, aOutputStr); - mColPos = 0; - } - - // Find the end of the first old line - oldLineEnd = aStr.FindChar(PRUnichar('\n'), 0); - - while ((!done) && (strOffset < length)) { - // This is how much is needed to fill up the new line - PRInt32 leftInLine = mMaxColumn - mColPos; - - // This is the last position in the current old line - PRInt32 oldLineLimit; - if (oldLineEnd == kNotFound) { - oldLineLimit = length; - } - else { - oldLineLimit = oldLineEnd; - } - - PRBool addLineBreak = PR_FALSE; - - // if we can fill up the new line with less than what's - // in the current old line... - if ((strOffset + leftInLine) < oldLineLimit) { - addLineBreak = PR_TRUE; - - // Look for the next word end to break - indx = aStr.FindChar(PRUnichar(' '), strOffset + leftInLine); - - // If it's after the end of the current line, then break at - // the current line - if ((indx == kNotFound) || - ((oldLineEnd != kNotFound) && (oldLineEnd < indx))) { - indx = oldLineEnd; - } - } - else { - indx = oldLineEnd; - } - - // if there was no place to break, then just add the entire string - if (indx == kNotFound) { - if (strOffset == 0) { - AppendToString(aStr, aOutputStr, aTranslateEntities); - } - else { - lineLength = length - strOffset; - aStr.Right(line, lineLength); - AppendToString(line, aOutputStr, aTranslateEntities); - } - done = PR_TRUE; - } - else { - // Add the part of the current old line that's part of the - // new line - lineLength = indx - strOffset; - aStr.Mid(line, strOffset, lineLength); - AppendToString(line, aOutputStr, aTranslateEntities); - - // if we've reached the end of an old line, don't add the - // old line break and find the end of the next old line. - if (indx == oldLineEnd) { - oldLineEnd = aStr.FindChar(PRUnichar('\n'), indx+1); - AppendToString(NS_LITERAL_STRING(" "), aOutputStr); - } - - if (addLineBreak) { - AppendToString(mLineBreak, aOutputStr); - mColPos = 0; - } - strOffset = indx+1; - } - } -} - -static PRUint16 kGTVal = 62; -static const char* kEntities[] = { - "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "amp", "", - "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", - "lt", "", "gt" -}; - -static const char* kAttrEntities[] = { - "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "quot", "", "", "", "amp", "apos", - "", "", "", "", "", "", "", "", "", "", - "", "", "", "", "", "", "", "", "", "", - "lt", "", "gt" -}; - -void -nsHTMLContentSerializer::AppendToString(const nsAReadableString& aStr, - nsAWritableString& aOutputStr, - PRBool aTranslateEntities, - PRBool aIncrColumn) -{ - if (mBodyOnly && !mInBody) { - return; - } - - if (aIncrColumn) { - mColPos += aStr.Length(); - } - - if (aTranslateEntities && !mInCDATA) { - if (mFlags & nsIDocumentEncoder::OutputEncodeEntities) { - nsCOMPtr parserService; - GetParserService(getter_AddRefs(parserService)); - - if (!parserService) { - NS_ERROR("Can't get parser service"); - return; - } - - nsReadingIterator done_reading; - aStr.EndReading(done_reading); - - // for each chunk of |aString|... - PRUint32 advanceLength = 0; - nsReadingIterator iter; - - const char **entityTable = mInAttribute ? kAttrEntities : kEntities; - - for (aStr.BeginReading(iter); - iter != done_reading; - iter.advance(PRInt32(advanceLength))) { - PRUint32 fragmentLength = iter.size_forward(); - const PRUnichar* c = iter.get(); - const PRUnichar* fragmentStart = c; - const PRUnichar* fragmentEnd = c + fragmentLength; - const char* entityText = nsnull; - nsCAutoString entityReplacement; - - advanceLength = 0; - // for each character in this chunk, check if it - // needs to be replaced - for (; c < fragmentEnd; c++, advanceLength++) { - PRUnichar val = *c; - if ((val <= kGTVal) && (entityTable[val][0] != 0)) { - entityText = entityTable[val]; - break; - } else if (mIsLatin1 && val > 127 && val < 256) { - parserService->HTMLConvertUnicodeToEntity(val, entityReplacement); - - if (entityReplacement.Length() > 0) { - entityText = entityReplacement.GetBuffer(); - break; - } - } - } - - aOutputStr.Append(fragmentStart, advanceLength); - if (entityText) { - aOutputStr.Append(PRUnichar('&')); - aOutputStr.Append(NS_ConvertASCIItoUCS2(entityText)); - aOutputStr.Append(PRUnichar(';')); - advanceLength++; - } - } - } else { - nsXMLContentSerializer::AppendToString(aStr, aOutputStr, aTranslateEntities, aIncrColumn); - } - - return; - } - - aOutputStr.Append(aStr); -} - -PRBool -nsHTMLContentSerializer::HasDirtyAttr(nsIContent* aContent) -{ - nsAutoString val; - - if (NS_CONTENT_ATTR_NOT_THERE != aContent->GetAttribute(kNameSpaceID_None, - nsLayoutAtoms::mozdirty, - val)) { - return PR_TRUE; - } - else { - return PR_FALSE; - } -} - -PRBool -nsHTMLContentSerializer::LineBreakBeforeOpen(nsIAtom* aName, - PRBool aHasDirtyAttr) -{ - if ((!mDoFormat && !aHasDirtyAttr) || mPreLevel || !mColPos || - (mFlags & nsIDocumentEncoder::OutputRaw)) { - return PR_FALSE; - } - - if (aName == nsHTMLAtoms::title || - aName == nsHTMLAtoms::meta || - aName == nsHTMLAtoms::link || - aName == nsHTMLAtoms::style || - aName == nsHTMLAtoms::script || - aName == nsHTMLAtoms::html) { - return PR_TRUE; - } - else { - nsCOMPtr parserService; - GetParserService(getter_AddRefs(parserService)); - - if (parserService) { - nsAutoString str; - aName->ToString(str); - PRBool res; - PRInt32 id; - - parserService->HTMLStringTagToId(str, &id); - parserService->IsBlock(id, res); - return res; - } - } - - return PR_FALSE; -} - -PRBool -nsHTMLContentSerializer::LineBreakAfterOpen(nsIAtom* aName, - PRBool aHasDirtyAttr) -{ - if ((!mDoFormat && !aHasDirtyAttr) || mPreLevel || - (mFlags & nsIDocumentEncoder::OutputRaw)) { - return PR_FALSE; - } - - if ((aName == nsHTMLAtoms::html) || - (aName == nsHTMLAtoms::head) || - (aName == nsHTMLAtoms::body) || - (aName == nsHTMLAtoms::ul) || - (aName == nsHTMLAtoms::ol) || - (aName == nsHTMLAtoms::dl) || - (aName == nsHTMLAtoms::table) || - (aName == nsHTMLAtoms::tbody) || - (aName == nsHTMLAtoms::tr) || - (aName == nsHTMLAtoms::br) || - (aName == nsHTMLAtoms::meta) || - (aName == nsHTMLAtoms::link) || - (aName == nsHTMLAtoms::script) || - (aName == nsHTMLAtoms::style)) { - return PR_TRUE; - } - - return PR_FALSE; -} - -PRBool -nsHTMLContentSerializer::LineBreakBeforeClose(nsIAtom* aName, - PRBool aHasDirtyAttr) -{ - if ((!mDoFormat && !aHasDirtyAttr) || mPreLevel || !mColPos || - (mFlags & nsIDocumentEncoder::OutputRaw)) { - return PR_FALSE; - } - - if ((aName == nsHTMLAtoms::html) || - (aName == nsHTMLAtoms::head) || - (aName == nsHTMLAtoms::body) || - (aName == nsHTMLAtoms::ul) || - (aName == nsHTMLAtoms::ol) || - (aName == nsHTMLAtoms::dl) || - (aName == nsHTMLAtoms::table) || - (aName == nsHTMLAtoms::tbody)) { - return PR_TRUE; - } - - return PR_FALSE; -} - -PRBool -nsHTMLContentSerializer::LineBreakAfterClose(nsIAtom* aName, - PRBool aHasDirtyAttr) -{ - if ((!mDoFormat && !aHasDirtyAttr) || mPreLevel || - (mFlags & nsIDocumentEncoder::OutputRaw)) { - return PR_FALSE; - } - - if ((aName == nsHTMLAtoms::html) || - (aName == nsHTMLAtoms::head) || - (aName == nsHTMLAtoms::body) || - (aName == nsHTMLAtoms::tr) || - (aName == nsHTMLAtoms::th) || - (aName == nsHTMLAtoms::td) || - (aName == nsHTMLAtoms::pre) || - (aName == nsHTMLAtoms::title) || - (aName == nsHTMLAtoms::li) || - (aName == nsHTMLAtoms::dt) || - (aName == nsHTMLAtoms::dd) || - (aName == nsHTMLAtoms::blockquote) || - (aName == nsHTMLAtoms::p) || - (aName == nsHTMLAtoms::div)) { - return PR_TRUE; - } - else { - nsCOMPtr parserService; - GetParserService(getter_AddRefs(parserService)); - - if (parserService) { - nsAutoString str; - aName->ToString(str); - PRBool res; - PRInt32 id; - - parserService->HTMLStringTagToId(str, &id); - parserService->IsBlock(id, res); - return res; - } - } - - return PR_FALSE; -} - -void -nsHTMLContentSerializer::StartIndentation(nsIAtom* aName, - PRBool aHasDirtyAttr, - nsAWritableString& aStr) -{ - if ((mDoFormat || aHasDirtyAttr) && !mPreLevel && !mColPos) { - for (PRInt32 i = mIndent; --i >= 0; ) { - AppendToString(kIndentStr, -1, - aStr); - } - } - - if ((aName == nsHTMLAtoms::head) || - (aName == nsHTMLAtoms::table) || - (aName == nsHTMLAtoms::tr) || - (aName == nsHTMLAtoms::ul) || - (aName == nsHTMLAtoms::ol) || - (aName == nsHTMLAtoms::tbody) || - (aName == nsHTMLAtoms::form) || - (aName == nsHTMLAtoms::frameset) || - (aName == nsHTMLAtoms::blockquote) || - (aName == nsHTMLAtoms::li) || - (aName == nsHTMLAtoms::dt) || - (aName == nsHTMLAtoms::dd)) { - mIndent++; - } -} - -void -nsHTMLContentSerializer::EndIndentation(nsIAtom* aName, - PRBool aHasDirtyAttr, - nsAWritableString& aStr) -{ - if ((aName == nsHTMLAtoms::head) || - (aName == nsHTMLAtoms::table) || - (aName == nsHTMLAtoms::tr) || - (aName == nsHTMLAtoms::ul) || - (aName == nsHTMLAtoms::ol) || - (aName == nsHTMLAtoms::li) || - (aName == nsHTMLAtoms::tbody) || - (aName == nsHTMLAtoms::form) || - (aName == nsHTMLAtoms::frameset)) { - mIndent--; - } - - if ((mDoFormat || aHasDirtyAttr) && !mPreLevel && !mColPos) { - for (PRInt32 i = mIndent; --i >= 0; ) { - AppendToString(kIndentStr, -1, - aStr); - } - } -} - -// See if the string has any lines longer than longLineLen: -// if so, we presume formatting is wonky (e.g. the node has been edited) -// and we'd better rewrap the whole text node. -PRBool -nsHTMLContentSerializer::HasLongLines(const nsString& text, PRInt32& aLastNewlineOffset) -{ - PRUint32 start=0; - PRUint32 theLen=text.Length(); - PRBool rv = PR_FALSE; - aLastNewlineOffset = kNotFound; - for (start = 0; start < theLen; ) - { - PRInt32 eol = text.FindChar('\n', PR_FALSE, start); - if (eol < 0) { - eol = text.Length(); - } - else { - aLastNewlineOffset = eol; - } - if (PRInt32(eol - start) > kLongLineLen) - rv = PR_TRUE; - start = eol+1; - } - return rv; -} diff --git a/layout/base/src/nsHTMLContentSerializer.h b/layout/base/src/nsHTMLContentSerializer.h deleted file mode 100644 index c1e6e0545969..000000000000 --- a/layout/base/src/nsHTMLContentSerializer.h +++ /dev/null @@ -1,114 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsHTMLContentSerializer_h__ -#define nsHTMLContentSerializer_h__ - -#include "nsXMLContentSerializer.h" -#include "nsIParserService.h" -#include "nsIEntityConverter.h" - -class nsIContent; -class nsIAtom; - -class nsHTMLContentSerializer : public nsXMLContentSerializer { - public: - nsHTMLContentSerializer(); - virtual ~nsHTMLContentSerializer(); - - NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn, - nsIAtom* aCharSet); - - NS_IMETHOD AppendText(nsIDOMText* aText, - PRInt32 aStartOffset, - PRInt32 aEndOffset, - nsAWritableString& aStr); - NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, - nsAWritableString& aStr); - - NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, - nsAWritableString& aStr); - protected: - PRBool HasDirtyAttr(nsIContent* aContent); - PRBool LineBreakBeforeOpen(nsIAtom* aName, PRBool aHasDirtyAttr); - PRBool LineBreakAfterOpen(nsIAtom* aName, PRBool aHasDirtyAttr); - PRBool LineBreakBeforeClose(nsIAtom* aName, PRBool aHasDirtyAttr); - PRBool LineBreakAfterClose(nsIAtom* aName, PRBool aHasDirtyAttr); - void StartIndentation(nsIAtom* aName, - PRBool aHasDirtyAttr, - nsAWritableString& aStr); - void EndIndentation(nsIAtom* aName, - PRBool aHasDirtyAttr, - nsAWritableString& aStr); - nsresult GetEntityConverter(nsIEntityConverter** aConverter); - nsresult GetParserService(nsIParserService** aParserService); - void SerializeAttributes(nsIContent* aContent, - nsIAtom* aTagName, - nsAWritableString& aStr); - virtual void AppendToString(const PRUnichar* aStr, - PRInt32 aLength, - nsAWritableString& aOutputStr); - virtual void AppendToString(const PRUnichar aChar, - nsAWritableString& aOutputStr); - virtual void AppendToString(const nsAReadableString& aStr, - nsAWritableString& aOutputStr, - PRBool aTranslateEntities = PR_FALSE, - PRBool aIncrColumn = PR_TRUE); - virtual void AppendToStringWrapped(const nsAReadableString& aStr, - nsAWritableString& aOutputStr, - PRBool aTranslateEntities); - PRBool HasLongLines(const nsString& text, PRInt32& aLastNewlineOffset); - - nsCOMPtr mParserService; - nsCOMPtr mEntityConverter; - - PRInt32 mIndent; - PRInt32 mColPos; - PRBool mInBody; - PRUint32 mFlags; - - PRBool mDoFormat; - PRBool mDoHeader; - PRBool mBodyOnly; - PRInt32 mPreLevel; - - /* - * mInCDATA is set to PR_TRUE while the serializer is serializing - * the content of a element whose content is considerd CDATA by the - * serializer (such elements are 'script', 'style', 'noscript' and - * possibly others) This doesn't have anything to do with if the - * element is defined as CDATA in the DTD, it simply means we'll - * output the content of the element without doing any entity encoding - * what so ever. - */ - PRBool mInCDATA; - - PRInt32 mMaxColumn; - - nsString mLineBreak; - - PRBool mIsLatin1; -}; - -extern nsresult NS_NewHTMLContentSerializer(nsIContentSerializer** aSerializer); - -#endif diff --git a/layout/base/src/nsNameSpaceManager.cpp b/layout/base/src/nsNameSpaceManager.cpp deleted file mode 100644 index 9f1838615324..000000000000 --- a/layout/base/src/nsNameSpaceManager.cpp +++ /dev/null @@ -1,432 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ -#include "nsINameSpaceManager.h" -#include "nsINameSpace.h" -#include "nsHashtable.h" -#include "nsVoidArray.h" -#include "nsLayoutAtoms.h" -#include "nsString.h" -#include "nsCRT.h" - - - -static const char kXMLNSNameSpaceURI[] = "http://www.w3.org/2000/xmlns"; -static const char kXMLNameSpaceURI[] = "http://www.w3.org/XML/1998/namespace"; -static const char kHTMLNameSpaceURI[] = "http://www.w3.org/TR/REC-html40"; // XXX?? "urn:w3-org-ns:HTML"?? -// XXX To be removed: Bug 7834 --- -static const char kXHTMLNameSpaceURI[] = "http://www.w3.org/1999/xhtml"; -static const char kXLinkNameSpaceURI[] = "http://www.w3.org/1999/xlink"; - -//----------------------------------------------------------- -// Name Space ID table support - -static PRInt32 gNameSpaceTableRefs; -static nsHashtable* gURIToIDTable; -static nsVoidArray* gURIArray; - -static void AddRefTable() -{ - if (0 == gNameSpaceTableRefs++) { - NS_ASSERTION(nsnull == gURIToIDTable, "already have URI table"); - NS_ASSERTION(nsnull == gURIArray, "already have URI array"); - - gURIToIDTable = new nsHashtable(); - gURIArray = new nsVoidArray(); - - nsString* xmlns = new nsString( NS_ConvertToString(kXMLNSNameSpaceURI) ); - nsString* xml = new nsString( NS_ConvertToString(kXMLNameSpaceURI) ); - nsString* xhtml = new nsString( NS_ConvertToString(kXHTMLNameSpaceURI) ); - nsString* xlink = new nsString( NS_ConvertToString(kXLinkNameSpaceURI) ); - nsString* html = new nsString( NS_ConvertToString(kHTMLNameSpaceURI) ); - gURIArray->AppendElement(xmlns); // ordering here needs to match IDs - gURIArray->AppendElement(xml); - gURIArray->AppendElement(xhtml); - gURIArray->AppendElement(xlink); - gURIArray->AppendElement(html); - nsStringKey xmlnsKey(*xmlns); - nsStringKey xmlKey(*xml); - nsStringKey xhtmlKey(*xhtml); - nsStringKey xlinkKey(*xlink); - nsStringKey htmlKey(*html); - gURIToIDTable->Put(&xmlnsKey, (void*)kNameSpaceID_XMLNS); - gURIToIDTable->Put(&xmlKey, (void*)kNameSpaceID_XML); - gURIToIDTable->Put(&xhtmlKey, (void*)kNameSpaceID_HTML); - gURIToIDTable->Put(&xlinkKey, (void*)kNameSpaceID_XLink); - gURIToIDTable->Put(&htmlKey, (void*)kNameSpaceID_HTML); - } - NS_ASSERTION(nsnull != gURIToIDTable, "no URI table"); - NS_ASSERTION(nsnull != gURIArray, "no URI array"); -} - -static void ReleaseTable() -{ - if (0 == --gNameSpaceTableRefs) { - delete gURIToIDTable; - PRInt32 index = gURIArray->Count(); - while (0 < index--) { - nsString* str = (nsString*)gURIArray->ElementAt(index); - delete str; - } - delete gURIArray; - gURIToIDTable = nsnull; - gURIArray = nsnull; - } -} - -static PRInt32 FindNameSpaceID(const nsAReadableString& aURI) -{ - NS_ASSERTION(nsnull != gURIToIDTable, "no URI table"); - nsStringKey key(aURI); - void* value = gURIToIDTable->Get(&key); - if (nsnull != value) { - return PRInt32(value); - } - return kNameSpaceID_Unknown; -} - -static const nsString* FindNameSpaceURI(PRInt32 aID) -{ - NS_ASSERTION(nsnull != gURIArray, "no URI array"); - return (const nsString*)gURIArray->ElementAt(aID - 1); -} - -//----------------------------------------------------------- -// Name Space - -class NameSpaceImpl : public nsINameSpace { -public: - NameSpaceImpl(nsINameSpaceManager* aManager, - NameSpaceImpl* aParent, - nsIAtom* aPrefix, - const nsAReadableString& aURI); - NameSpaceImpl(nsINameSpaceManager* aManager, - NameSpaceImpl* aParent, - nsIAtom* aPrefix, - PRInt32 aNameSpaceID); - virtual ~NameSpaceImpl(); - - NS_DECL_ISUPPORTS - - NS_IMETHOD GetNameSpaceManager(nsINameSpaceManager*& aManager) const; - - NS_IMETHOD GetNameSpaceID(PRInt32& aID) const; - NS_IMETHOD GetNameSpaceURI(nsAWritableString& aURI) const; - NS_IMETHOD GetNameSpacePrefix(nsIAtom*& aPrefix) const; - - NS_IMETHOD GetParentNameSpace(nsINameSpace*& aParent) const; - - NS_IMETHOD FindNameSpace(nsIAtom* aPrefix, nsINameSpace*& aNameSpace) const; - NS_IMETHOD FindNameSpaceID(nsIAtom* aPrefix, PRInt32& aNameSpaceID) const; - NS_IMETHOD FindNameSpacePrefix(PRInt32 aNameSpaceID, nsIAtom*& aPrefix) const; - - NS_IMETHOD CreateChildNameSpace(nsIAtom* aPrefix, const nsAReadableString& aURI, - nsINameSpace*& aChildNameSpace); - NS_IMETHOD CreateChildNameSpace(nsIAtom* aPrefix, PRInt32 aNameSpaceID, - nsINameSpace*& aChildNameSpace); - -private: - // These are not supported and are not implemented! - NameSpaceImpl(const NameSpaceImpl& aCopy); - NameSpaceImpl& operator=(const NameSpaceImpl& aCopy); - -public: - nsINameSpaceManager* mManager; - NameSpaceImpl* mParent; - nsIAtom* mPrefix; - PRInt32 mID; -}; - -NameSpaceImpl::NameSpaceImpl(nsINameSpaceManager* aManager, - NameSpaceImpl* aParent, - nsIAtom* aPrefix, - const nsAReadableString& aURI) - : mManager(aManager), - mParent(aParent), - mPrefix(aPrefix) -{ - NS_ASSERTION(nsnull != aManager, "null namespace manager"); - NS_INIT_REFCNT(); - NS_ADDREF(mManager); - NS_IF_ADDREF(mParent); - NS_IF_ADDREF(mPrefix); - mManager->RegisterNameSpace(aURI, mID); -} - -NameSpaceImpl::NameSpaceImpl(nsINameSpaceManager* aManager, - NameSpaceImpl* aParent, - nsIAtom* aPrefix, - PRInt32 aNameSpaceID) - : mManager(aManager), - mParent(aParent), - mPrefix(aPrefix), - mID(aNameSpaceID) -{ - NS_ASSERTION(nsnull != aManager, "null namespace manager"); - NS_INIT_REFCNT(); - NS_ADDREF(mManager); - NS_IF_ADDREF(mParent); - NS_IF_ADDREF(mPrefix); -} - -NameSpaceImpl::~NameSpaceImpl() -{ - NS_RELEASE(mManager); - NS_IF_RELEASE(mParent); - NS_IF_RELEASE(mPrefix); -} - -NS_IMPL_ISUPPORTS(NameSpaceImpl, NS_GET_IID(nsINameSpace)) - -NS_IMETHODIMP -NameSpaceImpl::GetNameSpaceManager(nsINameSpaceManager*& aManager) const -{ - NS_ASSERTION(nsnull != aManager, "null namespace manager"); - aManager = mManager; - NS_ADDREF(aManager); - return NS_OK; -} - -NS_IMETHODIMP -NameSpaceImpl::GetNameSpaceID(PRInt32& aID) const -{ - aID = mID; - return NS_OK; -} - -NS_IMETHODIMP -NameSpaceImpl::GetNameSpaceURI(nsAWritableString& aURI) const -{ - NS_ASSERTION(nsnull != mManager, "null namespace manager"); - return mManager->GetNameSpaceURI(mID, aURI); -} - -NS_IMETHODIMP -NameSpaceImpl::GetNameSpacePrefix(nsIAtom*& aPrefix) const -{ - aPrefix = mPrefix; - NS_IF_ADDREF(aPrefix); - return NS_OK; -} - -NS_IMETHODIMP -NameSpaceImpl::GetParentNameSpace(nsINameSpace*& aParent) const -{ - aParent = mParent; - NS_IF_ADDREF(aParent); - return NS_OK; -} - -NS_IMETHODIMP -NameSpaceImpl::FindNameSpace(nsIAtom* aPrefix, nsINameSpace*& aNameSpace) const -{ - const NameSpaceImpl* nameSpace = this; - do { - if (aPrefix == nameSpace->mPrefix) { - aNameSpace = (nsINameSpace*)nameSpace; - NS_ADDREF(aNameSpace); - return NS_OK; - } - nameSpace = nameSpace->mParent; - } - while (nsnull != nameSpace); - aNameSpace = nsnull; - return NS_ERROR_ILLEGAL_VALUE; -} - -NS_IMETHODIMP -NameSpaceImpl::FindNameSpaceID(nsIAtom* aPrefix, PRInt32& aNameSpaceID) const -{ - const NameSpaceImpl* nameSpace = this; - do { - if (aPrefix == nameSpace->mPrefix) { - aNameSpaceID = nameSpace->mID; - return NS_OK; - } - nameSpace = nameSpace->mParent; - } while (nsnull != nameSpace); - - if (nsnull == aPrefix) { - aNameSpaceID = kNameSpaceID_None; - } - else { - aNameSpaceID = kNameSpaceID_Unknown; - } - return NS_ERROR_ILLEGAL_VALUE; -} - -NS_IMETHODIMP -NameSpaceImpl::FindNameSpacePrefix(PRInt32 aNameSpaceID, nsIAtom*& aPrefix) const -{ - const NameSpaceImpl* nameSpace = this; - do { - if (aNameSpaceID == nameSpace->mID) { - aPrefix = nameSpace->mPrefix; - NS_IF_ADDREF(aPrefix); - return NS_OK; - } - nameSpace = nameSpace->mParent; - } - while (nsnull != nameSpace); - aPrefix = nsnull; - return NS_ERROR_ILLEGAL_VALUE; -} - -NS_IMETHODIMP -NameSpaceImpl::CreateChildNameSpace(nsIAtom* aPrefix, const nsAReadableString& aURI, - nsINameSpace*& aChildNameSpace) -{ - NameSpaceImpl* child = new NameSpaceImpl(mManager, this, aPrefix, aURI); - - if (child) { - return child->QueryInterface(NS_GET_IID(nsINameSpace), (void**)&aChildNameSpace); - } - aChildNameSpace = nsnull; - return NS_ERROR_OUT_OF_MEMORY; -} - -NS_IMETHODIMP -NameSpaceImpl::CreateChildNameSpace(nsIAtom* aPrefix, PRInt32 aNameSpaceID, - nsINameSpace*& aChildNameSpace) -{ - if (FindNameSpaceURI(aNameSpaceID)) { - NameSpaceImpl* child = new NameSpaceImpl(mManager, this, aPrefix, aNameSpaceID); - - if (child) { - return child->QueryInterface(NS_GET_IID(nsINameSpace), (void**)&aChildNameSpace); - } - aChildNameSpace = nsnull; - return NS_ERROR_OUT_OF_MEMORY; - } - aChildNameSpace = nsnull; - return NS_ERROR_ILLEGAL_VALUE; -} - -//----------------------------------------------------------- -// Name Space Manager - -class NameSpaceManagerImpl : public nsINameSpaceManager { -public: - NameSpaceManagerImpl(); - - NS_DECL_ISUPPORTS - - NS_IMETHOD CreateRootNameSpace(nsINameSpace*& aRootNameSpace); - - NS_IMETHOD RegisterNameSpace(const nsAReadableString& aURI, - PRInt32& aNameSpaceID); - - NS_IMETHOD GetNameSpaceURI(PRInt32 aNameSpaceID, nsAWritableString& aURI); - NS_IMETHOD GetNameSpaceID(const nsAReadableString& aURI, PRInt32& aNameSpaceID); - -private: - // These are not supported and are not implemented! - NameSpaceManagerImpl(const NameSpaceManagerImpl& aCopy); - NameSpaceManagerImpl& operator=(const NameSpaceManagerImpl& aCopy); - -protected: - virtual ~NameSpaceManagerImpl(); - -}; - -NameSpaceManagerImpl::NameSpaceManagerImpl() -{ - NS_INIT_REFCNT(); - AddRefTable(); -} - -NameSpaceManagerImpl::~NameSpaceManagerImpl() -{ - ReleaseTable(); -} - -NS_IMPL_ISUPPORTS(NameSpaceManagerImpl, NS_GET_IID(nsINameSpaceManager)) - -NS_IMETHODIMP -NameSpaceManagerImpl::CreateRootNameSpace(nsINameSpace*& aRootNameSpace) -{ - nsresult rv = NS_ERROR_OUT_OF_MEMORY; - aRootNameSpace = nsnull; - - NameSpaceImpl* xmlns = new NameSpaceImpl(this, nsnull, nsLayoutAtoms::xmlnsNameSpace, kNameSpaceID_XMLNS); - if (nsnull != xmlns) { - NameSpaceImpl* xml = new NameSpaceImpl(this, xmlns, nsLayoutAtoms::xmlNameSpace, kNameSpaceID_XML); - if (nsnull != xml) { - rv = xml->QueryInterface(NS_GET_IID(nsINameSpace), (void**)&aRootNameSpace); - } - else { - delete xmlns; - } - } - return rv; -} - -NS_IMETHODIMP -NameSpaceManagerImpl::RegisterNameSpace(const nsAReadableString& aURI, - PRInt32& aNameSpaceID) -{ - PRInt32 id = FindNameSpaceID(aURI); - - if (kNameSpaceID_Unknown == id) { - nsString* uri = new nsString(aURI); - gURIArray->AppendElement(uri); - id = gURIArray->Count(); // id is index + 1 - nsStringKey key(*uri); - gURIToIDTable->Put(&key, (void*)id); - } - aNameSpaceID = id; - return NS_OK; -} - -NS_IMETHODIMP -NameSpaceManagerImpl::GetNameSpaceURI(PRInt32 aNameSpaceID, nsAWritableString& aURI) -{ - const nsString* result = FindNameSpaceURI(aNameSpaceID); - if (nsnull != result) { - aURI = *result; - return NS_OK; - } - aURI.Truncate(); - return NS_ERROR_ILLEGAL_VALUE; -} - -NS_IMETHODIMP -NameSpaceManagerImpl::GetNameSpaceID(const nsAReadableString& aURI, PRInt32& aNameSpaceID) -{ - aNameSpaceID = FindNameSpaceID(aURI); - return NS_OK; -} - -NS_LAYOUT nsresult -NS_NewNameSpaceManager(nsINameSpaceManager** aInstancePtrResult) -{ - if (aInstancePtrResult == nsnull) { - return NS_ERROR_NULL_POINTER; - } - - NameSpaceManagerImpl *it = new NameSpaceManagerImpl(); - - if (nsnull == it) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return it->QueryInterface(NS_GET_IID(nsINameSpaceManager), (void **) aInstancePtrResult); -} diff --git a/layout/base/src/nsNodeInfo.cpp b/layout/base/src/nsNodeInfo.cpp deleted file mode 100644 index bae5d9c904d2..000000000000 --- a/layout/base/src/nsNodeInfo.cpp +++ /dev/null @@ -1,439 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsNodeInfo.h" -#include "nsNodeInfoManager.h" -#include "nsCOMPtr.h" -#include "nsString.h" -#include "nsIAtom.h" -#include "nsINameSpaceManager.h" - - -nsNodeInfo::nsNodeInfo() - : mInner(), mOwnerManager(nsnull) -{ - NS_INIT_REFCNT(); -} - - -nsNodeInfo::~nsNodeInfo() -{ - if (mOwnerManager) { - mOwnerManager->RemoveNodeInfo(this); - NS_RELEASE(mOwnerManager); - } - - NS_IF_RELEASE(mInner.mName); - NS_IF_RELEASE(mInner.mPrefix); -} - - -nsresult -nsNodeInfo::Init(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID, - nsNodeInfoManager *aOwnerManager) -{ - NS_ENSURE_TRUE(!mInner.mName && !mInner.mPrefix && !mOwnerManager, - NS_ERROR_ALREADY_INITIALIZED); - NS_ENSURE_ARG_POINTER(aName); - NS_ENSURE_ARG_POINTER(aOwnerManager); - - mInner.mName = aName; - NS_ADDREF(mInner.mName); - - mInner.mPrefix = aPrefix; - NS_IF_ADDREF(mInner.mPrefix); - - mInner.mNamespaceID = aNamespaceID; - - mOwnerManager = aOwnerManager; - NS_ADDREF(mOwnerManager); - - return NS_OK; -} - - -// nsISupports - -NS_IMPL_THREADSAFE_ISUPPORTS(nsNodeInfo, NS_GET_IID(nsINodeInfo)); - - -// nsINodeInfo - -NS_IMETHODIMP -nsNodeInfo::GetName(nsAWritableString& aName) -{ - NS_ENSURE_TRUE(mInner.mName, NS_ERROR_NOT_INITIALIZED); - - return mInner.mName->ToString(aName); -} - - -NS_IMETHODIMP -nsNodeInfo::GetNameAtom(nsIAtom*& aAtom) -{ - NS_ABORT_IF_FALSE(mInner.mName, "nsNodeInfo not initialized!"); - - aAtom = mInner.mName; - NS_IF_ADDREF(aAtom); - - return NS_OK; -} - - -NS_IMETHODIMP -nsNodeInfo::GetQualifiedName(nsAWritableString& aQualifiedName) -{ - NS_ENSURE_TRUE(mInner.mName, NS_ERROR_NOT_INITIALIZED); - - if (mInner.mPrefix) { - mInner.mPrefix->ToString(aQualifiedName); - - aQualifiedName.Append(PRUnichar(':')); - } - - const PRUnichar *name; - mInner.mName->GetUnicode(&name); - - aQualifiedName.Append(name); - - return NS_OK; -} - - -NS_IMETHODIMP -nsNodeInfo::GetLocalName(nsAWritableString& aLocalName) -{ - NS_ENSURE_TRUE(mInner.mName, NS_ERROR_NOT_INITIALIZED); - -#ifdef STRICT_DOM_LEVEL2_LOCALNAME - if (mInner.mNamespaceID > 0) { - return mInner.mName->ToString(aLocalName); - } - - aLocalName.Truncate(); - - return NS_OK; -#else - return mInner.mName->ToString(aLocalName); -#endif -} - - -NS_IMETHODIMP -nsNodeInfo::GetPrefix(nsAWritableString& aPrefix) -{ - if (mInner.mPrefix) { - mInner.mPrefix->ToString(aPrefix); - } else { - aPrefix.Truncate(); - } - - return NS_OK; -} - - -NS_IMETHODIMP -nsNodeInfo::GetPrefixAtom(nsIAtom*& aAtom) -{ - aAtom = mInner.mPrefix; - NS_IF_ADDREF(aAtom); - - return NS_OK; -} - - -NS_IMETHODIMP -nsNodeInfo::GetNamespaceURI(nsAWritableString& aNameSpaceURI) -{ - NS_ENSURE_TRUE(mOwnerManager, NS_ERROR_NOT_INITIALIZED); - nsresult rv = NS_OK; - - if (mInner.mNamespaceID > 0) { - nsCOMPtr nsm; - - mOwnerManager->GetNamespaceManager(*getter_AddRefs(nsm)); - NS_ENSURE_TRUE(nsm, NS_ERROR_NOT_INITIALIZED); - - rv = nsm->GetNameSpaceURI(mInner.mNamespaceID, aNameSpaceURI); - } else { - aNameSpaceURI.Truncate(); - } - - return rv; -} - - -NS_IMETHODIMP -nsNodeInfo::GetNamespaceID(PRInt32& aResult) -{ - aResult = mInner.mNamespaceID; - - return NS_OK; -} - - -NS_IMETHODIMP -nsNodeInfo::GetIDAttributeAtom(nsIAtom** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - *aResult = mInner.mIDAttributeAtom; - NS_IF_ADDREF(*aResult); - - return NS_OK; -} - -NS_IMETHODIMP -nsNodeInfo::SetIDAttributeAtom(nsIAtom* aID) -{ - NS_ENSURE_ARG(aID); - mInner.mIDAttributeAtom = aID; - - return NS_OK; -} - - - -NS_IMETHODIMP -nsNodeInfo::GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) -{ - NS_ENSURE_TRUE(mOwnerManager, NS_ERROR_NOT_INITIALIZED); - - aNodeInfoManager = mOwnerManager; - - NS_ADDREF(aNodeInfoManager); - - return NS_OK; -} - - -NS_IMETHODIMP_(PRBool) -nsNodeInfo::Equals(nsINodeInfo *aNodeInfo) -{ - NS_ENSURE_ARG_POINTER(aNodeInfo); - - return aNodeInfo->Equals(mInner.mName, mInner.mPrefix, mInner.mNamespaceID); -} - - -NS_IMETHODIMP_(PRBool) -nsNodeInfo::Equals(nsIAtom *aNameAtom) -{ - return mInner.mName == aNameAtom; -} - - -NS_IMETHODIMP_(PRBool) -nsNodeInfo::Equals(const nsAReadableString& aName) -{ - if (!mInner.mName) return PR_FALSE; - - const PRUnichar *name; - mInner.mName->GetUnicode(&name); - - return aName.Equals(name); -} - - -NS_IMETHODIMP_(PRBool) -nsNodeInfo::Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom) -{ - return (mInner.mName == aNameAtom) && (mInner.mPrefix == aPrefixAtom); -} - - -NS_IMETHODIMP_(PRBool) -nsNodeInfo::Equals(const nsAReadableString& aName, const nsAReadableString& aPrefix) -{ - if (!mInner.mName) return PR_FALSE; - - const PRUnichar *name, *prefix = nsnull; - mInner.mName->GetUnicode(&name); - - if (mInner.mPrefix) - mInner.mPrefix->GetUnicode(&prefix); - - return aName.Equals(name) && aPrefix.Equals(prefix); -} - - -NS_IMETHODIMP_(PRBool) -nsNodeInfo::Equals(nsIAtom *aNameAtom, PRInt32 aNamespaceID) -{ - return (mInner.mName == aNameAtom) && (mInner.mNamespaceID == aNamespaceID); -} - - -NS_IMETHODIMP_(PRBool) -nsNodeInfo::Equals(const nsAReadableString& aName, PRInt32 aNamespaceID) -{ - if (!mInner.mName) return PR_FALSE; - - const PRUnichar *name; - mInner.mName->GetUnicode(&name); - - return aName.Equals(name) && (mInner.mNamespaceID == aNamespaceID); -} - - -NS_IMETHODIMP_(PRBool) -nsNodeInfo::Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom, - PRInt32 aNamespaceID) -{ - return (mInner.mName == aNameAtom) && - (mInner.mPrefix == aPrefixAtom) && - (mInner.mNamespaceID == aNamespaceID); -} - - -NS_IMETHODIMP_(PRBool) -nsNodeInfo::Equals(const nsAReadableString& aName, const nsAReadableString& aPrefix, - PRInt32 aNamespaceID) -{ - if (!mInner.mName) return PR_FALSE; - - const PRUnichar *name, *prefix = nsnull; - mInner.mName->GetUnicode(&name); - - if (mInner.mPrefix) - mInner.mPrefix->GetUnicode(&prefix); - - return aName.Equals(name) && aPrefix.Equals(prefix) && - (mInner.mNamespaceID == aNamespaceID); -} - - -NS_IMETHODIMP_(PRBool) -nsNodeInfo::NamespaceEquals(PRInt32 aNamespaceID) -{ - return mInner.mNamespaceID == aNamespaceID; -} - - -NS_IMETHODIMP_(PRBool) -nsNodeInfo::NamespaceEquals(const nsAReadableString& aNamespaceURI) -{ - NS_ENSURE_TRUE(mOwnerManager, NS_ERROR_NOT_INITIALIZED); - nsCOMPtr nsmgr; - - NS_ENSURE_SUCCESS(mOwnerManager->GetNamespaceManager(*getter_AddRefs(nsmgr)), - NS_ERROR_NOT_INITIALIZED); - - PRInt32 nsid; - nsmgr->GetNameSpaceID(aNamespaceURI, nsid); - - return mInner.mNamespaceID == nsid; -} - - -NS_IMETHODIMP_(PRBool) -nsNodeInfo::QualifiedNameEquals(const nsAReadableString& aQualifiedName) -{ - nsPromiseFlatString flatName(aQualifiedName); - const PRUnichar *qname = flatName.get(); - PRUint32 i = 0; - - if (mInner.mPrefix) { - const PRUnichar *prefix; - mInner.mPrefix->GetUnicode(&prefix); - - i = nsCRT::strlen(prefix); - - if (nsCRT::strncmp(qname, prefix, i)) - return PR_FALSE; - - if (*(qname + i) != PRUnichar(':')) - return PR_FALSE; - - i++; - } - - const PRUnichar *name; - mInner.mName->GetUnicode(&name); - - if (nsCRT::strcmp(qname + i, name)) - return PR_FALSE; - - return PR_TRUE; -} - -NS_IMETHODIMP -nsNodeInfo::NameChanged(nsIAtom *aName, nsINodeInfo*& aResult) -{ - NS_ENSURE_TRUE(mOwnerManager, NS_ERROR_NOT_INITIALIZED); - - return mOwnerManager->GetNodeInfo(aName, mInner.mPrefix, mInner.mNamespaceID, - aResult); -} - - -NS_IMETHODIMP -nsNodeInfo::PrefixChanged(nsIAtom *aPrefix, nsINodeInfo*& aResult) -{ - NS_ENSURE_TRUE(mOwnerManager, NS_ERROR_NOT_INITIALIZED); - - return mOwnerManager->GetNodeInfo(mInner.mName, aPrefix, mInner.mNamespaceID, - aResult); -} - - -PLHashNumber -nsNodeInfoInner::GetHashValue(const void *key) -{ -#ifdef NS_DEBUG // Just to shut down a compiler warning - NS_WARN_IF_FALSE(key, "Null key passed to nsNodeInfo::GetHashValue!"); -#endif - - if (key) { - const nsNodeInfoInner *node = (const nsNodeInfoInner *)key; - - // Is this an acceptable has value? - return (((PLHashNumber)node->mName) & 0xffff) >> 8; - } - - return 0; -} - - -PRIntn -nsNodeInfoInner::KeyCompare(const void *key1, const void *key2) -{ -#ifdef NS_DEBUG // Just to shut down a compiler warning - NS_WARN_IF_FALSE(key1 && key2, "Null key passed to nsNodeInfo::KeyCompare!"); -#endif - - if (!key1 || !key2) { - return PR_FALSE; - } - - const nsNodeInfoInner *node1 = (const nsNodeInfoInner *)key1; - const nsNodeInfoInner *node2 = (const nsNodeInfoInner *)key2; - - if (node1->mName == node2->mName && - node1->mPrefix == node2->mPrefix && - node1->mNamespaceID == node2->mNamespaceID) { - - return PR_TRUE; - } - - return PR_FALSE; -} - diff --git a/layout/base/src/nsNodeInfo.h b/layout/base/src/nsNodeInfo.h deleted file mode 100644 index e6fdff127247..000000000000 --- a/layout/base/src/nsNodeInfo.h +++ /dev/null @@ -1,124 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsNodeInfo_h___ -#define nsNodeInfo_h___ - -#include "nsINodeInfo.h" -#include "nsINameSpaceManager.h" -#include "plhash.h" -#include "nsIAtom.h" -#include "nsCOMPtr.h" - -/* - * nsNodeInfoInner is used for two things: - * - * 1. as a member in nsNodeInfo for holding the name, prefix and - * namespace ID - * 2. as the hash key in the hash table in nsNodeInfoManager - * - * nsNodeInfoInner does not do any kind of reference counting, that's up - * to the user of this class, since nsNodeInfoInner is a member of - * nsNodeInfo the hash table doesn't need to delete the keys, when the - * value (nsNodeInfo) the key is automatically deleted. - */ - -struct nsNodeInfoInner -{ - nsNodeInfoInner(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID) - : mName(aName), mPrefix(aPrefix), mNamespaceID(aNamespaceID) { } - - nsNodeInfoInner() - : mName(nsnull), mPrefix(nsnull), mNamespaceID(kNameSpaceID_None) { } - - static PRIntn PR_CALLBACK KeyCompare(const void *key1, const void *key2); - static PLHashNumber PR_CALLBACK GetHashValue(const void *key); - - nsIAtom* mName; - nsIAtom* mPrefix; - PRInt32 mNamespaceID; - nsCOMPtr mIDAttributeAtom; -}; - - -class nsNodeInfoManager; - -class nsNodeInfo : public nsINodeInfo -{ -public: - NS_DECL_ISUPPORTS - - // nsINodeInfo - NS_IMETHOD GetName(nsAWritableString& aName); - NS_IMETHOD GetNameAtom(nsIAtom*& aAtom); - NS_IMETHOD GetQualifiedName(nsAWritableString& aQualifiedName); - NS_IMETHOD GetLocalName(nsAWritableString& aLocalName); - NS_IMETHOD GetPrefix(nsAWritableString& aPrefix); - NS_IMETHOD GetPrefixAtom(nsIAtom*& aAtom); - NS_IMETHOD GetNamespaceURI(nsAWritableString& aNameSpaceURI); - NS_IMETHOD GetNamespaceID(PRInt32& aResult); - NS_IMETHOD GetIDAttributeAtom(nsIAtom** aResult); - NS_IMETHOD SetIDAttributeAtom(nsIAtom* aResult); - NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager); - NS_IMETHOD_(PRBool) Equals(nsINodeInfo *aNodeInfo); - NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom); - NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName); - - NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom); - NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName, - const nsAReadableString& aPrefix); - NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom, PRInt32 aNamespaceID); - NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName, PRInt32 aNamespaceID); - NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom, nsIAtom *aPrefixAtom, - PRInt32 aNamespaceID); - NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName, const nsAReadableString& aPrefix, - PRInt32 aNamespaceID); - NS_IMETHOD_(PRBool) NamespaceEquals(PRInt32 aNamespaceID); - NS_IMETHOD_(PRBool) NamespaceEquals(const nsAReadableString& aNamespaceURI); - NS_IMETHOD_(PRBool) QualifiedNameEquals(const nsAReadableString& aQualifiedName); - - NS_IMETHOD NameChanged(nsIAtom *aName, nsINodeInfo*& aResult); - NS_IMETHOD PrefixChanged(nsIAtom *aPrefix, nsINodeInfo*& aResult); - - // nsNodeInfo - nsNodeInfo(); - virtual ~nsNodeInfo(); - - /* - * Note! Init() must be called exactly once on every nsNodeInfo before - * the object is used, if Init() returns an error code the nsNodeInfo - * should not be used. - * - * aName and aOwnerManager may not be null. - */ - nsresult Init(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID, - nsNodeInfoManager *aOwnerManager); - -protected: - friend class nsNodeInfoManager; // The NodeInfoManager needs to pass this - // to the hash table. - nsNodeInfoInner mInner; - - nsNodeInfoManager* mOwnerManager; // Strong reference! -}; - -#endif /* nsNodeInfo_h___ */ diff --git a/layout/base/src/nsNodeInfoManager.cpp b/layout/base/src/nsNodeInfoManager.cpp deleted file mode 100644 index 392dc58ebdce..000000000000 --- a/layout/base/src/nsNodeInfoManager.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#include "nsNodeInfoManager.h" -#include "nsNodeInfo.h" -#include "nsCOMPtr.h" -#include "nsString.h" -#include "nsIAtom.h" - -nsNodeInfoManager* nsNodeInfoManager::gAnonymousNodeInfoManager = nsnull; -PRUint32 nsNodeInfoManager::gNodeManagerCount = 0; - - -nsresult NS_NewNodeInfoManager(nsINodeInfoManager** aResult) -{ - NS_ENSURE_ARG_POINTER(aResult); - - *aResult = new nsNodeInfoManager; - NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY); - - NS_ADDREF(*aResult); - - return NS_OK; -} - - -nsNodeInfoManager::nsNodeInfoManager() - : mNameSpaceManager(nsnull) -{ - NS_INIT_REFCNT(); - - if (gNodeManagerCount == 1 && gAnonymousNodeInfoManager) { - /* - * If we get here the global nodeinfo manager was the first one created, - * in that case we're not holding a strong reference to the global nodeinfo - * manager. Now we're creating one more nodeinfo manager so we'll grab - * a strong reference to the global nodeinfo manager so that it's - * lifetime will be longer than the lifetime of the other node managers. - */ - NS_ADDREF(gAnonymousNodeInfoManager); - } - - gNodeManagerCount++; - - mNodeInfoHash = PL_NewHashTable(32, nsNodeInfoInner::GetHashValue, - nsNodeInfoInner::KeyCompare, - PL_CompareValues, nsnull, nsnull); - -#ifdef DEBUG_jst - printf ("Creating NodeInfoManager, gcount = %d\n", gNodeManagerCount); -#endif -} - - -nsNodeInfoManager::~nsNodeInfoManager() -{ - gNodeManagerCount--; - - if (gNodeManagerCount == 1 && gAnonymousNodeInfoManager) { - NS_RELEASE(gAnonymousNodeInfoManager); - } else if (!gNodeManagerCount) { - /* - * Here we just make sure that we don't leave a dangling pointer to - * the global nodeinfo manager after it's deleted. - */ - gAnonymousNodeInfoManager = nsnull; - } - - if (mNodeInfoHash) - PL_HashTableDestroy(mNodeInfoHash); - -#ifdef DEBUG_jst - printf ("Removing NodeInfoManager, gcount = %d\n", gNodeManagerCount); -#endif -} - - -NS_IMPL_THREADSAFE_ISUPPORTS(nsNodeInfoManager, - NS_GET_IID(nsINodeInfoManager)); - - -// nsINodeInfoManager - -NS_IMETHODIMP -nsNodeInfoManager::Init(nsINameSpaceManager *aNameSpaceManager) -{ - NS_ENSURE_ARG_POINTER(aNameSpaceManager); - NS_ENSURE_TRUE(mNodeInfoHash, NS_ERROR_OUT_OF_MEMORY); - - mNameSpaceManager = aNameSpaceManager; - - return NS_OK; -} - - -NS_IMETHODIMP -nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, - PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo) -{ - NS_ENSURE_ARG_POINTER(aName); - - nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID); - - void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey); - - if (node) { - aNodeInfo = NS_STATIC_CAST(nsINodeInfo *, node); - - NS_ADDREF(aNodeInfo); - - return NS_OK; - } - - nsNodeInfo *newNodeInfo = new nsNodeInfo(); - NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY); - - NS_ADDREF(newNodeInfo); - - nsresult rv = newNodeInfo->Init(aName, aPrefix, aNamespaceID, this); - NS_ENSURE_SUCCESS(rv, rv); - - PLHashEntry *he; - he = PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo); - NS_ENSURE_TRUE(he, NS_ERROR_OUT_OF_MEMORY); - - aNodeInfo = newNodeInfo; - - return NS_OK; -} - - -NS_IMETHODIMP -nsNodeInfoManager::GetNodeInfo(const nsAReadableString& aName, nsIAtom *aPrefix, - PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo) -{ - NS_ENSURE_ARG(aName.Length()); - - nsCOMPtr name(dont_AddRef(NS_NewAtom(aName))); - NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY); - - return GetNodeInfo(name, aPrefix, aNamespaceID, aNodeInfo); -} - - -NS_IMETHODIMP -nsNodeInfoManager::GetNodeInfo(const nsAReadableString& aName, const nsAReadableString& aPrefix, - PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo) -{ - NS_ENSURE_ARG(aName.Length()); - - nsCOMPtr name(dont_AddRef(NS_NewAtom(aName))); - NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY); - - nsCOMPtr prefix; - - if (aPrefix.Length()) { - prefix = dont_AddRef(NS_NewAtom(aPrefix)); - NS_ENSURE_TRUE(prefix, NS_ERROR_OUT_OF_MEMORY); - } - - return GetNodeInfo(name, prefix, aNamespaceID, aNodeInfo); -} - - -NS_IMETHODIMP -nsNodeInfoManager::GetNodeInfo(const nsAReadableString& aName, const nsAReadableString& aPrefix, - const nsAReadableString& aNamespaceURI, - nsINodeInfo*& aNodeInfo) -{ - NS_ENSURE_ARG(aName.Length()); - - nsCOMPtr name(dont_AddRef(NS_NewAtom(aName))); - NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY); - - nsCOMPtr prefix; - - if (aPrefix.Length()) { - prefix = dont_AddRef(NS_NewAtom(aPrefix)); - NS_ENSURE_TRUE(prefix, NS_ERROR_OUT_OF_MEMORY); - } - - PRInt32 nsid = kNameSpaceID_None; - - if (aNamespaceURI.Length()) { - if (!mNameSpaceManager) { - return NS_ERROR_NOT_INITIALIZED; - } - - nsresult rv = mNameSpaceManager->RegisterNameSpace(aNamespaceURI, nsid); - NS_ENSURE_SUCCESS(rv, rv); - } - - return GetNodeInfo(name, prefix, nsid, aNodeInfo); -} - - -NS_IMETHODIMP -nsNodeInfoManager::GetNodeInfo(const nsAReadableString& aQualifiedName, - const nsAReadableString& aNamespaceURI, - nsINodeInfo*& aNodeInfo) -{ - NS_ENSURE_ARG(aQualifiedName.Length()); - - nsAutoString name(aQualifiedName); - nsAutoString prefix; - PRInt32 nsoffset = name.FindChar(':'); - if (-1 != nsoffset) { - name.Left(prefix, nsoffset); - name.Cut(0, nsoffset+1); - } - - nsCOMPtr nameAtom(dont_AddRef(NS_NewAtom(name))); - NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY); - - nsCOMPtr prefixAtom; - - if (prefix.Length()) { - prefixAtom = dont_AddRef(NS_NewAtom(prefix)); - NS_ENSURE_TRUE(prefixAtom, NS_ERROR_OUT_OF_MEMORY); - } - - PRInt32 nsid = kNameSpaceID_None; - - if (aNamespaceURI.Length()) { - NS_ENSURE_TRUE(mNameSpaceManager, NS_ERROR_NOT_INITIALIZED); - - nsresult rv = mNameSpaceManager->RegisterNameSpace(aNamespaceURI, nsid); - NS_ENSURE_SUCCESS(rv, rv); - } - - return GetNodeInfo(nameAtom, prefixAtom, nsid, aNodeInfo); -} - - -NS_IMETHODIMP -nsNodeInfoManager::GetNamespaceManager(nsINameSpaceManager*& aNameSpaceManager) -{ - NS_ENSURE_TRUE(mNameSpaceManager, NS_ERROR_NOT_INITIALIZED); - - aNameSpaceManager = mNameSpaceManager; - NS_ADDREF(aNameSpaceManager); - - return NS_OK; -} - - -void -nsNodeInfoManager::RemoveNodeInfo(nsNodeInfo *aNodeInfo) -{ - NS_WARN_IF_FALSE(aNodeInfo, "Trying to remove null nodeinfo from manager!"); - - if (aNodeInfo) { - PRBool ret = PL_HashTableRemove(mNodeInfoHash, &aNodeInfo->mInner); - - NS_WARN_IF_FALSE(ret, "Can't find nsINodeInfo to remove!!!"); - } -} - - -nsresult -nsNodeInfoManager::GetAnonymousManager(nsINodeInfoManager*& aNodeInfoManager) -{ - if (!gAnonymousNodeInfoManager) { - gAnonymousNodeInfoManager = new nsNodeInfoManager; - - if (!gAnonymousNodeInfoManager) - return NS_ERROR_OUT_OF_MEMORY; - - NS_ADDREF(gAnonymousNodeInfoManager); - - nsresult rv = NS_NewNameSpaceManager(getter_AddRefs(gAnonymousNodeInfoManager->mNameSpaceManager)); - - if (NS_FAILED(rv)) { - NS_RELEASE(gAnonymousNodeInfoManager); - - return rv; - } - } - - aNodeInfoManager = gAnonymousNodeInfoManager; - - /* - * If the only nodeinfo manager is the global one we don't hold a ref - * since the global nodeinfo manager should be destroyed when it's released, - * even if it's the last one arround. - */ - if (gNodeManagerCount > 1) { - NS_ADDREF(aNodeInfoManager); - } - - return NS_OK; -} - diff --git a/layout/base/src/nsNodeInfoManager.h b/layout/base/src/nsNodeInfoManager.h deleted file mode 100644 index 131200be872f..000000000000 --- a/layout/base/src/nsNodeInfoManager.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ - -#ifndef nsNodeInfoManager_h___ -#define nsNodeInfoManager_h___ - -#include "nsINodeInfo.h" -#include "nsINameSpaceManager.h" -#include "nsCOMPtr.h" -#include "plhash.h" - -class nsNodeInfo; - - -class nsNodeInfoManager : public nsINodeInfoManager -{ -public: - NS_DECL_ISUPPORTS - - // nsINodeInfoManager - NS_IMETHOD Init(nsINameSpaceManager *aNameSpaceManager); - NS_IMETHOD GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, - PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo); - NS_IMETHOD GetNodeInfo(const nsAReadableString& aName, nsIAtom *aPrefix, - PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo); - NS_IMETHOD GetNodeInfo(const nsAReadableString& aName, const nsAReadableString& aPrefix, - PRInt32 aNamespaceID, nsINodeInfo*& aNodeInfo); - NS_IMETHOD GetNodeInfo(const nsAReadableString& aName, const nsAReadableString& aPrefix, - const nsAReadableString& aNamespaceURI, - nsINodeInfo*& aNodeInfo); - NS_IMETHOD GetNodeInfo(const nsAReadableString& aQualifiedName, - const nsAReadableString& aNamespaceURI, - nsINodeInfo*& aNodeInfo); - NS_IMETHOD GetNamespaceManager(nsINameSpaceManager*& aNameSpaceManager); - - // nsNodeInfoManager - nsNodeInfoManager(); - virtual ~nsNodeInfoManager(); - - void RemoveNodeInfo(nsNodeInfo *aNodeInfo); - - static nsresult GetAnonymousManager(nsINodeInfoManager*& aNodeInfoManager); - -private: - PLHashTable *mNodeInfoHash; - nsCOMPtr mNameSpaceManager; - - /* - * gAnonymousNodeInfoManager is a global nodeinfo manager used for nodes - * that are no longer part of a document and for nodes that are created - * where no document is accessible. - * - * gAnonymousNodeInfoManager is allocated when requested for the first time - * and once the last nodeinfo manager (appart from gAnonymousNodeInfoManager) - * is destroyed gAnonymousNodeInfoManager is destroyed. If the global - * nodeinfo manager is the only nodeinfo manager used it can be deleted - * and later reallocated if all users of the nodeinfo manager drops the - * referernces to it. - */ - static nsNodeInfoManager *gAnonymousNodeInfoManager; - static PRUint32 gNodeManagerCount; -}; - -#endif /* nsNodeInfoManager_h___ */ diff --git a/layout/base/src/nsPlainTextSerializer.cpp b/layout/base/src/nsPlainTextSerializer.cpp deleted file mode 100644 index bf349798f822..000000000000 --- a/layout/base/src/nsPlainTextSerializer.cpp +++ /dev/null @@ -1,1778 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Daniel Bratell - * Ben Bucksch - */ - -#include "nsPlainTextSerializer.h" -#include "nsILineBreakerFactory.h" -#include "nsLWBrkCIID.h" -#include "nsIPref.h" -#include "nsIServiceManager.h" -#include "nsHTMLAtoms.h" -#include "nsIDOMText.h" -#include "nsIDOMElement.h" -#include "nsINameSpaceManager.h" -#include "nsIHTMLContent.h" -#include "nsITextContent.h" -#include "nsTextFragment.h" -#include "nsParserCIID.h" -#include "nsLayoutUtils.h" - -static NS_DEFINE_CID(kLWBrkCID, NS_LWBRK_CID); -static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); -static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID); - -#define PREF_STRUCTS "converter.html2txt.structs" -#define PREF_HEADER_STRATEGY "converter.html2txt.header_strategy" - -static const PRInt32 kTabSize=4; -static const PRInt32 kOLNumberWidth = 3; -static const PRInt32 kIndentSizeHeaders = 2; /* Indention of h1, if - mHeaderStrategy = 1 or = 2. - Indention of other headers - is derived from that. - XXX center h1? */ -static const PRInt32 kIndentIncrementHeaders = 2; /* If mHeaderStrategy = 1, - indent h(x+1) this many - columns more than h(x) */ -static const PRInt32 kIndentSizeList = (kTabSize > kOLNumberWidth+3) ? kTabSize: kOLNumberWidth+3; - // Indention of non-first lines of ul and ol -static const PRInt32 kIndentSizeDD = kTabSize; // Indention of

- -static PRInt32 HeaderLevel(eHTMLTags aTag); -static PRInt32 GetUnicharWidth(PRUnichar ucs); -static PRInt32 GetUnicharStringWidth(const PRUnichar* pwcs, PRInt32 n); - -// Someday may want to make this non-const: -static const PRUint32 TagStackSize = 500; -static const PRUint32 OLStackSize = 100; - -nsresult NS_NewPlainTextSerializer(nsIContentSerializer** aSerializer) -{ - nsPlainTextSerializer* it = new nsPlainTextSerializer(); - if (!it) { - return NS_ERROR_OUT_OF_MEMORY; - } - - return it->QueryInterface(NS_GET_IID(nsIContentSerializer), - (void**)aSerializer); -} - -nsPlainTextSerializer::nsPlainTextSerializer() - : kSpace(NS_LITERAL_STRING(" ")) // Init of "constant" -{ - NS_INIT_ISUPPORTS(); - - mOutputString = nsnull; - mInHead = PR_FALSE; - mAtFirstColumn = PR_TRUE; - mIndent = 0; - mCiteQuoteLevel = 0; - mStructs = PR_TRUE; // will be read from prefs later - mHeaderStrategy = 1 /*indent increasingly*/; // ditto - for (PRInt32 i = 0; i <= 6; i++) { - mHeaderCounter[i] = 0; - } - - // Line breaker - mWrapColumn = 72; // XXX magic number, we expect someone to reset this - mCurrentLineWidth = 0; - - // Flow - mEmptyLines = 1; // The start of the document is an "empty line" in itself, - mInWhitespace = PR_TRUE; - mPreFormatted = PR_FALSE; - mStartedOutput = PR_FALSE; - - // initialize the tag stack to zero: - mTagStack = new nsHTMLTag[TagStackSize]; - mTagStackIndex = 0; - - // initialize the OL stack, where numbers for ordered lists are kept: - mOLStack = new PRInt32[OLStackSize]; - mOLStackIndex = 0; -} - -nsPlainTextSerializer::~nsPlainTextSerializer() -{ - delete[] mTagStack; - delete[] mOLStack; -} - -NS_IMPL_ISUPPORTS4(nsPlainTextSerializer, - nsIContentSerializer, - nsIContentSink, - nsIHTMLContentSink, - nsIHTMLToTextSink) - - -NS_IMETHODIMP -nsPlainTextSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn, - nsIAtom* aCharSet) -{ -#ifdef DEBUG - // Check if the major control flags are set correctly. - if(aFlags & nsIDocumentEncoder::OutputFormatFlowed) { - NS_ASSERTION(aFlags & nsIDocumentEncoder::OutputFormatted, - "If you want format=flowed, you must combine it with " - "nsIDocumentEncoder::OutputFormatted"); - } - - if(aFlags & nsIDocumentEncoder::OutputFormatted) { - NS_ASSERTION(!(aFlags & nsIDocumentEncoder::OutputPreformatted), - "Can't do formatted and preformatted output at the same time!"); - } -#endif - - nsresult rv; - - mFlags = aFlags; - mWrapColumn = aWrapColumn; - - // Only create a linebreaker if we will handle wrapping. - if(MayWrap()) { - NS_WITH_SERVICE(nsILineBreakerFactory, lf, kLWBrkCID, &rv); - if (NS_SUCCEEDED(rv)) { - nsAutoString lbarg; - rv = lf->GetBreaker(lbarg, getter_AddRefs(mLineBreaker)); - if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - } - } - - // Set the line break character: - if ((mFlags & nsIDocumentEncoder::OutputCRLineBreak) - && (mFlags & nsIDocumentEncoder::OutputLFLineBreak)) // Windows/mail - mLineBreak.Assign(NS_LITERAL_STRING("\r\n")); - else if (mFlags & nsIDocumentEncoder::OutputCRLineBreak) // Mac - mLineBreak.Assign(PRUnichar('\r')); - else if (mFlags & nsIDocumentEncoder::OutputLFLineBreak) // Unix/DOM - mLineBreak.Assign(PRUnichar('\n')); - else - mLineBreak.AssignWithConversion(NS_LINEBREAK); // Platform/default - - - if(mFlags & nsIDocumentEncoder::OutputFormatted) { - // Get some prefs that controls how we do formatted output - NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv) && prefs) { - prefs->GetBoolPref(PREF_STRUCTS, &mStructs); - prefs->GetIntPref(PREF_HEADER_STRATEGY, &mHeaderStrategy); - } - } - - return NS_OK; -} - -NS_IMETHODIMP -nsPlainTextSerializer::Initialize(nsAWritableString* aOutString, - PRUint32 aFlags, PRUint32 aWrapCol) -{ - nsresult rv = Init(aFlags, aWrapCol, nsnull); - NS_ENSURE_SUCCESS(rv, rv); - - // XXX This is wrong. It violates XPCOM string ownership rules. - // We're only getting away with this because instances of this - // class are restricted to single function scope. - mOutputString = aOutString; - - return NS_OK; -} - -NS_IMETHODIMP -nsPlainTextSerializer::AppendText(nsIDOMText* aText, - PRInt32 aStartOffset, - PRInt32 aEndOffset, - nsAWritableString& aStr) -{ - NS_ENSURE_ARG(aText); - - nsresult rv = NS_OK; - PRInt32 length = 0; - nsAutoString textstr; - - nsCOMPtr content = do_QueryInterface(aText); - if (!content) return NS_ERROR_FAILURE; - - const nsTextFragment* frag; - content->GetText(&frag); - - if (frag) { - length = ((aEndOffset == -1) ? frag->GetLength() : aEndOffset) - aStartOffset; - if (frag->Is2b()) { - textstr.Assign(frag->Get2b() + aStartOffset, length); - } - else { - textstr.AssignWithConversion(frag->Get1b()+aStartOffset, length); - } - } - - mOutputString = &aStr; - - nsAutoString linebuffer; - - // We have to split the string across newlines - // to match parser behavior - PRInt32 start = 0; - PRInt32 offset = textstr.FindCharInSet("\n\r"); - while (offset != kNotFound) { - - if(offset>start) { - // Pass in the line - textstr.Mid(linebuffer, start, offset-start); - rv = DoAddLeaf(eHTMLTag_text, linebuffer); - if (NS_FAILED(rv)) break; - } - - // Pass in a newline - rv = DoAddLeaf(eHTMLTag_newline, mLineBreak); - if (NS_FAILED(rv)) break; - - start = offset+1; - offset = textstr.FindCharInSet("\n\r", start); - } - - // Consume the last bit of the string if there's any left - if (NS_SUCCEEDED(rv) & (start < length)) { - if (start) { - textstr.Mid(linebuffer, start, offset-start); - rv = DoAddLeaf(eHTMLTag_text, linebuffer); - } - else { - rv = DoAddLeaf(eHTMLTag_text, textstr); - } - } - - mOutputString = nsnull; - - return rv; -} - -NS_IMETHODIMP -nsPlainTextSerializer::AppendElementStart(nsIDOMElement *aElement, - nsAWritableString& aStr) -{ - NS_ENSURE_ARG(aElement); - - mContent = do_QueryInterface(aElement); - if (!mContent) return NS_ERROR_FAILURE; - - nsresult rv; - PRInt32 id; - rv = GetIdForContent(mContent, &id); - if (NS_FAILED(rv)) return rv; - - PRBool isContainer = IsContainer(id); - - mOutputString = &aStr; - - if (isContainer) { - rv = DoOpenContainer(id); - } - else { - nsAutoString empty; - rv = DoAddLeaf(id, empty); - } - - mContent = 0; - mOutputString = nsnull; - - if (!mInHead && id == eHTMLTag_head) - mInHead = PR_TRUE; - - return rv; -} - -NS_IMETHODIMP -nsPlainTextSerializer::AppendElementEnd(nsIDOMElement *aElement, - nsAWritableString& aStr) -{ - NS_ENSURE_ARG(aElement); - - mContent = do_QueryInterface(aElement); - if (!mContent) return NS_ERROR_FAILURE; - - nsresult rv; - PRInt32 id; - rv = GetIdForContent(mContent, &id); - if (NS_FAILED(rv)) return rv; - - PRBool isContainer = IsContainer(id); - - mOutputString = &aStr; - - rv = NS_OK; - if (isContainer) { - rv = DoCloseContainer(id); - } - - mContent = 0; - mOutputString = nsnull; - - if (mInHead && id == eHTMLTag_head) - mInHead = PR_FALSE; - - return rv; -} - -NS_IMETHODIMP -nsPlainTextSerializer::Flush(nsAWritableString& aStr) -{ - mOutputString = &aStr; - FlushLine(); - mOutputString = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsPlainTextSerializer::OpenContainer(const nsIParserNode& aNode) -{ - PRInt32 type = aNode.GetNodeType(); - - mParserNode = NS_CONST_CAST(nsIParserNode *, &aNode); - return DoOpenContainer(type); -} - -NS_IMETHODIMP -nsPlainTextSerializer::CloseContainer(const nsIParserNode& aNode) -{ - PRInt32 type = aNode.GetNodeType(); - const nsAReadableString& namestr = aNode.GetText(); - nsCOMPtr name = dont_AddRef(NS_NewAtom(namestr)); - - mParserNode = NS_CONST_CAST(nsIParserNode *, &aNode); - return DoCloseContainer(type); -} - -NS_IMETHODIMP -nsPlainTextSerializer::AddLeaf(const nsIParserNode& aNode) -{ - eHTMLTags type = (eHTMLTags)aNode.GetNodeType(); - const nsAReadableString& text = aNode.GetText(); - - mParserNode = NS_CONST_CAST(nsIParserNode *, &aNode); - if ((type == eHTMLTag_text) || - (type == eHTMLTag_whitespace) || - (type == eHTMLTag_newline)) { - // Copy the text out, stripping out CRs - nsAutoString str; - PRUint32 length; - str.SetCapacity(text.Length()); - nsReadingIterator srcStart, srcEnd; - length = nsLayoutUtils::CopyNewlineNormalizedUnicodeTo(text.BeginReading(srcStart), text.EndReading(srcEnd), str); - str.SetLength(length); - return DoAddLeaf(type, str); - } - else { - return DoAddLeaf(type, text); - } -} - -NS_IMETHODIMP -nsPlainTextSerializer::OpenHTML(const nsIParserNode& aNode) -{ - return OpenContainer(aNode); -} - -NS_IMETHODIMP -nsPlainTextSerializer::CloseHTML(const nsIParserNode& aNode) -{ - return CloseContainer(aNode); -} - -NS_IMETHODIMP -nsPlainTextSerializer::OpenHead(const nsIParserNode& aNode) -{ - mInHead = PR_TRUE; - return NS_OK; -} - -NS_IMETHODIMP -nsPlainTextSerializer::CloseHead(const nsIParserNode& aNode) -{ - mInHead = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP -nsPlainTextSerializer::OpenBody(const nsIParserNode& aNode) -{ - return OpenContainer(aNode); -} - -NS_IMETHODIMP -nsPlainTextSerializer::CloseBody(const nsIParserNode& aNode) -{ - return CloseContainer(aNode); -} - -NS_IMETHODIMP -nsPlainTextSerializer::OpenForm(const nsIParserNode& aNode) -{ - return OpenContainer(aNode); -} - -NS_IMETHODIMP -nsPlainTextSerializer::CloseForm(const nsIParserNode& aNode) -{ - return CloseContainer(aNode); -} - -NS_IMETHODIMP -nsPlainTextSerializer::OpenMap(const nsIParserNode& aNode) -{ - return OpenContainer(aNode); -} - -NS_IMETHODIMP -nsPlainTextSerializer::CloseMap(const nsIParserNode& aNode) -{ - return CloseContainer(aNode); -} - -NS_IMETHODIMP -nsPlainTextSerializer::OpenFrameset(const nsIParserNode& aNode) -{ - return OpenContainer(aNode); -} - -NS_IMETHODIMP -nsPlainTextSerializer::CloseFrameset(const nsIParserNode& aNode) -{ - return CloseContainer(aNode); -} - -NS_IMETHODIMP -nsPlainTextSerializer::OpenNoscript(const nsIParserNode& aNode) -{ - return OpenContainer(aNode); -} - -NS_IMETHODIMP -nsPlainTextSerializer::CloseNoscript(const nsIParserNode& aNode) -{ - return CloseContainer(aNode); -} - -NS_IMETHODIMP -nsPlainTextSerializer::DoFragment(PRBool aFlag) -{ - return NS_OK; -} - -nsresult -nsPlainTextSerializer::DoOpenContainer(PRInt32 aTag) -{ - eHTMLTags type = (eHTMLTags)aTag; - - if (mTagStackIndex < TagStackSize) { - mTagStack[mTagStackIndex++] = type; - } - - if (type == eHTMLTag_body) { - // Try to figure out here whether we have a - // preformatted style attribute. - // - // Trigger on the presence of a "-moz-pre-wrap" in the - // style attribute. That's a very simplistic way to do - // it, but better than nothing. - // Also set mWrapColumn to the value given there - // (which arguably we should only do if told to do so). - nsAutoString style; - PRInt32 whitespace; - if(NS_SUCCEEDED(GetAttributeValue(nsHTMLAtoms::style, style)) && - (kNotFound != (whitespace = style.Find("white-space:")))) { - - if (kNotFound != style.Find("-moz-pre-wrap", PR_TRUE, whitespace)) { -#ifdef DEBUG_preformatted - printf("Set mPreFormatted based on style moz-pre-wrap\n"); -#endif - mPreFormatted = PR_TRUE; - PRInt32 widthOffset = style.Find("width:"); - if (widthOffset >= 0) { - // We have to search for the ch before the semicolon, - // not for the semicolon itself, because nsString::ToInteger() - // considers 'c' to be a valid numeric char (even if radix=10) - // but then gets confused if it sees it next to the number - // when the radix specified was 10, and returns an error code. - PRInt32 semiOffset = style.Find("ch", widthOffset+6); - PRInt32 length = (semiOffset > 0 ? semiOffset - widthOffset - 6 - : style.Length() - widthOffset); - nsAutoString widthstr; - style.Mid(widthstr, widthOffset+6, length); - PRInt32 err; - PRInt32 col = widthstr.ToInteger(&err); - - if (NS_SUCCEEDED(err)) { - mWrapColumn = (PRUint32)col; -#ifdef DEBUG_preformatted - printf("Set wrap column to %d based on style\n", mWrapColumn); -#endif - } - } - } - else if (kNotFound != style.Find("pre", PR_TRUE, whitespace)) { -#ifdef DEBUG_preformatted - printf("Set mPreFormatted based on style pre\n"); -#endif - mPreFormatted = PR_TRUE; - mWrapColumn = 0; - } - } - else { - mPreFormatted = PR_FALSE; - } - - return NS_OK; - } - - if (!DoOutput()) { - return NS_OK; - } - - if (type == eHTMLTag_p || type == eHTMLTag_pre) { - EnsureVerticalSpace(1); // Should this be 0 in unformatted case? - } - else if (type == eHTMLTag_td || type == eHTMLTag_th) { - // We must make sure that the content of two table cells get a - // space between them. - - // Fow now, I will only add a SPACE. Could be a TAB or something - // else but I'm not sure everything can handle the TAB so SPACE - // seems like a better solution. - if(!mInWhitespace) { - // Maybe add something else? Several spaces? A TAB? SPACE+TAB? - AddToLine(kSpace.GetUnicode(), 1); - mInWhitespace = PR_TRUE; - } - } - else if (type == eHTMLTag_ul) { - // Indent here to support nested list, which aren't included in li :-( - EnsureVerticalSpace(1); // Must end the current line before we change indent. - mIndent += kIndentSizeList; - } - else if (type == eHTMLTag_ol) { - EnsureVerticalSpace(1); // Must end the current line before we change indent. - if (mOLStackIndex < OLStackSize) { - mOLStack[mOLStackIndex++] = 1; // XXX should get it from the node! - } - mIndent += kIndentSizeList; // see ul - } - else if (type == eHTMLTag_li) { - if (mTagStackIndex > 1 && mTagStack[mTagStackIndex-2] == eHTMLTag_ol) { - if (mOLStackIndex > 0) { - // This is what nsBulletFrame does for OLs: - mInIndentString.AppendInt(mOLStack[mOLStackIndex-1]++, 10); - } - else { - mInIndentString.Append(PRUnichar('#')); - } - - mInIndentString.Append(PRUnichar('.')); - - } - else { - mInIndentString.Append(PRUnichar('*')); - } - - mInIndentString.Append(PRUnichar(' ')); - } - else if (type == eHTMLTag_dl) { - EnsureVerticalSpace(1); - } - else if (type == eHTMLTag_dd) { - mIndent += kIndentSizeDD; - } - - // Else make sure we'll separate block level tags, - // even if we're about to leave, before doing any other formatting. - else if (IsBlockLevel(aTag)) { - EnsureVerticalSpace(0); - } - - ////////////////////////////////////////////////////////////// - if (!(mFlags & nsIDocumentEncoder::OutputFormatted)) { - return NS_OK; - } - ////////////////////////////////////////////////////////////// - // The rest of this routine is formatted output stuff, - // which we should skip if we're not formatted: - ////////////////////////////////////////////////////////////// - - if (type == eHTMLTag_h1 || type == eHTMLTag_h2 || - type == eHTMLTag_h3 || type == eHTMLTag_h4 || - type == eHTMLTag_h5 || type == eHTMLTag_h6) - { - EnsureVerticalSpace(2); - if (mHeaderStrategy == 2) { // numbered - mIndent += kIndentSizeHeaders; - // Caching - nsCAutoString leadup; - PRInt32 level = HeaderLevel(type); - // Increase counter for current level - mHeaderCounter[level]++; - // Reset all lower levels - PRInt32 i; - - for (i = level + 1; i <= 6; i++) { - mHeaderCounter[i] = 0; - } - - // Construct numbers - for (i = 1; i <= level; i++) { - leadup.AppendInt(mHeaderCounter[i]); - leadup += "."; - } - leadup += " "; - Write(NS_ConvertASCIItoUCS2(leadup.GetBuffer())); - } - else if (mHeaderStrategy == 1) { // indent increasingly - mIndent += kIndentSizeHeaders; - for (PRInt32 i = HeaderLevel(type); i > 1; i--) { - // for h(x), run x-1 times - mIndent += kIndentIncrementHeaders; - } - } - } - else if (type == eHTMLTag_blockquote) { - EnsureVerticalSpace(1); - - nsAutoString value; - nsresult rv = GetAttributeValue(nsHTMLAtoms::type, value); - - if (NS_SUCCEEDED(rv) && value.EqualsIgnoreCase("cite")) { - mCiteQuoteLevel++; - } - else { - mIndent += kTabSize; // Check for some maximum value? - } - } - else if (type == eHTMLTag_a && !IsCurrentNodeConverted()) { - nsAutoString url; - if (NS_SUCCEEDED(GetAttributeValue(nsHTMLAtoms::href, url)) - && !url.IsEmpty()) { - mURL = url; - } - } - else if (type == eHTMLTag_q) { - Write(NS_ConvertASCIItoUCS2("\"")); - } - else if (type == eHTMLTag_sup && mStructs && !IsCurrentNodeConverted()) { - Write(NS_ConvertASCIItoUCS2("^")); - } - else if (type == eHTMLTag_sub && mStructs && !IsCurrentNodeConverted()) { - Write(NS_ConvertASCIItoUCS2("_")); - } - else if (type == eHTMLTag_code && mStructs && !IsCurrentNodeConverted()) { - Write(NS_ConvertASCIItoUCS2("|")); - } - else if ((type == eHTMLTag_strong || type == eHTMLTag_b) - && mStructs && !IsCurrentNodeConverted()) { - Write(NS_ConvertASCIItoUCS2("*")); - } - else if ((type == eHTMLTag_em || type == eHTMLTag_i) - && mStructs && !IsCurrentNodeConverted()) { - Write(NS_ConvertASCIItoUCS2("/")); - } - else if (type == eHTMLTag_u && mStructs && !IsCurrentNodeConverted()) { - Write(NS_ConvertASCIItoUCS2("_")); - } - - return NS_OK; - -} - -nsresult -nsPlainTextSerializer::DoCloseContainer(PRInt32 aTag) -{ - eHTMLTags type = (eHTMLTags)aTag; - - if (mTagStackIndex > 0) { - --mTagStackIndex; - } - - // End current line if we're ending a block level tag - if((type == eHTMLTag_body) || (type == eHTMLTag_html)) { - // We want the output to end with a new line, - // but in preformatted areas like text fields, - // we can't emit newlines that weren't there. - // So add the newline only in the case of formatted output. - if (mFlags & nsIDocumentEncoder::OutputFormatted) { - EnsureVerticalSpace(0); - } - else { - FlushLine(); - } - // We won't want to do anything with these in formatted mode either, - // so just return now: - return NS_OK; - } - else if ((type == eHTMLTag_tr) || - (type == eHTMLTag_li) || - (type == eHTMLTag_pre) || - (type == eHTMLTag_dt)) { - // Items that should always end a line, but get no more whitespace - EnsureVerticalSpace(0); - } - else if (type == eHTMLTag_ul) { - mIndent -= kIndentSizeList; - } - else if (type == eHTMLTag_ol) { - FlushLine(); // Doing this after decreasing OLStackIndex would be wrong. - --mOLStackIndex; - mIndent -= kIndentSizeList; - } - else if (type == eHTMLTag_dd) { - mIndent -= kIndentSizeDD; - } - else if (IsBlockLevel(aTag) - && type != eHTMLTag_blockquote - && type != eHTMLTag_script - && type != eHTMLTag_doctypeDecl - && type != eHTMLTag_markupDecl) { - // All other blocks get 1 vertical space after them - // in formatted mode, otherwise 0. - // This is hard. Sometimes 0 is a better number, but - // how to know? - EnsureVerticalSpace((mFlags & nsIDocumentEncoder::OutputFormatted) - ? 1 : 0); - } - - ////////////////////////////////////////////////////////////// - if (!(mFlags & nsIDocumentEncoder::OutputFormatted)) { - return NS_OK; - } - ////////////////////////////////////////////////////////////// - // The rest of this routine is formatted output stuff, - // which we should skip if we're not formatted: - ////////////////////////////////////////////////////////////// - - if (type == eHTMLTag_h1 || type == eHTMLTag_h2 || - type == eHTMLTag_h3 || type == eHTMLTag_h4 || - type == eHTMLTag_h5 || type == eHTMLTag_h6) { - - if (mHeaderStrategy) { /*numbered or indent increasingly*/ - mIndent -= kIndentSizeHeaders; - } - if (mHeaderStrategy == 1 /*indent increasingly*/ ) { - for (PRInt32 i = HeaderLevel(type); i > 1; i--) { - // for h(x), run x-1 times - mIndent -= kIndentIncrementHeaders; - } - } - EnsureVerticalSpace(1); - } - else if (type == eHTMLTag_blockquote) { - FlushLine(); // Is this needed? - - nsAutoString value; - nsresult rv = GetAttributeValue(nsHTMLAtoms::type, value); - - if (NS_SUCCEEDED(rv) && value.EqualsIgnoreCase("cite")) { - mCiteQuoteLevel--; - } - else { - mIndent -= kTabSize; - } - - EnsureVerticalSpace(1); - } - else if (type == eHTMLTag_a && !IsCurrentNodeConverted() && !mURL.IsEmpty()) { - nsAutoString temp; - temp.Assign(NS_LITERAL_STRING(" <")); - temp += mURL; - temp.Append(PRUnichar('>')); - Write(temp); - mURL.Truncate(); - } - else if (type == eHTMLTag_q) { - Write(NS_ConvertASCIItoUCS2("\"")); - } - else if ((type == eHTMLTag_sup || type == eHTMLTag_sub) - && mStructs && !IsCurrentNodeConverted()) { - Write(kSpace); - } - else if (type == eHTMLTag_code && mStructs && !IsCurrentNodeConverted()) { - Write(NS_ConvertASCIItoUCS2("|")); - } - else if ((type == eHTMLTag_strong || type == eHTMLTag_b) - && mStructs && !IsCurrentNodeConverted()) { - Write(NS_ConvertASCIItoUCS2("*")); - } - else if ((type == eHTMLTag_em || type == eHTMLTag_i) - && mStructs && !IsCurrentNodeConverted()) { - Write(NS_ConvertASCIItoUCS2("/")); - } - else if (type == eHTMLTag_u && mStructs && !IsCurrentNodeConverted()) { - Write(NS_ConvertASCIItoUCS2("_")); - } - - return NS_OK; -} - -nsresult -nsPlainTextSerializer::DoAddLeaf(PRInt32 aTag, - const nsAReadableString& aText) -{ - // If we don't want any output, just return - if (!DoOutput()) { - return NS_OK; - } - - eHTMLTags type = (eHTMLTags)aTag; - - if ((mTagStackIndex > 1 && - mTagStack[mTagStackIndex-2] == eHTMLTag_select) || - (mTagStackIndex > 0 && - mTagStack[mTagStackIndex-1] == eHTMLTag_select)) { - // Don't output the contents of SELECT elements; - // Might be nice, eventually, to output just the selected element. - // Read more in bug 31994. - return NS_OK; - } - else if (mTagStackIndex > 0 && mTagStack[mTagStackIndex-1] == eHTMLTag_script) { - // Don't output the contents of