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)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-08-01 11:09:00 +03:00
|
|
|
void
|
|
|
|
SVGLineElement::MaybeAdjustForZeroLength(float aX1, float aY1,
|
|
|
|
float& aX2, float aY2)
|
|
|
|
{
|
|
|
|
if (aX1 == aX2 && aY1 == aY2) {
|
|
|
|
SVGContentUtils::AutoStrokeOptions strokeOptions;
|
|
|
|
SVGContentUtils::GetStrokeOptions(&strokeOptions, this, nullptr, nullptr,
|
|
|
|
SVGContentUtils::eIgnoreStrokeDashing);
|
|
|
|
|
|
|
|
if (strokeOptions.mLineCap != CapStyle::BUTT) {
|
|
|
|
float tinyLength =
|
|
|
|
strokeOptions.mLineWidth / SVG_ZERO_LENGTH_PATH_FIX_FACTOR;
|
|
|
|
aX2 += tinyLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// 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);
|
2015-08-01 11:09:00 +03:00
|
|
|
|
|
|
|
MaybeAdjustForZeroLength(x1, y1, x2, y2);
|
2014-10-22 15:29:05 +04:00
|
|
|
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);
|
|
|
|
|
2015-08-01 11:09:00 +03:00
|
|
|
MaybeAdjustForZeroLength(x1, y1, x2, y2);
|
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-09-01 07:17:00 +03:00
|
|
|
SVGLineElement::GetGeometryBounds(Rect* aBounds,
|
|
|
|
const StrokeOptions& aStrokeOptions,
|
|
|
|
const Matrix& aToBoundsSpace,
|
|
|
|
const Matrix* aToNonScalingStrokeSpace)
|
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-09-01 07:17:00 +03:00
|
|
|
*aBounds = Rect(aToBoundsSpace * Point(x1, y1), Size());
|
|
|
|
aBounds->ExpandToEnclose(aToBoundsSpace * Point(x2, y2));
|
2015-01-22 12:36:08 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-02 21:10:00 +03:00
|
|
|
// transform from non-scaling-stroke space to the space in which we compute
|
|
|
|
// bounds
|
|
|
|
Matrix nonScalingToBounds;
|
|
|
|
if (aToNonScalingStrokeSpace) {
|
2015-09-30 09:05:00 +03:00
|
|
|
MOZ_ASSERT(!aToNonScalingStrokeSpace->IsSingular());
|
2015-09-02 21:10:00 +03:00
|
|
|
Matrix nonScalingToUser = aToNonScalingStrokeSpace->Inverse();
|
|
|
|
nonScalingToBounds = nonScalingToUser * aToBoundsSpace;
|
|
|
|
}
|
|
|
|
|
2015-02-03 21:36:32 +03:00
|
|
|
if (aStrokeOptions.mLineCap == CapStyle::ROUND) {
|
2015-09-02 21:10:00 +03:00
|
|
|
if (!aToBoundsSpace.IsRectilinear() ||
|
|
|
|
(aToNonScalingStrokeSpace &&
|
|
|
|
!aToNonScalingStrokeSpace->IsRectilinear())) {
|
2015-01-22 12:36:08 +03:00
|
|
|
// TODO: handle this case.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Rect bounds(Point(x1, y1), Size());
|
|
|
|
bounds.ExpandToEnclose(Point(x2, y2));
|
2015-09-02 21:10:00 +03:00
|
|
|
if (aToNonScalingStrokeSpace) {
|
|
|
|
bounds = aToNonScalingStrokeSpace->TransformBounds(bounds);
|
|
|
|
bounds.Inflate(aStrokeOptions.mLineWidth / 2.f);
|
|
|
|
*aBounds = nonScalingToBounds.TransformBounds(bounds);
|
|
|
|
} else {
|
|
|
|
bounds.Inflate(aStrokeOptions.mLineWidth / 2.f);
|
|
|
|
*aBounds = aToBoundsSpace.TransformBounds(bounds);
|
|
|
|
}
|
2015-01-22 12:36:08 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-02 21:10:00 +03:00
|
|
|
// Handle butt and square linecap, normal and non-scaling stroke cases
|
|
|
|
// together: start with endpoints (x1, y1), (x2, y2) in the stroke space,
|
|
|
|
// compute the four corners of the stroked line, transform the corners to
|
|
|
|
// bounds space, and compute bounds there.
|
|
|
|
|
|
|
|
if (aToNonScalingStrokeSpace) {
|
|
|
|
Point nonScalingSpaceP1, nonScalingSpaceP2;
|
|
|
|
nonScalingSpaceP1 = *aToNonScalingStrokeSpace * Point(x1, y1);
|
|
|
|
nonScalingSpaceP2 = *aToNonScalingStrokeSpace * Point(x2, y2);
|
|
|
|
x1 = nonScalingSpaceP1.x;
|
|
|
|
y1 = nonScalingSpaceP1.y;
|
|
|
|
x2 = nonScalingSpaceP2.x;
|
|
|
|
y2 = nonScalingSpaceP2.y;
|
|
|
|
}
|
|
|
|
|
2015-01-22 12:36:08 +03:00
|
|
|
Float length = Float(NS_hypot(x2 - x1, y2 - y1));
|
|
|
|
Float xDelta;
|
|
|
|
Float yDelta;
|
2015-09-02 21:10:00 +03:00
|
|
|
Point points[4];
|
2015-01-22 12:36:08 +03:00
|
|
|
|
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);
|
|
|
|
}
|
2015-09-02 21:10:00 +03:00
|
|
|
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);
|
2015-01-22 12:36:08 +03:00
|
|
|
} 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-09-02 21:10:00 +03:00
|
|
|
points[0] = Point(x1 - xDelta, y1 + yDelta);
|
|
|
|
points[1] = Point(x1 - xDelta, y1 - yDelta);
|
|
|
|
points[2] = Point(x1 + xDelta, y1 - yDelta);
|
|
|
|
points[3] = Point(x1 + xDelta, y1 + yDelta);
|
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-09-02 21:10:00 +03:00
|
|
|
yDelta = ratio * (x2 - x1);
|
|
|
|
xDelta = ratio * (y2 - y1);
|
|
|
|
points[0] = Point(x1 - yDelta - xDelta, y1 - xDelta + yDelta);
|
|
|
|
points[1] = Point(x1 - yDelta + xDelta, y1 - xDelta - yDelta);
|
|
|
|
points[2] = Point(x2 + yDelta + xDelta, y2 + xDelta - yDelta);
|
|
|
|
points[3] = Point(x2 + yDelta - xDelta, y2 + xDelta + yDelta);
|
2015-01-22 12:36:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-02 21:10:00 +03:00
|
|
|
const Matrix& toBoundsSpace = aToNonScalingStrokeSpace ?
|
|
|
|
nonScalingToBounds : aToBoundsSpace;
|
2015-01-22 12:36:08 +03:00
|
|
|
|
2015-09-02 21:10:00 +03:00
|
|
|
*aBounds = Rect(toBoundsSpace * points[0], Size());
|
2015-01-22 12:36:08 +03:00
|
|
|
for (uint32_t i = 1; i < 4; ++i) {
|
2015-09-02 21:10:00 +03:00
|
|
|
aBounds->ExpandToEnclose(toBoundsSpace * points[i]);
|
2015-01-22 12:36:08 +03:00
|
|
|
}
|
2015-09-02 21:10:00 +03:00
|
|
|
|
2015-01-22 12:36:08 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|