Bug 1086284 - Avoid using refcounting when determining an SVG-as-an-image's intrinsic size so that the image doesn't end up in the CC graph. r=dholbert

This commit is contained in:
Jonathan Watt 2014-12-09 22:32:10 +00:00
Родитель 901e4c3d28
Коммит 9e326f88fc
3 изменённых файлов: 39 добавлений и 25 удалений

Просмотреть файл

@ -7,6 +7,7 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/ContentEvents.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/Likely.h"
#include "nsGkAtoms.h"
@ -1247,5 +1248,29 @@ SVGSVGElement::ClearTransformProperty()
return UnsetProperty(nsGkAtoms::transform);
}
float
SVGSVGElement::GetIntrinsicWidth() const
{
if (mLengthAttributes[ATTR_WIDTH].IsPercentage()) {
return UnspecifiedNaN<float>();
}
// Context is only needed for percentage resolution. We already know we
// don't have a percentage, so no context is needed; hence, nullptr.
SVGSVGElement* context = nullptr;
return std::max(mLengthAttributes[ATTR_WIDTH].GetAnimValue(context), 0.f);
}
float
SVGSVGElement::GetIntrinsicHeight() const
{
if (mLengthAttributes[ATTR_HEIGHT].IsPercentage()) {
return UnspecifiedNaN<float>();
}
// Context is only needed for percentage resolution. We already know we
// don't have a percentage, so no context is needed; hence, nullptr.
SVGSVGElement* context = nullptr;
return std::max(mLengthAttributes[ATTR_HEIGHT].GetAnimValue(context), 0.f);
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -147,6 +147,14 @@ public:
// public helpers:
/**
* Returns the user-unit width/height if those dimensions are not specified
* as percentage values. If they are specified as percentage values then this
* element does not have intrinsic width/height and these methods return NaN.
*/
float GetIntrinsicWidth() const;
float GetIntrinsicHeight() const;
/**
* Returns true if this element has a base/anim value for its "viewBox"
* attribute that defines a viewBox rectangle with finite values, or

Просмотреть файл

@ -6,6 +6,7 @@
#include "SVGDocumentWrapper.h"
#include "mozilla/dom/Element.h"
#include "mozilla/FloatingPoint.h"
#include "nsICategoryManager.h"
#include "nsIChannel.h"
#include "nsIContentViewer.h"
@ -76,34 +77,14 @@ SVGDocumentWrapper::GetWidthOrHeight(Dimension aDimension,
NS_ABORT_IF_FALSE(rootElem, "root elem missing or of wrong type");
// Get the width or height SVG object
nsRefPtr<SVGAnimatedLength> domAnimLength;
if (aDimension == eWidth) {
domAnimLength = rootElem->Width();
} else {
NS_ABORT_IF_FALSE(aDimension == eHeight, "invalid dimension");
domAnimLength = rootElem->Height();
}
NS_ENSURE_TRUE(domAnimLength, false);
float length = (aDimension == eWidth) ? rootElem->GetIntrinsicWidth()
: rootElem->GetIntrinsicHeight();
// Get the animated value from the object
nsRefPtr<DOMSVGLength> domLength = domAnimLength->AnimVal();
NS_ENSURE_TRUE(domLength, false);
// Check if it's a percent value (and fail if so)
uint16_t unitType;
nsresult rv = domLength->GetUnitType(&unitType);
NS_ENSURE_SUCCESS(rv, false);
if (unitType == nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE) {
return false;
if (!IsFinite(length)) {
return false; // Percentage size
}
// Non-percent value - woot! Grab it & return it.
float floatLength;
rv = domLength->GetValue(&floatLength);
NS_ENSURE_SUCCESS(rv, false);
aResult = nsSVGUtils::ClampToInt(floatLength);
aResult = nsSVGUtils::ClampToInt(length);
return true;
}