Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 824899 - Don't use nsIDOMSVGElement where possible r=longsonr
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbarsky committed Jan 6, 2013
1 parent 311d742 commit 20d51cb
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 38 deletions.
5 changes: 2 additions & 3 deletions content/svg/content/src/SVGContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "mozilla/Preferences.h"
#include "nsComputedDOMStyle.h"
#include "nsFontMetrics.h"
#include "nsIDOMSVGElement.h"
#include "nsIFrame.h"
#include "nsIScriptError.h"
#include "nsLayoutUtils.h"
Expand Down Expand Up @@ -160,7 +159,7 @@ SVGContentUtils::EstablishesViewport(nsIContent *aContent)
aContent->Tag() == nsGkAtoms::symbol);
}

already_AddRefed<nsIDOMSVGElement>
nsSVGElement*
SVGContentUtils::GetNearestViewportElement(nsIContent *aContent)
{
nsIContent *element = aContent->GetFlattenedTreeParent();
Expand All @@ -170,7 +169,7 @@ SVGContentUtils::GetNearestViewportElement(nsIContent *aContent)
if (element->Tag() == nsGkAtoms::foreignObject) {
return nullptr;
}
return nsCOMPtr<nsIDOMSVGElement>(do_QueryInterface(element)).forget();
return static_cast<nsSVGElement*>(element);
}
element = element->GetFlattenedTreeParent();
}
Expand Down
3 changes: 1 addition & 2 deletions content/svg/content/src/SVGContentUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

class nsIContent;
class nsIDocument;
class nsIDOMSVGElement;
class nsIFrame;
class nsStyleContext;
class nsSVGElement;
Expand Down Expand Up @@ -106,7 +105,7 @@ class SVGContentUtils
*/
static bool EstablishesViewport(nsIContent *aContent);

static already_AddRefed<nsIDOMSVGElement>
static nsSVGElement*
GetNearestViewportElement(nsIContent *aContent);

/* enum for specifying coordinate direction for ObjectSpace/UserSpace */
Expand Down
16 changes: 6 additions & 10 deletions content/svg/content/src/SVGLocatableElement.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* -*- Mode: C++; 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/. */
Expand Down Expand Up @@ -33,16 +32,15 @@ NS_INTERFACE_MAP_END_INHERITING(nsSVGElement)
NS_IMETHODIMP
SVGLocatableElement::GetNearestViewportElement(nsIDOMSVGElement * *aNearestViewportElement)
{
*aNearestViewportElement = SVGContentUtils::GetNearestViewportElement(this).get();
nsCOMPtr<nsIDOMSVGElement> domElem = do_QueryInterface(GetNearestViewportElement());
domElem.forget(aNearestViewportElement);
return NS_OK;
}

already_AddRefed<nsSVGElement>
nsSVGElement*
SVGLocatableElement::GetNearestViewportElement()
{
nsCOMPtr<nsIDOMSVGElement> elem = SVGContentUtils::GetNearestViewportElement(this);
nsCOMPtr<nsSVGElement> svgElem = do_QueryInterface(elem);
return svgElem.forget();
return SVGContentUtils::GetNearestViewportElement(this);
}

/* readonly attribute nsIDOMSVGElement farthestViewportElement; */
Expand All @@ -53,12 +51,10 @@ SVGLocatableElement::GetFarthestViewportElement(nsIDOMSVGElement * *aFarthestVie
return NS_OK;
}

already_AddRefed<nsSVGElement>
nsSVGElement*
SVGLocatableElement::GetFarthestViewportElement()
{
nsCOMPtr<nsIDOMSVGElement> elem = SVGContentUtils::GetOuterSVGElement(this);
nsCOMPtr<nsSVGElement> svgElem = do_QueryInterface(elem);
return svgElem.forget();
return SVGContentUtils::GetOuterSVGElement(this);
}

/* nsIDOMSVGRect getBBox (); */
Expand Down
4 changes: 2 additions & 2 deletions content/svg/content/src/SVGLocatableElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class SVGLocatableElement : public nsSVGElement,
NS_DECL_NSIDOMSVGLOCATABLE

// WebIDL
already_AddRefed<nsSVGElement> GetNearestViewportElement();
already_AddRefed<nsSVGElement> GetFarthestViewportElement();
nsSVGElement* GetNearestViewportElement();
nsSVGElement* GetFarthestViewportElement();
already_AddRefed<nsIDOMSVGRect> GetBBox(ErrorResult& rv);
already_AddRefed<DOMSVGMatrix> GetCTM();
already_AddRefed<DOMSVGMatrix> GetScreenCTM();
Expand Down
9 changes: 3 additions & 6 deletions content/svg/content/src/nsSVGElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,19 +1174,16 @@ nsSVGElement::GetOwnerSVGElement(ErrorResult& rv)
NS_IMETHODIMP
nsSVGElement::GetViewportElement(nsIDOMSVGElement * *aViewportElement)
{
nsCOMPtr<nsSVGElement> elem = GetViewportElement();
nsSVGElement* elem = GetViewportElement();
nsCOMPtr<nsIDOMSVGElement> svgElem = do_QueryInterface(elem);
svgElem.forget(aViewportElement);
return NS_OK;
}

already_AddRefed<nsSVGElement>
nsSVGElement*
nsSVGElement::GetViewportElement()
{
nsCOMPtr<nsIDOMSVGElement> elem =
SVGContentUtils::GetNearestViewportElement(this);
nsCOMPtr<nsSVGElement> svgElem = do_QueryInterface(elem);
return svgElem.forget();
return SVGContentUtils::GetNearestViewportElement(this);
}

already_AddRefed<nsIDOMSVGAnimatedString>
Expand Down
2 changes: 1 addition & 1 deletion content/svg/content/src/nsSVGElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class nsSVGElement : public nsSVGElementBase // nsIContent

// WebIDL
nsSVGSVGElement* GetOwnerSVGElement(mozilla::ErrorResult& rv);
already_AddRefed<nsSVGElement> GetViewportElement();
nsSVGElement* GetViewportElement();
already_AddRefed<nsIDOMSVGAnimatedString> ClassName();
nsICSSDeclaration* GetStyle(mozilla::ErrorResult& rv);
already_AddRefed<mozilla::dom::CSSValue> GetPresentationAttribute(const nsAString& aName, mozilla::ErrorResult& rv);
Expand Down
5 changes: 3 additions & 2 deletions dom/bindings/Bindings.conf
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ DOMInterfaces = {
'nativeType': 'nsSVGElement',
'hasXPConnectImpls': True,
'hasInstanceInterface': 'nsIDOMSVGElement',
'resultNotAddRefed': ['ownerSVGElement', 'style']
'resultNotAddRefed': ['ownerSVGElement', 'viewportElement', 'style']
},

'SVGGraphicsElement': {
Expand All @@ -615,7 +615,8 @@ DOMInterfaces = {

'SVGLocatableElement': {
'hasXPConnectImpls': True,
'concrete': False
'concrete': False,
'resultNotAddRefed': ['nearestViewportElement', 'farthestViewportElement']
},

'SVGLengthList': {
Expand Down
15 changes: 3 additions & 12 deletions embedding/browser/webBrowser/nsDocShellTreeOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "nsIDOMElement.h"
#include "Link.h"
#include "mozilla/dom/Element.h"
#include "nsIDOMSVGElement.h"
#include "nsIDOMSVGTitleElement.h"
#include "nsIDOMEvent.h"
#include "nsIDOMMouseEvent.h"
Expand Down Expand Up @@ -1015,19 +1014,11 @@ DefaultTooltipTextProvider::DefaultTooltipTextProvider()
static bool
UseSVGTitle(nsIDOMElement *currElement)
{
nsCOMPtr<nsIDOMSVGElement> svgContent(do_QueryInterface(currElement));
if (!svgContent)
nsCOMPtr<dom::Element> element(do_QueryInterface(currElement));
if (!element || !element->IsSVG() || !element->GetParentNode())
return false;

nsCOMPtr<nsIDOMNode> parent;
currElement->GetParentNode(getter_AddRefs(parent));
if (!parent)
return false;

uint16_t nodeType;
nsresult rv = parent->GetNodeType(&nodeType);

return NS_SUCCEEDED(rv) && nodeType != nsIDOMNode::DOCUMENT_NODE;
return element->GetParentNode()->NodeType() != nsIDOMNode::DOCUMENT_NODE;
}

/* void getNodeText (in nsIDOMNode aNode, out wstring aText); */
Expand Down

0 comments on commit 20d51cb

Please sign in to comment.