PageRenderTime 37ms CodeModel.GetById 19ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/parser/htmlparser/src/nsParserService.cpp

http://github.com/zpao/v8monkey
C++ | 160 lines | 100 code | 22 blank | 38 comment | 10 complexity | 6e581850edd66aa7752246f6df5b51ef MD5 | raw file
  1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2 *
  3 * ***** BEGIN LICENSE BLOCK *****
  4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5 *
  6 * The contents of this file are subject to the Mozilla Public License Version
  7 * 1.1 (the "License"); you may not use this file except in compliance with
  8 * the License. You may obtain a copy of the License at
  9 * http://www.mozilla.org/MPL/
 10 *
 11 * Software distributed under the License is distributed on an "AS IS" basis,
 12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 13 * for the specific language governing rights and limitations under the
 14 * License.
 15 *
 16 * The Original Code is Mozilla Communicator client code.
 17 *
 18 * The Initial Developer of the Original Code is
 19 * Netscape Communications Corporation.
 20 * Portions created by the Initial Developer are Copyright (C) 1998
 21 * the Initial Developer. All Rights Reserved.
 22 *
 23 * Contributor(s):
 24 *
 25 * Alternatively, the contents of this file may be used under the terms of
 26 * either of the GNU General Public License Version 2 or later (the "GPL"),
 27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 28 * in which case the provisions of the GPL or the LGPL are applicable instead
 29 * of those above. If you wish to allow use of your version of this file only
 30 * under the terms of either the GPL or the LGPL, and not to allow others to
 31 * use your version of this file under the terms of the MPL, indicate your
 32 * decision by deleting the provisions above and replace them with the notice
 33 * and other provisions required by the GPL or the LGPL. If you do not delete
 34 * the provisions above, a recipient may use your version of this file under
 35 * the terms of any one of the MPL, the GPL or the LGPL.
 36 *
 37 * ***** END LICENSE BLOCK ***** */
 38
 39#include "nsDOMError.h"
 40#include "nsIAtom.h"
 41#include "nsParserService.h"
 42#include "nsHTMLEntities.h"
 43#include "nsElementTable.h"
 44#include "nsICategoryManager.h"
 45#include "nsCategoryManagerUtils.h"
 46
 47extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
 48                                 int ns_aware, const char** colon);
 49
 50nsParserService::nsParserService()
 51{
 52}
 53
 54nsParserService::~nsParserService()
 55{
 56}
 57
 58NS_IMPL_ISUPPORTS1(nsParserService, nsIParserService)
 59
 60PRInt32
 61nsParserService::HTMLAtomTagToId(nsIAtom* aAtom) const
 62{
 63  return nsHTMLTags::LookupTag(nsDependentAtomString(aAtom));
 64}
 65
 66PRInt32
 67nsParserService::HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom) const
 68{
 69  return nsHTMLTags::CaseSensitiveLookupTag(aAtom);
 70}
 71
 72PRInt32
 73nsParserService::HTMLStringTagToId(const nsAString& aTag) const
 74{
 75  return nsHTMLTags::LookupTag(aTag);
 76}
 77
 78const PRUnichar*
 79nsParserService::HTMLIdToStringTag(PRInt32 aId) const
 80{
 81  return nsHTMLTags::GetStringValue((nsHTMLTag)aId);
 82}
 83  
 84nsIAtom*
 85nsParserService::HTMLIdToAtomTag(PRInt32 aId) const
 86{
 87  return nsHTMLTags::GetAtom((nsHTMLTag)aId);
 88}
 89
 90NS_IMETHODIMP
 91nsParserService::HTMLConvertEntityToUnicode(const nsAString& aEntity,
 92                                            PRInt32* aUnicode) const
 93{
 94  *aUnicode = nsHTMLEntities::EntityToUnicode(aEntity);
 95
 96  return NS_OK;
 97}
 98
 99NS_IMETHODIMP
100nsParserService::HTMLConvertUnicodeToEntity(PRInt32 aUnicode,
101                                            nsCString& aEntity) const
102{
103  const char* str = nsHTMLEntities::UnicodeToEntity(aUnicode);
104  if (str) {
105    aEntity.Assign(str);
106  }
107
108  return NS_OK;
109}
110
111NS_IMETHODIMP
112nsParserService::IsContainer(PRInt32 aId, bool& aIsContainer) const
113{
114  aIsContainer = nsHTMLElement::IsContainer((eHTMLTags)aId);
115
116  return NS_OK;
117}
118
119NS_IMETHODIMP
120nsParserService::IsBlock(PRInt32 aId, bool& aIsBlock) const
121{
122  if((aId>eHTMLTag_unknown) && (aId<eHTMLTag_userdefined)) {
123    aIsBlock=((gHTMLElements[aId].IsMemberOf(kBlock))       ||
124              (gHTMLElements[aId].IsMemberOf(kBlockEntity)) ||
125              (gHTMLElements[aId].IsMemberOf(kHeading))     ||
126              (gHTMLElements[aId].IsMemberOf(kPreformatted))||
127              (gHTMLElements[aId].IsMemberOf(kList)));
128  }
129  else {
130    aIsBlock = false;
131  }
132
133  return NS_OK;
134}
135
136nsresult
137nsParserService::CheckQName(const nsAString& aQName,
138                            bool aNamespaceAware,
139                            const PRUnichar** aColon)
140{
141  const char* colon;
142  const PRUnichar *begin, *end;
143  begin = aQName.BeginReading();
144  end = aQName.EndReading();
145  int result = MOZ_XMLCheckQName(reinterpret_cast<const char*>(begin),
146                                 reinterpret_cast<const char*>(end),
147                                 aNamespaceAware, &colon);
148  *aColon = reinterpret_cast<const PRUnichar*>(colon);
149
150  if (result == 0) {
151    return NS_OK;
152  }
153
154  // MOZ_EXPAT_EMPTY_QNAME || MOZ_EXPAT_INVALID_CHARACTER
155  if (result == (1 << 0) || result == (1 << 1)) {
156    return NS_ERROR_DOM_INVALID_CHARACTER_ERR;
157  }
158
159  return NS_ERROR_DOM_NAMESPACE_ERR;
160}