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:01 +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/SVGRectElement.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "mozilla/dom/SVGRectElementBinding.h"
|
2013-11-02 15:10:38 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-10-26 21:00:03 +03:00
|
|
|
#include "mozilla/gfx/Matrix.h"
|
|
|
|
#include "mozilla/gfx/Rect.h"
|
2013-11-02 15:10:38 +04:00
|
|
|
#include "mozilla/gfx/PathHelpers.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2013-01-06 13:32:01 +04:00
|
|
|
|
|
|
|
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Rect)
|
|
|
|
|
2013-11-02 15:10:38 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2013-01-06 13:32:01 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2013-03-12 02:05:58 +04:00
|
|
|
class SVGAnimatedLength;
|
|
|
|
|
2013-01-06 13:32:01 +04:00
|
|
|
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
|
|
|
SVGRectElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-01-06 13:32:01 +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 SVGRectElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-01-06 13:32:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::LengthInfo SVGRectElement::sLengthInfo[6] =
|
|
|
|
{
|
|
|
|
{ &nsGkAtoms::x, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
|
|
|
|
{ &nsGkAtoms::y, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
|
|
|
|
{ &nsGkAtoms::width, 0, nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
|
|
|
|
{ &nsGkAtoms::height, 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
|
|
|
SVGRectElement::SVGRectElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-01-06 13:32:01 +04:00
|
|
|
: SVGRectElementBase(aNodeInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode methods
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGRectElement)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:01 +04:00
|
|
|
SVGRectElement::X()
|
|
|
|
{
|
2013-01-06 13:32:02 +04:00
|
|
|
return mLengthAttributes[ATTR_X].ToDOMAnimatedLength(this);
|
2013-01-06 13:32:01 +04:00
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:01 +04:00
|
|
|
SVGRectElement::Y()
|
|
|
|
{
|
2013-01-06 13:32:02 +04:00
|
|
|
return mLengthAttributes[ATTR_Y].ToDOMAnimatedLength(this);
|
2013-01-06 13:32:01 +04:00
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:01 +04:00
|
|
|
SVGRectElement::Width()
|
|
|
|
{
|
2013-01-06 13:32:02 +04:00
|
|
|
return mLengthAttributes[ATTR_WIDTH].ToDOMAnimatedLength(this);
|
2013-01-06 13:32:01 +04:00
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:01 +04:00
|
|
|
SVGRectElement::Height()
|
|
|
|
{
|
2013-01-06 13:32:02 +04:00
|
|
|
return mLengthAttributes[ATTR_HEIGHT].ToDOMAnimatedLength(this);
|
2013-01-06 13:32:01 +04:00
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:01 +04:00
|
|
|
SVGRectElement::Rx()
|
|
|
|
{
|
2013-01-06 13:32:02 +04:00
|
|
|
return mLengthAttributes[ATTR_RX].ToDOMAnimatedLength(this);
|
2013-01-06 13:32:01 +04:00
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:01 +04:00
|
|
|
SVGRectElement::Ry()
|
|
|
|
{
|
2013-01-06 13:32:02 +04:00
|
|
|
return mLengthAttributes[ATTR_RY].ToDOMAnimatedLength(this);
|
2013-01-06 13:32:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGElement methods
|
|
|
|
|
|
|
|
/* virtual */ bool
|
|
|
|
SVGRectElement::HasValidDimensions() const
|
|
|
|
{
|
|
|
|
return mLengthAttributes[ATTR_WIDTH].IsExplicitlySet() &&
|
|
|
|
mLengthAttributes[ATTR_WIDTH].GetAnimValInSpecifiedUnits() > 0 &&
|
|
|
|
mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet() &&
|
|
|
|
mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSVGElement::LengthAttributesInfo
|
|
|
|
SVGRectElement::GetLengthInfo()
|
|
|
|
{
|
|
|
|
return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
|
|
|
|
ArrayLength(sLengthInfo));
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-12-18 13:42:51 +03:00
|
|
|
// nsSVGPathGeometryElement methods
|
2013-01-06 13:32:01 +04:00
|
|
|
|
2014-10-26 21:00:03 +03:00
|
|
|
bool
|
2015-09-01 07:17:00 +03:00
|
|
|
SVGRectElement::GetGeometryBounds(Rect* aBounds,
|
|
|
|
const StrokeOptions& aStrokeOptions,
|
|
|
|
const Matrix& aToBoundsSpace,
|
|
|
|
const Matrix* aToNonScalingStrokeSpace)
|
2014-10-26 21:00:03 +03:00
|
|
|
{
|
2014-10-29 20:07:11 +03:00
|
|
|
Rect rect;
|
2014-10-26 21:00:03 +03:00
|
|
|
Float rx, ry;
|
2014-10-29 20:07:11 +03:00
|
|
|
GetAnimatedLengthValues(&rect.x, &rect.y, &rect.width,
|
|
|
|
&rect.height, &rx, &ry, nullptr);
|
2014-10-26 21:00:03 +03:00
|
|
|
|
2014-10-29 20:07:11 +03:00
|
|
|
if (rect.IsEmpty()) {
|
2014-10-26 21:00:03 +03:00
|
|
|
// Rendering of the element disabled
|
2014-10-29 20:07:11 +03:00
|
|
|
rect.SetEmpty(); // Make sure width/height are zero and not negative
|
2015-01-21 16:09:45 +03:00
|
|
|
// We still want the x/y position from 'rect'
|
2015-09-01 07:17:00 +03:00
|
|
|
*aBounds = aToBoundsSpace.TransformBounds(rect);
|
2014-10-26 21:00:03 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-01 07:17:00 +03:00
|
|
|
if (!aToBoundsSpace.IsRectilinear()) {
|
2014-10-29 20:07:11 +03:00
|
|
|
// We can't ignore the radii in this case if we want tight bounds
|
|
|
|
rx = std::max(rx, 0.0f);
|
|
|
|
ry = std::max(ry, 0.0f);
|
2014-10-26 21:00:03 +03:00
|
|
|
|
2014-10-29 20:07:11 +03:00
|
|
|
if (rx != 0 || ry != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-26 21:00:03 +03:00
|
|
|
}
|
|
|
|
|
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 = aToNonScalingStrokeSpace->TransformBounds(rect);
|
|
|
|
// Note that, in principle, an author could cause the corners of the
|
|
|
|
// rect to be beveled by specifying stroke-linejoin or setting
|
|
|
|
// stroke-miterlimit to be less than sqrt(2). In that very unlikely
|
|
|
|
// event the bounds that we calculate here may be too big if
|
|
|
|
// aToBoundsSpace is non-rectilinear. This is likely to be so rare it's
|
|
|
|
// not worth handling though.
|
|
|
|
rect.Inflate(aStrokeOptions.mLineWidth / 2.f);
|
|
|
|
Matrix nonScalingToBounds =
|
|
|
|
aToNonScalingStrokeSpace->Inverse() * aToBoundsSpace;
|
|
|
|
*aBounds = nonScalingToBounds.TransformBounds(rect);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// The "beveled" comment above applies here too
|
2015-02-03 21:36:32 +03:00
|
|
|
rect.Inflate(aStrokeOptions.mLineWidth / 2.f);
|
2014-10-26 21:00:03 +03:00
|
|
|
}
|
|
|
|
|
2015-09-01 07:17:00 +03:00
|
|
|
*aBounds = aToBoundsSpace.TransformBounds(rect);
|
2014-10-26 21:00:03 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-22 15:29:05 +04:00
|
|
|
void
|
|
|
|
SVGRectElement::GetAsSimplePath(SimplePath* aSimplePath)
|
|
|
|
{
|
|
|
|
float x, y, width, height, rx, ry;
|
|
|
|
GetAnimatedLengthValues(&x, &y, &width, &height, &rx, &ry, nullptr);
|
|
|
|
|
|
|
|
if (width <= 0 || height <= 0) {
|
|
|
|
aSimplePath->Reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rx = std::max(rx, 0.0f);
|
|
|
|
ry = std::max(ry, 0.0f);
|
|
|
|
|
|
|
|
if (rx != 0 || ry != 0) {
|
|
|
|
aSimplePath->Reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aSimplePath->SetRect(x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<Path>
|
2014-07-06 00:53:04 +04:00
|
|
|
SVGRectElement::BuildPath(PathBuilder* aBuilder)
|
2013-11-02 15:10:38 +04:00
|
|
|
{
|
|
|
|
float x, y, width, height, rx, ry;
|
|
|
|
GetAnimatedLengthValues(&x, &y, &width, &height, &rx, &ry, nullptr);
|
|
|
|
|
2013-11-06 14:05:18 +04:00
|
|
|
if (width <= 0 || height <= 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
rx = std::max(rx, 0.0f);
|
|
|
|
ry = std::max(ry, 0.0f);
|
|
|
|
|
|
|
|
if (rx == 0 && ry == 0) {
|
|
|
|
// Optimization for the no rounded corners case.
|
|
|
|
Rect r(x, y, width, height);
|
2014-10-04 15:13:30 +04:00
|
|
|
aBuilder->MoveTo(r.TopLeft());
|
|
|
|
aBuilder->LineTo(r.TopRight());
|
|
|
|
aBuilder->LineTo(r.BottomRight());
|
|
|
|
aBuilder->LineTo(r.BottomLeft());
|
|
|
|
aBuilder->Close();
|
2013-11-06 14:05:18 +04:00
|
|
|
} else {
|
|
|
|
// If either the 'rx' or the 'ry' attribute isn't set, then we have to
|
|
|
|
// set it to the value of the other:
|
|
|
|
bool hasRx = mLengthAttributes[ATTR_RX].IsExplicitlySet();
|
|
|
|
bool hasRy = mLengthAttributes[ATTR_RY].IsExplicitlySet();
|
|
|
|
MOZ_ASSERT(hasRx || hasRy);
|
|
|
|
|
|
|
|
if (hasRx && !hasRy) {
|
|
|
|
ry = rx;
|
|
|
|
} else if (hasRy && !hasRx) {
|
|
|
|
rx = ry;
|
2013-11-02 15:10:38 +04:00
|
|
|
}
|
2013-11-06 14:05:18 +04:00
|
|
|
|
|
|
|
// Clamp rx and ry to half the rect's width and height respectively:
|
|
|
|
rx = std::min(rx, width / 2);
|
|
|
|
ry = std::min(ry, height / 2);
|
|
|
|
|
2014-10-30 12:34:10 +03:00
|
|
|
RectCornerRadii radii(rx, ry);
|
2014-10-04 15:13:30 +04:00
|
|
|
AppendRoundedRectToPath(aBuilder, Rect(x, y, width, height), radii);
|
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
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:01 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|