diff --git a/content/html/content/src/HTMLMenuElement.cpp b/content/html/content/src/HTMLMenuElement.cpp index a55cd9c6b94..0c8807281c8 100644 --- a/content/html/content/src/HTMLMenuElement.cpp +++ b/content/html/content/src/HTMLMenuElement.cpp @@ -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 aNodeInfo) : nsGenericHTMLElement(aNodeInfo), mType(MENU_TYPE_LIST) { + SetIsDOMBinding(); } HTMLMenuElement::~HTMLMenuElement() @@ -113,6 +115,16 @@ HTMLMenuElement::CreateBuilder(nsIMenuBuilder** _retval) return NS_OK; } +already_AddRefed +HTMLMenuElement::CreateBuilder() +{ + if (mType != MENU_TYPE_CONTEXT) { + return nullptr; + } + + nsCOMPtr 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 diff --git a/content/html/content/src/HTMLMenuElement.h b/content/html/content/src/HTMLMenuElement.h index 3f1dbd95407..74f480d35bc 100644 --- a/content/html/content/src/HTMLMenuElement.h +++ b/content/html/content/src/HTMLMenuElement.h @@ -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 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); diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 325b44ede0b..c2bc626de3e 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -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) diff --git a/dom/webidl/HTMLElement.webidl b/dom/webidl/HTMLElement.webidl index c39c8a9528d..9638b7de7b8 100644 --- a/dom/webidl/HTMLElement.webidl +++ b/dom/webidl/HTMLElement.webidl @@ -13,7 +13,6 @@ */ interface DOMStringMap; -interface HTMLMenuElement; // Hack to make sure that we initialize the touch prefs properly [PrefControlled] diff --git a/dom/webidl/HTMLMenuElement.webidl b/dom/webidl/HTMLMenuElement.webidl new file mode 100644 index 00000000000..5ee2e66e379 --- /dev/null +++ b/dom/webidl/HTMLMenuElement.webidl @@ -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 . + */ + [ChromeOnly] + void build(MenuBuilder aBuilder); +}; diff --git a/dom/webidl/WebIDL.mk b/dom/webidl/WebIDL.mk index 76a7458133e..500989981ad 100644 --- a/dom/webidl/WebIDL.mk +++ b/dom/webidl/WebIDL.mk @@ -83,6 +83,7 @@ webidl_files = \ HTMLLIElement.webidl \ HTMLLinkElement.webidl \ HTMLMapElement.webidl \ + HTMLMenuElement.webidl \ HTMLMenuItemElement.webidl \ HTMLMetaElement.webidl \ HTMLMeterElement.webidl \