Bug 838559 - Convert HTMLMenuElement to WebIDL. r=Ms2ger, r=peterv

This commit is contained in:
Andrea Marchesini 2013-02-18 06:59:08 -05:00
parent 8f44285b2e
commit acfa9340f7
6 changed files with 114 additions and 2 deletions

View File

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "HTMLMenuElement.h"
#include "mozilla/dom/HTMLMenuElementBinding.h"
#include "nsXULContextMenuBuilder.h"
#include "nsEventDispatcher.h"
#include "HTMLMenuItemElement.h"
@ -44,6 +45,7 @@ enum SeparatorType
HTMLMenuElement::HTMLMenuElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: nsGenericHTMLElement(aNodeInfo), mType(MENU_TYPE_LIST)
{
SetIsDOMBinding();
}
HTMLMenuElement::~HTMLMenuElement()
@ -113,6 +115,16 @@ HTMLMenuElement::CreateBuilder(nsIMenuBuilder** _retval)
return NS_OK;
}
already_AddRefed<nsIMenuBuilder>
HTMLMenuElement::CreateBuilder()
{
if (mType != MENU_TYPE_CONTEXT) {
return nullptr;
}
nsCOMPtr<nsIMenuBuilder> ret = new nsXULContextMenuBuilder();
return ret.forget();
}
NS_IMETHODIMP
HTMLMenuElement::Build(nsIMenuBuilder* aBuilder)
@ -255,5 +267,12 @@ HTMLMenuElement::AddSeparator(nsIMenuBuilder* aBuilder, int8_t& aSeparator)
aSeparator = ST_TRUE;
}
JSObject*
HTMLMenuElement::WrapNode(JSContext* aCx, JSObject* aScope,
bool* aTriedToWrap)
{
return HTMLMenuElementBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
} // namespace dom
} // namespace mozilla

View File

@ -54,6 +54,40 @@ public:
uint8_t GetType() const { return mType; }
// WebIDL
// The XPCOM GetType is OK for us
void SetType(const nsAString& aType, ErrorResult& aError)
{
SetHTMLAttr(nsGkAtoms::type, aType, aError);
}
// The XPCOM GetLabel is OK for us
void SetLabel(const nsAString& aLabel, ErrorResult& aError)
{
SetHTMLAttr(nsGkAtoms::label, aLabel, aError);
}
bool Compact() const
{
return GetBoolAttr(nsGkAtoms::compact);
}
void SetCompact(bool aCompact, ErrorResult& aError)
{
SetHTMLBoolAttr(nsGkAtoms::compact, aCompact, aError);
}
// The XPCOM SendShowEvent is OK for us
already_AddRefed<nsIMenuBuilder> CreateBuilder();
// The XPCOM Build is OK for us
protected:
virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope,
bool *aTriedToWrap) MOZ_OVERRIDE;
protected:
static bool CanLoadIcon(nsIContent* aContent, const nsAString& aIcon);

View File

@ -1177,7 +1177,6 @@ def addExternalHTMLElement(element):
headerFile=nativeElement + '.h')
addExternalHTMLElement('HTMLFormElement')
addExternalIface('HTMLMenuElement', nativeType='mozilla::dom::HTMLMenuElement', headerFile='HTMLMenuElement.h')
addExternalHTMLElement('HTMLOptionElement')
addExternalHTMLElement('HTMLVideoElement')
addExternalIface('Attr')
@ -1194,6 +1193,7 @@ addExternalIface('HTMLCanvasElement', nativeType='mozilla::dom::HTMLCanvasElemen
addExternalIface('imgINotificationObserver', nativeType='imgINotificationObserver')
addExternalIface('imgIRequest', nativeType='imgIRequest', notflattened=True)
addExternalIface('LockedFile')
addExternalIface('MenuBuilder', nativeType='nsIMenuBuilder', notflattened=True)
addExternalIface('MozBoxObject', nativeType='nsIBoxObject')
addExternalIface('MozControllers', nativeType='nsIControllers')
addExternalIface('MozFrameLoader', nativeType='nsIFrameLoader', notflattened=True)

View File

@ -13,7 +13,6 @@
*/
interface DOMStringMap;
interface HTMLMenuElement;
// Hack to make sure that we initialize the touch prefs properly
[PrefControlled]

View File

@ -0,0 +1,59 @@
/* -*- 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/.
*
* The origin of this IDL file is
* http://www.whatwg.org/specs/web-apps/current-work/#the-menu-element
* http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis
*
* © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
* Opera Software ASA. You are granted a license to use, reproduce
* and create derivative works of this document.
*/
interface MenuBuilder;
// http://www.whatwg.org/specs/web-apps/current-work/#the-menu-element
interface HTMLMenuElement : HTMLElement {
[SetterThrows]
attribute DOMString type;
[SetterThrows]
attribute DOMString label;
};
// http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis
partial interface HTMLMenuElement {
[SetterThrows]
attribute boolean compact;
};
// Mozilla specific stuff
partial interface HTMLMenuElement {
/**
* Creates and dispatches a trusted event named "show".
* The event is not cancelable and does not bubble.
* See http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#context-menus
*/
[ChromeOnly]
void sendShowEvent();
/**
* Creates a native menu builder. The builder type is dependent on menu type.
* Currently, it returns nsXULContextMenuBuilder for context menus.
* Toolbar menus are not yet supported (the method returns null).
*/
[ChromeOnly]
MenuBuilder createBuilder();
/*
* Builds a menu by iterating over menu children.
* See http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#building-menus-and-toolbars
* The caller can use a native builder by calling createBuilder() or provide
* a custom builder that implements the nsIMenuBuilder interface.
* A custom builder can be used for example to build native context menus
* that are not defined using <menupopup>.
*/
[ChromeOnly]
void build(MenuBuilder aBuilder);
};

View File

@ -83,6 +83,7 @@ webidl_files = \
HTMLLIElement.webidl \
HTMLLinkElement.webidl \
HTMLMapElement.webidl \
HTMLMenuElement.webidl \
HTMLMenuItemElement.webidl \
HTMLMetaElement.webidl \
HTMLMeterElement.webidl \