Bug#111496: Implement preserveAspectRatio. Checkin for <jonathan.watt@strath.ac.uk>. SVG only - not part of default builds. r=afri, sr=jst for dom/ changes.

This commit is contained in:
alex%croczilla.com 2004-07-01 08:10:34 +00:00
Родитель eb3c0ad1ef
Коммит 9d0a4a5eca
11 изменённых файлов: 727 добавлений и 18 удалений

Просмотреть файл

@ -111,6 +111,7 @@ SVG_ATOM(opacity, "opacity")
SVG_ATOM(pathLength, "pathLength")
SVG_ATOM(pointer_events, "pointer-events")
SVG_ATOM(points, "points")
SVG_ATOM(preserveAspectRatio, "preserveAspectRatio")
SVG_ATOM(r, "r")
SVG_ATOM(rx, "rx")
SVG_ATOM(ry, "ry")

Просмотреть файл

@ -66,6 +66,7 @@ CPPSRCS = \
nsSVGAnimatedLength.cpp \
nsSVGAnimatedLengthList.cpp \
nsSVGAnimatedRect.cpp \
nsSVGAnimatedPreserveAspectRatio.cpp \
nsSVGAnimatedString.cpp \
nsSVGAnimatedTransformList.cpp \
nsSVGCircleElement.cpp \
@ -91,6 +92,7 @@ CPPSRCS = \
nsSVGPointList.cpp \
nsSVGPolygonElement.cpp \
nsSVGPolylineElement.cpp \
nsSVGPreserveAspectRatio.cpp \
nsSVGStringProxyValue.cpp \
nsSVGStylableElement.cpp \
nsSVGRect.cpp \

Просмотреть файл

@ -0,0 +1,203 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla SVG Project code.
*
* The Initial Developer of the Original Code is
* Jonathan Watt.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jonathan Watt <jonathan.watt@strath.ac.uk> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsSVGAnimatedPreserveAspectRatio.h"
#include "nsSVGPreserveAspectRatio.h"
#include "nsSVGValue.h"
#include "nsWeakReference.h"
////////////////////////////////////////////////////////////////////////
// nsSVGAnimatedPreserveAspectRatio
class nsSVGAnimatedPreserveAspectRatio : public nsIDOMSVGAnimatedPreserveAspectRatio,
public nsSVGValue,
public nsISVGValueObserver,
public nsSupportsWeakReference
{
protected:
friend nsresult NS_NewSVGAnimatedPreserveAspectRatio(
nsIDOMSVGAnimatedPreserveAspectRatio** result,
nsIDOMSVGPreserveAspectRatio* baseVal);
nsSVGAnimatedPreserveAspectRatio();
~nsSVGAnimatedPreserveAspectRatio();
void Init(nsIDOMSVGPreserveAspectRatio* baseVal);
public:
// nsISupports interface:
NS_DECL_ISUPPORTS
// nsIDOMSVGAnimatedPreserveAspectRatio interface:
NS_DECL_NSIDOMSVGANIMATEDPRESERVEASPECTRATIO
// remainder of nsISVGValue interface:
NS_IMETHOD SetValueString(const nsAString& aValue);
NS_IMETHOD GetValueString(nsAString& aValue);
// nsISVGValueObserver
NS_IMETHOD WillModifySVGObservable(nsISVGValue* observable);
NS_IMETHOD DidModifySVGObservable (nsISVGValue* observable);
// nsISupportsWeakReference
// implementation inherited from nsSupportsWeakReference
protected:
nsCOMPtr<nsIDOMSVGPreserveAspectRatio> mBaseVal;
};
//----------------------------------------------------------------------
// Implementation
nsSVGAnimatedPreserveAspectRatio::nsSVGAnimatedPreserveAspectRatio()
{
}
nsSVGAnimatedPreserveAspectRatio::~nsSVGAnimatedPreserveAspectRatio()
{
nsCOMPtr<nsISVGValue> val( do_QueryInterface(mBaseVal) );
if (!val) return;
val->RemoveObserver(this);
}
void
nsSVGAnimatedPreserveAspectRatio::Init(nsIDOMSVGPreserveAspectRatio* aBaseVal)
{
mBaseVal = aBaseVal;
nsCOMPtr<nsISVGValue> val( do_QueryInterface(mBaseVal) );
NS_ASSERTION(val, "baseval needs to implement nsISVGValue interface");
if (!val) return;
val->AddObserver(this);
}
//----------------------------------------------------------------------
// nsISupports methods:
NS_IMPL_ADDREF(nsSVGAnimatedPreserveAspectRatio)
NS_IMPL_RELEASE(nsSVGAnimatedPreserveAspectRatio)
NS_INTERFACE_MAP_BEGIN(nsSVGAnimatedPreserveAspectRatio)
NS_INTERFACE_MAP_ENTRY(nsISVGValue)
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedPreserveAspectRatio)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGAnimatedPreserveAspectRatio)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISVGValue)
NS_INTERFACE_MAP_END
//----------------------------------------------------------------------
// nsISVGValue methods:
NS_IMETHODIMP
nsSVGAnimatedPreserveAspectRatio::SetValueString(const nsAString& aValue)
{
nsresult rv;
nsCOMPtr<nsISVGValue> val( do_QueryInterface(mBaseVal, &rv) );
return NS_FAILED(rv)? rv: val->SetValueString(aValue);
}
NS_IMETHODIMP
nsSVGAnimatedPreserveAspectRatio::GetValueString(nsAString& aValue)
{
nsresult rv;
nsCOMPtr<nsISVGValue> val( do_QueryInterface(mBaseVal, &rv) );
return NS_FAILED(rv)? rv: val->GetValueString(aValue);
}
//----------------------------------------------------------------------
// nsIDOMSVGAnimatedPreserveAspectRatio methods:
/* readonly attribute nsIDOMSVGPreserveAspectRatio baseVal; */
NS_IMETHODIMP
nsSVGAnimatedPreserveAspectRatio::GetBaseVal(nsIDOMSVGPreserveAspectRatio** aBaseVal)
{
*aBaseVal = mBaseVal;
NS_ADDREF(*aBaseVal);
return NS_OK;
}
/* readonly attribute nsIDOMSVGPreserveAspectRatio animVal; */
NS_IMETHODIMP
nsSVGAnimatedPreserveAspectRatio::GetAnimVal(nsIDOMSVGPreserveAspectRatio** aAnimVal)
{
*aAnimVal = mBaseVal;
NS_ADDREF(*aAnimVal);
return NS_OK;
}
//----------------------------------------------------------------------
// nsISVGValueObserver methods
NS_IMETHODIMP
nsSVGAnimatedPreserveAspectRatio::WillModifySVGObservable(nsISVGValue* observable)
{
WillModify();
return NS_OK;
}
NS_IMETHODIMP
nsSVGAnimatedPreserveAspectRatio::DidModifySVGObservable (nsISVGValue* observable)
{
DidModify();
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// Exported creation functions:
nsresult
NS_NewSVGAnimatedPreserveAspectRatio(nsIDOMSVGAnimatedPreserveAspectRatio** result,
nsIDOMSVGPreserveAspectRatio* baseVal)
{
*result = nsnull;
if (!baseVal) {
NS_ERROR("need baseVal");
return NS_ERROR_FAILURE;
}
nsSVGAnimatedPreserveAspectRatio* animatedPreserveAspectRatio = new nsSVGAnimatedPreserveAspectRatio();
if (!animatedPreserveAspectRatio)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(animatedPreserveAspectRatio);
animatedPreserveAspectRatio->Init(baseVal);
*result = (nsIDOMSVGAnimatedPreserveAspectRatio*) animatedPreserveAspectRatio;
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla SVG Project code.
*
* The Initial Developer of the Original Code is
* Jonathan Watt.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jonathan Watt <jonathan.watt@strath.ac.uk> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __NS_SVGANIMATEDPRESERVEASPECTRATIO_H__
#define __NS_SVGANIMATEDPRESERVEASPECTRATIO_H__
#include "nsIDOMSVGAnimPresAspRatio.h"
#include "nsIDOMSVGPresAspectRatio.h"
nsresult
NS_NewSVGAnimatedPreserveAspectRatio(
nsIDOMSVGAnimatedPreserveAspectRatio** result,
nsIDOMSVGPreserveAspectRatio* baseVal);
#endif //__NS_SVGANIMATEDPRESERVEASPECTRATIO_H__

Просмотреть файл

@ -108,11 +108,17 @@ nsSVGAnimatedRect::Init(nsIDOMSVGRect* baseVal)
//----------------------------------------------------------------------
// nsISupports methods:
NS_IMPL_ISUPPORTS4(nsSVGAnimatedRect,
nsISVGValue,
nsIDOMSVGAnimatedRect,
nsISupportsWeakReference,
nsISVGValueObserver)
NS_IMPL_ADDREF(nsSVGAnimatedRect)
NS_IMPL_RELEASE(nsSVGAnimatedRect)
NS_INTERFACE_MAP_BEGIN(nsSVGAnimatedRect)
NS_INTERFACE_MAP_ENTRY(nsISVGValue)
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedRect)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsISVGValueObserver)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGAnimatedRect)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISVGValue)
NS_INTERFACE_MAP_END
//----------------------------------------------------------------------
// nsISVGValue methods:

Просмотреть файл

@ -111,6 +111,7 @@ SVG_ATOM(opacity, "opacity")
SVG_ATOM(pathLength, "pathLength")
SVG_ATOM(pointer_events, "pointer-events")
SVG_ATOM(points, "points")
SVG_ATOM(preserveAspectRatio, "preserveAspectRatio")
SVG_ATOM(r, "r")
SVG_ATOM(rx, "rx")
SVG_ATOM(ry, "ry")

Просмотреть файл

@ -0,0 +1,290 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla SVG Project code.
*
* The Initial Developer of the Original Code is
* Jonathan Watt.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jonathan Watt <jonathan.watt@strath.ac.uk> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsSVGPreserveAspectRatio.h"
#include "nsSVGValue.h"
#include "nsCRT.h"
////////////////////////////////////////////////////////////////////////
// nsSVGPreserveAspectRatio class
class nsSVGPreserveAspectRatio : public nsIDOMSVGPreserveAspectRatio,
public nsSVGValue
{
protected:
friend nsresult NS_NewSVGPreserveAspectRatio(
nsIDOMSVGPreserveAspectRatio** result,
PRUint16 aAlign,
PRUint16 aMeetOrSlice);
nsSVGPreserveAspectRatio(PRUint16 aAlign, PRUint16 aMeetOrSlice);
~nsSVGPreserveAspectRatio();
public:
// nsISupports interface:
NS_DECL_ISUPPORTS
// nsIDOMSVGPreserveAspectRatio interface:
NS_DECL_NSIDOMSVGPRESERVEASPECTRATIO
// nsISVGValue interface:
NS_IMETHOD SetValueString(const nsAString& aValue);
NS_IMETHOD GetValueString(nsAString& aValue);
protected:
PRUint16 mAlign, mMeetOrSlice;
};
//----------------------------------------------------------------------
// implementation:
nsSVGPreserveAspectRatio::nsSVGPreserveAspectRatio(PRUint16 aAlign,
PRUint16 aMeetOrSlice)
: mAlign(aAlign), mMeetOrSlice(aMeetOrSlice)
{
}
nsSVGPreserveAspectRatio::~nsSVGPreserveAspectRatio()
{
}
//----------------------------------------------------------------------
// nsISupports methods:
NS_IMPL_ADDREF(nsSVGPreserveAspectRatio)
NS_IMPL_RELEASE(nsSVGPreserveAspectRatio)
NS_INTERFACE_MAP_BEGIN(nsSVGPreserveAspectRatio)
NS_INTERFACE_MAP_ENTRY(nsISVGValue)
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGPreserveAspectRatio)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGPreserveAspectRatio)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISVGValue)
NS_INTERFACE_MAP_END
//----------------------------------------------------------------------
// nsISVGValue methods:
NS_IMETHODIMP
nsSVGPreserveAspectRatio::SetValueString(const nsAString& aValue)
{
char* str = ToNewCString(aValue);
if (!str) return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = NS_OK;
char* rest = str;
char* token;
const char* delimiters = "\x20\x9\xD\xA";
PRUint16 align, meetOrSlice;
token = nsCRT::strtok(rest, delimiters, &rest);
if (token && !strcmp(token, "defer"))
// Ignore: only applicable for preserveAspectRatio on 'image' elements
token = nsCRT::strtok(rest, delimiters, &rest);
if (token) {
if (!strcmp(token, "none"))
align = SVG_PRESERVEASPECTRATIO_NONE;
else if (!strcmp(token, "xMinYMin"))
align = SVG_PRESERVEASPECTRATIO_XMINYMIN;
else if (!strcmp(token, "xMidYMin"))
align = SVG_PRESERVEASPECTRATIO_XMIDYMIN;
else if (!strcmp(token, "xMaxYMin"))
align = SVG_PRESERVEASPECTRATIO_XMAXYMIN;
else if (!strcmp(token, "xMinYMid"))
align = SVG_PRESERVEASPECTRATIO_XMINYMID;
else if (!strcmp(token, "xMidYMid"))
align = SVG_PRESERVEASPECTRATIO_XMIDYMID;
else if (!strcmp(token, "xMaxYMid"))
align = SVG_PRESERVEASPECTRATIO_XMAXYMID;
else if (!strcmp(token, "xMinYMax"))
align = SVG_PRESERVEASPECTRATIO_XMINYMAX;
else if (!strcmp(token, "xMidYMax"))
align = SVG_PRESERVEASPECTRATIO_XMIDYMAX;
else if (!strcmp(token, "xMaxYMax"))
align = SVG_PRESERVEASPECTRATIO_XMAXYMAX;
else
rv = NS_ERROR_FAILURE;
if (NS_SUCCEEDED(rv)) {
token = nsCRT::strtok(rest, delimiters, &rest);
if (token) {
if (!strcmp(token, "meet"))
meetOrSlice = SVG_MEETORSLICE_MEET;
else if (!strcmp(token, "slice"))
meetOrSlice = SVG_MEETORSLICE_SLICE;
else
rv = NS_ERROR_FAILURE;
}
else
meetOrSlice = SVG_MEETORSLICE_MEET;
}
}
else // align not specified
rv = NS_ERROR_FAILURE;
if (nsCRT::strtok(rest, delimiters, &rest)) // there's more
rv = NS_ERROR_FAILURE;
if (NS_SUCCEEDED(rv)) {
WillModify();
mAlign = align;
mMeetOrSlice = meetOrSlice;
DidModify();
}
nsMemory::Free(str);
return rv;
}
NS_IMETHODIMP
nsSVGPreserveAspectRatio::GetValueString(nsAString& aValue)
{
// XXX: defer isn't stored
switch (mAlign) {
case SVG_PRESERVEASPECTRATIO_NONE:
aValue.AssignLiteral("none");
break;
case SVG_PRESERVEASPECTRATIO_XMINYMIN:
aValue.AssignLiteral("xMinYMin");
break;
case SVG_PRESERVEASPECTRATIO_XMIDYMIN:
aValue.AssignLiteral("xMidYMin");
break;
case SVG_PRESERVEASPECTRATIO_XMAXYMIN:
aValue.AssignLiteral("xMaxYMin");
break;
case SVG_PRESERVEASPECTRATIO_XMINYMID:
aValue.AssignLiteral("xMinYMid");
break;
case SVG_PRESERVEASPECTRATIO_XMIDYMID:
aValue.AssignLiteral("xMidYMid");
break;
case SVG_PRESERVEASPECTRATIO_XMAXYMID:
aValue.AssignLiteral("xMaxYMid");
break;
case SVG_PRESERVEASPECTRATIO_XMINYMAX:
aValue.AssignLiteral("xMinYMax");
break;
case SVG_PRESERVEASPECTRATIO_XMIDYMAX:
aValue.AssignLiteral("xMidYMax");
break;
case SVG_PRESERVEASPECTRATIO_XMAXYMAX:
aValue.AssignLiteral("xMaxYMax");
break;
default:
NS_NOTREACHED("Unknown value for mAlign");
}
// XXX: meetOrSlice may not have been specified in the attribute
if (mAlign != SVG_PRESERVEASPECTRATIO_NONE) {
switch (mMeetOrSlice) {
case SVG_MEETORSLICE_MEET:
aValue.AppendLiteral(" meet");
break;
case SVG_MEETORSLICE_SLICE:
aValue.AppendLiteral(" slice");
break;
default:
NS_NOTREACHED("Unknown value for mMeetOrSlice");
}
}
return NS_OK;
}
//----------------------------------------------------------------------
// nsIDOMSVGPreserveAspectRatio methods:
/* attribute unsigned short align; */
NS_IMETHODIMP nsSVGPreserveAspectRatio::GetAlign(PRUint16 *aAlign)
{
*aAlign = mAlign;
return NS_OK;
}
NS_IMETHODIMP nsSVGPreserveAspectRatio::SetAlign(PRUint16 aAlign)
{
if (aAlign < SVG_PRESERVEASPECTRATIO_NONE ||
aAlign > SVG_PRESERVEASPECTRATIO_XMAXYMAX)
return NS_ERROR_FAILURE;
WillModify();
mAlign = aAlign;
DidModify();
return NS_OK;
}
/* attribute unsigned short meetOrSlice; */
NS_IMETHODIMP nsSVGPreserveAspectRatio::GetMeetOrSlice(PRUint16 *aMeetOrSlice)
{
*aMeetOrSlice = mMeetOrSlice;
return NS_OK;
}
NS_IMETHODIMP nsSVGPreserveAspectRatio::SetMeetOrSlice(PRUint16 aMeetOrSlice)
{
if (aMeetOrSlice < SVG_MEETORSLICE_MEET ||
aMeetOrSlice > SVG_MEETORSLICE_SLICE)
return NS_ERROR_FAILURE;
WillModify();
mMeetOrSlice = aMeetOrSlice;
DidModify();
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// Exported creation functions:
nsresult
NS_NewSVGPreserveAspectRatio(nsIDOMSVGPreserveAspectRatio** result,
PRUint16 aAlign, PRUint16 aMeetOrSlice)
{
*result = (nsIDOMSVGPreserveAspectRatio*) new nsSVGPreserveAspectRatio(aAlign, aMeetOrSlice);
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*result);
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,49 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla SVG Project code.
*
* The Initial Developer of the Original Code is
* Jonathan Watt.
* Portions created by the Initial Developer are Copyright (C) 2004
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Jonathan Watt <jonathan.watt@strath.ac.uk> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __NS_SVGPRESERVEASPECTRATIO_H__
#define __NS_SVGPRESERVEASPECTRATIO_H__
#include "nsIDOMSVGPresAspectRatio.h"
nsresult
NS_NewSVGPreserveAspectRatio(nsIDOMSVGPreserveAspectRatio** result,
PRUint16 aAlign=nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID,
PRUint16 aMeetOrSlice=nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET);
#endif //__NS_SVGPRESERVEASPECTRATIO_H__

Просмотреть файл

@ -48,6 +48,7 @@
#include "nsIPresContext.h"
#include "nsISVGViewportRect.h"
#include "nsSVGAnimatedRect.h"
#include "nsSVGAnimatedPreserveAspectRatio.h"
#include "nsSVGMatrix.h"
#include "nsSVGPoint.h"
#include "nsSVGTransform.h"
@ -62,6 +63,7 @@
#include "nsISVGOuterSVGFrame.h" //XXX
#include "nsSVGNumber.h"
#include "nsSVGRect.h"
#include "nsSVGPreserveAspectRatio.h"
#include "nsISVGValueUtils.h"
typedef nsSVGStylableElement nsSVGSVGElementBase;
@ -112,6 +114,7 @@ protected:
nsCOMPtr<nsISVGViewportRect> mViewport;
nsCOMPtr<nsIDOMSVGAnimatedRect> mViewBox;
nsCOMPtr<nsIDOMSVGMatrix> mViewBoxToViewportTransform;
nsCOMPtr<nsIDOMSVGAnimatedPreserveAspectRatio> mPreserveAspectRatio;
nsCOMPtr<nsIDOMSVGAnimatedLength> mX;
nsCOMPtr<nsIDOMSVGAnimatedLength> mY;
@ -149,6 +152,9 @@ nsSVGSVGElement::nsSVGSVGElement(nsINodeInfo* aNodeInfo)
nsSVGSVGElement::~nsSVGSVGElement()
{
if (mPreserveAspectRatio) {
NS_REMOVE_SVGVALUE_OBSERVER(mPreserveAspectRatio);
}
if (mViewBox) {
NS_REMOVE_SVGVALUE_OBSERVER(mViewBox);
}
@ -301,12 +307,25 @@ nsSVGSVGElement::Init()
NS_ENSURE_SUCCESS(rv,rv);
rv = AddMappedSVGValue(nsSVGAtoms::viewBox, mViewBox);
NS_ENSURE_SUCCESS(rv,rv);
// DOM property: preserveAspectRatio , #IMPLIED attrib: preserveAspectRatio
nsCOMPtr<nsIDOMSVGPreserveAspectRatio> preserveAspectRatio;
rv = NS_NewSVGPreserveAspectRatio(getter_AddRefs(preserveAspectRatio));
NS_ENSURE_SUCCESS(rv,rv);
rv = NS_NewSVGAnimatedPreserveAspectRatio(
getter_AddRefs(mPreserveAspectRatio),
preserveAspectRatio);
NS_ENSURE_SUCCESS(rv,rv);
rv = AddMappedSVGValue(nsSVGAtoms::preserveAspectRatio,
mPreserveAspectRatio);
NS_ENSURE_SUCCESS(rv,rv);
}
// add observers -------------------------- :
NS_ADD_SVGVALUE_OBSERVER(mViewport);
NS_ADD_SVGVALUE_OBSERVER(mViewBox);
NS_ADD_SVGVALUE_OBSERVER(mPreserveAspectRatio);
return rv;
}
@ -768,15 +787,15 @@ nsSVGSVGElement::GetViewboxToViewportTransform(nsIDOMSVGMatrix **_retval)
mViewport->GetWidth(&viewportWidth);
mViewport->GetHeight(&viewportHeight);
float viewboxWidth, viewboxHeight, viewboxX, viewboxY;
float viewboxX, viewboxY, viewboxWidth, viewboxHeight;
{
nsCOMPtr<nsIDOMSVGRect> vb;
mViewBox->GetAnimVal(getter_AddRefs(vb));
NS_ASSERTION(vb, "could not get viewbox");
vb->GetWidth(&viewboxWidth);
vb->GetHeight(&viewboxHeight);
vb->GetX(&viewboxX);
vb->GetY(&viewboxY);
vb->GetWidth(&viewboxWidth);
vb->GetHeight(&viewboxHeight);
}
if (viewboxWidth==0.0f || viewboxHeight==0.0f) {
NS_ERROR("XXX. We shouldn't get here. Viewbox width/height is set to 0. Need to disable display of element as per specs.");
@ -784,14 +803,85 @@ nsSVGSVGElement::GetViewboxToViewportTransform(nsIDOMSVGMatrix **_retval)
viewboxHeight = 1.0f;
}
// case with preserveAspectRatio=none:
float a, e, d, f;
PRUint16 align, meetOrSlice;
{
nsCOMPtr<nsIDOMSVGPreserveAspectRatio> par;
mPreserveAspectRatio->GetAnimVal(getter_AddRefs(par));
NS_ASSERTION(par, "could not get preserveAspectRatio");
par->GetAlign(&align);
par->GetMeetOrSlice(&meetOrSlice);
}
// default to the defaults
if (align == nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_UNKNOWN)
align = nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID;
if (meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_UNKNOWN)
align = nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET;
float a, d, e, f;
a = viewportWidth/viewboxWidth;
e = -a*viewboxX;
d = viewportHeight/viewboxHeight;
f = -d*viewboxY;
if (align != nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_NONE &&
a != d) {
if (meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET &&
a < d ||
meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE &&
d < a) {
d = a;
e = 0;
switch (align) {
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMIN:
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
f = 0;
break;
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
f = (viewportHeight - a * viewboxHeight) / 2;
break;
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
f = viewportHeight - a * viewboxHeight;
break;
default:
NS_NOTREACHED("Unknown value for align");
}
}
else if (
meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_MEET &&
d < a ||
meetOrSlice == nsIDOMSVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE &&
a < d) {
a = d;
f = 0;
switch (align) {
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMIN:
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
e = 0;
break;
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
e = (viewportWidth - a * viewboxWidth) / 2;
break;
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
case nsIDOMSVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
e = viewportWidth - a * viewboxWidth;
break;
default:
NS_NOTREACHED("Unknown value for align");
}
}
else NS_NOTREACHED("Unknown value for meetOrSlice");
}
if (viewboxX) e += -a * viewboxX;
if (viewboxY) f += -d * viewboxY;
#ifdef DEBUG
printf("SVG Viewport=(0?,0?,%f,%f)\n", viewportWidth, viewportHeight);
@ -825,8 +915,9 @@ nsSVGSVGElement::GetViewBox(nsIDOMSVGAnimatedRect * *aViewBox)
NS_IMETHODIMP
nsSVGSVGElement::GetPreserveAspectRatio(nsIDOMSVGAnimatedPreserveAspectRatio * *aPreserveAspectRatio)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
*aPreserveAspectRatio = mPreserveAspectRatio;
NS_ADDREF(*aPreserveAspectRatio);
return NS_OK;
}
//----------------------------------------------------------------------
@ -1058,7 +1149,7 @@ NS_IMETHODIMP
nsSVGSVGElement::WillModifySVGObservable(nsISVGValue* observable)
{
#ifdef DEBUG
printf("viewport/viewbox will be changed\n");
printf("viewport/viewbox/preserveAspectRatio will be changed\n");
#endif
return NS_OK;
}
@ -1067,7 +1158,7 @@ nsSVGSVGElement::WillModifySVGObservable(nsISVGValue* observable)
NS_IMETHODIMP
nsSVGSVGElement::DidModifySVGObservable (nsISVGValue* observable)
{
// either viewport or viewbox have changed
// either viewport, viewbox or preserveAspectRatio have changed
// invalidate viewbox -> viewport xform & inform frames
mViewBoxToViewportTransform = nsnull;
@ -1090,7 +1181,7 @@ nsSVGSVGElement::DidModifySVGObservable (nsISVGValue* observable)
#ifdef DEBUG
printf("viewport/viewbox have been changed\n");
printf("viewport/viewbox/preserveAspectRatio have been changed\n");
#endif
return NS_OK;
}

Просмотреть файл

@ -291,6 +291,8 @@ enum nsDOMClassInfoID {
eDOMClassInfo_SVGAnimatedString_id,
eDOMClassInfo_SVGImageElement_id,
eDOMClassInfo_SVGStyleElement_id,
eDOMClassInfo_SVGAnimatedPreserveAspectRatio_id,
eDOMClassInfo_SVGPreserveAspectRatio_id,
#endif //MOZ_SVG
// This one better be the last one in this list

Просмотреть файл

@ -299,6 +299,7 @@
#include "nsIDOMSVGAnimatedLengthList.h"
#include "nsIDOMSVGAnimatedPoints.h"
#include "nsIDOMSVGAnimatedPathData.h"
#include "nsIDOMSVGAnimPresAspRatio.h"
#include "nsIDOMSVGAnimTransformList.h"
#include "nsIDOMSVGCircleElement.h"
#include "nsIDOMSVGEllipseElement.h"
@ -320,6 +321,7 @@
#include "nsIDOMSVGPointList.h"
#include "nsIDOMSVGPolygonElement.h"
#include "nsIDOMSVGPolylineElement.h"
#include "nsIDOMSVGPresAspectRatio.h"
#include "nsIDOMSVGSVGElement.h"
#include "nsIDOMSVGTextElement.h"
#include "nsIDOMSVGTransformable.h"
@ -883,6 +885,10 @@ static nsDOMClassInfoData sClassInfoData[] = {
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(SVGStyleElement, nsElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(SVGAnimatedPreserveAspectRatio, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(SVGPreserveAspectRatio, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
#endif
};
@ -2361,6 +2367,14 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_SVG_ELEMENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(SVGAnimatedPreserveAspectRatio, nsIDOMSVGAnimatedPreserveAspectRatio)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGAnimatedPreserveAspectRatio)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(SVGPreserveAspectRatio, nsIDOMSVGPreserveAspectRatio)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMSVGPreserveAspectRatio)
DOM_CLASSINFO_MAP_END
#endif //MOZ_SVG
#ifdef NS_DEBUG