HTMLLIElement.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "mozilla/dom/HTMLLIElement.h"
  6. #include "mozilla/dom/HTMLLIElementBinding.h"
  7. #include "nsAttrValueInlines.h"
  8. #include "nsGkAtoms.h"
  9. #include "nsStyleConsts.h"
  10. #include "nsMappedAttributes.h"
  11. #include "nsRuleData.h"
  12. NS_IMPL_NS_NEW_HTML_ELEMENT(LI)
  13. namespace mozilla {
  14. namespace dom {
  15. HTMLLIElement::~HTMLLIElement()
  16. {
  17. }
  18. NS_IMPL_ISUPPORTS_INHERITED(HTMLLIElement, nsGenericHTMLElement,
  19. nsIDOMHTMLLIElement)
  20. NS_IMPL_ELEMENT_CLONE(HTMLLIElement)
  21. NS_IMPL_STRING_ATTR(HTMLLIElement, Type, type)
  22. NS_IMPL_INT_ATTR(HTMLLIElement, Value, value)
  23. // values that are handled case-insensitively
  24. static const nsAttrValue::EnumTable kUnorderedListItemTypeTable[] = {
  25. { "disc", NS_STYLE_LIST_STYLE_DISC },
  26. { "circle", NS_STYLE_LIST_STYLE_CIRCLE },
  27. { "round", NS_STYLE_LIST_STYLE_CIRCLE },
  28. { "square", NS_STYLE_LIST_STYLE_SQUARE },
  29. { nullptr, 0 }
  30. };
  31. // values that are handled case-sensitively
  32. static const nsAttrValue::EnumTable kOrderedListItemTypeTable[] = {
  33. { "A", NS_STYLE_LIST_STYLE_UPPER_ALPHA },
  34. { "a", NS_STYLE_LIST_STYLE_LOWER_ALPHA },
  35. { "I", NS_STYLE_LIST_STYLE_UPPER_ROMAN },
  36. { "i", NS_STYLE_LIST_STYLE_LOWER_ROMAN },
  37. { "1", NS_STYLE_LIST_STYLE_DECIMAL },
  38. { nullptr, 0 }
  39. };
  40. bool
  41. HTMLLIElement::ParseAttribute(int32_t aNamespaceID,
  42. nsIAtom* aAttribute,
  43. const nsAString& aValue,
  44. nsAttrValue& aResult)
  45. {
  46. if (aNamespaceID == kNameSpaceID_None) {
  47. if (aAttribute == nsGkAtoms::type) {
  48. return aResult.ParseEnumValue(aValue, kOrderedListItemTypeTable,
  49. true) ||
  50. aResult.ParseEnumValue(aValue, kUnorderedListItemTypeTable, false);
  51. }
  52. if (aAttribute == nsGkAtoms::value) {
  53. return aResult.ParseIntValue(aValue);
  54. }
  55. }
  56. return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
  57. aResult);
  58. }
  59. void
  60. HTMLLIElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
  61. nsRuleData* aData)
  62. {
  63. if (aData->mSIDs & NS_STYLE_INHERIT_BIT(List)) {
  64. nsCSSValue* listStyleType = aData->ValueForListStyleType();
  65. if (listStyleType->GetUnit() == eCSSUnit_Null) {
  66. // type: enum
  67. const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::type);
  68. if (value && value->Type() == nsAttrValue::eEnum)
  69. listStyleType->SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
  70. }
  71. }
  72. nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
  73. }
  74. NS_IMETHODIMP_(bool)
  75. HTMLLIElement::IsAttributeMapped(const nsIAtom* aAttribute) const
  76. {
  77. static const MappedAttributeEntry attributes[] = {
  78. { &nsGkAtoms::type },
  79. { nullptr },
  80. };
  81. static const MappedAttributeEntry* const map[] = {
  82. attributes,
  83. sCommonAttributeMap,
  84. };
  85. return FindAttributeDependence(aAttribute, map);
  86. }
  87. nsMapRuleToAttributesFunc
  88. HTMLLIElement::GetAttributeMappingFunction() const
  89. {
  90. return &MapAttributesIntoRule;
  91. }
  92. JSObject*
  93. HTMLLIElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
  94. {
  95. return HTMLLIElementBinding::Wrap(aCx, this, aGivenProto);
  96. }
  97. } // namespace dom
  98. } // namespace mozilla