Back to index

lightning-sunbird  0.9+nobinonly
nsParserService.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #ifndef NS_PARSERSERVICE_H__
00039 #define NS_PARSERSERVICE_H__
00040 
00041 #include "nsIParserService.h"
00042 #include "nsDTDUtils.h"
00043 #include "nsVoidArray.h"
00044 
00045 extern "C" int MOZ_XMLIsLetter(const char* ptr);
00046 extern "C" int MOZ_XMLIsNCNameChar(const char* ptr);
00047 extern "C" PRBool MOZ_XMLTranslateEntity(const char* ptr, const char* end,
00048                                          const char** next, PRUnichar* result);
00049 
00050 class nsParserService : public nsIParserService_MOZILLA_1_8_BRANCH {
00051 public:
00052   nsParserService();
00053   virtual ~nsParserService();
00054 
00055   NS_DECL_ISUPPORTS
00056 
00057   PRInt32 HTMLAtomTagToId(nsIAtom* aAtom) const;
00058 
00059   PRInt32 HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom) const;
00060 
00061   PRInt32 HTMLStringTagToId(const nsAString& aTag) const;
00062 
00063   const PRUnichar *HTMLIdToStringTag(PRInt32 aId) const;
00064   
00065   nsIAtom *HTMLIdToAtomTag(PRInt32 aId) const;
00066 
00067   NS_IMETHOD HTMLConvertEntityToUnicode(const nsAString& aEntity, 
00068                                         PRInt32* aUnicode) const;
00069   NS_IMETHOD HTMLConvertUnicodeToEntity(PRInt32 aUnicode,
00070                                         nsCString& aEntity) const;
00071   NS_IMETHOD IsContainer(PRInt32 aId, PRBool& aIsContainer) const;
00072   NS_IMETHOD IsBlock(PRInt32 aId, PRBool& aIsBlock) const;
00073 
00074    // Observer mechanism
00075   NS_IMETHOD RegisterObserver(nsIElementObserver* aObserver,
00076                               const nsAString& aTopic,
00077                               const eHTMLTags* aTags = nsnull);
00078 
00079   NS_IMETHOD UnregisterObserver(nsIElementObserver* aObserver,
00080                                 const nsAString& aTopic);
00081   NS_IMETHOD GetTopicObservers(const nsAString& aTopic,
00082                                nsIObserverEntry** aEntry);
00083 
00084   nsresult CheckQName(const nsASingleFragmentString& aQName,
00085                       PRBool aNamespaceAware, const PRUnichar** aColon);
00086 
00087   PRBool IsXMLLetter(PRUnichar aChar)
00088   {
00089     return MOZ_XMLIsLetter(NS_REINTERPRET_CAST(const char*, &aChar));
00090   }
00091   PRBool IsXMLNCNameChar(PRUnichar aChar)
00092   {
00093     return MOZ_XMLIsNCNameChar(NS_REINTERPRET_CAST(const char*, &aChar));
00094   }
00095   PRUint32 DecodeEntity(const PRUnichar* aStart, const PRUnichar* aEnd,
00096                         const PRUnichar** aNext, PRUnichar* aResult)
00097   {
00098     *aNext = nsnull;
00099     return MOZ_XMLTranslateEntity(NS_REINTERPRET_CAST(const char*, aStart),
00100                                   NS_REINTERPRET_CAST(const char*, aEnd),
00101                                   NS_REINTERPRET_CAST(const char**, aNext),
00102                                   aResult);
00103   }
00104 
00105 protected:
00106   nsObserverEntry* GetEntry(const nsAString& aTopic);
00107   nsresult CreateEntry(const nsAString& aTopic,
00108                        nsObserverEntry** aEntry);
00109 
00110   nsDeque  mEntries;  //each topic holds a list of observers per tag.
00111   PRBool   mHaveNotifiedCategoryObservers;
00112 };
00113 
00114 #endif