mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Fix for bug 804991 (Make FromContent expect a non-null pointer and add FromContentOrNull). r=bz.
--HG-- extra : rebase_source : 52e1c9171d05ba034971cfa16741e12061e7335d
This commit is contained in:
parent
340572b953
commit
584658dc3e
@ -904,4 +904,23 @@ inline nsIContent* nsINode::AsContent()
|
||||
return static_cast<nsIContent*>(this);
|
||||
}
|
||||
|
||||
#define NS_IMPL_FROMCONTENT_HELPER(_class, _check) \
|
||||
static _class* FromContent(nsIContent* aContent) \
|
||||
{ \
|
||||
return aContent->_check ? static_cast<_class*>(aContent) : nullptr; \
|
||||
} \
|
||||
static _class* FromContentOrNull(nsIContent* aContent) \
|
||||
{ \
|
||||
return aContent ? FromContent(aContent) : nullptr; \
|
||||
}
|
||||
|
||||
#define NS_IMPL_FROMCONTENT(_class, _nsid) \
|
||||
NS_IMPL_FROMCONTENT_HELPER(_class, IsInNamespace(_nsid))
|
||||
|
||||
#define NS_IMPL_FROMCONTENT_WITH_TAG(_class, _nsid, _tag) \
|
||||
NS_IMPL_FROMCONTENT_HELPER(_class, NodeInfo()->Equals(nsGkAtoms::_tag, _nsid))
|
||||
|
||||
#define NS_IMPL_FROMCONTENT_HTML_WITH_TAG(_class, _tag) \
|
||||
NS_IMPL_FROMCONTENT_WITH_TAG(_class, kNameSpaceID_XHTML, _tag)
|
||||
|
||||
#endif /* nsIContent_h___ */
|
||||
|
@ -46,13 +46,8 @@ public:
|
||||
nsHTMLCanvasElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
virtual ~nsHTMLCanvasElement();
|
||||
|
||||
static nsHTMLCanvasElement* FromContent(nsIContent* aPossibleCanvas)
|
||||
{
|
||||
if (!aPossibleCanvas || !aPossibleCanvas->IsHTML(nsGkAtoms::canvas)) {
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<nsHTMLCanvasElement*>(aPossibleCanvas);
|
||||
}
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(nsHTMLCanvasElement, canvas)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
|
@ -16,13 +16,7 @@ public:
|
||||
nsHTMLVideoElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
virtual ~nsHTMLVideoElement();
|
||||
|
||||
static nsHTMLVideoElement* FromContent(nsIContent* aPossibleVideo)
|
||||
{
|
||||
if (!aPossibleVideo || !aPossibleVideo->IsHTML(nsGkAtoms::video)) {
|
||||
return NULL;
|
||||
}
|
||||
return static_cast<nsHTMLVideoElement*>(aPossibleVideo);
|
||||
}
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(nsHTMLVideoElement, video)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
@ -3127,7 +3127,7 @@ nsGenericHTMLElement::GetContextMenu(nsIDOMHTMLMenuElement** aContextMenu)
|
||||
nsIDocument* doc = GetCurrentDoc();
|
||||
if (doc) {
|
||||
nsRefPtr<nsHTMLMenuElement> element =
|
||||
nsHTMLMenuElement::FromContent(doc->GetElementById(value));
|
||||
nsHTMLMenuElement::FromContentOrNull(doc->GetElementById(value));
|
||||
element.forget(aContextMenu);
|
||||
}
|
||||
|
||||
|
@ -53,13 +53,7 @@ public:
|
||||
SetFlags(NODE_HAS_DIRECTION_LTR);
|
||||
}
|
||||
|
||||
/** Typesafe, non-refcounting cast from nsIContent. Cheaper than QI. **/
|
||||
static nsGenericHTMLElement* FromContent(nsIContent *aContent)
|
||||
{
|
||||
if (aContent->IsHTML())
|
||||
return static_cast<nsGenericHTMLElement*>(aContent);
|
||||
return nullptr;
|
||||
}
|
||||
NS_IMPL_FROMCONTENT(nsGenericHTMLElement, kNameSpaceID_XHTML)
|
||||
|
||||
/**
|
||||
* Handle QI for the standard DOM interfaces (DOMNode, DOMElement,
|
||||
|
@ -21,14 +21,7 @@ public:
|
||||
nsHTMLFieldSetElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
virtual ~nsHTMLFieldSetElement();
|
||||
|
||||
/** Typesafe, non-refcounting cast from nsIContent. Cheaper than QI. **/
|
||||
static nsHTMLFieldSetElement* FromContent(nsIContent* aContent)
|
||||
{
|
||||
if (!aContent || !aContent->IsHTML(nsGkAtoms::fieldset)) {
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<nsHTMLFieldSetElement*>(aContent);
|
||||
}
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(nsHTMLFieldSetElement, fieldset)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
@ -47,6 +47,8 @@ public:
|
||||
nsHTMLFrameSetElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
virtual ~nsHTMLFrameSetElement();
|
||||
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(nsHTMLFrameSetElement, frameset)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
@ -111,12 +113,6 @@ public:
|
||||
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
|
||||
virtual nsXPCClassInfo* GetClassInfo();
|
||||
virtual nsIDOMNode* AsDOMNode() { return this; }
|
||||
static nsHTMLFrameSetElement* FromContent(nsIContent *aContent)
|
||||
{
|
||||
if (aContent->IsHTML(nsGkAtoms::frameset))
|
||||
return static_cast<nsHTMLFrameSetElement*>(aContent);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
nsresult ParseRowCol(const nsAString& aValue,
|
||||
|
@ -17,6 +17,8 @@ public:
|
||||
mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
|
||||
virtual ~nsHTMLIFrameElement();
|
||||
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(nsHTMLIFrameElement, iframe)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
@ -63,14 +65,6 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static nsHTMLIFrameElement* FromContent(nsIContent *aContent)
|
||||
{
|
||||
if (aContent->IsHTML(nsGkAtoms::iframe)) {
|
||||
return static_cast<nsHTMLIFrameElement*>(aContent);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void GetItemValueText(nsAString& text);
|
||||
virtual void SetItemValueText(const nsAString& text);
|
||||
|
@ -65,6 +65,8 @@ public:
|
||||
mozilla::dom::FromParser aFromParser);
|
||||
virtual ~nsHTMLInputElement();
|
||||
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(nsHTMLInputElement, input)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
@ -196,13 +198,6 @@ public:
|
||||
|
||||
virtual nsIDOMNode* AsDOMNode() { return this; }
|
||||
|
||||
static nsHTMLInputElement* FromContent(nsIContent *aContent)
|
||||
{
|
||||
if (aContent->NodeInfo()->Equals(nsGkAtoms::input, kNameSpaceID_XHTML))
|
||||
return static_cast<nsHTMLInputElement*>(aContent);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// nsIConstraintValidation
|
||||
bool IsTooLong();
|
||||
bool IsValueMissing() const;
|
||||
|
@ -19,14 +19,7 @@ public:
|
||||
nsHTMLLabelElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
virtual ~nsHTMLLabelElement();
|
||||
|
||||
static nsHTMLLabelElement* FromContent(nsIContent* aPossibleLabel)
|
||||
{
|
||||
if (aPossibleLabel->IsHTML(nsGkAtoms::label)) {
|
||||
return static_cast<nsHTMLLabelElement*>(aPossibleLabel);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(nsHTMLLabelElement, label)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
@ -15,13 +15,7 @@ public:
|
||||
nsHTMLLegendElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
virtual ~nsHTMLLegendElement();
|
||||
|
||||
static nsHTMLLegendElement* FromContent(nsIContent *aContent)
|
||||
{
|
||||
if (aContent->IsHTML(nsGkAtoms::legend)) {
|
||||
return static_cast<nsHTMLLegendElement*>(aContent);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(nsHTMLLegendElement, legend)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
@ -15,13 +15,7 @@ public:
|
||||
nsHTMLMenuElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
virtual ~nsHTMLMenuElement();
|
||||
|
||||
/** Typesafe, non-refcounting cast from nsIContent. Cheaper than QI. **/
|
||||
static nsHTMLMenuElement* FromContent(nsIContent* aContent)
|
||||
{
|
||||
if (aContent && aContent->IsHTML(nsGkAtoms::menu))
|
||||
return static_cast<nsHTMLMenuElement*>(aContent);
|
||||
return nullptr;
|
||||
}
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(nsHTMLMenuElement, menu)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
@ -18,14 +18,7 @@ public:
|
||||
mozilla::dom::FromParser aFromParser);
|
||||
virtual ~nsHTMLMenuItemElement();
|
||||
|
||||
/** Typesafe, non-refcounting cast from nsIContent. Cheaper than QI. **/
|
||||
static nsHTMLMenuItemElement* FromContent(nsIContent* aContent)
|
||||
{
|
||||
if (aContent && aContent->IsHTML(nsGkAtoms::menuitem)) {
|
||||
return static_cast<nsHTMLMenuItemElement*>(aContent);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(nsHTMLMenuItemElement, menuitem)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
@ -350,8 +350,9 @@ nsHTMLOptionElement::GetSelect()
|
||||
nsIContent* parent = this;
|
||||
while ((parent = parent->GetParent()) &&
|
||||
parent->IsHTML()) {
|
||||
if (parent->Tag() == nsGkAtoms::select) {
|
||||
return nsHTMLSelectElement::FromContent(parent);
|
||||
nsHTMLSelectElement* select = nsHTMLSelectElement::FromContent(parent);
|
||||
if (select) {
|
||||
return select;
|
||||
}
|
||||
if (parent->Tag() != nsGkAtoms::optgroup) {
|
||||
break;
|
||||
|
@ -21,13 +21,7 @@ public:
|
||||
nsHTMLOptionElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
virtual ~nsHTMLOptionElement();
|
||||
|
||||
/** Typesafe, non-refcounting cast from nsIContent. Cheaper than QI. **/
|
||||
static nsHTMLOptionElement* FromContent(nsIContent *aContent)
|
||||
{
|
||||
if (aContent && aContent->IsHTML(nsGkAtoms::option))
|
||||
return static_cast<nsHTMLOptionElement*>(aContent);
|
||||
return nullptr;
|
||||
}
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(nsHTMLOptionElement, option)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
@ -53,7 +53,7 @@ nsSafeOptionListMutation::nsSafeOptionListMutation(nsIContent* aSelect,
|
||||
nsIContent* aKid,
|
||||
uint32_t aIndex,
|
||||
bool aNotify)
|
||||
: mSelect(nsHTMLSelectElement::FromContent(aSelect))
|
||||
: mSelect(nsHTMLSelectElement::FromContentOrNull(aSelect))
|
||||
, mTopLevelMutation(false)
|
||||
, mNeedsRebuild(false)
|
||||
{
|
||||
|
@ -237,14 +237,8 @@ public:
|
||||
mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
|
||||
virtual ~nsHTMLSelectElement();
|
||||
|
||||
/** Typesafe, non-refcounting cast from nsIContent. Cheaper than QI. **/
|
||||
static nsHTMLSelectElement* FromContent(nsIContent* aContent)
|
||||
{
|
||||
if (aContent && aContent->IsHTML(nsGkAtoms::select))
|
||||
return static_cast<nsHTMLSelectElement*>(aContent);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(nsHTMLSelectElement, select)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
|
@ -1672,8 +1672,8 @@ bool
|
||||
nsTextEditorState::GetMaxLength(int32_t* aMaxLength)
|
||||
{
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(mTextCtrlElement);
|
||||
NS_ENSURE_TRUE(content, false);
|
||||
nsGenericHTMLElement* element = nsGenericHTMLElement::FromContent(content);
|
||||
nsGenericHTMLElement* element =
|
||||
nsGenericHTMLElement::FromContentOrNull(content);
|
||||
NS_ENSURE_TRUE(element, false);
|
||||
|
||||
const nsAttrValue* attr = element->GetParsedAttr(nsGkAtoms::maxlength);
|
||||
|
@ -333,18 +333,9 @@ PR_STATIC_ASSERT((ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + 2) < 32);
|
||||
|
||||
class nsScriptEventHandlerOwnerTearoff;
|
||||
|
||||
class nsXULElement : public nsStyledElement, public nsIDOMXULElement
|
||||
class nsXULElement : public nsStyledElement,
|
||||
public nsIDOMXULElement
|
||||
{
|
||||
public:
|
||||
|
||||
/** Typesafe, non-refcounting cast from nsIContent. Cheaper than QI. **/
|
||||
static nsXULElement* FromContent(nsIContent *aContent)
|
||||
{
|
||||
if (aContent->IsXUL())
|
||||
return static_cast<nsXULElement*>(aContent);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
nsXULElement(already_AddRefed<nsINodeInfo> aNodeInfo);
|
||||
|
||||
@ -352,6 +343,8 @@ public:
|
||||
Create(nsXULPrototypeElement* aPrototype, nsIDocument* aDocument,
|
||||
bool aIsScriptable, mozilla::dom::Element** aResult);
|
||||
|
||||
NS_IMPL_FROMCONTENT(nsXULElement, kNameSpaceID_XUL)
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXULElement,
|
||||
|
@ -305,10 +305,8 @@ nsFileControlFrame::CaptureMouseListener::HandleEvent(nsIDOMEvent* aMouseEvent)
|
||||
|
||||
// Get parent nsPIDOMWindow object.
|
||||
nsIContent* content = mFrame->GetContent();
|
||||
if (!content)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsHTMLInputElement* inputElement = nsHTMLInputElement::FromContent(content);
|
||||
nsHTMLInputElement* inputElement =
|
||||
nsHTMLInputElement::FromContentOrNull(content);
|
||||
if (!inputElement)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -23,13 +23,6 @@
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::layers;
|
||||
|
||||
static nsHTMLCanvasElement *
|
||||
CanvasElementFromContent(nsIContent *content)
|
||||
{
|
||||
nsCOMPtr<nsIDOMHTMLCanvasElement> domCanvas(do_QueryInterface(content));
|
||||
return domCanvas ? static_cast<nsHTMLCanvasElement*>(domCanvas.get()) : nullptr;
|
||||
}
|
||||
|
||||
class nsDisplayCanvas : public nsDisplayItem {
|
||||
public:
|
||||
nsDisplayCanvas(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
||||
@ -49,7 +42,8 @@ public:
|
||||
bool* aSnap) {
|
||||
*aSnap = false;
|
||||
nsIFrame* f = GetUnderlyingFrame();
|
||||
nsHTMLCanvasElement *canvas = CanvasElementFromContent(f->GetContent());
|
||||
nsHTMLCanvasElement *canvas =
|
||||
nsHTMLCanvasElement::FromContent(f->GetContent());
|
||||
nsRegion result;
|
||||
if (canvas->GetIsOpaque()) {
|
||||
result = GetBounds(aBuilder, aSnap);
|
||||
@ -74,7 +68,7 @@ public:
|
||||
LayerManager* aManager,
|
||||
const FrameLayerBuilder::ContainerParameters& aParameters)
|
||||
{
|
||||
if (CanvasElementFromContent(mFrame->GetContent())->ShouldForceInactiveLayer(aManager))
|
||||
if (nsHTMLCanvasElement::FromContent(mFrame->GetContent())->ShouldForceInactiveLayer(aManager))
|
||||
return LAYER_INACTIVE;
|
||||
|
||||
// If compositing is cheap, just do that
|
||||
@ -117,7 +111,8 @@ nsIntSize
|
||||
nsHTMLCanvasFrame::GetCanvasSize()
|
||||
{
|
||||
nsIntSize size(0,0);
|
||||
nsHTMLCanvasElement *canvas = CanvasElementFromContent(GetContent());
|
||||
nsHTMLCanvasElement *canvas =
|
||||
nsHTMLCanvasElement::FromContentOrNull(GetContent());
|
||||
if (canvas) {
|
||||
size = canvas->GetSize();
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user