| |
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| |
2 * |
| |
3 * This Source Code Form is subject to the terms of the Mozilla Public |
| |
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| |
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| |
6 |
| |
7 #include "nsError.h" |
| |
8 #include "nsIAtom.h" |
| |
9 #include "nsParserService.h" |
| |
10 #include "nsHTMLEntities.h" |
| |
11 #include "nsElementTable.h" |
| |
12 #include "nsICategoryManager.h" |
| |
13 #include "nsCategoryManagerUtils.h" |
| |
14 |
| |
15 nsParserService::nsParserService() |
| |
16 { |
| |
17 } |
| |
18 |
| |
19 nsParserService::~nsParserService() |
| |
20 { |
| |
21 } |
| |
22 |
| |
23 NS_IMPL_ISUPPORTS(nsParserService, nsIParserService) |
| |
24 |
| |
25 int32_t |
| |
26 nsParserService::HTMLAtomTagToId(nsIAtom* aAtom) const |
| |
27 { |
| |
28 return nsHTMLTags::LookupTag(nsDependentAtomString(aAtom)); |
| |
29 } |
| |
30 |
| |
31 int32_t |
| |
32 nsParserService::HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom) const |
| |
33 { |
| |
34 return nsHTMLTags::CaseSensitiveLookupTag(aAtom); |
| |
35 } |
| |
36 |
| |
37 int32_t |
| |
38 nsParserService::HTMLStringTagToId(const nsAString& aTag) const |
| |
39 { |
| |
40 return nsHTMLTags::LookupTag(aTag); |
| |
41 } |
| |
42 |
| |
43 const char16_t* |
| |
44 nsParserService::HTMLIdToStringTag(int32_t aId) const |
| |
45 { |
| |
46 return nsHTMLTags::GetStringValue((nsHTMLTag)aId); |
| |
47 } |
| |
48 |
| |
49 nsIAtom* |
| |
50 nsParserService::HTMLIdToAtomTag(int32_t aId) const |
| |
51 { |
| |
52 return nsHTMLTags::GetAtom((nsHTMLTag)aId); |
| |
53 } |
| |
54 |
| |
55 NS_IMETHODIMP |
| |
56 nsParserService::HTMLConvertEntityToUnicode(const nsAString& aEntity, |
| |
57 int32_t* aUnicode) const |
| |
58 { |
| |
59 *aUnicode = nsHTMLEntities::EntityToUnicode(aEntity); |
| |
60 |
| |
61 return NS_OK; |
| |
62 } |
| |
63 |
| |
64 NS_IMETHODIMP |
| |
65 nsParserService::HTMLConvertUnicodeToEntity(int32_t aUnicode, |
| |
66 nsCString& aEntity) const |
| |
67 { |
| |
68 const char* str = nsHTMLEntities::UnicodeToEntity(aUnicode); |
| |
69 if (str) { |
| |
70 aEntity.Assign(str); |
| |
71 } |
| |
72 |
| |
73 return NS_OK; |
| |
74 } |
| |
75 |
| |
76 NS_IMETHODIMP |
| |
77 nsParserService::IsContainer(int32_t aId, bool& aIsContainer) const |
| |
78 { |
| |
79 aIsContainer = nsHTMLElement::IsContainer((eHTMLTags)aId); |
| |
80 |
| |
81 return NS_OK; |
| |
82 } |
| |
83 |
| |
84 NS_IMETHODIMP |
| |
85 nsParserService::IsBlock(int32_t aId, bool& aIsBlock) const |
| |
86 { |
| |
87 if((aId>eHTMLTag_unknown) && (aId<eHTMLTag_userdefined)) { |
| |
88 aIsBlock=((gHTMLElements[aId].IsMemberOf(kBlock)) || |
| |
89 (gHTMLElements[aId].IsMemberOf(kBlockEntity)) || |
| |
90 (gHTMLElements[aId].IsMemberOf(kHeading)) || |
| |
91 (gHTMLElements[aId].IsMemberOf(kPreformatted))|| |
| |
92 (gHTMLElements[aId].IsMemberOf(kList))); |
| |
93 } |
| |
94 else { |
| |
95 aIsBlock = false; |
| |
96 } |
| |
97 |
| |
98 return NS_OK; |
| |
99 } |