Bug 619996, part b: make nsHTMLOptionElement::GetSelect return nsHTMLSelectElement; r=bz

This commit is contained in:
Ms2ger 2011-04-12 14:32:00 +02:00
parent bb2faf4a3d
commit 038d6657ef
3 changed files with 15 additions and 5 deletions

View File

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

View File

@ -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<nsHTMLOptionElement*>(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;

View File

@ -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<nsHTMLSelectElement*>(aContent);
return nsnull;
}
// nsISupports
NS_DECL_ISUPPORTS_INHERITED