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: */
|
2012-05-21 15:12:37 +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/. */
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SVG_SVGRECT_H_
|
|
|
|
#define DOM_SVG_SVGRECT_H_
|
2000-04-01 18:38:51 +04:00
|
|
|
|
2019-06-20 17:03:54 +03:00
|
|
|
#include "mozilla/dom/SVGElement.h"
|
2014-03-18 06:41:33 +04:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2007-01-31 19:05:42 +03:00
|
|
|
|
2007-09-06 03:07:34 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
2013-03-26 19:52:41 +04:00
|
|
|
// SVGRect class
|
2007-09-06 03:07:34 +04:00
|
|
|
|
2013-03-26 19:52:41 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2019-06-20 17:03:54 +03:00
|
|
|
class SVGSVGElement;
|
|
|
|
|
2019-08-19 22:10:03 +03:00
|
|
|
class SVGRect final : public nsWrapperCache {
|
2007-09-06 03:07:34 +04:00
|
|
|
public:
|
2020-08-13 02:54:29 +03:00
|
|
|
enum class RectType : uint8_t { BaseValue, AnimValue, CreatedValue };
|
2007-09-06 03:07:34 +04:00
|
|
|
|
2019-08-19 22:10:03 +03:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(SVGRect)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(SVGRect)
|
2007-09-06 03:07:34 +04:00
|
|
|
|
2019-06-20 17:03:54 +03:00
|
|
|
/**
|
|
|
|
* 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);
|
2020-08-13 02:54:29 +03:00
|
|
|
MOZ_ASSERT(mType == RectType::BaseValue || mType == RectType::AnimValue);
|
2019-06-20 17:03:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ctor for creating the objects returned by SVGSVGElement.createSVGRect(),
|
|
|
|
* which do not initially belong to an attribute.
|
|
|
|
*/
|
|
|
|
explicit SVGRect(SVGSVGElement* aSVGElement);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ctor for all other non-attribute usage i.e getBBox, getExtentOfChar etc.
|
|
|
|
*/
|
|
|
|
SVGRect(nsIContent* aParent, const gfx::Rect& aRect)
|
2020-08-13 02:54:29 +03:00
|
|
|
: mVal(nullptr),
|
|
|
|
mRect(aRect),
|
|
|
|
mParent(aParent),
|
|
|
|
mType(RectType::CreatedValue) {
|
2019-06-20 17:03:54 +03:00
|
|
|
MOZ_ASSERT(mParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
float X();
|
|
|
|
float Y();
|
|
|
|
float Width();
|
|
|
|
float Height();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
nsIContent* GetParentObject() const {
|
|
|
|
MOZ_ASSERT(mParent);
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~SVGRect();
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// 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;
|
2007-09-06 03:07:34 +04:00
|
|
|
};
|
|
|
|
|
2013-03-26 19:52:41 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SVG_SVGRECT_H_
|