Compare commits

..

68 Commits

Author SHA1 Message Date
jfrancis%netscape.com
874090591c forcing out the table into the text/html string if we were going to include tabel sections anyway.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80675 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-07 09:11:46 +00:00
jst%netscape.com
fca94c00d0 Cleaning away a function pointer.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80673 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-07 08:58:09 +00:00
jfrancis%netscape.com
ff911d9ffc making changes per code review from kin
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80665 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-07 06:53:18 +00:00
jfrancis%netscape.com
e98752a576 improving performance of GetPromotedPoint()
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80664 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-07 06:22:19 +00:00
jfrancis%netscape.com
c8c563c85b fixing paste bug
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80634 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-07 01:17:48 +00:00
akkana%netscape.com
4f4bf1cde4 Remove OutputXIF and Selection As XIF
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80628 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-07 00:40:15 +00:00
jst%netscape.com
d470752eee Performance work in plain text serializer. Better line-wrapping for HTML content serialization.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80627 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-07 00:34:49 +00:00
jst%netscape.com
59f824c070 Fixing bug in nsAReadableString::FindChar(), the method should return index + offset and not just index
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80609 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-06 23:15:29 +00:00
jfrancis%netscape.com
f39d215a9a guarantee that if we aste table or list contents we won't orphan the beginnin gof the structure on paste. Make StripFormattingNodes less aggressive so that preformmated text is pasted properly.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80570 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-06 10:18:54 +00:00
jfrancis%netscape.com
0308035724 fixed error that caused lxr pages to not paste properly
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80569 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-06 09:16:39 +00:00
jfrancis%netscape.com
0e969c48b3 no text nodes in the context heirarchy
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80526 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-05 23:46:06 +00:00
jfrancis%netscape.com
76ce4d0cfa more paste work
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80525 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-05 23:45:27 +00:00
jfrancis%netscape.com
558908b4d4 improvements to "nonsignificant whitespace determination".
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80475 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-05 21:18:59 +00:00
jst%netscape.com
946ee63a8c Adding newline at end of file.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80466 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-05 20:34:23 +00:00
jfrancis%netscape.com
bb63d2b2e6 fixing mail reply regression, making selection update correctly after paste
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80465 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-05 20:14:35 +00:00
jst%netscape.com
61d316ab16 Fixing win build bustage.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80463 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-05 19:59:44 +00:00
akkana%netscape.com
3ce6bdee8e Add ./ in front of commands, so it won't require . in the path. r=jst
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80455 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-05 18:35:27 +00:00
jfrancis%netscape.com
d7ecf7dc4d make sure range hints dont cause client to skip over html containers we want to force it to include.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80454 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-05 18:04:36 +00:00
jfrancis%netscape.com
7a59f46018 even more paste fixes
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80453 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-05 18:03:25 +00:00
jfrancis%netscape.com
dcda0377d7 more paste fixes
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80452 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-05 17:02:54 +00:00
jfrancis%netscape.com
699b51b14c making <li> behave for containment queries
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80451 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-05 16:58:44 +00:00
jst%netscape.com
1e254dbfd7 Adding back code that got lost in the last merge.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80440 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-05 09:40:07 +00:00
jfrancis%netscape.com
85d67fdba7 merging tip onto branch, take 2
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80382 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-04 23:35:25 +00:00
jfrancis%netscape.com
94cb9b826b merging from tip
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80370 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-04 21:36:53 +00:00
kin%netscape.com
b62815170d Fixing win32 build bustage.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80369 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-04 21:04:15 +00:00
akkana%netscape.com
d2aaff6524 Add a .get to fix build problem
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80366 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-04 20:23:59 +00:00
akkana%netscape.com
2350998715 Fix a typo to make it compile
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80359 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-04 19:53:40 +00:00
jfrancis%netscape.com
fa0a8e3dc3 merging tip onto branch
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80356 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-04 19:22:22 +00:00
jfrancis%netscape.com
897276b73c merging tip to branch
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80355 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-04 18:40:28 +00:00
jfrancis%netscape.com
21fccd0d00 fixing mac build problem
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80285 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-04 01:35:22 +00:00
(no author)
cbb34332a8 This commit was manufactured by cvs2svn to create branch
'NOXIF_20000911_BRANCH'.

git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80282 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-04 00:41:54 +00:00
jfrancis%netscape.com
bc44fdf80f adding back in the clipboard converter for html copy
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80279 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-03 23:04:17 +00:00
jfrancis%netscape.com
bb01edbf88 landing first draft of editor paste changes
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80271 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-03 20:18:30 +00:00
jfrancis%netscape.com
cfbbc797c7 mkaing sure dtd recognizes text nodes as such
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80270 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-03 20:16:05 +00:00
jfrancis%netscape.com
2eaaf5c928 adding CTransitionalDTD for editor use to support HTML 4.0 transitional dtd editting rules.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80264 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-03 14:29:22 +00:00
jfrancis%netscape.com
ec24c79b43 html copy now sports some additional data flavors that provide contextual info
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80263 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-03 14:27:11 +00:00
jfrancis%netscape.com
a4c577044e adding in changes to document encoder to support getting extra context info at copy time. This version has the original SerializeRangeNodes() call.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80262 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-03 14:21:46 +00:00
jfrancis%netscape.com
a2a64470e2 tweaking GetTopAncestorInRange() to behave better when the entre root is selected
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80261 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-03 14:05:33 +00:00
jfrancis%netscape.com
3804e84b0f project got squashed by the merge earlier merge to tip; restoring changes
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80260 18797224-902f-48f8-a5cc-f745e15eee43
2000-10-03 14:04:37 +00:00
akkana%netscape.com
9b5dc5c96c 54016: Copy Daniel Bratell's crash fix to the sink stream on the trunk over to the serializer
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80011 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-27 20:51:50 +00:00
cmanske%netscape.com
f5fefd0e4c Fixing new content serializer's formatting to match behavior in current HTMLContentSink output. (This is a branch to be integrated later; not part of any current tip or 6.0 branch build) r/a=vidur
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@80003 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-27 19:23:36 +00:00
akkana%netscape.com
a75fad13c6 Add pre to list of tags for which we include context
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79680 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-21 00:51:41 +00:00
akkana%netscape.com
e804518b9a Recycle some cstrings
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79656 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-20 21:42:38 +00:00
akkana%netscape.com
31d3e029b1 Remove more XIF tests
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79650 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-20 21:01:52 +00:00
akkana%netscape.com
f88e43f7e7 Fix plaintext test so it passes
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79649 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-20 21:01:38 +00:00
akkana%netscape.com
7c5f09fd81 Initialize wrap column
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79646 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-20 20:10:17 +00:00
akkana%netscape.com
086a16e65f Remove unneeded includes
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79645 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-20 20:09:41 +00:00
akkana%netscape.com
b16923f44f Turn on the output tests now that they build again
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79639 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-20 19:16:14 +00:00
akkana%netscape.com
aa8f637eca Fix the output test to use the new serializer model. html->plain only for now
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79638 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-20 19:12:57 +00:00
jfrancis%netscape.com
71ca7a0332 fixing prob with getting branch in sync with tip
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79604 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-20 06:06:39 +00:00
jst%netscape.com
7a445ab2aa Merging this branch with the tip.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79560 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-19 22:55:19 +00:00
jfrancis%netscape.com
810e947f9a mac specific htmlconverter work
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79478 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-18 23:21:34 +00:00
(no author)
51d0bc694b This commit was manufactured by cvs2svn to create branch
'NOXIF_20000911_BRANCH'.

git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79456 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-18 20:24:17 +00:00
jfrancis%netscape.com
07548b1ecb fixing compilation error
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79405 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-17 23:04:59 +00:00
jfrancis%netscape.com
a0ab16f2aa removing xif
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79404 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-17 23:04:23 +00:00
jfrancis%netscape.com
2f804e0c41 adding serializers to mac layout project. NOT PART OF BUILD: NOXIF Branch only.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79402 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-17 21:59:34 +00:00
jst%netscape.com
a5258e0d68 Adding support for pre and post range context for HTML selections.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79386 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-16 02:52:08 +00:00
jst%netscape.com
646fcb7f82 Use enum values in stead of 1 and -1 as the in/out iteration direction. Not part of the build.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79253 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-15 02:48:55 +00:00
jst%netscape.com
94c9b82e31 Fixing the range traversal code, not part of the build.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@79238 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-15 00:01:02 +00:00
jst%netscape.com
75c32ae741 Changing the index stored in the ancestor array to always be the index of the current node.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@78997 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-13 07:59:41 +00:00
jst%netscape.com
0184bb1a6f More fixes to the range traversal code.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@78986 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-13 07:04:33 +00:00
jst%netscape.com
159c818cd3 Checking in more serializer changes, mostly done by vidur.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@78972 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-13 05:12:45 +00:00
jst%netscape.com
42e20dbd64 fixed doctype serialization. this is not part of the build.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@78963 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-13 03:40:15 +00:00
jst%netscape.com
625fd7ca6c More fixes for the range iterating code, not part of the build.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@78961 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-13 03:18:12 +00:00
jst%netscape.com
bcafd1c5dc Fixing the range iterating code, not part of the build.
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@78955 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-13 02:41:27 +00:00
jst%netscape.com
e746d0ab6a Making the editor, the document encoder and the clipboard code not use XIF
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@78788 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-11 22:33:37 +00:00
jst%netscape.com
1fd78ad497 Making the editor, the document encoder and the clipboard code not use XIF
git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@78784 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-11 22:21:34 +00:00
(no author)
ca3f61dd8f This commit was manufactured by cvs2svn to create branch
'NOXIF_20000911_BRANCH'.

git-svn-id: svn://10.0.0.236/branches/NOXIF_20000911_BRANCH@78781 18797224-902f-48f8-a5cc-f745e15eee43
2000-09-11 22:10:10 +00:00
6573 changed files with 1445254 additions and 106012 deletions

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,46 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsIAnonymousContent_h___
#define nsIAnonymousContent_h___
#include "nsISupports.h"
#include "nsIContent.h"
#include "nsCOMPtr.h"
class nsISupportsArray;
class nsIAtom;
#define NS_IANONYMOUS_CONTENT_IID { 0x41a69e00, 0x2d6d, 0x12d3, { 0xb0, 0x33, 0xa1, 0x38, 0x71, 0x39, 0x78, 0x7c } }
/**
* If a node is anonymous. Then it should implement this interface.
*/
class nsIAnonymousContent : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IANONYMOUS_CONTENT_IID; return iid; }
};
#endif

View File

@@ -0,0 +1,328 @@
/* -*- 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 nsIXIFConverter;
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;
/**
* Test and see if this piece of content is synthetic. Synthetic content
* is content generated stylistically and should normally be ignored
* during content saving.
*/
NS_IMETHOD IsSynthetic(PRBool& aResult) = 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;
/**
* Translate the content object into the (XIF) XML Interchange Format
* XIF is an intermediate form of the content model, the buffer
* will then be parsed into any number of formats including HTML, TXT, etc.
* BeginConvertToXIF -- opens a container and writes out the attributes
* ConvertContentToXIF -- typically does nothing unless there is text content
* FinishConvertToXIF -- closes a container
*/
NS_IMETHOD BeginConvertToXIF(nsIXIFConverter *aConverter) const = 0;
NS_IMETHOD ConvertContentToXIF(nsIXIFConverter * aConverter) const = 0;
NS_IMETHOD FinishConvertToXIF(nsIXIFConverter * aConverter) 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,80 @@
/* -*- 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"
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) = 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,364 @@
/* -*- 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 "nsIUnicharInputStream.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 nsIXIFConverter;
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;
/**
* Methods to append to the prolog and epilog of
* a document. The prolog is the content before the document
* element, the epilog after.
*/
NS_IMETHOD AppendToProlog(nsIContent* aContent) = 0;
NS_IMETHOD AppendToEpilog(nsIContent* aContent) = 0;
/**
* Get the direct children of the document - content in
* the prolog, the root content and content in the epilog.
*/
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const = 0;
NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const = 0;
NS_IMETHOD GetChildCount(PRInt32& aCount) = 0;
/**
* Get the style sheets owned by this document.
* Style sheets are ordered, most significant last.
*/
virtual PRInt32 GetNumberOfStyleSheets() = 0;
virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex) = 0;
virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet) = 0;
virtual void AddStyleSheet(nsIStyleSheet* aSheet) = 0;
virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) = 0;
NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets) = 0;
NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify) = 0;
virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
PRBool mDisabled) = 0;
/**
* Set the object from which a document can get a script context.
* This is the context within which all scripts (during document
* creation and during event handling) will run.
*/
NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject** aGlobalObject) = 0;
NS_IMETHOD SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0;
/**
* Get the name space manager for this document
*/
NS_IMETHOD GetNameSpaceManager(nsINameSpaceManager*& aManager) = 0;
//----------------------------------------------------------------------
// Document notification API's
/**
* Add a new observer of document change notifications. Whenever
* content is changed, appended, inserted or removed the observers are
* informed.
*/
virtual void AddObserver(nsIDocumentObserver* aObserver) = 0;
/**
* Remove an observer of document change notifications. This will
* return false if the observer cannot be found.
*/
virtual PRBool RemoveObserver(nsIDocumentObserver* aObserver) = 0;
// Observation hooks used by content nodes to propagate
// notifications to document observers.
NS_IMETHOD BeginUpdate() = 0;
NS_IMETHOD EndUpdate() = 0;
NS_IMETHOD BeginLoad() = 0;
NS_IMETHOD EndLoad() = 0;
NS_IMETHOD ContentChanged(nsIContent* aContent,
nsISupports* aSubContent) = 0;
// notify that one or two content nodes changed state
// either may be nsnull, but not both
NS_IMETHOD ContentStatesChanged(nsIContent* aContent1,
nsIContent* aContent2) = 0;
NS_IMETHOD AttributeChanged(nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint) = 0; // See nsStyleConsts fot hint values
NS_IMETHOD ContentAppended(nsIContent* aContainer,
PRInt32 aNewIndexInContainer) = 0;
NS_IMETHOD ContentInserted(nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer) = 0;
NS_IMETHOD ContentReplaced(nsIContent* aContainer,
nsIContent* aOldChild,
nsIContent* aNewChild,
PRInt32 aIndexInContainer) = 0;
NS_IMETHOD ContentRemoved(nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer) = 0;
// Observation hooks for style data to propogate notifications
// to document observers
NS_IMETHOD StyleRuleChanged(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint) = 0; // See nsStyleConsts fot hint values
NS_IMETHOD StyleRuleAdded(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) = 0;
NS_IMETHOD StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) = 0;
/**
* Finds text in content
*/
NS_IMETHOD FindNext(const nsAReadableString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound) = 0;
/**
* Converts the document or a selection of the
* document to XIF (XML Interchange Format)
* and places the result in aBuffer.
* NOTE: we may way to place the result in a stream,
* but we will use a string for now -- gpk
*/
NS_IMETHOD CreateXIF(nsAWritableString & aBuffer, nsISelection* aSelection = nsnull) = 0;
NS_IMETHOD ToXIF(nsIXIFConverter * aConverter, nsIDOMNode* aNode) = 0;
virtual void BeginConvertToXIF(nsIXIFConverter * aConverter, nsIDOMNode* aNode) = 0;
virtual void ConvertChildrenToXIF(nsIXIFConverter * aConverter, nsIDOMNode* aNode) = 0;
virtual void FinishConvertToXIF(nsIXIFConverter * aConverter, nsIDOMNode* aNode) = 0;
/* Helper methods to help determine the logical positioning of content */
virtual PRBool IsInSelection(nsISelection* aSelection, const nsIContent *aContent) const = 0;
virtual nsIContent* GetPrevContent(const nsIContent *aContent) const = 0;
virtual nsIContent* GetNextContent(const nsIContent *aContent) const = 0;
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus* aEventStatus) = 0;
NS_IMETHOD FlushPendingNotifications() = 0;
NS_IMETHOD GetAndIncrementContentID(PRInt32* aID) = 0;
NS_IMETHOD GetBindingManager(nsIBindingManager** aResult) = 0;
NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) = 0;
};
// XXX These belong somewhere else
extern NS_LAYOUT nsresult
NS_NewHTMLDocument(nsIDocument** aInstancePtrResult);
extern NS_LAYOUT nsresult
NS_NewXMLDocument(nsIDocument** aInstancePtrResult);
extern NS_LAYOUT nsresult
NS_NewImageDocument(nsIDocument** aInstancePtrResult);
extern NS_LAYOUT nsresult
NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult,
nsIDocument* aOwnerDocument);
extern NS_LAYOUT nsresult
NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
const nsAReadableString& aNamespaceURI,
const nsAReadableString& aQualifiedName,
nsIDOMDocumentType* aDoctype,
nsIURI* aBaseURI);
// Note: The buffer passed into NewPostData(...) becomes owned by the IPostData
// instance and is freed when the instance is destroyed...
//
#if 0
extern NS_LAYOUT nsresult
NS_NewPostData(PRBool aIsFile, char *aData, nsIPostData** aInstancePtrResult);
#endif
#endif /* nsIDocument_h___ */

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,178 @@
/* -*- 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;
#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 } }
#define NS_HTMLCOPY_ENCODER_CONTRACTID "@mozilla.org/layout/htmlCopyEncoder"
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,
// OutputNoDoctype is obsolete, flag 4 available for other uses
//OutputNoDoctype = 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;
/**
* 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;
};
#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,66 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsISupports.idl"
#include "domstubs.idl"
#include "nsISelectionListener.idl"
#include "nsIEnumerator.idl"
%{C++
class nsIDOMNode;
class nsIDOMRange;
class nsISelectionListener;
%}
[scriptable, uuid(B2C7ED59-8634-4352-9E37-5484C8B6E4E1)]
interface nsISelection : nsISupports
{
readonly attribute nsIDOMNode anchorNode;
readonly attribute long anchorOffset;
readonly attribute nsIDOMNode focusNode;
readonly attribute long focusOffset;
readonly attribute boolean isCollapsed;
readonly attribute long rangeCount;
nsIDOMRange getRangeAt(in long index);
void collapse(in nsIDOMNode parentNode, in long offset);
void extend(in nsIDOMNode parentNode, in long offset);
void collapseToStart();
void collapseToEnd();
boolean containsNode(in nsIDOMNode node, in boolean recursive);
void selectAllChildren(in nsIDOMNode parentNode);
void addRange(in nsIDOMRange range);
void removeRange(in nsIDOMRange range);
void removeAllRanges();
void deleteFromDocument();
wstring toString();
};

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.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
* !!Note this is for a javascriptable pres shell currently for accessing selection
* the selection refers only to that which listens to keybindings which is the "NORMAL"
* selection this will be IDLIZED LATER
*/
#ifndef nsISelectionControler_h___
#define nsISelectionControler_h___
#include "nsISupports.h"
#define NS_ISELECTIONCONTROLER_IID_STR "D2D1D179-85A7-11d3-9932-00108301233C"
#define NS_ISELECTIONCONTROLER_IID \
{ 0xd2d1d179, 0x85a7, 0x11d3, \
{ 0x99, 0x32, 0x0, 0x10, 0x83, 0x1, 0x23, 0x3c }}
class nsISelectionControler : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_ISELECTIONCONTROLER_IID; return iid; }
/** CharacterMove will move the selection one character forward/backward in the document.
* this will also have the effect of collapsing the selection if the aExtend = PR_FALSE
* the "point" of selection that is extended is considered the "focus" point.
* or the last point adjusted by the selection.
* @param aForward forward or backward if PR_FALSE
* @param aExtend should it collapse the selection of extend it?
*/
NS_IMETHOD CharacterMove(PRBool aForward, PRBool aExtend) = 0;
/** WordMove will move the selection one word forward/backward in the document.
* this will also have the effect of collapsing the selection if the aExtend = PR_FALSE
* the "point" of selection that is extended is considered the "focus" point.
* or the last point adjusted by the selection.
* @param aForward forward or backward if PR_FALSE
* @param aExtend should it collapse the selection of extend it?
*/
NS_IMETHOD WordMove(PRBool aForward, PRBool aExtend) = 0;
/** LineMove will move the selection one line forward/backward in the document.
* this will also have the effect of collapsing the selection if the aExtend = PR_FALSE
* the "point" of selection that is extended is considered the "focus" point.
* or the last point adjusted by the selection.
* @param aForward forward or backward if PR_FALSE
* @param aExtend should it collapse the selection of extend it?
*/
NS_IMETHOD LineMove(PRBool aForward, PRBool aExtend) = 0;
/** IntraLineMove will move the selection to the front of the line or end of the line
* in the document.
* this will also have the effect of collapsing the selection if the aExtend = PR_FALSE
* the "point" of selection that is extended is considered the "focus" point.
* or the last point adjusted by the selection.
* @param aForward forward or backward if PR_FALSE
* @param aExtend should it collapse the selection of extend it?
*/
NS_IMETHOD IntraLineMove(PRBool aForward, PRBool aExtend) = 0;
/** PageMove will move the selection one page forward/backward in the document.
* this will also have the effect of collapsing the selection if the aExtend = PR_FALSE
* the "point" of selection that is extended is considered the "focus" point.
* or the last point adjusted by the selection.
* @param aForward forward or backward if PR_FALSE
* @param aExtend should it collapse the selection of extend it?
*/
NS_IMETHOD PageMove(PRBool aForward, PRBool aExtend) = 0;
/** ScrollPage will scroll the page without affecting the selection.
* @param aForward scroll forward or backwards in selection
*/
NS_IMETHOD ScrollPage(PRBool aForward) = 0;
/** SelectAll will select the whole page
*/
NS_IMETHOD SelectAll() = 0;
};
#endif /* nsISelectionControler_h___ */

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,57 @@
/* -*- 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 wrapCount);
void addSelectionListener(in nsISelectionListener newListener);
void removeSelectionListener(in nsISelectionListener listenerToRemove);
};

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,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.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;
// 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,
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,24 @@
#ifndef _nsIStyleRuleSupplier_h
#define _nsIStyleRuleSupplier_h
#include "nsISupports.h"
#include "nsISupportsArray.h"
// {2D77A45B-4F3A-4203-A7D2-F4B84D0C1EE4}
#define NS_ISTYLERULESUPPLIER_IID \
{ 0x2d77a45b, 0x4f3a, 0x4203, { 0xa7, 0xd2, 0xf4, 0xb8, 0x4d, 0xc, 0x1e, 0xe4 } }
class nsIContent;
class nsIStyleSet;
class nsIStyleRuleSupplier : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISTYLERULESUPPLIER_IID)
NS_IMETHOD UseDocumentRules(nsIContent* aContent, PRBool* aResult)=0;
NS_IMETHOD WalkRules(nsIStyleSet* aStyleSet,
nsISupportsArrayEnumFunc aFunc, void* aData,
nsIContent* aContent)=0;
};
#endif /* _nsIStyleRuleSupplier_h */

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,242 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsTextFragment_h___
#define nsTextFragment_h___
#include "nslayout.h"
#include "nsAWritableString.h"
class nsString;
// XXX should this normalize the code to keep a \u0000 at the end?
// XXX nsTextFragmentPool?
// XXX these need I18N spankage
#define XP_IS_SPACE(_ch) \
(((_ch) == ' ') || ((_ch) == '\t') || ((_ch) == '\n'))
#define XP_IS_UPPERCASE(_ch) \
(((_ch) >= 'A') && ((_ch) <= 'Z'))
#define XP_IS_LOWERCASE(_ch) \
(((_ch) >= 'a') && ((_ch) <= 'z'))
#define XP_TO_LOWER(_ch) ((_ch) | 32)
#define XP_TO_UPPER(_ch) ((_ch) & ~32)
#define XP_IS_SPACE_W XP_IS_SPACE
/**
* A fragment of text. If mIs2b is 1 then the m2b pointer is valid
* otherwise the m1b pointer is valid. If m1b is used then each byte
* of data represents a single ucs2 character with the high byte being
* zero.
*
* This class does not have a virtual destructor therefore it is not
* meant to be subclassed.
*/
class NS_LAYOUT nsTextFragment {
public:
/**
* Default constructor. Initialize the fragment to be empty.
*/
nsTextFragment() {
m1b = nsnull;
mAllBits = 0;
}
~nsTextFragment();
/**
* Initialize the contents of this fragment to be a copy of
* the argument fragment.
*/
nsTextFragment(const nsTextFragment& aOther);
/**
* Initialize the contents of this fragment to be a copy of
* the argument 7bit ascii string.
*/
nsTextFragment(const char* aString);
/**
* Initialize the contents of this fragment to be a copy of
* the argument ucs2 string.
*/
nsTextFragment(const PRUnichar* aString);
/**
* Initialize the contents of this fragment to be a copy of
* the argument string.
*/
nsTextFragment(const nsString& aString);
/**
* Change the contents of this fragment to be a copy of the
* the argument fragment.
*/
nsTextFragment& operator=(const nsTextFragment& aOther);
/**
* Change the contents of this fragment to be a copy of the
* the argument 7bit ascii string.
*/
nsTextFragment& operator=(const char* aString);
/**
* Change the contents of this fragment to be a copy of the
* the argument ucs2 string.
*/
nsTextFragment& operator=(const PRUnichar* aString);
/**
* Change the contents of this fragment to be a copy of the
* the argument string.
*/
nsTextFragment& operator=(const nsAReadableString& aString);
/**
* Return PR_TRUE if this fragment is represented by PRUnichar data
*/
PRBool Is2b() const {
return mState.mIs2b;
}
/**
* Get a pointer to constant PRUnichar data.
*/
const PRUnichar* Get2b() const {
NS_ASSERTION(Is2b(), "not 2b text");
return m2b;
}
/**
* Get a pointer to constant char data.
*/
const char* Get1b() const {
NS_ASSERTION(!Is2b(), "not 1b text");
return (const char*) m1b;
}
/**
* Get the length of the fragment. The length is the number of logical
* characters, not the number of bytes to store the characters.
*/
PRInt32 GetLength() const {
return PRInt32(mState.mLength);
}
/**
* Mutable version of Get2b. Only works for a non-const object.
* Returns a pointer to the PRUnichar data.
*/
PRUnichar* Get2b() {
NS_ASSERTION(Is2b(), "not 2b text");
return m2b;
}
/**
* Mutable version of Get1b. Only works for a non-const object.
* Returns a pointer to the char data.
*/
char* Get1b() {
NS_ASSERTION(!Is2b(), "not 1b text");
return (char*) m1b;
}
/**
* Change the contents of this fragment to be the given buffer and
* length. The memory becomes owned by the fragment. In addition,
* the memory for aBuffer must have been allocated using the
* nsIMemory interface.
*/
void SetTo(PRUnichar* aBuffer, PRInt32 aLength, PRBool aRelease);
/**
* Change the contents of this fragment to be a copy of the given
* buffer. Like operator= except a length is specified instead of
* assuming 0 termination.
*/
void SetTo(const PRUnichar* aBuffer, PRInt32 aLength);
/**
* Change the contents of this fragment to be a copy of the given
* buffer. Like operator= except a length is specified instead of
* assuming 0 termination.
*/
void SetTo(const char* aBuffer, PRInt32 aLength);
/**
* Append the contents of this string fragment to aString
*/
void AppendTo(nsString& aString) const;
/**
* Make a copy of the fragments contents starting at offset for
* count characters. The offset and count will be adjusted to
* lie within the fragments data. The fragments data is converted if
* necessary.
*/
void CopyTo(PRUnichar* aDest, PRInt32 aOffset, PRInt32 aCount);
/**
* Make a copy of the fragments contents starting at offset for
* count characters. The offset and count will be adjusted to
* lie within the fragments data. The fragments data is converted if
* necessary.
*/
void CopyTo(char* aDest, PRInt32 aOffset, PRInt32 aCount);
/**
* Return the character in the text-fragment at the given
* index. This always returns a PRUnichar.
*/
PRUnichar CharAt(PRInt32 aIndex) const {
NS_ASSERTION(PRUint32(aIndex) < mState.mLength, "bad index");
return mState.mIs2b ? m2b[aIndex] : PRUnichar(m1b[aIndex]);
}
protected:
union {
PRUnichar* m2b;
unsigned char* m1b;
};
public:
struct FragmentBits {
PRUint32 mInHeap : 1;
PRUint32 mIs2b : 1;
PRUint32 mLength : 30;
};
protected:
union {
PRUint32 mAllBits;
FragmentBits mState;
};
void ReleaseText();
};
#endif /* nsTextFragment_h___ */

View File

@@ -0,0 +1,563 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsIDOMComment.h"
#include "nsGenericDOMDataNode.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMEventReceiver.h"
#include "nsIContent.h"
#include "nsFrame.h"
#include "nsLayoutAtoms.h"
#include "nsISelection.h"
#include "nsISelectionPrivate.h"
#include "nsIXIFConverter.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 IsSynthetic(PRBool& aResult) {
return mInner.IsSynthetic(aResult);
}
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 BeginConvertToXIF(nsIXIFConverter* aConverter) const {
return mInner.BeginConvertToXIF(aConverter);
}
NS_IMETHOD ConvertContentToXIF(nsIXIFConverter* aConverter) const;
NS_IMETHOD FinishConvertToXIF(nsIXIFConverter* aConverter) const {
return mInner.FinishConvertToXIF(aConverter);
}
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);
}
nsresult NS_NewCommentFrame(nsIPresShell* aPresShell, nsIFrame*& aResult);
nsresult
NS_NewCommentFrame(nsIPresShell* aPresShell, nsIFrame*& aResult)
{
nsIFrame* frame;
NS_NewEmptyFrame(aPresShell, &frame);
if (nsnull == frame) {
return NS_ERROR_OUT_OF_MEMORY;
}
aResult = frame;
return NS_OK;
}
/**
* Translate the content object into the (XIF) XML Interchange Format
* XIF is an intermediate form of the content model, the buffer
* will then be parsed into any number of formats including HTML, TXT, etc.
*/
nsresult
nsCommentNode::ConvertContentToXIF(nsIXIFConverter* aConverter) const
{
const nsIContent* content = this;
nsCOMPtr<nsISelection> sel;
aConverter->GetSelection(getter_AddRefs(sel));
nsIDocument* document;
nsresult res;
res = GetDocument(document);
if (!NS_SUCCEEDED(res))
return res;
const nsTextFragment* textFrag;
// XXX This method is const, but GetText() isn't,
// XXX so cast away the constness of mInner:
nsGenericDOMDataNode* inner = (nsGenericDOMDataNode*)&mInner;
res = inner->GetText(&textFrag);
if (!NS_SUCCEEDED(res))
return res;
if (sel != nsnull && document->IsInSelection(sel,content))
{
nsIEnumerator *enumerator;
nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(sel));
if (NS_SUCCEEDED(selPrivate->GetEnumerator(&enumerator))) {
for (enumerator->First();NS_OK != enumerator->IsDone(); enumerator->Next()) {
nsIDOMRange* range = nsnull;
if (NS_SUCCEEDED(enumerator->CurrentItem((nsISupports**)&range))) {
nsCOMPtr<nsIDOMNode> startNode;
nsCOMPtr<nsIDOMNode> endNode;
PRInt32 startOffset = 0;
PRInt32 endOffset = 0;
range->GetStartContainer(getter_AddRefs(startNode));
range->GetEndContainer(getter_AddRefs(endNode));
range->GetStartOffset(&startOffset);
range->GetEndOffset(&endOffset);
nsCOMPtr<nsIContent> startContent;
nsCOMPtr<nsIContent> endContent;
startContent = do_QueryInterface(startNode);
endContent = do_QueryInterface(endNode);
nsString buffer;
textFrag->AppendTo(buffer);
if (startContent.get() == content || endContent.get() == content)
{
// NOTE: ORDER MATTERS!
// This must go before the Cut
if (endContent.get() == content)
buffer.Truncate(endOffset);
// This must go after the Trunctate
if (startContent.get() == content)
buffer.Cut(0,startOffset);
}
aConverter->AddContentComment(buffer);
}
}
}
}
else
{
nsString buffer;
textFrag->AppendTo(buffer);
aConverter->AddContentComment(buffer);
}
NS_IF_RELEASE(document);
// XXX Possible mem leak: Do we need to delete textFrag?
return NS_OK;
}
#if 0
nsresult
nsCommentNode::BeginConvertToXIF(nsIXIFConverter* aConverter) const
{
return NS_OK;
}
nsresult
nsCommentNode::FinishConvertToXIF(nsIXIFConverter* aConverter) const
{
return NS_OK;
}
#endif
// 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,563 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsContentList.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocument.h"
#include "nsINameSpaceManager.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsGenericElement.h"
#include "nsLayoutAtoms.h"
#include "nsHTMLAtoms.h" // XXX until atoms get factored into nsLayoutAtoms
nsContentList::nsContentList(nsIDocument *aDocument)
{
NS_INIT_REFCNT();
mScriptObject = nsnull;
mFunc = nsnull;
mMatchAtom = nsnull;
mDocument = aDocument;
mData = nsnull;
mMatchAll = PR_FALSE;
mRootContent = nsnull;
}
nsContentList::nsContentList(nsIDocument *aDocument,
nsIAtom* aMatchAtom,
PRInt32 aMatchNameSpaceId,
nsIContent* aRootContent)
{
mMatchAtom = aMatchAtom;
NS_IF_ADDREF(mMatchAtom);
if (nsLayoutAtoms::wildcard == mMatchAtom) {
mMatchAll = PR_TRUE;
}
else {
mMatchAll = PR_FALSE;
}
mMatchNameSpaceId = aMatchNameSpaceId;
mFunc = nsnull;
mData = nsnull;
mRootContent = aRootContent;
Init(aDocument);
}
nsContentList::nsContentList(nsIDocument *aDocument,
nsContentListMatchFunc aFunc,
const nsString* aData,
nsIContent* aRootContent)
{
mFunc = aFunc;
if (nsnull != aData) {
mData = new nsString(*aData);
// If this fails, fail silently
}
else {
mData = nsnull;
}
mMatchAtom = nsnull;
mRootContent = aRootContent;
mMatchAll = PR_FALSE;
Init(aDocument);
}
void nsContentList::Init(nsIDocument *aDocument)
{
NS_INIT_REFCNT();
mScriptObject = nsnull;
// We don't reference count the reference to the document
// If the document goes away first, we'll be informed and we
// can drop our reference.
// If we go away first, we'll get rid of ourselves from the
// document's observer list.
mDocument = aDocument;
if (nsnull != mDocument) {
mDocument->AddObserver(this);
}
PopulateSelf();
}
nsContentList::~nsContentList()
{
if (nsnull != mDocument) {
mDocument->RemoveObserver(this);
}
NS_IF_RELEASE(mMatchAtom);
if (nsnull != mData) {
delete mData;
}
}
nsresult nsContentList::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(NS_GET_IID(nsIDOMNodeList))) {
*aInstancePtr = (void*)(nsIDOMNodeList*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIDOMHTMLCollection))) {
*aInstancePtr = (void*)(nsIDOMHTMLCollection*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIScriptObjectOwner))) {
*aInstancePtr = (void*)(nsIScriptObjectOwner*)this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsISupports))) {
*aInstancePtr = (void*)(nsISupports*)(nsIDOMNodeList*)this;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsContentList)
NS_IMPL_RELEASE(nsContentList)
NS_IMETHODIMP
nsContentList::GetLength(PRUint32* aLength)
{
nsresult result = CheckDocumentExistence();
if (NS_OK == result) {
*aLength = mContent.Count();
}
return result;
}
NS_IMETHODIMP
nsContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
nsresult result = CheckDocumentExistence();
if (NS_OK == result) {
if (nsnull != mDocument) {
mDocument->FlushPendingNotifications(); // Flush pending content changes Bug 4891
}
nsISupports *element = (nsISupports *)mContent.ElementAt(aIndex);
if (nsnull != element) {
result = element->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)aReturn);
}
else {
*aReturn = nsnull;
}
}
return result;
}
NS_IMETHODIMP
nsContentList::NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn)
{
nsresult result = CheckDocumentExistence();
if (NS_OK == result) {
if (nsnull != mDocument) {
mDocument->FlushPendingNotifications(); // Flush pending content changes Bug 4891
}
PRInt32 i, count = mContent.Count();
for (i = 0; i < count; i++) {
nsIContent *content = (nsIContent *)mContent.ElementAt(i);
if (nsnull != content) {
nsAutoString name;
// XXX Should it be an EqualsIgnoreCase?
if (((content->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::name, name) == NS_CONTENT_ATTR_HAS_VALUE) &&
(aName.Equals(name))) ||
((content->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::id, name) == NS_CONTENT_ATTR_HAS_VALUE) &&
(aName.Equals(name)))) {
return content->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)aReturn);
}
}
}
}
*aReturn = nsnull;
return result;
}
NS_IMETHODIMP
nsContentList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
nsresult res = NS_OK;
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
res = nsGenericElement::GetScriptObjectFactory(&factory);
if (NS_OK != res) {
return res;
}
res = factory->NewScriptHTMLCollection(aContext,
(nsISupports*)(nsIDOMHTMLCollection*)this,
global,
(void**)&mScriptObject);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;
NS_RELEASE(global);
return res;
}
NS_IMETHODIMP
nsContentList::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
NS_IMETHODIMP
nsContentList::ContentAppended(nsIDocument *aDocument,
nsIContent* aContainer,
PRInt32 aNewIndexInContainer)
{
PRInt32 i, count;
aContainer->ChildCount(count);
if ((count > 0) && IsDescendantOfRoot(aContainer)) {
PRBool repopulate = PR_FALSE;
for (i = aNewIndexInContainer; i <= count-1; i++) {
nsIContent *content;
aContainer->ChildAt(i, content);
if (mMatchAll || MatchSelf(content)) {
repopulate = PR_TRUE;
}
NS_RELEASE(content);
}
if (repopulate) {
PopulateSelf();
}
}
return NS_OK;
}
NS_IMETHODIMP
nsContentList::ContentInserted(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer)
{
if (IsDescendantOfRoot(aContainer)) {
if (mMatchAll || MatchSelf(aChild)) {
PopulateSelf();
}
}
return NS_OK;
}
NS_IMETHODIMP
nsContentList::ContentReplaced(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aOldChild,
nsIContent* aNewChild,
PRInt32 aIndexInContainer)
{
if (IsDescendantOfRoot(aContainer)) {
if (mMatchAll || MatchSelf(aOldChild) || MatchSelf(aNewChild)) {
PopulateSelf();
}
}
else if (ContainsRoot(aOldChild)) {
DisconnectFromDocument();
}
return NS_OK;
}
NS_IMETHODIMP
nsContentList::ContentRemoved(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer)
{
if (IsDescendantOfRoot(aContainer) && MatchSelf(aChild)) {
PopulateSelf();
}
else if (ContainsRoot(aChild)) {
DisconnectFromDocument();
}
return NS_OK;
}
NS_IMETHODIMP
nsContentList::DocumentWillBeDestroyed(nsIDocument *aDocument)
{
if (nsnull != mDocument) {
aDocument->RemoveObserver(this);
mDocument = nsnull;
}
Reset();
return NS_OK;
}
// Returns whether the content element matches the
// criterion
nsresult
nsContentList::Match(nsIContent *aContent, PRBool *aMatch)
{
*aMatch = PR_FALSE;
if (!aContent) {
return NS_OK;
}
if (mMatchAtom) {
nsCOMPtr<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 (nsnull != mFunc) {
*aMatch = (*mFunc)(aContent, mData);
}
return NS_OK;
}
nsresult
nsContentList::Add(nsIContent *aContent)
{
// Shouldn't hold a reference since we'll be
// told when the content leaves the document or
// the document will be destroyed.
mContent.AppendElement(aContent);
return NS_OK;
}
nsresult
nsContentList::Remove(nsIContent *aContent)
{
mContent.RemoveElement(aContent);
return NS_OK;
}
nsresult
nsContentList::IndexOf(nsIContent *aContent, PRInt32& aIndex)
{
aIndex = mContent.IndexOf(aContent);
return NS_OK;
}
nsresult
nsContentList::Reset()
{
mContent.Clear();
return NS_OK;
}
// If we were created outside the context of a document and we
// have root content, then check if our content has been added
// to a document yet. If so, we'll become an observer of the document.
nsresult
nsContentList::CheckDocumentExistence()
{
nsresult result = NS_OK;
if ((nsnull == mDocument) && (nsnull != mRootContent)) {
result = mRootContent->GetDocument(mDocument);
if (nsnull != mDocument) {
mDocument->AddObserver(this);
PopulateSelf();
}
}
return result;
}
// Match recursively. See if anything in the subtree
// matches the criterion.
PRBool
nsContentList::MatchSelf(nsIContent *aContent)
{
PRBool match;
PRInt32 i, count;
Match(aContent, &match);
if (match) {
return PR_TRUE;
}
aContent->ChildCount(count);
for (i = 0; i < count; i++) {
nsIContent *child;
aContent->ChildAt(i, child);
if (MatchSelf(child)) {
NS_RELEASE(child);
return PR_TRUE;
}
NS_RELEASE(child);
}
return PR_FALSE;
}
// Add all elements in this subtree that match to
// our list.
void
nsContentList::PopulateWith(nsIContent *aContent, PRBool aIncludeRoot)
{
PRBool match;
PRInt32 i, count;
if (aIncludeRoot) {
Match(aContent, &match);
if (match) {
Add(aContent);
}
}
aContent->ChildCount(count);
for (i = 0; i < count; i++) {
nsIContent *child;
aContent->ChildAt(i, child);
PopulateWith(child, PR_TRUE);
NS_RELEASE(child);
}
}
// Clear out our old list and build up a new one
void
nsContentList::PopulateSelf()
{
Reset();
if (nsnull != mRootContent) {
PopulateWith(mRootContent, PR_FALSE);
}
else if (nsnull != mDocument) {
nsIContent *root;
root = mDocument->GetRootContent();
PopulateWith(root, PR_TRUE);
NS_RELEASE(root);
}
}
// Is the specified element a descendant of the root? If there
// is no root, then yes. Otherwise keep tracing up the tree from
// the element till we find our root, or until we reach the
// document root.
PRBool
nsContentList::IsDescendantOfRoot(nsIContent* aContainer)
{
if (nsnull == mRootContent) {
return PR_TRUE;
}
else if (mRootContent == aContainer) {
return PR_TRUE;
}
else if (nsnull == aContainer) {
return PR_FALSE;
}
else {
nsIContent* parent;
PRBool ret;
aContainer->GetParent(parent);
ret = IsDescendantOfRoot(parent);
NS_IF_RELEASE(parent);
return ret;
}
}
// Does this subtree contain the root?
PRBool
nsContentList::ContainsRoot(nsIContent* aContent)
{
if (nsnull == mRootContent) {
return PR_FALSE;
}
else if (mRootContent == aContent) {
return PR_TRUE;
}
else {
PRInt32 i, count;
aContent->ChildCount(count);
for (i = 0; i < count; i++) {
nsIContent *child;
aContent->ChildAt(i, child);
if (ContainsRoot(child)) {
NS_RELEASE(child);
return PR_TRUE;
}
NS_RELEASE(child);
}
return PR_FALSE;
}
}
// Our root content has been disconnected from the
// document, so stop observing. The list then becomes
// a snapshot rather than a dynamic list.
void
nsContentList::DisconnectFromDocument()
{
if (nsnull != mDocument) {
mDocument->RemoveObserver(this);
mDocument = nsnull;
}
}

View File

@@ -0,0 +1,148 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsContentList_h___
#define nsContentList_h___
#include "nsISupports.h"
#include "nsVoidArray.h"
#include "nsString.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMNodeList.h"
#include "nsIDocumentObserver.h"
#include "nsIScriptObjectOwner.h"
typedef PRBool (*nsContentListMatchFunc)(nsIContent* aContent, nsString* aData);
class nsIDocument;
class nsContentList : public nsIDOMNodeList,
public nsIDOMHTMLCollection,
public nsIScriptObjectOwner,
public nsIDocumentObserver {
public:
nsContentList(nsIDocument *aDocument);
nsContentList(nsIDocument *aDocument,
nsIAtom* aMatchAtom,
PRInt32 aMatchNameSpaceId,
nsIContent* aRootContent=nsnull);
nsContentList(nsIDocument *aDocument,
nsContentListMatchFunc aFunc,
const nsString* aData,
nsIContent* aRootContent=nsnull);
virtual ~nsContentList();
NS_DECL_ISUPPORTS
// nsIDOMHTMLCollection
NS_IMETHOD GetLength(PRUint32* aLength);
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn);
NS_IMETHOD NamedItem(const nsAReadableString& aName, nsIDOMNode** aReturn);
// nsIScriptObjectOwner
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
// nsIDocumentObserver
NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD EndLoad(nsIDocument *aDocument) { return NS_OK; }
NS_IMETHOD BeginReflow(nsIDocument *aDocument,
nsIPresShell* aShell) { return NS_OK; }
NS_IMETHOD EndReflow(nsIDocument *aDocument,
nsIPresShell* aShell) { return NS_OK; }
NS_IMETHOD ContentChanged(nsIDocument *aDocument,
nsIContent* aContent,
nsISupports* aSubContent) { return NS_OK; }
NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument,
nsIContent* aContent1,
nsIContent* aContent2) { return NS_OK; }
NS_IMETHOD AttributeChanged(nsIDocument *aDocument,
nsIContent* aContent,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint) { return NS_OK; }
NS_IMETHOD ContentAppended(nsIDocument *aDocument,
nsIContent* aContainer,
PRInt32 aNewIndexInContainer);
NS_IMETHOD ContentInserted(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer);
NS_IMETHOD ContentReplaced(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aOldChild,
nsIContent* aNewChild,
PRInt32 aIndexInContainer);
NS_IMETHOD ContentRemoved(nsIDocument *aDocument,
nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer);
NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet) { return NS_OK; }
NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet) { return NS_OK; }
NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled) { return NS_OK; }
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint) { return NS_OK; }
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument);
nsresult Add(nsIContent *aContent);
nsresult Remove(nsIContent *aContent);
nsresult IndexOf(nsIContent *aContent, PRInt32& aIndex);
protected:
nsresult Match(nsIContent *aContent, PRBool *aMatch);
nsresult Reset();
void Init(nsIDocument *aDocument);
void PopulateWith(nsIContent *aContent, PRBool aIncludeRoot);
PRBool MatchSelf(nsIContent *aContent);
void PopulateSelf();
void DisconnectFromDocument();
PRBool IsDescendantOfRoot(nsIContent* aContainer);
PRBool ContainsRoot(nsIContent* aContent);
nsresult CheckDocumentExistence();
nsIAtom* mMatchAtom;
PRInt32 mMatchNameSpaceId;
nsContentListMatchFunc mFunc;
nsString* mData;
nsVoidArray mContent;
void *mScriptObject;
nsIDocument* mDocument;
nsIContent* mRootContent;
PRBool mMatchAll;
};
#endif // nsContentList_h___

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,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,478 @@
/* -*- 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;
nsDOMAttributeMap* map = (nsDOMAttributeMap*) aMap;
PRUint32 sum = sizeof(nsDOMAttributeMap);
*aResult = sum;
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,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___

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,528 @@
/* -*- 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 "nsIXIFConverter.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"
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;
nsAutoString 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;
};
class nsAnonymousContentList : public nsGenericDOMNodeList
{
public:
nsAnonymousContentList(nsISupportsArray* aElements);
virtual ~nsAnonymousContentList();
// nsIDOMNodeList interface
NS_DECL_IDOMNODELIST
private:
nsISupportsArray* mElements;
};
// Base class for our document implementations
class nsDocument : public nsIDocument,
public nsIDOMDocument,
public nsIDOMNSDocument,
public nsIDOMDocumentEvent,
public nsIDOMDocumentStyle,
public nsIDOMDocumentView,
public nsIDOMDocumentXBL,
public nsIDiskDocument,
public nsIJSScriptObject,
public nsSupportsWeakReference,
public nsIDOMEventReceiver,
public nsIScriptObjectPrincipal
{
public:
NS_DECL_ISUPPORTS
virtual nsIArena* GetArena();
NS_IMETHOD StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
nsISupports* aContainer,
nsIStreamListener **aDocListener,
PRBool aReset = PR_TRUE);
NS_IMETHOD StopDocumentLoad();
/**
* Return the title of the document. May return null.
*/
virtual const nsString* GetDocumentTitle() const;
/**
* Return the URL for the document. May return null.
*/
virtual nsIURI* GetDocumentURL() const;
/**
* Return the principal responsible for this document.
*/
NS_IMETHOD GetPrincipal(nsIPrincipal **aPrincipal);
/**
* Update principal responsible for this document to the intersection
* of its previous value and aPrincipal, and return its new value.
*/
NS_IMETHOD AddPrincipal(nsIPrincipal *aPrincipal);
/**
* Return the content (mime) type of this document.
*/
NS_IMETHOD GetContentType(nsAWritableString& aContentType) const;
/**
* Return the LoadGroup for the document. May return null.
*/
NS_IMETHOD GetDocumentLoadGroup(nsILoadGroup **aGroup) const;
/**
* Return the base URL for realtive URLs in the document. May return null (or the document URL).
*/
NS_IMETHOD GetBaseURL(nsIURI*& aURL) const;
/**
* Return a standard name for the document's character set. This will
* trigger a startDocumentLoad if necessary to answer the question.
*/
NS_IMETHOD GetDocumentCharacterSet(nsAWritableString& oCharsetID);
NS_IMETHOD SetDocumentCharacterSet(const nsAReadableString& aCharSetID);
/**
* Add an observer that gets notified whenever the charset changes.
*/
NS_IMETHOD AddCharSetObserver(nsIObserver* aObserver);
/**
* Remove a charset observer.
*/
NS_IMETHOD RemoveCharSetObserver(nsIObserver* aObserver);
/**
* Return the Line Breaker for the document
*/
NS_IMETHOD GetLineBreaker(nsILineBreaker** aResult) ;
NS_IMETHOD SetLineBreaker(nsILineBreaker* aLineBreaker) ;
NS_IMETHOD GetWordBreaker(nsIWordBreaker** aResult) ;
NS_IMETHOD SetWordBreaker(nsIWordBreaker* aWordBreaker) ;
/**
* Access HTTP header data (this may also get set from other sources, like
* HTML META tags).
*/
NS_IMETHOD GetHeaderData(nsIAtom* aHeaderField, nsAWritableString& aData) const;
NS_IMETHOD SetHeaderData(nsIAtom* aheaderField, const nsAReadableString& aData);
/**
* Create a new presentation shell that will use aContext for
* it's presentation context (presentation context's <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);
/**
* Methods to append to the prolog and epilog of
* a document. The prolog is the content before the document
* element, the epilog after.
*/
NS_IMETHOD AppendToProlog(nsIContent* aContent);
NS_IMETHOD AppendToEpilog(nsIContent* aContent);
/**
* Get the direct children of the document - content in
* the prolog, the root content and content in the epilog.
*/
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const;
NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aIndex) const;
NS_IMETHOD GetChildCount(PRInt32& aCount);
/**
* Get the style sheets owned by this document.
* These are ordered, highest priority last
*/
virtual PRInt32 GetNumberOfStyleSheets();
virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex);
virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet);
virtual void AddStyleSheet(nsIStyleSheet* aSheet);
virtual void RemoveStyleSheet(nsIStyleSheet* aSheet);
NS_IMETHOD UpdateStyleSheets(nsISupportsArray* aOldSheets, nsISupportsArray* aNewSheets);
virtual void AddStyleSheetToStyleSets(nsIStyleSheet* aSheet);
virtual void RemoveStyleSheetFromStyleSets(nsIStyleSheet* aSheet);
NS_IMETHOD InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex, PRBool aNotify);
virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
PRBool mDisabled);
/**
* Set the object from which a document can get a script context.
* This is the context within which all scripts (during document
* creation and during event handling) will run.
*/
NS_IMETHOD GetScriptGlobalObject(nsIScriptGlobalObject** aGlobalObject);
NS_IMETHOD SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject);
/**
* Get the name space manager for this document
*/
NS_IMETHOD GetNameSpaceManager(nsINameSpaceManager*& aManager);
/**
* Add a new observer of document change notifications. Whenever
* content is changed, appended, inserted or removed the observers are
* informed.
*/
virtual void AddObserver(nsIDocumentObserver* aObserver);
/**
* Remove an observer of document change notifications. This will
* return false if the observer cannot be found.
*/
virtual PRBool RemoveObserver(nsIDocumentObserver* aObserver);
// Observation hooks used by content nodes to propagate
// notifications to document observers.
NS_IMETHOD BeginUpdate();
NS_IMETHOD EndUpdate();
NS_IMETHOD BeginLoad();
NS_IMETHOD EndLoad();
NS_IMETHOD ContentChanged(nsIContent* aContent,
nsISupports* aSubContent);
NS_IMETHOD ContentStatesChanged(nsIContent* aContent1, nsIContent* aContent2);
NS_IMETHOD AttributeChanged(nsIContent* aChild,
PRInt32 aNameSpaceID,
nsIAtom* aAttribute,
PRInt32 aHint);
NS_IMETHOD ContentAppended(nsIContent* aContainer,
PRInt32 aNewIndexInContainer);
NS_IMETHOD ContentInserted(nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer);
NS_IMETHOD ContentReplaced(nsIContent* aContainer,
nsIContent* aOldChild,
nsIContent* aNewChild,
PRInt32 aIndexInContainer);
NS_IMETHOD ContentRemoved(nsIContent* aContainer,
nsIContent* aChild,
PRInt32 aIndexInContainer);
NS_IMETHOD StyleRuleChanged(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint); // See nsStyleConsts fot hint values
NS_IMETHOD StyleRuleAdded(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
/**
* Finds text in content
*/
NS_IMETHOD FindNext(const nsAReadableString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound);
/**
* Converts the document or a selection of the
* document to XIF (XML Interchange Format)
* and places the result in aBuffer.
*/
NS_IMETHOD CreateXIF(nsAWritableString & aBuffer, nsISelection* aSelection);
NS_IMETHOD ToXIF(nsIXIFConverter * aConverter, nsIDOMNode* aNode);
virtual void BeginConvertToXIF(nsIXIFConverter * aConverter, nsIDOMNode* aNode);
virtual void ConvertChildrenToXIF(nsIXIFConverter * aConverter, nsIDOMNode* aNode);
virtual void FinishConvertToXIF(nsIXIFConverter * aConverter, nsIDOMNode* aNode);
NS_IMETHOD FlushPendingNotifications();
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);
// 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_IMETHOD InitDiskDocument(nsFileSpec *aFileSpec);
NS_IMETHOD SaveFile(nsFileSpec* aFileSpec,
PRBool aReplaceExisting,
PRBool aSaveCopy,
const nsString& aSaveFileType,
const nsString& aSaveCharset,
PRUint32 aFlags);
NS_IMETHOD GetFileSpec(nsFileSpec& aFileSpec);
NS_IMETHOD GetModCount(PRInt32 *outModCount);
NS_IMETHOD ResetModCount();
NS_IMETHOD IncrementModCount(PRInt32 aNumMods);
// 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);
virtual PRBool IsInSelection(nsISelection* aSelection, const nsIContent *aContent) const;
virtual nsIContent* GetPrevContent(const nsIContent *aContent) const;
virtual nsIContent* GetNextContent(const nsIContent *aContent) const;
// nsIJSScriptObject interface
virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj,
jsval aID, jsval *aVp);
virtual PRBool DeleteProperty(JSContext *aContext,
JSObject *aObj, jsval aID, jsval *aVp);
virtual PRBool GetProperty(JSContext *aContext, JSObject *aObj,
jsval aID, jsval *aVp);
virtual PRBool SetProperty(JSContext *aContext, JSObject *aObj,
jsval aID, jsval *aVp);
virtual PRBool EnumerateProperty(JSContext *aContext, JSObject *aObj);
virtual PRBool Resolve(JSContext *aContext, JSObject *aObj, jsval aID,
PRBool *aDidDefineProperty);
virtual PRBool Convert(JSContext *aContext, JSObject *aObj, jsval aID);
virtual void Finalize(JSContext *aContext, JSObject *aObj);
virtual nsresult Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
virtual nsresult SetDocumentURL(nsIURI* aURI);
protected:
nsIContent* FindContent(const nsIContent* aStartNode,
const nsIContent* aTest1,
const nsIContent* aTest2) const;
NS_IMETHOD GetDTD(nsIDTD** aDTD) const;
protected:
virtual void InternalAddStyleSheet(nsIStyleSheet* aSheet); // subclass hooks for sheet ordering
virtual void InternalInsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex);
nsDocument();
virtual ~nsDocument();
nsresult Init();
nsIArena* mArena;
nsString* mDocumentTitle;
nsIURI* mDocumentURL;
nsIPrincipal* mPrincipal;
nsWeakPtr mDocumentLoadGroup;
nsString mCharacterSet;
nsVoidArray mCharSetObservers;
nsIDocument* mParentDocument;
nsVoidArray mSubDocuments;
nsVoidArray mPresShells;
nsIContent* mRootContent;
nsVoidArray mStyleSheets;
nsVoidArray mObservers;
void* mScriptObject;
nsCOMPtr<nsIScriptGlobalObject> mScriptGlobalObject;
nsIEventListenerManager* mListenerManager;
PRInt8 mDisplaySelection;
PRBool mInDestructor;
nsDOMStyleSheetList *mDOMStyleSheets;
nsINameSpaceManager* mNameSpaceManager;
nsDocHeaderData* mHeaderData;
nsILineBreaker* mLineBreaker;
nsVoidArray *mProlog;
nsVoidArray *mEpilog;
nsDocumentChildNodes* mChildNodes;
nsIWordBreaker* mWordBreaker;
// 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
nsFileSpec* mFileSpec;
PRInt32 mModCount;
nsIDTD* mDTD;
nsCOMPtr<nsIBindingManager> mBindingManager;
nsCOMPtr<nsINodeInfoManager> mNodeInfoManager; // OWNER
};
#endif /* nsDocument_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,472 @@
/* -*- 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 nsIContent,
public nsIDOMDocumentFragment,
public nsIScriptObjectOwner
{
public:
nsDocumentFragment(nsIDocument* aOwnerDocument, nsINodeInfo *aNodeInfo);
virtual ~nsDocumentFragment();
// nsISupports
NS_DECL_ISUPPORTS
// interface nsIDOMDocumentFragment
NS_IMETHOD GetNodeName(nsAWritableString& aNodeName);
NS_IMETHOD GetNodeValue(nsAWritableString& aNodeValue);
NS_IMETHOD SetNodeValue(const nsAReadableString& aNodeValue);
NS_IMETHOD GetNodeType(PRUint16* aNodeType);
NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode)
{
*aParentNode = nsnull;
return NS_OK;
}
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes)
{ return mInner.GetChildNodes(aChildNodes); }
NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild)
{ return mInner.GetFirstChild(aFirstChild); }
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild)
{ return mInner.GetLastChild(aLastChild); }
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling)
{
*aPreviousSibling = nsnull;
return NS_OK;
}
NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling)
{
*aNextSibling = nsnull;
return NS_OK;
}
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 mInner.InsertBefore(aNewChild, aRefChild, aReturn); }
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild,
nsIDOMNode** aReturn)
{ return mInner.ReplaceChild(aNewChild, aOldChild, aReturn); }
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
{ return mInner.RemoveChild(aOldChild, aReturn); }
NS_IMETHOD AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
{ return mInner.AppendChild(aNewChild, aReturn); }
NS_IMETHOD HasChildNodes(PRBool* aReturn)
{ return mInner.HasChildNodes(aReturn); }
NS_IMETHOD HasAttributes(PRBool* aReturn)
{ return mInner.HasAttributes(aReturn); }
NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn);
NS_IMETHOD GetPrefix(nsAWritableString& aPrefix);
NS_IMETHOD SetPrefix(const nsAReadableString& aPrefix);
NS_IMETHOD GetNamespaceURI(nsAWritableString& aNamespaceURI);
NS_IMETHOD GetLocalName(nsAWritableString& aLocalName);
NS_IMETHOD Normalize();
NS_IMETHOD IsSupported(const nsAReadableString& aFeature,
const nsAReadableString& aVersion,
PRBool* aReturn);
// interface nsIScriptObjectOwner
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
// interface nsIContent
NS_IMETHOD NormalizeAttributeString(const nsAReadableString& aStr,
nsINodeInfo*& aNodeInfo)
{
aNodeInfo = nsnull;
return NS_OK;
}
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
{
aResult = nsnull;
return NS_OK;
}
NS_IMETHOD SetParent(nsIContent* aParent)
{ return NS_OK; }
NS_IMETHOD GetNameSpaceID(PRInt32& aResult) const
{
aResult = kNameSpaceID_None;
return NS_OK;
}
NS_IMETHOD GetTag(nsIAtom*& aResult) const
{
aResult = nsnull;
return NS_OK;
}
NS_IMETHOD GetNodeInfo(nsINodeInfo*& aResult) const
{
aResult = nsnull;
return NS_OK;
}
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& aIndex) const
{ return mInner.IndexOf(aPossibleChild, aIndex); }
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 IsSynthetic(PRBool& aResult)
{ return mInner.IsSynthetic(aResult); }
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 GetAttributeCount(PRInt32& aCountResult) const
{
aCountResult = 0;
return NS_OK;
}
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const
{ return mInner.List(out, aIndent); }
NS_IMETHOD DumpContent(FILE* out = stdout, PRInt32 aIndent = 0,PRBool aDumpAll=PR_TRUE) const
{
return mInner.DumpContent(out, aIndent,aDumpAll);
}
NS_IMETHOD BeginConvertToXIF(nsIXIFConverter* aConverter) const
{ return NS_OK; }
NS_IMETHOD ConvertContentToXIF(nsIXIFConverter* aConverter) const
{ return NS_OK; }
NS_IMETHOD FinishConvertToXIF(nsIXIFConverter* aConverter) const
{ return NS_OK; }
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 GetContentID(PRUint32* aID) {
*aID = 0;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD SetContentID(PRUint32 aID) {
return NS_ERROR_NOT_IMPLEMENTED;
}
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;
}
protected:
nsGenericContainerElement mInner;
void* mScriptObject;
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, nodeInfo);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(NS_GET_IID(nsIDOMDocumentFragment),
(void**) aInstancePtrResult);
}
nsDocumentFragment::nsDocumentFragment(nsIDocument* aOwnerDocument,
nsINodeInfo *aNodeInfo)
{
NS_INIT_REFCNT();
mInner.Init(this, aNodeInfo);
mScriptObject = nsnull;
mOwnerDocument = aOwnerDocument;
NS_IF_ADDREF(mOwnerDocument);
}
nsDocumentFragment::~nsDocumentFragment()
{
NS_IF_RELEASE(mOwnerDocument);
}
NS_IMPL_ADDREF(nsDocumentFragment)
NS_IMPL_RELEASE(nsDocumentFragment)
nsresult
nsDocumentFragment::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (aIID.Equals(NS_GET_IID(nsISupports))) {
nsIDOMDocumentFragment* tmp = this;
nsISupports* tmp2 = tmp;
*aInstancePtr = (void*) tmp2;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIDOMDocumentFragment))) {
nsIDOMDocumentFragment* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIDOMNode))) {
nsIDOMDocumentFragment* 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(nsIContent))) {
nsIContent* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
nsDocumentFragment::GetNodeName(nsAWritableString& aNodeName)
{
aNodeName.Assign(NS_ConvertASCIItoUCS2("#document-fragment"));
return NS_OK;
}
NS_IMETHODIMP
nsDocumentFragment::GetNodeValue(nsAWritableString& aNodeValue)
{
aNodeValue.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsDocumentFragment::SetNodeValue(const nsAReadableString& aNodeValue)
{
// The node value can't be modified
return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
}
NS_IMETHODIMP
nsDocumentFragment::GetNodeType(PRUint16* aNodeType)
{
*aNodeType = (PRUint16)nsIDOMNode::DOCUMENT_FRAGMENT_NODE;
return NS_OK;
}
NS_IMETHODIMP
nsDocumentFragment::GetOwnerDocument(nsIDOMDocument** aOwnerDocument)
{
if (nsnull != mOwnerDocument) {
return mOwnerDocument->QueryInterface(NS_GET_IID(nsIDOMDocument), (void **)aOwnerDocument);
}
else {
*aOwnerDocument = nsnull;
return NS_OK;
}
}
NS_IMETHODIMP
nsDocumentFragment::GetNamespaceURI(nsAWritableString& aNamespaceURI)
{
aNamespaceURI.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsDocumentFragment::GetPrefix(nsAWritableString& aPrefix)
{
aPrefix.Truncate();
return NS_OK;
}
NS_IMETHODIMP
nsDocumentFragment::SetPrefix(const nsAReadableString& aPrefix)
{
return NS_ERROR_DOM_NAMESPACE_ERR;
}
NS_IMETHODIMP
nsDocumentFragment::GetLocalName(nsAWritableString& aLocalName)
{
return GetNodeName(aLocalName);
}
NS_IMETHODIMP
nsDocumentFragment::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
{
nsDocumentFragment* it;
it = new nsDocumentFragment(mOwnerDocument, mInner.mNodeInfo);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
//XXX mInner.CopyInnerTo(this, &it->mInner);
return it->QueryInterface(NS_GET_IID(nsIDOMNode), (void**) aReturn);
}
NS_IMETHODIMP
nsDocumentFragment::Normalize()
{
// Nothing to do here yet
return NS_OK;
}
NS_IMETHODIMP
nsDocumentFragment::IsSupported(const nsAReadableString& aFeature,
const nsAReadableString& aVersion,
PRBool* aReturn)
{
return nsGenericElement::InternalIsSupported(aFeature, aVersion, aReturn);
}
NS_IMETHODIMP
nsDocumentFragment::GetScriptObject(nsIScriptContext* aContext,
void** aScriptObject)
{
nsresult res = NS_OK;
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
res = mInner.GetScriptObjectFactory(&factory);
if (NS_OK != res) {
return res;
}
res = factory->NewScriptDocumentFragment(aContext,
(nsISupports*)(nsIDOMDocumentFragment*)this,
mOwnerDocument,
(void**)&mScriptObject);
NS_RELEASE(factory);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsDocumentFragment::SetScriptObject(void* aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}

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,659 @@
/* -*- 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 IsSynthetic(PRBool& aResult) {
aResult = PR_FALSE;
return NS_OK;
}
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;
// Implementation for nsIContent
nsresult BeginConvertToXIF(nsIXIFConverter * aConverter) const;
nsresult ConvertContentToXIF(const nsIContent *aOuterContent,
nsIXIFConverter * aConverter) const;
nsresult FinishConvertToXIF(nsIXIFConverter * aConverter) const;
nsresult CanContainChildren(PRBool& aResult) const {
aResult = PR_FALSE;
return NS_OK;
}
nsresult ChildCount(PRInt32& aResult) const {
aResult = 0;
return NS_OK;
}
nsresult ChildAt(PRInt32 aIndex, nsIContent*& aResult) const {
aResult = nsnull;
return NS_OK;
}
nsresult IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const {
aResult = -1;
return NS_OK;
}
nsresult InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) {
return NS_OK;
}
nsresult ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify) {
return NS_OK;
}
nsresult AppendChildTo(nsIContent* aKid, PRBool aNotify) {
return NS_OK;
}
nsresult RemoveChildAt(PRInt32 aIndex, PRBool aNotify) {
return NS_OK;
}
nsresult SplitText(nsIContent *aOuterContent, PRUint32 aOffset,
nsIDOMText** aReturn);
nsresult GetText(const nsTextFragment** aFragmentsResult);
nsresult GetTextLength(PRInt32* aLengthResult);
nsresult CopyText(nsAWritableString& aResult);
nsresult SetText(nsIContent *aOuterContent,
const PRUnichar* aBuffer,
PRInt32 aLength,
PRBool aNotify);
nsresult SetText(nsIContent *aOuterContent,
const nsAReadableString& aStr,
PRBool aNotify);
nsresult SetText(nsIContent *aOuterContent,
const char* aBuffer,
PRInt32 aLength,
PRBool aNotify);
nsresult IsOnlyWhitespace(PRBool* aResult);
//----------------------------------------
nsresult GetListenerManager(nsIContent* aOuterContent, nsIEventListenerManager** aInstancePtrResult);
void ToCString(nsAWritableString& aBuf, PRInt32 aOffset, PRInt32 aLen) const;
nsIDocument* mDocument;
nsIContent* mParent;
void* mScriptObject;
nsIEventListenerManager* mListenerManager;
nsIContent* mCapturer;
nsTextFragment mText;
nsVoidArray *mRangeList;
};
//----------------------------------------------------------------------
/**
* Mostly implement the nsIDOMNode API by forwarding the methods to a
* generic content object (either nsGenericHTMLLeafElement or
* nsGenericHTMLContainerContent)
*
* Note that classes using this macro will need to implement:
* NS_IMETHOD GetNodeType(PRUint16* aNodeType);
* NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn);
*/
#define NS_IMPL_IDOMNODE_USING_GENERIC_DOM_DATA(_g) \
NS_IMETHOD GetNodeName(nsAWritableString& aNodeName); \
NS_IMETHOD GetLocalName(nsAWritableString& aLocalName) { \
return GetNodeName(aLocalName); \
} \
NS_IMETHOD GetNodeValue(nsAWritableString& aNodeValue) { \
return _g.GetNodeValue(aNodeValue); \
} \
NS_IMETHOD SetNodeValue(const nsAReadableString& aNodeValue) { \
return _g.SetNodeValue(this, aNodeValue); \
} \
NS_IMETHOD GetNodeType(PRUint16* aNodeType); \
NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode) { \
return _g.GetParentNode(aParentNode); \
} \
NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes) { \
return _g.GetChildNodes(aChildNodes); \
} \
NS_IMETHOD HasChildNodes(PRBool* aHasChildNodes) { \
return _g.HasChildNodes(aHasChildNodes); \
} \
NS_IMETHOD HasAttributes(PRBool* aHasAttributes) { \
return _g.HasAttributes(aHasAttributes); \
} \
NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild) { \
return _g.GetFirstChild(aFirstChild); \
} \
NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild) { \
return _g.GetLastChild(aLastChild); \
} \
NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling) { \
return _g.GetPreviousSibling(this, aPreviousSibling); \
} \
NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling) { \
return _g.GetNextSibling(this, aNextSibling); \
} \
NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes) { \
return _g.GetAttributes(aAttributes); \
} \
NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, \
nsIDOMNode** aReturn) { \
return _g.InsertBefore(aNewChild, aRefChild, aReturn); \
} \
NS_IMETHOD AppendChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { \
return _g.AppendChild(aOldChild, aReturn); \
} \
NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, \
nsIDOMNode** aReturn) { \
return _g.ReplaceChild(aNewChild, aOldChild, aReturn); \
} \
NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { \
return _g.RemoveChild(aOldChild, aReturn); \
} \
NS_IMETHOD GetOwnerDocument(nsIDOMDocument** aOwnerDocument) { \
return _g.GetOwnerDocument(aOwnerDocument); \
} \
NS_IMETHOD GetNamespaceURI(nsAWritableString& aNamespaceURI) { \
return _g.GetNamespaceURI(aNamespaceURI); \
} \
NS_IMETHOD GetPrefix(nsAWritableString& aPrefix) { \
return _g.GetPrefix(aPrefix); \
} \
NS_IMETHOD SetPrefix(const nsAReadableString& aPrefix) { \
return _g.SetPrefix(aPrefix); \
} \
NS_IMETHOD Normalize() { \
return NS_OK; \
} \
NS_IMETHOD IsSupported(const nsAReadableString& aFeature, \
const nsAReadableString& aVersion, \
PRBool* aReturn) { \
return _g.IsSupported(aFeature, aVersion, aReturn); \
} \
NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn);
#define NS_IMPL_IDOMCHARACTERDATA_USING_GENERIC_DOM_DATA(_g) \
NS_IMETHOD GetData(nsAWritableString& aData) { \
return _g.GetData(aData); \
} \
NS_IMETHOD SetData(const nsAReadableString& aData) { \
return _g.SetData(this, aData); \
} \
NS_IMETHOD GetLength(PRUint32* aLength) { \
return _g.GetLength(aLength); \
} \
NS_IMETHOD SubstringData(PRUint32 aStart, PRUint32 aEnd, nsAWritableString& aReturn) { \
return _g.SubstringData(aStart, aEnd, aReturn); \
} \
NS_IMETHOD AppendData(const nsAReadableString& aData) { \
return _g.AppendData(this, aData); \
} \
NS_IMETHOD InsertData(PRUint32 aOffset, const nsAReadableString& aData) { \
return _g.InsertData(this, aOffset, aData); \
} \
NS_IMETHOD DeleteData(PRUint32 aOffset, PRUint32 aCount) { \
return _g.DeleteData(this, aOffset, aCount); \
} \
NS_IMETHOD ReplaceData(PRUint32 aOffset, PRUint32 aCount, \
const nsAReadableString& aData) { \
return _g.ReplaceData(this, aOffset, aCount, aData); \
}
/**
* Implement the nsIDOMEventReceiver API by forwarding the methods to a
* generic content object (either nsGenericHTMLLeafElement or
* nsGenericHTMLContainerContent)
*/
#define NS_IMPL_IDOMEVENTRECEIVER_USING_GENERIC_DOM_DATA(_g) \
NS_IMETHOD AddEventListenerByIID(nsIDOMEventListener *aListener, \
const nsIID& aIID) { \
return _g.AddEventListenerByIID(aListener, aIID); \
} \
NS_IMETHOD RemoveEventListenerByIID(nsIDOMEventListener *aListener, \
const nsIID& aIID) { \
return _g.RemoveEventListenerByIID(aListener, aIID); \
} \
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aResult) { \
return _g.GetListenerManager(aResult); \
} \
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager** aResult) { \
return _g.GetNewListenerManager(aResult); \
} \
NS_IMETHOD HandleEvent(nsIDOMEvent *aEvent) { \
return _g.HandleEvent(aEvent); \
} \
NS_IMETHOD AddEventListener(const nsAReadableString& aType, \
nsIDOMEventListener* aListener, \
PRBool aUseCapture) { \
return _g.AddEventListener(aType, aListener, aUseCapture); \
} \
NS_IMETHOD RemoveEventListener(const nsAReadableString& aType, \
nsIDOMEventListener* aListener, \
PRBool aUseCapture) { \
return _g.RemoveEventListener(aType, aListener, aUseCapture); \
}
/**
* Implement the nsIScriptObjectOwner API by forwarding the methods to a
* generic content object (either nsGenericHTMLLeafElement or
* nsGenericHTMLContainerContent)
*/
#define NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC_DOM_DATA(_g) \
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, \
void** aScriptObject) { \
return _g.GetScriptObject(this, aContext, aScriptObject); \
} \
NS_IMETHOD SetScriptObject(void *aScriptObject) { \
return _g.SetScriptObject(aScriptObject); \
}
#define NS_IMPL_ICONTENT_USING_GENERIC_DOM_DATA(_g) \
NS_IMETHOD GetDocument(nsIDocument*& aResult) const { \
return _g.GetDocument(aResult); \
} \
NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep, PRBool aCompileEventHandlers) { \
return _g.SetDocument(aDocument, aDeep, aCompileEventHandlers); \
} \
NS_IMETHOD GetParent(nsIContent*& aResult) const { \
return _g.GetParent(aResult); \
} \
NS_IMETHOD SetParent(nsIContent* aParent) { \
return _g.SetParent(aParent); \
} \
NS_IMETHOD CanContainChildren(PRBool& aResult) const { \
return _g.CanContainChildren(aResult); \
} \
NS_IMETHOD ChildCount(PRInt32& aResult) const { \
return _g.ChildCount(aResult); \
} \
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const { \
return _g.ChildAt(aIndex, aResult); \
} \
NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const { \
return _g.IndexOf(aPossibleChild, aResult); \
} \
NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, \
PRBool aNotify) { \
return _g.InsertChildAt(aKid, aIndex, aNotify); \
} \
NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, \
PRBool aNotify) { \
return _g.ReplaceChildAt(aKid, aIndex, aNotify); \
} \
NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify) { \
return _g.AppendChildTo(aKid, aNotify); \
} \
NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify) { \
return _g.RemoveChildAt(aIndex, aNotify); \
} \
NS_IMETHOD IsSynthetic(PRBool& aResult) { \
return _g.IsSynthetic(aResult); \
} \
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 BeginConvertToXIF(nsIXIFConverter * aConverter) const { \
return _g.BeginConvertToXIF(aConverter); \
} \
NS_IMETHOD ConvertContentToXIF(nsIXIFConverter * aConverter) const { \
return _g.ConvertContentToXIF(this, aConverter); \
} \
NS_IMETHOD FinishConvertToXIF(nsIXIFConverter * aConverter) const { \
return _g.FinishConvertToXIF(aConverter); \
} \
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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,717 @@
/* -*- 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"
static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID);
static NS_DEFINE_CID(kEntityConverterCID, NS_ENTITYCONVERTER_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;
}
nsHTMLContentSerializer::~nsHTMLContentSerializer()
{
}
nsresult
nsHTMLContentSerializer::GetEntityConverter(nsIEntityConverter** aConverter)
{
if (!mEntityConverter) {
nsresult rv;
rv = nsComponentManager::CreateInstance(kEntityConverterCID, NULL,
NS_GET_IID(nsIEntityConverter),
getter_AddRefs(mEntityConverter));
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
}
CallQueryInterface(mEntityConverter.get(), aConverter);
return NS_OK;
}
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)
{
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;
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)) {
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),
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;
}
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) {
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;
}
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 oldLineOffset = 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);
}
if (addLineBreak) {
AppendToString(mLineBreak, aOutputStr);
mColPos = 0;
}
strOffset = indx+1;
}
}
}
void
nsHTMLContentSerializer::AppendToString(const nsAReadableString& aStr,
nsAWritableString& aOutputStr,
PRBool aTranslateEntities,
PRBool aIncrColumn)
{
if (mBodyOnly && !mInBody) {
return;
}
nsresult rv;
if (aIncrColumn) {
mColPos += aStr.Length();
}
if (aTranslateEntities) {
nsCOMPtr<nsIEntityConverter> converter;
GetEntityConverter(getter_AddRefs(converter));
if (converter) {
PRUnichar *encodedBuffer;
rv = mEntityConverter->ConvertToEntities(nsPromiseFlatString(aStr),
nsIEntityConverter::html40Latin1,
&encodedBuffer);
if (NS_SUCCEEDED(rv)) {
aOutputStr.Append(encodedBuffer);
nsCRT::free(encodedBuffer);
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) {
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) {
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) {
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) {
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, -1,
aStr);
}
}
if ((aName == nsHTMLAtoms::head) ||
(aName == nsHTMLAtoms::table) ||
(aName == nsHTMLAtoms::tr) ||
(aName == nsHTMLAtoms::ul) ||
(aName == nsHTMLAtoms::ol) ||
(aName == nsHTMLAtoms::tbody) ||
(aName == nsHTMLAtoms::form) ||
(aName == nsHTMLAtoms::frameset) ||
(aName == nsHTMLAtoms::blockquote) ||
(aName == nsHTMLAtoms::li) ||
(aName == nsHTMLAtoms::dt) ||
(aName == nsHTMLAtoms::dd)) {
mIndent++;
}
}
void
nsHTMLContentSerializer::EndIndentation(nsIAtom* aName,
PRBool aHasDirtyAttr,
nsAWritableString& aStr)
{
if ((aName == nsHTMLAtoms::head) ||
(aName == nsHTMLAtoms::table) ||
(aName == nsHTMLAtoms::tr) ||
(aName == nsHTMLAtoms::ul) ||
(aName == nsHTMLAtoms::ol) ||
(aName == nsHTMLAtoms::li) ||
(aName == nsHTMLAtoms::tbody) ||
(aName == nsHTMLAtoms::form) ||
(aName == nsHTMLAtoms::frameset)) {
mIndent--;
}
if ((mDoFormat || aHasDirtyAttr) && !mPreLevel && !mColPos) {
for (PRInt32 i = mIndent; --i >= 0; ) {
AppendToString(kIndentStr, -1,
aStr);
}
}
}
// See if the string has any lines longer than longLineLen:
// if so, we presume formatting is wonky (e.g. the node has been edited)
// and we'd better rewrap the whole text node.
PRBool
nsHTMLContentSerializer::HasLongLines(const nsString& text, PRInt32& aLastNewlineOffset)
{
PRUint32 start=0;
PRUint32 theLen=text.Length();
PRBool rv = PR_FALSE;
aLastNewlineOffset = kNotFound;
for (start = 0; start < theLen; )
{
PRInt32 eol = text.FindChar('\n', PR_FALSE, start);
if (eol < 0) {
eol = text.Length();
}
else {
aLastNewlineOffset = eol;
}
if (PRInt32(eol - start) > kLongLineLen)
rv = PR_TRUE;
start = eol+1;
}
return rv;
}

View File

@@ -0,0 +1,100 @@
/* -*- 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);
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;
PRInt32 mMaxColumn;
nsString mLineBreak;
};
extern nsresult NS_NewHTMLContentSerializer(nsIContentSerializer** aSerializer);
#endif

View File

@@ -0,0 +1,434 @@
/* -*- 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 NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID);
static NS_DEFINE_IID(kINameSpaceIID, NS_INAMESPACE_IID);
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, kINameSpaceIID)
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(kINameSpaceIID, (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(kINameSpaceIID, (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, kINameSpaceManagerIID)
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(kINameSpaceIID, (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(kINameSpaceManagerIID, (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___ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,191 @@
/* -*- 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"
class nsPlainTextSerializer : public nsIContentSerializer,
public nsIHTMLContentSink,
public nsIHTMLToTextSink
{
public:
nsPlainTextSerializer();
virtual ~nsPlainTextSerializer();
NS_DECL_ISUPPORTS
// nsIContentSerializer
NS_IMETHOD Init(PRUint32 flags, PRUint32 aWrapColumn);
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 WriteQuotesAndIndent();
void WriteSimple(nsString& aString);
void Write(const nsString& aString);
PRBool DoOutput();
PRBool MayWrap();
PRBool IsBlockLevel(PRInt32 aId);
PRBool IsContainer(PRInt32 aId);
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 nsString& aText);
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;
PRInt32 mColPos;
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 mCacheLine; // If the line should be cached before output. This makes it possible to do smarter wrapping.
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;
};
extern nsresult NS_NewPlainTextSerializer(nsIContentSerializer** aSerializer);
#endif

File diff suppressed because it is too large Load Diff

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.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();
// 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);
/*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;
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 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);
nsresult ComparePointToRange(nsIDOMNode* aParent, PRInt32 aOffset, PRInt32* aResult);
PRInt32 GetAncestorsAndOffsets(nsIDOMNode* aNode, PRInt32 aOffset,
nsVoidArray* aAncestorNodes, nsVoidArray* aAncestorOffsets);
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,262 @@
/* -*- 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 "nsTextFragment.h"
#include "nsString.h"
#include "nsCRT.h"
#include "nsReadableUtils.h"
#include "nsMemory.h"
nsTextFragment::~nsTextFragment()
{
ReleaseText();
}
void
nsTextFragment::ReleaseText()
{
if (mState.mLength && m1b && mState.mInHeap) {
if (mState.mIs2b) {
nsMemory::Free(m2b);
}
else {
nsMemory::Free(m1b);
}
}
m1b = nsnull;
mState.mIs2b = 0;
mState.mInHeap = 0;
mState.mLength = 0;
}
nsTextFragment::nsTextFragment(const nsTextFragment& aOther)
: m1b(nsnull),
mAllBits(0)
{
if (aOther.Is2b()) {
SetTo(aOther.Get2b(), aOther.GetLength());
}
else {
SetTo(aOther.Get1b(), aOther.GetLength());
}
}
nsTextFragment::nsTextFragment(const char* aString)
: m1b(nsnull),
mAllBits(0)
{
SetTo(aString, strlen(aString));
}
nsTextFragment::nsTextFragment(const PRUnichar* aString)
: m1b(nsnull),
mAllBits(0)
{
SetTo(aString, nsCRT::strlen(aString));
}
nsTextFragment::nsTextFragment(const nsString& aString)
: m1b(nsnull),
mAllBits(0)
{
SetTo(aString.GetUnicode(), aString.Length());
}
nsTextFragment&
nsTextFragment::operator=(const nsTextFragment& aOther)
{
if (aOther.Is2b()) {
SetTo(aOther.Get2b(), aOther.GetLength());
}
else {
SetTo(aOther.Get1b(), aOther.GetLength());
}
return *this;
}
nsTextFragment&
nsTextFragment::operator=(const char* aString)
{
SetTo(aString, nsCRT::strlen(aString));
return *this;
}
nsTextFragment&
nsTextFragment::operator=(const PRUnichar* aString)
{
SetTo(aString, nsCRT::strlen(aString));
return *this;
}
nsTextFragment&
nsTextFragment::operator=(const nsAReadableString& aString)
{
ReleaseText();
PRUint32 length = aString.Length();
if (length > 0) {
if (IsASCII(aString)) {
m1b = NS_REINTERPRET_CAST(unsigned char *, ToNewCString(aString));
mState.mIs2b = 0;
}
else {
m2b = ToNewUnicode(aString);
mState.mIs2b = 1;
}
mState.mInHeap = 1;
mState.mLength = (PRInt32)length;
}
return *this;
}
void
nsTextFragment::SetTo(PRUnichar* aBuffer, PRInt32 aLength, PRBool aRelease)
{
ReleaseText();
m2b = aBuffer;
mState.mIs2b = 1;
mState.mInHeap = aRelease ? 1 : 0;
mState.mLength = aLength;
}
void
nsTextFragment::SetTo(const PRUnichar* aBuffer, PRInt32 aLength)
{
ReleaseText();
if (0 != aLength) {
// See if we need to store the data in ucs2 or not
PRBool need2 = PR_FALSE;
const PRUnichar* ucp = aBuffer;
const PRUnichar* uend = aBuffer + aLength;
while (ucp < uend) {
PRUnichar ch = *ucp++;
if (ch >> 8) {
need2 = PR_TRUE;
break;
}
}
if (need2) {
// Use ucs2 storage because we have to
PRUnichar* nt = (PRUnichar*)nsMemory::Alloc(aLength*sizeof(PRUnichar));
if (nsnull != nt) {
// Copy data
nsCRT::memcpy(nt, aBuffer, sizeof(PRUnichar) * aLength);
// Setup our fields
m2b = nt;
mState.mIs2b = 1;
mState.mInHeap = 1;
mState.mLength = aLength;
}
}
else {
// Use 1 byte storage because we can
unsigned char* nt = (unsigned char*)nsMemory::Alloc(aLength*sizeof(unsigned char));
if (nsnull != nt) {
// Copy data
unsigned char* cp = nt;
unsigned char* end = nt + aLength;
while (cp < end) {
*cp++ = (unsigned char) *aBuffer++;
}
// Setup our fields
m1b = nt;
mState.mIs2b = 0;
mState.mInHeap = 1;
mState.mLength = aLength;
}
}
}
}
void
nsTextFragment::SetTo(const char* aBuffer, PRInt32 aLength)
{
ReleaseText();
if (0 != aLength) {
unsigned char* nt = (unsigned char*)nsMemory::Alloc(aLength*sizeof(unsigned char));
if (nsnull != nt) {
nsCRT::memcpy(nt, aBuffer, sizeof(unsigned char) * aLength);
m1b = nt;
mState.mIs2b = 0;
mState.mInHeap = 1;
mState.mLength = aLength;
}
}
}
void
nsTextFragment::AppendTo(nsString& aString) const
{
if (mState.mIs2b) {
aString.Append(m2b, mState.mLength);
}
else {
aString.AppendWithConversion((char*)m1b, mState.mLength);
}
}
void
nsTextFragment::CopyTo(PRUnichar* aDest, PRInt32 aOffset, PRInt32 aCount)
{
if (aOffset < 0) aOffset = 0;
if (aOffset + aCount > GetLength()) {
aCount = mState.mLength - aOffset;
}
if (0 != aCount) {
if (mState.mIs2b) {
nsCRT::memcpy(aDest, m2b + aOffset, sizeof(PRUnichar) * aCount);
}
else {
unsigned char* cp = m1b + aOffset;
unsigned char* end = cp + aCount;
while (cp < end) {
*aDest++ = PRUnichar(*cp++);
}
}
}
}
void
nsTextFragment::CopyTo(char* aDest, PRInt32 aOffset, PRInt32 aCount)
{
if (aOffset < 0) aOffset = 0;
if (aOffset + aCount > GetLength()) {
aCount = mState.mLength - aOffset;
}
if (0 != aCount) {
if (mState.mIs2b) {
PRUnichar* cp = m2b + aOffset;
PRUnichar* end = cp + aCount;
while (cp < end) {
*aDest++ = (unsigned char) (*cp++);
}
}
else {
nsCRT::memcpy(aDest, m1b + aOffset, sizeof(char) * aCount);
}
}
}

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 "nsIDOMText.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMEventReceiver.h"
#include "nsIContent.h"
#include "nsITextContent.h"
#include "nsGenericDOMDataNode.h"
#include "nsFrame.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,582 @@
/* -*- 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;
}
nsXMLContentSerializer::~nsXMLContentSerializer()
{
}
NS_IMPL_ISUPPORTS1(nsXMLContentSerializer, nsIContentSerializer)
NS_IMETHODIMP
nsXMLContentSerializer::Init(PRUint32 flags, PRUint32 aWrapColumn)
{
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);
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; index >= 0; index--) {
NameSpaceDecl* decl = (NameSpaceDecl*)mNameSpaceStack.ElementAt(index);
if (decl) {
if (decl->mOwner != aOwner) {
break;
}
mNameSpaceStack.RemoveElementAt(index);
delete decl;
}
}
}
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; index >= 0; index--) {
NameSpaceDecl* decl = (NameSpaceDecl*)mNameSpaceStack.ElementAt(index);
if (decl) {
// 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);
AppendToString(aValue, aStr, PR_TRUE);
AppendToString(NS_LITERAL_STRING("\""), aStr);
}
NS_IMETHODIMP
nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
nsAWritableString& aStr)
{
NS_ENSURE_ARG(aElement);
nsAutoString tagPrefix, tagLocalName, tagNamespaceURI;
nsAutoString xmlnsStr, defaultnsStr;
xmlnsStr.Assign(kXMLNS);
defaultnsStr.Assign(NS_LITERAL_STRING(""));
aElement->GetPrefix(tagPrefix);
aElement->GetLocalName(tagLocalName);
aElement->GetNamespaceURI(tagNamespaceURI);
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
if (!content) return NS_ERROR_FAILURE;
PRInt32 index, count;
nsAutoString nameStr, prefixStr, uriStr, valueStr;
PRInt32 namespaceID;
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 (attrPrefix) {
attrPrefix->ToString(prefixStr);
}
else {
prefixStr.Truncate();
}
attrName->ToString(nameStr);
content->GetAttribute(namespaceID, attrName, uriStr);
if ((namespaceID == kNameSpaceID_XMLNS) ||
prefixStr.Equals(kXMLNS)) {
PushNameSpaceDecl(nameStr, uriStr, aElement);
}
else if (nameStr.Equals(kXMLNS)) {
PushNameSpaceDecl(defaultnsStr, uriStr, aElement);
}
}
PRBool addNSAttr;
// Serialize the qualified name of the element
addNSAttr = ConfirmPrefix(tagPrefix, tagNamespaceURI);
AppendToString(NS_LITERAL_STRING("<"), aStr);
if (tagPrefix.Length() > 0) {
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) {
prefixStr.Assign(kXMLNS);
}
else if (nsmanager) {
nsmanager->GetNameSpaceURI(namespaceID, uriStr);
addNSAttr = ConfirmPrefix(prefixStr, uriStr);
}
content->GetAttribute(namespaceID, attrName, valueStr);
attrName->ToString(nameStr);
SerializeAttr(prefixStr, nameStr, valueStr, aStr);
if (addNSAttr) {
SerializeAttr(xmlnsStr, prefixStr, uriStr, aStr);
PushNameSpaceDecl(prefixStr, uriStr, aElement);
}
}
AppendToString(NS_LITERAL_STRING(">"), aStr);
return NS_OK;
}
NS_IMETHODIMP
nsXMLContentSerializer::AppendElementEnd(nsIDOMElement *aElement,
nsAWritableString& aStr)
{
NS_ENSURE_ARG(aElement);
nsAutoString tagPrefix, tagLocalName, tagNamespaceURI;
aElement->GetPrefix(tagPrefix);
aElement->GetLocalName(tagLocalName);
aElement->GetNamespaceURI(tagNamespaceURI);
ConfirmPrefix(tagPrefix, tagNamespaceURI);
AppendToString(NS_LITERAL_STRING("</"), aStr);
if (tagPrefix.Length() > 0) {
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[] = {
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "",
"", "", "", "", "&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;
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;
// for each character in this chunk, check if it
// needs to be replaced
for (; c < fragmentEnd; c++, advanceLength++) {
PRUnichar val = *c;
if ((val <= kGTVal) && (kEntities[val][0] != 0)) {
entityText = kEntities[val];
break;
}
}
aOutputStr.Append(fragmentStart, advanceLength);
if (entityText) {
aOutputStr.Append(NS_ConvertASCIItoUCS2(entityText));
advanceLength++;
}
}
}
aOutputStr.Append(aStr);
}

View File

@@ -0,0 +1,101 @@
/* -*- 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);
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;
};
extern nsresult NS_NewXMLContentSerializer(nsIContentSerializer** aSerializer);
#endif

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
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,9 @@
#
# This is a list of local files which get copied to the mozilla:dist:layout directory
#
nsIEventListenerManager.h
nsIEventStateManager.h
nsIPrivateDOMEvent.h
nsIPrivateTextEvent.h
nsIPrivateTextRange.h
nsIPrivateCompositionEvent.h

View File

@@ -0,0 +1,43 @@
#
# 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
EXPORTS = \
nsIEventListenerManager.h \
nsIEventStateManager.h \
nsIPrivateDOMEvent.h \
nsIPrivateTextEvent.h \
nsIPrivateTextRange.h \
nsIPrivateCompositionEvent.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,37 @@
#!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 = \
nsIEventListenerManager.h \
nsIEventStateManager.h \
nsIPrivateDOMEvent.h \
nsIPrivateTextEvent.h \
nsIPrivateTextRange.h \
nsIPrivateCompositionEvent.h \
$(NULL)
MODULE=raptor
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,149 @@
/* -*- 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 nsIEventListenerManager_h__
#define nsIEventListenerManager_h__
#include "nsGUIEvent.h"
#include "nsISupports.h"
#include "nsVoidArray.h"
class nsIPresContext;
class nsIDOMEventListener;
class nsIScriptObjectOwner;
class nsIDOMEventTarget;
/*
* Event listener manager interface.
*/
#define NS_IEVENTLISTENERMANAGER_IID \
{ /* cd91bcf0-ded9-11d1-bd85-00805f8ae3f4 */ \
0xcd91bcf0, 0xded9, 0x11d1, \
{0xbd, 0x85, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} }
class nsIEventListenerManager : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IEVENTLISTENERMANAGER_IID; return iid; }
/**
* Retrieves events listeners of all types.
* @param
*/
virtual nsresult GetEventListeners(nsVoidArray **aListeners, const nsIID& aIID) = 0;
/**
* Sets events listeners of all types.
* @param an event listener
*/
virtual nsresult AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 flags) = 0;
/**
* Removes events listeners of all types.
* @param an event listener
*/
virtual nsresult RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 flags) = 0;
/**
* Sets events listeners of all types.
* @param an event listener
*/
virtual nsresult AddEventListenerByType(nsIDOMEventListener *aListener, const nsAReadableString& type, PRInt32 flags) = 0;
/**
* Removes events listeners of all types.
* @param an event listener
*/
virtual nsresult RemoveEventListenerByType(nsIDOMEventListener *aListener, const nsAReadableString& type, PRInt32 flags) = 0;
/**
* Creates a script event listener for the given script object with name mName and function
* body mFunc.
* @param an event listener
*/
virtual nsresult AddScriptEventListener(nsIScriptContext*aContext,
nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName,
const nsAReadableString& aFunc,
REFNSIID aIID,
PRBool aDeferCompilation) = 0;
/**
* Registers an event listener that already exists on the given script object with the event
* listener manager.
* @param an event listener
*/
virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext,
nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom* aName,
REFNSIID aIID) = 0;
/**
* Causes a check for event listeners and processing by them if they exist.
* Event flags live in nsGUIEvent.h
* @param an event listener
*/
virtual nsresult HandleEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aFlags,
nsEventStatus* aEventStatus) = 0;
/**
* Creates a DOM event that can subsequently be passed into HandleEvent.
* (used rarely in the situation where methods on the event need to be
* invoked prior to the processing of the event).
*/
virtual nsresult CreateEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
const nsAReadableString& aEventType,
nsIDOMEvent** aDOMEvent) = 0;
/**
* Changes script listener of specified event types from bubbling listeners to capturing listeners.
* @param event types
*/
virtual nsresult CaptureEvent(PRInt32 aEventTypes) = 0;
/**
* Changes script listener of specified event types from capturing listeners to bubbling listeners.
* @param event types
*/
virtual nsresult ReleaseEvent(PRInt32 aEventTypes) = 0;
/**
* Removes all event listeners registered by this instance of the listener
* manager.
*/
virtual nsresult RemoveAllListeners(PRBool aScriptOnly) = 0;
/**
* Removes all event listeners registered by this instance of the listener
* manager.
*/
virtual nsresult SetListenerTarget(nsISupports* aTarget) = 0;
};
extern NS_HTML nsresult NS_NewEventListenerManager(nsIEventListenerManager** aInstancePtrResult);
#endif // nsIEventListenerManager_h__

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.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 nsIEventStateManager_h__
#define nsIEventStateManager_h__
#include "nsGUIEvent.h"
#include "nsISupports.h"
#include "nsVoidArray.h"
class nsIContent;
class nsIPresContext;
class nsIDOMEvent;
class nsIFrame;
class nsIView;
class nsIWidget;
/*
* Event listener manager interface.
*/
#define NS_IEVENTSTATEMANAGER_IID \
{ /* 80a98c80-2036-11d2-bd89-00805f8ae3f4 */ \
0x80a98c80, 0x2036, 0x11d2, \
{0xbd, 0x89, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} }
class nsIEventStateManager : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IEVENTSTATEMANAGER_IID; return iid; }
NS_IMETHOD Init() = 0;
NS_IMETHOD PreHandleEvent(nsIPresContext* aPresContext,
nsEvent *aEvent,
nsIFrame* aTargetFrame,
nsEventStatus* aStatus,
nsIView* aView) = 0;
NS_IMETHOD PostHandleEvent(nsIPresContext* aPresContext,
nsEvent *aEvent,
nsIFrame* aTargetFrame,
nsEventStatus* aStatus,
nsIView* aView) = 0;
NS_IMETHOD SetPresContext(nsIPresContext* aPresContext) = 0;
NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame) = 0;
NS_IMETHOD GetEventTarget(nsIFrame **aFrame) = 0;
NS_IMETHOD GetEventTargetContent(nsEvent* aEvent, nsIContent** aContent) = 0;
NS_IMETHOD GetEventRelatedContent(nsIContent** aContent) = 0;
NS_IMETHOD GetContentState(nsIContent *aContent, PRInt32& aState) = 0;
NS_IMETHOD SetContentState(nsIContent *aContent, PRInt32 aState) = 0;
NS_IMETHOD GetFocusedContent(nsIContent **aContent) = 0;
NS_IMETHOD SetFocusedContent(nsIContent* aContent) = 0;
// This is an experiement and may be temporary
NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) = 0;
// Access Key Registration
NS_IMETHOD RegisterAccessKey(nsIFrame * aFrame, nsIContent* aContent, PRUint32 aKey) = 0;
NS_IMETHOD UnregisterAccessKey(nsIFrame * aFrame, nsIContent* aContent, PRUint32 aKey) = 0;
NS_IMETHOD SetCursor(PRInt32 aCursor, nsIWidget* aWidget, PRBool aLockCursor) = 0;
//Method for centralized distribution of new DOM events
NS_IMETHOD DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent) = 0;
};
#define NS_EVENT_STATE_UNSPECIFIED 0x0000
#define NS_EVENT_STATE_ACTIVE 0x0001 // mouse is down on content
#define NS_EVENT_STATE_FOCUS 0x0002 // content has focus
#define NS_EVENT_STATE_HOVER 0x0004 // mouse is hovering over content
#define NS_EVENT_STATE_DRAGOVER 0x0008 // drag is hovering over content
#endif // nsIEventStateManager_h__

View File

@@ -0,0 +1,44 @@
/* -*- 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 nsIPrivateCompositionEvent_h__
#define nsIPrivateCompositionEvent_h__
#include "nsGUIEvent.h"
#include "nsISupports.h"
// {ECF6BEF1-5F0C-11d3-9EB3-0060089FE59B}
#define NS_IPRIVATECOMPOSITIONEVENT_IID \
{ 0xecf6bef1, 0x5f0c, 0x11d3, \
{ 0x9e, 0xb3, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b }}
class nsIPrivateCompositionEvent : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IPRIVATECOMPOSITIONEVENT_IID; return iid; }
NS_IMETHOD GetCompositionReply(struct nsTextEventReply** aReply) = 0;
NS_IMETHOD GetReconversionReply(nsReconversionEventReply** aReply) = 0;
};
#endif // nsIPrivateCompositionEvent_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 nsIPrivateDOMEvent_h__
#define nsIPrivateDOMEvent_h__
#include "nsGUIEvent.h"
#include "nsISupports.h"
class nsIPresContext;
/*
* Event listener manager interface.
*/
#define NS_IPRIVATEDOMEVENT_IID \
{ /* 80a98c80-2036-11d2-bd89-00805f8ae3f4 */ \
0x80a98c80, 0x2036, 0x11d2, \
{0xbd, 0x89, 0x00, 0x80, 0x5f, 0x8a, 0xe3, 0xf4} }
class nsIDOMEventTarget;
class nsIDOMEvent;
class nsIPrivateDOMEvent : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IPRIVATEDOMEVENT_IID; return iid; }
NS_IMETHOD DuplicatePrivateData() = 0;
NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget) = 0;
NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aTarget) = 0;
NS_IMETHOD SetOriginalTarget(nsIDOMEventTarget* aTarget) = 0;
NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchPrevented) = 0;
NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent) = 0;
NS_IMETHOD HasOriginalTarget(PRBool* aResult)=0;
};
extern nsresult NS_NewDOMEvent(nsIDOMEvent** aInstancePtrResult, nsIPresContext* aPresContext, nsEvent *aEvent);
extern nsresult NS_NewDOMUIEvent(nsIDOMEvent** aInstancePtrResult,
nsIPresContext* aPresContext,
const nsAReadableString& aEventType,
nsEvent *aEvent);
#endif // nsIPrivateDOMEvent_h__

View File

@@ -0,0 +1,46 @@
/* -*- 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 nsIPrivateTextEvent_h__
#define nsIPrivateTextEvent_h__
#include "nsGUIEvent.h"
#include "nsISupports.h"
#include "nsIPrivateTextRange.h"
#define NS_IPRIVATETEXTEVENT_IID \
{ /* 37B69251-4ACE-11d3-9EA6-0060089FE59B */ \
0x37b69251, 0x4ace, 0x11d3, \
{0x9e, 0xa6, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b} }
class nsIPrivateTextEvent : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IPRIVATETEXTEVENT_IID; return iid; }
NS_IMETHOD GetText(nsString& aText) = 0;
NS_IMETHOD GetInputRange(nsIPrivateTextRangeList** aInputRange) = 0;
NS_IMETHOD GetEventReply(struct nsTextEventReply** aReply) = 0;
};
#endif // nsIPrivateTextEvent_h__

View File

@@ -0,0 +1,66 @@
/* -*- 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 nsIPrivateTextRange_h__
#define nsIPrivateTextRange_h__
#include "nsISupports.h"
#include "nsString.h"
#define NS_IPRIVATETEXTRANGE_IID \
{0xb471ab41, 0x2a79, 0x11d3, \
{ 0x9e, 0xa4, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b } }
class nsIPrivateTextRange : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IPRIVATETEXTRANGE_IID; return iid; }
enum {
TEXTRANGE_CARETPOSITION = 1,
TEXTRANGE_RAWINPUT = 2,
TEXTRANGE_SELECTEDRAWTEXT = 3,
TEXTRANGE_CONVERTEDTEXT = 4,
TEXTRANGE_SELECTEDCONVERTEDTEXT = 5
};
NS_IMETHOD GetRangeStart(PRUint16* aRangeStart)=0;
NS_IMETHOD SetRangeStart(PRUint16 aRangeStart)=0;
NS_IMETHOD GetRangeEnd(PRUint16* aRangeEnd)=0;
NS_IMETHOD SetRangeEnd(PRUint16 aRangeEnd)=0;
NS_IMETHOD GetRangeType(PRUint16* aRangeType)=0;
NS_IMETHOD SetRangeType(PRUint16 aRangeType)=0;
};
#define NS_IPRIVATETEXTRANGELIST_IID \
{ 0x1ee9d531, 0x2a79, 0x11d3, \
{ 0x9e, 0xa4, 0x0, 0x60, 0x8, 0x9f, 0xe5, 0x9b} }
class nsIPrivateTextRangeList : public nsISupports {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IPRIVATETEXTRANGELIST_IID; return iid; }
NS_IMETHOD GetLength(PRUint16* aLength)=0;
NS_IMETHOD Item(PRUint16 aIndex, nsIPrivateTextRange** aReturn)=0;
};
#endif // nsIPrivateTextRange_h__

View File

@@ -0,0 +1,7 @@
#
# This is a list of local files which get copied to the mozilla:dist:layout directory
#
nsEventListenerManager.h
nsEventStateManager.h
nsDOMEvent.h
nsDOMEventsIIDs.h

View File

@@ -0,0 +1,62 @@
#
# 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 = gkevents_s
CPPSRCS = \
nsEventListenerManager.cpp \
nsEventStateManager.cpp \
nsDOMEvent.cpp \
nsDOMEventsIIDs.cpp \
nsPrivateTextRange.cpp \
$(NULL)
EXPORTS = \
nsEventListenerManager.h \
nsEventStateManager.h \
nsDOMEvent.h \
nsDOMEventsIIDs.h \
nsPrivateTextRange.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
# 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_HTML
INCLUDES += -I$(srcdir)/../../html/base/src \
-I$(srcdir)/../../xul/content/src \
$(NULL)

View File

@@ -0,0 +1,63 @@
#!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>
LIBRARY_NAME=raptorevents_s
MODULE=raptor
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
CPPSRCS= nsEventListenerManager.cpp \
nsEventStateManager.cpp \
nsDOMEvent.cpp \
nsDOMEventsIIDs.cpp \
nsPrivateTextRange.cpp \
$(NULL)
CPP_OBJS= .\$(OBJDIR)\nsEventListenerManager.obj \
.\$(OBJDIR)\nsEventStateManager.obj \
.\$(OBJDIR)\nsDOMEvent.obj \
.\$(OBJDIR)\nsDOMEventsIIDs.obj \
.\$(OBJDIR)\nsPrivateTextRange.obj \
$(NULL)
EXPORTS= nsEventListenerManager.h nsEventStateManager.h nsDOMEvent.h nsDOMEventsIIDs.h nsPrivateTextRange.h
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \
-I$(PUBLIC)\dom -I$(PUBLIC)\js -I..\..\html\base\src -I$(PUBLIC)\netlib -I..\..\xul\content\src
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

File diff suppressed because it is too large Load Diff

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 nsDOMEvent_h__
#define nsDOMEvent_h__
#include "nsIDOMKeyEvent.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMNSUIEvent.h"
#include "nsISupports.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIPrivateCompositionEvent.h"
#include "nsIPrivateTextEvent.h"
#include "nsIPrivateTextRange.h"
#include "nsIDOMEvent.h"
#include "nsIPresContext.h"
#include "nsPoint.h"
#include "nsGUIEvent.h"
class nsIContent;
class nsIScrollableView;
class nsDOMEvent : public nsIDOMKeyEvent,
public nsIDOMMouseEvent,
public nsIDOMNSUIEvent,
public nsIPrivateDOMEvent,
public nsIPrivateTextEvent,
public nsIPrivateCompositionEvent {
public:
// Note: this enum must be kept in sync with mEventNames in nsDOMEvent.cpp
enum nsDOMEvents {
eDOMEvents_mousedown=0,
eDOMEvents_mouseup,
eDOMEvents_click,
eDOMEvents_dblclick,
eDOMEvents_mouseover,
eDOMEvents_mouseout,
eDOMEvents_mousemove,
eDOMEvents_keydown,
eDOMEvents_keyup,
eDOMEvents_keypress,
eDOMEvents_focus,
eDOMEvents_blur,
eDOMEvents_load,
eDOMEvents_unload,
eDOMEvents_abort,
eDOMEvents_error,
eDOMEvents_submit,
eDOMEvents_reset,
eDOMEvents_change,
eDOMEvents_select,
eDOMEvents_input,
eDOMEvents_paint,
eDOMEvents_text,
eDOMEvents_create,
eDOMEvents_close,
eDOMEvents_destroy,
eDOMEvents_command,
eDOMEvents_broadcast,
eDOMEvents_commandupdate,
eDOMEvents_dragenter,
eDOMEvents_dragover,
eDOMEvents_dragexit,
eDOMEvents_dragdrop,
eDOMEvents_draggesture,
eDOMEvents_resize,
eDOMEvents_scroll,
eDOMEvents_overflow,
eDOMEvents_underflow,
eDOMEvents_overflowchanged
};
nsDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, const nsAReadableString& aEventType);
virtual ~nsDOMEvent();
NS_DECL_ISUPPORTS
// nsIDOMEvent Interface
NS_IMETHOD GetType(nsAWritableString& aType);
NS_IMETHOD GetTarget(nsIDOMEventTarget** aTarget);
NS_IMETHOD GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget);
NS_IMETHOD GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget);
NS_IMETHOD GetEventPhase(PRUint16* aEventPhase);
NS_IMETHOD GetBubbles(PRBool* aBubbles);
NS_IMETHOD GetCancelable(PRBool* aCancelable);
NS_IMETHOD GetTimeStamp(PRUint64* aTimestamp);
NS_IMETHOD StopPropagation();
NS_IMETHOD PreventBubble();
NS_IMETHOD PreventCapture();
NS_IMETHOD PreventDefault();
NS_IMETHOD InitEvent(const nsAReadableString& aEventTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg);
// nsIDOMUIEvent Interface
NS_IMETHOD GetView(nsIDOMAbstractView** aView);
NS_IMETHOD GetDetail(PRInt32* aDetail);
NS_IMETHOD InitUIEvent(const nsAReadableString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, nsIDOMAbstractView* aViewArg, PRInt32 aDetailArg);
// nsIDOMMouseEvent Interface and nsIDOMKeyEvent Interface
NS_IMETHOD GetScreenX(PRInt32* aScreenX);
NS_IMETHOD GetScreenY(PRInt32* aScreenY);
NS_IMETHOD GetClientX(PRInt32* aClientX);
NS_IMETHOD GetClientY(PRInt32* aClientY);
NS_IMETHOD GetAltKey(PRBool* aAltKey);
NS_IMETHOD GetCtrlKey(PRBool* aCtrlKey);
NS_IMETHOD GetShiftKey(PRBool* aShiftKey);
NS_IMETHOD GetMetaKey(PRBool* aMetaKey);
NS_IMETHOD GetButton(PRUint16* aButton);
NS_IMETHOD GetRelatedTarget(nsIDOMEventTarget** aRelatedTarget);
NS_IMETHOD GetCharCode(PRUint32* aCharCode);
NS_IMETHOD GetKeyCode(PRUint32* aKeyCode);
NS_IMETHOD InitMouseEvent(const nsAReadableString& aTypeArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRInt32 aScreenXArg, PRInt32 aScreenYArg, PRInt32 aClientXArg, PRInt32 aClientYArg, PRUint16 aButtonArg, PRUint16 aDetailArg);
NS_IMETHOD InitKeyEvent(const nsAReadableString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, PRBool aCtrlKeyArg, PRBool aAltKeyArg, PRBool aShiftKeyArg, PRBool aMetaKeyArg, PRUint32 aKeyCodeArg, PRUint32 aCharCodeArg, nsIDOMAbstractView* aViewArg);
// nsIDOMNSUIEvent interface
NS_IMETHOD GetLayerX(PRInt32* aLayerX);
NS_IMETHOD GetLayerY(PRInt32* aLayerY);
NS_IMETHOD GetPageX(PRInt32* aClientX);
NS_IMETHOD GetPageY(PRInt32* aClientY);
NS_IMETHOD GetWhich(PRUint32* aKeyCode);
NS_IMETHOD GetRangeParent(nsIDOMNode** aRangeParent);
NS_IMETHOD GetRangeOffset(PRInt32* aRangeOffset);
NS_IMETHOD GetCancelBubble(PRBool* aCancelBubble);
NS_IMETHOD SetCancelBubble(PRBool aCancelBubble);
NS_IMETHOD GetIsChar(PRBool* aIsChar);
NS_IMETHOD GetPreventDefault(PRBool* aReturn);
// nsIPrivateDOMEvent interface
NS_IMETHOD DuplicatePrivateData();
NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget);
NS_IMETHOD SetCurrentTarget(nsIDOMEventTarget* aCurrentTarget);
NS_IMETHOD SetOriginalTarget(nsIDOMEventTarget* aOriginalTarget);
NS_IMETHOD IsDispatchStopped(PRBool* aIsDispatchStopped);
NS_IMETHOD GetInternalNSEvent(nsEvent** aNSEvent);
NS_IMETHOD HasOriginalTarget(PRBool* aResult);
NS_IMETHOD IsHandled(PRBool* aHandled);
NS_IMETHOD SetHandled(PRBool aHandled);
// nsIPrivateTextEvent interface
NS_IMETHOD GetText(nsString& aText);
NS_IMETHOD GetInputRange(nsIPrivateTextRangeList** aInputRange);
NS_IMETHOD GetEventReply(nsTextEventReply** aReply);
// nsIPrivateCompositionEvent interface
NS_IMETHOD GetCompositionReply(nsTextEventReply** aReply);
NS_IMETHOD GetReconversionReply(nsReconversionEventReply** aReply);
protected:
//Internal helper funcs
nsresult GetScrollInfo(nsIScrollableView** aScrollableView, float* aP2T, float* aT2P);
nsresult SetEventType(const nsAReadableString& aEventTypeArg);
nsEvent* mEvent;
PRBool mEventIsInternal;
nsIPresContext* mPresContext;
nsIDOMEventTarget* mTarget;
nsIDOMEventTarget* mCurrentTarget;
nsIDOMEventTarget* mOriginalTarget;
nsString* mText;
nsIPrivateTextRangeList* mTextRange;
const char* GetEventName(PRUint32 aEventType);
};
#endif // nsDOMEvent_h__

View File

@@ -0,0 +1,47 @@
/* -*- 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 "nsDOMEventsIIDs.h"
#include "nsIDOMMouseListener.h"
#include "nsIDOMKeyListener.h"
#include "nsIDOMMouseMotionListener.h"
#include "nsIDOMFocusListener.h"
#include "nsIDOMFormListener.h"
#include "nsIDOMLoadListener.h"
#include "nsIDOMDragListener.h"
#include "nsIDOMPaintListener.h"
#include "nsIDOMTextListener.h"
#include "nsIDOMCompositionListener.h"
#include "nsIDOMMenuListener.h"
#include "nsIDOMScrollListener.h"
NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID);
NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID);
NS_DEFINE_IID(kIDOMMouseMotionListenerIID, NS_IDOMMOUSEMOTIONLISTENER_IID);
NS_DEFINE_IID(kIDOMFocusListenerIID, NS_IDOMFOCUSLISTENER_IID);
NS_DEFINE_IID(kIDOMFormListenerIID, NS_IDOMFORMLISTENER_IID);
NS_DEFINE_IID(kIDOMLoadListenerIID, NS_IDOMLOADLISTENER_IID);
NS_DEFINE_IID(kIDOMDragListenerIID, NS_IDOMDRAGLISTENER_IID);
NS_DEFINE_IID(kIDOMPaintListenerIID, NS_IDOMPAINTLISTENER_IID);
NS_DEFINE_IID(kIDOMTextListenerIID,NS_IDOMTEXTLISTENER_IID);
NS_DEFINE_IID(kIDOMCompositionListenerIID,NS_IDOMCOMPOSITIONLISTENER_IID);
NS_DEFINE_IID(kIDOMMenuListenerIID, NS_IDOMMENULISTENER_IID);
NS_DEFINE_IID(kIDOMScrollListenerIID, NS_IDOMSCROLLLISTENER_IID);

View File

@@ -0,0 +1,40 @@
/* -*- 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 nsDOMEVENTSIIDs_h___
#define nsDOMEVENTSIIDs_h___
#include "nsISupports.h"
extern const nsIID kIDOMMouseListenerIID;
extern const nsIID kIDOMKeyListenerIID;
extern const nsIID kIDOMMouseMotionListenerIID;
extern const nsIID kIDOMFocusListenerIID;
extern const nsIID kIDOMFormListenerIID;
extern const nsIID kIDOMLoadListenerIID;
extern const nsIID kIDOMDragListenerIID;
extern const nsIID kIDOMPaintListenerIID;
extern const nsIID kIDOMTextListenerIID;
extern const nsIID kIDOMCompositionListenerIID;
extern const nsIID kIDOMMenuListenerIID;
extern const nsIID kIDOMScrollListenerIID;
#endif /* nsDOMEVENTSIIDs_h___ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,245 @@
/* -*- 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 nsEventListenerManager_h__
#define nsEventListenerManager_h__
#include "nsIEventListenerManager.h"
#include "jsapi.h"
#include "nsCOMPtr.h"
#include "nsIPrincipal.h"
#include "nsIDOMEventReceiver.h"
class nsIDOMEvent;
class nsIAtom;
typedef struct {
nsIDOMEventListener* mListener;
PRUint8 mFlags;
PRUint8 mSubType;
PRUint8 mHandlerIsString;
PRUint8 mSubTypeCapture;
} nsListenerStruct;
//Flag must live higher than all event flags in nsGUIEvent.h
#define NS_PRIV_EVENT_FLAG_SCRIPT 0x80
/*
* Event listener manager
*/
class nsEventListenerManager : public nsIEventListenerManager,
public nsIDOMEventReceiver
{
public:
nsEventListenerManager();
virtual ~nsEventListenerManager();
NS_DECL_ISUPPORTS
nsVoidArray** GetListenersByIID(const nsIID& aIID);
/**
* Retrieves events listeners of all types.
* @param
*/
virtual nsresult GetEventListeners(nsVoidArray **aListeners, const nsIID& aIID);
/**
* Sets events listeners of all types.
* @param an event listener
*/
virtual nsresult AddEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags);
virtual nsresult RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags);
virtual nsresult AddEventListenerByType(nsIDOMEventListener *aListener, const nsAReadableString& type, PRInt32 aFlags);
virtual nsresult RemoveEventListenerByType(nsIDOMEventListener *aListener, const nsAReadableString& type, PRInt32 aFlags) ;
virtual nsresult AddScriptEventListener(nsIScriptContext*aContext,
nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom *aName,
const nsAReadableString& aFunc,
REFNSIID aIID,
PRBool aDeferCompilation);
virtual nsresult RegisterScriptEventListener(nsIScriptContext *aContext,
nsIScriptObjectOwner *aScriptObjectOwner,
nsIAtom* aName,
const nsIID& aIID);
virtual nsresult CaptureEvent(PRInt32 aEventTypes);
virtual nsresult ReleaseEvent(PRInt32 aEventTypes);
virtual nsresult HandleEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aFlags,
nsEventStatus* aEventStatus);
virtual nsresult CreateEvent(nsIPresContext* aPresContext,
nsEvent* aEvent,
const nsAReadableString& aEventType,
nsIDOMEvent** aDOMEvent);
virtual nsresult RemoveAllListeners(PRBool aScriptOnly);
virtual nsresult SetListenerTarget(nsISupports* aTarget);
static nsresult GetIdentifiersForType(nsIAtom* aType, nsIID& aIID, PRInt32* aSubType);
// 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);
// 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);
protected:
nsresult HandleEventSubType(nsListenerStruct* aListenerStruct,
nsIDOMEvent* aDOMEvent,
nsIDOMEventTarget* aCurrentTarget,
PRUint32 aSubType,
PRUint32 aPhaseFlags);
nsListenerStruct* FindJSEventListener(REFNSIID aIID);
nsresult SetJSEventListener(nsIScriptContext *aContext, nsIScriptObjectOwner *aOwner, nsIAtom* aName, REFNSIID aIID, PRBool aIsString);
nsresult AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags, PRInt32 aSubType);
nsresult RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID, PRInt32 aFlags, PRInt32 aSubType);
void ReleaseListeners(nsVoidArray** aListeners, PRBool aScriptOnly);
nsresult FlipCaptureBit(PRInt32 aEventTypes, PRBool aInitCapture);
nsVoidArray* mEventListeners;
nsVoidArray* mMouseListeners;
nsVoidArray* mMouseMotionListeners;
nsVoidArray* mKeyListeners;
nsVoidArray* mLoadListeners;
nsVoidArray* mFocusListeners;
nsVoidArray* mFormListeners;
nsVoidArray* mDragListeners;
nsVoidArray* mPaintListeners;
nsVoidArray* mTextListeners;
nsVoidArray* mCompositionListeners;
nsVoidArray* mMenuListeners;
nsVoidArray* mScrollListeners;
nsCOMPtr<nsIPrincipal> mPrincipal;
PRBool mDestroyed;
nsISupports* mTarget; //WEAK
};
//Set of defines for distinguishing event handlers within listener groupings
//XXX Current usage allows no more than 7 types per listener grouping
#define NS_EVENT_BITS_NONE 0x00
//nsIDOMMouseListener
#define NS_EVENT_BITS_MOUSE_NONE 0x00
#define NS_EVENT_BITS_MOUSE_MOUSEDOWN 0x01
#define NS_EVENT_BITS_MOUSE_MOUSEUP 0x02
#define NS_EVENT_BITS_MOUSE_CLICK 0x04
#define NS_EVENT_BITS_MOUSE_DBLCLICK 0x08
#define NS_EVENT_BITS_MOUSE_MOUSEOVER 0x10
#define NS_EVENT_BITS_MOUSE_MOUSEOUT 0x20
//nsIDOMMouseMotionListener
#define NS_EVENT_BITS_MOUSEMOTION_NONE 0x00
#define NS_EVENT_BITS_MOUSEMOTION_MOUSEMOVE 0x01
#define NS_EVENT_BITS_MOUSEMOTION_DRAGMOVE 0x02
//nsIDOMKeyListener
#define NS_EVENT_BITS_KEY_NONE 0x00
#define NS_EVENT_BITS_KEY_KEYDOWN 0x01
#define NS_EVENT_BITS_KEY_KEYUP 0x02
#define NS_EVENT_BITS_KEY_KEYPRESS 0x04
//nsIDOMTextListener
#define NS_EVENT_BITS_TEXT_NONE 0x00
#define NS_EVENT_BITS_TEXT_TEXT 0x01
//nsIDOMCompositionListener
#define NS_EVENT_BITS_COMPOSITION_NONE 0x00
#define NS_EVENT_BITS_COMPOSITION_START 0x01
#define NS_EVENT_BITS_COMPOSITION_END 0x02
#define NS_EVENT_BITS_COMPOSITION_QUERY 0x04
//nsIDOMFocusListener
#define NS_EVENT_BITS_FOCUS_NONE 0x00
#define NS_EVENT_BITS_FOCUS_FOCUS 0x01
#define NS_EVENT_BITS_FOCUS_BLUR 0x02
//nsIDOMFormListener
#define NS_EVENT_BITS_FORM_NONE 0x00
#define NS_EVENT_BITS_FORM_SUBMIT 0x01
#define NS_EVENT_BITS_FORM_RESET 0x02
#define NS_EVENT_BITS_FORM_CHANGE 0x04
#define NS_EVENT_BITS_FORM_SELECT 0x08
#define NS_EVENT_BITS_FORM_INPUT 0x10
//nsIDOMLoadListener
#define NS_EVENT_BITS_LOAD_NONE 0x00
#define NS_EVENT_BITS_LOAD_LOAD 0x01
#define NS_EVENT_BITS_LOAD_UNLOAD 0x02
#define NS_EVENT_BITS_LOAD_ABORT 0x04
#define NS_EVENT_BITS_LOAD_ERROR 0x08
//nsIDOMMenuListener
#define NS_EVENT_BITS_MENU_NONE 0x00
#define NS_EVENT_BITS_MENU_CREATE 0x01
#define NS_EVENT_BITS_XUL_CLOSE 0x02
#define NS_EVENT_BITS_MENU_DESTROY 0x04
#define NS_EVENT_BITS_MENU_ACTION 0x08
#define NS_EVENT_BITS_XUL_BROADCAST 0x10
#define NS_EVENT_BITS_XUL_COMMAND_UPDATE 0x20
//nsIScrollListener
#define NS_EVENT_BITS_SCROLLPORT_NONE 0x00
#define NS_EVENT_BITS_SCROLLPORT_OVERFLOW 0x01
#define NS_EVENT_BITS_SCROLLPORT_UNDERFLOW 0x02
#define NS_EVENT_BITS_SCROLLPORT_OVERFLOWCHANGED 0x04
//nsIDOMDragListener
#define NS_EVENT_BITS_DRAG_NONE 0x00
#define NS_EVENT_BITS_DRAG_ENTER 0x01
#define NS_EVENT_BITS_DRAG_OVER 0x02
#define NS_EVENT_BITS_DRAG_EXIT 0x04
#define NS_EVENT_BITS_DRAG_DROP 0x08
#define NS_EVENT_BITS_DRAG_GESTURE 0x10
//nsIDOMPaintListener
#define NS_EVENT_BITS_PAINT_NONE 0x00
#define NS_EVENT_BITS_PAINT_PAINT 0x01
#define NS_EVENT_BITS_PAINT_RESIZE 0x02
#define NS_EVENT_BITS_PAINT_SCROLL 0x04
#endif // nsEventListenerManager_h__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,189 @@
/* -*- 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 nsEventStateManager_h__
#define nsEventStateManager_h__
#include "nsIEventStateManager.h"
#include "nsGUIEvent.h"
#include "nsIContent.h"
#include "nsIPref.h"
#include "nsIObserver.h"
#include "nsWeakReference.h"
#include "nsHashtable.h"
class nsIDocument;
class nsIScrollableView;
class nsIPresShell;
/*
* Event listener manager
*/
class nsEventStateManager : public nsSupportsWeakReference,
public nsIEventStateManager,
public nsIObserver
{
public:
nsEventStateManager();
virtual ~nsEventStateManager();
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_IMETHOD Init();
nsresult Shutdown();
/* The PreHandleEvent method is called before event dispatch to either
* the DOM or frames. Any processing which must not be prevented or
* cancelled should occur here. Any processing which is intended to
* be conditional based on either DOM or frame processing should occur in
* PostHandleEvent. Any centralized event processing which must occur before
* DOM or frame event handling should occur here as well.
*/
NS_IMETHOD PreHandleEvent(nsIPresContext* aPresContext,
nsEvent *aEvent,
nsIFrame* aTargetFrame,
nsEventStatus* aStatus,
nsIView* aView);
/* The PostHandleEvent method should contain all system processing which
* should occur conditionally based on DOM or frame processing. It should
* also contain any centralized event processing which must occur after
* DOM and frame processing.
*/
NS_IMETHOD PostHandleEvent(nsIPresContext* aPresContext,
nsEvent *aEvent,
nsIFrame* aTargetFrame,
nsEventStatus* aStatus,
nsIView* aView);
NS_IMETHOD SetPresContext(nsIPresContext* aPresContext);
NS_IMETHOD ClearFrameRefs(nsIFrame* aFrame);
NS_IMETHOD GetEventTarget(nsIFrame **aFrame);
NS_IMETHOD GetEventTargetContent(nsEvent* aEvent, nsIContent** aContent);
NS_IMETHOD GetEventRelatedContent(nsIContent** aContent);
NS_IMETHOD GetContentState(nsIContent *aContent, PRInt32& aState);
NS_IMETHOD SetContentState(nsIContent *aContent, PRInt32 aState);
NS_IMETHOD GetFocusedContent(nsIContent **aContent);
NS_IMETHOD SetFocusedContent(nsIContent* aContent);
// This is an experiement and may be temporary
NS_IMETHOD ConsumeFocusEvents(PRBool aDoConsume) { mConsumeFocusEvents = aDoConsume; return NS_OK; }
// Access Key Registration
NS_IMETHOD RegisterAccessKey(nsIFrame * aFrame, nsIContent* aContent, PRUint32 aKey);
NS_IMETHOD UnregisterAccessKey(nsIFrame * aFrame, nsIContent* aContent, PRUint32 aKey);
NS_IMETHOD SetCursor(PRInt32 aCursor, nsIWidget* aWidget, PRBool aLockCursor);
//Method for centralized distribution of new DOM events
NS_IMETHOD DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent);
protected:
void UpdateCursor(nsIPresContext* aPresContext, nsEvent* aEvent, nsIFrame* aTargetFrame, nsEventStatus* aStatus);
void GenerateMouseEnterExit(nsIPresContext* aPresContext, nsGUIEvent* aEvent);
void GenerateDragDropEnterExit(nsIPresContext* aPresContext, nsGUIEvent* aEvent);
NS_IMETHOD SetClickCount(nsIPresContext* aPresContext, nsMouseEvent *aEvent, nsEventStatus* aStatus);
NS_IMETHOD CheckForAndDispatchClick(nsIPresContext* aPresContext, nsMouseEvent *aEvent, nsEventStatus* aStatus);
PRBool ChangeFocus(nsIContent* aFocus, nsIFrame* aFocusFrame, PRBool aSetFocus);
void ShiftFocus(PRBool foward);
NS_IMETHOD GetNextTabbableContent(nsIContent* aRootContent, nsIFrame* aFrame, PRBool foward, nsIContent** aResult);
PRInt32 GetNextTabIndex(nsIContent* aParent, PRBool foward);
NS_IMETHOD SendFocusBlur(nsIPresContext* aPresContext, nsIContent *aContent);
PRBool CheckDisabled(nsIContent* aContent);
void EnsureDocument(nsIPresShell* aPresShell);
void EnsureDocument(nsIPresContext* aPresContext);
// These functions are for mousewheel scrolling
nsIScrollableView* GetNearestScrollingView(nsIView* aView);
void ForceViewUpdate(nsIView* aView);
nsresult getPrefService();
nsresult ChangeTextSize(PRInt32 change);
// end mousewheel functions
// routines for the d&d gesture tracking state machine
void BeginTrackingDragGesture ( nsGUIEvent* inDownEvent, nsIFrame* inDownFrame ) ;
void StopTrackingDragGesture ( ) ;
void GenerateDragGesture ( nsIPresContext* aPresContext, nsGUIEvent *aEvent ) ;
PRBool IsTrackingDragGesture ( ) const { return mIsTrackingDragGesture; }
PRBool mSuppressFocusChange; // Used only for Ender text fields to suppress a focus firing on mouse down
//Any frames here must be checked for validity in ClearFrameRefs
nsIFrame* mCurrentTarget;
nsIContent* mCurrentTargetContent;
nsIContent* mCurrentRelatedContent;
nsIFrame* mLastMouseOverFrame;
nsCOMPtr<nsIContent> mLastMouseOverContent;
nsIFrame* mLastDragOverFrame;
// member variables for the d&d gesture state machine
PRBool mIsTrackingDragGesture;
nsPoint mGestureDownPoint;
nsIFrame* mGestureDownFrame;
nsIContent* mLastLeftMouseDownContent;
nsIContent* mLastMiddleMouseDownContent;
nsIContent* mLastRightMouseDownContent;
nsIContent* mActiveContent;
nsIContent* mHoverContent;
nsIContent* mDragOverContent;
nsIContent* mCurrentFocus;
PRInt32 mCurrentTabIndex;
nsIWidget * mLastWindowToHaveFocus; // last native window to get focus via the evs
PRBool mConsumeFocusEvents;
PRInt32 mLockCursor;
//Anti-recursive stack controls
nsIContent* mFirstBlurEvent;
nsIContent* mFirstFocusEvent;
nsCOMPtr<nsIContent> mFirstMouseOverEventContent;
nsCOMPtr<nsIContent> mFirstMouseOutEventContent;
nsIPresContext* mPresContext; // Not refcnted
nsIDocument* mDocument; // [OWNER], but doesn't need to be.
PRUint32 mLClickCount;
PRUint32 mMClickCount;
PRUint32 mRClickCount;
//Hashtable for accesskey support
nsSupportsHashtable *mAccessKeys;
static PRUint32 mInstanceCount;
// For mousewheel preferences handling
nsCOMPtr<nsIPref> mPrefService;
PRBool m_haveShutdown;
//Pref for using hierarchical hover (possibly expensive) or not
PRBool hHover;
};
extern nsresult NS_NewEventStateManager(nsIEventStateManager** aInstancePtrResult);
#endif // nsEventStateManager_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.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 "nsPrivateTextRange.h"
nsPrivateTextRange::nsPrivateTextRange(PRUint16 aRangeStart, PRUint16 aRangeEnd, PRUint16 aRangeType)
: mRangeStart(aRangeStart),
mRangeEnd(aRangeEnd),
mRangeType(aRangeType)
{
NS_INIT_REFCNT();
}
nsPrivateTextRange::~nsPrivateTextRange(void)
{
}
NS_IMPL_ISUPPORTS1(nsPrivateTextRange, nsIPrivateTextRange)
NS_METHOD nsPrivateTextRange::GetRangeStart(PRUint16* aRangeStart)
{
*aRangeStart = mRangeStart;
return NS_OK;
}
NS_METHOD nsPrivateTextRange::SetRangeStart(PRUint16 aRangeStart)
{
mRangeStart = aRangeStart;
return NS_OK;
}
NS_METHOD nsPrivateTextRange::GetRangeEnd(PRUint16* aRangeEnd)
{
*aRangeEnd = mRangeEnd;
return NS_OK;
}
NS_METHOD nsPrivateTextRange::SetRangeEnd(PRUint16 aRangeEnd)
{
mRangeEnd = aRangeEnd;
return NS_OK;
}
NS_METHOD nsPrivateTextRange::GetRangeType(PRUint16* aRangeType)
{
*aRangeType = mRangeType;
return NS_OK;
}
NS_METHOD nsPrivateTextRange::SetRangeType(PRUint16 aRangeType)
{
mRangeType = aRangeType;
return NS_OK;
}
nsPrivateTextRangeList::nsPrivateTextRangeList(PRUint16 aLength,nsIPrivateTextRange** aList)
: mLength(aLength),
mList(aList)
{
if (aList==nsnull)
aLength = 0;
NS_INIT_REFCNT();
}
nsPrivateTextRangeList::~nsPrivateTextRangeList(void)
{
int i;
for(i=0;i<mLength;i++)
mList[i]->Release();
}
NS_IMPL_ISUPPORTS1(nsPrivateTextRangeList, nsIPrivateTextRangeList)
NS_METHOD nsPrivateTextRangeList::GetLength(PRUint16* aLength)
{
*aLength = mLength;
return NS_OK;
}
NS_METHOD nsPrivateTextRangeList::Item(PRUint16 aIndex, nsIPrivateTextRange** aReturn)
{
if (aIndex>mLength) {
*aReturn = nsnull;
return NS_ERROR_FAILURE;
}
mList[aIndex]->AddRef();
*aReturn = mList[aIndex];
return NS_OK;
}

View File

@@ -0,0 +1,71 @@
/* -*- 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 nsPrivateTextRange_h__
#define nsPrivateTextRange_h__
#include "nsIPrivateTextRange.h"
class nsPrivateTextRange : public nsIPrivateTextRange
{
NS_DECL_ISUPPORTS
public:
nsPrivateTextRange(PRUint16 aRangeStart, PRUint16 aRangeEnd, PRUint16 aRangeType);
virtual ~nsPrivateTextRange(void);
NS_IMETHOD GetRangeStart(PRUint16* aRangeStart);
NS_IMETHOD SetRangeStart(PRUint16 aRangeStart);
NS_IMETHOD GetRangeEnd(PRUint16* aRangeEnd);
NS_IMETHOD SetRangeEnd(PRUint16 aRangeEnd);
NS_IMETHOD GetRangeType(PRUint16* aRangeType);
NS_IMETHOD SetRangeType(PRUint16 aRangeType);
protected:
PRUint16 mRangeStart;
PRUint16 mRangeEnd;
PRUint16 mRangeType;
};
class nsPrivateTextRangeList: public nsIPrivateTextRangeList
{
NS_DECL_ISUPPORTS
public:
nsPrivateTextRangeList(PRUint16 aLength,nsIPrivateTextRange** aList);
virtual ~nsPrivateTextRangeList(void);
NS_IMETHOD GetLength(PRUint16* aLength);
NS_IMETHOD Item(PRUint16 aIndex, nsIPrivateTextRange** aReturn);
protected:
PRUint16 mLength;
nsIPrivateTextRange** mList;
};
#endif

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

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