mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 21:28:55 +00:00
Bug 1551030 - Merge all SVGRect classes r=dholbert
This commit is contained in:
parent
8ea522bf4e
commit
160c161d5f
@ -1005,10 +1005,6 @@ DOMInterfaces = {
|
||||
'headerFile': 'mozilla/dom/SVGGradientElement.h',
|
||||
},
|
||||
|
||||
'SVGRect': {
|
||||
'nativeType': 'mozilla::dom::SVGIRect'
|
||||
},
|
||||
|
||||
'SVGStringList': {
|
||||
'nativeType': 'mozilla::DOMSVGStringList',
|
||||
'headerFile': 'DOMSVGStringList.h',
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include "SVGAnimatedRect.h"
|
||||
#include "mozilla/dom/SVGAnimatedRectBinding.h"
|
||||
#include "mozilla/dom/SVGElement.h"
|
||||
#include "mozilla/dom/SVGRect.h"
|
||||
#include "SVGAnimatedViewBox.h"
|
||||
#include "SVGIRect.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@ -26,11 +26,11 @@ SVGAnimatedRect::~SVGAnimatedRect() {
|
||||
SVGAnimatedViewBox::sSVGAnimatedRectTearoffTable.RemoveTearoff(mVal);
|
||||
}
|
||||
|
||||
already_AddRefed<SVGIRect> SVGAnimatedRect::GetBaseVal() {
|
||||
already_AddRefed<SVGRect> SVGAnimatedRect::GetBaseVal() {
|
||||
return mVal->ToDOMBaseVal(mSVGElement);
|
||||
}
|
||||
|
||||
already_AddRefed<SVGIRect> SVGAnimatedRect::GetAnimVal() {
|
||||
already_AddRefed<SVGRect> SVGAnimatedRect::GetAnimVal() {
|
||||
return mVal->ToDOMAnimVal(mSVGElement);
|
||||
}
|
||||
|
||||
|
@ -9,15 +9,21 @@
|
||||
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "mozilla/dom/SVGElement.h"
|
||||
#include "mozilla/dom/SVGRectBinding.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class SVGAnimatedViewBox;
|
||||
|
||||
namespace dom {
|
||||
|
||||
class SVGRect;
|
||||
|
||||
// Despite the name of this class appearing to be generic,
|
||||
// SVGAnimatedRect is only used for viewBox attributes.
|
||||
|
||||
class SVGAnimatedRect final : public nsWrapperCache {
|
||||
public:
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(SVGAnimatedRect)
|
||||
@ -30,9 +36,9 @@ class SVGAnimatedRect final : public nsWrapperCache {
|
||||
virtual JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
already_AddRefed<SVGIRect> GetBaseVal();
|
||||
already_AddRefed<SVGRect> GetBaseVal();
|
||||
|
||||
already_AddRefed<SVGIRect> GetAnimVal();
|
||||
already_AddRefed<SVGRect> GetAnimVal();
|
||||
|
||||
private:
|
||||
virtual ~SVGAnimatedRect();
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "mozilla/Move.h"
|
||||
#include "mozilla/SMILValue.h"
|
||||
#include "mozilla/SVGContentUtils.h"
|
||||
#include "mozilla/dom/SVGRect.h"
|
||||
#include "nsCharSeparatedTokenizer.h"
|
||||
#include "SVGViewBoxSMILType.h"
|
||||
#include "nsTextFormatter.h"
|
||||
@ -61,32 +62,9 @@ nsresult SVGViewBox::FromString(const nsAString& aStr, SVGViewBox* aViewBox) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* Cycle collection macros for SVGAnimatedViewBox */
|
||||
|
||||
NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(SVGAnimatedViewBox::DOMBaseVal,
|
||||
mSVGElement)
|
||||
NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(SVGAnimatedViewBox::DOMAnimVal,
|
||||
mSVGElement)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(SVGAnimatedViewBox::DOMBaseVal)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(SVGAnimatedViewBox::DOMBaseVal)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(SVGAnimatedViewBox::DOMAnimVal)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(SVGAnimatedViewBox::DOMAnimVal)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGAnimatedViewBox::DOMBaseVal)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGAnimatedViewBox::DOMAnimVal)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
static SVGAttrTearoffTable<SVGAnimatedViewBox, SVGAnimatedViewBox::DOMBaseVal>
|
||||
static SVGAttrTearoffTable<SVGAnimatedViewBox, SVGRect>
|
||||
sBaseSVGViewBoxTearoffTable;
|
||||
static SVGAttrTearoffTable<SVGAnimatedViewBox, SVGAnimatedViewBox::DOMAnimVal>
|
||||
static SVGAttrTearoffTable<SVGAnimatedViewBox, SVGRect>
|
||||
sAnimSVGViewBoxTearoffTable;
|
||||
SVGAttrTearoffTable<SVGAnimatedViewBox, SVGAnimatedRect>
|
||||
SVGAnimatedViewBox::sSVGAnimatedRectTearoffTable;
|
||||
@ -206,70 +184,45 @@ already_AddRefed<SVGAnimatedRect> SVGAnimatedViewBox::ToSVGAnimatedRect(
|
||||
return domAnimatedRect.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<SVGIRect> SVGAnimatedViewBox::ToDOMBaseVal(
|
||||
already_AddRefed<SVGRect> SVGAnimatedViewBox::ToDOMBaseVal(
|
||||
SVGElement* aSVGElement) {
|
||||
if (!mHasBaseVal || mBaseVal.none) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<DOMBaseVal> domBaseVal = sBaseSVGViewBoxTearoffTable.GetTearoff(this);
|
||||
RefPtr<SVGRect> domBaseVal = sBaseSVGViewBoxTearoffTable.GetTearoff(this);
|
||||
if (!domBaseVal) {
|
||||
domBaseVal = new DOMBaseVal(this, aSVGElement);
|
||||
domBaseVal = new SVGRect(this, aSVGElement, SVGRect::BaseValue);
|
||||
sBaseSVGViewBoxTearoffTable.AddTearoff(this, domBaseVal);
|
||||
}
|
||||
|
||||
return domBaseVal.forget();
|
||||
}
|
||||
|
||||
SVGAnimatedViewBox::DOMBaseVal::~DOMBaseVal() {
|
||||
sBaseSVGViewBoxTearoffTable.RemoveTearoff(mVal);
|
||||
SVGRect::~SVGRect() {
|
||||
if (mType == BaseValue) {
|
||||
sBaseSVGViewBoxTearoffTable.RemoveTearoff(mVal);
|
||||
} else if (mType == AnimValue) {
|
||||
sAnimSVGViewBoxTearoffTable.RemoveTearoff(mVal);
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<SVGIRect> SVGAnimatedViewBox::ToDOMAnimVal(
|
||||
already_AddRefed<SVGRect> SVGAnimatedViewBox::ToDOMAnimVal(
|
||||
SVGElement* aSVGElement) {
|
||||
if ((mAnimVal && mAnimVal->none) ||
|
||||
(!mAnimVal && (!mHasBaseVal || mBaseVal.none))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<DOMAnimVal> domAnimVal = sAnimSVGViewBoxTearoffTable.GetTearoff(this);
|
||||
RefPtr<SVGRect> domAnimVal = sAnimSVGViewBoxTearoffTable.GetTearoff(this);
|
||||
if (!domAnimVal) {
|
||||
domAnimVal = new DOMAnimVal(this, aSVGElement);
|
||||
domAnimVal = new SVGRect(this, aSVGElement, SVGRect::AnimValue);
|
||||
sAnimSVGViewBoxTearoffTable.AddTearoff(this, domAnimVal);
|
||||
}
|
||||
|
||||
return domAnimVal.forget();
|
||||
}
|
||||
|
||||
SVGAnimatedViewBox::DOMAnimVal::~DOMAnimVal() {
|
||||
sAnimSVGViewBoxTearoffTable.RemoveTearoff(mVal);
|
||||
}
|
||||
|
||||
void SVGAnimatedViewBox::DOMBaseVal::SetX(float aX, ErrorResult& aRv) {
|
||||
SVGViewBox rect = mVal->GetBaseValue();
|
||||
rect.x = aX;
|
||||
mVal->SetBaseValue(rect, mSVGElement);
|
||||
}
|
||||
|
||||
void SVGAnimatedViewBox::DOMBaseVal::SetY(float aY, ErrorResult& aRv) {
|
||||
SVGViewBox rect = mVal->GetBaseValue();
|
||||
rect.y = aY;
|
||||
mVal->SetBaseValue(rect, mSVGElement);
|
||||
}
|
||||
|
||||
void SVGAnimatedViewBox::DOMBaseVal::SetWidth(float aWidth, ErrorResult& aRv) {
|
||||
SVGViewBox rect = mVal->GetBaseValue();
|
||||
rect.width = aWidth;
|
||||
mVal->SetBaseValue(rect, mSVGElement);
|
||||
}
|
||||
|
||||
void SVGAnimatedViewBox::DOMBaseVal::SetHeight(float aHeight,
|
||||
ErrorResult& aRv) {
|
||||
SVGViewBox rect = mVal->GetBaseValue();
|
||||
rect.height = aHeight;
|
||||
mVal->SetBaseValue(rect, mSVGElement);
|
||||
}
|
||||
|
||||
UniquePtr<SMILAttr> SVGAnimatedViewBox::ToSMILAttr(SVGElement* aSVGElement) {
|
||||
return MakeUnique<SMILViewBox>(this, aSVGElement);
|
||||
}
|
||||
|
@ -15,13 +15,13 @@
|
||||
#include "mozilla/SMILAttr.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "mozilla/dom/SVGAnimatedRect.h"
|
||||
#include "mozilla/dom/SVGIRect.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class SMILValue;
|
||||
|
||||
namespace dom {
|
||||
class SVGRect;
|
||||
class SVGAnimationElement;
|
||||
class SVGElement;
|
||||
} // namespace dom
|
||||
@ -80,11 +80,9 @@ class SVGAnimatedViewBox {
|
||||
already_AddRefed<mozilla::dom::SVGAnimatedRect> ToSVGAnimatedRect(
|
||||
SVGElement* aSVGElement);
|
||||
|
||||
already_AddRefed<mozilla::dom::SVGIRect> ToDOMBaseVal(
|
||||
SVGElement* aSVGElement);
|
||||
already_AddRefed<dom::SVGRect> ToDOMBaseVal(SVGElement* aSVGElement);
|
||||
|
||||
already_AddRefed<mozilla::dom::SVGIRect> ToDOMAnimVal(
|
||||
SVGElement* aSVGElement);
|
||||
already_AddRefed<dom::SVGRect> ToDOMAnimVal(SVGElement* aSVGElement);
|
||||
|
||||
mozilla::UniquePtr<SMILAttr> ToSMILAttr(SVGElement* aSVGElement);
|
||||
|
||||
@ -94,89 +92,6 @@ class SVGAnimatedViewBox {
|
||||
bool mHasBaseVal;
|
||||
|
||||
public:
|
||||
struct DOMBaseVal final : public mozilla::dom::SVGIRect {
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMBaseVal)
|
||||
|
||||
DOMBaseVal(SVGAnimatedViewBox* aVal, SVGElement* aSVGElement)
|
||||
: mozilla::dom::SVGIRect(), mVal(aVal), mSVGElement(aSVGElement) {}
|
||||
|
||||
SVGAnimatedViewBox* mVal; // kept alive because it belongs to content
|
||||
RefPtr<SVGElement> mSVGElement;
|
||||
|
||||
float X() const final { return mVal->GetBaseValue().x; }
|
||||
|
||||
float Y() const final { return mVal->GetBaseValue().y; }
|
||||
|
||||
float Width() const final { return mVal->GetBaseValue().width; }
|
||||
|
||||
float Height() const final { return mVal->GetBaseValue().height; }
|
||||
|
||||
void SetX(float aX, mozilla::ErrorResult& aRv) final;
|
||||
void SetY(float aY, mozilla::ErrorResult& aRv) final;
|
||||
void SetWidth(float aWidth, mozilla::ErrorResult& aRv) final;
|
||||
void SetHeight(float aHeight, mozilla::ErrorResult& aRv) final;
|
||||
|
||||
virtual nsIContent* GetParentObject() const override { return mSVGElement; }
|
||||
|
||||
private:
|
||||
virtual ~DOMBaseVal();
|
||||
};
|
||||
|
||||
struct DOMAnimVal final : public mozilla::dom::SVGIRect {
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMAnimVal)
|
||||
|
||||
DOMAnimVal(SVGAnimatedViewBox* aVal, SVGElement* aSVGElement)
|
||||
: mozilla::dom::SVGIRect(), mVal(aVal), mSVGElement(aSVGElement) {}
|
||||
|
||||
SVGAnimatedViewBox* mVal; // kept alive because it belongs to content
|
||||
RefPtr<SVGElement> mSVGElement;
|
||||
|
||||
// Script may have modified animation parameters or timeline -- DOM getters
|
||||
// need to flush any resample requests to reflect these modifications.
|
||||
float X() const final {
|
||||
mSVGElement->FlushAnimations();
|
||||
return mVal->GetAnimValue().x;
|
||||
}
|
||||
|
||||
float Y() const final {
|
||||
mSVGElement->FlushAnimations();
|
||||
return mVal->GetAnimValue().y;
|
||||
}
|
||||
|
||||
float Width() const final {
|
||||
mSVGElement->FlushAnimations();
|
||||
return mVal->GetAnimValue().width;
|
||||
}
|
||||
|
||||
float Height() const final {
|
||||
mSVGElement->FlushAnimations();
|
||||
return mVal->GetAnimValue().height;
|
||||
}
|
||||
|
||||
void SetX(float aX, mozilla::ErrorResult& aRv) final {
|
||||
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
||||
}
|
||||
|
||||
void SetY(float aY, mozilla::ErrorResult& aRv) final {
|
||||
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
||||
}
|
||||
|
||||
void SetWidth(float aWidth, mozilla::ErrorResult& aRv) final {
|
||||
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
||||
}
|
||||
|
||||
void SetHeight(float aHeight, mozilla::ErrorResult& aRv) final {
|
||||
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
||||
}
|
||||
|
||||
virtual nsIContent* GetParentObject() const override { return mSVGElement; }
|
||||
|
||||
private:
|
||||
virtual ~DOMAnimVal();
|
||||
};
|
||||
|
||||
struct SMILViewBox : public SMILAttr {
|
||||
public:
|
||||
SMILViewBox(SVGAnimatedViewBox* aVal, SVGElement* aSVGElement)
|
||||
|
@ -1,52 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* 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/. */
|
||||
|
||||
#ifndef mozilla_dom_SVGIRect_h
|
||||
#define mozilla_dom_SVGIRect_h
|
||||
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "mozilla/dom/SVGRectBinding.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
class nsIContent;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class SVGIRect : public nsISupports, public nsWrapperCache {
|
||||
public:
|
||||
virtual ~SVGIRect() = default;
|
||||
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override {
|
||||
return SVGRect_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
virtual nsIContent* GetParentObject() const = 0;
|
||||
|
||||
virtual float X() const = 0;
|
||||
|
||||
virtual void SetX(float aX, ErrorResult& aRv) = 0;
|
||||
|
||||
virtual float Y() const = 0;
|
||||
|
||||
virtual void SetY(float aY, ErrorResult& aRv) = 0;
|
||||
|
||||
virtual float Width() const = 0;
|
||||
|
||||
virtual void SetWidth(float aWidth, ErrorResult& aRv) = 0;
|
||||
|
||||
virtual float Height() const = 0;
|
||||
|
||||
virtual void SetHeight(float aHeight, ErrorResult& aRv) = 0;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_SVGIRect_h
|
@ -5,19 +5,17 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/dom/SVGRect.h"
|
||||
#include "SVGElement.h"
|
||||
|
||||
#include "mozilla/dom/SVGRectBinding.h"
|
||||
#include "mozilla/dom/SVGSVGElement.h"
|
||||
#include "SVGAnimatedViewBox.h"
|
||||
#include "nsWrapperCache.h"
|
||||
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// implementation:
|
||||
|
||||
SVGRect::SVGRect(nsIContent* aParent, float x, float y, float w, float h)
|
||||
: SVGIRect(), mParent(aParent), mX(x), mY(y), mWidth(w), mHeight(h) {}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// nsISupports methods:
|
||||
|
||||
@ -31,23 +29,132 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGRect)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// implementation:
|
||||
|
||||
SVGRect::SVGRect(SVGSVGElement* aSVGElement)
|
||||
: mVal(nullptr), mParent(aSVGElement), mType(CreatedValue) {
|
||||
MOZ_ASSERT(mParent);
|
||||
mRect = gfx::Rect(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
JSObject* SVGRect::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) {
|
||||
MOZ_ASSERT(mParent);
|
||||
return SVGRect_Binding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
float SVGRect::X() {
|
||||
switch (mType) {
|
||||
case AnimValue:
|
||||
static_cast<SVGElement*>(mParent->AsElement())->FlushAnimations();
|
||||
return mVal->GetAnimValue().x;
|
||||
case BaseValue:
|
||||
return mVal->GetBaseValue().x;
|
||||
default:
|
||||
return mRect.x;
|
||||
}
|
||||
}
|
||||
|
||||
float SVGRect::Y() {
|
||||
switch (mType) {
|
||||
case AnimValue:
|
||||
static_cast<SVGElement*>(mParent->AsElement())->FlushAnimations();
|
||||
return mVal->GetAnimValue().y;
|
||||
case BaseValue:
|
||||
return mVal->GetBaseValue().y;
|
||||
default:
|
||||
return mRect.y;
|
||||
}
|
||||
}
|
||||
|
||||
float SVGRect::Width() {
|
||||
switch (mType) {
|
||||
case AnimValue:
|
||||
static_cast<SVGElement*>(mParent->AsElement())->FlushAnimations();
|
||||
return mVal->GetAnimValue().width;
|
||||
case BaseValue:
|
||||
return mVal->GetBaseValue().width;
|
||||
default:
|
||||
return mRect.width;
|
||||
}
|
||||
}
|
||||
|
||||
float SVGRect::Height() {
|
||||
switch (mType) {
|
||||
case AnimValue:
|
||||
static_cast<SVGElement*>(mParent->AsElement())->FlushAnimations();
|
||||
return mVal->GetAnimValue().height;
|
||||
case BaseValue:
|
||||
return mVal->GetBaseValue().height;
|
||||
default:
|
||||
return mRect.height;
|
||||
}
|
||||
}
|
||||
|
||||
void SVGRect::SetX(float aX, ErrorResult& aRv) {
|
||||
switch (mType) {
|
||||
case AnimValue:
|
||||
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
||||
return;
|
||||
case BaseValue: {
|
||||
SVGViewBox rect = mVal->GetBaseValue();
|
||||
rect.x = aX;
|
||||
mVal->SetBaseValue(rect, static_cast<SVGElement*>(mParent->AsElement()));
|
||||
return;
|
||||
}
|
||||
default:
|
||||
mRect.x = aX;
|
||||
}
|
||||
}
|
||||
|
||||
void SVGRect::SetY(float aY, ErrorResult& aRv) {
|
||||
switch (mType) {
|
||||
case AnimValue:
|
||||
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
||||
return;
|
||||
case BaseValue: {
|
||||
SVGViewBox rect = mVal->GetBaseValue();
|
||||
rect.y = aY;
|
||||
mVal->SetBaseValue(rect, static_cast<SVGElement*>(mParent->AsElement()));
|
||||
return;
|
||||
}
|
||||
default:
|
||||
mRect.y = aY;
|
||||
}
|
||||
}
|
||||
|
||||
void SVGRect::SetWidth(float aWidth, ErrorResult& aRv) {
|
||||
switch (mType) {
|
||||
case AnimValue:
|
||||
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
||||
return;
|
||||
case BaseValue: {
|
||||
SVGViewBox rect = mVal->GetBaseValue();
|
||||
rect.width = aWidth;
|
||||
mVal->SetBaseValue(rect, static_cast<SVGElement*>(mParent->AsElement()));
|
||||
return;
|
||||
}
|
||||
default:
|
||||
mRect.width = aWidth;
|
||||
}
|
||||
}
|
||||
|
||||
void SVGRect::SetHeight(float aHeight, ErrorResult& aRv) {
|
||||
switch (mType) {
|
||||
case AnimValue:
|
||||
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
||||
return;
|
||||
case BaseValue: {
|
||||
SVGViewBox rect = mVal->GetBaseValue();
|
||||
rect.height = aHeight;
|
||||
mVal->SetBaseValue(rect, static_cast<SVGElement*>(mParent->AsElement()));
|
||||
return;
|
||||
}
|
||||
default:
|
||||
mRect.height = aHeight;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Exported creation functions:
|
||||
|
||||
already_AddRefed<mozilla::dom::SVGRect> NS_NewSVGRect(nsIContent* aParent,
|
||||
float aX, float aY,
|
||||
float aWidth,
|
||||
float aHeight) {
|
||||
RefPtr<mozilla::dom::SVGRect> rect =
|
||||
new mozilla::dom::SVGRect(aParent, aX, aY, aWidth, aHeight);
|
||||
|
||||
return rect.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<mozilla::dom::SVGRect> NS_NewSVGRect(nsIContent* aParent,
|
||||
const Rect& aRect) {
|
||||
return NS_NewSVGRect(aParent, aRect.x, aRect.y, aRect.width, aRect.height);
|
||||
}
|
||||
|
@ -7,10 +7,8 @@
|
||||
#ifndef mozilla_dom_SVGRect_h
|
||||
#define mozilla_dom_SVGRect_h
|
||||
|
||||
#include "mozilla/dom/SVGIRect.h"
|
||||
#include "mozilla/dom/SVGElement.h"
|
||||
#include "mozilla/gfx/Rect.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "SVGElement.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// SVGRect class
|
||||
@ -18,50 +16,71 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class SVGRect final : public SVGIRect {
|
||||
class SVGSVGElement;
|
||||
|
||||
class SVGRect final : public nsISupports, public nsWrapperCache {
|
||||
public:
|
||||
explicit SVGRect(nsIContent* aParent, float x = 0.0f, float y = 0.0f,
|
||||
float w = 0.0f, float h = 0.0f);
|
||||
typedef enum { BaseValue, AnimValue, CreatedValue } RectType;
|
||||
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(SVGRect)
|
||||
|
||||
// WebIDL
|
||||
float X() const final { return mX; }
|
||||
/**
|
||||
* Generic ctor for objects that are created for an attribute.
|
||||
*/
|
||||
SVGRect(SVGAnimatedViewBox* aVal, SVGElement* aSVGElement, RectType aType)
|
||||
: mVal(aVal), mParent(aSVGElement), mType(aType) {
|
||||
MOZ_ASSERT(mParent);
|
||||
MOZ_ASSERT(mType == BaseValue || mType == AnimValue);
|
||||
}
|
||||
|
||||
void SetX(float aX, ErrorResult& aRv) final { mX = aX; }
|
||||
/**
|
||||
* Ctor for creating the objects returned by SVGSVGElement.createSVGRect(),
|
||||
* which do not initially belong to an attribute.
|
||||
*/
|
||||
explicit SVGRect(SVGSVGElement* aSVGElement);
|
||||
|
||||
float Y() const final { return mY; }
|
||||
/**
|
||||
* Ctor for all other non-attribute usage i.e getBBox, getExtentOfChar etc.
|
||||
*/
|
||||
SVGRect(nsIContent* aParent, const gfx::Rect& aRect)
|
||||
: mVal(nullptr), mRect(aRect), mParent(aParent), mType(CreatedValue) {
|
||||
MOZ_ASSERT(mParent);
|
||||
}
|
||||
|
||||
void SetY(float aY, ErrorResult& aRv) final { mY = aY; }
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
float Width() const final { return mWidth; }
|
||||
float X();
|
||||
float Y();
|
||||
float Width();
|
||||
float Height();
|
||||
|
||||
void SetWidth(float aWidth, ErrorResult& aRv) final { mWidth = aWidth; }
|
||||
void SetX(float aX, mozilla::ErrorResult& aRv);
|
||||
void SetY(float aY, mozilla::ErrorResult& aRv);
|
||||
void SetWidth(float aWidth, mozilla::ErrorResult& aRv);
|
||||
void SetHeight(float aHeight, mozilla::ErrorResult& aRv);
|
||||
|
||||
float Height() const final { return mHeight; }
|
||||
nsIContent* GetParentObject() const {
|
||||
MOZ_ASSERT(mParent);
|
||||
return mParent;
|
||||
}
|
||||
|
||||
void SetHeight(float aHeight, ErrorResult& aRv) final { mHeight = aHeight; }
|
||||
private:
|
||||
virtual ~SVGRect();
|
||||
|
||||
virtual nsIContent* GetParentObject() const override { return mParent; }
|
||||
// If we're actually representing a viewBox rect then our value
|
||||
// will come from that element's viewBox attribute's value.
|
||||
SVGAnimatedViewBox* mVal; // kept alive because it belongs to content
|
||||
gfx::Rect mRect;
|
||||
|
||||
protected:
|
||||
~SVGRect() = default;
|
||||
|
||||
nsCOMPtr<nsIContent> mParent;
|
||||
float mX, mY, mWidth, mHeight;
|
||||
// If mType is AnimValue or BaseValue this will be an element that
|
||||
// has a viewBox, otherwise it could be any nsIContent.
|
||||
RefPtr<nsIContent> mParent;
|
||||
const RectType mType;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
already_AddRefed<mozilla::dom::SVGRect> NS_NewSVGRect(nsIContent* aParent,
|
||||
float x = 0.0f,
|
||||
float y = 0.0f,
|
||||
float width = 0.0f,
|
||||
float height = 0.0f);
|
||||
|
||||
already_AddRefed<mozilla::dom::SVGRect> NS_NewSVGRect(
|
||||
nsIContent* aParent, const mozilla::gfx::Rect& rect);
|
||||
|
||||
#endif // mozilla_dom_SVGRect_h
|
||||
|
@ -270,8 +270,8 @@ already_AddRefed<SVGMatrix> SVGSVGElement::CreateSVGMatrix() {
|
||||
return do_AddRef(new SVGMatrix());
|
||||
}
|
||||
|
||||
already_AddRefed<SVGIRect> SVGSVGElement::CreateSVGRect() {
|
||||
return NS_NewSVGRect(this);
|
||||
already_AddRefed<SVGRect> SVGSVGElement::CreateSVGRect() {
|
||||
return do_AddRef(new SVGRect(this));
|
||||
}
|
||||
|
||||
already_AddRefed<DOMSVGTransform> SVGSVGElement::CreateSVGTransform() {
|
||||
|
@ -25,7 +25,7 @@ class DOMSVGAngle;
|
||||
class DOMSVGLength;
|
||||
class DOMSVGNumber;
|
||||
class SVGMatrix;
|
||||
class SVGIRect;
|
||||
class SVGRect;
|
||||
class SVGSVGElement;
|
||||
|
||||
// Stores svgView arguments of SVG fragment identifiers.
|
||||
@ -137,7 +137,7 @@ class SVGSVGElement final : public SVGSVGElementBase {
|
||||
already_AddRefed<DOMSVGAngle> CreateSVGAngle();
|
||||
already_AddRefed<nsISVGPoint> CreateSVGPoint();
|
||||
already_AddRefed<SVGMatrix> CreateSVGMatrix();
|
||||
already_AddRefed<SVGIRect> CreateSVGRect();
|
||||
already_AddRefed<SVGRect> CreateSVGRect();
|
||||
already_AddRefed<DOMSVGTransform> CreateSVGTransform();
|
||||
already_AddRefed<DOMSVGTransform> CreateSVGTransformFromMatrix(
|
||||
SVGMatrix& matrix);
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include "mozilla/dom/SVGLengthBinding.h"
|
||||
#include "mozilla/dom/SVGTextContentElementBinding.h"
|
||||
#include "mozilla/dom/SVGIRect.h"
|
||||
#include "mozilla/dom/SVGRect.h"
|
||||
#include "nsBidiUtils.h"
|
||||
#include "nsISVGPoint.h"
|
||||
#include "nsTextFragment.h"
|
||||
@ -163,7 +163,7 @@ already_AddRefed<nsISVGPoint> SVGTextContentElement::GetEndPositionOfChar(
|
||||
return point.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<SVGIRect> SVGTextContentElement::GetExtentOfChar(
|
||||
already_AddRefed<SVGRect> SVGTextContentElement::GetExtentOfChar(
|
||||
uint32_t charnum, ErrorResult& rv) {
|
||||
SVGTextFrame* textFrame = GetSVGTextFrame();
|
||||
|
||||
@ -172,7 +172,7 @@ already_AddRefed<SVGIRect> SVGTextContentElement::GetExtentOfChar(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<SVGIRect> rect;
|
||||
RefPtr<SVGRect> rect;
|
||||
rv = textFrame->GetExtentOfChar(this, charnum, getter_AddRefs(rect));
|
||||
return rect.forget();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class nsISVGPoint;
|
||||
namespace dom {
|
||||
|
||||
struct DOMPointInit;
|
||||
class SVGIRect;
|
||||
class SVGRect;
|
||||
|
||||
typedef SVGGraphicsElement SVGTextContentElementBase;
|
||||
|
||||
@ -46,7 +46,7 @@ class SVGTextContentElement : public SVGTextContentElementBase {
|
||||
already_AddRefed<nsISVGPoint> GetEndPositionOfChar(uint32_t charnum,
|
||||
ErrorResult& rv);
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
already_AddRefed<SVGIRect> GetExtentOfChar(uint32_t charnum, ErrorResult& rv);
|
||||
already_AddRefed<SVGRect> GetExtentOfChar(uint32_t charnum, ErrorResult& rv);
|
||||
MOZ_CAN_RUN_SCRIPT float GetRotationOfChar(uint32_t charnum, ErrorResult& rv);
|
||||
MOZ_CAN_RUN_SCRIPT int32_t GetCharNumAtPosition(const DOMPointInit& aPoint);
|
||||
|
||||
|
@ -156,7 +156,7 @@ SVGElement* SVGTransformableElement::GetFarthestViewportElement() {
|
||||
return SVGContentUtils::GetOuterSVGElement(this);
|
||||
}
|
||||
|
||||
already_AddRefed<SVGIRect> SVGTransformableElement::GetBBox(
|
||||
already_AddRefed<SVGRect> SVGTransformableElement::GetBBox(
|
||||
const SVGBoundingBoxOptions& aOptions, ErrorResult& rv) {
|
||||
nsIFrame* frame = GetPrimaryFrame(FlushType::Layout);
|
||||
|
||||
@ -199,14 +199,14 @@ already_AddRefed<SVGIRect> SVGTransformableElement::GetBBox(
|
||||
rec.x += float(text->GetPosition().x) / AppUnitsPerCSSPixel();
|
||||
rec.y += float(text->GetPosition().y) / AppUnitsPerCSSPixel();
|
||||
|
||||
return NS_NewSVGRect(this, ToRect(rec));
|
||||
return do_AddRef(new SVGRect(this, ToRect(rec)));
|
||||
}
|
||||
|
||||
if (!NS_SVGNewGetBBoxEnabled()) {
|
||||
return NS_NewSVGRect(
|
||||
return do_AddRef(new SVGRect(
|
||||
this, ToRect(nsSVGUtils::GetBBox(
|
||||
frame, nsSVGUtils::eBBoxIncludeFillGeometry |
|
||||
nsSVGUtils::eUseUserSpaceOfUseElement)));
|
||||
nsSVGUtils::eUseUserSpaceOfUseElement))));
|
||||
}
|
||||
uint32_t flags = 0;
|
||||
if (aOptions.mFill) {
|
||||
@ -222,14 +222,15 @@ already_AddRefed<SVGIRect> SVGTransformableElement::GetBBox(
|
||||
flags |= nsSVGUtils::eBBoxIncludeClipped;
|
||||
}
|
||||
if (flags == 0) {
|
||||
return NS_NewSVGRect(this, 0, 0, 0, 0);
|
||||
return do_AddRef(new SVGRect(this, gfx::Rect()));
|
||||
}
|
||||
if (flags == nsSVGUtils::eBBoxIncludeMarkers ||
|
||||
flags == nsSVGUtils::eBBoxIncludeClipped) {
|
||||
flags |= nsSVGUtils::eBBoxIncludeFill;
|
||||
}
|
||||
flags |= nsSVGUtils::eUseUserSpaceOfUseElement;
|
||||
return NS_NewSVGRect(this, ToRect(nsSVGUtils::GetBBox(frame, flags)));
|
||||
return do_AddRef(
|
||||
new SVGRect(this, ToRect(nsSVGUtils::GetBBox(frame, flags))));
|
||||
}
|
||||
|
||||
already_AddRefed<SVGMatrix> SVGTransformableElement::GetCTM() {
|
||||
|
@ -20,7 +20,7 @@ namespace dom {
|
||||
class DOMSVGAnimatedTransformList;
|
||||
class SVGGraphicsElement;
|
||||
class SVGMatrix;
|
||||
class SVGIRect;
|
||||
class SVGRect;
|
||||
struct SVGBoundingBoxOptions;
|
||||
|
||||
class SVGTransformableElement : public SVGElement {
|
||||
@ -36,8 +36,8 @@ class SVGTransformableElement : public SVGElement {
|
||||
SVGElement* GetNearestViewportElement();
|
||||
SVGElement* GetFarthestViewportElement();
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
already_AddRefed<SVGIRect> GetBBox(const SVGBoundingBoxOptions& aOptions,
|
||||
ErrorResult& rv);
|
||||
already_AddRefed<SVGRect> GetBBox(const SVGBoundingBoxOptions& aOptions,
|
||||
ErrorResult& rv);
|
||||
already_AddRefed<SVGMatrix> GetCTM();
|
||||
already_AddRefed<SVGMatrix> GetScreenCTM();
|
||||
already_AddRefed<SVGMatrix> GetTransformToElement(
|
||||
|
@ -62,7 +62,6 @@ EXPORTS.mozilla.dom += [
|
||||
'SVGGradientElement.h',
|
||||
'SVGGraphicsElement.h',
|
||||
'SVGImageElement.h',
|
||||
'SVGIRect.h',
|
||||
'SVGLineElement.h',
|
||||
'SVGMarkerElement.h',
|
||||
'SVGMaskElement.h',
|
||||
|
@ -4035,7 +4035,7 @@ nsresult SVGTextFrame::GetEndPositionOfChar(nsIContent* aContent,
|
||||
* text content element.
|
||||
*/
|
||||
nsresult SVGTextFrame::GetExtentOfChar(nsIContent* aContent, uint32_t aCharNum,
|
||||
SVGIRect** aResult) {
|
||||
SVGRect** aResult) {
|
||||
nsIFrame* kid = PrincipalChildList().FirstChild();
|
||||
if (NS_SUBTREE_DIRTY(kid)) {
|
||||
// We're never reflowed if we're under a non-SVG element that is
|
||||
@ -4088,7 +4088,7 @@ nsresult SVGTextFrame::GetExtentOfChar(nsIContent* aContent, uint32_t aCharNum,
|
||||
// Transform the glyph's rect into user space.
|
||||
gfxRect r = m.TransformBounds(glyphRect);
|
||||
|
||||
RefPtr<SVGRect> rect = new SVGRect(aContent, r.x, r.y, r.width, r.height);
|
||||
RefPtr<SVGRect> rect = new SVGRect(aContent, ToRect(r));
|
||||
rect.forget(aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class TextRenderedRunIterator;
|
||||
|
||||
namespace dom {
|
||||
struct DOMPointInit;
|
||||
class SVGIRect;
|
||||
class SVGRect;
|
||||
class SVGGeometryElement;
|
||||
} // namespace dom
|
||||
|
||||
@ -247,7 +247,7 @@ class SVGTextFrame final : public nsSVGDisplayContainerFrame {
|
||||
nsresult GetEndPositionOfChar(nsIContent* aContent, uint32_t aCharNum,
|
||||
mozilla::nsISVGPoint** aResult);
|
||||
nsresult GetExtentOfChar(nsIContent* aContent, uint32_t aCharNum,
|
||||
mozilla::dom::SVGIRect** aResult);
|
||||
mozilla::dom::SVGRect** aResult);
|
||||
nsresult GetRotationOfChar(nsIContent* aContent, uint32_t aCharNum,
|
||||
float* aResult);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user