1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/* -*- 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/. */
#include "mozilla/dom/SVGRect.h"
#include "SVGAnimatedViewBox.h"
#include "mozilla/dom/SVGRectBinding.h"
#include "mozilla/dom/SVGSVGElement.h"
#include "nsWrapperCache.h"
using namespace mozilla::gfx;
namespace mozilla::dom {
//----------------------------------------------------------------------
// nsISupports methods:
NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(SVGRect, mParent)
//----------------------------------------------------------------------
// implementation:
SVGRect::SVGRect(SVGSVGElement* aSVGElement)
: mVal(nullptr), mParent(aSVGElement), mType(RectType::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 RectType::AnimValue:
static_cast<SVGElement*>(mParent->AsElement())->FlushAnimations();
return mVal->GetAnimValue().x;
case RectType::BaseValue:
return mVal->GetBaseValue().x;
default:
return mRect.x;
}
}
float SVGRect::Y() {
switch (mType) {
case RectType::AnimValue:
static_cast<SVGElement*>(mParent->AsElement())->FlushAnimations();
return mVal->GetAnimValue().y;
case RectType::BaseValue:
return mVal->GetBaseValue().y;
default:
return mRect.y;
}
}
float SVGRect::Width() {
switch (mType) {
case RectType::AnimValue:
static_cast<SVGElement*>(mParent->AsElement())->FlushAnimations();
return mVal->GetAnimValue().width;
case RectType::BaseValue:
return mVal->GetBaseValue().width;
default:
return mRect.width;
}
}
float SVGRect::Height() {
switch (mType) {
case RectType::AnimValue:
static_cast<SVGElement*>(mParent->AsElement())->FlushAnimations();
return mVal->GetAnimValue().height;
case RectType::BaseValue:
return mVal->GetBaseValue().height;
default:
return mRect.height;
}
}
void SVGRect::SetX(float aX, ErrorResult& aRv) {
switch (mType) {
case RectType::AnimValue:
aRv.ThrowNoModificationAllowedError("Animated values cannot be set");
return;
case RectType::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 RectType::AnimValue:
aRv.ThrowNoModificationAllowedError("Animated values cannot be set");
return;
case RectType::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 RectType::AnimValue:
aRv.ThrowNoModificationAllowedError("Animated values cannot be set");
return;
case RectType::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 RectType::AnimValue:
aRv.ThrowNoModificationAllowedError("Animated values cannot be set");
return;
case RectType::BaseValue: {
SVGViewBox rect = mVal->GetBaseValue();
rect.height = aHeight;
mVal->SetBaseValue(rect, static_cast<SVGElement*>(mParent->AsElement()));
return;
}
default:
mRect.height = aHeight;
}
}
} // namespace mozilla::dom
|