123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
- /* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
- #include "mozilla/dom/HTMLTableColElement.h"
- #include "nsMappedAttributes.h"
- #include "nsAttrValueInlines.h"
- #include "nsRuleData.h"
- #include "mozilla/dom/HTMLTableColElementBinding.h"
- NS_IMPL_NS_NEW_HTML_ELEMENT(TableCol)
- namespace mozilla {
- namespace dom {
- // use the same protection as ancient code did
- // http://lxr.mozilla.org/classic/source/lib/layout/laytable.c#46
- #define MAX_COLSPAN 1000
- HTMLTableColElement::~HTMLTableColElement()
- {
- }
- JSObject*
- HTMLTableColElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
- {
- return HTMLTableColElementBinding::Wrap(aCx, this, aGivenProto);
- }
- NS_IMPL_ELEMENT_CLONE(HTMLTableColElement)
- bool
- HTMLTableColElement::ParseAttribute(int32_t aNamespaceID,
- nsIAtom* aAttribute,
- const nsAString& aValue,
- nsAttrValue& aResult)
- {
- if (aNamespaceID == kNameSpaceID_None) {
- /* ignore these attributes, stored simply as strings ch */
- if (aAttribute == nsGkAtoms::charoff) {
- return aResult.ParseSpecialIntValue(aValue);
- }
- if (aAttribute == nsGkAtoms::span) {
- /* protection from unrealistic large colspan values */
- aResult.ParseIntWithFallback(aValue, 1, MAX_COLSPAN);
- return true;
- }
- if (aAttribute == nsGkAtoms::width) {
- return aResult.ParseSpecialIntValue(aValue);
- }
- if (aAttribute == nsGkAtoms::align) {
- return ParseTableCellHAlignValue(aValue, aResult);
- }
- if (aAttribute == nsGkAtoms::valign) {
- return ParseTableVAlignValue(aValue, aResult);
- }
- }
- return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
- aResult);
- }
- void
- HTMLTableColElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
- nsRuleData* aData)
- {
- if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Table)) {
- nsCSSValue *span = aData->ValueForSpan();
- if (span->GetUnit() == eCSSUnit_Null) {
- // span: int
- const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::span);
- if (value && value->Type() == nsAttrValue::eInteger) {
- int32_t val = value->GetIntegerValue();
- // Note: Do NOT use this code for table cells! The value "0"
- // means something special for colspan and rowspan, but for <col
- // span> and <colgroup span> it's just disallowed.
- if (val > 0) {
- span->SetIntValue(value->GetIntegerValue(), eCSSUnit_Integer);
- }
- }
- }
- }
- if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Position)) {
- nsCSSValue* width = aData->ValueForWidth();
- if (width->GetUnit() == eCSSUnit_Null) {
- // width
- const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
- if (value) {
- switch (value->Type()) {
- case nsAttrValue::ePercent: {
- width->SetPercentValue(value->GetPercentValue());
- break;
- }
- case nsAttrValue::eInteger: {
- width->SetFloatValue((float)value->GetIntegerValue(), eCSSUnit_Pixel);
- break;
- }
- default:
- break;
- }
- }
- }
- }
- if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
- nsCSSValue* textAlign = aData->ValueForTextAlign();
- if (textAlign->GetUnit() == eCSSUnit_Null) {
- // align: enum
- const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
- if (value && value->Type() == nsAttrValue::eEnum)
- textAlign->SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
- }
- }
- if (aData->mSIDs & NS_STYLE_INHERIT_BIT(Display)) {
- nsCSSValue* verticalAlign = aData->ValueForVerticalAlign();
- if (verticalAlign->GetUnit() == eCSSUnit_Null) {
- // valign: enum
- const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::valign);
- if (value && value->Type() == nsAttrValue::eEnum)
- verticalAlign->SetIntValue(value->GetEnumValue(), eCSSUnit_Enumerated);
- }
- }
- nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
- }
- NS_IMETHODIMP_(bool)
- HTMLTableColElement::IsAttributeMapped(const nsIAtom* aAttribute) const
- {
- static const MappedAttributeEntry attributes[] = {
- { &nsGkAtoms::width },
- { &nsGkAtoms::align },
- { &nsGkAtoms::valign },
- { &nsGkAtoms::span },
- { nullptr }
- };
- static const MappedAttributeEntry* const map[] = {
- attributes,
- sCommonAttributeMap,
- };
- return FindAttributeDependence(aAttribute, map);
- }
- nsMapRuleToAttributesFunc
- HTMLTableColElement::GetAttributeMappingFunction() const
- {
- return &MapAttributesIntoRule;
- }
- } // namespace dom
- } // namespace mozilla
|