2004-12-18 02:45:30 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2004-12-18 02:45:30 +03:00
|
|
|
|
2012-03-26 15:58:59 +04:00
|
|
|
// Keep in (case-insensitive) order:
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxMatrix.h"
|
|
|
|
#include "gfxPlatform.h"
|
2004-12-18 02:45:30 +03:00
|
|
|
#include "imgIContainer.h"
|
2013-01-06 13:32:01 +04:00
|
|
|
#include "nsIImageLoadingContent.h"
|
2009-04-05 13:52:14 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2012-10-12 20:11:22 +04:00
|
|
|
#include "imgINotificationObserver.h"
|
2012-03-20 16:15:53 +04:00
|
|
|
#include "nsSVGEffects.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGPathGeometryFrame.h"
|
2013-01-10 03:02:45 +04:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2012-03-26 15:58:59 +04:00
|
|
|
#include "nsSVGUtils.h"
|
2012-09-22 23:26:05 +04:00
|
|
|
#include "SVGContentUtils.h"
|
2013-03-01 00:22:43 +04:00
|
|
|
#include "SVGImageContext.h"
|
2013-01-06 13:32:01 +04:00
|
|
|
#include "mozilla/dom/SVGImageElement.h"
|
2013-02-01 03:11:49 +04:00
|
|
|
#include "nsContentUtils.h"
|
2013-09-15 04:05:05 +04:00
|
|
|
#include "nsIReflowCallback.h"
|
2011-10-19 19:37:49 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-01-06 13:32:01 +04:00
|
|
|
using namespace mozilla::dom;
|
2004-12-18 02:45:30 +03:00
|
|
|
|
|
|
|
class nsSVGImageFrame;
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
class nsSVGImageListener MOZ_FINAL : public imgINotificationObserver
|
2004-12-18 02:45:30 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsSVGImageListener(nsSVGImageFrame *aFrame);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2012-10-12 20:11:22 +04:00
|
|
|
NS_DECL_IMGINOTIFICATIONOBSERVER
|
2004-12-18 02:45:30 +03:00
|
|
|
|
|
|
|
void SetFrame(nsSVGImageFrame *frame) { mFrame = frame; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsSVGImageFrame *mFrame;
|
|
|
|
};
|
|
|
|
|
2011-10-19 19:37:49 +04:00
|
|
|
typedef nsSVGPathGeometryFrame nsSVGImageFrameBase;
|
2004-12-18 02:45:30 +03:00
|
|
|
|
2013-09-15 04:05:05 +04:00
|
|
|
class nsSVGImageFrame : public nsSVGImageFrameBase,
|
|
|
|
public nsIReflowCallback
|
2004-12-18 02:45:30 +03:00
|
|
|
{
|
2005-11-11 05:36:29 +03:00
|
|
|
friend nsIFrame*
|
2009-01-19 21:31:34 +03:00
|
|
|
NS_NewSVGImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
2004-12-18 02:45:30 +03:00
|
|
|
|
2007-07-13 13:32:37 +04:00
|
|
|
protected:
|
2013-09-15 04:05:05 +04:00
|
|
|
nsSVGImageFrame(nsStyleContext* aContext) : nsSVGImageFrameBase(aContext),
|
|
|
|
mReflowCallbackPosted(false) {}
|
2004-12-18 02:45:30 +03:00
|
|
|
virtual ~nsSVGImageFrame();
|
|
|
|
|
|
|
|
public:
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2004-12-18 02:45:30 +03:00
|
|
|
// nsISVGChildFrame interface:
|
2013-09-11 11:27:45 +04:00
|
|
|
NS_IMETHOD PaintSVG(nsRenderingContext *aContext, const nsIntRect *aDirtyRect,
|
|
|
|
nsIFrame* aTransformRoot) MOZ_OVERRIDE;
|
2008-08-25 13:23:54 +04:00
|
|
|
NS_IMETHOD_(nsIFrame*) GetFrameForPoint(const nsPoint &aPoint);
|
2012-07-22 04:01:44 +04:00
|
|
|
virtual void ReflowSVG();
|
2004-12-18 02:45:30 +03:00
|
|
|
|
2006-06-20 21:01:09 +04:00
|
|
|
// nsSVGPathGeometryFrame methods:
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual uint16_t GetHitTestFlags();
|
2006-06-20 21:01:09 +04:00
|
|
|
|
|
|
|
// nsIFrame interface:
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHOD AttributeChanged(int32_t aNameSpaceID,
|
2006-06-20 21:01:09 +04:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType);
|
2013-03-20 05:47:48 +04:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2011-11-10 01:39:16 +04:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot);
|
2006-06-20 21:01:09 +04:00
|
|
|
|
2005-04-01 23:56:08 +04:00
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
2006-12-26 20:47:52 +03:00
|
|
|
* @see nsGkAtoms::svgImageFrame
|
2005-04-01 23:56:08 +04:00
|
|
|
*/
|
|
|
|
virtual nsIAtom* GetType() const;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGImage"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-15 04:05:05 +04:00
|
|
|
// nsIReflowCallback
|
|
|
|
virtual bool ReflowFinished() MOZ_OVERRIDE;
|
|
|
|
virtual void ReflowCallbackCanceled() MOZ_OVERRIDE;
|
|
|
|
|
2004-12-18 02:45:30 +03:00
|
|
|
private:
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxMatrix GetRasterImageTransform(int32_t aNativeWidth,
|
|
|
|
int32_t aNativeHeight,
|
2013-09-11 11:27:45 +04:00
|
|
|
uint32_t aFor,
|
|
|
|
nsIFrame* aTransformRoot = nullptr);
|
|
|
|
gfxMatrix GetVectorImageTransform(uint32_t aFor,
|
|
|
|
nsIFrame* aTransformRoot = nullptr);
|
|
|
|
bool TransformContextForPainting(gfxContext* aGfxContext,
|
|
|
|
nsIFrame* aTransformRoot);
|
2006-09-19 20:35:29 +04:00
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
nsCOMPtr<imgINotificationObserver> mListener;
|
2004-12-18 02:45:30 +03:00
|
|
|
|
2006-12-07 01:23:10 +03:00
|
|
|
nsCOMPtr<imgIContainer> mImageContainer;
|
2004-12-18 02:45:30 +03:00
|
|
|
|
2013-09-15 04:05:05 +04:00
|
|
|
bool mReflowCallbackPosted;
|
|
|
|
|
2004-12-18 02:45:30 +03:00
|
|
|
friend class nsSVGImageListener;
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2009-01-19 21:31:34 +03:00
|
|
|
NS_NewSVGImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2004-12-18 02:45:30 +03:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsSVGImageFrame(aContext);
|
2004-12-18 02:45:30 +03:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsSVGImageFrame)
|
|
|
|
|
2004-12-18 02:45:30 +03: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 18:20:58 +04:00
|
|
|
reinterpret_cast<nsSVGImageListener*>(mListener.get())->SetFrame(nullptr);
|
2004-12-18 02:45:30 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mListener = nullptr;
|
2004-12-18 02:45:30 +03:00
|
|
|
}
|
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2007-08-30 21:01:37 +04:00
|
|
|
nsSVGImageFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2004-12-18 02:45:30 +03:00
|
|
|
{
|
2013-01-08 07:22:41 +04:00
|
|
|
NS_ASSERTION(aContent->IsSVG(nsGkAtoms::image),
|
|
|
|
"Content is not an SVG image!");
|
2009-01-19 21:31:34 +03:00
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
nsSVGImageFrameBase::Init(aContent, aParent, aPrevInFlow);
|
2013-01-08 07:22:41 +04:00
|
|
|
|
2004-12-18 02:45:30 +03:00
|
|
|
mListener = new nsSVGImageListener(this);
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
2013-03-20 05:47:48 +04:00
|
|
|
if (!imageLoader) {
|
|
|
|
NS_RUNTIMEABORT("Why is this not an image loading content?");
|
|
|
|
}
|
2011-02-01 07:50:01 +03:00
|
|
|
|
2011-11-10 01:39:16 +04: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);
|
|
|
|
|
2004-12-18 02:45:30 +03:00
|
|
|
imageLoader->AddObserver(mListener);
|
|
|
|
}
|
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
/* virtual */ void
|
|
|
|
nsSVGImageFrame::DestroyFrom(nsIFrame* aDestructRoot)
|
|
|
|
{
|
2013-09-15 04:05:05 +04:00
|
|
|
if (mReflowCallbackPosted) {
|
|
|
|
PresContext()->PresShell()->CancelReflowCallback(this);
|
|
|
|
mReflowCallbackPosted = false;
|
|
|
|
}
|
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader =
|
|
|
|
do_QueryInterface(nsFrame::mContent);
|
|
|
|
|
|
|
|
if (imageLoader) {
|
|
|
|
imageLoader->FrameDestroyed(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFrame::DestroyFrom(aDestructRoot);
|
|
|
|
}
|
|
|
|
|
2004-12-18 02:45:30 +03:00
|
|
|
//----------------------------------------------------------------------
|
2006-03-02 23:22:19 +03:00
|
|
|
// nsIFrame methods:
|
2004-12-18 02:45:30 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGImageFrame::AttributeChanged(int32_t aNameSpaceID,
|
2006-03-02 23:22:19 +03:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aModType)
|
2004-12-18 02:45:30 +03:00
|
|
|
{
|
2012-03-20 16:15:53 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
if (aAttribute == nsGkAtoms::x ||
|
|
|
|
aAttribute == nsGkAtoms::y ||
|
|
|
|
aAttribute == nsGkAtoms::width ||
|
|
|
|
aAttribute == nsGkAtoms::height) {
|
2013-04-25 13:18:42 +04:00
|
|
|
nsSVGEffects::InvalidateRenderingObservers(this);
|
2012-11-28 13:42:13 +04:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(this);
|
2012-03-20 16:15:53 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (aAttribute == nsGkAtoms::preserveAspectRatio) {
|
2013-11-24 23:50:45 +04:00
|
|
|
// We don't paint the content of the image using display lists, therefore
|
|
|
|
// we have to invalidate for this children-only transform changes since
|
|
|
|
// there is no layer tree to notice that the transform changed and
|
|
|
|
// recomposite.
|
|
|
|
InvalidateFrame();
|
2012-03-20 16:15:53 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-19 19:37:49 +04:00
|
|
|
}
|
|
|
|
if (aNameSpaceID == kNameSpaceID_XLink &&
|
|
|
|
aAttribute == nsGkAtoms::href) {
|
2011-10-29 12:18:25 +04:00
|
|
|
|
|
|
|
// Prevent setting image.src by exiting early
|
|
|
|
if (nsContentUtils::IsImageSrcSetDisabled()) {
|
2011-10-19 19:37:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-01-06 13:32:01 +04:00
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
2011-10-19 19:37:49 +04:00
|
|
|
|
2013-01-06 13:32:01 +04:00
|
|
|
if (element->mStringAttributes[SVGImageElement::HREF].IsExplicitlySet()) {
|
2011-10-19 19:37:49 +04:00
|
|
|
element->LoadSVGImage(true, true);
|
|
|
|
} else {
|
|
|
|
element->CancelImageRequests(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsSVGImageFrameBase::AttributeChanged(aNameSpaceID,
|
|
|
|
aAttribute, aModType);
|
2004-12-18 02:45:30 +03:00
|
|
|
}
|
|
|
|
|
2009-07-23 12:35:59 +04:00
|
|
|
gfxMatrix
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGImageFrame::GetRasterImageTransform(int32_t aNativeWidth,
|
|
|
|
int32_t aNativeHeight,
|
2013-09-11 11:27:45 +04:00
|
|
|
uint32_t aFor,
|
|
|
|
nsIFrame* aTransformRoot)
|
2006-09-19 20:35:29 +04:00
|
|
|
{
|
|
|
|
float x, y, width, height;
|
2013-01-06 13:32:01 +04:00
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
2012-07-30 18:20:58 +04:00
|
|
|
element->GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2006-09-19 20:35:29 +04:00
|
|
|
|
2013-12-30 10:50:17 +04:00
|
|
|
Matrix viewBoxTM =
|
2013-03-03 12:11:03 +04:00
|
|
|
SVGContentUtils::GetViewBoxTransform(width, height,
|
2012-09-22 23:26:05 +04:00
|
|
|
0, 0, aNativeWidth, aNativeHeight,
|
|
|
|
element->mPreserveAspectRatio);
|
2009-07-23 12:35:59 +04:00
|
|
|
|
2013-12-30 10:50:17 +04:00
|
|
|
return ThebesMatrix(viewBoxTM) *
|
2013-09-11 11:27:45 +04:00
|
|
|
gfxMatrix().Translate(gfxPoint(x, y)) *
|
|
|
|
GetCanvasTM(aFor, aTransformRoot);
|
2006-09-19 20:35:29 +04:00
|
|
|
}
|
|
|
|
|
2010-12-20 03:45:29 +03:00
|
|
|
gfxMatrix
|
2013-09-11 11:27:45 +04:00
|
|
|
nsSVGImageFrame::GetVectorImageTransform(uint32_t aFor,
|
|
|
|
nsIFrame* aTransformRoot)
|
2010-12-20 03:45:29 +03:00
|
|
|
{
|
|
|
|
float x, y, width, height;
|
2013-01-06 13:32:01 +04:00
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
2012-07-30 18:20:58 +04:00
|
|
|
element->GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2010-12-20 03:45:29 +03: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.
|
|
|
|
|
2013-09-11 11:27:45 +04:00
|
|
|
return gfxMatrix().Translate(gfxPoint(x, y)) *
|
|
|
|
GetCanvasTM(aFor, aTransformRoot);
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-09-11 11:27:45 +04:00
|
|
|
nsSVGImageFrame::TransformContextForPainting(gfxContext* aGfxContext,
|
|
|
|
nsIFrame* aTransformRoot)
|
2010-12-20 03:45:29 +03:00
|
|
|
{
|
|
|
|
gfxMatrix imageTransform;
|
|
|
|
if (mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) {
|
2013-09-11 11:27:45 +04:00
|
|
|
imageTransform = GetVectorImageTransform(FOR_PAINTING, aTransformRoot);
|
2010-12-20 03:45:29 +03:00
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nativeWidth, nativeHeight;
|
2010-12-20 03:45:29 +03:00
|
|
|
if (NS_FAILED(mImageContainer->GetWidth(&nativeWidth)) ||
|
|
|
|
NS_FAILED(mImageContainer->GetHeight(&nativeHeight)) ||
|
|
|
|
nativeWidth == 0 || nativeHeight == 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
2012-06-30 15:20:46 +04:00
|
|
|
imageTransform =
|
2013-09-11 11:27:45 +04:00
|
|
|
GetRasterImageTransform(nativeWidth, nativeHeight, FOR_PAINTING,
|
|
|
|
aTransformRoot);
|
2013-11-09 03:14:53 +04: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-20 03:45:29 +03:00
|
|
|
}
|
|
|
|
|
2011-01-11 08:57:19 +03:00
|
|
|
if (imageTransform.IsSingular()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-01-11 08:57:19 +03:00
|
|
|
}
|
|
|
|
|
2013-06-13 11:47:26 +04:00
|
|
|
aGfxContext->Multiply(imageTransform);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
|
|
|
|
2004-12-18 02:45:30 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISVGChildFrame methods:
|
|
|
|
NS_IMETHODIMP
|
2012-03-02 12:28:59 +04:00
|
|
|
nsSVGImageFrame::PaintSVG(nsRenderingContext *aContext,
|
2013-09-11 11:27:45 +04:00
|
|
|
const nsIntRect *aDirtyRect,
|
|
|
|
nsIFrame* aTransformRoot)
|
2004-12-18 02:45:30 +03:00
|
|
|
{
|
2006-10-27 14:34:23 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
if (!StyleVisibility()->IsVisible())
|
2005-01-25 06:55:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-12 19:40:46 +04:00
|
|
|
float x, y, width, height;
|
2013-01-06 13:32:01 +04:00
|
|
|
SVGImageElement *imgElem = static_cast<SVGImageElement*>(mContent);
|
2012-07-30 18:20:58 +04:00
|
|
|
imgElem->GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
2012-03-03 13:21:09 +04:00
|
|
|
NS_ASSERTION(width > 0 && height > 0,
|
|
|
|
"Should only be painting things with valid width/height");
|
2007-07-12 19:40:46 +04:00
|
|
|
|
2006-12-07 01:23:10 +03:00
|
|
|
if (!mImageContainer) {
|
2004-12-18 02:45:30 +03:00
|
|
|
nsCOMPtr<imgIRequest> currentRequest;
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> imageLoader = do_QueryInterface(mContent);
|
|
|
|
if (imageLoader)
|
|
|
|
imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(currentRequest));
|
|
|
|
|
|
|
|
if (currentRequest)
|
2006-12-07 01:23:10 +03:00
|
|
|
currentRequest->GetImage(getter_AddRefs(mImageContainer));
|
|
|
|
}
|
2004-12-18 02:45:30 +03:00
|
|
|
|
2010-10-12 00:08:19 +04:00
|
|
|
if (mImageContainer) {
|
2012-03-02 12:28:59 +04:00
|
|
|
gfxContext* ctx = aContext->ThebesContext();
|
2010-10-12 00:08:19 +04:00
|
|
|
gfxContextAutoSaveRestore autoRestorer(ctx);
|
2006-11-27 20:30:57 +03:00
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow()) {
|
2010-10-12 00:08:19 +04:00
|
|
|
gfxRect clipRect = nsSVGUtils::GetClipRectForFrame(this, x, y,
|
|
|
|
width, height);
|
2013-09-11 11:27:45 +04:00
|
|
|
nsSVGUtils::SetClipRect(ctx, GetCanvasTM(FOR_PAINTING, aTransformRoot),
|
|
|
|
clipRect);
|
2006-03-23 02:17:26 +03:00
|
|
|
}
|
|
|
|
|
2013-09-11 11:27:45 +04:00
|
|
|
if (!TransformContextForPainting(ctx, aTransformRoot)) {
|
2010-12-20 03:45:29 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-10-12 00:08:19 +04:00
|
|
|
|
2007-01-04 18:05:39 +03: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-17 01:51:02 +04:00
|
|
|
opacity = StyleDisplay()->mOpacity;
|
2007-01-04 18:05:39 +03:00
|
|
|
}
|
|
|
|
|
2013-09-15 07:40:11 +04:00
|
|
|
if (opacity != 1.0f || StyleDisplay()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2013-09-25 00:45:13 +04:00
|
|
|
ctx->PushGroup(GFX_CONTENT_COLOR_ALPHA);
|
2010-10-12 00:08:19 +04:00
|
|
|
}
|
2008-03-12 20:19:51 +03:00
|
|
|
|
2010-12-20 03:45:29 +03:00
|
|
|
nscoord appUnitsPerDevPx = PresContext()->AppUnitsPerDevPixel();
|
2010-10-12 00:08:19 +04:00
|
|
|
nsRect dirtyRect; // only used if aDirtyRect is non-null
|
|
|
|
if (aDirtyRect) {
|
2012-07-20 22:12:29 +04:00
|
|
|
NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
|
2013-07-12 11:13:07 +04:00
|
|
|
(mState & NS_FRAME_IS_NONDISPLAY),
|
2012-07-20 22:12:29 +04:00
|
|
|
"Display lists handle dirty rect intersection test");
|
2010-10-23 02:55:04 +04:00
|
|
|
dirtyRect = aDirtyRect->ToAppUnits(appUnitsPerDevPx);
|
2010-10-22 20:52:41 +04:00
|
|
|
// Adjust dirtyRect to match our local coordinate system.
|
2012-02-10 16:33:46 +04:00
|
|
|
nsRect rootRect =
|
2012-06-30 15:20:46 +04:00
|
|
|
nsSVGUtils::TransformFrameRectToOuterSVG(mRect,
|
|
|
|
GetCanvasTM(FOR_PAINTING), PresContext());
|
2012-02-10 16:33:46 +04:00
|
|
|
dirtyRect.MoveBy(-rootRect.TopLeft());
|
2010-10-12 00:08:19 +04:00
|
|
|
}
|
2006-03-23 02:17:26 +03:00
|
|
|
|
2010-10-12 00:08:19 +04: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 19:56:38 +04:00
|
|
|
uint32_t drawFlags = imgIContainer::FLAG_SYNC_DECODE;
|
2010-12-20 03:45:29 +03:00
|
|
|
|
|
|
|
if (mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) {
|
2013-03-01 00:22:43 +04: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-20 03:45:29 +03: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 12:28:59 +04:00
|
|
|
aContext,
|
2010-12-20 03:45:29 +03:00
|
|
|
mImageContainer,
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(this),
|
|
|
|
destRect,
|
|
|
|
aDirtyRect ? dirtyRect : destRect,
|
2013-03-01 00:22:43 +04:00
|
|
|
&context,
|
2010-12-20 03:45:29 +03:00
|
|
|
drawFlags);
|
|
|
|
} else { // mImageContainer->GetType() == TYPE_RASTER
|
|
|
|
nsLayoutUtils::DrawSingleUnscaledImage(
|
2012-03-02 12:28:59 +04:00
|
|
|
aContext,
|
2010-12-20 03:45:29 +03:00
|
|
|
mImageContainer,
|
|
|
|
nsLayoutUtils::GetGraphicsFilterForFrame(this),
|
|
|
|
nsPoint(0, 0),
|
2012-07-30 18:20:58 +04:00
|
|
|
aDirtyRect ? &dirtyRect : nullptr,
|
2010-12-20 03:45:29 +03:00
|
|
|
drawFlags);
|
|
|
|
}
|
2010-10-12 00:08:19 +04:00
|
|
|
|
2013-09-15 07:40:11 +04:00
|
|
|
if (opacity != 1.0f || StyleDisplay()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2010-10-12 00:08:19 +04:00
|
|
|
ctx->PopGroupToSource();
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
ctx->Paint(opacity);
|
|
|
|
}
|
|
|
|
// gfxContextAutoSaveRestore goes out of scope & cleans up our gfxContext
|
2004-12-18 02:45:30 +03:00
|
|
|
}
|
|
|
|
|
2006-10-27 14:34:23 +04:00
|
|
|
return rv;
|
2004-12-18 02:45:30 +03:00
|
|
|
}
|
|
|
|
|
2008-08-25 13:23:54 +04:00
|
|
|
NS_IMETHODIMP_(nsIFrame*)
|
|
|
|
nsSVGImageFrame::GetFrameForPoint(const nsPoint &aPoint)
|
2006-09-19 20:35:29 +04:00
|
|
|
{
|
2010-12-20 03:45:29 +03: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-17 01:51:02 +04:00
|
|
|
if (StyleDisplay()->IsScrollableOverflow() && mImageContainer) {
|
2010-12-20 03:45:29 +03:00
|
|
|
if (mImageContainer->GetType() == imgIContainer::TYPE_RASTER) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nativeWidth, nativeHeight;
|
2010-12-20 03:45:29 +03:00
|
|
|
if (NS_FAILED(mImageContainer->GetWidth(&nativeWidth)) ||
|
|
|
|
NS_FAILED(mImageContainer->GetHeight(&nativeHeight)) ||
|
|
|
|
nativeWidth == 0 || nativeHeight == 0) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!nsSVGUtils::HitTestRect(
|
2012-06-30 15:20:46 +04:00
|
|
|
GetRasterImageTransform(nativeWidth, nativeHeight,
|
|
|
|
FOR_HIT_TESTING),
|
2010-12-20 03:45:29 +03:00
|
|
|
0, 0, nativeWidth, nativeHeight,
|
|
|
|
PresContext()->AppUnitsToDevPixels(aPoint.x),
|
|
|
|
PresContext()->AppUnitsToDevPixels(aPoint.y))) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-12-20 03:45:29 +03:00
|
|
|
}
|
2006-09-19 20:35:29 +04:00
|
|
|
}
|
2010-12-20 03:45:29 +03: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.
|
2006-09-19 20:35:29 +04:00
|
|
|
}
|
|
|
|
|
2011-10-19 19:37:49 +04:00
|
|
|
return nsSVGImageFrameBase::GetFrameForPoint(aPoint);
|
2006-09-19 20:35:29 +04:00
|
|
|
}
|
|
|
|
|
2005-04-01 23:56:08 +04:00
|
|
|
nsIAtom *
|
|
|
|
nsSVGImageFrame::GetType() const
|
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::svgImageFrame;
|
2005-04-01 23:56:08 +04:00
|
|
|
}
|
|
|
|
|
2006-06-21 19:42:28 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGPathGeometryFrame methods:
|
|
|
|
|
2009-08-31 15:26:23 +04:00
|
|
|
// Lie about our fill/stroke so that covered region and hit detection work properly
|
|
|
|
|
2012-03-20 16:15:53 +04:00
|
|
|
void
|
2012-07-22 04:01:44 +04:00
|
|
|
nsSVGImageFrame::ReflowSVG()
|
2009-08-31 15:26:23 +04:00
|
|
|
{
|
2012-07-22 04:01:44 +04:00
|
|
|
NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingReflowSVG(this),
|
|
|
|
"This call is probably a wasteful mistake");
|
2012-03-20 16:15:53 +04:00
|
|
|
|
2013-07-12 11:13:07 +04:00
|
|
|
NS_ABORT_IF_FALSE(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY),
|
2012-07-22 04:01:44 +04:00
|
|
|
"ReflowSVG mechanism not designed for this");
|
2012-03-20 16:15:53 +04:00
|
|
|
|
2012-07-22 04:01:44 +04:00
|
|
|
if (!nsSVGUtils::NeedsReflowSVG(this)) {
|
2012-03-20 16:15:53 +04:00
|
|
|
return;
|
|
|
|
}
|
2009-08-31 15:26:23 +04:00
|
|
|
|
2013-12-06 13:59:36 +04:00
|
|
|
gfxContext tmpCtx(gfxPlatform::GetPlatform()->ScreenReferenceSurface());
|
2009-08-31 15:26:23 +04:00
|
|
|
|
2012-12-20 17:49:54 +04: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 14:07:00 +04:00
|
|
|
}
|
2013-12-06 13:59:36 +04:00
|
|
|
tmpCtx.Save();
|
|
|
|
GeneratePath(&tmpCtx, scaling);
|
|
|
|
tmpCtx.Restore();
|
|
|
|
gfxRect extent = tmpCtx.GetUserPathExtent();
|
2012-12-20 17:49:54 +04:00
|
|
|
if (applyScaling) {
|
|
|
|
extent.Scale(1 / scaleFactors.width, 1 / scaleFactors.height);
|
|
|
|
}
|
2009-08-31 15:26:23 +04:00
|
|
|
|
|
|
|
if (!extent.IsEmpty()) {
|
2012-02-10 16:33:18 +04:00
|
|
|
mRect = nsLayoutUtils::RoundGfxRectToAppRect(extent,
|
2012-02-17 10:07:51 +04:00
|
|
|
PresContext()->AppUnitsPerCSSPixel());
|
2012-03-20 16:15:53 +04:00
|
|
|
} else {
|
|
|
|
mRect.SetEmpty();
|
2009-08-31 15:26:23 +04:00
|
|
|
}
|
|
|
|
|
2012-05-17 08:05:09 +04: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);
|
2013-09-15 04:05:05 +04:00
|
|
|
|
|
|
|
if (!mReflowCallbackPosted) {
|
|
|
|
nsIPresShell* shell = PresContext()->PresShell();
|
2013-09-15 04:05:06 +04:00
|
|
|
mReflowCallbackPosted = true;
|
|
|
|
shell->PostReflowCallback(this);
|
2013-09-15 04:05:05 +04:00
|
|
|
}
|
2012-05-17 08:05:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect overflow = nsRect(nsPoint(0,0), mRect.Size());
|
|
|
|
nsOverflowAreas overflowAreas(overflow, overflow);
|
|
|
|
FinishAndStoreOverflow(overflowAreas, mRect.Size());
|
|
|
|
|
2012-03-20 16:15:53 +04:00
|
|
|
mState &= ~(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
|
|
|
|
NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
|
2012-11-28 14:34:58 +04: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 16:15:53 +04:00
|
|
|
}
|
2009-08-31 15:26:23 +04:00
|
|
|
}
|
2005-04-02 00:49:42 +04:00
|
|
|
|
2013-09-15 04:05:05 +04:00
|
|
|
bool
|
|
|
|
nsSVGImageFrame::ReflowFinished()
|
|
|
|
{
|
|
|
|
mReflowCallbackPosted = false;
|
|
|
|
|
|
|
|
nsLayoutUtils::UpdateImageVisibilityForFrame(this);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGImageFrame::ReflowCallbackCanceled()
|
|
|
|
{
|
|
|
|
mReflowCallbackPosted = false;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t
|
2011-07-08 17:20:14 +04:00
|
|
|
nsSVGImageFrame::GetHitTestFlags()
|
2005-04-02 00:49:42 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t flags = 0;
|
2005-04-02 00:49:42 +04:00
|
|
|
|
2013-02-17 01:51:02 +04:00
|
|
|
switch(StyleVisibility()->mPointerEvents) {
|
2005-04-02 00:49:42 +04:00
|
|
|
case NS_STYLE_POINTER_EVENTS_NONE:
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEPAINTED:
|
2009-08-27 07:53:35 +04:00
|
|
|
case NS_STYLE_POINTER_EVENTS_AUTO:
|
2013-02-17 01:51:02 +04:00
|
|
|
if (StyleVisibility()->IsVisible()) {
|
2005-04-02 00:49:42 +04:00
|
|
|
/* XXX: should check pixel transparency */
|
2011-07-08 17:20:14 +04:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2005-04-02 00:49:42 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLEFILL:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLESTROKE:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_VISIBLE:
|
2013-02-17 01:51:02 +04:00
|
|
|
if (StyleVisibility()->IsVisible()) {
|
2011-07-08 17:20:14 +04:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2005-04-02 00:49:42 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_PAINTED:
|
|
|
|
/* XXX: should check pixel transparency */
|
2011-07-08 17:20:14 +04:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2005-04-02 00:49:42 +04:00
|
|
|
break;
|
|
|
|
case NS_STYLE_POINTER_EVENTS_FILL:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_STROKE:
|
|
|
|
case NS_STYLE_POINTER_EVENTS_ALL:
|
2011-07-08 17:20:14 +04:00
|
|
|
flags |= SVG_HIT_TEST_FILL;
|
2005-04-02 00:49:42 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("not reached");
|
|
|
|
break;
|
|
|
|
}
|
2006-06-20 21:01:09 +04:00
|
|
|
|
2011-07-08 17:20:14 +04:00
|
|
|
return flags;
|
2005-04-02 00:49:42 +04:00
|
|
|
}
|
|
|
|
|
2004-12-18 02:45:30 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsSVGImageListener implementation
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsSVGImageListener, imgINotificationObserver)
|
2004-12-18 02:45:30 +03:00
|
|
|
|
|
|
|
nsSVGImageListener::nsSVGImageListener(nsSVGImageFrame *aFrame) : mFrame(aFrame)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:11:22 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsSVGImageListener::Notify(imgIRequest *aRequest, int32_t aType, const nsIntRect* aData)
|
2012-10-12 05:58:24 +04:00
|
|
|
{
|
|
|
|
if (!mFrame)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-01-18 20:46:36 +03:00
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::LOAD_COMPLETE) {
|
2013-06-10 04:14:01 +04:00
|
|
|
mFrame->InvalidateFrame();
|
2013-04-25 13:18:42 +04:00
|
|
|
nsSVGEffects::InvalidateRenderingObservers(mFrame);
|
2012-11-28 13:42:13 +04:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(mFrame);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
2012-10-12 05:58:24 +04:00
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::FRAME_UPDATE) {
|
2012-10-12 20:11:22 +04:00
|
|
|
// No new dimensions, so we don't need to call
|
|
|
|
// nsSVGUtils::InvalidateAndScheduleBoundsUpdate.
|
|
|
|
nsSVGEffects::InvalidateRenderingObservers(mFrame);
|
2013-06-10 04:14:01 +04:00
|
|
|
mFrame->InvalidateFrame();
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
2012-10-12 05:58:24 +04:00
|
|
|
|
2012-10-12 20:11:23 +04:00
|
|
|
if (aType == imgINotificationObserver::SIZE_AVAILABLE) {
|
2012-10-12 20:11:22 +04:00
|
|
|
// Called once the resource's dimensions have been obtained.
|
|
|
|
aRequest->GetImage(getter_AddRefs(mFrame->mImageContainer));
|
2013-06-10 04:14:01 +04:00
|
|
|
mFrame->InvalidateFrame();
|
2013-04-25 13:18:42 +04:00
|
|
|
nsSVGEffects::InvalidateRenderingObservers(mFrame);
|
2012-11-28 13:42:13 +04:00
|
|
|
nsSVGUtils::ScheduleReflowSVG(mFrame);
|
2012-10-12 20:11:22 +04:00
|
|
|
}
|
2007-01-18 20:46:36 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|