2015-05-03 12:32:37 -07: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 01:32:02 -08: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 04:10:38 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-01-06 01:32:02 -08:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "mozilla/dom/SVGCircleElementBinding.h"
|
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Circle)
|
|
|
|
|
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*
|
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 07:13:33 -07:00
|
|
|
SVGCircleElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-01-06 01:32:02 -08: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 07:13:33 -07:00
|
|
|
return SVGCircleElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-06 01:32:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::LengthInfo SVGCircleElement::sLengthInfo[3] =
|
|
|
|
{
|
|
|
|
{ &nsGkAtoms::cx, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
|
|
|
|
{ &nsGkAtoms::cy, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
|
|
|
|
{ &nsGkAtoms::r, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::XY }
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
SVGCircleElement::SVGCircleElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-01-06 01:32:02 -08:00
|
|
|
: SVGCircleElementBase(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGCircleElement)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2013-01-19 12:56:00 -08:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 01:32:02 -08:00
|
|
|
SVGCircleElement::Cx()
|
|
|
|
{
|
2013-01-06 01:32:02 -08:00
|
|
|
return mLengthAttributes[ATTR_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
|
|
|
SVGCircleElement::Cy()
|
|
|
|
{
|
2013-01-06 01:32:02 -08:00
|
|
|
return mLengthAttributes[ATTR_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
|
|
|
SVGCircleElement::R()
|
|
|
|
{
|
2013-01-06 01:32:02 -08:00
|
|
|
return mLengthAttributes[ATTR_R].ToDOMAnimatedLength(this);
|
2013-01-06 01:32:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGElement methods
|
|
|
|
|
|
|
|
/* virtual */ bool
|
|
|
|
SVGCircleElement::HasValidDimensions() const
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_R].IsExplicitlySet() &&
|
|
|
|
mLengthAttributes[ATTR_R].GetAnimValInSpecifiedUnits() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::LengthAttributesInfo
|
|
|
|
SVGCircleElement::GetLengthInfo()
|
|
|
|
{
|
|
|
|
return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
|
|
|
|
ArrayLength(sLengthInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGPathGeometryElement methods
|
|
|
|
|
2014-10-28 18:59:36 -07:00
|
|
|
bool
|
2015-02-03 10:36:32 -08:00
|
|
|
SVGCircleElement::GetGeometryBounds(
|
|
|
|
Rect* aBounds, const StrokeOptions& aStrokeOptions, const Matrix& aTransform)
|
2014-10-28 18:59:36 -07:00
|
|
|
{
|
|
|
|
float x, y, r;
|
|
|
|
GetAnimatedLengthValues(&x, &y, &r, nullptr);
|
|
|
|
|
|
|
|
if (r <= 0.f) {
|
|
|
|
// Rendering of the element is disabled
|
2015-01-21 05:09:45 -08:00
|
|
|
*aBounds = Rect(aTransform * Point(x, y), Size());
|
2014-10-28 18:59:36 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aTransform.IsRectilinear()) {
|
|
|
|
// Optimize the case where we can treat the circle as a rectangle and
|
|
|
|
// still get tight bounds.
|
2015-02-03 10:36:32 -08:00
|
|
|
if (aStrokeOptions.mLineWidth > 0.f) {
|
|
|
|
r += aStrokeOptions.mLineWidth / 2.f;
|
2014-10-28 18:59:36 -07:00
|
|
|
}
|
|
|
|
Rect rect(x - r, y - r, 2 * r, 2 * r);
|
|
|
|
*aBounds = aTransform.TransformBounds(rect);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-17 07:00:52 -07:00
|
|
|
already_AddRefed<Path>
|
2014-07-05 13:53:04 -07:00
|
|
|
SVGCircleElement::BuildPath(PathBuilder* aBuilder)
|
2013-11-02 04:10:38 -07:00
|
|
|
{
|
|
|
|
float x, y, r;
|
|
|
|
GetAnimatedLengthValues(&x, &y, &r, nullptr);
|
|
|
|
|
2013-11-06 02:05:18 -08:00
|
|
|
if (r <= 0.0f) {
|
|
|
|
return nullptr;
|
2013-11-02 04:10:38 -07:00
|
|
|
}
|
|
|
|
|
2014-10-04 04:13:30 -07:00
|
|
|
aBuilder->Arc(Point(x, y), r, 0, Float(2*M_PI));
|
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
|