Remove JS hacks in marquee and just rely on the attribute mapping code. Bug

313642, patch by Martijn Wargers <martijn.martijn@gmail.com>, r=doron,
sr=bzbarsky
This commit is contained in:
bzbarsky%mit.edu 2005-10-26 20:23:56 +00:00
parent a1754701a6
commit 0e97132ac9
4 changed files with 59 additions and 61 deletions

View File

@ -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)

View File

@ -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.

View File

@ -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));

View File

@ -142,34 +142,13 @@
<property name="height"
onget="return this.getAttribute('height');"
onset="this.setAttribute('height', val);"
/>
<property name="width">
<getter>
<![CDATA[
var rv = "1px";
if (this.hasAttribute("width"))
rv = this.getAttribute("width");
else if (this.offsetWidth) {
// if the element has an offsetWidth, don't set a width
rv = "";
} else if (this.offsetParent) {
var myElem = this.offsetParent;
// lets walk up the offsetParent tree looking for an
// element with a width.
while (myElem.offsetParent && (myElem.offsetWidth <= 0))
myElem = myElem.offsetParent;
if (myElem)
rv = myElem.offsetWidth + "px";
}
return rv;
]]>
</getter>
</property>
<property name="width"
onget="return this.getAttribute('width');"
onset="this.setAttribute('width', val);"
/>
<!-- For sniffing purposes -->
<field name="nsMarqueeVersion">"0.9.7"</field>
@ -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 @@
<method name="init">
<body>
<![CDATA[
var height;
if (this.hasAttribute('height')) {
height = this.getAttribute('height');
this.outerDiv.style.height = height + "px";
}
this.outerDiv.style.width = this.width;
// Some sites access the element via the evil IE way of elementID.foo()
if (this.hasAttribute('id'))
window[this.getAttribute('id')] = this;
// Website can define a background color via the bgcolor attribute
if (this.hasAttribute("bgcolor"))
this.outerDiv.style.backgroundColor = this.getAttribute("bgcolor");
// store the original height before we add padding
this.originalHeight = this.innerDiv.offsetHeight;