parser/htmlparser/src/nsParserService.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/htmlparser/src/nsParserService.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "nsError.h"
    1.11 +#include "nsIAtom.h"
    1.12 +#include "nsParserService.h"
    1.13 +#include "nsHTMLEntities.h"
    1.14 +#include "nsElementTable.h"
    1.15 +#include "nsICategoryManager.h"
    1.16 +#include "nsCategoryManagerUtils.h"
    1.17 +
    1.18 +nsParserService::nsParserService()
    1.19 +{
    1.20 +}
    1.21 +
    1.22 +nsParserService::~nsParserService()
    1.23 +{
    1.24 +}
    1.25 +
    1.26 +NS_IMPL_ISUPPORTS(nsParserService, nsIParserService)
    1.27 +
    1.28 +int32_t
    1.29 +nsParserService::HTMLAtomTagToId(nsIAtom* aAtom) const
    1.30 +{
    1.31 +  return nsHTMLTags::LookupTag(nsDependentAtomString(aAtom));
    1.32 +}
    1.33 +
    1.34 +int32_t
    1.35 +nsParserService::HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom) const
    1.36 +{
    1.37 +  return nsHTMLTags::CaseSensitiveLookupTag(aAtom);
    1.38 +}
    1.39 +
    1.40 +int32_t
    1.41 +nsParserService::HTMLStringTagToId(const nsAString& aTag) const
    1.42 +{
    1.43 +  return nsHTMLTags::LookupTag(aTag);
    1.44 +}
    1.45 +
    1.46 +const char16_t*
    1.47 +nsParserService::HTMLIdToStringTag(int32_t aId) const
    1.48 +{
    1.49 +  return nsHTMLTags::GetStringValue((nsHTMLTag)aId);
    1.50 +}
    1.51 +  
    1.52 +nsIAtom*
    1.53 +nsParserService::HTMLIdToAtomTag(int32_t aId) const
    1.54 +{
    1.55 +  return nsHTMLTags::GetAtom((nsHTMLTag)aId);
    1.56 +}
    1.57 +
    1.58 +NS_IMETHODIMP
    1.59 +nsParserService::HTMLConvertEntityToUnicode(const nsAString& aEntity,
    1.60 +                                            int32_t* aUnicode) const
    1.61 +{
    1.62 +  *aUnicode = nsHTMLEntities::EntityToUnicode(aEntity);
    1.63 +
    1.64 +  return NS_OK;
    1.65 +}
    1.66 +
    1.67 +NS_IMETHODIMP
    1.68 +nsParserService::HTMLConvertUnicodeToEntity(int32_t aUnicode,
    1.69 +                                            nsCString& aEntity) const
    1.70 +{
    1.71 +  const char* str = nsHTMLEntities::UnicodeToEntity(aUnicode);
    1.72 +  if (str) {
    1.73 +    aEntity.Assign(str);
    1.74 +  }
    1.75 +
    1.76 +  return NS_OK;
    1.77 +}
    1.78 +
    1.79 +NS_IMETHODIMP
    1.80 +nsParserService::IsContainer(int32_t aId, bool& aIsContainer) const
    1.81 +{
    1.82 +  aIsContainer = nsHTMLElement::IsContainer((eHTMLTags)aId);
    1.83 +
    1.84 +  return NS_OK;
    1.85 +}
    1.86 +
    1.87 +NS_IMETHODIMP
    1.88 +nsParserService::IsBlock(int32_t aId, bool& aIsBlock) const
    1.89 +{
    1.90 +  if((aId>eHTMLTag_unknown) && (aId<eHTMLTag_userdefined)) {
    1.91 +    aIsBlock=((gHTMLElements[aId].IsMemberOf(kBlock))       ||
    1.92 +              (gHTMLElements[aId].IsMemberOf(kBlockEntity)) ||
    1.93 +              (gHTMLElements[aId].IsMemberOf(kHeading))     ||
    1.94 +              (gHTMLElements[aId].IsMemberOf(kPreformatted))||
    1.95 +              (gHTMLElements[aId].IsMemberOf(kList)));
    1.96 +  }
    1.97 +  else {
    1.98 +    aIsBlock = false;
    1.99 +  }
   1.100 +
   1.101 +  return NS_OK;
   1.102 +}

mercurial