2007-03-22 10:30:00 -07:00
|
|
|
/* -*- 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 the Mozilla SVG project.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is IBM Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* 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 "nsSVGPathGeometryFrame.h"
|
|
|
|
#include "imgIContainer.h"
|
|
|
|
#include "nsStubImageDecoderObserver.h"
|
|
|
|
#include "nsImageLoadingContent.h"
|
|
|
|
#include "nsIDOMSVGImageElement.h"
|
2009-04-05 02:52:14 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2009-01-04 17:19:38 -08:00
|
|
|
#include "nsSVGImageElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsSVGUtils.h"
|
|
|
|
#include "gfxContext.h"
|
2009-07-23 01:35:59 -07:00
|
|
|
#include "gfxMatrix.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2010-08-20 12:29:01 -07:00
|
|
|
#include "gfxPlatform.h"
|
2010-12-19 16:45:29 -08:00
|
|
|
#include "nsSVGSVGElement.h"
|
2011-10-19 08:37:49 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsSVGImageFrame;
|
|
|
|
|
|
|
|
class nsSVGImageListener : public nsStubImageDecoderObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsSVGImageListener(nsSVGImageFrame *aFrame);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
// imgIDecoderObserver (override nsStubImageDecoderObserver)
|
|
|
|
NS_IMETHOD OnStopDecode(imgIRequest *aRequest, nsresult status,
|
|
|
|
const PRUnichar *statusArg);
|
|
|
|
// imgIContainerObserver (override nsStubImageDecoderObserver)
|
2010-08-13 21:09:48 -07:00
|
|
|
NS_IMETHOD FrameChanged(imgIContainer *aContainer,
|
|
|
|
const nsIntRect *aDirtyRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
// imgIContainerObserver (override nsStubImageDecoderObserver)
|
|
|
|
NS_IMETHOD OnStartContainer(imgIRequest *aRequest,
|
|
|
|
imgIContainer *aContainer);
|
|
|
|
|
|
|
|
void SetFrame(nsSVGImageFrame *frame) { mFrame = frame; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsSVGImageFrame *mFrame;
|
|
|
|
};
|
|
|
|
|
2011-10-19 08:37:49 -07:00
|
|
|
typedef nsSVGPathGeometryFrame nsSVGImageFrameBase;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-19 08:37:49 -07:00
|
|
|
class nsSVGImageFrame : public nsSVGImageFrameBase
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
friend nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-07-13 02:32:37 -07:00
|
|
|
protected:
|
2011-10-19 08:37:49 -07:00
|
|
|
nsSVGImageFrame(nsStyleContext* aContext) : nsSVGImageFrameBase(aContext) {}
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual ~nsSVGImageFrame();
|
|
|
|
|
|
|
|
public:
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsISVGChildFrame interface:
|
2008-10-20 01:42:03 -07:00
|
|
|
NS_IMETHOD PaintSVG(nsSVGRenderState *aContext, const nsIntRect *aDirtyRect);
|
2008-08-25 02:23:54 -07:00
|
|
|
NS_IMETHOD_(nsIFrame*) GetFrameForPoint(const nsPoint &aPoint);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsSVGPathGeometryFrame methods:
|
2009-08-31 04:26:23 -07:00
|
|
|
NS_IMETHOD UpdateCoveredRegion();
|
2011-07-08 06:20:14 -07:00
|
|
|
virtual PRUint16 GetHitTestFlags();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIFrame interface:
|
|
|
|
NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType);
|
2007-08-30 10:01:37 -07:00
|
|
|
NS_IMETHOD Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
|
|
|
* @see nsGkAtoms::svgImageFrame
|
|
|
|
*/
|
|
|
|
virtual nsIAtom* GetType() const;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGImage"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
2010-12-19 16:45:29 -08:00
|
|
|
gfxMatrix GetRasterImageTransform(PRInt32 aNativeWidth,
|
|
|
|
PRInt32 aNativeHeight);
|
|
|
|
gfxMatrix GetVectorImageTransform();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool TransformContextForPainting(gfxContext* aGfxContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<imgIDecoderObserver> mListener;
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> mImageContainer;
|
|
|
|
|
|
|
|
friend class nsSVGImageListener;
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
|
|
|
nsIFrame*
|
2009-01-19 10:31:34 -08:00
|
|
|
NS_NewSVGImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return new (aPresShell) nsSVGImageFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGImageFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGImageFrame::~nsSVGImageFrame()
|
|
|
|
{
|
|
|
|
// set the frame to null so we don't send messages to a dead object.
|
|
|
|
if (mListener) {
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (imageLoader) {
|
2011-01-31 20:50:01 -08:00
|
|
|
// Push a null JSContext on the stack so that code that runs
|
|
|
|
// within the below code doesn't think it's being called by
|
|
|
|
// JS. See bug 604262.
|
|
|
|
nsCxPusher pusher;
|
|
|
|
pusher.PushNull();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
imageLoader->RemoveObserver(mListener);
|
|
|
|
}
|
2007-07-08 00:08:04 -07:00
|
|
|
reinterpret_cast<nsSVGImageListener*>(mListener.get())->SetFrame(nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
mListener = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-08-30 10:01:37 -07:00
|
|
|
nsSVGImageFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-01-19 10:31:34 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIDOMSVGImageElement> image = do_QueryInterface(aContent);
|
|
|
|
NS_ASSERTION(image, "Content is not an SVG image!");
|
|
|
|
#endif
|
|
|
|
|
2011-10-19 08:37:49 -07:00
|
|
|
nsresult rv = nsSVGImageFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
mListener = new nsSVGImageListener(this);
|
|
|
|
if (!mListener) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED);
|
2011-01-31 20:50:01 -08:00
|
|
|
|
|
|
|
// Push a null JSContext on the stack so that code that runs within
|
|
|
|
// the below code doesn't think it's being called by JS. See bug
|
|
|
|
// 604262.
|
|
|
|
nsCxPusher pusher;
|
|
|
|
pusher.PushNull();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
imageLoader->AddObserver(mListener);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGImageFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aModType)
|
|
|
|
{
|
2011-10-19 08:37:49 -07:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None &&
|
|
|
|
(aAttribute == nsGkAtoms::x ||
|
|
|
|
aAttribute == nsGkAtoms::y ||
|
|
|
|
aAttribute == nsGkAtoms::width ||
|
|
|
|
aAttribute == nsGkAtoms::height ||
|
|
|
|
aAttribute == nsGkAtoms::preserveAspectRatio)) {
|
|
|
|
nsSVGUtils::UpdateGraphic(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aNameSpaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
2011-10-29 01:18:25 -07:00
|
|
|
|
|
|
|
// Prevent setting image.src by exiting early
|
|
|
|
if (nsContentUtils::IsImageSrcSetDisabled()) {
|
2011-10-19 08:37:49 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsSVGImageElement *element = static_cast<nsSVGImageElement*>(mContent);
|
|
|
|
|
|
|
|
if (element->mStringAttributes[nsSVGImageElement::HREF].IsExplicitlySet()) {
|
|
|
|
element->LoadSVGImage(true, true);
|
|
|
|
} else {
|
|
|
|
element->CancelImageRequests(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsSVGImageFrameBase::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
gfxMatrix
|
2010-12-19 16:45:29 -08:00
|
|
|
nsSVGImageFrame::GetRasterImageTransform(PRInt32 aNativeWidth, PRInt32 aNativeHeight)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
float x, y, width, height;
|
2009-01-04 17:19:38 -08:00
|
|
|
nsSVGImageElement *element = static_cast<nsSVGImageElement*>(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
element->GetAnimatedLengthValues(&x, &y, &width, &height, nsnull);
|
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
gfxMatrix viewBoxTM =
|
2010-02-07 18:28:01 -08:00
|
|
|
nsSVGUtils::GetViewBoxTransform(element,
|
|
|
|
width, height,
|
2010-10-26 01:19:31 -07:00
|
|
|
0, 0, aNativeWidth, aNativeHeight,
|
2009-07-23 01:35:59 -07:00
|
|
|
element->mPreserveAspectRatio);
|
|
|
|
|
|
|
|
return viewBoxTM * gfxMatrix().Translate(gfxPoint(x, y)) * GetCanvasTM();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
gfxMatrix
|
|
|
|
nsSVGImageFrame::GetVectorImageTransform()
|
|
|
|
{
|
|
|
|
float x, y, width, height;
|
|
|
|
nsSVGImageElement *element = static_cast<nsSVGImageElement*>(mContent);
|
|
|
|
element->GetAnimatedLengthValues(&x, &y, &width, &height, nsnull);
|
|
|
|
|
|
|
|
// No viewBoxTM needed here -- our height/width overrides any concept of
|
|
|
|
// "native size" that the SVG image has, and it will handle viewBox and
|
|
|
|
// preserveAspectRatio on its own once we give it a region to draw into.
|
|
|
|
|
|
|
|
return gfxMatrix().Translate(gfxPoint(x, y)) * GetCanvasTM();
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-12-19 16:45:29 -08:00
|
|
|
nsSVGImageFrame::TransformContextForPainting(gfxContext* aGfxContext)
|
|
|
|
{
|
|
|
|
gfxMatrix imageTransform;
|
|
|
|
if (mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) {
|
|
|
|
imageTransform = GetVectorImageTransform();
|
|
|
|
} else {
|
|
|
|
PRInt32 nativeWidth, nativeHeight;
|
|
|
|
if (NS_FAILED(mImageContainer->GetWidth(&nativeWidth)) ||
|
|
|
|
NS_FAILED(mImageContainer->GetHeight(&nativeHeight)) ||
|
|
|
|
nativeWidth == 0 || nativeHeight == 0) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-12-19 16:45:29 -08:00
|
|
|
}
|
|
|
|
imageTransform = GetRasterImageTransform(nativeWidth, nativeHeight);
|
|
|
|
}
|
|
|
|
|
2011-01-10 21:57:19 -08:00
|
|
|
if (imageTransform.IsSingular()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-01-10 21:57:19 -08:00
|
|
|
}
|
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
// NOTE: We need to cancel out the effects of Full-Page-Zoom, or else
|
|
|
|
// it'll get applied an extra time by DrawSingleUnscaledImage.
|
|
|
|
nscoord appUnitsPerDevPx = PresContext()->AppUnitsPerDevPixel();
|
|
|
|
gfxFloat pageZoomFactor =
|
|
|
|
nsPresContext::AppUnitsToFloatCSSPixels(appUnitsPerDevPx);
|
|
|
|
aGfxContext->Multiply(imageTransform.Scale(pageZoomFactor, pageZoomFactor));
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-12-19 16:45:29 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods:
|
|
|
|
NS_IMETHODIMP
|
2008-10-20 01:42:03 -07:00
|
|
|
nsSVGImageFrame::PaintSVG(nsSVGRenderState *aContext,
|
|
|
|
const nsIntRect *aDirtyRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!GetStyleVisibility()->IsVisible())
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-12 08:40:46 -07:00
|
|
|
float x, y, width, height;
|
2010-12-19 16:45:29 -08:00
|
|
|
nsSVGImageElement *imgElem = static_cast<nsSVGImageElement*>(mContent);
|
|
|
|
imgElem->GetAnimatedLengthValues(&x, &y, &width, &height, nsnull);
|
2007-07-12 08:40:46 -07:00
|
|
|
if (width <= 0 || height <= 0)
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mImageContainer) {
|
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (imageLoader)
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
|
|
|
|
|
|
|
if (currentRequest)
|
|
|
|
currentRequest->GetImage(getter_AddRefs(mImageContainer));
|
|
|
|
}
|
|
|
|
|
2010-10-11 13:08:19 -07:00
|
|
|
if (mImageContainer) {
|
|
|
|
gfxContext* ctx = aContext->GetGfxContext();
|
|
|
|
gfxContextAutoSaveRestore autoRestorer(ctx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-30 02:02:38 -07:00
|
|
|
if (GetStyleDisplay()->IsScrollableOverflow()) {
|
2010-10-11 13:08:19 -07:00
|
|
|
gfxRect clipRect = nsSVGUtils::GetClipRectForFrame(this, x, y,
|
|
|
|
width, height);
|
|
|
|
nsSVGUtils::SetClipRect(ctx, GetCanvasTM(), clipRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
if (!TransformContextForPainting(ctx)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-10-11 13:08:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// fill-opacity doesn't affect <image>, so if we're allowed to
|
|
|
|
// optimize group opacity, the opacity used for compositing the
|
|
|
|
// image into the current canvas is just the group opacity.
|
|
|
|
float opacity = 1.0f;
|
|
|
|
if (nsSVGUtils::CanOptimizeOpacity(this)) {
|
|
|
|
opacity = GetStyleDisplay()->mOpacity;
|
|
|
|
}
|
|
|
|
|
2010-10-11 13:08:19 -07:00
|
|
|
if (opacity != 1.0f) {
|
|
|
|
ctx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
|
|
|
}
|
2008-03-12 10:19:51 -07:00
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
nscoord appUnitsPerDevPx = PresContext()->AppUnitsPerDevPixel();
|
2010-10-11 13:08:19 -07:00
|
|
|
nsRect dirtyRect; // only used if aDirtyRect is non-null
|
|
|
|
if (aDirtyRect) {
|
2010-10-22 15:55:04 -07:00
|
|
|
dirtyRect = aDirtyRect->ToAppUnits(appUnitsPerDevPx);
|
2010-10-22 09:52:41 -07:00
|
|
|
// Adjust dirtyRect to match our local coordinate system.
|
|
|
|
dirtyRect.MoveBy(-mRect.TopLeft());
|
2010-10-11 13:08:19 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-10-11 13:08:19 -07:00
|
|
|
// XXXbholley - I don't think huge images in SVGs are common enough to
|
|
|
|
// warrant worrying about the responsiveness impact of doing synchronous
|
|
|
|
// decodes. The extra code complexity of determinining when we want to
|
|
|
|
// force sync probably just isn't worth it, so always pass FLAG_SYNC_DECODE
|
2010-12-19 16:45:29 -08:00
|
|
|
PRUint32 drawFlags = imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
|
|
|
|
if (mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) {
|
2010-12-19 16:45:29 -08:00
|
|
|
nsIFrame* imgRootFrame = mImageContainer->GetRootLayoutFrame();
|
|
|
|
if (!imgRootFrame) {
|
|
|
|
// bad image (e.g. XML parse error in image's SVG file)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Grab root node (w/ sanity-check to make sure it exists & is <svg>)
|
|
|
|
nsSVGSVGElement* rootSVGElem =
|
|
|
|
static_cast<nsSVGSVGElement*>(imgRootFrame->GetContent());
|
|
|
|
if (!rootSVGElem || rootSVGElem->GetNameSpaceID() != kNameSpaceID_SVG ||
|
|
|
|
rootSVGElem->Tag() != nsGkAtoms::svg) {
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ABORT_IF_FALSE(false, "missing or non-<svg> root node!!");
|
|
|
|
return false;
|
2010-12-19 16:45:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Override preserveAspectRatio in our helper document
|
|
|
|
// XXXdholbert We should technically be overriding the helper doc's clip
|
|
|
|
// and overflow properties here, too. See bug 272288 comment 36.
|
|
|
|
rootSVGElem->SetImageOverridePreserveAspectRatio(
|
|
|
|
imgElem->mPreserveAspectRatio.GetAnimValue());
|
2010-12-19 16:45:29 -08:00
|
|
|
nsRect destRect(0, 0,
|
|
|
|
appUnitsPerDevPx * width,
|
|
|
|
appUnitsPerDevPx * height);
|
|
|
|
|
|
|
|
// Note: Can't use DrawSingleUnscaledImage for the TYPE_VECTOR case.
|
|
|
|
// That method needs our image to have a fixed native width & height,
|
|
|
|
// and that's not always true for TYPE_VECTOR images.
|
|
|
|
nsLayoutUtils::DrawSingleImage(
|
|
|
|
aContext->GetRenderingContext(this),
|
|
|
|
mImageContainer,
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(this),
|
|
|
|
destRect,
|
|
|
|
aDirtyRect ? dirtyRect : destRect,
|
|
|
|
drawFlags);
|
2010-12-19 16:45:29 -08:00
|
|
|
|
|
|
|
rootSVGElem->ClearImageOverridePreserveAspectRatio();
|
2010-12-19 16:45:29 -08:00
|
|
|
} else { // mImageContainer->GetType() == TYPE_RASTER
|
|
|
|
nsLayoutUtils::DrawSingleUnscaledImage(
|
|
|
|
aContext->GetRenderingContext(this),
|
|
|
|
mImageContainer,
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(this),
|
|
|
|
nsPoint(0, 0),
|
|
|
|
aDirtyRect ? &dirtyRect : nsnull,
|
|
|
|
drawFlags);
|
|
|
|
}
|
2010-10-11 13:08:19 -07:00
|
|
|
|
|
|
|
if (opacity != 1.0f) {
|
|
|
|
ctx->PopGroupToSource();
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
ctx->Paint(opacity);
|
|
|
|
}
|
|
|
|
// gfxContextAutoSaveRestore goes out of scope & cleans up our gfxContext
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2008-08-25 02:23:54 -07:00
|
|
|
NS_IMETHODIMP_(nsIFrame*)
|
|
|
|
nsSVGImageFrame::GetFrameForPoint(const nsPoint &aPoint)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-12-19 16:45:29 -08:00
|
|
|
// Special case for raster images -- we only want to accept points that fall
|
|
|
|
// in the underlying image's (transformed) native bounds. That region
|
|
|
|
// doesn't necessarily map to our <image> element's [x,y,width,height]. So,
|
|
|
|
// we have to look up the native image size & our image transform in order
|
|
|
|
// to filter out points that fall outside that area.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (GetStyleDisplay()->IsScrollableOverflow() && mImageContainer) {
|
2010-12-19 16:45:29 -08:00
|
|
|
if (mImageContainer->GetType() == imgIContainer::TYPE_RASTER) {
|
|
|
|
PRInt32 nativeWidth, nativeHeight;
|
|
|
|
if (NS_FAILED(mImageContainer->GetWidth(&nativeWidth)) ||
|
|
|
|
NS_FAILED(mImageContainer->GetHeight(&nativeHeight)) ||
|
|
|
|
nativeWidth == 0 || nativeHeight == 0) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nsSVGUtils::HitTestRect(
|
|
|
|
GetRasterImageTransform(nativeWidth, nativeHeight),
|
|
|
|
0, 0, nativeWidth, nativeHeight,
|
|
|
|
PresContext()->AppUnitsToDevPixels(aPoint.x),
|
|
|
|
PresContext()->AppUnitsToDevPixels(aPoint.y))) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-12-19 16:45:29 -08:00
|
|
|
// The special case above doesn't apply to vector images, because they
|
|
|
|
// don't limit their drawing to explicit "native bounds" -- they have
|
|
|
|
// an infinite canvas on which to place content. So it's reasonable to
|
|
|
|
// just fall back on our <image> element's own bounds here.
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-19 08:37:49 -07:00
|
|
|
return nsSVGImageFrameBase::GetFrameForPoint(aPoint);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *
|
|
|
|
nsSVGImageFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::svgImageFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGPathGeometryFrame methods:
|
|
|
|
|
2009-08-31 04:26:23 -07:00
|
|
|
// Lie about our fill/stroke so that covered region and hit detection work properly
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGImageFrame::UpdateCoveredRegion()
|
|
|
|
{
|
2011-04-18 20:07:23 -07:00
|
|
|
mRect.SetEmpty();
|
2009-08-31 04:26:23 -07:00
|
|
|
|
2010-08-20 12:29:01 -07:00
|
|
|
gfxContext context(gfxPlatform::GetPlatform()->ScreenReferenceSurface());
|
2009-08-31 04:26:23 -07:00
|
|
|
|
|
|
|
GeneratePath(&context);
|
|
|
|
context.IdentityMatrix();
|
|
|
|
|
|
|
|
gfxRect extent = context.GetUserPathExtent();
|
|
|
|
|
|
|
|
if (!extent.IsEmpty()) {
|
|
|
|
mRect = nsSVGUtils::ToAppPixelRect(PresContext(), extent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRUint16
|
2011-07-08 06:20:14 -07:00
|
|
|
nsSVGImageFrame::GetHitTestFlags()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-07-08 06:20:14 -07:00
|
|
|
PRUint16 flags = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-26 20:53:35 -07:00
|
|
|
switch(GetStyleVisibility()->mPointerEvents) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_STYLE_POINTER_EVENTS_NONE:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEPAINTED:
|
2009-08-26 20:53:35 -07:00
|
|
|
case NS_STYLE_POINTER_EVENTS_AUTO:
|
2007-03-22 10:30:00 -07:00
|
|
|
if (GetStyleVisibility()->IsVisible()) {
|
|
|
|
/* XXX: should check pixel transparency */
|
2011-07-08 06:20:14 -07:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEFILL:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLESTROKE:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLE:
|
|
|
|
if (GetStyleVisibility()->IsVisible()) {
|
2011-07-08 06:20:14 -07:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_PAINTED:
|
|
|
|
/* XXX: should check pixel transparency */
|
2011-07-08 06:20:14 -07:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_FILL:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_STROKE:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_ALL:
|
2011-07-08 06:20:14 -07:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("not reached");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-08 06:20:14 -07:00
|
|
|
return flags;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGImageListener implementation
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS2(nsSVGImageListener,
|
|
|
|
imgIDecoderObserver,
|
|
|
|
imgIContainerObserver)
|
|
|
|
|
|
|
|
nsSVGImageListener::nsSVGImageListener(nsSVGImageFrame *aFrame) : mFrame(aFrame)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsSVGImageListener::OnStopDecode(imgIRequest *aRequest,
|
|
|
|
nsresult status,
|
|
|
|
const PRUnichar *statusArg)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGUtils::UpdateGraphic(mFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsSVGImageListener::FrameChanged(imgIContainer *aContainer,
|
2010-08-13 21:09:48 -07:00
|
|
|
const nsIntRect *aDirtyRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGUtils::UpdateGraphic(mFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsSVGImageListener::OnStartContainer(imgIRequest *aRequest,
|
|
|
|
imgIContainer *aContainer)
|
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
mFrame->mImageContainer = aContainer;
|
2008-04-08 05:51:19 -07:00
|
|
|
nsSVGUtils::UpdateGraphic(mFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|