Bug 1365162 - Part 2: Factor out lang="" namespace checks. r=emilio
MozReview-Commit-ID: CBwV3xB5sz9
--- a/dom/base/nsIContent.h
+++ b/dom/base/nsIContent.h
@@ -916,30 +916,33 @@ public:
/**
* If the content is a part of HTML editor, this returns editing
* host content. When the content is in designMode, this returns its body
* element. Also, when the content isn't editable, this returns null.
*/
mozilla::dom::Element* GetEditingHost();
+ bool SupportsLangAttr() const {
+ return IsHTMLElement() || IsSVGElement() || IsXULElement();
+ }
+
/**
* Determining language. Look at the nearest ancestor element that has a lang
* attribute in the XML namespace or is an HTML/SVG element and has a lang in
* no namespace attribute. Returns false if no language was specified.
*/
bool GetLang(nsAString& aResult) const {
for (const nsIContent* content = this; content; content = content->GetParent()) {
if (content->GetAttrCount() > 0) {
// xml:lang has precedence over lang on HTML elements (see
// XHTML1 section C.7).
bool hasAttr = content->GetAttr(kNameSpaceID_XML, nsGkAtoms::lang,
aResult);
- if (!hasAttr && (content->IsHTMLElement() || content->IsSVGElement() ||
- content->IsXULElement())) {
+ if (!hasAttr && content->SupportsLangAttr()) {
hasAttr = content->GetAttr(kNameSpaceID_None, nsGkAtoms::lang,
aResult);
}
NS_ASSERTION(hasAttr || aResult.IsEmpty(),
"GetAttr that returns false should not make string non-empty");
if (hasAttr) {
return true;
}