Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends
nsSVGTransformList Class Reference

#include <nsSVGTransformList.h>

Inheritance diagram for nsSVGTransformList:
Inheritance graph
[legend]
Collaboration diagram for nsSVGTransformList:
Collaboration graph
[legend]

List of all members.

Public Types

enum  modificationType { mod_other = 0, mod_context, mod_die }

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIDOMSVGTRANSFORMLIST
NS_IMETHOD 
SetValueString (const nsAString &aValue)
NS_IMETHOD GetValueString (nsAString &aValue)
NS_IMETHOD WillModifySVGObservable (nsISVGValue *observable, modificationType aModType)
NS_IMETHOD DidModifySVGObservable (nsISVGValue *observable, modificationType aModType)
nsIDOMSVGTransformElementAt (PRInt32 index)
PRBool AppendElement (nsIDOMSVGTransform *aElement)
NS_IMETHOD AddObserver (nsISVGValueObserver *observer)
NS_IMETHOD RemoveObserver (nsISVGValueObserver *observer)
NS_IMETHOD BeginBatchUpdate ()
NS_IMETHOD EndBatchUpdate ()
typedef NS_STDCALL_FUNCPROTO (nsresult, SVGObserverNotifyFunction, nsISVGValueObserver, DidModifySVGObservable,(nsISVGValue *, nsISVGValue::modificationType))
void clear ()
nsIDOMSVGTransform initialize (in nsIDOMSVGTransform newItem)
nsIDOMSVGTransform getItem (in unsigned long index)
nsIDOMSVGTransform insertItemBefore (in nsIDOMSVGTransform newItem, in unsigned long index)
nsIDOMSVGTransform replaceItem (in nsIDOMSVGTransform newItem, in unsigned long index)
nsIDOMSVGTransform removeItem (in unsigned long index)
nsIDOMSVGTransform appendItem (in nsIDOMSVGTransform newItem)
nsIDOMSVGTransform createSVGTransformFromMatrix (in nsIDOMSVGMatrix matrix)
nsIDOMSVGTransform consolidate ()
nsIDOMSVGMatrix getConsolidationMatrix ()

Static Public Member Functions

static nsresult Create (nsIDOMSVGTransformList **aResult)

Public Attributes

readonly attribute unsigned long numberOfItems

Protected Member Functions

 nsSVGTransformList ()
virtual ~nsSVGTransformList ()
PRInt32 ParseParameterList (char *paramstr, float *vars, PRInt32 nvars)
void ReleaseTransforms ()
void WillModify (modificationType aModType=mod_other)
void DidModify (modificationType aModType=mod_other)
void ReleaseObservers ()
void NotifyObservers (SVGObserverNotifyFunction f, modificationType aModType)
PRInt32 GetModifyNestCount ()

Protected Attributes

nsAutoVoidArray mTransforms

Friends

class nsSVGValueAutoNotifier

Detailed Description

Definition at line 48 of file nsSVGTransformList.h.


Member Enumeration Documentation

Enumerator:
mod_other 
mod_context 
mod_die 

Definition at line 68 of file nsISVGValue.h.


Constructor & Destructor Documentation

Definition at line 61 of file nsSVGTransformList.cpp.

{
}

Here is the caller graph for this function:

nsSVGTransformList::~nsSVGTransformList ( ) [protected, virtual]

Definition at line 65 of file nsSVGTransformList.cpp.

Here is the call graph for this function:


Member Function Documentation

NS_IMETHODIMP nsSVGValue::AddObserver ( nsISVGValueObserver observer) [virtual, inherited]

Implements nsISVGValue.

Definition at line 97 of file nsSVGValue.cpp.

{
  nsIWeakReference* wr = NS_GetWeakReference(observer);
  if (!wr) return NS_ERROR_FAILURE;
  mObservers.AppendElement((void*)wr);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 91 of file nsSVGTransformList.cpp.

{
  PRBool rv = mTransforms.AppendElement((void*)aElement);
  if (rv) {
    NS_ADDREF(aElement);
    nsCOMPtr<nsISVGValue> val = do_QueryInterface(aElement);
    if (val)
      val->AddObserver(this);
  }

  return rv;
}

Here is the call graph for this function:

NS_IMETHODIMP nsSVGValue::BeginBatchUpdate ( ) [virtual, inherited]

Implements nsISVGValue.

Definition at line 119 of file nsSVGValue.cpp.

{
  WillModify();
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 52 of file nsSVGTransformList.cpp.

{
  *aResult = new nsSVGTransformList();
  if (!*aResult) return NS_ERROR_OUT_OF_MEMORY;
  
  NS_ADDREF(*aResult);
  return NS_OK;
}

Here is the call graph for this function:

void nsSVGValue::DidModify ( modificationType  aModType = mod_other) [protected, inherited]

Definition at line 86 of file nsSVGValue.cpp.

{
  NS_ASSERTION(mModifyNestCount>0, "unbalanced Will/DidModify calls");
  if (--mModifyNestCount == 0) {
    OnDidModify();
    NotifyObservers(&nsISVGValueObserver::DidModifySVGObservable, aModType);
  }
}

Here is the call graph for this function:

Implements nsISVGValueObserver.

Definition at line 589 of file nsSVGTransformList.cpp.

{
  DidModify(aModType);
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 85 of file nsSVGTransformList.cpp.

{
  return (nsIDOMSVGTransform*)mTransforms.ElementAt(index);
}

Here is the caller graph for this function:

NS_IMETHODIMP nsSVGValue::EndBatchUpdate ( ) [virtual, inherited]

Implements nsISVGValue.

Definition at line 126 of file nsSVGValue.cpp.

{
  DidModify();
  return NS_OK;
}

Here is the call graph for this function:

nsIDOMSVGTransform nsIDOMSVGTransformList::getItem ( in unsigned long  index) [inherited]
PRInt32 nsSVGValue::GetModifyNestCount ( ) [inline, protected, inherited]

Definition at line 79 of file nsSVGValue.h.

{ return mModifyNestCount; }
NS_IMETHODIMP nsSVGTransformList::GetValueString ( nsAString &  aValue) [virtual]

Implements nsISVGValue.

Definition at line 312 of file nsSVGTransformList.cpp.

{
  aValue.Truncate();

  PRInt32 count = mTransforms.Count();

  if (count<=0) return NS_OK;

  PRInt32 i = 0;
  
  while (1) {
    nsIDOMSVGTransform* transform = ElementAt(i);

    nsCOMPtr<nsISVGValue> val = do_QueryInterface(transform);
    nsAutoString str;
    val->GetValueString(str);
    aValue.Append(str);

    if (++i >= count) break;

    aValue.AppendLiteral(" ");
  }
  
  return NS_OK;

}

Here is the call graph for this function:

void nsSVGValue::NotifyObservers ( SVGObserverNotifyFunction  f,
modificationType  aModType 
) [protected, inherited]

Definition at line 66 of file nsSVGValue.cpp.

{
  PRInt32 count = mObservers.Count();
  for (PRInt32 i = 0; i < count; ++i) {
    nsIWeakReference* wr = NS_STATIC_CAST(nsIWeakReference*,mObservers.ElementAt(i));
    nsCOMPtr<nsISVGValueObserver> observer = do_QueryReferent(wr);
    if (observer)
       (NS_STATIC_CAST(nsISVGValueObserver*,observer)->*f)(this, aModType);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

typedef nsSVGValue::NS_STDCALL_FUNCPROTO ( nsresult  ,
SVGObserverNotifyFunction  ,
nsISVGValueObserver  ,
DidModifySVGObservable  ,
(nsISVGValue *, nsISVGValue::modificationType  
) [inherited]
PRInt32 nsSVGTransformList::ParseParameterList ( char *  paramstr,
float *  vars,
PRInt32  nvars 
) [protected]

Definition at line 284 of file nsSVGTransformList.cpp.

{
  if (!paramstr)
    return 0;

  char *arg, *argend, *argrest = paramstr;
  int num_args_found = 0;
  float f;

  const char arg_delimiters[] = "\x20\x09\x0d\x0a,";

  while ((arg = nsCRT::strtok(argrest, arg_delimiters, &argrest))) {
    if (num_args_found < nvars) {
      f = (float) PR_strtod(arg, &argend);
      if (arg == argend || *argend != '\0')
        return -1;

      vars[num_args_found] = f;
    }

    arg = argrest;
    num_args_found++;
  }

  return num_args_found;
}

Here is the call graph for this function:

void nsSVGValue::ReleaseObservers ( ) [protected, inherited]

Definition at line 53 of file nsSVGValue.cpp.

{
  PRInt32 count = mObservers.Count();
  PRInt32 i;
  for (i = 0; i < count; ++i) {
    nsIWeakReference* wr = NS_STATIC_CAST(nsIWeakReference*,mObservers.ElementAt(i));
    NS_RELEASE(wr);
  }
  while (i)
    mObservers.RemoveElementAt(--i);
}

Here is the caller graph for this function:

Definition at line 71 of file nsSVGTransformList.cpp.

{
  PRInt32 count = mTransforms.Count();
  for (PRInt32 i = 0; i < count; ++i) {
    nsIDOMSVGTransform* transform = ElementAt(i);
    nsCOMPtr<nsISVGValue> val = do_QueryInterface(transform);
    if (val)
      val->RemoveObserver(this);
    NS_RELEASE(transform);
  }
  mTransforms.Clear();
}

Here is the call graph for this function:

Here is the caller graph for this function:

NS_IMETHODIMP nsSVGValue::RemoveObserver ( nsISVGValueObserver observer) [virtual, inherited]

Implements nsISVGValue.

Definition at line 106 of file nsSVGValue.cpp.

{
  nsCOMPtr<nsIWeakReference> wr = do_GetWeakReference(observer);
  if (!wr) return NS_ERROR_FAILURE;
  PRInt32 i = mObservers.IndexOf((void*)wr);
  if (i<0) return NS_ERROR_FAILURE;
  nsIWeakReference* wr2 = NS_STATIC_CAST(nsIWeakReference*,mObservers.ElementAt(i));
  NS_RELEASE(wr2);
  mObservers.RemoveElementAt(i);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIDOMSVGTransform nsIDOMSVGTransformList::replaceItem ( in nsIDOMSVGTransform  newItem,
in unsigned long  index 
) [inherited]

Implements nsISVGValue.

Definition at line 129 of file nsSVGTransformList.cpp.

{
  // XXX: we don't implement the _exact_ BNF given in the
  // specs. 
  
  nsresult rv = NS_OK;

  char *str = ToNewCString(aValue);
  
  char* rest = str;
  char* keyword;
  char* args;
  const char* delimiters1 = "\x20\x9\xD\xA,(";
  const char* delimiters2 = "()";
  nsCOMArray<nsIDOMSVGTransform> xforms;
    
  while ((keyword = nsCRT::strtok(rest, delimiters1, &rest))) {

    while (rest && isspace(*rest))
      ++rest;

    if (!(args = nsCRT::strtok(rest, delimiters2, &rest))) {
      rv = NS_ERROR_FAILURE;
      break; // parse error
    }
    nsCOMPtr<nsIDOMSVGTransform> transform;
    NS_NewSVGTransform(getter_AddRefs(transform));
    if (!transform) {
      rv = NS_ERROR_OUT_OF_MEMORY;
      break;
    }
    
    nsCOMPtr<nsIAtom> keyatom = do_GetAtom(keyword);
    
    if (keyatom == nsSVGAtoms::translate) {
      // tx [ty=0]
      float t[2] = { 0.f };
      PRInt32 num_parsed = ParseParameterList(args, t, 2);
      if (num_parsed != 1 && num_parsed != 2) {
        rv = NS_ERROR_FAILURE;
        break; // parse error
      }

      transform->SetTranslate(t[0], t[1]);
    }
    else if (keyatom == nsSVGAtoms::scale) { 
      // sx [sy=sx]
      float s[2] = { 0.f };
      PRInt32 num_parsed = ParseParameterList(args, s, 2);
      if (num_parsed != 1 && num_parsed != 2) {
        rv = NS_ERROR_FAILURE;
        break; // parse error
      }

      if (num_parsed == 1)
        s[1] = s[0];

      transform->SetScale(s[0], s[1]);
    }
    else if (keyatom == nsSVGAtoms::rotate) {
      // r [x0=0 y0=0]
      float r[3] = { 0.f };
      PRInt32 num_parsed = ParseParameterList(args, r, 3);
      if (num_parsed != 1 && num_parsed != 3) {
        rv = NS_ERROR_FAILURE;
        break; // parse error
      }

      transform->SetRotate(r[0], r[1], r[2]);
    }
    else if (keyatom == nsSVGAtoms::skewX) {
      // x-angle
      float angle;
      PRInt32 num_parsed = ParseParameterList(args, &angle, 1);
      if (num_parsed != 1) {
        rv = NS_ERROR_FAILURE;
        break; // parse error
      }

      transform->SetSkewX(angle);
    }
    else if (keyatom == nsSVGAtoms::skewY) {
      // y-angle
      float angle;
      PRInt32 num_parsed = ParseParameterList(args, &angle, 1);
      if (num_parsed != 1) {
        rv = NS_ERROR_FAILURE;
        break; // parse error
      }

      transform->SetSkewY(angle);
    }
    else if (keyatom == nsSVGAtoms::matrix) {
      // a b c d e f
      float m[6];
      PRInt32 num_parsed = ParseParameterList(args, m, 6);
      if (num_parsed != 6) {
        rv = NS_ERROR_FAILURE;
        break; // parse error
      }

      nsCOMPtr<nsIDOMSVGMatrix> matrix;
      NS_NewSVGMatrix(getter_AddRefs(matrix),
                      m[0], m[1], m[2], m[3], m[4], m[5]);
      NS_ASSERTION(matrix, "couldn't create matrix");
      transform->SetMatrix(matrix);
    }
    else { // parse error
      rv = NS_ERROR_FAILURE;
      break;
    }
    xforms.AppendObject(transform);
  }

  if (keyword || NS_FAILED(rv)) { 
    // there was a parse error. 
    rv = NS_ERROR_FAILURE;
    NS_ERROR("transform-attribute parse error");
  }
  else {
    WillModify();
    ReleaseTransforms();
    PRInt32 count = xforms.Count();
    for (PRInt32 i=0; i<count; ++i) {
      AppendElement(xforms.ObjectAt(i));
    }
    DidModify();
  }

  nsMemory::Free(str);
  
  return rv;
}

Here is the call graph for this function:

void nsSVGValue::WillModify ( modificationType  aModType = mod_other) [protected, inherited]

Definition at line 79 of file nsSVGValue.cpp.

Here is the call graph for this function:

Implements nsISVGValueObserver.

Definition at line 581 of file nsSVGTransformList.cpp.

{
  WillModify(aModType);
  return NS_OK;
}

Here is the call graph for this function:


Friends And Related Function Documentation

friend class nsSVGValueAutoNotifier [friend, inherited]

Definition at line 59 of file nsSVGValue.h.


Member Data Documentation

nsAutoVoidArray nsSVGTransformList::mTransforms [protected]

Definition at line 89 of file nsSVGTransformList.h.

readonly attribute unsigned long nsIDOMSVGTransformList::numberOfItems [inherited]

Definition at line 47 of file nsIDOMSVGTransformList.idl.


The documentation for this class was generated from the following files: