2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-03-26 04:58:59 -07:00
|
|
|
// Keep in (case-insensitive) order:
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "gfxPlatform.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "imgIContainer.h"
|
2013-01-06 01:32:01 -08:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2009-04-05 02:52:14 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2012-10-12 09:11:22 -07:00
|
|
|
#include "imgINotificationObserver.h"
|
2012-03-20 05:15:53 -07:00
|
|
|
#include "nsSVGEffects.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGPathGeometryFrame.h"
|
2013-01-09 15:02:45 -08:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2012-03-26 04:58:59 -07:00
|
|
|
#include "nsSVGUtils.h"
|
2012-09-22 12:26:05 -07:00
|
|
|
#include "SVGContentUtils.h"
|
2013-02-28 12:22:43 -08:00
|
|
|
#include "SVGImageContext.h"
|
2013-01-06 01:32:01 -08:00
|
|
|
#include "mozilla/dom/SVGImageElement.h"
|
2013-01-31 15:11:49 -08:00
|
|
|
#include "nsContentUtils.h"
|
2011-10-19 08:37:49 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-01-06 01:32:01 -08:00
|
|
|
using namespace mozilla::dom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsSVGImageFrame;
|
|
|
|
|
2012-10-12 09:11:22 -07:00
|
|
|
class nsSVGImageListener MOZ_FINAL : public imgINotificationObserver
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsSVGImageListener(nsSVGImageFrame *aFrame);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2012-10-12 09:11:22 -07:00
|
|
|
NS_DECL_IMGINOTIFICATIONOBSERVER
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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:
|
2012-03-02 00:28:59 -08:00
|
|
|
NS_IMETHOD PaintSVG(nsRenderingContext *aContext, const nsIntRect *aDirtyRect);
|
2008-08-25 02:23:54 -07:00
|
|
|
NS_IMETHOD_(nsIFrame*) GetFrameForPoint(const nsPoint &aPoint);
|
2012-07-21 17:01:44 -07:00
|
|
|
virtual void ReflowSVG();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsSVGPathGeometryFrame methods:
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual uint16_t GetHitTestFlags();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIFrame interface:
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType);
|
2013-03-19 18:47:48 -07:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2011-11-09 13:39:16 -08:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot);
|
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:
|
2012-08-22 08:56:38 -07:00
|
|
|
gfxMatrix GetRasterImageTransform(int32_t aNativeWidth,
|
|
|
|
int32_t aNativeHeight,
|
|
|
|
uint32_t aFor);
|
|
|
|
gfxMatrix GetVectorImageTransform(uint32_t aFor);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool TransformContextForPainting(gfxContext* aGfxContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-12 09:11:22 -07:00
|
|
|
nsCOMPtr<imgINotificationObserver> mListener;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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) {
|
|
|
|
imageLoader->RemoveObserver(mListener);
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
reinterpret_cast<nsSVGImageListener*>(mListener.get())->SetFrame(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
mListener = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
void
|
2007-08-30 10:01:37 -07:00
|
|
|
nsSVGImageFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-07 19:22:41 -08:00
|
|
|
NS_ASSERTION(aContent->IsSVG(nsGkAtoms::image),
|
|
|
|
"Content is not an SVG image!");
|
2009-01-19 10:31:34 -08:00
|
|
|
|
2013-03-19 18:47:48 -07:00
|
|
|
nsSVGImageFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2013-01-07 19:22:41 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mListener = new nsSVGImageListener(this);
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
2013-03-19 18:47:48 -07:00
|
|
|
if (!imageLoader) {
|
|
|
|
NS_RUNTIMEABORT("Why is this not an image loading content?");
|
|
|
|
}
|
2011-01-31 20:50:01 -08:00
|
|
|
|
2011-11-09 13:39:16 -08:00
|
|
|
// We should have a PresContext now, so let's notify our image loader that
|
|
|
|
// we need to register any image animations with the refresh driver.
|
|
|
|
imageLoader->FrameCreated(this);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
imageLoader->AddObserver(mListener);
|
|
|
|
}
|
|
|
|
|
2011-11-09 13:39:16 -08:00
|
|
|
/* virtual */ void
|
|
|
|
nsSVGImageFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader =
|
|
|
|
do_QueryInterface(nsFrame::mContent);
|
|
|
|
|
|
|
|
if (imageLoader) {
|
|
|
|
imageLoader->FrameDestroyed(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFrame::DestroyFrom(aDestructRoot);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIFrame methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGImageFrame::AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-03-20 05:15:53 -07:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::x ||
|
|
|
|
aAttribute == nsGkAtoms::y ||
|
|
|
|
aAttribute == nsGkAtoms::width ||
|
|
|
|
aAttribute == nsGkAtoms::height) {
|
2013-04-25 02:18:42 -07:00
|
|
|
nsSVGEffects::InvalidateRenderingObservers(this);
|
2012-11-28 01:42:13 -08:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-03-20 05:15:53 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (aAttribute == nsGkAtoms::preserveAspectRatio) {
|
2013-02-11 15:25:56 -08:00
|
|
|
// Don't invalidate (the layers code does that).
|
|
|
|
SchedulePaint();
|
2012-03-20 05:15:53 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-19 08:37:49 -07:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2013-01-06 01:32:01 -08:00
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
2011-10-19 08:37:49 -07:00
|
|
|
|
2013-01-06 01:32:01 -08:00
|
|
|
if (element->mStringAttributes[SVGImageElement::HREF].IsExplicitlySet()) {
|
2011-10-19 08:37:49 -07:00
|
|
|
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
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGImageFrame::GetRasterImageTransform(int32_t aNativeWidth,
|
|
|
|
int32_t aNativeHeight,
|
|
|
|
uint32_t aFor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
float x, y, width, height;
|
2013-01-06 01:32:01 -08:00
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
2012-07-30 07:20:58 -07:00
|
|
|
element->GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-23 01:35:59 -07:00
|
|
|
gfxMatrix viewBoxTM =
|
2013-03-03 00:11:03 -08:00
|
|
|
SVGContentUtils::GetViewBoxTransform(width, height,
|
2012-09-22 12:26:05 -07:00
|
|
|
0, 0, aNativeWidth, aNativeHeight,
|
|
|
|
element->mPreserveAspectRatio);
|
2009-07-23 01:35:59 -07:00
|
|
|
|
2012-06-30 04:20:46 -07:00
|
|
|
return viewBoxTM * gfxMatrix().Translate(gfxPoint(x, y)) * GetCanvasTM(aFor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
gfxMatrix
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGImageFrame::GetVectorImageTransform(uint32_t aFor)
|
2010-12-19 16:45:29 -08:00
|
|
|
{
|
|
|
|
float x, y, width, height;
|
2013-01-06 01:32:01 -08:00
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
2012-07-30 07:20:58 -07:00
|
|
|
element->GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2010-12-19 16:45:29 -08:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2012-06-30 04:20:46 -07:00
|
|
|
return gfxMatrix().Translate(gfxPoint(x, y)) * GetCanvasTM(aFor);
|
2010-12-19 16:45:29 -08:00
|
|
|
}
|
|
|
|
|
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) {
|
2012-06-30 04:20:46 -07:00
|
|
|
imageTransform = GetVectorImageTransform(FOR_PAINTING);
|
2010-12-19 16:45:29 -08:00
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nativeWidth, nativeHeight;
|
2010-12-19 16:45:29 -08:00
|
|
|
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
|
|
|
}
|
2012-06-30 04:20:46 -07:00
|
|
|
imageTransform =
|
|
|
|
GetRasterImageTransform(nativeWidth, nativeHeight, FOR_PAINTING);
|
2013-06-13 00:47:26 -07: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);
|
|
|
|
imageTransform.Scale(pageZoomFactor, pageZoomFactor);
|
2010-12-19 16:45:29 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-06-13 00:47:26 -07:00
|
|
|
aGfxContext->Multiply(imageTransform);
|
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
|
2012-03-02 00:28:59 -08:00
|
|
|
nsSVGImageFrame::PaintSVG(nsRenderingContext *aContext,
|
2008-10-20 01:42:03 -07:00
|
|
|
const nsIntRect *aDirtyRect)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
if (!StyleVisibility()->IsVisible())
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-12 08:40:46 -07:00
|
|
|
float x, y, width, height;
|
2013-01-06 01:32:01 -08:00
|
|
|
SVGImageElement *imgElem = static_cast<SVGImageElement*>(mContent);
|
2012-07-30 07:20:58 -07:00
|
|
|
imgElem->GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2012-03-03 01:21:09 -08:00
|
|
|
NS_ASSERTION(width > 0 && height > 0,
|
|
|
|
"Should only be painting things with valid width/height");
|
2007-07-12 08:40:46 -07:00
|
|
|
|
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) {
|
2012-03-02 00:28:59 -08:00
|
|
|
gfxContext* ctx = aContext->ThebesContext();
|
2010-10-11 13:08:19 -07:00
|
|
|
gfxContextAutoSaveRestore autoRestorer(ctx);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow()) {
|
2010-10-11 13:08:19 -07:00
|
|
|
gfxRect clipRect = nsSVGUtils::GetClipRectForFrame(this, x, y,
|
|
|
|
width, height);
|
2012-06-30 04:20:46 -07:00
|
|
|
nsSVGUtils::SetClipRect(ctx, GetCanvasTM(FOR_PAINTING), 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)) {
|
2013-02-16 13:51:02 -08:00
|
|
|
opacity = StyleDisplay()->mOpacity;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
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) {
|
2012-07-20 11:12:29 -07:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
|
2013-07-12 00:13:07 -07:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY),
|
2012-07-20 11:12:29 -07:00
|
|
|
"Display lists handle dirty rect intersection test");
|
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.
|
2012-02-10 04:33:46 -08:00
|
|
|
nsRect rootRect =
|
2012-06-30 04:20:46 -07:00
|
|
|
nsSVGUtils::TransformFrameRectToOuterSVG(mRect,
|
|
|
|
GetCanvasTM(FOR_PAINTING), PresContext());
|
2012-02-10 04:33:46 -08:00
|
|
|
dirtyRect.MoveBy(-rootRect.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
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t drawFlags = imgIContainer::FLAG_SYNC_DECODE;
|
2010-12-19 16:45:29 -08:00
|
|
|
|
|
|
|
if (mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) {
|
2013-02-28 12:22:43 -08:00
|
|
|
// Package up the attributes of this image element which can override the
|
|
|
|
// attributes of mImageContainer's internal SVG document.
|
|
|
|
SVGImageContext context(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(
|
2012-03-02 00:28:59 -08:00
|
|
|
aContext,
|
2010-12-19 16:45:29 -08:00
|
|
|
mImageContainer,
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(this),
|
|
|
|
destRect,
|
|
|
|
aDirtyRect ? dirtyRect : destRect,
|
2013-02-28 12:22:43 -08:00
|
|
|
&context,
|
2010-12-19 16:45:29 -08:00
|
|
|
drawFlags);
|
|
|
|
} else { // mImageContainer->GetType() == TYPE_RASTER
|
|
|
|
nsLayoutUtils::DrawSingleUnscaledImage(
|
2012-03-02 00:28:59 -08:00
|
|
|
aContext,
|
2010-12-19 16:45:29 -08:00
|
|
|
mImageContainer,
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(this),
|
|
|
|
nsPoint(0, 0),
|
2012-07-30 07:20:58 -07:00
|
|
|
aDirtyRect ? &dirtyRect : nullptr,
|
2010-12-19 16:45:29 -08:00
|
|
|
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.
|
2013-02-16 13:51:02 -08:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow() && mImageContainer) {
|
2010-12-19 16:45:29 -08:00
|
|
|
if (mImageContainer->GetType() == imgIContainer::TYPE_RASTER) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nativeWidth, nativeHeight;
|
2010-12-19 16:45:29 -08:00
|
|
|
if (NS_FAILED(mImageContainer->GetWidth(&nativeWidth)) ||
|
|
|
|
NS_FAILED(mImageContainer->GetHeight(&nativeHeight)) ||
|
|
|
|
nativeWidth == 0 || nativeHeight == 0) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-12-19 16:45:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!nsSVGUtils::HitTestRect(
|
2012-06-30 04:20:46 -07:00
|
|
|
GetRasterImageTransform(nativeWidth, nativeHeight,
|
|
|
|
FOR_HIT_TESTING),
|
2010-12-19 16:45:29 -08:00
|
|
|
0, 0, nativeWidth, nativeHeight,
|
|
|
|
PresContext()->AppUnitsToDevPixels(aPoint.x),
|
|
|
|
PresContext()->AppUnitsToDevPixels(aPoint.y))) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-12-19 16:45:29 -08:00
|
|
|
}
|
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
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
void
|
2012-07-21 17:01:44 -07:00
|
|
|
nsSVGImageFrame::ReflowSVG()
|
2009-08-31 04:26:23 -07:00
|
|
|
{
|
2012-07-21 17:01:44 -07:00
|
|
|
NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingReflowSVG(this),
|
|
|
|
"This call is probably a wasteful mistake");
|
2012-03-20 05:15:53 -07:00
|
|
|
|
2013-07-12 00:13:07 -07:00
|
|
|
NS_ABORT_IF_FALSE(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
2012-07-21 17:01:44 -07:00
|
|
|
"ReflowSVG mechanism not designed for this");
|
2012-03-20 05:15:53 -07:00
|
|
|
|
2012-07-21 17:01:44 -07:00
|
|
|
if (!nsSVGUtils::NeedsReflowSVG(this)) {
|
2012-03-20 05:15:53 -07:00
|
|
|
return;
|
|
|
|
}
|
2009-08-31 04:26:23 -07:00
|
|
|
|
2012-06-14 20:02:29 -07:00
|
|
|
gfxContext tmpCtx(gfxPlatform::GetPlatform()->ScreenReferenceSurface());
|
2009-08-31 04:26:23 -07:00
|
|
|
|
2012-12-20 05:49:54 -08:00
|
|
|
// We'd like to just pass the identity matrix to GeneratePath, but if
|
|
|
|
// this frame's user space size is _very_ large/small then the extents we
|
|
|
|
// obtain below might have overflowed or otherwise be broken. This would
|
|
|
|
// cause us to end up with a broken mRect and visual overflow rect and break
|
|
|
|
// painting of this frame. This is particularly noticeable if the transforms
|
|
|
|
// between us and our nsSVGOuterSVGFrame scale this frame to a reasonable
|
|
|
|
// size. To avoid this we sadly have to do extra work to account for the
|
|
|
|
// transforms between us and our nsSVGOuterSVGFrame, even though the
|
|
|
|
// overwhelming number of SVGs will never have this problem.
|
|
|
|
// XXX Will Azure eventually save us from having to do this?
|
|
|
|
gfxSize scaleFactors = GetCanvasTM(FOR_OUTERSVG_TM).ScaleFactors(true);
|
|
|
|
bool applyScaling = fabs(scaleFactors.width) >= 1e-6 &&
|
|
|
|
fabs(scaleFactors.height) >= 1e-6;
|
|
|
|
gfxMatrix scaling;
|
|
|
|
if (applyScaling) {
|
|
|
|
scaling.Scale(scaleFactors.width, scaleFactors.height);
|
2012-12-22 02:07:00 -08:00
|
|
|
}
|
|
|
|
tmpCtx.Save();
|
2012-12-20 05:49:54 -08:00
|
|
|
GeneratePath(&tmpCtx, scaling);
|
2012-12-22 02:07:00 -08:00
|
|
|
tmpCtx.Restore();
|
2012-06-14 20:02:29 -07:00
|
|
|
gfxRect extent = tmpCtx.GetUserPathExtent();
|
2012-12-20 05:49:54 -08:00
|
|
|
if (applyScaling) {
|
|
|
|
extent.Scale(1 / scaleFactors.width, 1 / scaleFactors.height);
|
|
|
|
}
|
2009-08-31 04:26:23 -07:00
|
|
|
|
|
|
|
if (!extent.IsEmpty()) {
|
2012-02-10 04:33:18 -08:00
|
|
|
mRect = nsLayoutUtils::RoundGfxRectToAppRect(extent,
|
2012-02-16 22:07:51 -08:00
|
|
|
PresContext()->AppUnitsPerCSSPixel());
|
2012-03-20 05:15:53 -07:00
|
|
|
} else {
|
|
|
|
mRect.SetEmpty();
|
2009-08-31 04:26:23 -07:00
|
|
|
}
|
|
|
|
|
2012-05-16 21:05:09 -07:00
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
|
|
|
// Make sure we have our filter property (if any) before calling
|
|
|
|
// FinishAndStoreOverflow (subsequent filter changes are handled off
|
|
|
|
// nsChangeHint_UpdateEffects):
|
|
|
|
nsSVGEffects::UpdateEffects(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect overflow = nsRect(nsPoint(0,0), mRect.Size());
|
|
|
|
nsOverflowAreas overflowAreas(overflow, overflow);
|
|
|
|
FinishAndStoreOverflow(overflowAreas, mRect.Size());
|
|
|
|
|
2012-03-20 05:15:53 -07:00
|
|
|
mState &= ~(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
|
2012-11-28 02:34:58 -08:00
|
|
|
// Invalidate, but only if this is not our first reflow (since if it is our
|
|
|
|
// first reflow then we haven't had our first paint yet).
|
|
|
|
if (!(GetParent()->GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
|
|
|
InvalidateFrame();
|
2012-03-20 05:15:53 -07:00
|
|
|
}
|
2009-08-31 04:26:23 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t
|
2011-07-08 06:20:14 -07:00
|
|
|
nsSVGImageFrame::GetHitTestFlags()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t flags = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
switch(StyleVisibility()->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:
|
2013-02-16 13:51:02 -08:00
|
|
|
if (StyleVisibility()->IsVisible()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
/* 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:
|
2013-02-16 13:51:02 -08:00
|
|
|
if (StyleVisibility()->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
|
|
|
|
|
2012-10-12 09:11:22 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(nsSVGImageListener, imgINotificationObserver)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsSVGImageListener::nsSVGImageListener(nsSVGImageFrame *aFrame) : mFrame(aFrame)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-12 09:11:22 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGImageListener::Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData)
|
2012-10-11 18:58:24 -07:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-12 09:11:23 -07:00
|
|
|
if (aType == imgINotificationObserver::LOAD_COMPLETE) {
|
2013-06-09 17:14:01 -07:00
|
|
|
mFrame->InvalidateFrame();
|
2013-04-25 02:18:42 -07:00
|
|
|
nsSVGEffects::InvalidateRenderingObservers(mFrame);
|
2012-11-28 01:42:13 -08:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(mFrame);
|
2012-10-12 09:11:22 -07:00
|
|
|
}
|
2012-10-11 18:58:24 -07:00
|
|
|
|
2012-10-12 09:11:23 -07:00
|
|
|
if (aType == imgINotificationObserver::FRAME_UPDATE) {
|
2012-10-12 09:11:22 -07:00
|
|
|
// No new dimensions, so we don't need to call
|
|
|
|
// nsSVGUtils::InvalidateAndScheduleBoundsUpdate.
|
|
|
|
nsSVGEffects::InvalidateRenderingObservers(mFrame);
|
2013-06-09 17:14:01 -07:00
|
|
|
mFrame->InvalidateFrame();
|
2012-10-12 09:11:22 -07:00
|
|
|
}
|
2012-10-11 18:58:24 -07:00
|
|
|
|
2012-10-12 09:11:23 -07:00
|
|
|
if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
|
2012-10-12 09:11:22 -07:00
|
|
|
// Called once the resource's dimensions have been obtained.
|
|
|
|
aRequest->GetImage(getter_AddRefs(mFrame->mImageContainer));
|
2013-06-09 17:14:01 -07:00
|
|
|
mFrame->InvalidateFrame();
|
2013-04-25 02:18:42 -07:00
|
|
|
nsSVGEffects::InvalidateRenderingObservers(mFrame);
|
2012-11-28 01:42:13 -08:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(mFrame);
|
2012-10-12 09:11:22 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|