Beispiel #1
0
NS_IMETHODIMP
nsSVGPatternFrame::AttributeChanged(PRInt32         aNameSpaceID,
                                    nsIAtom*        aAttribute,
                                    PRInt32         aModType)
{
  if (aNameSpaceID == kNameSpaceID_None &&
      (aAttribute == nsGkAtoms::patternUnits ||
       aAttribute == nsGkAtoms::patternContentUnits ||
       aAttribute == nsGkAtoms::patternTransform ||
       aAttribute == nsGkAtoms::x ||
       aAttribute == nsGkAtoms::y ||
       aAttribute == nsGkAtoms::width ||
       aAttribute == nsGkAtoms::height ||
       aAttribute == nsGkAtoms::preserveAspectRatio ||
       aAttribute == nsGkAtoms::viewBox)) {
    WillModify();
    DidModify();
    return NS_OK;
  } 

  if (aNameSpaceID == kNameSpaceID_XLink &&
      aAttribute == nsGkAtoms::href) {
    if (mNextPattern)
      mNextPattern->RemoveObserver(this);
    mNextPattern = nsnull;
    WillModify();
    DidModify();
    return NS_OK;
  }

  return nsSVGPatternFrameBase::AttributeChanged(aNameSpaceID,
                                                 aAttribute, aModType);
}
/* void setSkewY (in float angle); */
NS_IMETHODIMP nsSVGTransform::SetSkewY(float angle)
{
  NS_ENSURE_FINITE(angle, NS_ERROR_ILLEGAL_VALUE);

  float ta = static_cast<float>(tan(angle * radPerDegree));

  NS_ENSURE_FINITE(ta, NS_ERROR_DOM_SVG_INVALID_VALUE_ERR);

  WillModify();
  
  mType = SVG_TRANSFORM_SKEWY;
  mAngle = angle;

  NS_REMOVE_SVGVALUE_OBSERVER(mMatrix);
  mMatrix->SetA(1.0f);
  mMatrix->SetB(ta);
  mMatrix->SetC(0.0f);
  mMatrix->SetD(1.0f);
  mMatrix->SetE(0.0f);
  mMatrix->SetF(0.0f);
  NS_ADD_SVGVALUE_OBSERVER(mMatrix);

  DidModify();
  return NS_OK;
}
NS_IMETHODIMP
nsSVGAnimatedAngle::WillModifySVGObservable(nsISVGValue* observable,
                                            modificationType aModType)
{
  WillModify(aModType);
  return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP nsSVGTransformList::Clear()
{
  WillModify();
  ReleaseTransforms();
  DidModify();
  return NS_OK;
}
/* void setRotate (in float angle, in float cx, in float cy); */
NS_IMETHODIMP nsSVGTransform::SetRotate(float angle, float cx, float cy)
{
  NS_ENSURE_FINITE3(angle, cx, cy, NS_ERROR_ILLEGAL_VALUE);

  WillModify();
  
  mType = SVG_TRANSFORM_ROTATE;
  mAngle = angle;
  mOriginX = cx;
  mOriginY = cy;

  gfxMatrix matrix(1, 0, 0, 1, cx, cy);
  matrix.Rotate(angle * radPerDegree);
  matrix.Translate(gfxPoint(-cx, -cy));

  NS_REMOVE_SVGVALUE_OBSERVER(mMatrix);
  mMatrix->SetA(static_cast<float>(matrix.xx));
  mMatrix->SetB(static_cast<float>(matrix.yx));
  mMatrix->SetC(static_cast<float>(matrix.xy));
  mMatrix->SetD(static_cast<float>(matrix.yy));
  mMatrix->SetE(static_cast<float>(matrix.x0));
  mMatrix->SetF(static_cast<float>(matrix.y0));
  NS_ADD_SVGVALUE_OBSERVER(mMatrix);

  DidModify();
  return NS_OK;
}
/* void setMatrix (in nsIDOMSVGMatrix matrix); */
NS_IMETHODIMP nsSVGTransform::SetMatrix(nsIDOMSVGMatrix *matrix)
{
  float a, b, c, d, e, f;

  if (!matrix)
    return NS_ERROR_DOM_SVG_WRONG_TYPE_ERR;

  WillModify();

  mType = SVG_TRANSFORM_MATRIX;
  mAngle = 0.0f;
  
  matrix->GetA(&a);
  matrix->GetB(&b);
  matrix->GetC(&c);
  matrix->GetD(&d);
  matrix->GetE(&e);
  matrix->GetF(&f);

  NS_REMOVE_SVGVALUE_OBSERVER(mMatrix);
  mMatrix->SetA(a);
  mMatrix->SetB(b);
  mMatrix->SetC(c);
  mMatrix->SetD(d);
  mMatrix->SetE(e);
  mMatrix->SetF(f);
  NS_ADD_SVGVALUE_OBSERVER(mMatrix);

  DidModify();
  return NS_OK;
}
Beispiel #7
0
NS_IMETHODIMP nsSVGNumber::SetValue(float aValue)
{
    WillModify();
    mValue = aValue;
    DidModify();
    return NS_OK;
}
NS_IMETHODIMP
nsSVGTransformList::WillModifySVGObservable(nsISVGValue* observable,
                                            modificationType aModType)
{
  WillModify(aModType);
  return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP nsSVGPathSegList::Clear()
{
  WillModify();
  ReleaseSegments();
  DidModify();
  return NS_OK;
}
/* void clear (); */
NS_IMETHODIMP nsSVGLengthList::Clear()
{
  WillModify();
  ReleaseLengths();
  DidModify();
  return NS_OK;
}
NS_INTERFACE_MAP_END

//----------------------------------------------------------------------
// nsISVGValue methods:

NS_IMETHODIMP
nsSVGTransformList::SetValueString(const nsAString& aValue)
{
  // XXX: we don't implement the _exact_ BNF given in the
  // specs.

  nsresult rv = NS_OK;

  // parse transform attribute value
  nsCOMArray<nsIDOMSVGTransform> xforms;
  nsSVGTransformListParser parser(&xforms);
  rv = parser.Parse(aValue);

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

  return rv;
}
Beispiel #12
0
//----------------------------------------------------------------------
// nsISVGValueObserver methods:
NS_IMETHODIMP
nsSVGPatternFrame::WillModifySVGObservable(nsISVGValue* observable,
                                            modificationType aModType)
{
  WillModify(aModType);
  return NS_OK;
}
Beispiel #13
0
NS_IMETHODIMP
nsSVGPatternFrame::DidSetStyleContext()
{
  WillModify();
  DidModify();
  return NS_OK;
}
Beispiel #14
0
NS_IMETHODIMP
nsSVGLength::SetValueAsString(const nsAString & aValueAsString)
{
  nsresult rv = NS_OK;

  char *str = ToNewCString(aValueAsString);

  char* number = str;
  while (*number && isspace(*number))
    ++number;

  if (*number) {
    char *rest;
    float value = float(PR_strtod(number, &rest));
    if (rest!=number) {
      const char* unitStr = nsCRT::strtok(rest, "\x20\x9\xD\xA", &rest);
      PRUint16 unitType = SVG_LENGTHTYPE_UNKNOWN;
      if (!unitStr || *unitStr=='\0') {
        unitType = SVG_LENGTHTYPE_NUMBER;
      } else {
        nsCOMPtr<nsIAtom> unitAtom = do_GetAtom(unitStr);
        if (unitAtom == nsGkAtoms::px)
          unitType = SVG_LENGTHTYPE_PX;
        else if (unitAtom == nsGkAtoms::mm)
          unitType = SVG_LENGTHTYPE_MM;
        else if (unitAtom == nsGkAtoms::cm)
          unitType = SVG_LENGTHTYPE_CM;
        else if (unitAtom == nsGkAtoms::in)
          unitType = SVG_LENGTHTYPE_IN;
        else if (unitAtom == nsGkAtoms::pt)
          unitType = SVG_LENGTHTYPE_PT;
        else if (unitAtom == nsGkAtoms::pc)
          unitType = SVG_LENGTHTYPE_PC;
        else if (unitAtom == nsGkAtoms::em)
          unitType = SVG_LENGTHTYPE_EMS;
        else if (unitAtom == nsGkAtoms::ex)
          unitType = SVG_LENGTHTYPE_EXS;
        else if (unitAtom == nsGkAtoms::percentage)
          unitType = SVG_LENGTHTYPE_PERCENTAGE;
      }
      if (IsValidUnitType(unitType) && NS_FloatIsFinite(value)) {
        WillModify();
        mValueInSpecifiedUnits = value;
        mSpecifiedUnitType     = unitType;
        DidModify();
      } else { // parse error
        // not a valid unit type
        rv = NS_ERROR_DOM_SYNTAX_ERR;
      }
    }
    else { // parse error
      // no number
      rv = NS_ERROR_DOM_SYNTAX_ERR;
    }
  }

  nsMemory::Free(str);

  return rv;
}
NS_INTERFACE_MAP_END

//----------------------------------------------------------------------
// nsISVGValue methods:

NS_IMETHODIMP
nsSVGPathSegList::SetValueString(const nsAString& aValue)
{
  nsresult rv;
  
  WillModify();
  ReleaseSegments(PR_FALSE);
  nsSVGPathDataParserToDOM parser(&mSegments);
  rv = parser.Parse(aValue);

  PRInt32 count = mSegments.Count();
  for (PRInt32 i=0; i<count; ++i) {
    nsSVGPathSeg* seg = static_cast<nsSVGPathSeg*>(mSegments.ObjectAt(i));
    seg->SetCurrentList(this);
  }

  if (NS_FAILED(rv)) {
    NS_ERROR("path data parse error!");
    ReleaseSegments(PR_FALSE);
  }
  DidModify();
  return rv;
}
NS_IMETHODIMP nsSVGRect::SetWidth(float aWidth)
{
  NS_ENSURE_FINITE(aWidth, NS_ERROR_ILLEGAL_VALUE);
  WillModify();
  mWidth = aWidth;
  DidModify();
  return NS_OK;
}
NS_IMETHODIMP nsSVGRect::SetX(float aX)
{
  NS_ENSURE_FINITE(aX, NS_ERROR_ILLEGAL_VALUE);
  WillModify();
  mX = aX;
  DidModify();
  return NS_OK;
}
NS_IMETHODIMP nsSVGRect::SetY(float aY)
{
  NS_ENSURE_FINITE(aY, NS_ERROR_ILLEGAL_VALUE);
  WillModify();
  mY = aY;
  DidModify();
  return NS_OK;
}
NS_IMETHODIMP nsSVGRect::SetHeight(float aHeight)
{
  NS_ENSURE_FINITE(aHeight, NS_ERROR_ILLEGAL_VALUE);
  WillModify();
  mHeight = aHeight;
  DidModify();
  return NS_OK;
}
Beispiel #20
0
nsSVGPatternFrame::~nsSVGPatternFrame()
{
  WillModify(mod_die);
  if (mNextPattern)
    mNextPattern->RemoveObserver(this);

  // Notify the world that we're dying
  DidModify(mod_die);
}
void
nsSVGPathSegList::RemoveElementAt(PRInt32 index)
{
  WillModify();
  nsSVGPathSeg* seg = static_cast<nsSVGPathSeg*>(mSegments.ObjectAt(index));
  seg->SetCurrentList(nsnull);
  mSegments.RemoveObjectAt(index);
  DidModify();
}
Beispiel #22
0
NS_IMETHODIMP
nsSVGLength::SetValueInSpecifiedUnits(float aValueInSpecifiedUnits)
{
  NS_ENSURE_FINITE(aValueInSpecifiedUnits, NS_ERROR_ILLEGAL_VALUE);
  WillModify();
  mValueInSpecifiedUnits = aValueInSpecifiedUnits;
  DidModify();
  return NS_OK;
}
Beispiel #23
0
void
nsSVGPathSegList::AppendElement(nsIDOMSVGPathSeg* aElement)
{
  WillModify();
  NS_ADDREF(aElement);
  mSegments.AppendElement((void*)aElement);
  nsCOMPtr<nsISVGValue> val = do_QueryInterface(aElement);
  if (val)
    val->AddObserver(this);
  DidModify();
}
void
nsSVGPathSegList::InsertElementAt(nsSVGPathSeg* aElement, PRInt32 index)
{
  WillModify();
  // XXX: we should only remove an item from its current list if we
  // successfully added it to this list
  RemoveFromCurrentList(aElement);
  mSegments.InsertObjectAt(aElement, index);
  aElement->SetCurrentList(this);
  DidModify();
}
void
nsSVGPathSegList::AppendElement(nsSVGPathSeg* aElement)
{
  WillModify();
  // XXX: we should only remove an item from its current list if we
  // successfully added it to this list
  RemoveFromCurrentList(aElement);
  mSegments.AppendObject(aElement);
  aElement->SetCurrentList(this);
  DidModify();
}
Beispiel #26
0
void
nsSVGPathSegList::InsertElementAt(nsIDOMSVGPathSeg* aElement, PRInt32 index)
{
  WillModify();
  NS_ADDREF(aElement);
  mSegments.InsertElementAt((void*)aElement, index);
  nsCOMPtr<nsISVGValue> val = do_QueryInterface(aElement);
  if (val)
    val->AddObserver(this);
  DidModify();
}
void
nsSVGLengthList::RemoveElementAt(PRInt32 index)
{
  WillModify();
  nsISVGLength* length = ElementAt(index);
  NS_ASSERTION(length, "null length");
  NS_REMOVE_SVGVALUE_OBSERVER(length);
  mLengths.RemoveElementAt(index);
  NS_RELEASE(length);
  DidModify();
}
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;
}
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;
}
Beispiel #30
0
void
nsSVGPathSegList::RemoveElementAt(PRInt32 index)
{
  WillModify();
  nsIDOMSVGPathSeg* seg = ElementAt(index);
  NS_ASSERTION(seg, "null pathsegment");
  nsCOMPtr<nsISVGValue> val = do_QueryInterface(seg);
  if (val)
    val->RemoveObserver(this);
  mSegments.RemoveElementAt(index);
  NS_RELEASE(seg);
  DidModify();
}