Move WalkDescendantsClearAncestorDirAuto from BeforeSetAttr to OnSetDirAttr to simplify the test for elements that had dir=auto but no longer do, especially <bdi>. Bug 845093, r=ehsan

This commit is contained in:
Simon Montagu 2013-03-07 22:53:08 +02:00
parent 9227c29ea2
commit 65bca04d24
5 changed files with 23 additions and 26 deletions

View File

@ -117,6 +117,7 @@ void SetDirectionalityFromValue(mozilla::dom::Element* aElement,
void OnSetDirAttr(mozilla::dom::Element* aElement,
const nsAttrValue* aNewValue,
bool hadValidDir,
bool hadDirAuto,
bool aNotify);
/**

View File

@ -862,7 +862,7 @@ SetDirectionalityFromValue(Element* aElement, const nsAString& value,
void
OnSetDirAttr(Element* aElement, const nsAttrValue* aNewValue,
bool hadValidDir, bool aNotify)
bool hadValidDir, bool hadDirAuto, bool aNotify)
{
if (aElement->IsHTML(nsGkAtoms::input)) {
return;
@ -883,6 +883,20 @@ OnSetDirAttr(Element* aElement, const nsAttrValue* aNewValue,
// determined by a text node descendant
WalkAncestorsResetAutoDirection(aElement, aNotify);
}
} else if (hadDirAuto && !aElement->HasDirAuto()) {
// The element isn't a descendant of an element with dir = auto, and is
// having its dir attribute set to something other than auto.
// Walk the descendant tree and clear the AncestorHasDirAuto flag.
//
// N.B: For elements other than <bdi> it would be enough to test that the
// current value of dir was "auto" in BeforeSetAttr to know that we
// were unsetting dir="auto". For <bdi> things are more complicated,
// since it behaves like dir="auto" whenever the dir attribute is
// empty or invalid, so we would have to check whether the old value
// was not either "ltr" or "rtl", and the new value was either "ltr"
// or "rtl". Element::HasDirAuto() encapsulates all that, so doing it
// here is simpler.
WalkDescendantsClearAncestorDirAuto(aElement);
}
if (aElement->HasDirAuto()) {

View File

@ -1854,10 +1854,12 @@ Element::SetAttrAndNotify(int32_t aNamespaceID,
}
bool hadValidDir = false;
bool hadDirAuto = false;
if (aNamespaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::dir) {
hadValidDir = HasValidDir() || IsHTML(nsGkAtoms::bdi);
hadDirAuto = HasDirAuto(); // already takes bdi into account
}
// XXXbz Perhaps we should push up the attribute mapping function
@ -1897,7 +1899,8 @@ Element::SetAttrAndNotify(int32_t aNamespaceID,
NS_ENSURE_SUCCESS(rv, rv);
if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::dir) {
OnSetDirAttr(this, &aValueForAfterSetAttr, hadValidDir, aNotify);
OnSetDirAttr(this, &aValueForAfterSetAttr,
hadValidDir, hadDirAuto, aNotify);
}
}
@ -2052,9 +2055,11 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName,
nsMutationGuard::DidMutate();
bool hadValidDir = false;
bool hadDirAuto = false;
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::dir) {
hadValidDir = HasValidDir() || IsHTML(nsGkAtoms::bdi);
hadDirAuto = HasDirAuto(); // already takes bdi into account
}
nsAttrValue oldValue;
@ -2080,7 +2085,7 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName,
NS_ENSURE_SUCCESS(rv, rv);
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::dir) {
OnSetDirAttr(this, nullptr, hadValidDir, aNotify);
OnSetDirAttr(this, nullptr, hadValidDir, hadDirAuto, aNotify);
}
if (hasMutationListeners) {

View File

@ -774,25 +774,6 @@ nsGenericHTMLElement::GetHrefURIForAnchors() const
return uri.forget();
}
nsresult
nsGenericHTMLElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString* aValue,
bool aNotify)
{
if (aNamespaceID == kNameSpaceID_None &&
aName == nsGkAtoms::dir &&
HasDirAuto() && !AncestorHasDirAuto()) {
// When setting dir on an element that currently has dir=auto, we walk the
// descendant tree and clear the AncestorHasDirAuto flag; unless this
// element itself has the AncestorHasDirAuto flag
WalkDescendantsClearAncestorDirAuto(this);
SetHasDirAuto();
}
return nsGenericHTMLElementBase::BeforeSetAttr(aNamespaceID, aName,
aValue, aNotify);
}
nsresult
nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify)

View File

@ -760,10 +760,6 @@ private:
void RegUnRegAccessKey(bool aDoReg);
protected:
virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValueOrString* aValue,
bool aNotify);
virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify);