Bug 1408169 - Remove nsIDOMHTMLMenuItemElement; r?bz
Removes the XPCOM interface for nsIDOMHTMLMenuItemElement, replacing it
with binding class usage.
MozReview-Commit-ID: 9HtCmwKyV1W
--- a/dom/html/HTMLMenuItemElement.cpp
+++ b/dom/html/HTMLMenuItemElement.cpp
@@ -168,20 +168,20 @@ HTMLMenuItemElement::HTMLMenuItemElement
mParserCreating = aFromParser;
}
HTMLMenuItemElement::~HTMLMenuItemElement()
{
}
-NS_IMPL_ISUPPORTS_INHERITED(HTMLMenuItemElement, nsGenericHTMLElement,
- nsIDOMHTMLMenuItemElement)
+NS_IMPL_ISUPPORTS_INHERITED0(HTMLMenuItemElement, nsGenericHTMLElement)
//NS_IMPL_ELEMENT_CLONE(HTMLMenuItemElement)
+
nsresult
HTMLMenuItemElement::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
bool aPreallocateArrays) const
{
*aResult = nullptr;
already_AddRefed<mozilla::dom::NodeInfo> ni = RefPtr<mozilla::dom::NodeInfo>(aNodeInfo).forget();
RefPtr<HTMLMenuItemElement> it =
new HTMLMenuItemElement(ni, NOT_FROM_PARSER);
@@ -200,35 +200,23 @@ HTMLMenuItemElement::Clone(mozilla::dom:
}
it.forget(aResult);
}
return rv;
}
-
-NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(HTMLMenuItemElement, Type, type,
- kMenuItemDefaultType->tag)
-// GetText returns a whitespace compressed .textContent value.
-NS_IMPL_STRING_ATTR_WITH_FALLBACK(HTMLMenuItemElement, Label, label, GetText)
-NS_IMPL_URI_ATTR(HTMLMenuItemElement, Icon, icon)
-NS_IMPL_BOOL_ATTR(HTMLMenuItemElement, Disabled, disabled)
-NS_IMPL_BOOL_ATTR(HTMLMenuItemElement, DefaultChecked, checked)
-//NS_IMPL_BOOL_ATTR(HTMLMenuItemElement, Checked, checked)
-NS_IMPL_STRING_ATTR(HTMLMenuItemElement, Radiogroup, radiogroup)
-
-NS_IMETHODIMP
-HTMLMenuItemElement::GetChecked(bool* aChecked)
+void
+HTMLMenuItemElement::GetType(DOMString& aValue)
{
- *aChecked = mChecked;
- return NS_OK;
+ GetEnumAttr(nsGkAtoms::type, kMenuItemDefaultType->tag, aValue);
}
-NS_IMETHODIMP
+void
HTMLMenuItemElement::SetChecked(bool aChecked)
{
bool checkedChanged = mChecked != aChecked;
mChecked = aChecked;
if (mType == CMD_TYPE_RADIO) {
if (checkedChanged) {
@@ -243,35 +231,34 @@ HTMLMenuItemElement::SetChecked(bool aCh
}
} else if (!mCheckedDirty) {
SetCheckedDirtyVisitor visitor;
WalkRadioGroup(&visitor);
}
} else {
mCheckedDirty = true;
}
-
- return NS_OK;
}
nsresult
HTMLMenuItemElement::GetEventTargetParent(EventChainPreVisitor& aVisitor)
{
if (aVisitor.mEvent->mMessage == eMouseClick) {
bool originalCheckedValue = false;
switch (mType) {
case CMD_TYPE_CHECKBOX:
originalCheckedValue = mChecked;
SetChecked(!originalCheckedValue);
aVisitor.mItemFlags |= NS_CHECKED_IS_TOGGLED;
break;
case CMD_TYPE_RADIO:
- nsCOMPtr<nsIDOMHTMLMenuItemElement> selectedRadio = GetSelectedRadio();
- aVisitor.mItemData = selectedRadio;
+ // casting back to Element* here to resolve nsISupports ambiguity.
+ Element* supports = GetSelectedRadio();
+ aVisitor.mItemData = supports;
originalCheckedValue = mChecked;
if (!originalCheckedValue) {
SetChecked(true);
aVisitor.mItemFlags |= NS_CHECKED_IS_TOGGLED;
}
break;
}
@@ -293,18 +280,18 @@ HTMLMenuItemElement::PostHandleEvent(Eve
// Check to see if the event was cancelled.
if (aVisitor.mEvent->mMessage == eMouseClick &&
aVisitor.mItemFlags & NS_CHECKED_IS_TOGGLED &&
aVisitor.mEventStatus == nsEventStatus_eConsumeNoDefault) {
bool originalCheckedValue =
!!(aVisitor.mItemFlags & NS_ORIGINAL_CHECKED_VALUE);
uint8_t oldType = NS_MENUITEM_TYPE(aVisitor.mItemFlags);
- nsCOMPtr<nsIDOMHTMLMenuItemElement> selectedRadio =
- do_QueryInterface(aVisitor.mItemData);
+ nsCOMPtr<nsIContent> content(do_QueryInterface(aVisitor.mItemData));
+ RefPtr<HTMLMenuItemElement> selectedRadio = HTMLMenuItemElement::FromContentOrNull(content);
if (selectedRadio) {
selectedRadio->SetChecked(true);
if (mType != CMD_TYPE_RADIO) {
SetChecked(false);
}
} else if (oldType == CMD_TYPE_CHECKBOX) {
SetChecked(originalCheckedValue);
}
@@ -476,18 +463,17 @@ HTMLMenuItemElement::AddedToRadioGroup()
WalkRadioGroup(&visitor);
}
mCheckedDirty = checkedDirty;
}
void
HTMLMenuItemElement::InitChecked()
{
- bool defaultChecked;
- GetDefaultChecked(&defaultChecked);
+ bool defaultChecked = DefaultChecked();
mChecked = defaultChecked;
if (mType == CMD_TYPE_RADIO) {
ClearCheckedVisitor visitor(this);
WalkRadioGroup(&visitor);
}
}
JSObject*
--- a/dom/html/HTMLMenuItemElement.h
+++ b/dom/html/HTMLMenuItemElement.h
@@ -3,44 +3,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_HTMLMenuItemElement_h
#define mozilla_dom_HTMLMenuItemElement_h
#include "mozilla/Attributes.h"
-#include "nsIDOMHTMLMenuItemElement.h"
#include "nsGenericHTMLElement.h"
namespace mozilla {
class EventChainPreVisitor;
namespace dom {
class Visitor;
-class HTMLMenuItemElement final : public nsGenericHTMLElement,
- public nsIDOMHTMLMenuItemElement
+class HTMLMenuItemElement final : public nsGenericHTMLElement
{
public:
using mozilla::dom::Element::GetText;
HTMLMenuItemElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
mozilla::dom::FromParser aFromParser);
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLMenuItemElement, menuitem)
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
- // nsIDOMHTMLMenuItemElement
- NS_DECL_NSIDOMHTMLMENUITEMELEMENT
-
virtual nsresult GetEventTargetParent(
EventChainPreVisitor& aVisitor) override;
virtual nsresult PostHandleEvent(
EventChainPostVisitor& aVisitor) override;
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
nsIContent* aBindingParent,
bool aCompileEventHandlers) override;
@@ -62,53 +57,63 @@ public:
*/
bool IsChecked() const { return mChecked; }
bool IsCheckedDirty() const { return mCheckedDirty; }
void GetText(nsAString& aText);
// WebIDL
- // The XPCOM GetType is OK for us
+ void GetType(DOMString& aValue);
void SetType(const nsAString& aType, ErrorResult& aError)
{
SetHTMLAttr(nsGkAtoms::type, aType, aError);
}
- // The XPCOM GetLabel is OK for us
+ // nsAString needed for HTMLMenuElement
+ void GetLabel(nsAString& aValue)
+ {
+ if (!GetAttr(kNameSpaceID_None, nsGkAtoms::label, aValue)) {
+ GetText(aValue);
+ }
+ }
void SetLabel(const nsAString& aLabel, ErrorResult& aError)
{
- SetAttrHelper(nsGkAtoms::label, aLabel);
+ SetHTMLAttr(nsGkAtoms::label, aLabel, aError);
}
- // The XPCOM GetIcon is OK for us
+ // nsAString needed for HTMLMenuElement
+ void GetIcon(nsAString& aValue)
+ {
+ GetURIAttr(nsGkAtoms::icon, nullptr, aValue);
+ }
void SetIcon(const nsAString& aIcon, ErrorResult& aError)
{
- SetAttrHelper(nsGkAtoms::icon, aIcon);
+ SetHTMLAttr(nsGkAtoms::icon, aIcon, aError);
}
bool Disabled() const
{
return GetBoolAttr(nsGkAtoms::disabled);
}
void SetDisabled(bool aDisabled, ErrorResult& aError)
{
SetHTMLBoolAttr(nsGkAtoms::disabled, aDisabled, aError);
}
bool Checked() const
{
return mChecked;
}
- void SetChecked(bool aChecked, ErrorResult& aError)
+ void SetChecked(bool aChecked);
+
+ void GetRadiogroup(DOMString& aValue)
{
- aError = SetChecked(aChecked);
+ GetHTMLAttr(nsGkAtoms::radiogroup, aValue);
}
-
- // The XPCOM GetRadiogroup is OK for us
void SetRadiogroup(const nsAString& aRadiogroup, ErrorResult& aError)
{
SetHTMLAttr(nsGkAtoms::radiogroup, aRadiogroup, aError);
}
bool DefaultChecked() const
{
return GetBoolAttr(nsGkAtoms::checked);
--- a/dom/html/htmlMenuBuilder.js
+++ b/dom/html/htmlMenuBuilder.js
@@ -60,16 +60,21 @@ HTMLMenuBuilder.prototype =
children: []
};
parent.children.push(this.currentNode);
this.nestedStack.push(parent);
}
},
addItemFor: function(aElement, aCanLoadIcon) {
+ // Since we no longer type check this at the IDL level, make sure we've got
+ // the right element type here.
+ if (ChromeUtils.getClassName(aElement) !== "HTMLMenuItemElement") {
+ return;
+ }
if (!("children" in this.currentNode)) {
return;
}
let item = {
type: "menuitem",
label: aElement.label
};
--- a/dom/html/nsIMenuBuilder.idl
+++ b/dom/html/nsIMenuBuilder.idl
@@ -1,16 +1,16 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
-interface nsIDOMHTMLMenuItemElement;
+interface nsIDOMElement;
/**
* An interface used to construct native toolbar or context menus from <menu>
*/
[scriptable, uuid(93F4A48F-D043-4F45-97FD-9771EA1AF976)]
interface nsIMenuBuilder : nsISupports
{
@@ -23,17 +23,17 @@ interface nsIMenuBuilder : nsISupports
void openContainer(in DOMString aLabel);
/**
* Add a new menu item. All menu item details can be obtained from
* the element. This method is not called for hidden elements or elements
* with no or empty label. The icon should be loaded only if aCanLoadIcon
* is true.
*/
- void addItemFor(in nsIDOMHTMLMenuItemElement aElement,
+ void addItemFor(in nsIDOMElement aElement,
in boolean aCanLoadIcon);
/**
* Create a new separator.
*/
void addSeparator();
/**
--- a/dom/interfaces/html/moz.build
+++ b/dom/interfaces/html/moz.build
@@ -11,17 +11,16 @@ XPIDL_SOURCES += [
'nsIDOMHTMLBaseElement.idl',
'nsIDOMHTMLCollection.idl',
'nsIDOMHTMLDocument.idl',
'nsIDOMHTMLElement.idl',
'nsIDOMHTMLFormElement.idl',
'nsIDOMHTMLHtmlElement.idl',
'nsIDOMHTMLInputElement.idl',
'nsIDOMHTMLMediaElement.idl',
- 'nsIDOMHTMLMenuItemElement.idl',
'nsIDOMHTMLOptionElement.idl',
'nsIDOMHTMLOptionsCollection.idl',
'nsIDOMHTMLScriptElement.idl',
'nsIDOMHTMLSelectElement.idl',
'nsIDOMHTMLSourceElement.idl',
'nsIDOMHTMLTextAreaElement.idl',
'nsIDOMMozBrowserFrame.idl',
'nsIDOMTimeRanges.idl',
deleted file mode 100644
--- a/dom/interfaces/html/nsIDOMHTMLMenuItemElement.idl
+++ /dev/null
@@ -1,30 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsIDOMHTMLElement.idl"
-
-/**
- * The nsIDOMHTMLMenuItemElement interface is the interface to a HTML
- * <menuitem> element.
- */
-
-[uuid(979d6e44-5930-4232-b405-873939655c19)]
-interface nsIDOMHTMLMenuItemElement : nsISupports
-{
- attribute DOMString type;
- attribute DOMString label;
- attribute DOMString icon;
- attribute boolean disabled;
-
- // This should be 'default' but in the IDL implementation
- // this has been renamed 'defaultChecked'.
- attribute boolean defaultChecked;
-
- attribute boolean checked;
- attribute DOMString radiogroup;
-
- // Currently not implemented.
- // readonly attribute HTMLElement? command;
-};
--- a/dom/webidl/HTMLMenuItemElement.webidl
+++ b/dom/webidl/HTMLMenuItemElement.webidl
@@ -17,17 +17,17 @@ interface HTMLMenuItemElement : HTMLElem
[CEReactions, SetterThrows]
attribute DOMString type;
[CEReactions, SetterThrows]
attribute DOMString label;
[CEReactions, SetterThrows]
attribute DOMString icon;
[CEReactions, SetterThrows]
attribute boolean disabled;
- [CEReactions, SetterThrows]
+ [CEReactions]
attribute boolean checked;
[CEReactions, SetterThrows]
attribute DOMString radiogroup;
// This should be 'default' but in the IDL implementation
// this has been renamed 'defaultChecked'.
[CEReactions, SetterThrows]
attribute boolean defaultChecked;
--- a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp
+++ b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp
@@ -48,17 +48,16 @@
#include "nsIDOMHTMLBaseElement.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMHTMLFormElement.h"
#include "nsIDOMHTMLHtmlElement.h"
#include "nsIDOMHTMLInputElement.h"
#include "nsIDOMHTMLMediaElement.h"
-#include "nsIDOMHTMLMenuItemElement.h"
#include "nsIDOMHTMLOptionElement.h"
#include "nsIDOMHTMLOptionsCollection.h"
#include "nsIDOMHTMLScriptElement.h"
#include "nsIDOMHTMLSelectElement.h"
#include "nsIDOMHTMLSourceElement.h"
#include "nsIDOMHTMLTextAreaElement.h"
#include "nsIDOMKeyEvent.h"
#include "nsIDOMMediaList.h"
@@ -153,17 +152,16 @@
#include "mozilla/dom/HTMLCollectionBinding.h"
#include "mozilla/dom/HTMLDocumentBinding.h"
#include "mozilla/dom/HTMLElementBinding.h"
#include "mozilla/dom/HTMLFormElementBinding.h"
#include "mozilla/dom/HTMLFrameSetElementBinding.h"
#include "mozilla/dom/HTMLHtmlElementBinding.h"
#include "mozilla/dom/HTMLInputElementBinding.h"
#include "mozilla/dom/HTMLMediaElementBinding.h"
-#include "mozilla/dom/HTMLMenuItemElementBinding.h"
#include "mozilla/dom/HTMLObjectElementBinding.h"
#include "mozilla/dom/HTMLOptionElementBinding.h"
#include "mozilla/dom/HTMLOptionsCollectionBinding.h"
#include "mozilla/dom/HTMLScriptElementBinding.h"
#include "mozilla/dom/HTMLSelectElementBinding.h"
#include "mozilla/dom/HTMLSourceElementBinding.h"
#include "mozilla/dom/HTMLTextAreaElementBinding.h"
#include "mozilla/dom/KeyEventBinding.h"
@@ -311,17 +309,16 @@ const ComponentsInterfaceShimEntry kComp
DEFINE_SHIM(HTMLBaseElement),
DEFINE_SHIM(HTMLCollection),
DEFINE_SHIM(HTMLDocument),
DEFINE_SHIM(HTMLElement),
DEFINE_SHIM(HTMLFormElement),
DEFINE_SHIM(HTMLHtmlElement),
DEFINE_SHIM(HTMLInputElement),
DEFINE_SHIM(HTMLMediaElement),
- DEFINE_SHIM(HTMLMenuItemElement),
DEFINE_SHIM(HTMLOptionElement),
DEFINE_SHIM(HTMLOptionsCollection),
DEFINE_SHIM(HTMLScriptElement),
DEFINE_SHIM(HTMLSelectElement),
DEFINE_SHIM(HTMLSourceElement),
DEFINE_SHIM(HTMLTextAreaElement),
DEFINE_SHIM(KeyEvent),
DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIListBoxObject, ListBoxObject),