mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 667582 - Stop const_casting in nsHTMLOptionElement; r=bz
This commit is contained in:
parent
9fa708c87f
commit
3f2027861d
@ -183,14 +183,7 @@ NS_IMETHODIMP
|
||||
nsHTMLOptionElement::GetSelected(PRBool* aValue)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aValue);
|
||||
*aValue = PR_FALSE;
|
||||
|
||||
// If we haven't been explictly selected or deselected, use our default value
|
||||
if (!mSelectedChanged) {
|
||||
return GetDefaultSelected(aValue);
|
||||
}
|
||||
|
||||
*aValue = mIsSelected;
|
||||
*aValue = Selected();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -257,6 +250,23 @@ nsHTMLOptionElement::GetIndex(PRInt32* aIndex)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
nsHTMLOptionElement::Selected() const
|
||||
{
|
||||
// If we haven't been explictly selected or deselected, use our default value
|
||||
if (!mSelectedChanged) {
|
||||
return DefaultSelected();
|
||||
}
|
||||
|
||||
return mIsSelected;
|
||||
}
|
||||
|
||||
bool
|
||||
nsHTMLOptionElement::DefaultSelected() const
|
||||
{
|
||||
return HasAttr(kNameSpaceID_None, nsGkAtoms::selected);
|
||||
}
|
||||
|
||||
nsChangeHint
|
||||
nsHTMLOptionElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
||||
PRInt32 aModType) const
|
||||
@ -341,18 +351,10 @@ nsEventStates
|
||||
nsHTMLOptionElement::IntrinsicState() const
|
||||
{
|
||||
nsEventStates state = nsGenericHTMLElement::IntrinsicState();
|
||||
// Nasty hack because we need to call an interface method, and one that
|
||||
// toggles some of our hidden internal state at that! Would that we could
|
||||
// use |mutable|.
|
||||
PRBool selected;
|
||||
const_cast<nsHTMLOptionElement*>(this)->GetSelected(&selected);
|
||||
if (selected) {
|
||||
if (Selected()) {
|
||||
state |= NS_EVENT_STATE_CHECKED;
|
||||
}
|
||||
|
||||
// Also calling a non-const interface method (for :default)
|
||||
const_cast<nsHTMLOptionElement*>(this)->GetDefaultSelected(&selected);
|
||||
if (selected) {
|
||||
if (DefaultSelected()) {
|
||||
state |= NS_EVENT_STATE_DEFAULT;
|
||||
}
|
||||
|
||||
@ -475,9 +477,7 @@ nsHTMLOptionElement::CopyInnerTo(nsGenericElement* aDest) const
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (aDest->GetOwnerDoc()->IsStaticDocument()) {
|
||||
PRBool selected = PR_FALSE;
|
||||
const_cast<nsHTMLOptionElement*>(this)->GetSelected(&selected);
|
||||
static_cast<nsHTMLOptionElement*>(aDest)->SetSelected(selected);
|
||||
static_cast<nsHTMLOptionElement*>(aDest)->SetSelected(Selected());
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -80,6 +80,9 @@ public:
|
||||
using nsGenericElement::GetText;
|
||||
NS_DECL_NSIDOMHTMLOPTIONELEMENT
|
||||
|
||||
bool Selected() const;
|
||||
bool DefaultSelected() const;
|
||||
|
||||
// nsIJSNativeInitializer
|
||||
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,
|
||||
JSObject *aObj, PRUint32 argc, jsval *argv);
|
||||
|
Loading…
Reference in New Issue
Block a user