Compare commits

..

8 Commits

Author SHA1 Message Date
waterson%netscape.com
a0cbbe0dfc Add outliner files to build.
git-svn-id: svn://10.0.0.236/branches/RDF_OUTLINER_20010322_BRANCH@90242 18797224-902f-48f8-a5cc-f745e15eee43
2001-03-23 10:47:24 +00:00
waterson%netscape.com
dc2422482b Use NS_NAMED_LITERAL_STRING so that Mac doesn't nuke references.
git-svn-id: svn://10.0.0.236/branches/RDF_OUTLINER_20010322_BRANCH@90240 18797224-902f-48f8-a5cc-f745e15eee43
2001-03-23 10:41:46 +00:00
waterson%netscape.com
d85c601985 Use contract IDs instead of class IDs to instantiate builders. Call DocumentWillBeDestroyed() on observers before tearing down doc internals.
git-svn-id: svn://10.0.0.236/branches/RDF_OUTLINER_20010322_BRANCH@90239 18797224-902f-48f8-a5cc-f745e15eee43
2001-03-23 10:01:46 +00:00
waterson%netscape.com
cee6f64348 Fix type modifier on Win32.
git-svn-id: svn://10.0.0.236/branches/RDF_OUTLINER_20010322_BRANCH@90232 18797224-902f-48f8-a5cc-f745e15eee43
2001-03-23 09:12:17 +00:00
waterson%netscape.com
14734c7d7e Fix string-fu for Mac.
git-svn-id: svn://10.0.0.236/branches/RDF_OUTLINER_20010322_BRANCH@90226 18797224-902f-48f8-a5cc-f745e15eee43
2001-03-23 09:04:24 +00:00
waterson%netscape.com
d6fbde4db9 Add new files for RDF outliner.
git-svn-id: svn://10.0.0.236/branches/RDF_OUTLINER_20010322_BRANCH@90225 18797224-902f-48f8-a5cc-f745e15eee43
2001-03-23 09:03:16 +00:00
waterson%netscape.com
1bbd6668ca Land RDF outliner changes onto RDF_OUTLINER_20010322_BRANCH to get building cross-platform.
git-svn-id: svn://10.0.0.236/branches/RDF_OUTLINER_20010322_BRANCH@90219 18797224-902f-48f8-a5cc-f745e15eee43
2001-03-23 07:55:47 +00:00
(no author)
c89620d298 This commit was manufactured by cvs2svn to create branch
'RDF_OUTLINER_20010322_BRANCH'.

git-svn-id: svn://10.0.0.236/branches/RDF_OUTLINER_20010322_BRANCH@90213 18797224-902f-48f8-a5cc-f745e15eee43
2001-03-23 07:39:33 +00:00
888 changed files with 217635 additions and 106012 deletions

View File

@@ -0,0 +1,34 @@
#
# 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):
#
DEPTH = ..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = base html xml xul xbl xsl
DIRS += events shared build
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,32 @@
#
# 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):
#
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,27 @@
#!nmake
#
# 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):
DEPTH=..\..
DIRS=public src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,27 @@
#
# This is a list of local files which get copied to the mozilla:dist:content directory
#
nsContentPolicyUtils.h
nsIAnonymousContent.h
nsIContent.h
nsIContentIterator.h
nsIContentSerializer.h
nsIDocument.h
nsIDocumentContainer.h
nsIDocumentEncoder.h
nsIDocumentObserver.h
nsIDocumentViewer.h
nsIElementFactory.h
nsIHTMLToTextSink.h
nsINameSpace.h
nsINameSpaceManager.h
nsINodeInfo.h
nsIPrivateDOMImplementation.h
nsIStyledContent.h
nsIStyleRule.h
nsIStyleRuleProcessor.h
nsIStyleRuleSupplier.h
nsIStyleSheet.h
nsIStyleSheetLinkingElement.h
nsITextContent.h

View File

@@ -0,0 +1,10 @@
#
# This is a list of local files which get copied to the mozilla:dist:idl directory
#
nsIContentPolicy.idl
nsIDiskDocument.idl
nsISelection.idl
nsISelectionController.idl
nsISelectionListener.idl
nsISelectionPrivate.idl

View File

@@ -0,0 +1,71 @@
#
# 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):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = layout
XPIDL_MODULE = content_base
EXPORTS = \
nsIContent.h \
nsIAnonymousContent.h \
nsIContentIterator.h \
nsContentPolicyUtils.h \
nsContentUtils.h \
nsIDocument.h \
nsIDocumentContainer.h \
nsIDocumentEncoder.h \
nsIDocumentObserver.h \
nsIDocumentViewer.h \
nsIElementFactory.h \
nsINameSpace.h \
nsINameSpaceManager.h \
nsINodeInfo.h \
nsIStyledContent.h \
nsIStyleRule.h \
nsIStyleRuleSupplier.h \
nsIStyleSheet.h \
nsIStyleSheetLinkingElement.h \
nsIStyleRuleProcessor.h \
nsITextContent.h \
nsIPrivateDOMImplementation.h \
nsIContentSerializer.h \
nsIHTMLToTextSink.h \
$(NULL)
XPIDLSRCS = \
nsIContentPolicy.idl \
nsIDiskDocument.idl \
nsISelectionController.idl \
nsISelectionListener.idl \
nsISelection.idl \
nsISelectionPrivate.idl \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,64 @@
#!nmake
#
# 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):
DEPTH=..\..\..
EXPORTS = \
nsContentPolicyUtils.h \
nsIContent.h \
nsIAnonymousContent.h \
nsIContentIterator.h \
nsIDocument.h \
nsIDocumentContainer.h \
nsIDocumentEncoder.h \
nsIDocumentObserver.h \
nsIDocumentViewer.h \
nsIElementFactory.h \
nsINameSpace.h \
nsINameSpaceManager.h \
nsINodeInfo.h \
nsIStyledContent.h \
nsIStyleRule.h \
nsIStyleRuleSupplier.h \
nsIStyleSheet.h \
nsIStyleSheetLinkingElement.h \
nsIStyleRuleProcessor.h \
nsITextContent.h \
nsContentUtils.h \
nsIPrivateDOMImplementation.h \
nsIContentSerializer.h \
nsIHTMLToTextSink.h \
$(NULL)
MODULE=content_base
XPIDLSRCS= \
.\nsIContentPolicy.idl \
.\nsIDiskDocument.idl \
.\nsISelectionController.idl \
.\nsISelectionListener.idl \
.\nsISelection.idl \
.\nsISelectionPrivate.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,256 @@
/* -*- 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 nsContentCID_h__
#define nsContentCID_h__
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIComponentManager.h"
// {1691E1F7-EE41-11d4-9885-00C04FA0CF4B}
#define NS_STYLESET_CID \
{ 0x1691e1f7, 0xee41, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {96882B70-8A27-11d2-8EAF-00805F29F370}
#define NS_HTMLSTYLESHEET_CID \
{ 0x96882b70, 0x8a27, 0x11d2, { 0x8e, 0xaf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {972D8D8F-F0DA-11d4-9885-00C04FA0CF4B}
#define NS_DOCUMENT_VIEWER_CID \
{ 0x972d8d8f, 0xf0da, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {A5121627-EDB6-11d4-9885-00C04FA0CF4B}
#define NS_ANONYMOUSCONTENT_CID \
{ 0xa5121627, 0xedb6, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {FC886801-E768-11d4-9885-00C04FA0CF4B}
#define NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID \
{ 0xfc886801, 0xe768, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
/* a6cf90f9-15b3-11d2-932e-00805f8add32 */
#define NS_LAYOUT_DEBUGGER_CID \
{ 0xa6cf90f9, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
/* a6cf90fc-15b3-11d2-932e-00805f8add32 */
#define NS_HTML_ELEMENT_FACTORY_CID \
{ 0xa6cf90fc, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
#define NS_HTMLDOCUMENT_CID \
{ /* 5d0fcdd0-4daa-11d2-b328-00805f8a3859 */ \
0x5d0fcdd0, 0x4daa, 0x11d2, \
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
#define NS_XMLDOCUMENT_CID \
{ /* a6cf9063-15b3-11d2-932e-00805f8add32 */ \
0xa6cf9063, 0x15b3, 0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
#define NS_XML_ELEMENT_FACTORY_CID \
{ /* CF170391-79CC-11d3-BE44-0020A6361667 */ \
0xcf170391, 0x79cc, 0x11d3, \
{0xbe, 0x44, 0x0, 0x20, 0xa6, 0x36, 0x16, 0x67}}
#define NS_IMAGEDOCUMENT_CID \
{ /* e11a6080-4daa-11d2-b328-00805f8a3859 */ \
0xe11a6080, 0x4daa, 0x11d2, \
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
// {A1FDE864-E802-11d4-9885-00C04FA0CF4B}
#define NS_HTMLHRELEMENT_CID \
{ 0xa1fde864, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {A1FDE865-E802-11d4-9885-00C04FA0CF4B}
#define NS_HTMLINPUTELEMENT_CID \
{ 0xa1fde865, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {A1FDE866-E802-11d4-9885-00C04FA0CF4B}
#define NS_HTMLATTRIBUTES_CID \
{ 0xa1fde866, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
#define NS_HTMLIMAGEELEMENT_CID \
{ /* d6008c40-4dad-11d2-b328-00805f8a3859 */ \
0xd6008c40, 0x4dad, 0x11d2, \
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
#define NS_HTMLOPTIONELEMENT_CID \
{ /* a6cf90f5-15b3-11d2-932e-00805f8add32 */ \
0xa6cf90f5, 0x15b3, 0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
#define NS_NAMESPACEMANAGER_CID \
{ /* d9783472-8fe9-11d2-9d3c-0060088f9ff7 */ \
0xd9783472, 0x8fe9, 0x11d2, \
{0x9d, 0x3c, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
/* a6cf90d7-15b3-11d2-932e-00805f8add32 */
#define NS_FRAME_UTIL_CID \
{ 0xa6cf90d5, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
// XXX This should really be factored into a style-specific DLL so
// that all the HTML, generic layout, and style stuff isn't munged
// together.
// {2E363D60-872E-11d2-B531-000000000000}
#define NS_CSSPARSER_CID \
{ 0x2e363d60, 0x872e, 0x11d2, { 0xb5, 0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {95F46161-D177-11d2-BF86-00105A1B0627}
#define NS_HTML_CSS_STYLESHEET_CID \
{ 0x95f46161, 0xd177, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {A1FDE867-E802-11d4-9885-00C04FA0CF4B}
#define NS_CSS_STYLESHEET_CID \
{ 0xa1fde867, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {eaca2576-0d4a-11d3-9d7e-0060088f9ff7}
#define NS_CSS_LOADER_CID \
{ 0xeaca2576, 0x0d4a, 0x11d3, { 0x9d, 0x7e, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7 } }
// {96882B71-8A27-11d2-8EAF-00805F29F370}
#define NS_TEXTNODE_CID \
{ 0x96882b71, 0x8a27, 0x11d2, { 0x8e, 0xaf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {96882B72-8A27-11d2-8EAF-00805F29F370}
#define NS_SELECTION_CID \
{ 0x96882b72, 0x8a27, 0x11d2, { 0x8e, 0xaf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
#define NS_FRAMESELECTION_CID \
{/* {905F80F1-8A7B-11d2-918C-0080C8E44DB5}*/ \
0x905f80f1, 0x8a7b, 0x11d2, { 0x91, 0x8c, 0x0, 0x80, 0xc8, 0xe4, 0x4d, 0xb5 } }
#define NS_DOMSELECTION_CID \
{/* {C87A37FC-8109-4ce2-A322-8CDEC925379F}*/ \
0xc87a37fc, 0x8109, 0x4ce2, { 0xa3, 0x22, 0x8c, 0xde, 0xc9, 0x25, 0x37, 0x9f } }
#define NS_RANGE_CID \
{/* {56AD2981-8A87-11d2-918C-0080C8E44DB5}*/ \
0x56ad2981, 0x8a87, 0x11d2, { 0x91, 0x8c, 0x0, 0x80, 0xc8, 0xe4, 0x4d, 0xb5 } }
// {A1FDE868-E802-11d4-9885-00C04FA0CF4B}
#define NS_ATTRIBUTECONTENT_CID \
{ 0xa1fde868, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
#define NS_CONTENTITERATOR_CID \
{/* {a6cf90e3-15b3-11d2-932e-00805f8add32}*/ \
0xa6cf90e3, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
#define NS_GENERATEDSUBTREEITERATOR_CID \
{/* {9A45253B-EB8F-49f1-B925-E9EA90D3EB3A}*/ \
0x9a45253b, 0xeb8f, 0x49f1, { 0xb9, 0x25, 0xe9, 0xea, 0x90, 0xd3, 0xeb, 0x3a } }
#define NS_GENERATEDCONTENTITERATOR_CID \
{/* {A364930F-E353-49f1-AC69-91637EB8B757}*/ \
0xa364930f, 0xe353, 0x49f1, { 0xac, 0x69, 0x91, 0x63, 0x7e, 0xb8, 0xb7, 0x57 } }
#define NS_SUBTREEITERATOR_CID \
{/* {a6cf90e5-15b3-11d2-932e-00805f8add32}*/ \
0xa6cf90e5, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
// {09F689E0-B4DA-11d2-A68B-00104BDE6048}
#define NS_EVENTLISTENERMANAGER_CID \
{ 0x9f689e0, 0xb4da, 0x11d2, { 0xa6, 0x8b, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
// {A1FDE862-E802-11d4-9885-00C04FA0CF4B}
#define NS_EVENTSTATEMANAGER_CID \
{ 0xa1fde862, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {64F300A1-C88C-11d3-97FB-00400553EEF0}
#define NS_XBLSERVICE_CID \
{ 0x64f300a1, 0xc88c, 0x11d3, { 0x97, 0xfb, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } }
// {15671AF5-39F9-4c70-8CE3-72C97111B52D}
#define NS_BINDINGMANAGER_CID \
{ 0x15671af5, 0x39f9, 0x4c70, { 0x8c, 0xe3, 0x72, 0xc9, 0x71, 0x11, 0xb5, 0x2d } }
// 3a9cd622-264d-11d4-ba06-0060b0fc76dd
#define NS_DOM_IMPLEMENTATION_CID \
{ 0x3a9cd622, 0x264d, 0x11d4, {0xba, 0x06, 0x00, 0x60, 0xb0, 0xfc, 0x76, 0xdd } }
// {AE52FE52-683A-437D-B661-DE55F4E0A873}
#define NS_NODEINFOMANAGER_CID \
{ 0xae52fe52, 0x683a, 0x437d, { 0xb6, 0x61, 0xde, 0x55, 0xf4, 0xe0, 0xa8, 0x73 } }
// {ECEA1B28-AE54-4047-8BBE-C624235106B4}
#define NS_COMPUTEDDOMSTYLE_CID \
{ 0xecea1b28, 0xae54, 0x4047, { 0x8b, 0xbe, 0xc6, 0x24, 0x23, 0x51, 0x06, 0xb4 } }
// {4aef38b7-6364-4e23-a5e7-12f837fbbd9c}
#define NS_XMLCONTENTSERIALIZER_CID \
{ 0x4aef38b7, 0x6364, 0x4e23, { 0xa5, 0xe7, 0x12, 0xf8, 0x37, 0xfb, 0xbd, 0x9c } }
// {9d3f70da-86e9-11d4-95ec-00b0d03e37b7}
#define NS_HTMLCONTENTSERIALIZER_CID \
{ 0x9d3f70da, 0x86e9, 0x11d4, { 0x95, 0xec, 0x00, 0xb0, 0xd0, 0x3e, 0x37, 0xb7 } }
// {6030f7ef-32ed-46a7-9a63-6a5d3f90445f}
#define NS_PLAINTEXTSERIALIZER_CID \
{ 0x6030f7ef, 0x32ed, 0x46a7, { 0x9a, 0x63, 0x6a, 0x5d, 0x3f, 0x90, 0x44, 0x5f } }
// {3986B301-097C-11d3-BF87-00105A1B0627}
#define NS_XULPOPUPLISTENER_CID \
{ 0x3986b301, 0x97c, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {1F5C1721-7DC3-11d3-BF87-00105A1B0627}
#define NS_XULCONTROLLERS_CID \
{ 0x1f5c1721, 0x7dc3, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {daedcb43-1dd1-11b2-b1d2-caf06cb40387}
#define NS_DLGDEFAULTKEYS_CID \
{ 0xdaedcb43, 0x1dd1, 0x11b2, { 0xb1, 0xd2, 0xca, 0xf0, 0x6c, 0xb4, 0x3, 0x87 } }
// {76E92881-CDDB-11d3-BF87-00105A1B0627}
#define NS_XULELEMENTFACTORY_CID \
{ 0x76e92881, 0xcddb, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {508f5601-e09b-11d3-9f7e-cf931f9f173c}
#define NS_CONTROLLERCOMMANDMANAGER_CID \
{ 0x508f5601, 0xe09b, 0x11d3, { 0x9f, 0x7e, 0xcf, 0x93, 0x1f, 0x9f, 0x17, 0x3c } }
// {BFD05264-834C-11d2-8EAC-00805F29F371}
#define NS_XULSORTSERVICE_CID \
{ 0xbfd05264, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x71 } }
// {3D262D00-8B5A-11d2-8EB0-00805F29F370}
#define NS_XULTEMPLATEBUILDER_CID \
{ 0x3d262d00, 0x8b5a, 0x11d2, { 0x8e, 0xb0, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {1abdcc96-1dd2-11b2-b520-f8f59cdd67bc}
#define NS_XULOUTLINERBUILDER_CID \
{ 0x1abdcc96, 0x1dd2, 0x11b2, { 0xb5, 0x20, 0xf8, 0xf5, 0x9c, 0xdd, 0x67, 0xbc } }
// {CE058B21-BA9C-11d2-BF86-00105A1B0627}
#define NS_XULCONTENTSINK_CID \
{ 0xce058b21, 0xba9c, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {541AFCB2-A9A3-11d2-8EC5-00805F29F370}
#define NS_XULDOCUMENT_CID \
{ 0x541afcb2, 0xa9a3, 0x11d2, { 0x8e, 0xc5, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {3A0A0FC1-8349-11d3-BE47-00104BDE6048}
#define NS_XULPROTOTYPECACHE_CID \
{ 0x3a0a0fc1, 0x8349, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
#endif /* nsContentCID_h__ */

View File

@@ -0,0 +1,69 @@
/* -*- 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__ */

View File

@@ -0,0 +1,75 @@
/* -*- 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 oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* 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):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
/* A namespace class for static layout utilities. */
#ifndef nsContentUtils_h___
#define nsContentUtils_h___
#include "nslayout.h"
#include "jspubtd.h"
#include "nsAReadableString.h"
class nsIScriptContext;
class nsIScriptGlobalObject;
class nsContentUtils
{
public:
// These are copied from nsJSUtils.h
static nsresult GetStaticScriptGlobal(JSContext* aContext,
JSObject* aObj,
nsIScriptGlobalObject** aNativeGlobal);
static nsresult GetStaticScriptContext(JSContext* aContext,
JSObject* aObj,
nsIScriptContext** aScriptContext);
static nsresult GetDynamicScriptGlobal(JSContext *aContext,
nsIScriptGlobalObject** aNativeGlobal);
static nsresult GetDynamicScriptContext(JSContext *aContext,
nsIScriptContext** aScriptContext);
static PRUint32 CopyNewlineNormalizedUnicodeTo(const nsAReadableString& aSource,
PRUint32 aSrcOffset,
PRUnichar* aDest,
PRUint32 aLength);
static PRUint32 CopyNewlineNormalizedUnicodeTo(nsReadingIterator<PRUnichar>& aSrcStart, const nsReadingIterator<PRUnichar>& aSrcEnd, nsAWritableString& aDest);
};
#endif /* nsContentUtils_h___ */

View File

@@ -0,0 +1,50 @@
/* -*- 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;
class nsINodeInfo;
#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; }
NS_IMETHOD Init(nsINodeInfo *aInfo) = 0;
};
nsresult NS_NewAnonymousContent2(nsIContent **aNewNode);
#endif

View File

@@ -0,0 +1,308 @@
/* -*- 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 <stdio.h>
#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.
*
* <UL>
*
* <LI>If the attribute is not set and has no default value, return
* NS_CONTENT_ATTR_NOT_THERE.
*
* <LI>If the attribute exists, but has no value, return
* NS_CONTENT_ATTR_NO_VALUE.
*
* <LI>If the attribute has a non-empty value, set ret to
* be the value, and return NS_CONTENT_ATTR_HAS_VALUE (== NS_OK).
*
* </UL>
*/
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.
*
* <UL>
*
* <LI>If the attribute is not set and has no default value, return
* NS_CONTENT_ATTR_NOT_THERE.
*
* <LI>If the attribute exists, but has no value, return
* NS_CONTENT_ATTR_NO_VALUE.
*
* <LI>If the attribute has a non-empty value, set ret to
* be the value, and return NS_CONTENT_ATTR_HAS_VALUE (== NS_OK).
*
* </UL>
*
* 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___ */

View File

@@ -0,0 +1,113 @@
/* -*- 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___

View File

@@ -0,0 +1,56 @@
/* -*- 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);
};

View File

@@ -0,0 +1,82 @@
/* -*- 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__ */

View File

@@ -0,0 +1,83 @@
/* -*- 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);
};

View File

@@ -0,0 +1,343 @@
/* -*- 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 <b>must not</b> 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 AttributeWillChange(nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute) = 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_(PRBool) EventCaptureRegistration(PRInt32 aCapturerIncrement) = 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;
NS_IMETHOD Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) = 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___ */

View File

@@ -0,0 +1,75 @@
/* -*- 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___ */

View File

@@ -0,0 +1,209 @@
/* -*- 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 <pre>), 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 &nbsp; 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__ */

View File

@@ -0,0 +1,312 @@
/* -*- 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 <b>before</b>
* 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. <p>
*
* 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. <p>
*
* 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. <p>
*
* @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___ */

View File

@@ -0,0 +1,59 @@
/* -*- 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___ */

View File

@@ -0,0 +1,55 @@
/* -*- 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___ */

View File

@@ -0,0 +1,48 @@
/* -*- 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

View File

@@ -0,0 +1,76 @@
/* -*- 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___

View File

@@ -0,0 +1,85 @@
/* -*- 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___

View File

@@ -0,0 +1,234 @@
/* -*- 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 "<body>" this will return "body" and for the XML
* element "<html:body>" 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 "<body>" this will return the "body" atom and for
* the XML element "<html:body>" 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 "<body>" this will return "body" and for the XML
* element "<html:body>" 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 "<body>" in a HTML document this will return a null
* string and for the XML element "<html:body>" this will return "body".
*/
NS_IMETHOD GetLocalName(nsAWritableString& aLocalName) = 0;
/*
* Get the prefix from this node as a string.
*
* For the HTML element "<body>" this will return a null string and for
* the XML element "<html:body>" 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 "<body>" this will return a null atom and for
* the XML element "<html:body>" 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 "<body>" in a HTML document this will return a null
* string and for the XML element "<html:body>" (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 "<body>" in a HTML document this will return
* kNameSpaceID_None and for the XML element "<html:body>" (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___ */

View File

@@ -0,0 +1,49 @@
/* -*- 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__

View File

@@ -0,0 +1,141 @@
/* -*- 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"
/* THIS IS A PUBLIC INTERFACE */
%{C++
class nsIDOMNode;
class nsIDOMRange;
%}
/**
* Interface for manipulating and querying the current selected range
* of nodes within the document.
*/
[scriptable, uuid(B2C7ED59-8634-4352-9E37-5484C8B6E4E1)]
interface nsISelection : nsISupports
{
/**
* The node representing one end of the selection.
*/
readonly attribute nsIDOMNode anchorNode;
/**
* The offset within the (text) node where the selection begins.
*/
readonly attribute long anchorOffset;
/**
* The node with keyboard focus.
*/
readonly attribute nsIDOMNode focusNode;
/**
* The offset within the (text) node where focus starts.
*/
readonly attribute long focusOffset;
/**
* Indicates if the whole selection just one point, or unset.
*/
readonly attribute boolean isCollapsed;
/**
* Returns the number of ranges in the selection.
*/
readonly attribute long rangeCount;
/**
* Returns the range at the specified index.
*/
nsIDOMRange getRangeAt(in long index);
/**
* Sets the whole selection down to a single point specified
* by the node and offset.
*/
void collapse(in nsIDOMNode parentNode, in long offset);
/**
* Changes the current selection to extend to the specified node
* and offset.
*/
void extend(in nsIDOMNode parentNode, in long offset);
/**
* Sets the whole selection to be a point at the start of the current
* selection.
*/
void collapseToStart();
/**
* Sets the whole selection to be a point at the end of the current
* selection.
*/
void collapseToEnd();
/**
* Tests whether the node is in the selection, optionally
* using recursion to locate it.
*/
boolean containsNode(in nsIDOMNode node, in boolean recursive);
/**
* Adds all children of the specified node to the selection.
*/
void selectAllChildren(in nsIDOMNode parentNode);
/**
* Adds a range to the current selection.
*/
void addRange(in nsIDOMRange range);
/**
* Removes a range from the current selection.
*/
void removeRange(in nsIDOMRange range);
/**
* Removes all ranges from the current selection.
*/
void removeAllRanges();
/**
* Deletes this selection from document the nodes belong to.
*/
void deleteFromDocument();
/**
* Modifies the cursor Bidi level after a change in keyboard direction
* @param langRTL is PR_TRUE if the new language is right-to-left or
* PR_FALSE if the new language is left-to-right
*/
void selectionLanguageChange(in boolean langRTL);
/**
* Returns the whole selection into a plain text string.
*/
wstring toString();
};

View File

@@ -0,0 +1,233 @@
/* -*- 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 }}
%}

View File

@@ -0,0 +1,44 @@
/* -*- 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);
};

View File

@@ -0,0 +1,75 @@
/* -*- 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);
};

View File

@@ -0,0 +1,61 @@
/* -*- 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 <stdio.h>
#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___ */

View File

@@ -0,0 +1,78 @@
/* -*- 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 <stdio.h>
#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___ */

View File

@@ -0,0 +1,25 @@
#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;
NS_IMETHOD MatchesScopedRoot(nsIContent* aContent, PRBool* aResult)=0;
};
#endif /* _nsIStyleRuleSupplier_h */

View File

@@ -0,0 +1,81 @@
/* -*- 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 <stdio.h>
#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___ */

View File

@@ -0,0 +1,56 @@
/* -*- 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__

View File

@@ -0,0 +1,62 @@
/* -*- 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___ */

View File

@@ -0,0 +1,135 @@
/* -*- 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___ */

View File

@@ -0,0 +1,7 @@
#
# This is a list of local files which get copied to the mozilla:dist:content directory
#
nsContentList.h
nsDocument.h
nsGenericDOMNodeList.h
nsGenericElement.h

View File

@@ -0,0 +1,79 @@
#
# 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):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = layout
LIBRARY_NAME = gkconbase_s
REQUIRES = xpcom string dom widget view locale timer htmlparser js webshell necko caps lwbrk intl uconv chrome docshell pref uriloader xpconnect util unicharutil rdf
CPPSRCS = \
nsCommentNode.cpp \
nsContentIterator.cpp \
nsContentList.cpp \
nsContentPolicy.cpp \
nsDocument.cpp \
nsDocumentEncoder.cpp \
nsDocumentFragment.cpp \
nsDocumentViewer.cpp \
nsDOMAttribute.cpp \
nsDOMAttributeMap.cpp \
nsDOMDocumentType.cpp \
nsGeneratedIterator.cpp \
nsGenericDOMDataNode.cpp \
nsGenericDOMNodeList.cpp \
nsGenericElement.cpp \
nsContentUtils.cpp \
nsNameSpaceManager.cpp \
nsNodeInfo.cpp \
nsNodeInfoManager.cpp \
nsRange.cpp \
nsSelection.cpp \
nsStyleContext.cpp \
nsStyleSet.cpp \
nsTextContentChangeData.cpp \
nsTextNode.cpp \
nsXMLContentSerializer.cpp \
nsHTMLContentSerializer.cpp \
nsParserUtils.cpp \
nsPlainTextSerializer.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.
override NO_SHARED_LIB=1
override NO_STATIC_LIB=
include $(topsrcdir)/config/rules.mk
DEFINES += -D_IMPL_NS_LAYOUT
INCLUDES += \
-I$(srcdir)/../../events/src \
-I$(srcdir)/../../html/base/src \
-I$(srcdir)/../../html/style/src \
-I$(srcdir)/../../xul/base/src \
-I$(srcdir)/../../xul/content/src \
$(NULL)

View File

@@ -0,0 +1,116 @@
#!nmake
#
# 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):
DEPTH=..\..\..
LIBRARY_NAME=contentbase_s
DEFINES=-D_IMPL_NS_LAYOUT -DWIN32_LEAN_AND_MEAN
!if defined(XP_NEW_SELECTION)
DEFINES = $(DEFINES) -DXP_NEW_SELECTION
!endif
CPPSRCS = \
nsStyleContext.cpp \
nsStyleSet.cpp \
nsCommentNode.cpp \
nsGenericElement.cpp \
nsGenericDOMDataNode.cpp \
nsGenericDOMNodeList.cpp \
nsContentList.cpp \
nsContentIterator.cpp \
nsContentPolicy.cpp \
nsDocument.cpp \
nsDocumentEncoder.cpp \
nsDocumentFragment.cpp \
nsDocumentViewer.cpp \
nsDOMAttribute.cpp \
nsDOMAttributeMap.cpp \
nsDOMDocumentType.cpp \
nsGeneratedIterator.cpp \
nsNameSpaceManager.cpp \
nsNodeInfo.cpp \
nsNodeInfoManager.cpp \
nsTextFragment.cpp \
nsSelection.cpp \
nsRange.cpp \
nsTextContentChangeData.cpp \
nsTextNode.cpp \
nsXMLContentSerializer.cpp \
nsHTMLContentSerializer.cpp \
nsParserUtils.cpp \
nsPlainTextSerializer.cpp \
nsContentUtils.cpp \
$(NULL)
MODULE=raptor
CPP_OBJS= \
.\$(OBJDIR)\nsStyleContext.obj \
.\$(OBJDIR)\nsStyleSet.obj \
.\$(OBJDIR)\nsCommentNode.obj \
.\$(OBJDIR)\nsGenericDOMDataNode.obj \
.\$(OBJDIR)\nsGenericDOMNodeList.obj \
.\$(OBJDIR)\nsGenericElement.obj \
.\$(OBJDIR)\nsContentList.obj \
.\$(OBJDIR)\nsContentIterator.obj \
.\$(OBJDIR)\nsContentPolicy.obj \
.\$(OBJDIR)\nsDocument.obj \
.\$(OBJDIR)\nsDocumentEncoder.obj \
.\$(OBJDIR)\nsDocumentFragment.obj \
.\$(OBJDIR)\nsDocumentViewer.obj \
.\$(OBJDIR)\nsDOMAttribute.obj \
.\$(OBJDIR)\nsDOMAttributeMap.obj \
.\$(OBJDIR)\nsDOMDocumentType.obj \
.\$(OBJDIR)\nsGeneratedIterator.obj \
.\$(OBJDIR)\nsNameSpaceManager.obj \
.\$(OBJDIR)\nsNodeInfo.obj \
.\$(OBJDIR)\nsNodeInfoManager.obj \
.\$(OBJDIR)\nsSelection.obj \
.\$(OBJDIR)\nsRange.obj \
.\$(OBJDIR)\nsTextContentChangeData.obj \
.\$(OBJDIR)\nsTextNode.obj \
.\$(OBJDIR)\nsXMLContentSerializer.obj \
.\$(OBJDIR)\nsHTMLContentSerializer.obj \
.\$(OBJDIR)\nsParserUtils.obj \
.\$(OBJDIR)\nsPlainTextSerializer.obj \
.\$(OBJDIR)\nsContentUtils.obj \
$(NULL)
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
-I$(PUBLIC)\dom -I$(PUBLIC)\js -I$(PUBLIC)\netlib \
-I$(PUBLIC)\pref -I..\..\html\base\src -I..\..\html\style\src \
-I..\..\xul\base\src -I..\..\xul\content\src \
-I..\..\events\src \
-I$(PUBLIC)\lwbrk -I$(PUBLIC)\plugin
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
rm -f $(PDBFILE).pdb

View File

@@ -0,0 +1,443 @@
/* -*- 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 "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<!--", this, mRefCnt);
nsAutoString tmp;
mInner.ToCString(tmp, 0, mInner.mText.GetLength());
fputs(tmp, out);
fputs("-->\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);
}
// 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* kCommentEnd = "->";
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);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,782 @@
/* -*- 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
// Form related includes
#include "nsIDOMHTMLFormElement.h"
nsBaseContentList::nsBaseContentList()
: mScriptObject(nsnull)
{
NS_INIT_REFCNT();
}
nsBaseContentList::~nsBaseContentList()
{
// mElements only has weak references to the content objects so we
// don't need to do any cleanup here.
}
NS_IMPL_ADDREF(nsBaseContentList)
NS_IMPL_RELEASE(nsBaseContentList)
NS_INTERFACE_MAP_BEGIN(nsBaseContentList)
NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList)
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectOwner)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeList)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
nsBaseContentList::GetLength(PRUint32* aLength)
{
*aLength = mElements.Count();
return NS_OK;
}
NS_IMETHODIMP
nsBaseContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsISupports *tmp = NS_REINTERPRET_CAST(nsISupports *,
mElements.ElementAt(aIndex));
if (!tmp) {
*aReturn = nsnull;
return NS_OK;
}
return CallQueryInterface(tmp, aReturn);
}
NS_IMETHODIMP
nsBaseContentList::GetScriptObject(nsIScriptContext *aContext,
void** aScriptObject)
{
nsresult res = NS_OK;
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
if (!mScriptObject) {
nsIDOMScriptObjectFactory *factory;
res = nsGenericElement::GetScriptObjectFactory(&factory);
if (NS_FAILED(res)) {
return res;
}
res = factory->NewScriptNodeList(aContext,
NS_STATIC_CAST(nsIDOMNodeList *, this),
global, &mScriptObject);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;
NS_RELEASE(global);
return res;
}
NS_IMETHODIMP
nsBaseContentList::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
NS_IMETHODIMP
nsBaseContentList::AppendElement(nsIContent *aContent)
{
// Shouldn't hold a reference since we'll be told when the content
// leaves the document or the document will be destroyed.
mElements.AppendElement(aContent);
return NS_OK;
}
NS_IMETHODIMP
nsBaseContentList::RemoveElement(nsIContent *aContent)
{
mElements.RemoveElement(aContent);
return NS_OK;
}
NS_IMETHODIMP
nsBaseContentList::IndexOf(nsIContent *aContent, PRInt32& aIndex)
{
aIndex = mElements.IndexOf(aContent);
return NS_OK;
}
NS_IMETHODIMP
nsBaseContentList::Reset()
{
mElements.Clear();
return NS_OK;
}
// nsFormContentList
// This helper function checks if aContent is in some way associated
// with aForm, this check is only successful if the form is a
// container (and a form is a container as long as the document is
// wellformed). If the form is a container the only elements that are
// considerd to be associated with a form are the elements that are
// contained within the form. If the form is a leaf element then all
// the elements will be accepted into this list.
static PRBool BelongsInForm(nsIDOMHTMLFormElement *aForm,
nsIContent *aContent)
{
nsCOMPtr<nsIContent> form(do_QueryInterface(aForm));
if (!form) {
NS_WARNING("This should not happen, form is not an nsIContent!");
return PR_TRUE;
}
if (form.get() == aContent) {
// The list for aForm contains the form itself, forms should not
// be reachable by name in the form namespace, so we return false
// here.
return PR_FALSE;
}
nsCOMPtr<nsIContent> content;
aContent->GetParent(*getter_AddRefs(content));
while (content) {
if (content == form) {
// aContent is contained within the form so we return true.
return PR_TRUE;
}
nsCOMPtr<nsIAtom> tag;
content->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsHTMLAtoms::form) {
// The child is contained within a form, but not the right form
// so we ignore it.
return PR_FALSE;
}
nsIContent *tmp = content;
tmp->GetParent(*getter_AddRefs(content));
}
PRInt32 count = 0;
form->ChildCount(count);
if (!count) {
// The form is a leaf and aContent wasn't inside any other form so
// we return true
return PR_TRUE;
}
// The form is a container but aContent wasn't inside the form,
// return false
return PR_FALSE;
}
nsFormContentList::nsFormContentList(nsIDOMHTMLFormElement *aForm,
nsBaseContentList& aContentList)
: nsBaseContentList()
{
NS_INIT_REFCNT();
// move elements that belong to mForm into this content list
PRUint32 i, length = 0;
nsCOMPtr<nsIDOMNode> item;
aContentList.GetLength(&length);
for (i = 0; i < length; i++) {
aContentList.Item(i, getter_AddRefs(item));
nsCOMPtr<nsIContent> c(do_QueryInterface(item));
if (c && BelongsInForm(aForm, c)) {
AppendElement(c);
}
}
}
nsFormContentList::~nsFormContentList()
{
Reset();
}
NS_IMETHODIMP
nsFormContentList::AppendElement(nsIContent *aContent)
{
NS_ADDREF(aContent);
return nsBaseContentList::AppendElement(aContent);
}
NS_IMETHODIMP
nsFormContentList::RemoveElement(nsIContent *aContent)
{
PRInt32 i = mElements.IndexOf(aContent);
if (i >= 0) {
nsIContent *content = NS_STATIC_CAST(nsIContent *, mElements.ElementAt(i));
NS_RELEASE(content);
mElements.RemoveElementAt(i);
}
return NS_OK;
}
NS_IMETHODIMP
nsFormContentList::Reset()
{
PRInt32 i, length = mElements.Count();
for (i = 0; i < length; i++) {
nsIContent *content = NS_STATIC_CAST(nsIContent *, mElements.ElementAt(i));
NS_RELEASE(content);
}
return nsBaseContentList::Reset();
}
// nsContentList implementation
nsContentList::nsContentList(const nsContentList& aContentList)
: nsBaseContentList()
{
mFunc = aContentList.mFunc;
mMatchAtom = aContentList.mMatchAtom;
mDocument = aContentList.mDocument;
if (aContentList.mData) {
mData = new nsString(*aContentList.mData);
} else {
mData = nsnull;
}
mMatchAll = aContentList.mMatchAll;
mRootContent = aContentList.mRootContent;
mElements = aContentList.mElements;
}
nsContentList::nsContentList(nsIDocument *aDocument)
: nsBaseContentList()
{
mFunc = nsnull;
mMatchAtom = nsnull;
mDocument = aDocument;
mData = nsnull;
mMatchAll = PR_FALSE;
mRootContent = nsnull;
}
nsContentList::nsContentList(nsIDocument *aDocument,
nsIAtom* aMatchAtom,
PRInt32 aMatchNameSpaceId,
nsIContent* aRootContent)
: nsBaseContentList()
{
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 nsAReadableString& aData,
nsIContent* aRootContent)
: nsBaseContentList()
{
mFunc = aFunc;
if (!aData.IsEmpty()) {
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)
{
// 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 (mDocument) {
mDocument->AddObserver(this);
}
PopulateSelf();
}
nsContentList::~nsContentList()
{
if (mDocument) {
mDocument->RemoveObserver(this);
}
NS_IF_RELEASE(mMatchAtom);
delete mData;
}
NS_INTERFACE_MAP_BEGIN(nsContentList)
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLCollection)
NS_INTERFACE_MAP_END_INHERITING(nsBaseContentList)
NS_IMPL_ADDREF_INHERITED(nsContentList, nsBaseContentList)
NS_IMPL_RELEASE_INHERITED(nsContentList, nsBaseContentList)
NS_IMETHODIMP
nsContentList::GetLength(PRUint32* aLength)
{
nsresult result = CheckDocumentExistence();
if (NS_SUCCEEDED(result)) {
if (mDocument) {
mDocument->FlushPendingNotifications(PR_FALSE);
}
*aLength = mElements.Count();
}
return result;
}
NS_IMETHODIMP
nsContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsresult result = CheckDocumentExistence();
if (NS_SUCCEEDED(result)) {
if (mDocument) {
// Flush pending content changes Bug 4891
mDocument->FlushPendingNotifications(PR_FALSE);
}
nsISupports *element = NS_STATIC_CAST(nsISupports *,
mElements.ElementAt(aIndex));
if (element) {
result = CallQueryInterface(element, aReturn);
}
else {
*aReturn = nsnull;
}
}
return result;
}
NS_IMETHODIMP
nsContentList::NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn)
{
nsresult result = CheckDocumentExistence();
if (NS_SUCCEEDED(result)) {
if (mDocument) {
mDocument->FlushPendingNotifications(PR_FALSE); // Flush pending content changes Bug 4891
}
PRInt32 i, count = mElements.Count();
for (i = 0; i < count; i++) {
nsIContent *content = NS_STATIC_CAST(nsIContent *,
mElements.ElementAt(i));
if (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 CallQueryInterface(content, aReturn);
}
}
}
}
*aReturn = nsnull;
return result;
}
NS_IMETHODIMP
nsContentList::GetScriptObject(nsIScriptContext *aContext,
void** aScriptObject)
{
nsresult res = NS_OK;
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
if (!mScriptObject) {
nsIDOMScriptObjectFactory *factory;
res = nsGenericElement::GetScriptObjectFactory(&factory);
if (NS_FAILED(res)) {
return res;
}
res = factory->NewScriptHTMLCollection(aContext,
NS_STATIC_CAST(nsIDOMNodeList *,
this),
global, &mScriptObject);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;
NS_RELEASE(global);
return res;
}
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++) {
nsCOMPtr<nsIContent> content;
aContainer->ChildAt(i, *getter_AddRefs(content));
if (mMatchAll || MatchSelf(content)) {
repopulate = PR_TRUE;
}
}
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 (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<nsINodeInfo> ni;
aContent->GetNodeInfo(*getter_AddRefs(ni));
if (!ni)
return NS_OK;
nsCOMPtr<nsIDOMNode> 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 (mFunc) {
*aMatch = (*mFunc)(aContent, mData);
}
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 (!mDocument && mRootContent) {
result = mRootContent->GetDocument(mDocument);
if (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) {
mElements.AppendElement(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 (mRootContent) {
PopulateWith(mRootContent, PR_FALSE);
}
else if (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 (!mRootContent) {
return PR_TRUE;
}
else if (mRootContent == aContainer) {
return PR_TRUE;
}
else if (!aContainer) {
return PR_FALSE;
}
else {
nsCOMPtr<nsIContent> parent;
PRBool ret;
aContainer->GetParent(*getter_AddRefs(parent));
ret = IsDescendantOfRoot(parent);
return ret;
}
}
// Does this subtree contain the root?
PRBool
nsContentList::ContainsRoot(nsIContent* aContent)
{
if (!mRootContent) {
return PR_FALSE;
}
else if (mRootContent == aContent) {
return PR_TRUE;
}
else {
PRInt32 i, count;
aContent->ChildCount(count);
for (i = 0; i < count; i++) {
nsCOMPtr<nsIContent> child;
aContent->ChildAt(i, *getter_AddRefs(child));
if (ContainsRoot(child)) {
return PR_TRUE;
}
}
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 (mDocument) {
mDocument->RemoveObserver(this);
mDocument = nsnull;
}
}

View File

@@ -0,0 +1,185 @@
/* -*- 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 nsIDOMHTMLFormElement;
class nsBaseContentList : public nsIDOMNodeList,
public nsIScriptObjectOwner
{
public:
nsBaseContentList();
virtual ~nsBaseContentList();
NS_DECL_ISUPPORTS
// nsIDOMNodeList
NS_DECL_IDOMNODELIST
// nsIScriptObjectOwner
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
NS_IMETHOD AppendElement(nsIContent *aContent);
NS_IMETHOD RemoveElement(nsIContent *aContent);
NS_IMETHOD IndexOf(nsIContent *aContent, PRInt32& aIndex);
NS_IMETHOD Reset();
protected:
nsVoidArray mElements;
void *mScriptObject;
};
// This class is used only by form element code and this is a static
// list of elements. NOTE! This list holds strong references to
// the elements in the list.
class nsFormContentList : public nsBaseContentList
{
public:
nsFormContentList(nsIDOMHTMLFormElement *aForm,
nsBaseContentList& aContentList);
virtual ~nsFormContentList();
NS_IMETHOD AppendElement(nsIContent *aContent);
NS_IMETHOD RemoveElement(nsIContent *aContent);
NS_IMETHOD Reset();
};
class nsContentList : public nsBaseContentList,
public nsIDOMHTMLCollection,
public nsIDocumentObserver
{
public:
NS_DECL_ISUPPORTS_INHERITED
nsContentList(const nsContentList& aContentList);
nsContentList(nsIDocument *aDocument);
nsContentList(nsIDocument *aDocument,
nsIAtom* aMatchAtom,
PRInt32 aMatchNameSpaceId,
nsIContent* aRootContent=nsnull);
nsContentList(nsIDocument *aDocument,
nsContentListMatchFunc aFunc,
const nsAReadableString& aData,
nsIContent* aRootContent=nsnull);
virtual ~nsContentList();
// 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);
// 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);
protected:
nsresult Match(nsIContent *aContent, PRBool *aMatch);
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;
nsIDocument* mDocument;
nsIContent* mRootContent;
PRBool mMatchAll;
};
#endif // nsContentList_h___

View File

@@ -0,0 +1,176 @@
/* -*- 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<nsISimpleEnumerator> 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<nsISupports> item;
while (NS_SUCCEEDED(catEnum->GetNext(getter_AddRefs(item)))) {
nsCOMPtr<nsISupportsString> 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<nsISupports> 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<nsIContentPolicy> 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);
}

View File

@@ -0,0 +1,46 @@
/* -*- 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<nsISupportsArray> mPolicies;
NS_IMETHOD CheckPolicy(PRInt32 policyType, PRInt32 contentType,
nsIDOMElement *element,
const PRUnichar *contentLocation,
PRBool *shouldProceed);
};
nsresult
NS_NewContentPolicy(nsIContentPolicy **aResult);
#endif /* __nsContentPolicy_h__ */

View File

@@ -0,0 +1,273 @@
/* -*- 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 oqr
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* 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):
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the NPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the NPL or the GPL.
*/
/* A namespace class for static layout utilities. */
#include "jsapi.h"
#include "nsCOMPtr.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "nsContentUtils.h"
// static
nsresult
nsContentUtils::GetStaticScriptGlobal(JSContext* aContext,
JSObject* aObj,
nsIScriptGlobalObject** aNativeGlobal)
{
nsISupports* supports;
JSClass* clazz;
JSObject* parent;
JSObject* glob = aObj; // starting point for search
if (!glob)
return NS_ERROR_FAILURE;
while (nsnull != (parent = JS_GetParent(aContext, glob)))
glob = parent;
#ifdef JS_THREADSAFE
clazz = JS_GetClass(aContext, glob);
#else
clazz = JS_GetClass(glob);
#endif
if (!clazz ||
!(clazz->flags & JSCLASS_HAS_PRIVATE) ||
!(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) ||
!(supports = (nsISupports*) JS_GetPrivate(aContext, glob))) {
return NS_ERROR_FAILURE;
}
return supports->QueryInterface(NS_GET_IID(nsIScriptGlobalObject),
(void**) aNativeGlobal);
}
//static
nsresult
nsContentUtils::GetStaticScriptContext(JSContext* aContext,
JSObject* aObj,
nsIScriptContext** aScriptContext)
{
nsCOMPtr<nsIScriptGlobalObject> nativeGlobal;
GetStaticScriptGlobal(aContext, aObj, getter_AddRefs(nativeGlobal));
if (!nativeGlobal)
return NS_ERROR_FAILURE;
nsIScriptContext* scriptContext = nsnull;
nativeGlobal->GetContext(&scriptContext);
*aScriptContext = scriptContext;
return scriptContext ? NS_OK : NS_ERROR_FAILURE;
}
//static
nsresult
nsContentUtils::GetDynamicScriptGlobal(JSContext* aContext,
nsIScriptGlobalObject** aNativeGlobal)
{
nsIScriptGlobalObject* nativeGlobal = nsnull;
nsCOMPtr<nsIScriptContext> scriptCX;
GetDynamicScriptContext(aContext, getter_AddRefs(scriptCX));
if (scriptCX) {
*aNativeGlobal = nativeGlobal = scriptCX->GetGlobalObject();
}
return nativeGlobal ? NS_OK : NS_ERROR_FAILURE;
}
//static
nsresult
nsContentUtils::GetDynamicScriptContext(JSContext *aContext,
nsIScriptContext** aScriptContext)
{
// XXX We rely on the rule that if any JSContext in our JSRuntime has a
// private set then that private *must* be a pointer to an nsISupports.
nsISupports *supports = (nsIScriptContext*) JS_GetContextPrivate(aContext);
if (!supports)
return nsnull;
return supports->QueryInterface(NS_GET_IID(nsIScriptContext),
(void**)aScriptContext);
}
template <class OutputIterator>
struct NormalizeNewlinesCharTraits {
public:
typedef typename OutputIterator::value_type value_type;
public:
NormalizeNewlinesCharTraits(OutputIterator& aIterator) : mIterator(aIterator) { }
void writechar(typename OutputIterator::value_type aChar) {
*mIterator++ = aChar;
}
private:
OutputIterator mIterator;
};
#ifdef HAVE_CPP_PARTIAL_SPECIALIZATION
template <class CharT>
struct NormalizeNewlinesCharTraits<CharT*> {
public:
typedef CharT value_type;
public:
NormalizeNewlinesCharTraits(CharT* aCharPtr) : mCharPtr(aCharPtr) { }
void writechar(CharT aChar) {
*mCharPtr++ = aChar;
}
private:
CharT* mCharPtr;
};
#else
NS_SPECIALIZE_TEMPLATE
struct NormalizeNewlinesCharTraits<char*> {
public:
typedef char value_type;
public:
NormalizeNewlinesCharTraits(char* aCharPtr) : mCharPtr(aCharPtr) { }
void writechar(char aChar) {
*mCharPtr++ = aChar;
}
private:
char* mCharPtr;
};
NS_SPECIALIZE_TEMPLATE
struct NormalizeNewlinesCharTraits<PRUnichar*> {
public:
typedef PRUnichar value_type;
public:
NormalizeNewlinesCharTraits(PRUnichar* aCharPtr) : mCharPtr(aCharPtr) { }
void writechar(PRUnichar aChar) {
*mCharPtr++ = aChar;
}
private:
PRUnichar* mCharPtr;
};
#endif
template <class OutputIterator>
class CopyNormalizeNewlines
{
public:
typedef typename OutputIterator::value_type value_type;
public:
CopyNormalizeNewlines(OutputIterator* aDestination) :
mLastCharCR(PR_FALSE),
mDestination(aDestination),
mWritten(0)
{ }
PRUint32 GetCharsWritten() {
return mWritten;
}
PRUint32 write(const typename OutputIterator::value_type* aSource, PRUint32 aSourceLength) {
// If the last source buffer ended with a CR...
if (mLastCharCR) {
// ..and if the next one is a LF, then skip it since
// we've already written out a newline
if (aSourceLength && (*aSource == value_type('\n'))) {
aSource++;
}
mLastCharCR = PR_FALSE;
}
const typename OutputIterator::value_type* done_writing = aSource + aSourceLength;
PRUint32 num_written = 0;
while ( aSource < done_writing ) {
if (*aSource == value_type('\r')) {
mDestination->writechar('\n');
aSource++;
// If we've reached the end of the buffer, record
// that we wrote out a CR
if (aSource == done_writing) {
mLastCharCR = PR_TRUE;
}
// If the next character is a LF, skip it
else if (*aSource == value_type('\n')) {
aSource++;
}
}
else {
mDestination->writechar(*aSource++);
}
num_written++;
}
mWritten += num_written;
return aSourceLength;
}
private:
PRBool mLastCharCR;
OutputIterator* mDestination;
PRUint32 mWritten;
};
// static
PRUint32
nsContentUtils::CopyNewlineNormalizedUnicodeTo(const nsAReadableString& aSource, PRUint32 aSrcOffset, PRUnichar* aDest, PRUint32 aLength)
{
typedef NormalizeNewlinesCharTraits<PRUnichar*> sink_traits;
sink_traits dest_traits(aDest);
CopyNormalizeNewlines<sink_traits> normalizer(&dest_traits);
nsReadingIterator<PRUnichar> fromBegin, fromEnd;
copy_string(aSource.BeginReading(fromBegin).advance( PRInt32(aSrcOffset) ), aSource.BeginReading(fromEnd).advance( PRInt32(aSrcOffset+aLength) ), normalizer);
return normalizer.GetCharsWritten();
}
// static
PRUint32
nsContentUtils::CopyNewlineNormalizedUnicodeTo(nsReadingIterator<PRUnichar>& aSrcStart, const nsReadingIterator<PRUnichar>& aSrcEnd, nsAWritableString& aDest)
{
typedef nsWritingIterator<PRUnichar> WritingIterator;
typedef NormalizeNewlinesCharTraits<WritingIterator> sink_traits;
WritingIterator iter;
aDest.BeginWriting(iter);
sink_traits dest_traits(iter);
CopyNormalizeNewlines<sink_traits> normalizer(&dest_traits);
copy_string(aSrcStart, aSrcEnd, normalizer);
return normalizer.GetCharsWritten();
}

View File

@@ -0,0 +1,575 @@
/* -*- 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<nsIAtom> 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<nsIAtom> 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<nsIAtom> 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<nsINodeInfo> newNodeInfo;
nsCOMPtr<nsIAtom> 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<nsIAtom> 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;
}

View File

@@ -0,0 +1,107 @@
/* -*- 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<nsINodeInfo> 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___ */

View File

@@ -0,0 +1,476 @@
/* -*- 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<nsINodeInfo> ni;
mContent->NormalizeAttributeString(aAttrName, *getter_AddRefs(ni));
NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE);
PRInt32 nsid;
nsCOMPtr<nsIAtom> 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<nsIDOMAttr> attribute(do_QueryInterface(aNode));
if (!attribute) {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
nsAutoString name, value;
attribute->GetName(name);
nsCOMPtr<nsINodeInfo> ni;
mContent->NormalizeAttributeString(name, *getter_AddRefs(ni));
NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE);
nsCOMPtr<nsIAtom> 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<nsINodeInfo> ni;
mContent->NormalizeAttributeString(aName, *getter_AddRefs(ni));
NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE);
nsCOMPtr<nsIAtom> nameAtom;
PRInt32 nsid;
ni->GetNamespaceID(nsid);
ni->GetNameAtom(*getter_AddRefs(nameAtom));
nsCOMPtr<nsIDOMNode> 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<nsIAtom> 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<nsINodeInfo> ni;
mContent->GetNodeInfo(*getter_AddRefs(ni));
NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE);
nsCOMPtr<nsINodeInfoManager> 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<nsIAtom> nameAtom(dont_AddRef(NS_NewAtom(aLocalName)));
PRInt32 nameSpaceID = kNameSpaceID_None;
nsCOMPtr<nsIAtom> prefix;
nsCOMPtr<nsINodeInfo> ni;
mContent->GetNodeInfo(*getter_AddRefs(ni));
NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE);
nsCOMPtr<nsINodeInfoManager> nimgr;
ni->GetNodeInfoManager(*getter_AddRefs(nimgr));
NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE);
if (aNamespaceURI.Length()) {
nsCOMPtr<nsINameSpaceManager> 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<nsIDOMAttr> attribute(do_QueryInterface(aArg));
if (!attribute) {
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
}
nsAutoString name, nsURI, value;
nsCOMPtr<nsIAtom> nameAtom;
PRInt32 nameSpaceID;
attribute->GetName(name);
attribute->GetPrefix(name);
attribute->GetNamespaceURI(nsURI);
nsCOMPtr<nsINodeInfo> ni;
mContent->GetNodeInfo(*getter_AddRefs(ni));
NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE);
nsCOMPtr<nsINodeInfoManager> 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<nsIAtom> nameAtom(dont_AddRef(NS_NewAtom(aLocalName)));
PRInt32 nameSpaceID = kNameSpaceID_None;
nsCOMPtr<nsIDOMNode> attribute;
nsCOMPtr<nsIAtom> prefix;
nsCOMPtr<nsINodeInfo> ni;
mContent->GetNodeInfo(*getter_AddRefs(ni));
NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE);
nsCOMPtr<nsINodeInfoManager> nimgr;
ni->GetNodeInfoManager(*getter_AddRefs(nimgr));
NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE);
if (aNamespaceURI.Length()) {
nsCOMPtr<nsINameSpaceManager> 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;
*aResult = sizeof(nsDOMAttributeMap);
return NS_OK;
}
#endif

View File

@@ -0,0 +1,73 @@
/* -*- 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___ */

View File

@@ -0,0 +1,117 @@
/* -*- 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 "nsDOMClassInfo.h"
nsDOMClassInfo::nsDOMClassInfo()
{
NS_INIT_REFCNT();
}
nsDOMClassInfo::~nsDOMClassInfo()
{
}
NS_IMPL_ADDREF(nsDOMClassInfo);
NS_IMPL_RELEASE(nsDOMClassInfo);
NS_INTERFACE_MAP_BEGIN(nsDOMClassInfo)
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
nsDOMClassInfo::GetInterfaces(PRUint32 *aCount, nsIID * **aArray)
{
nsAutoVoidArray void_array;
GetIIDs(void_array);
PRInt32 i, count = void_array.Count();
if (!count) {
*aCount = 0;
*aArray = nsnull;
return NS_OK;
}
*aArray = NS_STATIC_CAST(nsIID **, nsMemory::Alloc(count * sizeof(nsIID *)));
NS_ENSURE_TRUE(*aArray, NS_ERROR_OUT_OF_MEMORY);
for (i = 0; i < count; i++) {
*aArray[i] = NS_STATIC_CAST(nsIID *, nsMemory::Alloc(sizeof(nsIID)));
if (!*aArray[i])
break;
*(*aArray[i]) = *NS_STATIC_CAST(nsIID *, void_array.ElementAt(i));
}
if (i != count) {
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, *aArray);
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMClassInfo::GetHelperForLanguage(PRUint32 language, nsISupports **_retval)
{
*_retval = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMClassInfo::GetContractID(char * *aContractID)
{
*aContractID = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMClassInfo::GetClassID(nsCID * *aClassID)
{
*aClassID = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsDOMClassInfo::GetImplementationLanguage(PRUint32 *aImplLanguage)
{
*aImplLanguage = LANGUAGE_CPP;
return NS_OK;
}
NS_IMETHODIMP
nsDOMClassInfo::GetFlags(PRUint32 *aFlags)
{
*aFlags = 0;
return NS_OK;
}

View File

@@ -0,0 +1,104 @@
/* -*- 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 nsDOMClassInfo_h___
#define nsDOMClassInfo_h___
#include "nsIClassInfo.h"
#include "nsVoidArray.h"
class nsDOMClassInfo : public nsIClassInfo
{
public:
nsDOMClassInfo();
virtual ~nsDOMClassInfo();
NS_DECL_ISUPPORTS
NS_DECL_NSICLASSINFO
virtual void GetIIDs(nsVoidArray& aArray) = 0;
};
/**
* nsIClassInfo helper macros
*/
#define __NS_DECL_DOM_CLASSINFO_BODY(_class) \
{ \
public: \
void GetIIDs(nsVoidArray& aArray); \
\
static _class##_dci *sClassInfo; \
};
#define NS_DECL_DOM_CLASSINFO(_class, _baseclass) \
class _class##_dci : public _baseclass##_dci \
__NS_DECL_DOM_CLASSINFO_BODY(_class)
#define NS_DECL_DOM_CLASSINFO_NO_BASE(_class) \
class _class##_dci : public nsDOMClassInfo \
__NS_DECL_DOM_CLASSINFO_BODY(_class)
#define NS_BEGIN_DOM_CLASSINFO_IMPL(_class) \
_class##_dci *_class##_dci::sClassInfo = nsnull; \
\
void _class##_dci::GetIIDs(nsVoidArray& aArray) \
{
#define NS_DOM_CLASSINFO_IID_ENTRY(_interface) \
aArray.AppendElement((void *)&NS_GET_IID(_interface));
#define NS_DOM_CLASSINFO_BASECLASS_IIDS(_base) \
_base##_dci::GetIIDs(aArray);
#define NS_END_DOM_CLASSINFO_DECL_NO_STATIC \
}
#define NS_END_DOM_CLASSINFO_IMPL \
}
#define NS_DEFINE_DOM_CLASSINFO_STATIC(_class) \
_class##_dci *_class##_dci::sClassInfo = nsnull;
#define NS_DOM_INTERFACE_MAP_CLASSINFO(_class) \
if (aIID.Equals(NS_GET_IID(nsIClassInfo))) { \
if (!_class##_dci::sClassInfo) { \
_class##_dci::sClassInfo = new _class##_dci; \
NS_ENSURE_TRUE(_class##_dci::sClassInfo, NS_ERROR_OUT_OF_MEMORY); \
NS_ADDREF(_class##_dci::sClassInfo); \
} \
\
inst = _class##_dci::sClassInfo; \
} else
#endif /* nsDOMClassInfo_h___ */

View File

@@ -0,0 +1,268 @@
/* -*- 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;
}

View File

@@ -0,0 +1,88 @@
/* -*- 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___

View File

@@ -0,0 +1,378 @@
/* -*- 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) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Johnny Stenback <jst@netscape.com> (original author)
*/
#include "nsDOMScriptableHelper.h"
#include "jsapi.h"
#include "nsContentUtils.h"
#include "nsString.h"
#include "nsIServiceManager.h"
// nsHTMLDocument helper includes
#include "nsIDOMDocument.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMNSDocument.h"
#include "nsIDOMLocation.h"
#include "nsIDOMNodeList.h"
// nsHTMLFormElement helper includes
#include "nsIDOMHTMLFormElement.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMNSHTMLFormControlList.h"
jsid nsDOMScriptableHelper::sLocation_id = nsnull;
PRUint32 nsDOMScriptableHelper::sInstanceCount = 0;
nsIXPConnect *nsDOMScriptableHelper::sXPConnect = nsnull;
nsDOMScriptableHelper::nsDOMScriptableHelper()
{
NS_INIT_REFCNT();
if (!sXPConnect) {
nsServiceManager::GetService(nsIXPConnect::GetCID(),
nsIXPConnect::GetIID(),
(nsISupports **)&sXPConnect);
}
sInstanceCount++;
}
nsDOMScriptableHelper::~nsDOMScriptableHelper()
{
sInstanceCount--;
if (!sInstanceCount) {
NS_IF_RELEASE(sXPConnect);
}
}
NS_IMPL_ADDREF(nsDOMScriptableHelper);
NS_IMPL_RELEASE(nsDOMScriptableHelper);
NS_INTERFACE_MAP_BEGIN(nsDOMScriptableHelper)
NS_INTERFACE_MAP_ENTRY(nsIXPCScriptable)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
XPC_IMPLEMENT_FORWARD_CREATE(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_GETFLAGS(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_LOOKUPPROPERTY(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_DEFINEPROPERTY(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_GETPROPERTY(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_SETPROPERTY(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_GETATTRIBUTES(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_SETATTRIBUTES(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_DELETEPROPERTY(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_DEFAULTVALUE(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_ENUMERATE(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_CHECKACCESS(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_CALL(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_CONSTRUCT(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_HASINSTANCE(nsDOMScriptableHelper)
XPC_IMPLEMENT_FORWARD_FINALIZE(nsDOMScriptableHelper)
// static
nsresult
nsDOMScriptableHelper::GetDefaultHelper(void **aHelper)
{
static nsIXPCScriptable *sHelper = nsnull;
if (!sHelper) {
nsresult rv = GetHelperBody(new nsDOMScriptableHelper, &sHelper);
NS_ENSURE_SUCCESS(rv, rv);
}
*aHelper = sHelper;
NS_ADDREF(sHelper);
return NS_OK;
}
nsresult
nsDOMScriptableHelper::GetHelperBody(nsDOMScriptableHelper *aHelper,
nsIXPCScriptable **aStaticHolder)
{
if (!aHelper) {
return NS_ERROR_OUT_OF_MEMORY;
}
*aStaticHolder = aHelper;
return nsContentUtils::ReleaseOnShutdown(NS_REINTERPRET_CAST(nsISupports **,
aStaticHolder));
}
static PRBool
DefineJSId(JSContext *cx, const char *str, jsval *val)
{
JSString *jsstr = ::JS_InternString(cx, str);
if (!jsstr)
return PR_FALSE;
return ::JS_ValueToId(cx, STRING_TO_JSVAL(jsstr), val);
}
// static
nsresult
nsDOMScriptableHelper::DefineStaticJSIds(JSContext *cx)
{
if (!DefineJSId(cx, "location", &sLocation_id))
return NS_ERROR_FAILURE;
return NS_OK;
}
// nsHTMLDocument helper
class nsHTMLDocHelper : nsDOMScriptableHelper
{
public:
virtual ~nsHTMLDocHelper() {};
NS_IMETHOD GetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval);
NS_IMETHOD SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval);
};
NS_IMETHODIMP
nsHTMLDocHelper::GetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
jsval val;
if (!::JS_IdToValue(cx, id, &val))
return NS_ERROR_OUT_OF_MEMORY; // Is this correct?
if (JSVAL_IS_STRING(val)) {
NS_ENSURE_TRUE(sXPConnect, NS_ERROR_NOT_AVAILABLE);
nsCOMPtr<nsISupports> native;
wrapper->GetNative(getter_AddRefs(native));
NS_ABORT_IF_FALSE(native, "No native!");
nsCOMPtr<nsIDOMHTMLDocument> doc(do_QueryInterface(native));
JSString *jsstr = JSVAL_TO_STRING(val);
nsLiteralString prop_name(NS_REINTERPRET_CAST(const PRUnichar *,
::JS_GetStringChars(jsstr)),
::JS_GetStringLength(jsstr));
nsCOMPtr<nsIDOMNodeList> node_list;
doc->GetElementsByName(prop_name, getter_AddRefs(node_list));
if (node_list) {
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = sXPConnect->WrapNative(cx, obj, node_list,
NS_GET_IID(nsIDOMNodeList /* nsISupports */),
getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, rv);
JSObject* prop_obj = nsnull; // XPConnect-wrapped property value.
holder->GetJSObject(&prop_obj);
if (prop_obj) {
*vp = OBJECT_TO_JSVAL(prop_obj);
*retval = PR_TRUE;
return NS_OK;
}
}
}
return arbitrary->GetProperty(cx, obj, id, vp, wrapper, NULL, retval);
}
NS_IMETHODIMP
nsHTMLDocHelper::SetProperty(JSContext *cx, JSObject *obj, jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
if (!DidDefineStaticJSIds()) {
DefineStaticJSIds(cx);
}
if (id == sLocation_id) {
nsCOMPtr<nsISupports> native;
wrapper->GetNative(getter_AddRefs(native));
NS_ABORT_IF_FALSE(native, "No native!");
nsCOMPtr<nsIDOMNSDocument> doc(do_QueryInterface(native));
nsCOMPtr<nsIDOMLocation> location;
doc->GetLocation(getter_AddRefs(location));
if (!location)
return NS_OK;
JSString *jsstr = ::JS_ValueToString(cx, *vp);
if (!jsstr)
return NS_ERROR_OUT_OF_MEMORY;
nsLiteralString str(NS_REINTERPRET_CAST(const PRUnichar *,
::JS_GetStringChars(jsstr)),
::JS_GetStringLength(jsstr));
return location->SetHref(str);
}
return arbitrary->SetProperty(cx, obj, id, vp, wrapper, NULL, retval);
}
// static
nsresult
nsDOMScriptableHelper::GetHTMLDocHelper(void **aHelper)
{
static nsIXPCScriptable *sHelper = nsnull;
if (!sHelper) {
nsresult rv = GetHelperBody(new nsHTMLDocHelper, &sHelper);
NS_ENSURE_SUCCESS(rv, rv);
}
*aHelper = sHelper;
NS_ADDREF(sHelper);
return NS_OK;
}
// nsHTMLFormElement helper
class nsHTMLFormHelper : nsDOMScriptableHelper
{
public:
virtual ~nsHTMLFormHelper() {};
NS_IMETHOD GetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval);
};
NS_IMETHODIMP
nsHTMLFormHelper::GetProperty(JSContext *cx, JSObject *obj,
jsid id, jsval *vp,
nsIXPConnectWrappedNative* wrapper,
nsIXPCScriptable* arbitrary,
JSBool* retval)
{
jsval val;
if (!::JS_IdToValue(cx, id, &val))
return NS_ERROR_OUT_OF_MEMORY; // Is this correct?
if (JSVAL_IS_STRING(val)) {
nsCOMPtr<nsISupports> native;
wrapper->GetNative(getter_AddRefs(native));
NS_ABORT_IF_FALSE(native, "No native!");
nsCOMPtr<nsIDOMHTMLFormElement> element(do_QueryInterface(native));
nsCOMPtr<nsIDOMHTMLCollection> html_collection;
element->GetElements(getter_AddRefs(html_collection));
nsCOMPtr<nsIDOMNSHTMLFormControlList>
form_ctrl_list(do_QueryInterface(html_collection));
JSString *jsstr = JSVAL_TO_STRING(val);
nsLiteralString prop(NS_REINTERPRET_CAST(const PRUnichar *,
::JS_GetStringChars(jsstr)),
::JS_GetStringLength(jsstr));
nsCOMPtr<nsISupports> propValue;
form_ctrl_list->NamedItem(prop, getter_AddRefs(propValue));
if (propValue) {
JSObject* interfaceObject; // XPConnect-wrapped property value.
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = sXPConnect->WrapNative(cx, obj, propValue,
NS_GET_IID(nsISupports),
getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, rv);
holder->GetJSObject(&interfaceObject);
if (interfaceObject) {
*vp = OBJECT_TO_JSVAL(interfaceObject);
*retval = PR_TRUE;
return NS_OK;
}
}
}
return arbitrary->GetProperty(cx, obj, id, vp, wrapper, NULL, retval);
}
// static
nsresult
nsDOMScriptableHelper::GetHTMLFormHelper(void **aHelper)
{
static nsIXPCScriptable *sHelper = nsnull;
if (!sHelper) {
nsresult rv = GetHelperBody(new nsHTMLDocHelper, &sHelper);
NS_ENSURE_SUCCESS(rv, rv);
}
*aHelper = sHelper;
NS_ADDREF(sHelper);
return NS_OK;
}

View File

@@ -0,0 +1,61 @@
/* -*- 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) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Johnny Stenback <jst@netscape.com> (original author)
*/
#ifndef nsDOMScriptableHelper_h___
#define nsDOMScriptableHelper_h___
#include "nsIXPCScriptable.h"
class nsDOMScriptableHelper : public nsIXPCScriptable
{
public:
// nsISupports
NS_DECL_ISUPPORTS
// nsIXPCScriptable
XPC_DECLARE_IXPCSCRIPTABLE
nsDOMScriptableHelper();
virtual ~nsDOMScriptableHelper();
static nsresult GetDefaultHelper(void **aHelper);
static nsresult GetHTMLDocHelper(void **aHelper);
static nsresult GetHTMLFormHelper(void **aHelper);
protected:
PRBool DidDefineStaticJSIds()
{
return sLocation_id;
}
nsresult DefineStaticJSIds(JSContext *cx);
static nsresult GetHelperBody(nsDOMScriptableHelper *aHelper,
nsIXPCScriptable **aStaticHolder);
static jsid sLocation_id;
static nsIXPConnect* sXPConnect;
static PRUint32 sInstanceCount;
};
#endif /* nsDOMScriptableHelper_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,504 @@
/* -*- 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 Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
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 <b>must not</b> 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 AttributeWillChange(nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute);
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);
NS_IMETHOD GetDir(nsAWritableString& aDirection);
NS_IMETHOD SetDir(const nsAReadableString& aDirection);
// 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);
NS_IMETHOD_(PRBool) EventCaptureRegistration(PRInt32 aCapturerIncrement);
// 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 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);
virtual PRBool InternalRegisterCompileEventHandler(JSContext* aContext, jsval aPropName,
jsval *aVp, PRBool aCompile);
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<nsISupportsArray> 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<nsIScriptGlobalObject> mScriptGlobalObject;
nsIEventListenerManager* mListenerManager;
PRBool mInDestructor;
nsDOMStyleSheetList *mDOMStyleSheets;
nsINameSpaceManager* mNameSpaceManager;
nsDocHeaderData* mHeaderData;
nsCOMPtr<nsILineBreaker> mLineBreaker;
nsCOMPtr<nsIWordBreaker> 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<nsIFile> mFileSpec;
PRInt32 mModCount;
nsIDTD* mDTD;
nsCOMPtr<nsIBindingManager> mBindingManager;
nsCOMPtr<nsINodeInfoManager> mNodeInfoManager; // OWNER
nsSupportsHashtable* mBoxObjectTable;
PRInt32 mNumCapturers; //Number of capturing event handlers in doc. Used to optimize event delivery.
private:
// These are not implemented and not supported.
nsDocument(const nsDocument& aOther);
nsDocument& operator=(const nsDocument& aOther);
};
#endif /* nsDocument_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,312 @@
/* -*- 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<nsIDocument> mOwnerDocument;
};
nsresult
NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult,
nsIDocument* aOwnerDocument)
{
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
nsCOMPtr<nsINodeInfoManager> nimgr;
nsCOMPtr<nsINodeInfo> 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<nsIContent> 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<nsIDOMScriptObjectFactory> 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;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
#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();
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,637 @@
/* -*- 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;
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<nsIEventListenerManager> 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<nsIEventListenerManager> 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___ */

View File

@@ -0,0 +1,88 @@
/* -*- 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;
}

View File

@@ -0,0 +1,60 @@
/* -*- 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__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,475 @@
/* -*- 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;
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);
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;
virtual PRBool InternalRegisterCompileEventHandler(JSContext* aContext, jsval aPropName,
jsval *aVp, PRBool aCompile);
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___ */

View File

@@ -0,0 +1,790 @@
/* -*- 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("</")
static const PRInt32 kLongLineLen = 128;
nsresult NS_NewHTMLContentSerializer(nsIContentSerializer** aSerializer)
{
nsHTMLContentSerializer* it = new nsHTMLContentSerializer();
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->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<nsIAtom> 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).get(),
sizeof(kMozStr)-1) == 0) {
continue;
}
aContent->GetAttribute(namespaceID, attrName, valueStr);
//
// Filter out special case of <br type="_moz"> or <br _moz*>,
// 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<nsIDocument> document;
aContent->GetDocument(*getter_AddRefs(document));
if (document) {
nsCOMPtr<nsIURI> 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<nsIContent> 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<nsIAtom> 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<nsIContent> content = do_QueryInterface(aElement);
if (!content) return NS_ERROR_FAILURE;
PRBool hasDirtyAttr = HasDirtyAttr(content);
nsCOMPtr<nsIAtom> 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<nsIParserService> 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<nsIParserService> parserService;
GetParserService(getter_AddRefs(parserService));
if (!parserService) {
NS_ERROR("Can't get parser service");
return;
}
nsReadingIterator<PRUnichar> done_reading;
aStr.EndReading(done_reading);
// for each chunk of |aString|...
PRUint32 advanceLength = 0;
nsReadingIterator<PRUnichar> 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.get();
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<nsIParserService> 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<nsIParserService> 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, 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, 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;
}

View File

@@ -0,0 +1,114 @@
/* -*- 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<nsIParserService> mParserService;
nsCOMPtr<nsIEntityConverter> 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

View File

@@ -0,0 +1,432 @@
/* -*- 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);
}

View File

@@ -0,0 +1,439 @@
/* -*- 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<nsINameSpaceManager> 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<nsINameSpaceManager> 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;
}

View File

@@ -0,0 +1,124 @@
/* -*- 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<nsIAtom> 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___ */

View File

@@ -0,0 +1,312 @@
/* -*- 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<nsIAtom> 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<nsIAtom> name(dont_AddRef(NS_NewAtom(aName)));
NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsIAtom> 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<nsIAtom> name(dont_AddRef(NS_NewAtom(aName)));
NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsIAtom> 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<nsIAtom> nameAtom(dont_AddRef(NS_NewAtom(name)));
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsIAtom> 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;
}

View File

@@ -0,0 +1,83 @@
/* -*- 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<nsINameSpaceManager> 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___ */

View File

@@ -0,0 +1,147 @@
/* -*- 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 "nsParserUtils.h"
#include "nsIParser.h" // for kQuote et. al.
#include "jsapi.h"
// This method starts at aOffSet in aStr and tries to find aChar. It keeps
// skipping whitespace till it finds aChar or some other non-whitespace character. If
// it finds aChar, it returns aChar's offset. If it finds some other non-whitespace character
// or runs into the end of the string, it returns -1.
static PRInt32
FindWhileSkippingWhitespace(nsString& aStr, PRUnichar aChar, PRInt32 aOffset)
{
PRInt32 i = aOffset;
PRUnichar ch = aStr.CharAt(i);
PRInt32 index = -1;
while (ch == '\n' || ch == '\t' || ch == '\r') {
ch = aStr.CharAt(++i);
}
if (ch == aChar)
index = i;
return index;
}
nsresult
nsParserUtils::GetQuotedAttributeValue(nsString& aSource,
const nsString& aAttribute,
nsString& aValue)
{
PRInt32 startOfAttribute = 0; // Index into aSource where the attribute name starts
PRInt32 startOfValue = 0; // Index into aSource where the attribute value starts
PRInt32 posnOfValueDelimeter = 0;
nsresult result = NS_ERROR_FAILURE;
// While there are more characters to look at
while (startOfAttribute != -1) {
// Find the attribute starting at offset
startOfAttribute = aSource.Find(aAttribute, PR_FALSE, startOfAttribute);
// If attribute found
if (startOfAttribute != -1) {
// Find the '=' character while skipping whitespace
startOfValue = FindWhileSkippingWhitespace(aSource, '=', startOfAttribute + aAttribute.Length());
// If '=' found
if (startOfValue != -1) {
PRUnichar delimeter = kQuote;
// Find the quote or apostrophe while skipping whitespace
posnOfValueDelimeter = FindWhileSkippingWhitespace(aSource, kQuote, startOfValue + 1);
if (posnOfValueDelimeter == -1) {
posnOfValueDelimeter = FindWhileSkippingWhitespace(aSource, kApostrophe, startOfValue + 1);
delimeter = kApostrophe;
}
// If quote or apostrophe found
if (posnOfValueDelimeter != -1) {
startOfValue = posnOfValueDelimeter + 1;
// Find the ending quote or apostrophe
posnOfValueDelimeter = aSource.FindChar(delimeter, PR_FALSE, startOfValue);
// If found
if (posnOfValueDelimeter != -1) {
// Set the value of the attibute and exit the loop
// The attribute value starts at startOfValue and ends at (posnOfValueDelimeter - 1)
aSource.Mid(aValue, startOfValue, posnOfValueDelimeter - startOfValue);
result = NS_OK;
break;
}
else {
// Try to find the attribute in the remainder of the string
startOfAttribute++;
continue;
} // Endif found
}
else {
// Try to find the attribute in the remainder of the string
startOfAttribute++;
continue;
} // Endif quote or apostrophe found
}
else {
// Try to find the attribute in the remainder of the string
startOfAttribute++;
continue;
} // Endif '=' found
} // Endif attribute found
} // End while
return result;
}
// XXX Stolen from nsHTMLContentSink. Needs to be shared.
// XXXbe share also with nsRDFParserUtils.cpp and nsHTMLContentSink.cpp
// Returns PR_TRUE if the language name is a version of JavaScript and
// PR_FALSE otherwise
PRBool
nsParserUtils::IsJavaScriptLanguage(const nsString& aName, const char* *aVersion)
{
JSVersion version = JSVERSION_UNKNOWN;
if (aName.EqualsIgnoreCase("JavaScript") ||
aName.EqualsIgnoreCase("LiveScript") ||
aName.EqualsIgnoreCase("Mocha")) {
version = JSVERSION_DEFAULT;
}
else if (aName.EqualsIgnoreCase("JavaScript1.1")) {
version = JSVERSION_1_1;
}
else if (aName.EqualsIgnoreCase("JavaScript1.2")) {
version = JSVERSION_1_2;
}
else if (aName.EqualsIgnoreCase("JavaScript1.3")) {
version = JSVERSION_1_3;
}
else if (aName.EqualsIgnoreCase("JavaScript1.4")) {
version = JSVERSION_1_4;
}
else if (aName.EqualsIgnoreCase("JavaScript1.5")) {
version = JSVERSION_1_5;
}
if (version == JSVERSION_UNKNOWN)
return PR_FALSE;
*aVersion = JS_VersionToString(version);
return PR_TRUE;
}

View File

@@ -0,0 +1,42 @@
/* -*- 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 nsParserUtils_h__
#define nsParserUtils_h__
#include "nsString.h"
class nsParserUtils {
public:
static nsresult
GetQuotedAttributeValue(nsString& aSource,
const nsString& aAttribute,
nsString& aValue);
static PRBool
IsJavaScriptLanguage(const nsString& aName, const char* *aVersion);
};
#endif // nsParserUtils_h__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,208 @@
/* -*- 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 nsPlainTextSerializer_h__
#define nsPlainTextSerializer_h__
#include "nsIContentSerializer.h"
#include "nsIHTMLContentSink.h"
#include "nsHTMLTags.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsILineBreaker.h"
#include "nsIParserService.h"
#include "nsIContent.h"
#include "nsIAtom.h"
#include "nsIHTMLToTextSink.h"
#include "nsIDocumentEncoder.h"
class nsPlainTextSerializer : public nsIContentSerializer,
public nsIHTMLContentSink,
public nsIHTMLToTextSink
{
public:
nsPlainTextSerializer();
virtual ~nsPlainTextSerializer();
NS_DECL_ISUPPORTS
// nsIContentSerializer
NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn,
nsIAtom* aCharSet);
NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAWritableString& aStr);
NS_IMETHOD AppendCDATASection(nsIDOMCDATASection* aCDATASection,
PRInt32 aStartOffset, PRInt32 aEndOffset,
nsAWritableString& aStr) { return NS_OK; }
NS_IMETHOD AppendProcessingInstruction(nsIDOMProcessingInstruction* aPI,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsAWritableString& aStr) { return NS_OK; }
NS_IMETHOD AppendComment(nsIDOMComment* aComment, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAWritableString& aStr) { return NS_OK; }
NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype,
nsAWritableString& aStr) { return NS_OK; }
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement,
nsAWritableString& aStr);
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement,
nsAWritableString& aStr);
NS_IMETHOD Flush(nsAWritableString& aStr);
// nsIContentSink
NS_IMETHOD WillBuildModel(void) { return NS_OK; }
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel) { return NS_OK; }
NS_IMETHOD WillInterrupt(void) { return NS_OK; }
NS_IMETHOD WillResume(void) { return NS_OK; }
NS_IMETHOD SetParser(nsIParser* aParser) { return NS_OK; }
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
NS_IMETHOD NotifyError(const nsParserError* aError) { return NS_OK; }
NS_IMETHOD AddComment(const nsIParserNode& aNode) { return NS_OK; }
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode) { return NS_OK; }
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode, PRInt32 aMode=0) { return NS_OK; }
NS_IMETHOD FlushPendingNotifications() { return NS_OK; }
// nsIHTMLContentSink
NS_IMETHOD SetTitle(const nsString& aValue) { return NS_OK; }
NS_IMETHOD OpenHTML(const nsIParserNode& aNode);
NS_IMETHOD CloseHTML(const nsIParserNode& aNode);
NS_IMETHOD OpenHead(const nsIParserNode& aNode);
NS_IMETHOD CloseHead(const nsIParserNode& aNode);
NS_IMETHOD OpenBody(const nsIParserNode& aNode);
NS_IMETHOD CloseBody(const nsIParserNode& aNode);
NS_IMETHOD OpenForm(const nsIParserNode& aNode);
NS_IMETHOD CloseForm(const nsIParserNode& aNode);
NS_IMETHOD OpenMap(const nsIParserNode& aNode);
NS_IMETHOD CloseMap(const nsIParserNode& aNode);
NS_IMETHOD OpenFrameset(const nsIParserNode& aNode);
NS_IMETHOD CloseFrameset(const nsIParserNode& aNode);
NS_IMETHOD OpenNoscript(const nsIParserNode& aNode);
NS_IMETHOD CloseNoscript(const nsIParserNode& aNode);
NS_IMETHOD DoFragment(PRBool aFlag);
NS_IMETHOD BeginContext(PRInt32 aPosition) { return NS_OK; }
NS_IMETHOD EndContext(PRInt32 aPosition) { return NS_OK; }
// nsIHTMLToTextSink
NS_IMETHOD Initialize(nsAWritableString* aOutString,
PRUint32 aFlags, PRUint32 aWrapCol);
protected:
nsresult GetAttributeValue(nsIAtom* aName, nsString& aValueRet);
void AddToLine(const PRUnichar* aStringToAdd, PRInt32 aLength);
void EndLine(PRBool softlinebreak);
void EnsureVerticalSpace(PRInt32 noOfRows);
void FlushLine();
void OutputQuotesAndIndent();
void Output(nsString& aString);
void Write(const nsAReadableString& aString);
PRBool IsBlockLevel(PRInt32 aId);
PRBool IsContainer(PRInt32 aId);
PRBool IsInPre();
PRBool IsCurrentNodeConverted();
nsresult GetIdForContent(nsIContent* aContent, PRInt32* aID);
nsresult GetParserService(nsIParserService** aParserService);
nsresult DoOpenContainer(PRInt32 aTag);
nsresult DoCloseContainer(PRInt32 aTag);
nsresult DoAddLeaf(PRInt32 aTag, const nsAReadableString& aText);
// Inlined functions
inline PRBool MayWrap()
{
return mWrapColumn &&
((mFlags & nsIDocumentEncoder::OutputFormatted) ||
(mFlags & nsIDocumentEncoder::OutputWrap));
}
inline PRBool DoOutput()
{
return !mInHead;
}
protected:
nsString mCurrentLine;
PRBool mInHead;
PRInt32 mIndent;
// mInIndentString keeps a header that has to be written in the indent.
// That could be, for instance, the bullet in a bulleted list.
nsString mInIndentString;
PRInt32 mCiteQuoteLevel;
PRBool mAtFirstColumn;
PRInt32 mFlags;
// The wrap column is how many standard sized chars (western languages)
// should be allowed on a line. There could be less chars if the chars
// are wider than latin chars of more if the chars are more narrow.
PRUint32 mWrapColumn;
// The width of the line as it will appear on the screen (approx.)
PRUint32 mCurrentLineWidth;
PRBool mDoFragment;
PRInt32 mEmptyLines; // Will be the number of empty lines before
// the current. 0 if we are starting a new
// line and -1 if we are in a line.
PRBool mInWhitespace;
PRBool mPreFormatted;
PRBool mStartedOutput; // we've produced at least a character
nsString mURL;
PRBool mStructs; // Output structs (pref)
PRInt32 mHeaderStrategy; /* Header strategy (pref)
0 = no indention
1 = indention, increased with
header level (default)
2 = numbering and slight indention */
PRInt32 mHeaderCounter[7]; /* For header-numbering:
Number of previous headers of
the same depth and in the same
section.
mHeaderCounter[1] for <h1> etc. */
nsCOMPtr<nsIContent> mContent;
nsIParserNode* mParserNode;
nsAWritableString* mOutputString;
// The tag stack: the stack of tags we're operating on, so we can nest:
nsHTMLTag *mTagStack;
PRUint32 mTagStackIndex;
// The stack for ordered lists:
PRInt32 *mOLStack;
PRUint32 mOLStackIndex;
nsString mLineBreak;
nsCOMPtr<nsILineBreaker> mLineBreaker;
nsCOMPtr<nsIParserService> mParserService;
// Conveniance constant. It would be nice to have it as a const static
// variable, but that causes issues with OpenBSD and module unloading.
const nsString kSpace;
};
extern nsresult NS_NewPlainTextSerializer(nsIContentSerializer** aSerializer);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,239 @@
/* -*- 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 nsRange_h___
#define nsRange_h___
/*
* nsRange.h: interface of the nsRange object.
*/
#include "nsIDOMRange.h"
#include "nsIDOMNSRange.h"
#include "nsCOMPtr.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
#include "nsIScriptObjectOwner.h"
#include "prmon.h"
class nsVoidArray;
class nsRange : public nsIDOMRange,
public nsIDOMNSRange,
public nsIScriptObjectOwner
{
public:
NS_DECL_ISUPPORTS
nsRange();
virtual ~nsRange();
// for layout module destructor
static void Shutdown();
// nsIDOMRange interface
NS_IMETHOD GetIsPositioned(PRBool* aIsPositioned);
NS_IMETHOD GetStartContainer(nsIDOMNode** aStartParent);
NS_IMETHOD GetStartOffset(PRInt32* aStartOffset);
NS_IMETHOD GetEndContainer(nsIDOMNode** aEndParent);
NS_IMETHOD GetEndOffset(PRInt32* aEndOffset);
NS_IMETHOD GetCollapsed(PRBool* aIsCollapsed);
NS_IMETHOD GetCommonAncestorContainer(nsIDOMNode** aCommonParent);
NS_IMETHOD SetStart(nsIDOMNode* aParent, PRInt32 aOffset);
NS_IMETHOD SetStartBefore(nsIDOMNode* aSibling);
NS_IMETHOD SetStartAfter(nsIDOMNode* aSibling);
NS_IMETHOD SetEnd(nsIDOMNode* aParent, PRInt32 aOffset);
NS_IMETHOD SetEndBefore(nsIDOMNode* aSibling);
NS_IMETHOD SetEndAfter(nsIDOMNode* aSibling);
NS_IMETHOD Collapse(PRBool aToStart);
NS_IMETHOD Unposition();
NS_IMETHOD SelectNode(nsIDOMNode* aN);
NS_IMETHOD SelectNodeContents(nsIDOMNode* aN);
NS_IMETHOD CompareBoundaryPoints(PRUint16 how, nsIDOMRange* srcRange, PRInt32* ret);
NS_IMETHOD DeleteContents();
NS_IMETHOD ExtractContents(nsIDOMDocumentFragment** aReturn);
NS_IMETHOD CloneContents(nsIDOMDocumentFragment** aReturn);
NS_IMETHOD InsertNode(nsIDOMNode* aN);
NS_IMETHOD SurroundContents(nsIDOMNode* aN);
NS_IMETHOD CloneRange(nsIDOMRange** aReturn);
NS_IMETHOD Detach();
NS_IMETHOD ToString(nsAWritableString& aReturn);
/*BEGIN nsIDOMNSRange interface implementations*/
NS_IMETHOD CreateContextualFragment(const nsAReadableString& aFragment,
nsIDOMDocumentFragment** aReturn);
NS_IMETHOD IsValidFragment(const nsAReadableString& aFragment, PRBool* aReturn);
NS_IMETHOD IsPointInRange(nsIDOMNode* aParent, PRInt32 aOffset,
PRBool* aResult);
NS_IMETHOD ComparePoint(nsIDOMNode* aParent, PRInt32 aOffset,
PRInt16* aResult);
NS_IMETHOD IntersectsNode(nsIDOMNode* aNode, PRBool* aReturn);
NS_IMETHOD CompareNode(nsIDOMNode* aNode, PRUint16* aReturn);
NS_IMETHOD NSDetach();
/*END nsIDOMNSRange interface implementations*/
NS_IMETHOD GetHasGeneratedBefore(PRBool *aBool);
NS_IMETHOD GetHasGeneratedAfter(PRBool *aBool);
NS_IMETHOD SetHasGeneratedBefore(PRBool aBool);
NS_IMETHOD SetHasGeneratedAfter(PRBool aBool);
NS_IMETHOD SetBeforeAndAfter(PRBool aBefore, PRBool aAfter);
/*BEGIN nsIScriptObjectOwner interface implementations*/
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
/*END nsIScriptObjectOwner interface implementations*/
// nsRange interface extensions
static NS_METHOD OwnerGone(nsIContent* aParentNode);
static NS_METHOD OwnerChildInserted(nsIContent* aParentNode, PRInt32 aOffset);
static NS_METHOD OwnerChildRemoved(nsIContent* aParentNode, PRInt32 aOffset, nsIContent* aRemovedNode);
static NS_METHOD OwnerChildReplaced(nsIContent* aParentNode, PRInt32 aOffset, nsIContent* aReplacedNode);
static NS_METHOD TextOwnerChanged(nsIContent* aTextNode, PRInt32 aStartOffset, PRInt32 aEndOffset, PRInt32 aReplaceLength);
//private: I wish VC++ would give me a &&*@!#$ break
PRBool mIsPositioned;
PRBool mIsDetached;
PRInt32 mStartOffset;
PRInt32 mEndOffset;
nsCOMPtr<nsIDOMNode> mStartParent;
nsCOMPtr<nsIDOMNode> mEndParent;
static PRMonitor *mMonitor; // monitor to protect the following statics
static nsVoidArray *mStartAncestors; // just keeping these static to avoid reallocing the arrays.
static nsVoidArray *mEndAncestors; // the contents of these arrays are discarded across calls.
static nsVoidArray *mStartAncestorOffsets; // this also makes nsRange objects lighter weight.
static nsVoidArray *mEndAncestorOffsets; //
// no copy's or assigns
nsRange(const nsRange&);
nsRange& operator=(const nsRange&);
// helper routines
static PRBool InSameDoc(nsIDOMNode* aNode1, nsIDOMNode* aNode2);
static PRInt32 IndexOf(nsIDOMNode* aNode);
static PRInt32 FillArrayWithAncestors(nsVoidArray* aArray,nsIDOMNode* aNode);
static PRInt32 GetAncestorsAndOffsets(nsIDOMNode* aNode, PRInt32 aOffset,
nsVoidArray* aAncestorNodes, nsVoidArray* aAncestorOffsets);
static nsCOMPtr<nsIDOMNode> CommonParent(nsIDOMNode* aNode1, nsIDOMNode* aNode2);
static nsresult GetDOMNodeFromContent(nsIContent* inContentNode, nsCOMPtr<nsIDOMNode>* outDomNode);
static nsresult GetContentFromDOMNode(nsIDOMNode* inDomNode, nsCOMPtr<nsIContent>* outContentNode);
static nsresult PopRanges(nsIDOMNode* aDestNode, PRInt32 aOffset, nsIContent* aSourceNode);
static nsresult Lock();
static nsresult Unlock();
static nsresult CloneSibsAndParents(nsIDOMNode* parentNode,
PRInt32 nodeOffset,
nsIDOMNode* clonedNode,
nsIDOMNode* commonParent,
nsIDOMDocumentFragment* docfrag,
PRBool leftP);
nsresult DoSetRange(nsIDOMNode* aStartN, PRInt32 aStartOffset,
nsIDOMNode* aEndN, PRInt32 aEndOffset);
PRBool IsIncreasing(nsIDOMNode* aStartN, PRInt32 aStartOff,
nsIDOMNode* aEndN, PRInt32 aEndOff);
PRBool IsDetached(){return mIsDetached;}
nsresult ComparePointToRange(nsIDOMNode* aParent, PRInt32 aOffset, PRInt32* aResult);
nsresult AddToListOf(nsIDOMNode* aNode);
nsresult RemoveFromListOf(nsIDOMNode* aNode);
nsresult ContentOwnsUs(nsIDOMNode* domNode);
protected:
void* mScriptObject;
PRBool mBeforeGenContent;
PRBool mAfterGenContent;
};
// Make a new nsIDOMRange object
nsresult NS_NewRange(nsIDOMRange** aInstancePtrResult);
/*************************************************************************************
* Utility routine to compare two "points", were a point is a node/offset pair
* Returns -1 if point1 < point2, 1, if point1 > point2,
* 0 if error or if point1 == point2.
************************************************************************************/
PRInt32 ComparePoints(nsIDOMNode* aParent1, PRInt32 aOffset1,
nsIDOMNode* aParent2, PRInt32 aOffset2);
/*************************************************************************************
* Utility routine to detect if a content node intersects a range
************************************************************************************/
PRBool IsNodeIntersectsRange(nsIContent* aNode, nsIDOMRange* aRange);
/*************************************************************************************
* Utility routine to detect if a content node starts before a range and/or
* ends after a range. If neither it is contained inside the range.
*
* XXX - callers responsibility to ensure node in same doc as range!
*
************************************************************************************/
nsresult CompareNodeToRange(nsIContent* aNode,
nsIDOMRange* aRange,
PRBool *outNodeBefore,
PRBool *outNodeAfter);
/*************************************************************************************
* Utility routine to create a pair of dom points to represent
* the start and end locations of a single node. Return false
* if we dont' succeed.
************************************************************************************/
PRBool GetNodeBracketPoints(nsIContent* aNode,
nsCOMPtr<nsIDOMNode>* outParent,
PRInt32* outStartOffset,
PRInt32* outEndOffset);
#endif /* nsRange_h___ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,96 @@
/* -*- 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 "nsTextContentChangeData.h"
// Create a new instance of nsTextContentChangeData with a refcnt of 1
nsresult
NS_NewTextContentChangeData(nsTextContentChangeData** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
nsTextContentChangeData* it = new nsTextContentChangeData();
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(it);
*aResult = it;
return NS_OK;
}
nsTextContentChangeData::nsTextContentChangeData()
: mType(Insert),
mOffset(0),
mLength(0),
mReplaceLength(0)
{
NS_INIT_REFCNT();
}
nsTextContentChangeData::~nsTextContentChangeData()
{
}
NS_IMPL_ISUPPORTS1(nsTextContentChangeData, nsITextContentChangeData);
NS_IMETHODIMP
nsTextContentChangeData::GetChangeType(ChangeType* aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mType;
return NS_OK;
}
NS_IMETHODIMP
nsTextContentChangeData::GetReplaceData(PRInt32* aOffset,
PRInt32* aSourceLength,
PRInt32* aReplaceLength)
{
NS_ENSURE_ARG_POINTER(aOffset);
NS_ENSURE_ARG_POINTER(aSourceLength);
NS_ENSURE_ARG_POINTER(aReplaceLength);
*aOffset = mOffset;
*aSourceLength = mLength;
*aReplaceLength = mReplaceLength;
return NS_OK;
}
NS_IMETHODIMP
nsTextContentChangeData::GetInsertData(PRInt32* aOffset,
PRInt32* aInsertLength)
{
NS_ENSURE_ARG_POINTER(aOffset);
NS_ENSURE_ARG_POINTER(aInsertLength);
*aOffset = mOffset;
*aInsertLength = mLength;
return NS_OK;
}
NS_IMETHODIMP
nsTextContentChangeData::GetAppendData(PRInt32* aOffset,
PRInt32* aAppendLength)
{
NS_ENSURE_ARG_POINTER(aOffset);
NS_ENSURE_ARG_POINTER(aAppendLength);
*aOffset = mOffset;
*aAppendLength = mLength;
return NS_OK;
}

View File

@@ -0,0 +1,72 @@
/* -*- 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 nsTextContentChangeData_h___
#define nsTextContentChangeData_h___
#include "nsITextContent.h"
class nsTextContentChangeData : public nsITextContentChangeData {
public:
friend nsresult
NS_NewTextContentChangeData(nsTextContentChangeData** aResult);
// nsISupports
NS_DECL_ISUPPORTS
// nsITextContentChangedData
NS_IMETHOD GetChangeType(ChangeType* aResult);
NS_IMETHOD GetReplaceData(PRInt32* aOffset,
PRInt32* aSourceLength,
PRInt32* aReplaceLength);
NS_IMETHOD GetInsertData(PRInt32* aOffset,
PRInt32* aInsertLength);
NS_IMETHOD GetAppendData(PRInt32* aOffset,
PRInt32* aAppendLength);
void SetData(ChangeType aType, PRInt32 aOffset, PRInt32 aLength) {
mType = aType;
mOffset = aOffset;
mLength = aLength;
}
void SetReplaceLength(PRInt32 aReplaceLength) {
mReplaceLength = aReplaceLength;
}
protected:
nsTextContentChangeData();
virtual ~nsTextContentChangeData();
ChangeType mType;
PRInt32 mOffset;
PRInt32 mLength;
PRInt32 mReplaceLength; // only used for replace type
};
// Create a new instance of nsTextContentChangeData with a refcnt of 1
extern nsresult
NS_NewTextContentChangeData(nsTextContentChangeData** aResult);
#endif /* nsTextContentChangeData_h___ */

View File

@@ -0,0 +1,267 @@
/* -*- 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 "nsIDOMText.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMEventReceiver.h"
#include "nsIContent.h"
#include "nsITextContent.h"
#include "nsGenericDOMDataNode.h"
#include "nsIDocument.h"
#include "nsCRT.h"
#include "nsLayoutAtoms.h"
class nsTextNode : public nsIDOMText,
public nsIScriptObjectOwner,
public nsITextContent
{
public:
nsTextNode();
virtual ~nsTextNode();
// nsISupports
NS_DECL_ISUPPORTS
// nsIDOMNode
NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(mInner)
// nsIDOMCharacterData
NS_IMPL_IDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(mInner)
// nsIDOMText
NS_IMPL_IDOMTEXT_USING_GENERIC_DOM_DATA(mInner)
// nsIScriptObjectOwner
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 {
return mInner.SizeOf(aSizer, aResult, sizeof(*this));
}
// nsITextContent
NS_IMPL_ITEXTCONTENT_USING_GENERIC_DOM_DATA(mInner)
protected:
nsGenericDOMDataNode mInner;
PRUint32 mContentID;
};
nsresult
NS_NewTextNode(nsIContent** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsTextNode* it;
NS_NEWXPCOM(it, nsTextNode);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(NS_GET_IID(nsIContent), (void **) aInstancePtrResult);
}
nsTextNode::nsTextNode()
{
NS_INIT_REFCNT();
mContentID = 0;
}
nsTextNode::~nsTextNode()
{
}
NS_IMPL_ADDREF(nsTextNode)
NS_IMPL_RELEASE(nsTextNode)
NS_IMETHODIMP
nsTextNode::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
NS_IMPL_DOM_DATA_QUERY_INTERFACE(aIID, aInstancePtr, this)
if (aIID.Equals(NS_GET_IID(nsIDOMText))) {
nsIDOMText* 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
nsTextNode::GetTag(nsIAtom*& aResult) const
{
aResult = nsLayoutAtoms::textTagName;
NS_ADDREF(aResult);
return NS_OK;
}
NS_IMETHODIMP
nsTextNode::GetNodeInfo(nsINodeInfo*& aResult) const
{
aResult = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsTextNode::GetNodeName(nsAWritableString& aNodeName)
{
aNodeName.Assign(NS_LITERAL_STRING("#text"));
return NS_OK;
}
NS_IMETHODIMP
nsTextNode::GetNodeType(PRUint16* aNodeType)
{
*aNodeType = (PRUint16)nsIDOMNode::TEXT_NODE;
return NS_OK;
}
NS_IMETHODIMP
nsTextNode::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
{
nsresult result = NS_OK;
nsTextNode* it;
NS_NEWXPCOM(it, nsTextNode);
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
nsTextNode::CloneContent(PRBool aCloneText, nsITextContent** aReturn)
{
nsresult result = NS_OK;
nsTextNode* it;
NS_NEWXPCOM(it, nsTextNode);
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
nsTextNode::List(FILE* out, PRInt32 aIndent) const
{
NS_PRECONDITION(nsnull != mInner.mDocument, "bad content");
PRInt32 index;
for (index = aIndent; --index >= 0; ) fputs(" ", out);
fprintf(out, "Text@%p refcount=%d<", this, mRefCnt);
nsAutoString tmp;
mInner.ToCString(tmp, 0, mInner.mText.GetLength());
fputs(tmp, out);
fputs(">\n", out);
return NS_OK;
}
NS_IMETHODIMP
nsTextNode::DumpContent(FILE* out, PRInt32 aIndent,PRBool aDumpAll) const
{
NS_PRECONDITION(nsnull != mInner.mDocument, "bad content");
if(aDumpAll) {
PRInt32 index;
for (index = aIndent; --index >= 0; ) fputs(" ", out);
nsAutoString tmp;
mInner.ToCString(tmp, 0, mInner.mText.GetLength());
if(!tmp.EqualsWithConversion("\\n")) {
fputs(tmp, out);
if(aIndent) fputs("\n", out);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsTextNode::HandleDOMEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus* aEventStatus)
{
return mInner.HandleDOMEvent(aPresContext, aEvent, aDOMEvent,
aFlags, aEventStatus);
}
NS_IMETHODIMP
nsTextNode::GetContentID(PRUint32* aID)
{
*aID = mContentID;
return NS_OK;
}
NS_IMETHODIMP
nsTextNode::SetContentID(PRUint32 aID)
{
mContentID = aID;
return NS_OK;
}

View File

@@ -0,0 +1,639 @@
/* -*- 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 "nsXMLContentSerializer.h"
#include "nsIDOMText.h"
#include "nsIDOMCDATASection.h"
#include "nsIDOMProcessingInstruction.h"
#include "nsIDOMComment.h"
#include "nsIDOMDocumentType.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsINameSpaceManager.h"
#include "nsITextContent.h"
#include "nsTextFragment.h"
#include "nsString.h"
#include "prprf.h"
typedef struct {
nsString mPrefix;
nsString mURI;
nsIDOMElement* mOwner;
} NameSpaceDecl;
nsresult NS_NewXMLContentSerializer(nsIContentSerializer** aSerializer)
{
nsXMLContentSerializer* it = new nsXMLContentSerializer();
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(NS_GET_IID(nsIContentSerializer), (void**)aSerializer);
}
nsXMLContentSerializer::nsXMLContentSerializer()
{
NS_INIT_ISUPPORTS();
mPrefixIndex = 0;
mInAttribute = PR_FALSE;
}
nsXMLContentSerializer::~nsXMLContentSerializer()
{
}
NS_IMPL_ISUPPORTS1(nsXMLContentSerializer, nsIContentSerializer)
NS_IMETHODIMP
nsXMLContentSerializer::Init(PRUint32 flags, PRUint32 aWrapColumn,
nsIAtom* aCharSet)
{
return NS_OK;
}
nsresult
nsXMLContentSerializer::AppendTextData(nsIDOMNode* aNode,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsAWritableString& aStr,
PRBool aTranslateEntities,
PRBool aIncrColumn)
{
nsCOMPtr<nsITextContent> content(do_QueryInterface(aNode));
if (!content) return NS_ERROR_FAILURE;
const nsTextFragment* frag;
content->GetText(&frag);
if (frag) {
PRInt32 length = ((aEndOffset == -1) ? frag->GetLength() : aEndOffset) - aStartOffset;
if (frag->Is2b()) {
AppendToString(nsLiteralString(frag->Get2b()+aStartOffset, length),
aStr,
aTranslateEntities,
aIncrColumn);
}
else {
AppendToString(NS_ConvertASCIItoUCS2(frag->Get1b()+aStartOffset, length),
aStr,
aTranslateEntities,
aIncrColumn);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsXMLContentSerializer::AppendText(nsIDOMText* aText,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsAWritableString& aStr)
{
NS_ENSURE_ARG(aText);
return AppendTextData(aText, aStartOffset, aEndOffset, aStr, PR_TRUE, PR_TRUE);
}
NS_IMETHODIMP
nsXMLContentSerializer::AppendCDATASection(nsIDOMCDATASection* aCDATASection,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsAWritableString& aStr)
{
NS_ENSURE_ARG(aCDATASection);
nsresult rv;
AppendToString(NS_LITERAL_STRING("<![CDATA["), aStr);
rv = AppendTextData(aCDATASection, aStartOffset, aEndOffset, aStr, PR_FALSE, PR_TRUE);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
AppendToString(NS_LITERAL_STRING("]]>"), aStr);
return NS_OK;
}
NS_IMETHODIMP
nsXMLContentSerializer::AppendProcessingInstruction(nsIDOMProcessingInstruction* aPI,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsAWritableString& aStr)
{
NS_ENSURE_ARG(aPI);
nsresult rv;
nsAutoString target, data;
rv = aPI->GetTarget(target);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = aPI->GetData(data);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
AppendToString(NS_LITERAL_STRING("<?"), aStr);
AppendToString(target, aStr);
if (data.Length() > 0) {
AppendToString(NS_LITERAL_STRING(" "), aStr);
AppendToString(data, aStr);
}
AppendToString(NS_LITERAL_STRING("?>"), aStr);
return NS_OK;
}
NS_IMETHODIMP
nsXMLContentSerializer::AppendComment(nsIDOMComment* aComment,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsAWritableString& aStr)
{
NS_ENSURE_ARG(aComment);
nsresult rv;
nsAutoString data;
rv = aComment->GetData(data);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
AppendToString(NS_LITERAL_STRING("<!--"), aStr);
if (aStartOffset || (aEndOffset != -1)) {
PRInt32 length = (aEndOffset == -1) ? data.Length() : aEndOffset;
length -= aStartOffset;
nsAutoString frag;
data.Mid(frag, aStartOffset, length);
AppendToString(frag, aStr);
}
else {
AppendToString(data, aStr);
}
AppendToString(NS_LITERAL_STRING("-->"), aStr);
return NS_OK;
}
NS_IMETHODIMP
nsXMLContentSerializer::AppendDoctype(nsIDOMDocumentType *aDoctype,
nsAWritableString& aStr)
{
NS_ENSURE_ARG(aDoctype);
nsresult rv;
nsAutoString name, publicId, systemId, internalSubset;
rv = aDoctype->GetName(name);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = aDoctype->GetPublicId(publicId);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = aDoctype->GetSystemId(systemId);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = aDoctype->GetInternalSubset(internalSubset);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
AppendToString(NS_LITERAL_STRING("<!DOCTYPE "), aStr);
AppendToString(name, aStr);
PRUnichar quote;
if (publicId.Length() > 0) {
AppendToString(NS_LITERAL_STRING(" PUBLIC "), aStr);
if (publicId.FindChar(PRUnichar('"')) == -1) {
quote = PRUnichar('"');
}
else {
quote = PRUnichar('\'');
}
AppendToString(quote, aStr);
AppendToString(publicId, aStr);
AppendToString(quote, aStr);
if (systemId.Length()) {
AppendToString(PRUnichar(' '), aStr);
if (systemId.FindChar(PRUnichar('"')) == -1) {
quote = PRUnichar('"');
}
else {
quote = PRUnichar('\'');
}
AppendToString(quote, aStr);
AppendToString(systemId, aStr);
AppendToString(quote, aStr);
}
}
else if (systemId.Length() > 0) {
if (systemId.FindChar(PRUnichar('"')) == -1) {
quote = PRUnichar('"');
}
else {
quote = PRUnichar('\'');
}
AppendToString(NS_LITERAL_STRING(" SYSTEM "), aStr);
AppendToString(quote, aStr);
AppendToString(systemId, aStr);
AppendToString(quote, aStr);
}
if (internalSubset.Length() > 0) {
AppendToString(PRUnichar(' '), aStr);
AppendToString(internalSubset, aStr);
}
AppendToString(NS_LITERAL_STRING(">"), aStr);
return NS_OK;
}
#define kXMLNS NS_LITERAL_STRING("xmlns")
nsresult
nsXMLContentSerializer::PushNameSpaceDecl(const nsAReadableString& aPrefix,
const nsAReadableString& aURI,
nsIDOMElement* aOwner)
{
NameSpaceDecl* decl = new NameSpaceDecl();
if (!decl) return NS_ERROR_OUT_OF_MEMORY;
decl->mPrefix.Assign(aPrefix);
decl->mURI.Assign(aURI);
// Don't addref - this weak reference will be removed when
// we pop the stack
decl->mOwner = aOwner;
mNameSpaceStack.AppendElement((void*)decl);
return NS_OK;
}
void
nsXMLContentSerializer::PopNameSpaceDeclsFor(nsIDOMElement* aOwner)
{
PRInt32 index, count;
count = mNameSpaceStack.Count();
for (index = count - 1; index >= 0; index--) {
NameSpaceDecl* decl = (NameSpaceDecl*)mNameSpaceStack.ElementAt(index);
if (decl->mOwner != aOwner) {
break;
}
mNameSpaceStack.RemoveElementAt(index);
delete decl;
}
}
/* ConfirmPrefix() is needed for cases where scripts have
* moved/modified elements/attributes
*/
PRBool
nsXMLContentSerializer::ConfirmPrefix(nsAWritableString& aPrefix,
const nsAReadableString& aURI)
{
if (aPrefix.Equals(kXMLNS)) {
return PR_FALSE;
}
if (aURI.Length() == 0) {
aPrefix.Truncate();
return PR_FALSE;
}
PRInt32 index, count;
nsAutoString closestURIMatch;
PRBool uriMatch = PR_FALSE;
count = mNameSpaceStack.Count();
for (index = count - 1; index >= 0; index--) {
NameSpaceDecl* decl = (NameSpaceDecl*)mNameSpaceStack.ElementAt(index);
// Check if we've found a prefix match
if (aPrefix.Equals(decl->mPrefix)) {
// If the URI's match, we don't have to add a namespace decl
if (aURI.Equals(decl->mURI)) {
return PR_FALSE;
}
// If they don't, we can't use this prefix
else {
aPrefix.Truncate();
}
}
// If we've found a URI match, then record the first one
else if (!uriMatch && aURI.Equals(decl->mURI)) {
uriMatch = PR_TRUE;
closestURIMatch.Assign(decl->mPrefix);
}
}
// There are no namespace declarations that match the prefix, uri pair.
// If there's another prefix that matches that URI, us it.
if (uriMatch) {
aPrefix.Assign(closestURIMatch);
return PR_FALSE;
}
// If we don't have a prefix, create one
else if (aPrefix.Length() == 0) {
aPrefix.Assign(NS_LITERAL_STRING("a"));
char buf[128];
PR_snprintf(buf, sizeof(buf), "%d", mPrefixIndex++);
aPrefix.Append(NS_ConvertASCIItoUCS2(buf));
}
// Indicate that we need to create a namespace decl for the
// final prefix
return PR_TRUE;
}
void
nsXMLContentSerializer::SerializeAttr(const nsAReadableString& aPrefix,
const nsAReadableString& aName,
const nsAReadableString& aValue,
nsAWritableString& aStr)
{
AppendToString(PRUnichar(' '), aStr);
if (aPrefix.Length() > 0) {
AppendToString(aPrefix, aStr);
AppendToString(NS_LITERAL_STRING(":"), aStr);
}
AppendToString(aName, aStr);
AppendToString(NS_LITERAL_STRING("=\""), aStr);
mInAttribute = PR_TRUE;
AppendToString(aValue, aStr, PR_TRUE);
mInAttribute = PR_FALSE;
AppendToString(NS_LITERAL_STRING("\""), aStr);
}
NS_IMETHODIMP
nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
nsAWritableString& aStr)
{
NS_ENSURE_ARG(aElement);
nsAutoString tagPrefix, tagLocalName, tagNamespaceURI;
nsAutoString xmlnsStr;
xmlnsStr.Assign(kXMLNS);
nsCOMPtr<nsIContent> content(do_QueryInterface(aElement));
if (!content) return NS_ERROR_FAILURE;
aElement->GetPrefix(tagPrefix);
aElement->GetLocalName(tagLocalName);
aElement->GetNamespaceURI(tagNamespaceURI);
PRInt32 namespaceID, elementNamespaceID;
content->GetNameSpaceID(elementNamespaceID);
if (elementNamespaceID == kNameSpaceID_HTML)
tagLocalName.ToLowerCase(); // XXX We shouldn't need this hack
PRInt32 index, count;
nsAutoString nameStr, prefixStr, uriStr, valueStr;
nsCOMPtr<nsIAtom> attrName, attrPrefix;
content->GetAttributeCount(count);
// First scan for namespace declarations, pushing each on the stack
for (index = 0; index < count; index++) {
content->GetAttributeNameAt(index,
namespaceID,
*getter_AddRefs(attrName),
*getter_AddRefs(attrPrefix));
if (namespaceID == kNameSpaceID_XMLNS ||
elementNamespaceID == kNameSpaceID_HTML /*XXX Hack*/) {
PRBool hasPrefix = attrPrefix ? PR_TRUE : PR_FALSE;
content->GetAttribute(namespaceID, attrName, uriStr);
attrName->ToString(nameStr);
// XXX We shouldn't need this hack
if (elementNamespaceID == kNameSpaceID_HTML) {
if (nameStr.EqualsWithConversion("xmlns:",PR_FALSE,6)) {
nameStr.Cut(0,6);
hasPrefix = PR_TRUE;
} else if (!nameStr.Equals(kXMLNS)) {
continue;
}
}
if (!hasPrefix) {
// Default NS attribute does not have prefix (and the name is "xmlns")
PushNameSpaceDecl(nsString(), uriStr, aElement);
} else {
PushNameSpaceDecl(nameStr, uriStr, aElement);
}
}
}
PRBool addNSAttr;
addNSAttr = ConfirmPrefix(tagPrefix, tagNamespaceURI);
// Serialize the qualified name of the element
AppendToString(NS_LITERAL_STRING("<"), aStr);
if (tagPrefix.Length() > 0 &&
!(elementNamespaceID == kNameSpaceID_HTML && tagPrefix.Equals(kXMLNS) /*XXX Hack*/)) {
AppendToString(tagPrefix, aStr);
AppendToString(NS_LITERAL_STRING(":"), aStr);
}
AppendToString(tagLocalName, aStr);
// If we had to add a new namespace declaration, serialize
// and push it on the namespace stack
if (addNSAttr) {
SerializeAttr(xmlnsStr, tagPrefix, tagNamespaceURI, aStr);
PushNameSpaceDecl(tagPrefix, tagNamespaceURI, aElement);
}
// Now serialize each of the attributes
// XXX Unfortunately we need a namespace manager to get
// attribute URIs.
nsCOMPtr<nsIDocument> document;
nsCOMPtr<nsINameSpaceManager> nsmanager;
content->GetDocument(*getter_AddRefs(document));
if (document) {
document->GetNameSpaceManager(*getter_AddRefs(nsmanager));
}
for (index = 0; index < count; index++) {
content->GetAttributeNameAt(index,
namespaceID,
*getter_AddRefs(attrName),
*getter_AddRefs(attrPrefix));
if (attrPrefix) {
attrPrefix->ToString(prefixStr);
}
else {
prefixStr.Truncate();
}
addNSAttr = PR_FALSE;
if (kNameSpaceID_XMLNS != namespaceID && nsmanager) {
nsmanager->GetNameSpaceURI(namespaceID, uriStr);
addNSAttr = ConfirmPrefix(prefixStr, uriStr);
}
content->GetAttribute(namespaceID, attrName, valueStr);
attrName->ToString(nameStr);
if (elementNamespaceID == kNameSpaceID_HTML && nameStr.Equals(NS_LITERAL_STRING("xmlns:xmlns")))
nameStr.Assign(kXMLNS); // XXX Shouldn't need this hack, breaks case where there really is xmlns:xmlns
SerializeAttr(prefixStr, nameStr, valueStr, aStr);
if (addNSAttr) {
SerializeAttr(xmlnsStr, prefixStr, uriStr, aStr);
PushNameSpaceDecl(prefixStr, uriStr, aElement);
}
}
// We don't output a separate end tag for empty element
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(aElement));
PRBool hasChildren;
if (NS_SUCCEEDED(node->HasChildNodes(&hasChildren)) && !hasChildren) {
AppendToString(NS_LITERAL_STRING("/>"), aStr);
} else {
AppendToString(NS_LITERAL_STRING(">"), aStr);
}
return NS_OK;
}
NS_IMETHODIMP
nsXMLContentSerializer::AppendElementEnd(nsIDOMElement *aElement,
nsAWritableString& aStr)
{
NS_ENSURE_ARG(aElement);
// We don't output a separate end tag for empty element
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(aElement));
PRBool hasChildren;
if (NS_SUCCEEDED(node->HasChildNodes(&hasChildren)) && !hasChildren) {
return NS_OK;
}
nsCOMPtr<nsIContent> content(do_QueryInterface(aElement));
if (!content) return NS_ERROR_FAILURE;
nsAutoString tagPrefix, tagLocalName, tagNamespaceURI;
aElement->GetPrefix(tagPrefix);
aElement->GetLocalName(tagLocalName);
aElement->GetNamespaceURI(tagNamespaceURI);
PRInt32 namespaceID;
content->GetNameSpaceID(namespaceID);
if (namespaceID == kNameSpaceID_HTML)
tagLocalName.ToLowerCase(); // XXX We shouldn't need this hack
ConfirmPrefix(tagPrefix, tagNamespaceURI);
AppendToString(NS_LITERAL_STRING("</"), aStr);
if (tagPrefix.Length() > 0 &&
!(namespaceID == kNameSpaceID_HTML && tagPrefix.Equals(kXMLNS) /*XXX Hack*/)) {
AppendToString(tagPrefix, aStr);
AppendToString(NS_LITERAL_STRING(":"), aStr);
}
AppendToString(tagLocalName, aStr);
AppendToString(NS_LITERAL_STRING(">"), aStr);
PopNameSpaceDeclsFor(aElement);
return NS_OK;
}
void
nsXMLContentSerializer::AppendToString(const PRUnichar* aStr,
PRInt32 aLength,
nsAWritableString& aOutputStr)
{
PRInt32 length = (aLength == -1) ? nsCRT::strlen(aStr) : aLength;
aOutputStr.Append(aStr, length);
}
void
nsXMLContentSerializer::AppendToString(const PRUnichar aChar,
nsAWritableString& aOutputStr)
{
aOutputStr.Append(aChar);
}
static PRUint16 kGTVal = 62;
static const char* kEntities[] = {
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "&amp;", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"&lt;", "", "&gt;"
};
static const char* kAttrEntities[] = {
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "&quot;", "", "", "", "&amp;", "&apos;",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"&lt;", "", "&gt;"
};
void
nsXMLContentSerializer::AppendToString(const nsAReadableString& aStr,
nsAWritableString& aOutputStr,
PRBool aTranslateEntities,
PRBool aIncrColumn)
{
if (aTranslateEntities) {
nsReadingIterator<PRUnichar> done_reading;
aStr.EndReading(done_reading);
// for each chunk of |aString|...
PRUint32 advanceLength = 0;
nsReadingIterator<PRUnichar> 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;
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;
}
}
aOutputStr.Append(fragmentStart, advanceLength);
if (entityText) {
aOutputStr.Append(NS_ConvertASCIItoUCS2(entityText));
advanceLength++;
}
}
return;
}
aOutputStr.Append(aStr);
}

View File

@@ -0,0 +1,103 @@
/* -*- 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 nsXMLContentSerializer_h__
#define nsXMLContentSerializer_h__
#include "nsIContentSerializer.h"
#include "nsISupportsUtils.h"
#include "nsCOMPtr.h"
#include "nsVoidArray.h"
class nsIDOMNode;
class nsXMLContentSerializer : public nsIContentSerializer {
public:
nsXMLContentSerializer();
virtual ~nsXMLContentSerializer();
NS_DECL_ISUPPORTS
NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn,
nsIAtom* aCharSet);
NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAWritableString& aStr);
NS_IMETHOD AppendCDATASection(nsIDOMCDATASection* aCDATASection,
PRInt32 aStartOffset, PRInt32 aEndOffset,
nsAWritableString& aStr);
NS_IMETHOD AppendProcessingInstruction(nsIDOMProcessingInstruction* aPI,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsAWritableString& aStr);
NS_IMETHOD AppendComment(nsIDOMComment* aComment, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAWritableString& aStr);
NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype,
nsAWritableString& aStr);
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement,
nsAWritableString& aStr);
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement,
nsAWritableString& aStr);
NS_IMETHOD Flush(nsAWritableString& aStr) { return NS_OK; }
protected:
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);
nsresult AppendTextData(nsIDOMNode* aNode,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsAWritableString& aStr,
PRBool aTranslateEntities,
PRBool aIncrColumn);
virtual nsresult PushNameSpaceDecl(const nsAReadableString& aPrefix,
const nsAReadableString& aURI,
nsIDOMElement* aOwner);
void PopNameSpaceDeclsFor(nsIDOMElement* aOwner);
PRBool ConfirmPrefix(nsAWritableString& aPrefix,
const nsAReadableString& aURI);
void SerializeAttr(const nsAReadableString& aPrefix,
const nsAReadableString& aName,
const nsAReadableString& aValue,
nsAWritableString& aStr);
PRInt32 mPrefixIndex;
nsVoidArray mNameSpaceStack;
PRBool mInAttribute;
};
extern nsresult NS_NewXMLContentSerializer(nsIContentSerializer** aSerializer);
#endif

View File

@@ -0,0 +1,5 @@
#
# This is a list of local files which get copied to the mozilla:dist:content directory
#
nsContentCID.h

View File

@@ -0,0 +1,110 @@
#
# 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):
#
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
BUILD_DATE = gbdate.h
MODULE = layout
LIBRARY_NAME = gkcontent
SHORT_LIBNAME = gkcontnt
IS_COMPONENT = 1
EXTRA_DSO_LIBS = jsdom gkgfx
REQUIRES = xpcom string widget necko rdf docshell dom htmlparser uriloader webshell locale unicharutil lwbrk timer js pref caps xul xuldoc xultmpl
CPPSRCS = \
nsContentDLF.cpp \
nsContentFactory.cpp \
nsContentModule.cpp \
nsContentHTTPStartup.cpp \
$(NULL)
ifndef MKSHLIB_FORCE_ALL
CPPSRCS += dlldeps.cpp
endif
EXPORTS = nsContentCID.h
SHARED_LIBRARY_LIBS = \
$(DIST)/lib/libgkconevents_s.$(LIB_SUFFIX) \
$(DIST)/lib/libgkconhtmlcon_s.$(LIB_SUFFIX) \
$(DIST)/lib/libgkconhtmldoc_s.$(LIB_SUFFIX) \
$(DIST)/lib/libgkconhtmlstyle_s.$(LIB_SUFFIX) \
$(DIST)/lib/libgkconxmlcon_s.$(LIB_SUFFIX) \
$(DIST)/lib/libgkconxmldoc_s.$(LIB_SUFFIX) \
$(DIST)/lib/libgkconxsldoc_s.$(LIB_SUFFIX) \
$(DIST)/lib/libgkconxulcon_s.$(LIB_SUFFIX) \
$(DIST)/lib/libgkconxuldoc_s.$(LIB_SUFFIX) \
$(DIST)/lib/libgkconxultmpl_s.$(LIB_SUFFIX) \
$(DIST)/lib/libgkconxbl_s.$(LIB_SUFFIX) \
$(DIST)/lib/libgkconbase_s.$(LIB_SUFFIX) \
$(DIST)/lib/libgkconshared_s.$(LIB_SUFFIX) \
$(NULL)
ifdef MOZ_PERF_METRICS
SHARED_LIBRARY_LIBS += \
$(DIST)/lib/libmozutil_s.$(LIB_SUFFIX) \
$(NULL)
endif
EXTRA_DSO_LDOPTS = \
-L$(DIST)/bin \
$(EXTRA_DSO_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(MOZ_JS_LIBS) \
$(NULL)
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
EXPORT_OBJS = 1
endif
include $(topsrcdir)/config/rules.mk
DEFINES += -D_IMPL_NS_HTML
INCLUDES += -I$(srcdir)/../base/src \
-I$(srcdir)/../html/base/src \
-I$(srcdir)/../html/style/src \
-I$(srcdir)/../xul/content/src \
-I$(srcdir)/../xul/base/src \
-I$(srcdir)/../xul/templates/src \
-I$(srcdir)/../events/src \
-I. \
$(NULL)
GARBAGE+=$(BUILD_DATE)
export:: $(BUILD_DATE)
$(BUILD_DATE): gbdate.pl
$(RM) $@
$(PERL) $(srcdir)/gbdate.pl > $@
# To prevent ILink from crashing
ifeq ($(MOZ_OS2_TOOLS),VACPP)
OS_DLLFLAGS := ilink /FREE /NOE /NOL /DLL /O:ngcontent.dll /M /INC:_dllentry
endif

View File

@@ -0,0 +1,38 @@
/* -*- 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):
*/
// Force references to all of the symbols that we want exported from
// the dll that are located in the .lib files we link with
#include "nsIDocument.h"
#include "nsHTMLParts.h"
#include "nsINameSpaceManager.h"
void XXXNeverCalled()
{
nsIDocument* doc;
NS_NewHTMLDocument(&doc);
NS_NewImageDocument(&doc);
nsINameSpaceManager* nsm;
NS_NewNameSpaceManager(&nsm);
NS_CreateHTMLElement(nsnull, nsnull);
}

27
mozilla/content/build/gbdate.pl Executable file
View File

@@ -0,0 +1,27 @@
#
# 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):
#
# XP way of doing the build date.
# 1998091509 = 1998, September, 15th, 9am local time zone
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
# localtime returns year minus 1900
$year = $year + 1900;
printf("#define PRODUCT_VERSION NS_LITERAL_STRING(\"%04d%02d%02d\").get()\n", $year, 1+$mon, $mday);

View File

@@ -0,0 +1,98 @@
#!nmake
#
# 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):
DEPTH=..\..
include <$(DEPTH)/config/config.mak>
DEFINES=-D_IMPL_NS_HTML
MODULE=raptor
IS_COMPONENT = 1
CPP_OBJS= \
.\$(OBJDIR)\dlldeps.obj \
.\$(OBJDIR)\nsContentDLF.obj \
.\$(OBJDIR)\nsContentFactory.obj \
.\$(OBJDIR)\nsContentModule.obj \
.\$(OBJDIR)\nsContentHTTPStartup.obj \
$(NULL)
EXPORTS=nsContentCID.h
MAKE_OBJ_TYPE = DLL
DLLNAME = gkcontent
DLL=.\$(OBJDIR)\$(DLLNAME).dll
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\dom \
-I$(PUBLIC)\js -I..\html\base\src -I..\base\src \
-I..\html\style\src \
-I..\xul\content\src \
-I..\xul\templates\src \
-I..\xul\base\src \
-I..\events\src \
-I$(PUBLIC)\rdf
# These are the libraries we need to link with to create the dll
LLIBS= \
$(DIST)\lib\contentbase_s.lib \
$(DIST)\lib\contenthtmlcontent_s.lib \
$(DIST)\lib\contenthtmldoc_s.lib \
$(DIST)\lib\contenthtmlstyle_s.lib \
$(DIST)\lib\contentxmlcontent_s.lib \
$(DIST)\lib\contentxmldoc_s.lib \
$(DIST)\lib\contentxsldoc_s.lib \
$(DIST)\lib\contentxulcontent_s.lib \
$(DIST)\lib\contentxuldocument_s.lib \
$(DIST)\lib\contentxultemplates_s.lib \
$(DIST)\lib\contentxbl_s.lib \
$(DIST)\lib\contentevents_s.lib \
$(DIST)\lib\contentshared_s.lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\gkgfxwin.lib \
$(DIST)\lib\timer_s.lib \
$(DIST)\lib\jsdom.lib \
$(DIST)\lib\js32$(VERSION_NUMBER).lib \
!if defined(MOZ_PERF)
$(DIST)\lib\util.lib \
!endif
$(LIBNSPR)
include <$(DEPTH)\config\rules.mak>
install:: gbdate.h $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
clobber::
rm -f $(DIST)\bin\$(DLLNAME).dll
rm -f $(DIST)\lib\$(DLLNAME).lib
rm -f gbdate.h
gbdate.h:: gbdate.pl
$(PERL) gbdate.pl > gbdate.h

View File

@@ -0,0 +1,256 @@
/* -*- 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 nsContentCID_h__
#define nsContentCID_h__
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIComponentManager.h"
// {1691E1F7-EE41-11d4-9885-00C04FA0CF4B}
#define NS_STYLESET_CID \
{ 0x1691e1f7, 0xee41, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {96882B70-8A27-11d2-8EAF-00805F29F370}
#define NS_HTMLSTYLESHEET_CID \
{ 0x96882b70, 0x8a27, 0x11d2, { 0x8e, 0xaf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {972D8D8F-F0DA-11d4-9885-00C04FA0CF4B}
#define NS_DOCUMENT_VIEWER_CID \
{ 0x972d8d8f, 0xf0da, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {A5121627-EDB6-11d4-9885-00C04FA0CF4B}
#define NS_ANONYMOUSCONTENT_CID \
{ 0xa5121627, 0xedb6, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {FC886801-E768-11d4-9885-00C04FA0CF4B}
#define NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID \
{ 0xfc886801, 0xe768, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
/* a6cf90f9-15b3-11d2-932e-00805f8add32 */
#define NS_LAYOUT_DEBUGGER_CID \
{ 0xa6cf90f9, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
/* a6cf90fc-15b3-11d2-932e-00805f8add32 */
#define NS_HTML_ELEMENT_FACTORY_CID \
{ 0xa6cf90fc, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
#define NS_HTMLDOCUMENT_CID \
{ /* 5d0fcdd0-4daa-11d2-b328-00805f8a3859 */ \
0x5d0fcdd0, 0x4daa, 0x11d2, \
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
#define NS_XMLDOCUMENT_CID \
{ /* a6cf9063-15b3-11d2-932e-00805f8add32 */ \
0xa6cf9063, 0x15b3, 0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
#define NS_XML_ELEMENT_FACTORY_CID \
{ /* CF170391-79CC-11d3-BE44-0020A6361667 */ \
0xcf170391, 0x79cc, 0x11d3, \
{0xbe, 0x44, 0x0, 0x20, 0xa6, 0x36, 0x16, 0x67}}
#define NS_IMAGEDOCUMENT_CID \
{ /* e11a6080-4daa-11d2-b328-00805f8a3859 */ \
0xe11a6080, 0x4daa, 0x11d2, \
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
// {A1FDE864-E802-11d4-9885-00C04FA0CF4B}
#define NS_HTMLHRELEMENT_CID \
{ 0xa1fde864, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {A1FDE865-E802-11d4-9885-00C04FA0CF4B}
#define NS_HTMLINPUTELEMENT_CID \
{ 0xa1fde865, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {A1FDE866-E802-11d4-9885-00C04FA0CF4B}
#define NS_HTMLATTRIBUTES_CID \
{ 0xa1fde866, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
#define NS_HTMLIMAGEELEMENT_CID \
{ /* d6008c40-4dad-11d2-b328-00805f8a3859 */ \
0xd6008c40, 0x4dad, 0x11d2, \
{0xb3, 0x28, 0x00, 0x80, 0x5f, 0x8a, 0x38, 0x59}}
#define NS_HTMLOPTIONELEMENT_CID \
{ /* a6cf90f5-15b3-11d2-932e-00805f8add32 */ \
0xa6cf90f5, 0x15b3, 0x11d2, \
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
#define NS_NAMESPACEMANAGER_CID \
{ /* d9783472-8fe9-11d2-9d3c-0060088f9ff7 */ \
0xd9783472, 0x8fe9, 0x11d2, \
{0x9d, 0x3c, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
/* a6cf90d7-15b3-11d2-932e-00805f8add32 */
#define NS_FRAME_UTIL_CID \
{ 0xa6cf90d5, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
// XXX This should really be factored into a style-specific DLL so
// that all the HTML, generic layout, and style stuff isn't munged
// together.
// {2E363D60-872E-11d2-B531-000000000000}
#define NS_CSSPARSER_CID \
{ 0x2e363d60, 0x872e, 0x11d2, { 0xb5, 0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {95F46161-D177-11d2-BF86-00105A1B0627}
#define NS_HTML_CSS_STYLESHEET_CID \
{ 0x95f46161, 0xd177, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {A1FDE867-E802-11d4-9885-00C04FA0CF4B}
#define NS_CSS_STYLESHEET_CID \
{ 0xa1fde867, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {eaca2576-0d4a-11d3-9d7e-0060088f9ff7}
#define NS_CSS_LOADER_CID \
{ 0xeaca2576, 0x0d4a, 0x11d3, { 0x9d, 0x7e, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7 } }
// {96882B71-8A27-11d2-8EAF-00805F29F370}
#define NS_TEXTNODE_CID \
{ 0x96882b71, 0x8a27, 0x11d2, { 0x8e, 0xaf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {96882B72-8A27-11d2-8EAF-00805F29F370}
#define NS_SELECTION_CID \
{ 0x96882b72, 0x8a27, 0x11d2, { 0x8e, 0xaf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
#define NS_FRAMESELECTION_CID \
{/* {905F80F1-8A7B-11d2-918C-0080C8E44DB5}*/ \
0x905f80f1, 0x8a7b, 0x11d2, { 0x91, 0x8c, 0x0, 0x80, 0xc8, 0xe4, 0x4d, 0xb5 } }
#define NS_DOMSELECTION_CID \
{/* {C87A37FC-8109-4ce2-A322-8CDEC925379F}*/ \
0xc87a37fc, 0x8109, 0x4ce2, { 0xa3, 0x22, 0x8c, 0xde, 0xc9, 0x25, 0x37, 0x9f } }
#define NS_RANGE_CID \
{/* {56AD2981-8A87-11d2-918C-0080C8E44DB5}*/ \
0x56ad2981, 0x8a87, 0x11d2, { 0x91, 0x8c, 0x0, 0x80, 0xc8, 0xe4, 0x4d, 0xb5 } }
// {A1FDE868-E802-11d4-9885-00C04FA0CF4B}
#define NS_ATTRIBUTECONTENT_CID \
{ 0xa1fde868, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
#define NS_CONTENTITERATOR_CID \
{/* {a6cf90e3-15b3-11d2-932e-00805f8add32}*/ \
0xa6cf90e3, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
#define NS_GENERATEDSUBTREEITERATOR_CID \
{/* {9A45253B-EB8F-49f1-B925-E9EA90D3EB3A}*/ \
0x9a45253b, 0xeb8f, 0x49f1, { 0xb9, 0x25, 0xe9, 0xea, 0x90, 0xd3, 0xeb, 0x3a } }
#define NS_GENERATEDCONTENTITERATOR_CID \
{/* {A364930F-E353-49f1-AC69-91637EB8B757}*/ \
0xa364930f, 0xe353, 0x49f1, { 0xac, 0x69, 0x91, 0x63, 0x7e, 0xb8, 0xb7, 0x57 } }
#define NS_SUBTREEITERATOR_CID \
{/* {a6cf90e5-15b3-11d2-932e-00805f8add32}*/ \
0xa6cf90e5, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
// {09F689E0-B4DA-11d2-A68B-00104BDE6048}
#define NS_EVENTLISTENERMANAGER_CID \
{ 0x9f689e0, 0xb4da, 0x11d2, { 0xa6, 0x8b, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
// {A1FDE862-E802-11d4-9885-00C04FA0CF4B}
#define NS_EVENTSTATEMANAGER_CID \
{ 0xa1fde862, 0xe802, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
// {64F300A1-C88C-11d3-97FB-00400553EEF0}
#define NS_XBLSERVICE_CID \
{ 0x64f300a1, 0xc88c, 0x11d3, { 0x97, 0xfb, 0x0, 0x40, 0x5, 0x53, 0xee, 0xf0 } }
// {15671AF5-39F9-4c70-8CE3-72C97111B52D}
#define NS_BINDINGMANAGER_CID \
{ 0x15671af5, 0x39f9, 0x4c70, { 0x8c, 0xe3, 0x72, 0xc9, 0x71, 0x11, 0xb5, 0x2d } }
// 3a9cd622-264d-11d4-ba06-0060b0fc76dd
#define NS_DOM_IMPLEMENTATION_CID \
{ 0x3a9cd622, 0x264d, 0x11d4, {0xba, 0x06, 0x00, 0x60, 0xb0, 0xfc, 0x76, 0xdd } }
// {AE52FE52-683A-437D-B661-DE55F4E0A873}
#define NS_NODEINFOMANAGER_CID \
{ 0xae52fe52, 0x683a, 0x437d, { 0xb6, 0x61, 0xde, 0x55, 0xf4, 0xe0, 0xa8, 0x73 } }
// {ECEA1B28-AE54-4047-8BBE-C624235106B4}
#define NS_COMPUTEDDOMSTYLE_CID \
{ 0xecea1b28, 0xae54, 0x4047, { 0x8b, 0xbe, 0xc6, 0x24, 0x23, 0x51, 0x06, 0xb4 } }
// {4aef38b7-6364-4e23-a5e7-12f837fbbd9c}
#define NS_XMLCONTENTSERIALIZER_CID \
{ 0x4aef38b7, 0x6364, 0x4e23, { 0xa5, 0xe7, 0x12, 0xf8, 0x37, 0xfb, 0xbd, 0x9c } }
// {9d3f70da-86e9-11d4-95ec-00b0d03e37b7}
#define NS_HTMLCONTENTSERIALIZER_CID \
{ 0x9d3f70da, 0x86e9, 0x11d4, { 0x95, 0xec, 0x00, 0xb0, 0xd0, 0x3e, 0x37, 0xb7 } }
// {6030f7ef-32ed-46a7-9a63-6a5d3f90445f}
#define NS_PLAINTEXTSERIALIZER_CID \
{ 0x6030f7ef, 0x32ed, 0x46a7, { 0x9a, 0x63, 0x6a, 0x5d, 0x3f, 0x90, 0x44, 0x5f } }
// {3986B301-097C-11d3-BF87-00105A1B0627}
#define NS_XULPOPUPLISTENER_CID \
{ 0x3986b301, 0x97c, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {1F5C1721-7DC3-11d3-BF87-00105A1B0627}
#define NS_XULCONTROLLERS_CID \
{ 0x1f5c1721, 0x7dc3, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {daedcb43-1dd1-11b2-b1d2-caf06cb40387}
#define NS_DLGDEFAULTKEYS_CID \
{ 0xdaedcb43, 0x1dd1, 0x11b2, { 0xb1, 0xd2, 0xca, 0xf0, 0x6c, 0xb4, 0x3, 0x87 } }
// {76E92881-CDDB-11d3-BF87-00105A1B0627}
#define NS_XULELEMENTFACTORY_CID \
{ 0x76e92881, 0xcddb, 0x11d3, { 0xbf, 0x87, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {508f5601-e09b-11d3-9f7e-cf931f9f173c}
#define NS_CONTROLLERCOMMANDMANAGER_CID \
{ 0x508f5601, 0xe09b, 0x11d3, { 0x9f, 0x7e, 0xcf, 0x93, 0x1f, 0x9f, 0x17, 0x3c } }
// {BFD05264-834C-11d2-8EAC-00805F29F371}
#define NS_XULSORTSERVICE_CID \
{ 0xbfd05264, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x71 } }
// {3D262D00-8B5A-11d2-8EB0-00805F29F370}
#define NS_XULTEMPLATEBUILDER_CID \
{ 0x3d262d00, 0x8b5a, 0x11d2, { 0x8e, 0xb0, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {1abdcc96-1dd2-11b2-b520-f8f59cdd67bc}
#define NS_XULOUTLINERBUILDER_CID \
{ 0x1abdcc96, 0x1dd2, 0x11b2, { 0xb5, 0x20, 0xf8, 0xf5, 0x9c, 0xdd, 0x67, 0xbc } }
// {CE058B21-BA9C-11d2-BF86-00105A1B0627}
#define NS_XULCONTENTSINK_CID \
{ 0xce058b21, 0xba9c, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {541AFCB2-A9A3-11d2-8EC5-00805F29F370}
#define NS_XULDOCUMENT_CID \
{ 0x541afcb2, 0xa9a3, 0x11d2, { 0x8e, 0xc5, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {3A0A0FC1-8349-11d3-BE47-00104BDE6048}
#define NS_XULPROTOTYPECACHE_CID \
{ 0x3a0a0fc1, 0x8349, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
#endif /* nsContentCID_h__ */

View File

@@ -0,0 +1,532 @@
/* -*- 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 "nsCOMPtr.h"
#include "nsContentModule.h"
#include "nsIComponentManager.h"
#include "nsIDocumentLoader.h"
#include "nsIDocumentLoaderFactory.h"
#include "nsIDocument.h"
#include "nsIDocumentViewer.h"
#include "nsIURL.h"
#include "nsICSSStyleSheet.h"
#include "nsString.h"
#include "nsContentCID.h"
#include "prprf.h"
#include "nsNetUtil.h"
#include "nsICSSLoader.h"
#include "nsRDFCID.h"
#include "nsIRDFResource.h"
#include "nsIXULContentSink.h"
#include "nsIDocStreamLoaderFactory.h"
#define VIEW_SOURCE_HTML
// URL for the "user agent" style sheet
#define UA_CSS_URL "resource:/res/ua.css"
// Factory code for creating variations on html documents
#undef NOISY_REGISTRY
static NS_DEFINE_IID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID);
static NS_DEFINE_IID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID);
static NS_DEFINE_IID(kXULDocumentCID, NS_XULDOCUMENT_CID);
extern nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult);
static char* gHTMLTypes[] = {
"text/html",
"text/plain",
"text/rtf",
"text/cpp",
"text/css",
0
};
static char* gXMLTypes[] = {
"text/xml",
"application/xml",
0
};
static char* gRDFTypes[] = {
"text/rdf",
"text/xul",
"text/cached-xul",
0
};
static char* gImageTypes[] = {
"image/gif",
"image/jpeg",
"image/png",
"image/x-png",
"image/x-art",
"image/x-jg",
0
};
class nsContentDLF : public nsIDocumentLoaderFactory,
public nsIDocStreamLoaderFactory
{
public:
nsContentDLF();
virtual ~nsContentDLF();
NS_DECL_ISUPPORTS
// for nsIDocumentLoaderFactory
NS_IMETHOD CreateInstance(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
const char* aContentType,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIStreamListener** aDocListener,
nsIContentViewer** aDocViewer);
NS_IMETHOD CreateInstanceForDocument(nsISupports* aContainer,
nsIDocument* aDocument,
const char *aCommand,
nsIContentViewer** aDocViewerResult);
// for nsIDocStreamLoaderFactory
NS_METHOD CreateInstance(nsIInputStream& aInputStream,
const char* aContentType,
const char* aCommand,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIContentViewer** aDocViewer);
nsresult InitUAStyleSheet();
nsresult CreateDocument(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
nsISupports* aContainer,
const nsCID& aDocumentCID,
nsIStreamListener** aDocListener,
nsIContentViewer** aDocViewer);
nsresult CreateRDFDocument(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
const char* aContentType,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIStreamListener** aDocListener,
nsIContentViewer** aDocViewer);
nsresult CreateXULDocumentFromStream(nsIInputStream& aXULStream,
const char* aCommand,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIContentViewer** aDocViewer);
nsresult CreateRDFDocument(nsISupports*,
nsCOMPtr<nsIDocument>*,
nsCOMPtr<nsIDocumentViewer>*);
static nsICSSStyleSheet* GetUAStyleSheet() {
return nsContentModule::gUAStyleSheet;
}
};
nsresult
NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult)
{
NS_PRECONDITION(aResult, "null OUT ptr");
if (!aResult) {
return NS_ERROR_NULL_POINTER;
}
nsContentDLF* it = new nsContentDLF();
if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(NS_GET_IID(nsIDocumentLoaderFactory), (void**)aResult);
}
nsContentDLF::nsContentDLF()
{
NS_INIT_REFCNT();
}
nsContentDLF::~nsContentDLF()
{
}
NS_IMPL_ADDREF(nsContentDLF)
NS_IMPL_RELEASE(nsContentDLF)
NS_IMETHODIMP
nsContentDLF::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
{
if (NULL == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
if (aIID.Equals(NS_GET_IID(nsIDocumentLoaderFactory))) {
nsIDocumentLoaderFactory *tmp = this;
*aInstancePtrResult = (void*) tmp;
AddRef();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIDocStreamLoaderFactory))) {
nsIDocStreamLoaderFactory *tmp = this;
*aInstancePtrResult = (void*) tmp;
AddRef();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
nsIDocumentLoaderFactory *tmp = this;
nsISupports *tmp2 = tmp;
*aInstancePtrResult = (void*) tmp2;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsContentDLF::CreateInstance(const char *aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
const char* aContentType,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIStreamListener** aDocListener,
nsIContentViewer** aDocViewer)
{
nsresult rv = NS_OK;
if (!GetUAStyleSheet()) {
// Load the UA style sheet
nsCOMPtr<nsIURI> uaURL;
rv = NS_NewURI(getter_AddRefs(uaURL), UA_CSS_URL);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsICSSLoader> cssLoader;
rv = NS_NewCSSLoader(getter_AddRefs(cssLoader));
if (cssLoader) {
PRBool complete;
rv = cssLoader->LoadAgentSheet(uaURL, nsContentModule::gUAStyleSheet, complete,
nsnull);
}
}
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("*** open of %s failed: error=%x\n", UA_CSS_URL, rv);
#endif
return rv;
}
}
if(0==PL_strcmp(aCommand,"view-source")) {
#ifdef VIEW_SOURCE_HTML
aContentType=gHTMLTypes[0];
#else
if(0==PL_strcmp(aContentType,gHTMLTypes[1])) {
aContentType=gHTMLTypes[0];
}
else if(0==PL_strcmp(aContentType,gHTMLTypes[2])) {
aContentType=gHTMLTypes[0];
}
else
aContentType=gXMLTypes[0];
#endif
}
// Try html
int typeIndex=0;
while(gHTMLTypes[typeIndex]) {
if (0== PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) {
return CreateDocument(aCommand,
aChannel, aLoadGroup,
aContainer, kHTMLDocumentCID,
aDocListener, aDocViewer);
}
}
// Try XML
typeIndex = 0;
while(gXMLTypes[typeIndex]) {
if (0== PL_strcmp(gXMLTypes[typeIndex++], aContentType)) {
return CreateDocument(aCommand,
aChannel, aLoadGroup,
aContainer, kXMLDocumentCID,
aDocListener, aDocViewer);
}
}
// Try RDF
typeIndex = 0;
while (gRDFTypes[typeIndex]) {
if (0 == PL_strcmp(gRDFTypes[typeIndex++], aContentType)) {
return CreateRDFDocument(aCommand,
aChannel, aLoadGroup,
aContentType, aContainer,
aExtraInfo, aDocListener, aDocViewer);
}
}
// Try image types
typeIndex = 0;
while(gImageTypes[typeIndex]) {
if (0== PL_strcmp(gImageTypes[typeIndex++], aContentType)) {
return CreateDocument(aCommand,
aChannel, aLoadGroup,
aContainer, kImageDocumentCID,
aDocListener, aDocViewer);
}
}
// If we get here, then we weren't able to create anything. Sorry!
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsContentDLF::CreateInstanceForDocument(nsISupports* aContainer,
nsIDocument* aDocument,
const char *aCommand,
nsIContentViewer** aDocViewerResult)
{
nsresult rv = NS_ERROR_FAILURE;
do {
nsCOMPtr<nsIDocumentViewer> docv;
// Create the document viewer
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
if (NS_FAILED(rv))
break;
docv->SetUAStyleSheet(nsContentDLF::GetUAStyleSheet());
// Bind the document to the Content Viewer
rv = docv->BindToDocument(aDocument, aCommand);
*aDocViewerResult = docv;
NS_IF_ADDREF(*aDocViewerResult);
} while (PR_FALSE);
return rv;
}
nsresult
nsContentDLF::CreateDocument(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
nsISupports* aContainer,
const nsCID& aDocumentCID,
nsIStreamListener** aDocListener,
nsIContentViewer** aDocViewer)
{
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIURI> aURL;
rv = aChannel->GetURI(getter_AddRefs(aURL));
if (NS_FAILED(rv)) return rv;
#ifdef NOISY_CREATE_DOC
if (nsnull != aURL) {
nsAutoString tmp;
aURL->ToString(tmp);
fputs(tmp, stdout);
printf(": creating document\n");
}
#endif
nsCOMPtr<nsIDocument> doc;
nsCOMPtr<nsIDocumentViewer> docv;
do {
// Create the document
rv = nsComponentManager::CreateInstance(aDocumentCID, nsnull,
NS_GET_IID(nsIDocument),
getter_AddRefs(doc));
if (NS_FAILED(rv))
break;
// Create the document viewer XXX: could reuse document viewer here!
rv = NS_NewDocumentViewer(getter_AddRefs(docv));
if (NS_FAILED(rv))
break;
docv->SetUAStyleSheet(nsContentDLF::GetUAStyleSheet());
// Initialize the document to begin loading the data. An
// nsIStreamListener connected to the parser is returned in
// aDocListener.
rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE);
if (NS_FAILED(rv))
break;
// Bind the document to the Content Viewer
rv = docv->BindToDocument(doc, aCommand);
*aDocViewer = docv;
NS_IF_ADDREF(*aDocViewer);
} while (PR_FALSE);
return rv;
}
NS_IMETHODIMP
nsContentDLF::CreateInstance(nsIInputStream& aInputStream,
const char* aContentType,
const char* aCommand,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIContentViewer** aDocViewer)
{
nsresult status = NS_ERROR_FAILURE;
// Try RDF
int typeIndex = 0;
while (gRDFTypes[typeIndex]) {
if (0 == PL_strcmp(gRDFTypes[typeIndex++], aContentType)) {
return CreateXULDocumentFromStream(aInputStream,
aCommand,
aContainer,
aExtraInfo,
aDocViewer);
}
}
return status;
}
// ...common work for |CreateRDFDocument| and |CreateXULDocumentFromStream|
nsresult
nsContentDLF::CreateRDFDocument(nsISupports* aExtraInfo,
nsCOMPtr<nsIDocument>* doc,
nsCOMPtr<nsIDocumentViewer>* docv)
{
nsresult rv = NS_ERROR_FAILURE;
// Create the XUL document
rv = nsComponentManager::CreateInstance(kXULDocumentCID, nsnull,
NS_GET_IID(nsIDocument),
getter_AddRefs(*doc));
if (NS_FAILED(rv)) return rv;
// Create the image content viewer...
rv = NS_NewDocumentViewer(getter_AddRefs(*docv));
if (NS_FAILED(rv)) return rv;
// Load the UA style sheet if we haven't already done that
(*docv)->SetUAStyleSheet(nsContentDLF::GetUAStyleSheet());
return NS_OK;
}
// ...note, this RDF document _may_ be XUL :-)
nsresult
nsContentDLF::CreateRDFDocument(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
const char* aContentType,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIStreamListener** aDocListener,
nsIContentViewer** aDocViewer)
{
nsCOMPtr<nsIDocument> doc;
nsCOMPtr<nsIDocumentViewer> docv;
nsresult rv = CreateRDFDocument(aExtraInfo, address_of(doc), address_of(docv));
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIURI> aURL;
rv = aChannel->GetURI(getter_AddRefs(aURL));
if (NS_FAILED(rv)) return rv;
/*
* Initialize the document to begin loading the data...
*
* An nsIStreamListener connected to the parser is returned in
* aDocListener.
*/
rv = doc->StartDocumentLoad(aCommand, aChannel, aLoadGroup, aContainer, aDocListener, PR_TRUE);
if (NS_SUCCEEDED(rv)) {
/*
* Bind the document to the Content Viewer...
*/
rv = docv->BindToDocument(doc, aCommand);
*aDocViewer = docv;
NS_IF_ADDREF(*aDocViewer);
}
return rv;
}
nsresult
nsContentDLF::CreateXULDocumentFromStream(nsIInputStream& aXULStream,
const char* aCommand,
nsISupports* aContainer,
nsISupports* aExtraInfo,
nsIContentViewer** aDocViewer)
{
nsresult status = NS_OK;
#if 0 // XXX dead code; remove
do
{
nsCOMPtr<nsIDocument> doc;
nsCOMPtr<nsIDocumentViewer> docv;
if ( NS_FAILED(status = CreateRDFDocument(aExtraInfo, address_of(doc), address_of(docv))) )
break;
if ( NS_FAILED(status = docv->BindToDocument(doc, aCommand)) )
break;
*aDocViewer = docv;
NS_IF_ADDREF(*aDocViewer);
nsCOMPtr<nsIStreamLoadableDocument> loader = do_QueryInterface(doc, &status);
if ( NS_FAILED(status) )
break;
status = loader->LoadFromStream(aXULStream, aContainer, aCommand);
}
while (0);
#endif
return status;
}
nsresult
nsContentModule::RegisterDocumentFactories(nsIComponentManager* aCompMgr,
nsIFile* aPath)
{
// We do not register view or view-source document factories because
// that is for layout. Now load-as-data might be a different story...
return NS_OK;
}
static NS_DEFINE_IID(kDocumentFactoryImplCID, NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID);
void
nsContentModule::UnregisterDocumentFactories(nsIComponentManager* aCompMgr,
nsIFile* aPath)
{
aCompMgr->UnregisterComponentSpec(kDocumentFactoryImplCID, aPath);
}

View File

@@ -0,0 +1,619 @@
/* -*- 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 "nslayout.h"
#include "nsContentModule.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsContentCID.h"
#include "nsIDocument.h"
#include "nsIHTMLContent.h"
#include "nsITextContent.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsISelection.h"
#include "nsIFrameUtil.h"
#include "nsHTMLAtoms.h"
#include "nsHTMLParts.h"
#include "nsDOMCID.h"
#include "nsIServiceManager.h"
#include "nsICSSParser.h"
#include "nsIHTMLStyleSheet.h"
#include "nsIHTMLCSSStyleSheet.h"
#include "nsICSSStyleSheet.h"
#include "nsICSSLoader.h"
#include "nsIDOMRange.h"
#include "nsIContentIterator.h"
#include "nsINameSpaceManager.h"
#include "nsIScriptNameSetRegistry.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIScriptExternalNameSet.h"
#include "nsIEventListenerManager.h"
#include "nsILayoutDebugger.h"
#include "nsIElementFactory.h"
#include "nsIDocumentEncoder.h"
#include "nsCOMPtr.h"
#include "nsIFrameSelection.h"
#include "nsIDOMDOMImplementation.h"
#include "nsIPrivateDOMImplementation.h"
#include "nsIDocumentViewer.h"
#include "nsIHTMLAttributes.h"
#include "nsIXBLService.h"
#include "nsIBindingManager.h"
#include "nsContentPolicyUtils.h"
#include "nsXMLContentSerializer.h"
#include "nsHTMLContentSerializer.h"
#include "nsPlainTextSerializer.h"
#include "nsINodeInfo.h"
#include "nsIComputedDOMStyle.h"
#include "nsEventStateManager.h"
class nsIDocumentLoaderFactory;
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_IID(kHTMLDocumentCID, NS_HTMLDOCUMENT_CID);
static NS_DEFINE_IID(kXMLDocumentCID, NS_XMLDOCUMENT_CID);
static NS_DEFINE_CID(kXMLElementFactoryCID, NS_XML_ELEMENT_FACTORY_CID);
static NS_DEFINE_IID(kImageDocumentCID, NS_IMAGEDOCUMENT_CID);
static NS_DEFINE_IID(kCSSParserCID, NS_CSSPARSER_CID);
static NS_DEFINE_CID(kHTMLCSSStyleSheetCID, NS_HTML_CSS_STYLESHEET_CID);
static NS_DEFINE_CID(kHTMLStyleSheetCID, NS_HTMLSTYLESHEET_CID);
static NS_DEFINE_CID(kStyleSetCID, NS_STYLESET_CID);
static NS_DEFINE_CID(kCSSStyleSheetCID, NS_CSS_STYLESHEET_CID);
static NS_DEFINE_CID(kCSSLoaderCID, NS_CSS_LOADER_CID);
static NS_DEFINE_IID(kHTMLImageElementCID, NS_HTMLIMAGEELEMENT_CID);
static NS_DEFINE_IID(kHTMLHrElementCID, NS_HTMLHRELEMENT_CID);
static NS_DEFINE_IID(kHTMLInputElementCID, NS_HTMLINPUTELEMENT_CID);
static NS_DEFINE_IID(kHTMLOptionElementCID, NS_HTMLOPTIONELEMENT_CID);
static NS_DEFINE_IID(kAnonymousElementCID, NS_ANONYMOUSCONTENT_CID);
static NS_DEFINE_IID(kHTMLAttributesCID, NS_HTMLATTRIBUTES_CID);
static NS_DEFINE_CID(kSelectionCID, NS_SELECTION_CID);
static NS_DEFINE_IID(kFrameSelectionCID, NS_FRAMESELECTION_CID);
static NS_DEFINE_IID(kDOMSelectionCID, NS_DOMSELECTION_CID);
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
static NS_DEFINE_IID(kAttributeContentCID, NS_ATTRIBUTECONTENT_CID);
static NS_DEFINE_IID(kContentIteratorCID, NS_CONTENTITERATOR_CID);
static NS_DEFINE_IID(kGeneratedContentIteratorCID, NS_GENERATEDCONTENTITERATOR_CID);
static NS_DEFINE_IID(kGeneratedSubtreeIteratorCID, NS_GENERATEDSUBTREEITERATOR_CID);
static NS_DEFINE_IID(kSubtreeIteratorCID, NS_SUBTREEITERATOR_CID);
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kFrameUtilCID, NS_FRAME_UTIL_CID);
static NS_DEFINE_CID(kEventListenerManagerCID, NS_EVENTLISTENERMANAGER_CID);
static NS_DEFINE_CID(kEventStateManagerCID, NS_EVENTSTATEMANAGER_CID);
static NS_DEFINE_CID(kDocumentViewerCID, NS_DOCUMENT_VIEWER_CID);
static NS_DEFINE_CID(kContentDocumentLoaderFactoryCID, NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID);
static NS_DEFINE_CID(kLayoutDebuggerCID, NS_LAYOUT_DEBUGGER_CID);
static NS_DEFINE_CID(kHTMLElementFactoryCID, NS_HTML_ELEMENT_FACTORY_CID);
static NS_DEFINE_CID(kTextEncoderCID, NS_TEXT_ENCODER_CID);
static NS_DEFINE_CID(kHTMLCopyTextEncoderCID, NS_HTMLCOPY_TEXT_ENCODER_CID);
static NS_DEFINE_CID(kXMLContentSerializerCID, NS_XMLCONTENTSERIALIZER_CID);
static NS_DEFINE_CID(kHTMLContentSerializerCID, NS_HTMLCONTENTSERIALIZER_CID);
static NS_DEFINE_CID(kPlainTextSerializerCID, NS_PLAINTEXTSERIALIZER_CID);
static NS_DEFINE_CID(kXBLServiceCID, NS_XBLSERVICE_CID);
static NS_DEFINE_CID(kBindingManagerCID, NS_BINDINGMANAGER_CID);
static NS_DEFINE_CID(kDOMImplementationCID, NS_DOM_IMPLEMENTATION_CID);
static NS_DEFINE_CID(kNodeInfoManagerCID, NS_NODEINFOMANAGER_CID);
static NS_DEFINE_CID(kContentPolicyCID, NS_CONTENTPOLICY_CID);
static NS_DEFINE_CID(kComputedDOMStyleCID, NS_COMPUTEDDOMSTYLE_CID);
static NS_DEFINE_CID(kControllerCommandManagerCID, NS_CONTROLLERCOMMANDMANAGER_CID);
extern nsresult NS_NewSelection(nsIFrameSelection** aResult);
extern nsresult NS_NewDomSelection(nsISelection** aResult);
extern nsresult NS_NewDocumentViewer(nsIDocumentViewer** aResult);
extern nsresult NS_NewRange(nsIDOMRange** aResult);
extern nsresult NS_NewContentIterator(nsIContentIterator** aResult);
extern nsresult NS_NewGenRegularIterator(nsIContentIterator** aResult);
extern nsresult NS_NewContentSubtreeIterator(nsIContentIterator** aResult);
extern nsresult NS_NewGenSubtreeIterator(nsIContentIterator** aInstancePtrResult);
extern nsresult NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult);
extern nsresult NS_NewHTMLElementFactory(nsIElementFactory** aResult);
extern nsresult NS_NewXMLElementFactory(nsIElementFactory** aResult);
extern nsresult NS_NewHTMLCopyTextEncoder(nsIDocumentEncoder** aResult);
extern nsresult NS_NewTextEncoder(nsIDocumentEncoder** aResult);
extern nsresult NS_NewXBLService(nsIXBLService** aResult);
extern nsresult NS_NewBindingManager(nsIBindingManager** aResult);
extern nsresult NS_NewNodeInfoManager(nsINodeInfoManager** aResult);
extern nsresult NS_NewContentPolicy(nsIContentPolicy** aResult);
#ifdef MOZ_XUL
#include "nsIXULSortService.h"
#include "nsIRDFContentModelBuilder.h"
#include "nsIXULContentSink.h"
#include "nsIXULDocument.h"
#include "nsIXULPopupListener.h"
#include "nsIXULPrototypeCache.h"
#include "nsIController.h"
#include "nsIControllers.h"
#include "nsIControllerCommand.h"
static NS_DEFINE_CID(kXULSortServiceCID, NS_XULSORTSERVICE_CID);
static NS_DEFINE_CID(kXULTemplateBuilderCID, NS_XULTEMPLATEBUILDER_CID);
static NS_DEFINE_CID(kXULOutlinerBuilderCID, NS_XULOUTLINERBUILDER_CID);
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
static NS_DEFINE_CID(kXULDocumentCID, NS_XULDOCUMENT_CID);
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
static NS_DEFINE_CID(kXULElementFactoryCID, NS_XULELEMENTFACTORY_CID);
static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID);
static NS_DEFINE_CID(kXULControllersCID, NS_XULCONTROLLERS_CID);
extern nsresult NS_NewXULElementFactory(nsIElementFactory** aResult);
extern NS_IMETHODIMP NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult);
#endif
//----------------------------------------------------------------------
nsContentFactory::nsContentFactory(const nsCID &aClass)
{
NS_INIT_ISUPPORTS();
mClassID = aClass;
#if 0
char* cs = aClass.ToString();
printf("+++ Creating Content factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
nsContentFactory::~nsContentFactory()
{
#if 0
char* cs = mClassID.ToString();
printf("+++ Destroying Content factory for %s\n", cs);
nsCRT::free(cs);
#endif
}
NS_IMPL_ISUPPORTS(nsContentFactory, NS_GET_IID(nsIFactory))
#ifdef DEBUG
#define LOG_NEW_FAILURE(_msg,_ec) \
printf("nsContentFactory::CreateInstance failed for %s: error=%d(0x%x)\n", \
_msg, _ec, _ec)
#else
#define LOG_NEW_FAILURE(_msg,_ec)
#endif
nsresult
nsContentFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
nsresult res;
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
if (aOuter) {
return NS_ERROR_NO_AGGREGATION;
}
nsISupports *inst = nsnull;
// XXX ClassID check happens here
if (mClassID.Equals(kHTMLDocumentCID)) {
res = NS_NewHTMLDocument((nsIDocument **)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewHTMLDocument", res);
return res;
}
}
else if (mClassID.Equals(kXMLDocumentCID)) {
res = NS_NewXMLDocument((nsIDocument **)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXMLDocument", res);
return res;
}
}
else if (mClassID.Equals(kImageDocumentCID)) {
res = NS_NewImageDocument((nsIDocument **)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewImageDocument", res);
return res;
}
}
else if (mClassID.Equals(kHTMLAttributesCID)) {
res = NS_NewHTMLAttributes((nsIHTMLAttributes**)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewHTMLAttributes", res);
return res;
}
}
#if 1
// XXX replace these with nsIElementFactory calls
else if (mClassID.Equals(kHTMLImageElementCID)) {
// Note! NS_NewHTMLImageElement is special cased to handle a null nodeinfo
res = NS_NewHTMLImageElement((nsIHTMLContent**)&inst, nsnull);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewHTMLImageElement", res);
return res;
}
}
else if (mClassID.Equals(kHTMLOptionElementCID)) {
// Note! NS_NewHTMLOptionElement is special cased to handle a null nodeinfo
res = NS_NewHTMLOptionElement((nsIHTMLContent**)&inst, nsnull);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewHTMLOptionElement", res);
return res;
}
}
else if (mClassID.Equals(kHTMLInputElementCID)) {
// Note! NS_NewHTMLOptionElement is special cased to handle a null nodeinfo
res = NS_NewHTMLInputElement((nsIHTMLContent**)&inst, nsnull);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewHTMLInputElement", res);
return res;
}
}
#endif
else if (mClassID.Equals(kFrameSelectionCID)) {
res = NS_NewSelection((nsIFrameSelection**)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewSelection", res);
return res;
}
}
else if (mClassID.Equals(kDOMSelectionCID)) {
res = NS_NewDomSelection((nsISelection**)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewDomSelection", res);
return res;
}
}
else if (mClassID.Equals(kRangeCID)) {
res = NS_NewRange((nsIDOMRange **)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewRange", res);
return res;
}
}
else if (mClassID.Equals(kAttributeContentCID)) {
res = NS_NewAttributeContent((nsIContent **)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewAttributeContent", res);
return res;
}
}
else if (mClassID.Equals(kContentIteratorCID)) {
res = NS_NewContentIterator((nsIContentIterator **)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewContentIterator", res);
return res;
}
}
else if (mClassID.Equals(kGeneratedContentIteratorCID)) {
res = NS_NewGenRegularIterator((nsIContentIterator **)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewGenRegularIterator", res);
return res;
}
}
else if (mClassID.Equals(kSubtreeIteratorCID)) {
res = NS_NewContentSubtreeIterator((nsIContentIterator **)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewContentSubtreeIterator", res);
return res;
}
}
else if (mClassID.Equals(kGeneratedSubtreeIteratorCID)) {
res = NS_NewGenSubtreeIterator((nsIContentIterator **)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewGenSubtreeIterator", res);
return res;
}
}
else if (mClassID.Equals(kCSSParserCID)) {
res = NS_NewCSSParser((nsICSSParser**)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewCSSParser", res);
return res;
}
}
else if (mClassID.Equals(kHTMLCSSStyleSheetCID)) {
res = NS_NewHTMLCSSStyleSheet((nsIHTMLCSSStyleSheet**)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewHTMLCSSStyleSheet", res);
return res;
}
}
else if (mClassID.Equals(kCSSStyleSheetCID)) {
res = NS_NewCSSStyleSheet((nsICSSStyleSheet**)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewCSSStyleSheet", res);
return res;
}
}
else if (mClassID.Equals(kStyleSetCID)) {
res = NS_NewStyleSet((nsIStyleSet**)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewStyleSet", res);
return res;
}
}
else if (mClassID.Equals(kHTMLStyleSheetCID)) {
res = NS_NewHTMLStyleSheet((nsIHTMLStyleSheet**)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewHTMLStyleSheet", res);
return res;
}
}
else if (mClassID.Equals(kCSSLoaderCID)) {
res = NS_NewCSSLoader((nsICSSLoader**)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewCSSLoader", res);
return res;
}
}
else if (mClassID.Equals(kTextNodeCID)) {
res = NS_NewTextNode((nsIContent**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewTextNode", res);
return res;
}
}
else if (mClassID.Equals(kNameSpaceManagerCID)) {
res = NS_NewNameSpaceManager((nsINameSpaceManager**)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewNameSpaceManager", res);
return res;
}
}
else if (mClassID.Equals(kEventListenerManagerCID)) {
res = NS_NewEventListenerManager((nsIEventListenerManager**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewEventListenerManager", res);
return res;
}
}
else if (mClassID.Equals(kEventStateManagerCID)) {
res = NS_NewEventStateManager((nsIEventStateManager**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewEventStateManager", res);
return res;
}
}
else if (mClassID.Equals(kContentDocumentLoaderFactoryCID)) {
res = NS_NewContentDocumentLoaderFactory((nsIDocumentLoaderFactory**)&inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewContentDocumentLoaderFactory", res);
return res;
}
}
else if (mClassID.Equals(kHTMLElementFactoryCID)) {
res = NS_NewHTMLElementFactory((nsIElementFactory**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewHTMLElementFactory", res);
return res;
}
}
else if (mClassID.Equals(kXMLElementFactoryCID)) {
res = NS_NewXMLElementFactory((nsIElementFactory**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXMLElementFactory", res);
return res;
}
}
else if (mClassID.Equals(kTextEncoderCID)) {
res = NS_NewTextEncoder((nsIDocumentEncoder**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewTextEncoder", res);
return res;
}
}
else if (mClassID.Equals(kHTMLCopyTextEncoderCID)) {
res = NS_NewHTMLCopyTextEncoder((nsIDocumentEncoder**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewHTMLCopyTextEncoder", res);
return res;
}
}
else if (mClassID.Equals(kXMLContentSerializerCID)) {
res = NS_NewXMLContentSerializer((nsIContentSerializer**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXMLContentSerializer", res);
return res;
}
}
else if (mClassID.Equals(kHTMLContentSerializerCID)) {
res = NS_NewHTMLContentSerializer((nsIContentSerializer**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewHTMLContentSerializer", res);
return res;
}
}
else if (mClassID.Equals(kPlainTextSerializerCID)) {
res = NS_NewPlainTextSerializer((nsIContentSerializer**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewPlainTextSerializer", res);
return res;
}
}
else if (mClassID.Equals(kXBLServiceCID)) {
res = NS_NewXBLService((nsIXBLService**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXBLService", res);
return res;
}
}
else if (mClassID.Equals(kBindingManagerCID)) {
res = NS_NewBindingManager((nsIBindingManager**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewBindingManager", res);
return res;
}
}
else if (mClassID.Equals(kNodeInfoManagerCID)) {
res = NS_NewNodeInfoManager((nsINodeInfoManager**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewNodeInfoManager", res);
return res;
}
}
else if (mClassID.Equals(kDOMImplementationCID)) {
res = NS_NewDOMImplementation((nsIDOMDOMImplementation**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewDOMImplementation", res);
return res;
}
}
else if (mClassID.Equals(kDocumentViewerCID)) {
res = NS_NewDocumentViewer((nsIDocumentViewer**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewDocumentViewer", res);
return res;
}
}
else if (mClassID.Equals(kContentPolicyCID)) {
res = NS_NewContentPolicy((nsIContentPolicy**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewContentPolicy", res);
return res;
}
}
else if (mClassID.Equals(kComputedDOMStyleCID)) {
res = NS_NewComputedDOMStyle((nsIComputedDOMStyle**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewComputedDOMStyle", res);
return res;
}
}
#if defined(MOZ_XUL)
else if (mClassID.Equals(kXULSortServiceCID)) {
res = NS_NewXULSortService((nsIXULSortService**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXULSortService", res);
return res;
}
}
else if (mClassID.Equals(kXULTemplateBuilderCID)) {
res = NS_NewXULContentBuilder(nsnull, aIID, (void**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXULContentBuilder", res);
return res;
}
}
else if (mClassID.Equals(kXULOutlinerBuilderCID)) {
res = NS_NewXULOutlinerBuilder(nsnull, aIID, (void**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXULOutlinerBuilder", res);
return res;
}
}
else if (mClassID.Equals(kXULContentSinkCID)) {
res = NS_NewXULContentSink((nsIXULContentSink**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXULContentSink", res);
return res;
}
}
else if (mClassID.Equals(kXULDocumentCID)) {
res = NS_NewXULDocument((nsIXULDocument**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXULDocument", res);
return res;
}
}
else if (mClassID.Equals(kXULPopupListenerCID)) {
res = NS_NewXULPopupListener((nsIXULPopupListener**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXULPopupListener", res);
return res;
}
}
else if (mClassID.Equals(kXULElementFactoryCID)) {
res = NS_NewXULElementFactory((nsIElementFactory**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXULElementFactory", res);
return res;
}
}
else if (mClassID.Equals(kXULPrototypeCacheCID)) {
res = NS_NewXULPrototypeCache(nsnull, NS_GET_IID(nsIXULPrototypeCache), (void**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXULPrototypeCache", res);
return res;
}
}
else if (mClassID.Equals(kXULControllersCID)) {
res = NS_NewXULControllers(nsnull, NS_GET_IID(nsIControllers), (void**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewXULControllers", res);
return res;
}
}
else if (mClassID.Equals(kControllerCommandManagerCID)) {
res = NS_NewControllerCommandManager((nsIControllerCommandManager**) &inst);
if (NS_FAILED(res)) {
LOG_NEW_FAILURE("NS_NewControllerCommandManager", res);
return res;
}
}
#endif
else {
return NS_NOINTERFACE;
}
if (NS_FAILED(res)) return res;
res = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);
if (NS_FAILED(res)) {
// We didn't get the right interface, so clean up
LOG_NEW_FAILURE("final QueryInterface", res);
}
return res;
}
nsresult nsContentFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}

Some files were not shown because too many files have changed in this diff Show More