Bug 1492326, add helpers to Element to get nsIDOMXUL* and nsIBrowser interfaces implented by custom elements, r=peterv

This commit is contained in:
Neil Deakin 2018-12-04 11:25:42 -05:00
parent d2ed932b7c
commit 90cfd345ef
2 changed files with 98 additions and 0 deletions

View File

@ -148,6 +148,17 @@
#include "nsDOMStringMap.h"
#include "DOMIntersectionObserver.h"
#include "nsIDOMXULButtonElement.h"
#include "nsIDOMXULContainerElement.h"
#include "nsIDOMXULControlElement.h"
#include "nsIDOMXULMenuListElement.h"
#include "nsIDOMXULMultSelectCntrlEl.h"
#include "nsIDOMXULRelatedElement.h"
#include "nsIDOMXULMultSelectCntrlEl.h"
#include "nsIDOMXULSelectCntrlEl.h"
#include "nsIDOMXULSelectCntrlItemEl.h"
#include "nsIBrowser.h"
#include "nsISpeculativeConnect.h"
#include "nsIIOService.h"
@ -3931,6 +3942,68 @@ void Element::SetCustomElementDefinition(CustomElementDefinition* aDefinition) {
data->SetCustomElementDefinition(aDefinition);
}
already_AddRefed<nsIDOMXULButtonElement> Element::AsXULButton() {
nsCOMPtr<nsIDOMXULButtonElement> value;
GetCustomInterface(getter_AddRefs(value));
return value.forget();
}
already_AddRefed<nsIDOMXULContainerElement> Element::AsXULContainer() {
nsCOMPtr<nsIDOMXULContainerElement> value;
GetCustomInterface(getter_AddRefs(value));
return value.forget();
}
already_AddRefed<nsIDOMXULContainerItemElement> Element::AsXULContainerItem() {
nsCOMPtr<nsIDOMXULContainerItemElement> value;
GetCustomInterface(getter_AddRefs(value));
return value.forget();
}
already_AddRefed<nsIDOMXULControlElement> Element::AsXULControl() {
nsCOMPtr<nsIDOMXULControlElement> value;
GetCustomInterface(getter_AddRefs(value));
return value.forget();
}
already_AddRefed<nsIDOMXULMenuListElement> Element::AsXULMenuList() {
nsCOMPtr<nsIDOMXULMenuListElement> value;
GetCustomInterface(getter_AddRefs(value));
return value.forget();
}
already_AddRefed<nsIDOMXULMultiSelectControlElement>
Element::AsXULMultiSelectControl() {
nsCOMPtr<nsIDOMXULMultiSelectControlElement> value;
GetCustomInterface(getter_AddRefs(value));
return value.forget();
}
already_AddRefed<nsIDOMXULRelatedElement> Element::AsXULRelated() {
nsCOMPtr<nsIDOMXULRelatedElement> value;
GetCustomInterface(getter_AddRefs(value));
return value.forget();
}
already_AddRefed<nsIDOMXULSelectControlElement> Element::AsXULSelectControl() {
nsCOMPtr<nsIDOMXULSelectControlElement> value;
GetCustomInterface(getter_AddRefs(value));
return value.forget();
}
already_AddRefed<nsIDOMXULSelectControlItemElement>
Element::AsXULSelectControlItem() {
nsCOMPtr<nsIDOMXULSelectControlItemElement> value;
GetCustomInterface(getter_AddRefs(value));
return value.forget();
}
already_AddRefed<nsIBrowser> Element::AsBrowser() {
nsCOMPtr<nsIBrowser> value;
GetCustomInterface(getter_AddRefs(value));
return value.forget();
}
MOZ_DEFINE_MALLOC_SIZE_OF(ServoElementMallocSizeOf)
MOZ_DEFINE_MALLOC_ENCLOSING_SIZE_OF(ServoElementMallocEnclosingSizeOf)

View File

@ -63,6 +63,17 @@ class nsDocument;
class nsDOMStringMap;
struct ServoNodeData;
class nsIDOMXULButtonElement;
class nsIDOMXULContainerElement;
class nsIDOMXULContainerItemElement;
class nsIDOMXULControlElement;
class nsIDOMXULMenuListElement;
class nsIDOMXULMultiSelectControlElement;
class nsIDOMXULRelatedElement;
class nsIDOMXULSelectControlElement;
class nsIDOMXULSelectControlItemElement;
class nsIBrowser;
namespace mozilla {
class DeclarationBlock;
struct MutationClosureData;
@ -1567,6 +1578,20 @@ class Element : public FragmentOrElement {
bool UpdateIntersectionObservation(DOMIntersectionObserver* aObserver,
int32_t threshold);
// A number of methods to cast to various XUL interfaces. They return a
// pointer only if the element implements that interface.
already_AddRefed<nsIDOMXULButtonElement> AsXULButton();
already_AddRefed<nsIDOMXULContainerElement> AsXULContainer();
already_AddRefed<nsIDOMXULContainerItemElement> AsXULContainerItem();
already_AddRefed<nsIDOMXULControlElement> AsXULControl();
already_AddRefed<nsIDOMXULMenuListElement> AsXULMenuList();
already_AddRefed<nsIDOMXULMultiSelectControlElement>
AsXULMultiSelectControl();
already_AddRefed<nsIDOMXULRelatedElement> AsXULRelated();
already_AddRefed<nsIDOMXULSelectControlElement> AsXULSelectControl();
already_AddRefed<nsIDOMXULSelectControlItemElement> AsXULSelectControlItem();
already_AddRefed<nsIBrowser> AsBrowser();
protected:
/*
* Named-bools for use with SetAttrAndNotify to make call sites easier to