From 0e97132ac93d3ca86f7decf7ae46c75998e84341 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Wed, 26 Oct 2005 20:23:56 +0000 Subject: [PATCH] Remove JS hacks in marquee and just rely on the attribute mapping code. Bug 313642, patch by Martijn Wargers , r=doron, sr=bzbarsky --- .../html/content/src/nsGenericHTMLElement.cpp | 25 ++++++- .../html/content/src/nsGenericHTMLElement.h | 21 ++++++ content/html/content/src/nsHTMLDivElement.cpp | 9 ++- layout/style/xbl-marquee/xbl-marquee.xml | 65 +++---------------- 4 files changed, 59 insertions(+), 61 deletions(-) diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index d8fcbfcf07ab..3fe06db198b8 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -2670,6 +2670,12 @@ nsGenericHTMLElement::sBackgroundAttributeMap[] = { { nsnull } }; +/* static */ const nsGenericElement::MappedAttributeEntry +nsGenericHTMLElement::sBackgroundColorAttributeMap[] = { + { &nsHTMLAtoms::bgcolor }, + { nsnull } +}; + /* static */ const nsGenericElement::MappedAttributeEntry nsGenericHTMLElement::sScrollingAttributeMap[] = { { &nsHTMLAtoms::scrolling }, @@ -2839,7 +2845,7 @@ nsGenericHTMLElement::MapImageBorderAttributeInto(const nsMappedAttributes* aAtt } void -nsGenericHTMLElement::MapBackgroundAttributesInto(const nsMappedAttributes* aAttributes, +nsGenericHTMLElement::MapBackgroundInto(const nsMappedAttributes* aAttributes, nsRuleData* aData) { if (aData->mSID != eStyleStruct_Background) @@ -2882,8 +2888,15 @@ nsGenericHTMLElement::MapBackgroundAttributesInto(const nsMappedAttributes* aAtt } } } +} + +void +nsGenericHTMLElement::MapBGColorInto(const nsMappedAttributes* aAttributes, + nsRuleData* aData) +{ + if (aData->mSID != eStyleStruct_Background) + return; - // bgcolor if (aData->mColorData->mBackColor.GetUnit() == eCSSUnit_Null) { const nsAttrValue* value = aAttributes->GetAttr(nsHTMLAtoms::bgcolor); nscolor color; @@ -2893,6 +2906,14 @@ nsGenericHTMLElement::MapBackgroundAttributesInto(const nsMappedAttributes* aAtt } } +void +nsGenericHTMLElement::MapBackgroundAttributesInto(const nsMappedAttributes* aAttributes, + nsRuleData* aData) +{ + MapBackgroundInto(aAttributes, aData); + MapBGColorInto(aAttributes, aData); +} + void nsGenericHTMLElement::MapScrollingAttributeInto(const nsMappedAttributes* aAttributes, nsRuleData* aData) diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index c709d406e1af..650416a7e317 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -443,6 +443,7 @@ public: static const MappedAttributeEntry sImageAlignAttributeMap[]; static const MappedAttributeEntry sDivAlignAttributeMap[]; static const MappedAttributeEntry sBackgroundAttributeMap[]; + static const MappedAttributeEntry sBackgroundColorAttributeMap[]; static const MappedAttributeEntry sScrollingAttributeMap[]; /** @@ -493,6 +494,26 @@ public: */ static void MapImageSizeAttributesInto(const nsMappedAttributes* aAttributes, nsRuleData* aData); + /** + * Helper to map the background attribute + * into a style struct. + * + * @param aAttributes the list of attributes to map + * @param aData the returned rule data [INOUT] + * @see GetAttributeMappingFunction + */ + static void MapBackgroundInto(const nsMappedAttributes* aAttributes, + nsRuleData* aData); + /** + * Helper to map the bgcolor attribute + * into a style struct. + * + * @param aAttributes the list of attributes to map + * @param aData the returned rule data [INOUT] + * @see GetAttributeMappingFunction + */ + static void MapBGColorInto(const nsMappedAttributes* aAttributes, + nsRuleData* aData); /** * Helper to map the background attributes (currently background and bgcolor) * into a style struct. diff --git a/content/html/content/src/nsHTMLDivElement.cpp b/content/html/content/src/nsHTMLDivElement.cpp index 69334ca3c0ed..9f6f95d7753c 100644 --- a/content/html/content/src/nsHTMLDivElement.cpp +++ b/content/html/content/src/nsHTMLDivElement.cpp @@ -113,8 +113,11 @@ nsHTMLDivElement::ParseAttribute(nsIAtom* aAttribute, (aAttribute == nsHTMLAtoms::height)) { return aResult.ParseSpecialIntValue(aValue, PR_TRUE, PR_FALSE); } - else if ((aAttribute == nsHTMLAtoms::hspace) || - (aAttribute == nsHTMLAtoms::vspace)) { + if (aAttribute == nsHTMLAtoms::bgcolor) { + return aResult.ParseColor(aValue, GetOwnerDoc()); + } + if ((aAttribute == nsHTMLAtoms::hspace) || + (aAttribute == nsHTMLAtoms::vspace)) { return aResult.ParseIntWithBounds(aValue, 0); } } @@ -139,6 +142,7 @@ MapMarqueeAttributesIntoRule(const nsMappedAttributes* aAttributes, nsRuleData* nsGenericHTMLElement::MapImageMarginAttributeInto(aAttributes, aData); nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData); nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData); + nsGenericHTMLElement::MapBGColorInto(aAttributes, aData); } NS_IMETHODIMP_(PRBool) @@ -154,6 +158,7 @@ nsHTMLDivElement::IsAttributeMapped(const nsIAtom* aAttribute) const if (mNodeInfo->Equals(nsHTMLAtoms::marquee)) { static const MappedAttributeEntry* const map[] = { sImageMarginSizeAttributeMap, + sBackgroundColorAttributeMap, sCommonAttributeMap }; return FindAttributeDependence(aAttribute, map, NS_ARRAY_LENGTH(map)); diff --git a/layout/style/xbl-marquee/xbl-marquee.xml b/layout/style/xbl-marquee/xbl-marquee.xml index 7f73a97ef326..6eef4ed5ec01 100644 --- a/layout/style/xbl-marquee/xbl-marquee.xml +++ b/layout/style/xbl-marquee/xbl-marquee.xml @@ -142,34 +142,13 @@ - - - - - + "0.9.7" @@ -206,24 +185,9 @@ if ((this.directionField == "up") || (this.directionField == "down")) { - // "", 0 and empty height should default to 200px - var height = - (this.getAttribute("height") != "0" && - this.getAttribute("height")) || - (document.defaultView.getComputedStyle(this,"").height != "0px" && - document.defaultView.getComputedStyle(this,"").height) || - "200px"; - - // support % heights - if (/%/.test(height)) { - height = parseInt('0' + height, 10); - height = (height/100) * this.outerDiv.offsetHeight; - } - + var height = document.defaultView.getComputedStyle(this, "").height; this.outerDiv.style.height = height; - this.innerDiv.style.padding = height + " 0"; - this.innerDiv.style.whiteSpace = ""; } switch (this.directionField) @@ -231,13 +195,13 @@ case "up": this.dirsign = 1; this.startAt = (this.behaviorField == 'alternate') ? this.originalHeight : 0; - this.stopAt = this.innerDiv.offsetHeight - parseInt(this.outerDiv.style.height) + this.stopAt = this.originalHeight + parseInt(height) - ((this.behaviorField == 'alternate') ? this.originalHeight : 0); break; case "down": this.dirsign = -1; - this.startAt = this.innerDiv.offsetHeight - parseInt(this.outerDiv.style.height) + this.startAt = this.originalHeight + parseInt(height) - ((this.behaviorField == 'alternate') ? this.originalHeight : 0); this.stopAt = (this.behaviorField == 'alternate') ? this.originalHeight : 0; break; @@ -300,23 +264,10 @@