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/SVGLineElement.h"
|
|
|
|
#include "mozilla/dom/SVGLineElementBinding.h"
|
2013-11-02 15:10:38 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-01-06 13:32:02 +04:00
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Line)
|
|
|
|
|
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
|
|
|
SVGLineElement::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 SVGLineElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-06 13:32:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::LengthInfo SVGLineElement::sLengthInfo[4] =
|
|
|
|
{
|
|
|
|
{ &nsGkAtoms::x1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
|
|
|
|
{ &nsGkAtoms::y1, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
|
|
|
|
{ &nsGkAtoms::x2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
|
|
|
|
{ &nsGkAtoms::y2, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
SVGLineElement::SVGLineElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-01-06 13:32:02 +04:00
|
|
|
: SVGLineElementBase(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGLineElement)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGLineElement::X1()
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_X1].ToDOMAnimatedLength(this);
|
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGLineElement::Y1()
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_Y1].ToDOMAnimatedLength(this);
|
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGLineElement::X2()
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_X2].ToDOMAnimatedLength(this);
|
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGLineElement::Y2()
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_Y2].ToDOMAnimatedLength(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
SVGLineElement::IsAttributeMapped(const nsIAtom* name) const
|
|
|
|
{
|
|
|
|
static const MappedAttributeEntry* const map[] = {
|
|
|
|
sMarkersMap
|
|
|
|
};
|
|
|
|
|
|
|
|
return FindAttributeDependence(name, map) ||
|
|
|
|
SVGLineElementBase::IsAttributeMapped(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGElement methods
|
|
|
|
|
|
|
|
nsSVGElement::LengthAttributesInfo
|
|
|
|
SVGLineElement::GetLengthInfo()
|
|
|
|
{
|
|
|
|
return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
|
|
|
|
ArrayLength(sLengthInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGPathGeometryElement methods
|
|
|
|
|
|
|
|
void
|
|
|
|
SVGLineElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks) {
|
|
|
|
float x1, y1, x2, y2;
|
|
|
|
|
|
|
|
GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr);
|
|
|
|
|
|
|
|
float angle = atan2(y2 - y1, x2 - x1);
|
|
|
|
|
2013-07-12 10:39:38 +04:00
|
|
|
aMarks->AppendElement(nsSVGMark(x1, y1, angle, nsSVGMark::eStart));
|
|
|
|
aMarks->AppendElement(nsSVGMark(x2, y2, angle, nsSVGMark::eEnd));
|
2013-01-06 13:32:02 +04:00
|
|
|
}
|
|
|
|
|
2014-10-22 15:29:05 +04:00
|
|
|
void
|
|
|
|
SVGLineElement::GetAsSimplePath(SimplePath* aSimplePath)
|
|
|
|
{
|
|
|
|
float x1, y1, x2, y2;
|
|
|
|
GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr);
|
|
|
|
aSimplePath->SetLine(x1, y1, x2, y2);
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<Path>
|
2014-07-06 00:53:04 +04:00
|
|
|
SVGLineElement::BuildPath(PathBuilder* aBuilder)
|
2013-11-02 15:10:38 +04:00
|
|
|
{
|
|
|
|
float x1, y1, x2, y2;
|
|
|
|
GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr);
|
|
|
|
|
2014-10-04 15:13:30 +04:00
|
|
|
aBuilder->MoveTo(Point(x1, y1));
|
|
|
|
aBuilder->LineTo(Point(x2, y2));
|
2013-11-02 15:10:38 +04:00
|
|
|
|
2014-10-04 15:13:30 +04:00
|
|
|
return aBuilder->Finish();
|
2013-11-02 15:10:38 +04:00
|
|
|
}
|
|
|
|
|
2015-01-22 12:36:08 +03:00
|
|
|
bool
|
2015-02-03 21:36:32 +03:00
|
|
|
SVGLineElement::GetGeometryBounds(
|
|
|
|
Rect* aBounds, const StrokeOptions& aStrokeOptions, const Matrix& aTransform)
|
2015-01-22 12:36:08 +03:00
|
|
|
{
|
|
|
|
float x1, y1, x2, y2;
|
|
|
|
GetAnimatedLengthValues(&x1, &y1, &x2, &y2, nullptr);
|
|
|
|
|
2015-02-03 21:36:32 +03:00
|
|
|
if (aStrokeOptions.mLineWidth <= 0) {
|
2015-01-22 12:36:08 +03:00
|
|
|
*aBounds = Rect(aTransform * Point(x1, y1), Size());
|
|
|
|
aBounds->ExpandToEnclose(aTransform * Point(x2, y2));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-03 21:36:32 +03:00
|
|
|
if (aStrokeOptions.mLineCap == CapStyle::ROUND) {
|
2015-01-22 12:36:08 +03:00
|
|
|
if (!aTransform.IsRectilinear()) {
|
|
|
|
// TODO: handle this case.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Rect bounds(Point(x1, y1), Size());
|
|
|
|
bounds.ExpandToEnclose(Point(x2, y2));
|
2015-02-03 21:36:32 +03:00
|
|
|
bounds.Inflate(aStrokeOptions.mLineWidth / 2.f);
|
2015-01-22 12:36:08 +03:00
|
|
|
*aBounds = aTransform.TransformBounds(bounds);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Float length = Float(NS_hypot(x2 - x1, y2 - y1));
|
|
|
|
Float xDelta;
|
|
|
|
Float yDelta;
|
|
|
|
|
2015-02-03 21:36:32 +03:00
|
|
|
if (aStrokeOptions.mLineCap == CapStyle::BUTT) {
|
2015-01-22 12:36:08 +03:00
|
|
|
if (length == 0.f) {
|
|
|
|
xDelta = yDelta = 0.f;
|
|
|
|
} else {
|
2015-02-03 21:36:32 +03:00
|
|
|
Float ratio = aStrokeOptions.mLineWidth / 2.f / length;
|
2015-01-22 12:36:08 +03:00
|
|
|
xDelta = ratio * (y2 - y1);
|
|
|
|
yDelta = ratio * (x2 - x1);
|
|
|
|
}
|
|
|
|
} else {
|
2015-02-03 21:36:32 +03:00
|
|
|
MOZ_ASSERT(aStrokeOptions.mLineCap == CapStyle::SQUARE);
|
2015-01-22 12:36:08 +03:00
|
|
|
if (length == 0.f) {
|
2015-02-03 21:36:32 +03:00
|
|
|
xDelta = yDelta = aStrokeOptions.mLineWidth / 2.f;
|
2015-01-22 12:36:08 +03:00
|
|
|
} else {
|
2015-02-03 21:36:32 +03:00
|
|
|
Float ratio = aStrokeOptions.mLineWidth / 2.f / length;
|
2015-01-22 12:36:08 +03:00
|
|
|
xDelta = yDelta = ratio * (fabs(y2 - y1) + fabs(x2 - x1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Point points[4];
|
|
|
|
|
|
|
|
points[0] = Point(x1 - xDelta, y1 - yDelta);
|
|
|
|
points[1] = Point(x1 + xDelta, y1 + yDelta);
|
|
|
|
points[2] = Point(x2 + xDelta, y2 + yDelta);
|
|
|
|
points[3] = Point(x2 - xDelta, y2 - yDelta);
|
|
|
|
|
|
|
|
*aBounds = Rect(aTransform * points[0], Size());
|
|
|
|
for (uint32_t i = 1; i < 4; ++i) {
|
|
|
|
aBounds->ExpandToEnclose(aTransform * points[i]);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|