2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-01-06 13:32:02 +04:00
|
|
|
/* 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 15:10:38 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
2015-10-18 07:40:10 +03:00
|
|
|
#include "mozilla/nsRefPtr.h"
|
2013-01-06 13:32:02 +04:00
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Ellipse)
|
|
|
|
|
2013-11-02 15:10:38 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
SVGEllipseElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-01-06 13:32:02 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return SVGEllipseElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-06 13:32:02 +04: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-20 06:01:40 +04:00
|
|
|
SVGEllipseElement::SVGEllipseElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-01-06 13:32:02 +04:00
|
|
|
: SVGEllipseElementBase(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGEllipseElement)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMSVGEllipseElement methods
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGEllipseElement::Cx()
|
|
|
|
{
|
2013-01-06 13:32:02 +04:00
|
|
|
return mLengthAttributes[CX].ToDOMAnimatedLength(this);
|
2013-01-06 13:32:02 +04:00
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGEllipseElement::Cy()
|
|
|
|
{
|
2013-01-06 13:32:02 +04:00
|
|
|
return mLengthAttributes[CY].ToDOMAnimatedLength(this);
|
2013-01-06 13:32:02 +04:00
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGEllipseElement::Rx()
|
|
|
|
{
|
2013-01-06 13:32:02 +04:00
|
|
|
return mLengthAttributes[RX].ToDOMAnimatedLength(this);
|
2013-01-06 13:32:02 +04:00
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGEllipseElement::Ry()
|
|
|
|
{
|
2013-01-06 13:32:02 +04:00
|
|
|
return mLengthAttributes[RY].ToDOMAnimatedLength(this);
|
2013-01-06 13:32:02 +04: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-29 04:59:36 +03:00
|
|
|
bool
|
2015-09-01 07:17:00 +03:00
|
|
|
SVGEllipseElement::GetGeometryBounds(Rect* aBounds,
|
|
|
|
const StrokeOptions& aStrokeOptions,
|
|
|
|
const Matrix& aToBoundsSpace,
|
|
|
|
const Matrix* aToNonScalingStrokeSpace)
|
2014-10-29 04:59:36 +03:00
|
|
|
{
|
|
|
|
float x, y, rx, ry;
|
|
|
|
GetAnimatedLengthValues(&x, &y, &rx, &ry, nullptr);
|
|
|
|
|
|
|
|
if (rx <= 0.f || ry <= 0.f) {
|
|
|
|
// Rendering of the element is disabled
|
2015-09-01 07:17:00 +03:00
|
|
|
*aBounds = Rect(aToBoundsSpace * Point(x, y), Size());
|
2014-10-29 04:59:36 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-01 07:17:00 +03:00
|
|
|
if (aToBoundsSpace.IsRectilinear()) {
|
2014-10-29 04:59:36 +03:00
|
|
|
// Optimize the case where we can treat the ellipse as a rectangle and
|
|
|
|
// still get tight bounds.
|
2015-02-03 21:36:32 +03:00
|
|
|
if (aStrokeOptions.mLineWidth > 0.f) {
|
2015-09-01 07:17:00 +03:00
|
|
|
if (aToNonScalingStrokeSpace) {
|
|
|
|
if (aToNonScalingStrokeSpace->IsRectilinear()) {
|
2015-09-30 09:05:00 +03:00
|
|
|
MOZ_ASSERT(!aToNonScalingStrokeSpace->IsSingular());
|
2015-09-01 07:17:00 +03:00
|
|
|
Rect userBounds(x - rx, y - ry, 2 * rx, 2 * ry);
|
|
|
|
SVGContentUtils::RectilinearGetStrokeBounds(
|
|
|
|
userBounds, aToBoundsSpace, *aToNonScalingStrokeSpace,
|
|
|
|
aStrokeOptions.mLineWidth, aBounds);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-03 21:36:32 +03:00
|
|
|
rx += aStrokeOptions.mLineWidth / 2.f;
|
|
|
|
ry += aStrokeOptions.mLineWidth / 2.f;
|
2014-10-29 04:59:36 +03:00
|
|
|
}
|
|
|
|
Rect rect(x - rx, y - ry, 2 * rx, 2 * ry);
|
2015-09-01 07:17:00 +03:00
|
|
|
*aBounds = aToBoundsSpace.TransformBounds(rect);
|
2014-10-29 04:59:36 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<Path>
|
2014-07-06 00:53:04 +04:00
|
|
|
SVGEllipseElement::BuildPath(PathBuilder* aBuilder)
|
2013-11-02 15:10:38 +04:00
|
|
|
{
|
|
|
|
float x, y, rx, ry;
|
|
|
|
GetAnimatedLengthValues(&x, &y, &rx, &ry, nullptr);
|
|
|
|
|
2013-11-06 14:05:18 +04:00
|
|
|
if (rx <= 0.0f || ry <= 0.0f) {
|
|
|
|
return nullptr;
|
2013-11-02 15:10:38 +04:00
|
|
|
}
|
|
|
|
|
2014-10-04 15:13:30 +04:00
|
|
|
EllipseToBezier(aBuilder, Point(x, y), Size(rx, ry));
|
2013-11-06 14:05:18 +04:00
|
|
|
|
2014-10-04 15:13:30 +04:00
|
|
|
return aBuilder->Finish();
|
2013-11-02 15:10:38 +04:00
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|