From 038d6657ef7ef47c68efbf84360261c50dd999c4 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 12 Apr 2011 14:32:00 +0200 Subject: [PATCH] Bug 619996, part b: make nsHTMLOptionElement::GetSelect return nsHTMLSelectElement; r=bz --- content/html/content/src/nsHTMLOptionElement.cpp | 5 +++-- content/html/content/src/nsHTMLOptionElement.h | 7 ++++--- content/html/content/src/nsHTMLSelectElement.h | 8 ++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/content/html/content/src/nsHTMLOptionElement.cpp b/content/html/content/src/nsHTMLOptionElement.cpp index 9a2fd031cdc..fd521712b0b 100644 --- a/content/html/content/src/nsHTMLOptionElement.cpp +++ b/content/html/content/src/nsHTMLOptionElement.cpp @@ -39,6 +39,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsHTMLOptionElement.h" +#include "nsHTMLSelectElement.h" #include "nsIDOMHTMLOptGroupElement.h" #include "nsIDOMHTMLFormElement.h" #include "nsIDOMEventTarget.h" @@ -371,14 +372,14 @@ nsHTMLOptionElement::IntrinsicState() const } // Get the select content element that contains this option -nsIContent* +nsHTMLSelectElement* nsHTMLOptionElement::GetSelect() { nsIContent* parent = this; while ((parent = parent->GetParent()) && parent->IsHTML()) { if (parent->Tag() == nsGkAtoms::select) { - return parent; + return nsHTMLSelectElement::FromContent(parent); } if (parent->Tag() != nsGkAtoms::optgroup) { break; diff --git a/content/html/content/src/nsHTMLOptionElement.h b/content/html/content/src/nsHTMLOptionElement.h index 9ce6c8a90f8..5d9e75c1d4d 100644 --- a/content/html/content/src/nsHTMLOptionElement.h +++ b/content/html/content/src/nsHTMLOptionElement.h @@ -45,6 +45,8 @@ #include "nsIDOMHTMLOptionElement.h" #include "nsIJSNativeInitializer.h" +class nsHTMLSelectElement; + class nsHTMLOptionElement : public nsGenericHTMLElement, public nsIDOMHTMLOptionElement, public nsIJSNativeInitializer @@ -56,7 +58,7 @@ public: /** Typesafe, non-refcounting cast from nsIContent. Cheaper than QI. **/ static nsHTMLOptionElement* FromContent(nsIContent *aContent) { - if (aContent->NodeInfo()->Equals(nsGkAtoms::option, kNameSpaceID_XHTML)) + if (aContent && aContent->IsHTML(nsGkAtoms::option)) return static_cast(aContent); return nsnull; } @@ -103,9 +105,8 @@ protected: * Get the select content element that contains this option, this * intentionally does not return nsresult, all we care about is if * there's a select associated with this option or not. - * @param aSelectElement the select element (out param) */ - nsIContent* GetSelect(); + nsHTMLSelectElement* GetSelect(); PRPackedBool mSelectedChanged; PRPackedBool mIsSelected; diff --git a/content/html/content/src/nsHTMLSelectElement.h b/content/html/content/src/nsHTMLSelectElement.h index d9912b1f0a0..585f520033f 100644 --- a/content/html/content/src/nsHTMLSelectElement.h +++ b/content/html/content/src/nsHTMLSelectElement.h @@ -253,6 +253,14 @@ public: mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER); virtual ~nsHTMLSelectElement(); + /** Typesafe, non-refcounting cast from nsIContent. Cheaper than QI. **/ + static nsHTMLSelectElement* FromContent(nsIContent* aContent) + { + if (aContent && aContent->IsHTML(nsGkAtoms::select)) + return static_cast(aContent); + return nsnull; + } + // nsISupports NS_DECL_ISUPPORTS_INHERITED