2015-05-03 19:32:37 +00: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 09:32:02 +00: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/SVGCircleElement.h"
|
2013-11-02 11:10:38 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-01-06 09:32:02 +00:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "mozilla/dom/SVGCircleElementBinding.h"
|
2018-02-02 13:21:33 +00:00
|
|
|
#include "mozilla/dom/SVGLengthBinding.h"
|
2013-01-06 09:32:02 +00:00
|
|
|
|
2018-12-21 11:43:29 +00:00
|
|
|
NS_IMPL_NS_NEW_SVG_ELEMENT(Circle)
|
2013-01-06 09:32:02 +00:00
|
|
|
|
2013-11-02 11:10:38 +00:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2013-01-06 09:32:02 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
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 14:13:33 +00:00
|
|
|
JSObject* SVGCircleElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-25 21:20:54 +00:00
|
|
|
return SVGCircleElement_Binding::Wrap(aCx, this, aGivenProto);
|
2013-01-06 09:32:02 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 08:58:14 +00:00
|
|
|
SVGElement::LengthInfo SVGCircleElement::sLengthInfo[3] = {
|
2018-03-29 09:45:24 +00:00
|
|
|
{nsGkAtoms::cx, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
|
|
|
|
SVGContentUtils::X},
|
|
|
|
{nsGkAtoms::cy, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
|
|
|
|
SVGContentUtils::Y},
|
|
|
|
{nsGkAtoms::r, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER,
|
|
|
|
SVGContentUtils::XY}};
|
2013-01-06 09:32:02 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2018-09-21 20:45:49 +00:00
|
|
|
SVGCircleElement::SVGCircleElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: SVGCircleElementBase(std::move(aNodeInfo)) {}
|
2013-01-06 09:32:02 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-05-30 02:58:49 +00:00
|
|
|
// nsINode methods
|
2013-01-06 09:32:02 +00:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGCircleElement)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2013-01-19 20:56:00 +00:00
|
|
|
already_AddRefed<SVGAnimatedLength> SVGCircleElement::Cx() {
|
2013-01-06 09:32:02 +00:00
|
|
|
return mLengthAttributes[ATTR_CX].ToDOMAnimatedLength(this);
|
2013-01-06 09:32:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-19 20:56:00 +00:00
|
|
|
already_AddRefed<SVGAnimatedLength> SVGCircleElement::Cy() {
|
2013-01-06 09:32:02 +00:00
|
|
|
return mLengthAttributes[ATTR_CY].ToDOMAnimatedLength(this);
|
2013-01-06 09:32:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-19 20:56:00 +00:00
|
|
|
already_AddRefed<SVGAnimatedLength> SVGCircleElement::R() {
|
2013-01-06 09:32:02 +00:00
|
|
|
return mLengthAttributes[ATTR_R].ToDOMAnimatedLength(this);
|
2013-01-06 09:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-21 08:58:14 +00:00
|
|
|
// SVGElement methods
|
2013-01-06 09:32:02 +00:00
|
|
|
|
|
|
|
/* virtual */ bool SVGCircleElement::HasValidDimensions() const {
|
|
|
|
return mLengthAttributes[ATTR_R].IsExplicitlySet() &&
|
|
|
|
mLengthAttributes[ATTR_R].GetAnimValInSpecifiedUnits() > 0;
|
|
|
|
}
|
|
|
|
|
2018-12-21 08:58:14 +00:00
|
|
|
SVGElement::LengthAttributesInfo SVGCircleElement::GetLengthInfo() {
|
2013-01-06 09:32:02 +00:00
|
|
|
return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
|
|
|
|
ArrayLength(sLengthInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-12-18 11:11:47 +00:00
|
|
|
// SVGGeometryElement methods
|
2013-01-06 09:32:02 +00:00
|
|
|
|
2015-09-01 04:17:00 +00:00
|
|
|
bool SVGCircleElement::GetGeometryBounds(
|
|
|
|
Rect* aBounds, const StrokeOptions& aStrokeOptions,
|
|
|
|
const Matrix& aToBoundsSpace, const Matrix* aToNonScalingStrokeSpace) {
|
2014-10-29 01:59:36 +00:00
|
|
|
float x, y, r;
|
|
|
|
GetAnimatedLengthValues(&x, &y, &r, nullptr);
|
|
|
|
|
|
|
|
if (r <= 0.f) {
|
|
|
|
// Rendering of the element is disabled
|
2016-09-08 16:26:03 +00:00
|
|
|
*aBounds = Rect(aToBoundsSpace.TransformPoint(Point(x, y)), Size());
|
2014-10-29 01:59:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-01 04:17:00 +00:00
|
|
|
if (aToBoundsSpace.IsRectilinear()) {
|
2014-10-29 01:59:36 +00:00
|
|
|
// Optimize the case where we can treat the circle as a rectangle and
|
|
|
|
// still get tight bounds.
|
2015-02-03 18:36:32 +00:00
|
|
|
if (aStrokeOptions.mLineWidth > 0.f) {
|
2015-09-01 04:17:00 +00:00
|
|
|
if (aToNonScalingStrokeSpace) {
|
|
|
|
if (aToNonScalingStrokeSpace->IsRectilinear()) {
|
2015-09-30 06:05:00 +00:00
|
|
|
MOZ_ASSERT(!aToNonScalingStrokeSpace->IsSingular());
|
2015-09-01 04:17:00 +00:00
|
|
|
Rect userBounds(x - r, y - r, 2 * r, 2 * r);
|
|
|
|
SVGContentUtils::RectilinearGetStrokeBounds(
|
|
|
|
userBounds, aToBoundsSpace, *aToNonScalingStrokeSpace,
|
|
|
|
aStrokeOptions.mLineWidth, aBounds);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-03 18:36:32 +00:00
|
|
|
r += aStrokeOptions.mLineWidth / 2.f;
|
2014-10-29 01:59:36 +00:00
|
|
|
}
|
|
|
|
Rect rect(x - r, y - r, 2 * r, 2 * r);
|
2015-09-01 04:17:00 +00:00
|
|
|
*aBounds = aToBoundsSpace.TransformBounds(rect);
|
2014-10-29 01:59:36 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-05 20:53:04 +00:00
|
|
|
already_AddRefed<Path> SVGCircleElement::BuildPath(PathBuilder* aBuilder) {
|
2013-11-02 11:10:38 +00:00
|
|
|
float x, y, r;
|
|
|
|
GetAnimatedLengthValues(&x, &y, &r, nullptr);
|
|
|
|
|
2013-11-06 10:05:18 +00:00
|
|
|
if (r <= 0.0f) {
|
|
|
|
return nullptr;
|
2013-11-02 11:10:38 +00:00
|
|
|
}
|
|
|
|
|
2014-10-04 11:13:30 +00:00
|
|
|
aBuilder->Arc(Point(x, y), r, 0, Float(2 * M_PI));
|
2013-11-06 10:05:18 +00:00
|
|
|
|
2014-10-04 11:13:30 +00:00
|
|
|
return aBuilder->Finish();
|
2013-11-02 11:10:38 +00:00
|
|
|
}
|
|
|
|
|
2013-01-06 09:32:02 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|