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 "gfxPlatform.h"
|
2014-03-31 04:53:54 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "imgIContainer.h"
|
2014-05-24 15:20:39 -07:00
|
|
|
#include "nsContainerFrame.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"
|
2013-09-14 17:05:05 -07:00
|
|
|
#include "nsIReflowCallback.h"
|
2011-10-19 08:37:49 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-01-06 01:32:01 -08:00
|
|
|
using namespace mozilla::dom;
|
2014-03-31 04:53:54 -07:00
|
|
|
using namespace mozilla::gfx;
|
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:
|
2014-06-23 15:40:01 -07:00
|
|
|
~nsSVGImageListener() {}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsSVGImageFrame *mFrame;
|
|
|
|
};
|
|
|
|
|
2011-10-19 08:37:49 -07:00
|
|
|
typedef nsSVGPathGeometryFrame nsSVGImageFrameBase;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-09-14 17:05:05 -07:00
|
|
|
class nsSVGImageFrame : public nsSVGImageFrameBase,
|
|
|
|
public nsIReflowCallback
|
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:
|
2013-09-14 17:05:05 -07:00
|
|
|
nsSVGImageFrame(nsStyleContext* aContext) : nsSVGImageFrameBase(aContext),
|
|
|
|
mReflowCallbackPosted(false) {}
|
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:
|
2014-02-19 14:34:31 -08:00
|
|
|
virtual nsresult PaintSVG(nsRenderingContext *aContext,
|
|
|
|
const nsIntRect *aDirtyRect,
|
|
|
|
nsIFrame* aTransformRoot) MOZ_OVERRIDE;
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsIFrame* GetFrameForPoint(const nsPoint &aPoint) MOZ_OVERRIDE;
|
|
|
|
virtual void ReflowSVG() MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsSVGPathGeometryFrame methods:
|
2014-01-04 00:29:02 -08:00
|
|
|
virtual uint16_t GetHitTestFlags() MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsIFrame interface:
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2014-02-18 00:36:33 -08:00
|
|
|
nsIAtom* aAttribute,
|
2014-02-24 06:41:56 -08:00
|
|
|
int32_t aModType) MOZ_OVERRIDE;
|
2014-05-24 15:20:40 -07:00
|
|
|
virtual void Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
|
|
|
* @see nsGkAtoms::svgImageFrame
|
|
|
|
*/
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("SVGImage"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-14 17:05:05 -07:00
|
|
|
// nsIReflowCallback
|
|
|
|
virtual bool ReflowFinished() MOZ_OVERRIDE;
|
|
|
|
virtual void ReflowCallbackCanceled() MOZ_OVERRIDE;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2013-12-30 13:42:26 -08:00
|
|
|
gfx::Matrix GetRasterImageTransform(int32_t aNativeWidth,
|
|
|
|
int32_t aNativeHeight,
|
|
|
|
uint32_t aFor,
|
|
|
|
nsIFrame* aTransformRoot = nullptr);
|
|
|
|
gfx::Matrix GetVectorImageTransform(uint32_t aFor,
|
|
|
|
nsIFrame* aTransformRoot = nullptr);
|
2013-09-11 00:27:45 -07:00
|
|
|
bool TransformContextForPainting(gfxContext* aGfxContext,
|
|
|
|
nsIFrame* aTransformRoot);
|
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;
|
|
|
|
|
2013-09-14 17:05:05 -07:00
|
|
|
bool mReflowCallbackPosted;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
2014-05-24 15:20:40 -07:00
|
|
|
nsSVGImageFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* 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)
|
|
|
|
{
|
2013-09-14 17:05:05 -07:00
|
|
|
if (mReflowCallbackPosted) {
|
|
|
|
PresContext()->PresShell()->CancelReflowCallback(this);
|
|
|
|
mReflowCallbackPosted = false;
|
|
|
|
}
|
|
|
|
|
2011-11-09 13:39:16 -08:00
|
|
|
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:
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
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-11-24 11:50:45 -08: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 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
|
|
|
}
|
|
|
|
|
2013-12-30 13:42:26 -08:00
|
|
|
gfx::Matrix
|
2012-08-22 08:56:38 -07:00
|
|
|
nsSVGImageFrame::GetRasterImageTransform(int32_t aNativeWidth,
|
|
|
|
int32_t aNativeHeight,
|
2013-09-11 00:27:45 -07:00
|
|
|
uint32_t aFor,
|
|
|
|
nsIFrame* aTransformRoot)
|
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
|
|
|
|
2013-12-29 22:50:17 -08:00
|
|
|
Matrix 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
|
|
|
|
2013-12-30 13:42:26 -08:00
|
|
|
return viewBoxTM *
|
2014-03-21 16:56:11 -07:00
|
|
|
gfx::Matrix::Translation(x, y) *
|
2013-12-30 13:42:26 -08:00
|
|
|
gfx::ToMatrix(GetCanvasTM(aFor, aTransformRoot));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-12-30 13:42:26 -08:00
|
|
|
gfx::Matrix
|
2013-09-11 00:27:45 -07:00
|
|
|
nsSVGImageFrame::GetVectorImageTransform(uint32_t aFor,
|
|
|
|
nsIFrame* aTransformRoot)
|
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.
|
|
|
|
|
2014-03-21 16:56:11 -07:00
|
|
|
return gfx::Matrix::Translation(x, y) *
|
2013-12-30 13:42:26 -08:00
|
|
|
gfx::ToMatrix(GetCanvasTM(aFor, aTransformRoot));
|
2010-12-19 16:45:29 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-09-11 00:27:45 -07:00
|
|
|
nsSVGImageFrame::TransformContextForPainting(gfxContext* aGfxContext,
|
|
|
|
nsIFrame* aTransformRoot)
|
2010-12-19 16:45:29 -08:00
|
|
|
{
|
2013-12-30 13:42:26 -08:00
|
|
|
gfx::Matrix imageTransform;
|
2010-12-19 16:45:29 -08:00
|
|
|
if (mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) {
|
2013-09-11 00:27:45 -07:00
|
|
|
imageTransform = GetVectorImageTransform(FOR_PAINTING, aTransformRoot);
|
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 =
|
2013-09-11 00:27:45 -07:00
|
|
|
GetRasterImageTransform(nativeWidth, nativeHeight, FOR_PAINTING,
|
|
|
|
aTransformRoot);
|
2013-11-08 15:14:53 -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);
|
|
|
|
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-12-30 13:42:26 -08:00
|
|
|
aGfxContext->Multiply(ThebesMatrix(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:
|
2014-02-19 14:34:31 -08:00
|
|
|
nsresult
|
2012-03-02 00:28:59 -08:00
|
|
|
nsSVGImageFrame::PaintSVG(nsRenderingContext *aContext,
|
2013-09-11 00:27:45 -07:00
|
|
|
const nsIntRect *aDirtyRect,
|
|
|
|
nsIFrame* aTransformRoot)
|
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);
|
2013-09-11 00:27:45 -07:00
|
|
|
nsSVGUtils::SetClipRect(ctx, GetCanvasTM(FOR_PAINTING, aTransformRoot),
|
|
|
|
clipRect);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-09-11 00:27:45 -07:00
|
|
|
if (!TransformContextForPainting(ctx, aTransformRoot)) {
|
2010-12-19 16:45:29 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-09-14 20:40:11 -07:00
|
|
|
if (opacity != 1.0f || StyleDisplay()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2014-01-23 10:26:40 -08:00
|
|
|
ctx->PushGroup(gfxContentType::COLOR_ALPHA);
|
2010-10-11 13:08:19 -07:00
|
|
|
}
|
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,
|
2014-06-19 23:42:30 -07:00
|
|
|
PresContext(),
|
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,
|
2014-06-19 23:42:30 -07:00
|
|
|
PresContext(),
|
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
|
|
|
|
2013-09-14 20:40:11 -07:00
|
|
|
if (opacity != 1.0f || StyleDisplay()->mMixBlendMode != NS_STYLE_BLEND_NORMAL) {
|
2010-10-11 13:08:19 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-19 14:34:31 -08:00
|
|
|
nsIFrame*
|
2008-08-25 02:23:54 -07:00
|
|
|
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,
|
2014-07-05 11:19:13 -07:00
|
|
|
PresContext()->AppUnitsToFloatCSSPixels(aPoint.x),
|
|
|
|
PresContext()->AppUnitsToFloatCSSPixels(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
|
|
|
|
2014-03-31 04:53:54 -07:00
|
|
|
float x, y, width, height;
|
|
|
|
SVGImageElement *element = static_cast<SVGImageElement*>(mContent);
|
|
|
|
element->GetAnimatedLengthValues(&x, &y, &width, &height, nullptr);
|
|
|
|
|
|
|
|
Rect extent(x, y, width, 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);
|
2013-09-14 17:05:05 -07:00
|
|
|
|
|
|
|
if (!mReflowCallbackPosted) {
|
|
|
|
nsIPresShell* shell = PresContext()->PresShell();
|
2013-09-14 17:05:06 -07:00
|
|
|
mReflowCallbackPosted = true;
|
|
|
|
shell->PostReflowCallback(this);
|
2013-09-14 17:05:05 -07:00
|
|
|
}
|
2012-05-16 21:05:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-09-14 17:05:05 -07:00
|
|
|
bool
|
|
|
|
nsSVGImageFrame::ReflowFinished()
|
|
|
|
{
|
|
|
|
mReflowCallbackPosted = false;
|
|
|
|
|
|
|
|
nsLayoutUtils::UpdateImageVisibilityForFrame(this);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSVGImageFrame::ReflowCallbackCanceled()
|
|
|
|
{
|
|
|
|
mReflowCallbackPosted = false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(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;
|
|
|
|
}
|
|
|
|
|