Bug 338060 - Move marker region to marker property. r=longsonr, sr=roc

This commit is contained in:
tor%cs.brown.edu 2006-05-17 05:26:05 +00:00
parent 6ae01bf56d
commit bf28ef1191
2 changed files with 67 additions and 60 deletions

View File

@ -64,6 +64,7 @@
#include "nsSVGGraphicElement.h"
struct nsSVGMarkerProperty {
nsCOMPtr<nsISVGRendererRegion> mMarkerRegion;
nsISVGMarkerFrame *mMarkerStart;
nsISVGMarkerFrame *mMarkerMid;
nsISVGMarkerFrame *mMarkerEnd;
@ -149,6 +150,15 @@ nsSVGPathGeometryFrame::DidSetStyleContext()
nsSVGUtils::StyleEffects(this);
if (GetStateBits() & NS_STATE_SVG_HAS_MARKERS) {
nsSVGMarkerProperty *property;
property = NS_STATIC_CAST(nsSVGMarkerProperty *,
GetProperty(nsGkAtoms::marker));
if (property->mMarkerRegion) {
nsISVGOuterSVGFrame *outerSVGFrame = nsSVGUtils::GetOuterSVGFrame(this);
if (outerSVGFrame)
outerSVGFrame->InvalidateRegion(property->mMarkerRegion, PR_TRUE);
}
DeleteProperty(nsGkAtoms::marker);
RemoveStateBits(NS_STATE_SVG_HAS_MARKERS);
}
@ -205,24 +215,14 @@ MarkerPropertyDtor(void *aObject, nsIAtom *aPropertyName,
delete property;
}
void
nsSVGPathGeometryFrame::GetMarkerFrames(nsISVGMarkerFrame **markerStart,
nsISVGMarkerFrame **markerMid,
nsISVGMarkerFrame **markerEnd)
nsSVGMarkerProperty *
nsSVGPathGeometryFrame::GetMarkerProperty()
{
*markerStart = *markerMid = *markerEnd = nsnull;
if (GetStateBits() & NS_STATE_SVG_HAS_MARKERS)
return NS_STATIC_CAST(nsSVGMarkerProperty *,
GetProperty(nsGkAtoms::marker));
if (GetStateBits() & NS_STATE_SVG_HAS_MARKERS) {
nsSVGMarkerProperty *property;
property = NS_STATIC_CAST(nsSVGMarkerProperty *,
GetProperty(nsGkAtoms::marker));
if (property) {
*markerStart = property->mMarkerStart;
*markerMid = property->mMarkerMid;
*markerEnd = property->mMarkerEnd;
}
}
return nsnull;
}
void
@ -287,13 +287,15 @@ nsSVGPathGeometryFrame::PaintSVG(nsISVGRendererCanvas* canvas)
if (markable) {
// Marker Property is added lazily and may have been removed by a restyle
UpdateMarkerProperty();
nsISVGMarkerFrame *markerEnd, *markerMid, *markerStart;
GetMarkerFrames(&markerStart, &markerMid, &markerEnd);
nsSVGMarkerProperty *property = GetMarkerProperty();
if (markerEnd || markerMid || markerStart) {
// need to set this up with the first draw
if (!mMarkerRegion)
mMarkerRegion = GetCoveredRegion();
if (property &&
(property->mMarkerEnd ||
property->mMarkerMid ||
property->mMarkerStart)) {
// need to set up marker region with the first draw
if (!property->mMarkerRegion)
property->mMarkerRegion = GetCoveredRegion();
float strokeWidth = GetStrokeWidth();
@ -302,15 +304,18 @@ nsSVGPathGeometryFrame::PaintSVG(nsISVGRendererCanvas* canvas)
PRUint32 num = marks.Count();
if (num && markerStart)
markerStart->PaintMark(canvas, this, (nsSVGMark *)marks[0], strokeWidth);
if (num && property->mMarkerStart)
property->mMarkerStart->PaintMark(canvas, this,
(nsSVGMark *)marks[0], strokeWidth);
if (num && markerMid)
if (num && property->mMarkerMid)
for (PRUint32 i = 1; i < num - 1; i++)
markerMid->PaintMark(canvas, this, (nsSVGMark *)marks[i], strokeWidth);
property->mMarkerMid->PaintMark(canvas, this,
(nsSVGMark *)marks[i], strokeWidth);
if (num && markerEnd)
markerEnd->PaintMark(canvas, this, (nsSVGMark *)marks[num-1], strokeWidth);
if (num && property->mMarkerEnd)
property->mMarkerEnd->PaintMark(canvas, this,
(nsSVGMark *)marks[num-1], strokeWidth);
}
}
@ -348,10 +353,12 @@ nsSVGPathGeometryFrame::GetCoveredRegion()
CallQueryInterface(this, &markable);
if (markable) {
nsISVGMarkerFrame *markerEnd, *markerMid, *markerStart;
GetMarkerFrames(&markerStart, &markerMid, &markerEnd);
nsSVGMarkerProperty *property = GetMarkerProperty();
if (!markerEnd && !markerMid && !markerStart)
if (!property ||
(!property->mMarkerEnd &&
!property->mMarkerMid &&
!property->mMarkerStart))
return region;
float strokeWidth = GetStrokeWidth();
@ -361,9 +368,11 @@ nsSVGPathGeometryFrame::GetCoveredRegion()
PRUint32 num = marks.Count();
if (num && markerStart) {
if (num && property->mMarkerStart) {
nsCOMPtr<nsISVGRendererRegion> mark;
mark = markerStart->RegionMark(this, (nsSVGMark *)marks[0], strokeWidth);
mark = property->mMarkerStart->RegionMark(this,
(nsSVGMark *)marks[0],
strokeWidth);
if (mark) {
nsCOMPtr<nsISVGRendererRegion> tmp = dont_AddRef(region);
@ -371,10 +380,12 @@ nsSVGPathGeometryFrame::GetCoveredRegion()
}
}
if (num && markerMid)
if (num && property->mMarkerMid)
for (PRUint32 i = 1; i < num - 1; i++) {
nsCOMPtr<nsISVGRendererRegion> mark;
mark = markerMid->RegionMark(this, (nsSVGMark *)marks[i], strokeWidth);
mark = property->mMarkerMid->RegionMark(this,
(nsSVGMark *)marks[i],
strokeWidth);
if (mark) {
nsCOMPtr<nsISVGRendererRegion> tmp = dont_AddRef(region);
@ -382,9 +393,11 @@ nsSVGPathGeometryFrame::GetCoveredRegion()
}
}
if (num && markerEnd) {
if (num && property->mMarkerEnd) {
nsCOMPtr<nsISVGRendererRegion> mark;
mark = markerEnd->RegionMark(this, (nsSVGMark *)marks[num-1], strokeWidth);
mark = property->mMarkerEnd->RegionMark(this,
(nsSVGMark *)marks[num-1],
strokeWidth);
if (mark) {
nsCOMPtr<nsISVGRendererRegion> tmp = dont_AddRef(region);
@ -666,29 +679,27 @@ nsSVGPathGeometryFrame::UpdateGraphic(PRUint32 flags,
if (filter_region) {
outerSVGFrame->InvalidateRegion(filter_region, PR_TRUE);
} else {
if (mMarkerRegion) {
outerSVGFrame->InvalidateRegion(mMarkerRegion, PR_TRUE);
mMarkerRegion = nsnull;
}
nsISVGMarkable *markable;
CallQueryInterface(this, &markable);
nsSVGMarkerProperty *property = GetMarkerProperty();
if (markable) {
nsISVGMarkerFrame *markerEnd, *markerMid, *markerStart;
GetMarkerFrames(&markerStart, &markerMid, &markerEnd);
if (markerEnd || markerMid || markerStart) {
mMarkerRegion = GetCoveredRegion();
if (mMarkerRegion)
outerSVGFrame->InvalidateRegion(mMarkerRegion, PR_TRUE);
if (property) {
if (property->mMarkerRegion) {
outerSVGFrame->InvalidateRegion(property->mMarkerRegion, PR_TRUE);
property->mMarkerRegion = nsnull;
}
if (property->mMarkerEnd ||
property->mMarkerMid ||
property->mMarkerStart) {
property->mMarkerRegion = GetCoveredRegion();
if (property->mMarkerRegion)
outerSVGFrame->InvalidateRegion(property->mMarkerRegion, PR_TRUE);
return NS_OK;
}
}
if (dirty_region)
outerSVGFrame->InvalidateRegion(dirty_region, PR_TRUE);
}
if (dirty_region)
outerSVGFrame->InvalidateRegion(dirty_region, PR_TRUE);
}
return NS_OK;

View File

@ -134,12 +134,8 @@ protected:
NS_IMETHOD InitSVG();
nsISVGRendererPathGeometry *GetGeometry();
nsCOMPtr<nsISVGRendererRegion> mMarkerRegion;
private:
void GetMarkerFrames(nsISVGMarkerFrame **markerStart,
nsISVGMarkerFrame **markerMid,
nsISVGMarkerFrame **markerEnd);
nsSVGMarkerProperty *GetMarkerProperty();
void GetMarkerFromStyle(nsISVGMarkerFrame **aResult,
nsSVGMarkerProperty *property,
nsIURI *aURI);