2013-01-06 01:32:02 -08:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/SVGEllipseElement.h"
|
|
|
|
#include "mozilla/dom/SVGEllipseElementBinding.h"
|
2013-11-02 04:10:38 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
2014-07-06 08:30:55 -07:00
|
|
|
#include "mozilla/RefPtr.h"
|
2013-01-06 01:32:02 -08:00
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Ellipse)
|
|
|
|
|
2013-11-02 04:10:38 -07:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2013-01-06 01:32:02 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
JSObject*
|
2014-04-08 15:27:17 -07:00
|
|
|
SVGEllipseElement::WrapNode(JSContext *aCx)
|
2013-01-06 01:32:02 -08:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return SVGEllipseElementBinding::Wrap(aCx, this);
|
2013-01-06 01:32:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::LengthInfo SVGEllipseElement::sLengthInfo[4] =
|
|
|
|
{
|
|
|
|
{ &nsGkAtoms::cx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
|
|
|
|
{ &nsGkAtoms::cy, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
|
|
|
|
{ &nsGkAtoms::rx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
|
|
|
|
{ &nsGkAtoms::ry, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
SVGEllipseElement::SVGEllipseElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-01-06 01:32:02 -08:00
|
|
|
: SVGEllipseElementBase(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGEllipseElement)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMSVGEllipseElement methods
|
|
|
|
|
2013-01-19 12:56:00 -08:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 01:32:02 -08:00
|
|
|
SVGEllipseElement::Cx()
|
|
|
|
{
|
2013-01-06 01:32:02 -08:00
|
|
|
return mLengthAttributes[CX].ToDOMAnimatedLength(this);
|
2013-01-06 01:32:02 -08:00
|
|
|
}
|
|
|
|
|
2013-01-19 12:56:00 -08:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 01:32:02 -08:00
|
|
|
SVGEllipseElement::Cy()
|
|
|
|
{
|
2013-01-06 01:32:02 -08:00
|
|
|
return mLengthAttributes[CY].ToDOMAnimatedLength(this);
|
2013-01-06 01:32:02 -08:00
|
|
|
}
|
|
|
|
|
2013-01-19 12:56:00 -08:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 01:32:02 -08:00
|
|
|
SVGEllipseElement::Rx()
|
|
|
|
{
|
2013-01-06 01:32:02 -08:00
|
|
|
return mLengthAttributes[RX].ToDOMAnimatedLength(this);
|
2013-01-06 01:32:02 -08:00
|
|
|
}
|
|
|
|
|
2013-01-19 12:56:00 -08:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 01:32:02 -08:00
|
|
|
SVGEllipseElement::Ry()
|
|
|
|
{
|
2013-01-06 01:32:02 -08:00
|
|
|
return mLengthAttributes[RY].ToDOMAnimatedLength(this);
|
2013-01-06 01:32:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGElement methods
|
|
|
|
|
|
|
|
/* virtual */ bool
|
|
|
|
SVGEllipseElement::HasValidDimensions() const
|
|
|
|
{
|
|
|
|
return mLengthAttributes[RX].IsExplicitlySet() &&
|
|
|
|
mLengthAttributes[RX].GetAnimValInSpecifiedUnits() > 0 &&
|
|
|
|
mLengthAttributes[RY].IsExplicitlySet() &&
|
|
|
|
mLengthAttributes[RY].GetAnimValInSpecifiedUnits() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::LengthAttributesInfo
|
|
|
|
SVGEllipseElement::GetLengthInfo()
|
|
|
|
{
|
|
|
|
return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
|
|
|
|
ArrayLength(sLengthInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGPathGeometryElement methods
|
|
|
|
|
2014-10-28 18:59:36 -07:00
|
|
|
bool
|
|
|
|
SVGEllipseElement::GetGeometryBounds(Rect* aBounds, Float aStrokeWidth,
|
|
|
|
const Matrix& aTransform)
|
|
|
|
{
|
|
|
|
float x, y, rx, ry;
|
|
|
|
GetAnimatedLengthValues(&x, &y, &rx, &ry, nullptr);
|
|
|
|
|
|
|
|
if (rx <= 0.f || ry <= 0.f) {
|
|
|
|
// Rendering of the element is disabled
|
|
|
|
aBounds->MoveTo(x, y);
|
|
|
|
aBounds->SetEmpty();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aTransform.IsRectilinear()) {
|
|
|
|
// Optimize the case where we can treat the ellipse as a rectangle and
|
|
|
|
// still get tight bounds.
|
|
|
|
if (aStrokeWidth > 0.f) {
|
|
|
|
rx += aStrokeWidth / 2.f;
|
|
|
|
ry += aStrokeWidth / 2.f;
|
|
|
|
}
|
|
|
|
Rect rect(x - rx, y - ry, 2 * rx, 2 * ry);
|
|
|
|
*aBounds = aTransform.TransformBounds(rect);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-02 04:10:38 -07:00
|
|
|
TemporaryRef<Path>
|
2014-07-05 13:53:04 -07:00
|
|
|
SVGEllipseElement::BuildPath(PathBuilder* aBuilder)
|
2013-11-02 04:10:38 -07:00
|
|
|
{
|
|
|
|
float x, y, rx, ry;
|
|
|
|
GetAnimatedLengthValues(&x, &y, &rx, &ry, nullptr);
|
|
|
|
|
2013-11-06 02:05:18 -08:00
|
|
|
if (rx <= 0.0f || ry <= 0.0f) {
|
|
|
|
return nullptr;
|
2013-11-02 04:10:38 -07:00
|
|
|
}
|
|
|
|
|
2014-10-04 04:13:30 -07:00
|
|
|
EllipseToBezier(aBuilder, Point(x, y), Size(rx, ry));
|
2013-11-06 02:05:18 -08:00
|
|
|
|
2014-10-04 04:13:30 -07:00
|
|
|
return aBuilder->Finish();
|
2013-11-02 04:10:38 -07:00
|
|
|
}
|
|
|
|
|
2013-01-06 01:32:02 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|